Prompting the user to set Pixel/Quickstep as default Home app.

requestQuietMode API throws SecurityException in case its called
from a non-default Launcher app.
To mitigate this, we catch the exception and prompt the user
to set their default launcher to the current app.

Video(Pixel): https://photos.app.goo.gl/ni5X1c6vBbYW2JMJ9
Video(Pixel-aosp): https://photos.app.goo.gl/cYLJpTYW76Jnbonc9

Bug: 320446272
Test: Manual
Flag: NONE Bug fix tweak.
Change-Id: I6afb2ae85cabc038e1503e9c34eebd974c4f7a50
This commit is contained in:
Himanshu Gupta
2024-05-31 12:35:09 +01:00
parent 533893e898
commit 261a62219b
7 changed files with 113 additions and 7 deletions
@@ -281,10 +281,28 @@ public class PrivateProfileManager extends UserProfileManager {
@Override
public void setQuietMode(boolean enable) {
super.setQuietMode(enable);
UI_HELPER_EXECUTOR.post(() ->
mUserCache.getUserProfiles()
.stream()
.filter(getUserMatcher())
.findFirst()
.ifPresent(userHandle -> setQuietModeSafely(enable, userHandle)));
mReadyToAnimate = true;
}
/**
* Sets Quiet Mode for Private Profile.
* If {@link SecurityException} is thrown, prompts the user to set this launcher as HOME app.
*/
private void setQuietModeSafely(boolean enable, UserHandle userHandle) {
try {
mUserManager.requestQuietModeEnabled(enable, userHandle);
} catch (SecurityException ex) {
ApiWrapper.INSTANCE.get(mAllApps.mActivityContext)
.assignDefaultHomeRole(mAllApps.mActivityContext);
}
}
/**
* Expand the private space after the app list has been added and updated from
* {@link AlphabeticalAppsList#onAppsUpdated()}