Merge "Refactor restorePermissionState() locking."

This commit is contained in:
Hai Zhang
2020-10-07 19:57:23 +00:00
committed by Android (Google) Code Review
3 changed files with 545 additions and 578 deletions

View File

@@ -207,13 +207,13 @@ public abstract class ApexManager {
/**
* Returns the active apex package's name that contains the (apk) package.
*
* @param containedPackage The (apk) package that might be in a apex
* @param containedPackageName The (apk) package that might be in a apex
* @return the apex package's name of {@code null} if the {@code containedPackage} is not inside
* any apex.
*/
@Nullable
public abstract String getActiveApexPackageNameContainingPackage(
@NonNull AndroidPackage containedPackage);
@NonNull String containedPackageName);
/**
* Retrieves information about an apexd staged session i.e. the internal state used by apexd to
@@ -650,15 +650,14 @@ public abstract class ApexManager {
@Override
@Nullable
public String getActiveApexPackageNameContainingPackage(AndroidPackage containedPackage) {
Objects.requireNonNull(containedPackage);
public String getActiveApexPackageNameContainingPackage(String containedPackageName) {
Objects.requireNonNull(containedPackageName);
synchronized (mLock) {
Preconditions.checkState(mPackageNameToApexModuleName != null,
"APEX packages have not been scanned");
int numApksInApex = mApksInApex.size();
for (int apkInApexNum = 0; apkInApexNum < numApksInApex; apkInApexNum++) {
if (mApksInApex.valueAt(apkInApexNum).contains(
containedPackage.getPackageName())) {
if (mApksInApex.valueAt(apkInApexNum).contains(containedPackageName)) {
String apexModuleName = mApksInApex.keyAt(apkInApexNum);
int numApexPkgs = mPackageNameToApexModuleName.size();
@@ -1080,8 +1079,8 @@ public abstract class ApexManager {
@Override
@Nullable
public String getActiveApexPackageNameContainingPackage(
@NonNull AndroidPackage containedPackage) {
Objects.requireNonNull(containedPackage);
@NonNull String containedPackageName) {
Objects.requireNonNull(containedPackageName);
return null;
}

View File

@@ -27,7 +27,6 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageInstaller;
import android.content.pm.PackageManager;
import android.content.pm.PackageManagerInternal;
import android.content.pm.VersionedPackage;
import android.content.rollback.PackageRollbackInfo;
import android.content.rollback.RollbackInfo;
@@ -44,13 +43,11 @@ import android.util.SparseArray;
import com.android.internal.util.FrameworkStatsLog;
import com.android.internal.util.Preconditions;
import com.android.server.LocalServices;
import com.android.server.PackageWatchdog;
import com.android.server.PackageWatchdog.FailureReasons;
import com.android.server.PackageWatchdog.PackageHealthObserver;
import com.android.server.PackageWatchdog.PackageHealthObserverImpact;
import com.android.server.pm.ApexManager;
import com.android.server.pm.parsing.pkg.AndroidPackage;
import java.io.BufferedReader;
import java.io.File;
@@ -342,14 +339,10 @@ final class RollbackPackageHealthObserver implements PackageHealthObserver {
private boolean isModule(String packageName) {
// Check if the package is an APK inside an APEX. If it is, use the parent APEX package when
// querying PackageManager.
PackageManagerInternal pmi = LocalServices.getService(PackageManagerInternal.class);
AndroidPackage apkPackage = pmi.getPackage(packageName);
if (apkPackage != null) {
String apexPackageName = mApexManager.getActiveApexPackageNameContainingPackage(
apkPackage);
if (apexPackageName != null) {
packageName = apexPackageName;
}
String apexPackageName = mApexManager.getActiveApexPackageNameContainingPackage(
packageName);
if (apexPackageName != null) {
packageName = apexPackageName;
}
PackageManager pm = mContext.getPackageManager();