Fix domain verification shell command "all" params

Iterates the user IDs from UserManager when USER_ALL is passed, and
also adds support for "all" domains to set-app-links-user-selection.

Bug: 180753593

Test: manual, run commands with changes

Change-Id: Ib2c8886ae475ac4b6f2a0b77959bb735b4ce34f2
This commit is contained in:
Winson
2021-02-19 15:32:30 -08:00
parent db9ef8e719
commit 907ad40dae
4 changed files with 36 additions and 22 deletions

View File

@@ -1755,6 +1755,11 @@ public class PackageManagerService extends IPackageManager.Stub
public boolean filterAppAccess(String packageName, int callingUid, int userId) {
return mPmInternal.filterAppAccess(packageName, callingUid, userId);
}
@Override
public int[] getAllUserIds() {
return mUserManager.getUserIds();
}
}
/**

View File

@@ -358,5 +358,8 @@ public interface DomainVerificationManagerInternal extends DomainVerificationMan
@Nullable
AndroidPackage getPackageLocked(@NonNull String pkgName);
@UserIdInt
int[] getAllUserIds();
}
}

View File

@@ -423,12 +423,8 @@ public class DomainVerificationService extends SystemService
for (int pkgStateIndex = 0; pkgStateIndex < pkgStateSize; pkgStateIndex++) {
DomainVerificationPkgState pkgState = mAttachedPkgStates.valueAt(pkgStateIndex);
if (userId == UserHandle.USER_ALL) {
SparseArray<DomainVerificationUserState> userStates =
pkgState.getUserSelectionStates();
int userStatesSize = userStates.size();
for (int userStateIndex = 0; userStateIndex < userStatesSize;
userStateIndex++) {
userStates.valueAt(userStateIndex)
for (int aUserId : mConnection.getAllUserIds()) {
pkgState.getOrCreateUserSelectionState(aUserId)
.setLinkHandlingAllowed(allowed);
}
} else {
@@ -436,7 +432,6 @@ public class DomainVerificationService extends SystemService
.setLinkHandlingAllowed(allowed);
}
}
}
} else {
synchronized (mLock) {
@@ -500,28 +495,33 @@ public class DomainVerificationService extends SystemService
@Override
public void setDomainVerificationUserSelectionInternal(@UserIdInt int userId,
@Nullable String packageName, boolean enabled, @NonNull ArraySet<String> domains)
@Nullable String packageName, boolean enabled, @Nullable ArraySet<String> domains)
throws NameNotFoundException {
mEnforcer.assertInternal(mConnection.getCallingUid());
if (packageName == null) {
synchronized (mLock) {
Set<String> validDomains = new ArraySet<>();
int size = mAttachedPkgStates.size();
for (int index = 0; index < size; index++) {
DomainVerificationPkgState pkgState = mAttachedPkgStates.valueAt(index);
String pkgName = pkgState.getPackageName();
PackageSetting pkgSetting = mConnection.getPackageSettingLocked(pkgName);
if (pkgSetting == null || pkgSetting.getPkg() == null) {
AndroidPackage pkg = pkgSetting == null ? null : pkgSetting.getPkg();
if (pkg == null) {
continue;
}
validDomains.clear();
validDomains.addAll(domains);
if (domains == null) {
validDomains = mCollector.collectAllWebDomains(pkg);
} else {
validDomains.clear();
validDomains.addAll(domains);
}
setDomainVerificationUserSelectionInternal(userId, pkgState,
pkgSetting.getPkg(), enabled, validDomains);
pkg, enabled, validDomains);
}
}
} else {
@@ -532,12 +532,16 @@ public class DomainVerificationService extends SystemService
}
PackageSetting pkgSetting = mConnection.getPackageSettingLocked(packageName);
if (pkgSetting == null || pkgSetting.getPkg() == null) {
AndroidPackage pkg = pkgSetting == null ? null : pkgSetting.getPkg();
if (pkg == null) {
throw DomainVerificationUtils.throwPackageUnavailable(packageName);
}
Set<String> validDomains =
domains == null ? mCollector.collectAllWebDomains(pkg) : domains;
setDomainVerificationUserSelectionInternal(userId, pkgState, pkgSetting.getPkg(),
enabled, domains);
enabled, validDomains);
}
}
@@ -549,12 +553,10 @@ public class DomainVerificationService extends SystemService
boolean enabled, Set<String> domains) {
domains.retainAll(mCollector.collectAllWebDomains(pkg));
SparseArray<DomainVerificationUserState> userStates =
pkgState.getUserSelectionStates();
if (userId == UserHandle.USER_ALL) {
int size = userStates.size();
for (int index = 0; index < size; index++) {
DomainVerificationUserState userState = userStates.valueAt(index);
for (int aUserId : mConnection.getAllUserIds()) {
DomainVerificationUserState userState =
pkgState.getOrCreateUserSelectionState(aUserId);
if (enabled) {
userState.addHosts(domains);
} else {

View File

@@ -250,6 +250,10 @@ public class DomainVerificationShell {
return false;
}
if (domains.size() == 1 && domains.contains("all")) {
domains = null;
}
try {
mCallback.setDomainVerificationUserSelectionInternal(userId,
packageName, enabled, domains);
@@ -446,10 +450,10 @@ public class DomainVerificationShell {
* @param packageName the package whose state to change, or all packages if non is
* specified
* @param enabled whether the domain is now approved by the user
* @param domains the set of domains to change
* @param domains the set of domains to change, or null to affect all domains
*/
void setDomainVerificationUserSelectionInternal(@UserIdInt int userId,
@Nullable String packageName, boolean enabled, @NonNull ArraySet<String> domains)
@Nullable String packageName, boolean enabled, @Nullable ArraySet<String> domains)
throws PackageManager.NameNotFoundException;
/**