Merge "Remove settings tasks on private space deletion" into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
2dc4310630
@@ -63,8 +63,9 @@ public class PrivateSpaceMaintainer {
|
||||
@GuardedBy("this")
|
||||
private UserHandle mUserHandle;
|
||||
private final KeyguardManager mKeyguardManager;
|
||||
/** This variable should be accessed via {@link #getBroadcastReceiver()} only. */
|
||||
@Nullable private ProfileAvailabilityBroadcastReceiver mProfileAvailabilityBroadcastReceiver;
|
||||
/** This variable should be accessed via {@link #getProfileBroadcastReceiver()} only. */
|
||||
@Nullable
|
||||
private ProfileBroadcastReceiver mProfileBroadcastReceiver;
|
||||
|
||||
/** This is the default value for the hide private space entry point settings. */
|
||||
public static final int HIDE_PRIVATE_SPACE_ENTRY_POINT_DISABLED_VAL = 0;
|
||||
@@ -150,7 +151,6 @@ public class PrivateSpaceMaintainer {
|
||||
Log.i(TAG, "Deleting Private space with id: " + mUserHandle.getIdentifier());
|
||||
if (mUserManager.removeUser(mUserHandle)) {
|
||||
Log.i(TAG, "Private space deleted");
|
||||
unregisterBroadcastReceiver();
|
||||
mUserHandle = null;
|
||||
|
||||
return ErrorDeletingPrivateSpace.DELETE_PS_ERROR_NONE;
|
||||
@@ -394,13 +394,15 @@ public class PrivateSpaceMaintainer {
|
||||
&& android.multiuser.Flags.enablePrivateSpaceFeatures();
|
||||
}
|
||||
|
||||
/** {@link BroadcastReceiver} which handles the private profile's availability related
|
||||
* broadcasts.
|
||||
/**
|
||||
* {@link BroadcastReceiver} which handles the private profile's availability and deletion
|
||||
* related broadcasts.
|
||||
*/
|
||||
private final class ProfileAvailabilityBroadcastReceiver extends BroadcastReceiver {
|
||||
private final class ProfileBroadcastReceiver extends BroadcastReceiver {
|
||||
void register() {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(Intent.ACTION_PROFILE_UNAVAILABLE);
|
||||
filter.addAction(Intent.ACTION_PROFILE_REMOVED);
|
||||
mContext.registerReceiver(/* receiver= */ this, filter, Context.RECEIVER_NOT_EXPORTED);
|
||||
}
|
||||
|
||||
@@ -412,6 +414,13 @@ public class PrivateSpaceMaintainer {
|
||||
@Override
|
||||
public void onReceive(@NonNull Context context, @NonNull Intent intent) {
|
||||
UserHandle userHandle = intent.getParcelableExtra(Intent.EXTRA_USER, UserHandle.class);
|
||||
if (intent.getAction().equals(Intent.ACTION_PROFILE_REMOVED)) {
|
||||
// This applies to all profiles getting removed, since there is no way to tell if
|
||||
// it is a private profile that got removed.
|
||||
removeSettingsAllTasks();
|
||||
unregisterBroadcastReceiver();
|
||||
return;
|
||||
}
|
||||
if (!userHandle.equals(getPrivateProfileHandle())) {
|
||||
Log.d(TAG, "Ignoring intent for non-private profile with user id "
|
||||
+ userHandle.getIdentifier());
|
||||
@@ -428,7 +437,7 @@ public class PrivateSpaceMaintainer {
|
||||
|| !android.multiuser.Flags.enablePrivateSpaceFeatures()) {
|
||||
return;
|
||||
}
|
||||
var broadcastReceiver = getBroadcastReceiver();
|
||||
var broadcastReceiver = getProfileBroadcastReceiver();
|
||||
if (broadcastReceiver == null) {
|
||||
return;
|
||||
}
|
||||
@@ -440,17 +449,18 @@ public class PrivateSpaceMaintainer {
|
||||
|| !android.multiuser.Flags.enablePrivateSpaceFeatures()) {
|
||||
return;
|
||||
}
|
||||
if (mProfileAvailabilityBroadcastReceiver == null) {
|
||||
if (mProfileBroadcastReceiver == null) {
|
||||
Log.w(TAG, "Requested to unregister when there is no receiver.");
|
||||
return;
|
||||
}
|
||||
mProfileAvailabilityBroadcastReceiver.unregister();
|
||||
mProfileAvailabilityBroadcastReceiver = null;
|
||||
mProfileBroadcastReceiver.unregister();
|
||||
mProfileBroadcastReceiver = null;
|
||||
}
|
||||
|
||||
/** Always use this getter to access {@link #mProfileAvailabilityBroadcastReceiver}. */
|
||||
/** Always use this getter to access {@link #mProfileBroadcastReceiver}. */
|
||||
@VisibleForTesting
|
||||
@Nullable synchronized ProfileAvailabilityBroadcastReceiver getBroadcastReceiver() {
|
||||
@Nullable
|
||||
synchronized ProfileBroadcastReceiver getProfileBroadcastReceiver() {
|
||||
if (!android.os.Flags.allowPrivateProfile()
|
||||
|| !android.multiuser.Flags.enablePrivateSpaceFeatures()) {
|
||||
return null;
|
||||
@@ -459,16 +469,16 @@ public class PrivateSpaceMaintainer {
|
||||
Log.e(TAG, "Cannot return a broadcast receiver when private space doesn't exist");
|
||||
return null;
|
||||
}
|
||||
if (mProfileAvailabilityBroadcastReceiver == null) {
|
||||
mProfileAvailabilityBroadcastReceiver = new ProfileAvailabilityBroadcastReceiver();
|
||||
if (mProfileBroadcastReceiver == null) {
|
||||
mProfileBroadcastReceiver = new ProfileBroadcastReceiver();
|
||||
}
|
||||
return mProfileAvailabilityBroadcastReceiver;
|
||||
return mProfileBroadcastReceiver;
|
||||
}
|
||||
|
||||
/** This is purely for testing purpose only, and should not be used elsewhere. */
|
||||
@VisibleForTesting
|
||||
synchronized void resetBroadcastReceiver() {
|
||||
mProfileAvailabilityBroadcastReceiver = null;
|
||||
mProfileBroadcastReceiver = null;
|
||||
}
|
||||
|
||||
private void removeSettingsAllTasks() {
|
||||
|
@@ -215,7 +215,7 @@ public class PrivateSpaceMaintainerTest {
|
||||
privateSpaceMaintainer.deletePrivateSpace();
|
||||
privateSpaceMaintainer.createPrivateSpace();
|
||||
// test that no exception is thrown, which would indicate that the receiver was registered.
|
||||
mContext.unregisterReceiver(privateSpaceMaintainer.getBroadcastReceiver());
|
||||
mContext.unregisterReceiver(privateSpaceMaintainer.getProfileBroadcastReceiver());
|
||||
privateSpaceMaintainer.resetBroadcastReceiver();
|
||||
}
|
||||
|
||||
@@ -227,7 +227,7 @@ public class PrivateSpaceMaintainerTest {
|
||||
PrivateSpaceMaintainer.getInstance(mContext);
|
||||
privateSpaceMaintainer.createPrivateSpace();
|
||||
privateSpaceMaintainer.deletePrivateSpace();
|
||||
assertThat(privateSpaceMaintainer.getBroadcastReceiver()).isNull();
|
||||
assertThat(privateSpaceMaintainer.getProfileBroadcastReceiver()).isNull();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user