From a7603d2b434e2907bdb1b246bcf22298bd4f91d6 Mon Sep 17 00:00:00 2001 From: josephpv Date: Fri, 22 Mar 2024 19:25:57 +0000 Subject: [PATCH] Handle startProfile failure during creation of private space This includes to verify return value of startProfile to check if profile is started successfully. If startProfile failed for any reason then delete the created profile and return false for createPrivateProfile(). Bug: 313926659 Test: atest PrivateSpaceMaintainerTest Change-Id: I493cb3a41cef8bdc1be42fe328c4f7bd04944b94 --- .../privatespace/PrivateSpaceMaintainer.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/com/android/settings/privatespace/PrivateSpaceMaintainer.java b/src/com/android/settings/privatespace/PrivateSpaceMaintainer.java index e219c078bce..6d07305e375 100644 --- a/src/com/android/settings/privatespace/PrivateSpaceMaintainer.java +++ b/src/com/android/settings/privatespace/PrivateSpaceMaintainer.java @@ -112,11 +112,10 @@ public class PrivateSpaceMaintainer { registerBroadcastReceiver(); - try { - //TODO(b/313926659): To check and handle failure of startProfile - mActivityManager.startProfile(mUserHandle); - } catch (IllegalArgumentException e) { - Log.e(TAG, "Unexpected that " + mUserHandle.getIdentifier() + " is not a profile"); + if (!startProfile()) { + // TODO(b/333884792): Add test to mock when startProfile fails. + Log.e(TAG, "profile not started, created profile is deleted"); + deletePrivateSpace(); return false; } @@ -314,6 +313,16 @@ public class PrivateSpaceMaintainer { return false; } + @GuardedBy("this") + private boolean startProfile() { + try { + return mActivityManager.startProfile(mUserHandle); + } catch (IllegalArgumentException e) { + Log.e(TAG, "Unexpected that " + mUserHandle.getIdentifier() + " is not a profile"); + } + return false; + } + @GuardedBy("this") private void resetPrivateSpaceSettings() { setHidePrivateSpaceEntryPointSetting(HIDE_PRIVATE_SPACE_ENTRY_POINT_DISABLED_VAL);