Merge "Using for loop instead of stream" into rvc-dev am: c822c12780 am: f8df08f780 am: a34e1e2ec4
Change-Id: I00e51802f8e703aef82252e22d531c3602509fdf
This commit is contained in:
@@ -72,7 +72,6 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Offers the ability to install, upgrade, and remove applications on the
|
||||
@@ -589,9 +588,15 @@ public class PackageInstaller {
|
||||
* * {@link SessionInfo#isStagedSessionActive()}.
|
||||
*/
|
||||
public @NonNull List<SessionInfo> getActiveStagedSessions() {
|
||||
return getStagedSessions().stream()
|
||||
.filter(s -> s.isStagedSessionActive())
|
||||
.collect(Collectors.toList());
|
||||
final List<SessionInfo> activeStagedSessions = new ArrayList<>();
|
||||
final List<SessionInfo> stagedSessions = getStagedSessions();
|
||||
for (int i = 0; i < stagedSessions.size(); i++) {
|
||||
final SessionInfo sessionInfo = stagedSessions.get(i);
|
||||
if (sessionInfo.isStagedSessionActive()) {
|
||||
activeStagedSessions.add(sessionInfo);
|
||||
}
|
||||
}
|
||||
return activeStagedSessions;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -61,11 +61,9 @@ import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* ApexManager class handles communications with the apex service to perform operation and queries,
|
||||
@@ -538,30 +536,42 @@ public abstract class ApexManager {
|
||||
List<PackageInfo> getActivePackages() {
|
||||
Preconditions.checkState(mAllPackagesCache != null,
|
||||
"APEX packages have not been scanned");
|
||||
return mAllPackagesCache
|
||||
.stream()
|
||||
.filter(item -> isActive(item))
|
||||
.collect(Collectors.toList());
|
||||
final List<PackageInfo> activePackages = new ArrayList<>();
|
||||
for (int i = 0; i < mAllPackagesCache.size(); i++) {
|
||||
final PackageInfo packageInfo = mAllPackagesCache.get(i);
|
||||
if (isActive(packageInfo)) {
|
||||
activePackages.add(packageInfo);
|
||||
}
|
||||
}
|
||||
return activePackages;
|
||||
}
|
||||
|
||||
@Override
|
||||
List<PackageInfo> getFactoryPackages() {
|
||||
Preconditions.checkState(mAllPackagesCache != null,
|
||||
"APEX packages have not been scanned");
|
||||
return mAllPackagesCache
|
||||
.stream()
|
||||
.filter(item -> isFactory(item))
|
||||
.collect(Collectors.toList());
|
||||
final List<PackageInfo> factoryPackages = new ArrayList<>();
|
||||
for (int i = 0; i < mAllPackagesCache.size(); i++) {
|
||||
final PackageInfo packageInfo = mAllPackagesCache.get(i);
|
||||
if (isFactory(packageInfo)) {
|
||||
factoryPackages.add(packageInfo);
|
||||
}
|
||||
}
|
||||
return factoryPackages;
|
||||
}
|
||||
|
||||
@Override
|
||||
List<PackageInfo> getInactivePackages() {
|
||||
Preconditions.checkState(mAllPackagesCache != null,
|
||||
"APEX packages have not been scanned");
|
||||
return mAllPackagesCache
|
||||
.stream()
|
||||
.filter(item -> !isActive(item))
|
||||
.collect(Collectors.toList());
|
||||
final List<PackageInfo> inactivePackages = new ArrayList<>();
|
||||
for (int i = 0; i < mAllPackagesCache.size(); i++) {
|
||||
final PackageInfo packageInfo = mAllPackagesCache.get(i);
|
||||
if (!isActive(packageInfo)) {
|
||||
inactivePackages.add(packageInfo);
|
||||
}
|
||||
}
|
||||
return inactivePackages;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -415,7 +415,6 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Keep track of all those APKs everywhere.
|
||||
@@ -2655,6 +2654,11 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
+ partition.folder);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return folder.getAbsolutePath() + ":" + scanFlag;
|
||||
}
|
||||
}
|
||||
|
||||
public PackageManagerService(Injector injector, boolean onlyCore, boolean factoryTest) {
|
||||
@@ -2757,15 +2761,19 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
mApexManager = ApexManager.getInstance();
|
||||
mAppsFilter = mInjector.getAppsFilter();
|
||||
|
||||
final List<ScanPartition> scanPartitions = new ArrayList<>();
|
||||
final List<ApexManager.ActiveApexInfo> activeApexInfos = mApexManager.getActiveApexInfos();
|
||||
for (int i = 0; i < activeApexInfos.size(); i++) {
|
||||
final ScanPartition scanPartition = resolveApexToScanPartition(activeApexInfos.get(i));
|
||||
if (scanPartition != null) {
|
||||
scanPartitions.add(scanPartition);
|
||||
}
|
||||
}
|
||||
|
||||
mDirsToScanAsSystem = new ArrayList<>();
|
||||
mDirsToScanAsSystem.addAll(SYSTEM_PARTITIONS);
|
||||
mDirsToScanAsSystem.addAll(mApexManager.getActiveApexInfos().stream()
|
||||
.map(PackageManagerService::resolveApexToScanPartition)
|
||||
.filter(Objects::nonNull).collect(Collectors.toList()));
|
||||
Slog.d(TAG,
|
||||
"Directories scanned as system partitions: [" + mDirsToScanAsSystem.stream().map(
|
||||
d -> (d.folder.getAbsolutePath() + ":" + d.scanFlag))
|
||||
.collect(Collectors.joining(",")) + "]");
|
||||
mDirsToScanAsSystem.addAll(scanPartitions);
|
||||
Slog.d(TAG, "Directories scanned as system partitions: " + mDirsToScanAsSystem);
|
||||
|
||||
// CHECKSTYLE:OFF IndentationCheck
|
||||
synchronized (mInstallLock) {
|
||||
|
||||
@@ -75,13 +75,11 @@ import com.android.server.rollback.WatchdogRollbackLogger;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* This class handles staged install sessions, i.e. install sessions that require packages to
|
||||
@@ -222,6 +220,7 @@ public class StagingManager {
|
||||
// which will be propagated to populate stagedSessionErrorMessage of this session.
|
||||
final ApexInfoList apexInfoList = mApexManager.submitStagedSession(apexSessionParams);
|
||||
final List<PackageInfo> result = new ArrayList<>();
|
||||
final List<String> apexPackageNames = new ArrayList<>();
|
||||
for (ApexInfo apexInfo : apexInfoList.apexInfos) {
|
||||
final PackageInfo packageInfo;
|
||||
int flags = PackageManager.GET_META_DATA;
|
||||
@@ -245,9 +244,10 @@ public class StagingManager {
|
||||
checkRequiredVersionCode(session, activePackage);
|
||||
checkDowngrade(session, activePackage, packageInfo);
|
||||
result.add(packageInfo);
|
||||
apexPackageNames.add(packageInfo.packageName);
|
||||
}
|
||||
Slog.d(TAG, "Session " + session.sessionId + " has following APEX packages: ["
|
||||
+ result.stream().map(p -> p.packageName).collect(Collectors.joining(",")) + "]");
|
||||
Slog.d(TAG, "Session " + session.sessionId + " has following APEX packages: "
|
||||
+ apexPackageNames);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -313,13 +313,16 @@ public class StagingManager {
|
||||
return filter.test(session);
|
||||
}
|
||||
synchronized (mStagedSessions) {
|
||||
return !(Arrays.stream(session.getChildSessionIds())
|
||||
// Retrieve cached sessions matching ids.
|
||||
.mapToObj(i -> mStagedSessions.get(i))
|
||||
// Filter only the ones containing APEX.
|
||||
.filter(childSession -> filter.test(childSession))
|
||||
.collect(Collectors.toList())
|
||||
.isEmpty());
|
||||
final int[] childSessionIds = session.getChildSessionIds();
|
||||
for (int id : childSessionIds) {
|
||||
// Retrieve cached sessions matching ids.
|
||||
final PackageInstallerSession s = mStagedSessions.get(id);
|
||||
// Filter only the ones containing APEX.
|
||||
if (filter.test(s)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -669,15 +672,15 @@ public class StagingManager {
|
||||
// contain an APK, and with those then create a new multi-package group of sessions,
|
||||
// carrying over all the session parameters and unmarking them as staged. On commit the
|
||||
// sessions will be installed atomically.
|
||||
final List<PackageInstallerSession> childSessions;
|
||||
final List<PackageInstallerSession> childSessions = new ArrayList<>();
|
||||
synchronized (mStagedSessions) {
|
||||
childSessions =
|
||||
Arrays.stream(session.getChildSessionIds())
|
||||
// Retrieve cached sessions matching ids.
|
||||
.mapToObj(i -> mStagedSessions.get(i))
|
||||
// Filter only the ones containing APKs.
|
||||
.filter(childSession -> !isApexSession(childSession))
|
||||
.collect(Collectors.toList());
|
||||
final int[] childSessionIds = session.getChildSessionIds();
|
||||
for (int id : childSessionIds) {
|
||||
final PackageInstallerSession s = mStagedSessions.get(id);
|
||||
if (!isApexSession(s)) {
|
||||
childSessions.add(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (childSessions.isEmpty()) {
|
||||
// APEX-only multi-package staged session, nothing to do.
|
||||
|
||||
Reference in New Issue
Block a user