Merge "Receive user added/removed intents from PermissionMonitor"

This commit is contained in:
Paul Hu 2022-11-07 04:58:44 +00:00 • committed by Gerrit Code Review
commit 38f2832f8a
2 changed files with 28 additions and 4 deletions

View file

@ -6101,14 +6101,12 @@ public class ConnectivityService extends IConnectivityManager.Stub
}
private void onUserAdded(@NonNull final UserHandle user) {
mPermissionMonitor.onUserAdded(user);
if (mOemNetworkPreferences.getNetworkPreferences().size() > 0) {
handleSetOemNetworkPreference(mOemNetworkPreferences, null);
}
}
private void onUserRemoved(@NonNull final UserHandle user) {
mPermissionMonitor.onUserRemoved(user);
// If there was a network preference for this user, remove it.
handleSetProfileNetworkPreference(
List.of(new ProfileNetworkPreferenceList.Preference(user, null, true)),

View file

@ -175,6 +175,22 @@ public class PermissionMonitor {
final String[] pkgList =
intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
onExternalApplicationsAvailable(pkgList);
} else if (Intent.ACTION_USER_ADDED.equals(action)) {
final UserHandle user = intent.getParcelableExtra(Intent.EXTRA_USER);
// User should be filled for below intents, check the existence.
if (user == null) {
Log.wtf(TAG, action + " broadcast without EXTRA_USER");
return;
}
onUserAdded(user);
} else if (Intent.ACTION_USER_REMOVED.equals(action)) {
final UserHandle user = intent.getParcelableExtra(Intent.EXTRA_USER);
// User should be filled for below intents, check the existence.
if (user == null) {
Log.wtf(TAG, action + " broadcast without EXTRA_USER");
return;
}
onUserRemoved(user);
} else {
Log.wtf(TAG, "received unexpected intent: " + action);
}
@ -408,6 +424,14 @@ public class PermissionMonitor {
mIntentReceiver, externalIntentFilter, null /* broadcastPermission */,
null /* scheduler */);
// Listen for user add/remove.
final IntentFilter userIntentFilter = new IntentFilter();
userIntentFilter.addAction(Intent.ACTION_USER_ADDED);
userIntentFilter.addAction(Intent.ACTION_USER_REMOVED);
userAllContext.registerReceiver(
mIntentReceiver, userIntentFilter, null /* broadcastPermission */,
null /* scheduler */);
// Register UIDS_ALLOWED_ON_RESTRICTED_NETWORKS setting observer
mDeps.registerContentObserver(
userAllContext,
@ -547,7 +571,8 @@ public class PermissionMonitor {
*
* @hide
*/
public synchronized void onUserAdded(@NonNull UserHandle user) {
@VisibleForTesting
synchronized void onUserAdded(@NonNull UserHandle user) {
mUsers.add(user);
final List<PackageInfo> apps = getInstalledPackagesAsUser(user);
@ -578,7 +603,8 @@ public class PermissionMonitor {
*
* @hide
*/
public synchronized void onUserRemoved(@NonNull UserHandle user) {
@VisibleForTesting
synchronized void onUserRemoved(@NonNull UserHandle user) {
mUsers.remove(user);
// Remove uids network permissions that belongs to the user.