Handle Quiet Mode for Work Profile gracefully when Pixel Launcher is not default.
Bug: 364759351 Change-Id: I997af16e2756ddfdd964916cce4ac98e39b86917 Test: Manual Flag: NONE Bug fix tweak.
This commit is contained in:
1 parent
f567652348
commit
45fe132a48
3 files changed
+18
-23
No files matched your search
@@ -18,6 +18,7 @@ package com.android.launcher3.allapps;
|
||||
|
||||
import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
|
||||
@@ -26,6 +27,7 @@ import androidx.annotation.IntDef;
|
||||
import com.android.launcher3.logging.StatsLogManager;
|
||||
import com.android.launcher3.model.data.ItemInfo;
|
||||
import com.android.launcher3.pm.UserCache;
|
||||
import com.android.launcher3.util.ApiWrapper;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
@@ -69,14 +71,26 @@ public abstract class UserProfileManager {
|
||||
}
|
||||
|
||||
/** Sets quiet mode as enabled/disabled for the profile type. */
|
||||
protected void setQuietMode(boolean enabled) {
|
||||
protected void setQuietMode(boolean enabled, Context context) {
|
||||
UI_HELPER_EXECUTOR.post(() ->
|
||||
mUserCache.getUserProfiles()
|
||||
.stream()
|
||||
.filter(getUserMatcher())
|
||||
.findFirst()
|
||||
.ifPresent(userHandle ->
|
||||
mUserManager.requestQuietModeEnabled(enabled, userHandle)));
|
||||
setQuietModeSafely(enabled, userHandle, context)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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, Context context) {
|
||||
try {
|
||||
mUserManager.requestQuietModeEnabled(enable, userHandle);
|
||||
} catch (SecurityException ex) {
|
||||
ApiWrapper.INSTANCE.get(context).assignDefaultHomeRole(context);
|
||||
}
|
||||
}
|
||||
|
||||
/** Sets current state for the profile type. */
|
||||
|
||||
Reference in new issue
Block a user