Merge "Fix VerifyingSession disabled check" into udc-dev

This commit is contained in:
Winson Chiu
2023-03-16 00:54:11 +00:00
committed by Android (Google) Code Review
4 changed files with 11 additions and 8 deletions

View File

@@ -41,6 +41,7 @@ import android.content.pm.SharedLibraryInfo;
import android.content.pm.SigningDetails; import android.content.pm.SigningDetails;
import android.content.pm.UserInfo; import android.content.pm.UserInfo;
import android.content.pm.VersionedPackage; import android.content.pm.VersionedPackage;
import android.os.UserHandle;
import android.util.ArrayMap; import android.util.ArrayMap;
import android.util.ArraySet; import android.util.ArraySet;
import android.util.Pair; import android.util.Pair;
@@ -519,14 +520,15 @@ public interface Computer extends PackageDataSnapshot {
* returns false. * returns false.
*/ */
boolean isComponentEffectivelyEnabled(@NonNull ComponentInfo componentInfo, boolean isComponentEffectivelyEnabled(@NonNull ComponentInfo componentInfo,
@UserIdInt int userId); @NonNull UserHandle userHandle);
/** /**
* @return true if the runtime app user enabled state and the install-time app manifest enabled * @return true if the runtime app user enabled state and the install-time app manifest enabled
* state are both effectively enabled for the given app. Or if the app cannot be found, * state are both effectively enabled for the given app. Or if the app cannot be found,
* returns false. * returns false.
*/ */
boolean isApplicationEffectivelyEnabled(@NonNull String packageName, @UserIdInt int userId); boolean isApplicationEffectivelyEnabled(@NonNull String packageName,
@NonNull UserHandle userHandle);
@Nullable @Nullable
KeySet getKeySetByAlias(@NonNull String packageName, @NonNull String alias); KeySet getKeySetByAlias(@NonNull String packageName, @NonNull String alias);

View File

@@ -5131,9 +5131,10 @@ public class ComputerEngine implements Computer {
@Override @Override
public boolean isComponentEffectivelyEnabled(@NonNull ComponentInfo componentInfo, public boolean isComponentEffectivelyEnabled(@NonNull ComponentInfo componentInfo,
@UserIdInt int userId) { @NonNull UserHandle userHandle) {
try { try {
String packageName = componentInfo.packageName; String packageName = componentInfo.packageName;
int userId = userHandle.getIdentifier();
int appEnabledSetting = int appEnabledSetting =
mSettings.getApplicationEnabledSetting(packageName, userId); mSettings.getApplicationEnabledSetting(packageName, userId);
if (appEnabledSetting == COMPONENT_ENABLED_STATE_DEFAULT) { if (appEnabledSetting == COMPONENT_ENABLED_STATE_DEFAULT) {
@@ -5156,9 +5157,10 @@ public class ComputerEngine implements Computer {
@Override @Override
public boolean isApplicationEffectivelyEnabled(@NonNull String packageName, public boolean isApplicationEffectivelyEnabled(@NonNull String packageName,
@UserIdInt int userId) { @NonNull UserHandle userHandle) {
try { try {
int appEnabledSetting = mSettings.getApplicationEnabledSetting(packageName, userId); int appEnabledSetting = mSettings.getApplicationEnabledSetting(packageName,
userHandle.getIdentifier());
if (appEnabledSetting == COMPONENT_ENABLED_STATE_DEFAULT) { if (appEnabledSetting == COMPONENT_ENABLED_STATE_DEFAULT) {
final AndroidPackage pkg = getPackage(packageName); final AndroidPackage pkg = getPackage(packageName);
if (pkg == null) { if (pkg == null) {

View File

@@ -2570,7 +2570,7 @@ public class PackageManagerService implements PackageSender, TestUtilityService
if (best == null || cur.priority > best.priority) { if (best == null || cur.priority > best.priority) {
if (computer.isComponentEffectivelyEnabled(cur.getComponentInfo(), if (computer.isComponentEffectivelyEnabled(cur.getComponentInfo(),
UserHandle.USER_SYSTEM)) { UserHandle.SYSTEM)) {
best = cur; best = cur;
} else { } else {
Slog.w(TAG, "Domain verification agent found but not enabled"); Slog.w(TAG, "Domain verification agent found but not enabled");

View File

@@ -26,7 +26,6 @@ import static android.content.pm.PackageManager.MATCH_DEBUG_TRIAGED_MISSING;
import static android.content.pm.SigningDetails.SignatureSchemeVersion.SIGNING_BLOCK_V4; import static android.content.pm.SigningDetails.SignatureSchemeVersion.SIGNING_BLOCK_V4;
import static android.os.PowerWhitelistManager.REASON_PACKAGE_VERIFIER; import static android.os.PowerWhitelistManager.REASON_PACKAGE_VERIFIER;
import static android.os.PowerWhitelistManager.TEMPORARY_ALLOWLIST_TYPE_FOREGROUND_SERVICE_ALLOWED; import static android.os.PowerWhitelistManager.TEMPORARY_ALLOWLIST_TYPE_FOREGROUND_SERVICE_ALLOWED;
import static android.os.Process.SYSTEM_UID;
import static android.os.Trace.TRACE_TAG_PACKAGE_MANAGER; import static android.os.Trace.TRACE_TAG_PACKAGE_MANAGER;
import static com.android.server.pm.PackageManagerService.CHECK_PENDING_INTEGRITY_VERIFICATION; import static com.android.server.pm.PackageManagerService.CHECK_PENDING_INTEGRITY_VERIFICATION;
@@ -408,7 +407,7 @@ final class VerifyingSession {
final int numRequiredVerifierPackages = requiredVerifierPackages.size(); final int numRequiredVerifierPackages = requiredVerifierPackages.size();
for (int i = numRequiredVerifierPackages - 1; i >= 0; i--) { for (int i = numRequiredVerifierPackages - 1; i >= 0; i--) {
if (!snapshot.isApplicationEffectivelyEnabled(requiredVerifierPackages.get(i), if (!snapshot.isApplicationEffectivelyEnabled(requiredVerifierPackages.get(i),
SYSTEM_UID)) { verifierUser)) {
Slog.w(TAG, Slog.w(TAG,
"Required verifier: " + requiredVerifierPackages.get(i) + " is disabled"); "Required verifier: " + requiredVerifierPackages.get(i) + " is disabled");
requiredVerifierPackages.remove(i); requiredVerifierPackages.remove(i);