Merge changes Ib9172e79,I7b88d425 into sc-dev

* changes:
  Avoid locking PMS when printing from DomainVerificationService
  Add more domain verification debug functionality
This commit is contained in:
TreeHugger Robot
2021-02-08 20:31:13 +00:00
committed by Android (Google) Code Review
7 changed files with 73 additions and 19 deletions

View File

@@ -23933,7 +23933,8 @@ public class PackageManagerService extends IPackageManager.Stub
writer.println("Domain verification status:");
writer.increaseIndent();
try {
mDomainVerificationManager.printState(writer, packageName, UserHandle.USER_ALL);
mDomainVerificationManager.printState(writer, packageName, UserHandle.USER_ALL,
mSettings::getPackageLPr);
} catch (PackageManager.NameNotFoundException e) {
pw.println("Failure printing domain verification information");
Slog.e(TAG, "Failure printing domain verification information", e);

View File

@@ -32,15 +32,30 @@ import android.util.SparseArray;
import com.android.internal.util.CollectionUtils;
import com.android.server.pm.PackageSetting;
import com.android.server.pm.parsing.pkg.AndroidPackage;
import com.android.server.pm.verify.domain.models.DomainVerificationPkgState;
import com.android.server.pm.verify.domain.models.DomainVerificationStateMap;
import com.android.server.pm.verify.domain.models.DomainVerificationUserState;
import com.android.server.pm.parsing.pkg.AndroidPackage;
import java.util.Arrays;
import java.util.Objects;
import java.util.Set;
import java.util.function.Function;
@SuppressWarnings("PointlessBooleanExpression")
public class DomainVerificationDebug {
// Disable to turn off all logging. This is used to allow a "basic" set of debug flags to be
// enabled and checked in, without having everything be on or off.
public static final boolean DEBUG_ANY = false;
// Enable to turn on all logging. Requires enabling DEBUG_ANY.
public static final boolean DEBUG_ALL = false;
public static final boolean DEBUG_APPROVAL = DEBUG_ANY && (DEBUG_ALL || true);
public static final boolean DEBUG_BROADCASTS = DEBUG_ANY && (DEBUG_ALL || false);
public static final boolean DEBUG_PROXIES = DEBUG_ANY && (DEBUG_ALL || false);
@NonNull
private final DomainVerificationCollector mCollector;
@@ -50,7 +65,7 @@ public class DomainVerificationDebug {
public void printState(@NonNull IndentingPrintWriter writer, @Nullable String packageName,
@Nullable @UserIdInt Integer userId,
@NonNull DomainVerificationService.Connection connection,
@NonNull Function<String, PackageSetting> pkgSettingFunction,
@NonNull DomainVerificationStateMap<DomainVerificationPkgState> stateMap)
throws NameNotFoundException {
ArrayMap<String, Integer> reusedMap = new ArrayMap<>();
@@ -61,7 +76,7 @@ public class DomainVerificationDebug {
for (int index = 0; index < size; index++) {
DomainVerificationPkgState pkgState = stateMap.valueAt(index);
String pkgName = pkgState.getPackageName();
PackageSetting pkgSetting = connection.getPackageSettingLocked(pkgName);
PackageSetting pkgSetting = pkgSettingFunction.apply(pkgName);
if (pkgSetting == null || pkgSetting.getPkg() == null) {
continue;
}
@@ -77,7 +92,7 @@ public class DomainVerificationDebug {
throw DomainVerificationUtils.throwPackageUnavailable(packageName);
}
PackageSetting pkgSetting = connection.getPackageSettingLocked(packageName);
PackageSetting pkgSetting = pkgSettingFunction.apply(packageName);
if (pkgSetting == null || pkgSetting.getPkg() == null) {
throw DomainVerificationUtils.throwPackageUnavailable(packageName);
}

View File

@@ -32,15 +32,16 @@ import android.util.TypedXmlPullParser;
import android.util.TypedXmlSerializer;
import com.android.server.pm.PackageSetting;
import com.android.server.pm.parsing.pkg.AndroidPackage;
import com.android.server.pm.verify.domain.models.DomainVerificationPkgState;
import com.android.server.pm.verify.domain.proxy.DomainVerificationProxy;
import com.android.server.pm.parsing.pkg.AndroidPackage;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.util.Set;
import java.util.UUID;
import java.util.function.Function;
public interface DomainVerificationManagerInternal extends DomainVerificationManager {
@@ -191,12 +192,21 @@ public interface DomainVerificationManagerInternal extends DomainVerificationMan
/**
* Print the verification state and user selection state of a package.
*
* @param packageName the package whose state to change, or all packages if none is specified
* @param userId the specific user to print, or null to skip printing user selection
* states, supports {@link android.os.UserHandle#USER_ALL}
* @param packageName the package whose state to change, or all packages if none is
* specified
* @param userId the specific user to print, or null to skip printing user selection
* states, supports {@link android.os.UserHandle#USER_ALL}
* @param pkgSettingFunction the method by which to retrieve package data; if this is called
* from {@link com.android.server.pm.PackageManagerService}, it is
* expected to pass in the snapshot of {@link PackageSetting} objects,
* or if null is passed, the manager may decide to lock {@link
* com.android.server.pm.PackageManagerService} through {@link
* Connection#getPackageSettingLocked(String)}
*/
void printState(@NonNull IndentingPrintWriter writer, @Nullable String packageName,
@Nullable @UserIdInt Integer userId) throws NameNotFoundException;
@Nullable @UserIdInt Integer userId,
@Nullable Function<String, PackageSetting> pkgSettingFunction)
throws NameNotFoundException;
@NonNull
DomainVerificationShell getShell();
@@ -225,7 +235,7 @@ public interface DomainVerificationManagerInternal extends DomainVerificationMan
throws IllegalArgumentException, NameNotFoundException;
interface Connection {
interface Connection extends Function<String, PackageSetting> {
/**
* Notify that a settings change has been made and that eventually
@@ -249,10 +259,19 @@ public interface DomainVerificationManagerInternal extends DomainVerificationMan
*/
void schedule(int code, @Nullable Object object);
// TODO(b/178733426): Make DomainVerificationService PMS snapshot aware so it can avoid
// locking package state at all. This can be as simple as removing this method in favor of
// accepting a PackageSetting function in at every method call, although should probably
// be abstracted to a wrapper class.
@Nullable
PackageSetting getPackageSettingLocked(@NonNull String pkgName);
@Nullable
AndroidPackage getPackageLocked(@NonNull String pkgName);
@Override
default PackageSetting apply(@NonNull String pkgName) {
return getPackageSettingLocked(pkgName);
}
}
}

View File

@@ -64,13 +64,14 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.function.Function;
public class DomainVerificationService extends SystemService
implements DomainVerificationManagerInternal, DomainVerificationShell.Callback {
private static final String TAG = "DomainVerificationService";
public static final boolean DEBUG_APPROVAL = true;
public static final boolean DEBUG_APPROVAL = DomainVerificationDebug.DEBUG_APPROVAL;
/**
* The new user preference API for verifying domains marked autoVerify=true in
@@ -890,9 +891,24 @@ public class DomainVerificationService extends SystemService
@Override
public void printState(@NonNull IndentingPrintWriter writer, @Nullable String packageName,
@Nullable @UserIdInt Integer userId) throws NameNotFoundException {
@Nullable Integer userId) throws NameNotFoundException {
// This method is only used by DomainVerificationShell, which doesn't lock PMS, so it's
// safe to pass mConnection directly here and lock PMS. This method is not exposed
// to the general system server/PMS.
printState(writer, packageName, userId, mConnection);
}
@Override
public void printState(@NonNull IndentingPrintWriter writer, @Nullable String packageName,
@Nullable @UserIdInt Integer userId,
@Nullable Function<String, PackageSetting> pkgSettingFunction)
throws NameNotFoundException {
if (pkgSettingFunction == null) {
pkgSettingFunction = mConnection;
}
synchronized (mLock) {
mDebug.printState(writer, packageName, userId, mConnection, mAttachedPkgStates);
mDebug.printState(writer, packageName, userId, pkgSettingFunction, mAttachedPkgStates);
}
}

View File

@@ -23,9 +23,10 @@ import android.content.Context;
import android.util.Slog;
import com.android.server.DeviceIdleInternal;
import com.android.server.pm.verify.domain.DomainVerificationMessageCodes;
import com.android.server.pm.verify.domain.DomainVerificationCollector;
import com.android.server.pm.verify.domain.DomainVerificationDebug;
import com.android.server.pm.verify.domain.DomainVerificationManagerInternal;
import com.android.server.pm.verify.domain.DomainVerificationMessageCodes;
import java.util.Objects;
import java.util.Set;
@@ -35,7 +36,7 @@ public interface DomainVerificationProxy {
String TAG = "DomainVerificationProxy";
boolean DEBUG_PROXIES = false;
boolean DEBUG_PROXIES = DomainVerificationDebug.DEBUG_PROXIES;
static <ConnectionType extends DomainVerificationProxyV1.Connection
& DomainVerificationProxyV2.Connection> DomainVerificationProxy makeProxy(

View File

@@ -37,10 +37,11 @@ import android.util.Pair;
import android.util.Slog;
import com.android.internal.annotations.GuardedBy;
import com.android.server.pm.parsing.pkg.AndroidPackage;
import com.android.server.pm.verify.domain.DomainVerificationCollector;
import com.android.server.pm.verify.domain.DomainVerificationDebug;
import com.android.server.pm.verify.domain.DomainVerificationManagerInternal;
import com.android.server.pm.verify.domain.DomainVerificationMessageCodes;
import com.android.server.pm.parsing.pkg.AndroidPackage;
import java.util.Collections;
import java.util.List;
@@ -52,7 +53,7 @@ public class DomainVerificationProxyV1 implements DomainVerificationProxy {
private static final String TAG = "DomainVerificationProxyV1";
private static final boolean DEBUG_BROADCASTS = false;
private static final boolean DEBUG_BROADCASTS = DomainVerificationDebug.DEBUG_BROADCASTS;
@NonNull
private final Context mContext;

View File

@@ -28,6 +28,7 @@ import android.os.Process;
import android.os.UserHandle;
import android.util.Slog;
import com.android.server.pm.verify.domain.DomainVerificationDebug;
import com.android.server.pm.verify.domain.DomainVerificationMessageCodes;
import java.util.Set;
@@ -36,7 +37,7 @@ public class DomainVerificationProxyV2 implements DomainVerificationProxy {
private static final String TAG = "DomainVerificationProxyV2";
private static final boolean DEBUG_BROADCASTS = true;
private static final boolean DEBUG_BROADCASTS = DomainVerificationDebug.DEBUG_BROADCASTS;
@NonNull
private final Context mContext;