Merge changes from topic "192281479-scdev" into sc-dev
* changes: Revert "Only update cache for new user on user create" Revert "Fixes incorrect array type comparison"
This commit is contained in:
committed by
Android (Google) Code Review
commit
c25d45b025
@@ -17,8 +17,6 @@
|
|||||||
package com.android.server.pm;
|
package com.android.server.pm;
|
||||||
|
|
||||||
import static android.os.Trace.TRACE_TAG_PACKAGE_MANAGER;
|
import static android.os.Trace.TRACE_TAG_PACKAGE_MANAGER;
|
||||||
import static android.os.UserHandle.USER_ALL;
|
|
||||||
import static android.os.UserHandle.USER_NULL;
|
|
||||||
import static android.provider.DeviceConfig.NAMESPACE_PACKAGE_MANAGER_SERVICE;
|
import static android.provider.DeviceConfig.NAMESPACE_PACKAGE_MANAGER_SERVICE;
|
||||||
|
|
||||||
import static com.android.internal.annotations.VisibleForTesting.Visibility.PRIVATE;
|
import static com.android.internal.annotations.VisibleForTesting.Visibility.PRIVATE;
|
||||||
@@ -687,7 +685,7 @@ public class AppsFilter implements Watchable, Snappable {
|
|||||||
synchronized (mCacheLock) {
|
synchronized (mCacheLock) {
|
||||||
if (mShouldFilterCache != null) {
|
if (mShouldFilterCache != null) {
|
||||||
updateShouldFilterCacheForPackage(mShouldFilterCache, null, newPkgSetting,
|
updateShouldFilterCacheForPackage(mShouldFilterCache, null, newPkgSetting,
|
||||||
settings, users, USER_ALL, settings.size());
|
settings, users, settings.size());
|
||||||
if (additionalChangedPackages != null) {
|
if (additionalChangedPackages != null) {
|
||||||
for (int index = 0; index < additionalChangedPackages.size(); index++) {
|
for (int index = 0; index < additionalChangedPackages.size(); index++) {
|
||||||
String changedPackage = additionalChangedPackages.valueAt(index);
|
String changedPackage = additionalChangedPackages.valueAt(index);
|
||||||
@@ -700,8 +698,7 @@ public class AppsFilter implements Watchable, Snappable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateShouldFilterCacheForPackage(mShouldFilterCache, null,
|
updateShouldFilterCacheForPackage(mShouldFilterCache, null,
|
||||||
changedPkgSetting, settings, users, USER_ALL,
|
changedPkgSetting, settings, users, settings.size());
|
||||||
settings.size());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // else, rebuild entire cache when system is ready
|
} // else, rebuild entire cache when system is ready
|
||||||
@@ -833,57 +830,24 @@ public class AppsFilter implements Watchable, Snappable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void updateEntireShouldFilterCache() {
|
|
||||||
updateEntireShouldFilterCache(USER_ALL);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateEntireShouldFilterCache(int subjectUserId) {
|
private void updateEntireShouldFilterCache() {
|
||||||
mStateProvider.runWithState((settings, users) -> {
|
mStateProvider.runWithState((settings, users) -> {
|
||||||
int userId = USER_NULL;
|
|
||||||
for (int u = 0; u < users.length; u++) {
|
|
||||||
if (subjectUserId == users[u].id) {
|
|
||||||
userId = subjectUserId;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (userId == USER_NULL) {
|
|
||||||
Slog.e(TAG, "We encountered a new user that isn't a member of known users, "
|
|
||||||
+ "updating the whole cache");
|
|
||||||
userId = USER_ALL;
|
|
||||||
}
|
|
||||||
WatchedSparseBooleanMatrix cache =
|
WatchedSparseBooleanMatrix cache =
|
||||||
updateEntireShouldFilterCacheInner(settings, users, userId);
|
updateEntireShouldFilterCacheInner(settings, users);
|
||||||
synchronized (mCacheLock) {
|
synchronized (mCacheLock) {
|
||||||
if (userId != USER_ALL) {
|
|
||||||
// if we're only updating a single user id, we need to copy over the prior
|
|
||||||
// cached values for the other users.
|
|
||||||
int[] uids = mShouldFilterCache.keys();
|
|
||||||
for (int i = 0; i < uids.length; i++) {
|
|
||||||
int uid1 = uids[i];
|
|
||||||
if (UserHandle.getUserId(uid1) == userId) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
for (int j = 0; j < uids.length; j++) {
|
|
||||||
int uid2 = uids[j];
|
|
||||||
if (UserHandle.getUserId(uid2) == userId) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
cache.put(uid1, uid2, mShouldFilterCache.get(uid1, uid2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mShouldFilterCache = cache;
|
mShouldFilterCache = cache;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private WatchedSparseBooleanMatrix updateEntireShouldFilterCacheInner(
|
private WatchedSparseBooleanMatrix updateEntireShouldFilterCacheInner(
|
||||||
ArrayMap<String, PackageSetting> settings, UserInfo[] users, int subjectUserId) {
|
ArrayMap<String, PackageSetting> settings, UserInfo[] users) {
|
||||||
WatchedSparseBooleanMatrix cache =
|
WatchedSparseBooleanMatrix cache =
|
||||||
new WatchedSparseBooleanMatrix(users.length * settings.size());
|
new WatchedSparseBooleanMatrix(users.length * settings.size());
|
||||||
for (int i = settings.size() - 1; i >= 0; i--) {
|
for (int i = settings.size() - 1; i >= 0; i--) {
|
||||||
updateShouldFilterCacheForPackage(cache,
|
updateShouldFilterCacheForPackage(cache,
|
||||||
null /*skipPackage*/, settings.valueAt(i), settings, users, subjectUserId, i);
|
null /*skipPackage*/, settings.valueAt(i), settings, users, i);
|
||||||
}
|
}
|
||||||
return cache;
|
return cache;
|
||||||
}
|
}
|
||||||
@@ -904,8 +868,8 @@ public class AppsFilter implements Watchable, Snappable {
|
|||||||
packagesCache.put(settings.keyAt(i), pkg);
|
packagesCache.put(settings.keyAt(i), pkg);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
WatchedSparseBooleanMatrix cache = updateEntireShouldFilterCacheInner(
|
WatchedSparseBooleanMatrix cache =
|
||||||
settingsCopy, usersRef[0], USER_ALL);
|
updateEntireShouldFilterCacheInner(settingsCopy, usersRef[0]);
|
||||||
boolean[] changed = new boolean[1];
|
boolean[] changed = new boolean[1];
|
||||||
// We have a cache, let's make sure the world hasn't changed out from under us.
|
// We have a cache, let's make sure the world hasn't changed out from under us.
|
||||||
mStateProvider.runWithState((settings, users) -> {
|
mStateProvider.runWithState((settings, users) -> {
|
||||||
@@ -935,10 +899,10 @@ public class AppsFilter implements Watchable, Snappable {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onUserCreated(int newUserId) {
|
public void onUsersChanged() {
|
||||||
synchronized (mCacheLock) {
|
synchronized (mCacheLock) {
|
||||||
if (mShouldFilterCache != null) {
|
if (mShouldFilterCache != null) {
|
||||||
updateEntireShouldFilterCache(newUserId);
|
updateEntireShouldFilterCache();
|
||||||
onChanged();
|
onChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -949,7 +913,7 @@ public class AppsFilter implements Watchable, Snappable {
|
|||||||
if (mShouldFilterCache != null) {
|
if (mShouldFilterCache != null) {
|
||||||
mStateProvider.runWithState((settings, users) -> {
|
mStateProvider.runWithState((settings, users) -> {
|
||||||
updateShouldFilterCacheForPackage(mShouldFilterCache, null /* skipPackage */,
|
updateShouldFilterCacheForPackage(mShouldFilterCache, null /* skipPackage */,
|
||||||
settings.get(packageName), settings, users, USER_ALL,
|
settings.get(packageName), settings, users,
|
||||||
settings.size() /*maxIndex*/);
|
settings.size() /*maxIndex*/);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -958,7 +922,7 @@ public class AppsFilter implements Watchable, Snappable {
|
|||||||
|
|
||||||
private void updateShouldFilterCacheForPackage(WatchedSparseBooleanMatrix cache,
|
private void updateShouldFilterCacheForPackage(WatchedSparseBooleanMatrix cache,
|
||||||
@Nullable String skipPackageName, PackageSetting subjectSetting, ArrayMap<String,
|
@Nullable String skipPackageName, PackageSetting subjectSetting, ArrayMap<String,
|
||||||
PackageSetting> allSettings, UserInfo[] allUsers, int subjectUserId, int maxIndex) {
|
PackageSetting> allSettings, UserInfo[] allUsers, int maxIndex) {
|
||||||
for (int i = Math.min(maxIndex, allSettings.size() - 1); i >= 0; i--) {
|
for (int i = Math.min(maxIndex, allSettings.size() - 1); i >= 0; i--) {
|
||||||
PackageSetting otherSetting = allSettings.valueAt(i);
|
PackageSetting otherSetting = allSettings.valueAt(i);
|
||||||
if (subjectSetting.appId == otherSetting.appId) {
|
if (subjectSetting.appId == otherSetting.appId) {
|
||||||
@@ -968,34 +932,25 @@ public class AppsFilter implements Watchable, Snappable {
|
|||||||
if (subjectSetting.name == skipPackageName || otherSetting.name == skipPackageName) {
|
if (subjectSetting.name == skipPackageName || otherSetting.name == skipPackageName) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (subjectUserId == USER_ALL) {
|
final int userCount = allUsers.length;
|
||||||
for (int su = 0; su < allUsers.length; su++) {
|
final int appxUidCount = userCount * allSettings.size();
|
||||||
updateShouldFilterCacheForUser(cache, subjectSetting, allUsers, otherSetting,
|
for (int su = 0; su < userCount; su++) {
|
||||||
allUsers[su].id);
|
int subjectUser = allUsers[su].id;
|
||||||
|
for (int ou = 0; ou < userCount; ou++) {
|
||||||
|
int otherUser = allUsers[ou].id;
|
||||||
|
int subjectUid = UserHandle.getUid(subjectUser, subjectSetting.appId);
|
||||||
|
int otherUid = UserHandle.getUid(otherUser, otherSetting.appId);
|
||||||
|
cache.put(subjectUid, otherUid,
|
||||||
|
shouldFilterApplicationInternal(
|
||||||
|
subjectUid, subjectSetting, otherSetting, otherUser));
|
||||||
|
cache.put(otherUid, subjectUid,
|
||||||
|
shouldFilterApplicationInternal(
|
||||||
|
otherUid, otherSetting, subjectSetting, subjectUser));
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
updateShouldFilterCacheForUser(cache, subjectSetting, allUsers, otherSetting,
|
|
||||||
subjectUserId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateShouldFilterCacheForUser(WatchedSparseBooleanMatrix cache,
|
|
||||||
PackageSetting subjectSetting, UserInfo[] allUsers, PackageSetting otherSetting,
|
|
||||||
int subjectUserId) {
|
|
||||||
for (int ou = 0; ou < allUsers.length; ou++) {
|
|
||||||
int otherUser = allUsers[ou].id;
|
|
||||||
int subjectUid = UserHandle.getUid(subjectUserId, subjectSetting.appId);
|
|
||||||
int otherUid = UserHandle.getUid(otherUser, otherSetting.appId);
|
|
||||||
cache.put(subjectUid, otherUid,
|
|
||||||
shouldFilterApplicationInternal(
|
|
||||||
subjectUid, subjectSetting, otherSetting, otherUser));
|
|
||||||
cache.put(otherUid, subjectUid,
|
|
||||||
shouldFilterApplicationInternal(
|
|
||||||
otherUid, otherSetting, subjectSetting, subjectUserId));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isSystemSigned(@NonNull PackageParser.SigningDetails sysSigningDetails,
|
private static boolean isSystemSigned(@NonNull PackageParser.SigningDetails sysSigningDetails,
|
||||||
PackageSetting pkgSetting) {
|
PackageSetting pkgSetting) {
|
||||||
return pkgSetting.isSystem()
|
return pkgSetting.isSystem()
|
||||||
@@ -1190,7 +1145,7 @@ public class AppsFilter implements Watchable, Snappable {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
updateShouldFilterCacheForPackage(mShouldFilterCache, setting.name,
|
updateShouldFilterCacheForPackage(mShouldFilterCache, setting.name,
|
||||||
siblingSetting, settings, users, USER_ALL, settings.size());
|
siblingSetting, settings, users, settings.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1207,7 +1162,7 @@ public class AppsFilter implements Watchable, Snappable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateShouldFilterCacheForPackage(mShouldFilterCache, null,
|
updateShouldFilterCacheForPackage(mShouldFilterCache, null,
|
||||||
changedPkgSetting, settings, users, USER_ALL, settings.size());
|
changedPkgSetting, settings, users, settings.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26504,7 +26504,7 @@ public class PackageManagerService extends IPackageManager.Stub
|
|||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
scheduleWritePackageRestrictionsLocked(userId);
|
scheduleWritePackageRestrictionsLocked(userId);
|
||||||
scheduleWritePackageListLocked(userId);
|
scheduleWritePackageListLocked(userId);
|
||||||
mAppsFilter.onUserCreated(userId);
|
mAppsFilter.onUsersChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -83,17 +83,9 @@ public class AppsFilterTest {
|
|||||||
private static final int DUMMY_OVERLAY_APPID = 10756;
|
private static final int DUMMY_OVERLAY_APPID = 10756;
|
||||||
private static final int SYSTEM_USER = 0;
|
private static final int SYSTEM_USER = 0;
|
||||||
private static final int SECONDARY_USER = 10;
|
private static final int SECONDARY_USER = 10;
|
||||||
private static final int ADDED_USER = 11;
|
|
||||||
private static final int[] USER_ARRAY = {SYSTEM_USER, SECONDARY_USER};
|
private static final int[] USER_ARRAY = {SYSTEM_USER, SECONDARY_USER};
|
||||||
private static final int[] USER_ARRAY_WITH_ADDED = {SYSTEM_USER, SECONDARY_USER, ADDED_USER};
|
private static final UserInfo[] USER_INFO_LIST = Arrays.stream(USER_ARRAY).mapToObj(
|
||||||
private static final UserInfo[] USER_INFO_LIST = toUserInfos(USER_ARRAY);
|
id -> new UserInfo(id, Integer.toString(id), 0)).toArray(UserInfo[]::new);
|
||||||
private static final UserInfo[] USER_INFO_LIST_WITH_ADDED = toUserInfos(USER_ARRAY_WITH_ADDED);
|
|
||||||
|
|
||||||
private static UserInfo[] toUserInfos(int[] userIds) {
|
|
||||||
return Arrays.stream(userIds)
|
|
||||||
.mapToObj(id -> new UserInfo(id, Integer.toString(id), 0))
|
|
||||||
.toArray(UserInfo[]::new);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
AppsFilter.FeatureConfig mFeatureConfigMock;
|
AppsFilter.FeatureConfig mFeatureConfigMock;
|
||||||
@@ -326,47 +318,6 @@ public class AppsFilterTest {
|
|||||||
watcher.verifyNoChangeReported("shouldFilterApplication");
|
watcher.verifyNoChangeReported("shouldFilterApplication");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testOnUserCreated_FilterMatches() throws Exception {
|
|
||||||
final AppsFilter appsFilter =
|
|
||||||
new AppsFilter(mStateProvider, mFeatureConfigMock, new String[]{}, false, null,
|
|
||||||
mMockExecutor);
|
|
||||||
simulateAddBasicAndroid(appsFilter);
|
|
||||||
|
|
||||||
appsFilter.onSystemReady();
|
|
||||||
|
|
||||||
PackageSetting target = simulateAddPackage(appsFilter,
|
|
||||||
pkgWithProvider("com.some.package", "com.some.authority"), DUMMY_TARGET_APPID);
|
|
||||||
PackageSetting calling = simulateAddPackage(appsFilter,
|
|
||||||
pkgQueriesProvider("com.some.other.package", "com.some.authority"),
|
|
||||||
DUMMY_CALLING_APPID);
|
|
||||||
|
|
||||||
for (int subjectUserId : USER_ARRAY) {
|
|
||||||
for (int otherUserId : USER_ARRAY) {
|
|
||||||
assertFalse(appsFilter.shouldFilterApplication(
|
|
||||||
UserHandle.getUid(DUMMY_CALLING_APPID, subjectUserId), calling, target,
|
|
||||||
otherUserId));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// adds new user
|
|
||||||
doAnswer(invocation -> {
|
|
||||||
((AppsFilter.StateProvider.CurrentStateCallback) invocation.getArgument(0))
|
|
||||||
.currentState(mExisting, USER_INFO_LIST_WITH_ADDED);
|
|
||||||
return new Object();
|
|
||||||
}).when(mStateProvider)
|
|
||||||
.runWithState(any(AppsFilter.StateProvider.CurrentStateCallback.class));
|
|
||||||
appsFilter.onUserCreated(ADDED_USER);
|
|
||||||
|
|
||||||
for (int subjectUserId : USER_ARRAY_WITH_ADDED) {
|
|
||||||
for (int otherUserId : USER_ARRAY_WITH_ADDED) {
|
|
||||||
assertFalse(appsFilter.shouldFilterApplication(
|
|
||||||
UserHandle.getUid(DUMMY_CALLING_APPID, subjectUserId), calling, target,
|
|
||||||
otherUserId));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testQueriesDifferentProvider_Filters() throws Exception {
|
public void testQueriesDifferentProvider_Filters() throws Exception {
|
||||||
final AppsFilter appsFilter =
|
final AppsFilter appsFilter =
|
||||||
|
|||||||
Reference in New Issue
Block a user