Set Private Space usehandle to null if we receive ACTION_PROFILE_REMOVED for PS user
Flag: EXEMPT bugfix Bug: 376044598 Test: Manually verified on a test device Change-Id: Id7e3caed8bbe3afe301a3c29a70ba5ec77c90116
This commit is contained in:
@@ -62,6 +62,7 @@ public class PrivateSpaceMaintainer {
|
||||
private final ActivityManager mActivityManager;
|
||||
private int mErrorCode;
|
||||
@GuardedBy("this")
|
||||
@Nullable
|
||||
private UserHandle mUserHandle;
|
||||
private final KeyguardManager mKeyguardManager;
|
||||
/** This variable should be accessed via {@link #getProfileBroadcastReceiver()} only. */
|
||||
@@ -419,12 +420,16 @@ public class PrivateSpaceMaintainer {
|
||||
mContext.unregisterReceiver(/* receiver= */ this);
|
||||
}
|
||||
|
||||
@GuardedBy("PrivateSpaceMaintainer.this")
|
||||
@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.
|
||||
if (userHandle.equals(getPrivateProfileHandle())) {
|
||||
mUserHandle = null;
|
||||
}
|
||||
removeSettingsAllTasks();
|
||||
unregisterBroadcastReceiver();
|
||||
return;
|
||||
|
||||
@@ -36,9 +36,11 @@ import android.app.IActivityManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Flags;
|
||||
import android.os.RemoteException;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.provider.Settings;
|
||||
@@ -46,6 +48,7 @@ import android.provider.Settings;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.compatibility.common.util.BlockingBroadcastReceiver;
|
||||
import com.android.settings.privatespace.PrivateSpaceMaintainer.ErrorDeletingPrivateSpace;
|
||||
|
||||
import org.junit.After;
|
||||
@@ -57,6 +60,9 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class PrivateSpaceMaintainerTest {
|
||||
private static final String TAG = "PSMaintainerTest";
|
||||
@@ -506,4 +512,25 @@ public class PrivateSpaceMaintainerTest {
|
||||
/* enabled */ 1,
|
||||
privateSpaceMaintainer.getPrivateProfileHandle().getIdentifier());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void profileRemovedFromUserManager_privateSpaceNoLongerExists() {
|
||||
PrivateSpaceMaintainer privateSpaceMaintainer = PrivateSpaceMaintainer.getInstance(
|
||||
mContext);
|
||||
privateSpaceMaintainer.createPrivateSpace();
|
||||
UserHandle privateSpaceUserHandle = privateSpaceMaintainer.getPrivateProfileHandle();
|
||||
assertThat(privateSpaceMaintainer.doesPrivateSpaceExist()).isTrue();
|
||||
Intent removedIntent = new Intent(Intent.ACTION_PROFILE_REMOVED);
|
||||
assertThat(privateSpaceUserHandle).isNotNull();
|
||||
final BlockingBroadcastReceiver receiver = new BlockingBroadcastReceiver(mContext,
|
||||
removedIntent.getAction());
|
||||
receiver.register();
|
||||
|
||||
Objects.requireNonNull(mContext.getSystemService(UserManager.class)).removeUser(
|
||||
privateSpaceUserHandle);
|
||||
|
||||
receiver.awaitForBroadcast(TimeUnit.SECONDS.toMillis(10));
|
||||
assertThat(privateSpaceMaintainer.doesPrivateSpaceExist()).isFalse();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user