From 42b39904f9a9ab207b72c54b8900632e104dc904 Mon Sep 17 00:00:00 2001 From: Ankit Kushwaha <97403760+AnkitK-NITB@users.noreply.github.com> Date: Tue, 3 Feb 2026 21:40:45 +0530 Subject: [PATCH] feat: Add work profile customization and fix issues (#6167) * Fix work profile unpause authentication prompt Skip credential challenge when enabling/disabling work profile by passing null Intent parameter to requestQuietModeEnabled(). This prevents password/biometric prompts for secure folders when toggling work profile state. - Use 3-parameter requestQuietModeEnabled() with null Intent on Android P+ - Fallback to 2-parameter version for older Android versions - Resolves authentication prompt issue when unpausing work profile * Fix work profile pause/unpause without authentication prompts * Fix work profile state detection on initial load Fixed bug where work profile quiet mode flag was not set correctly on initial app load when multiple user profiles exist. Changed direct assignment (=) to OR assignment (|=) to preserve quiet state across all work profiles. This ensures FLAG_WORK_PROFILE_QUIET_MODE_ENABLED is set properly both on initial load (LoaderTask) and during runtime pause/unpause events (PackageUpdatedTask). * Add work profile tab customization features - Add workProfileTabBackgroundColor preference for selected tab color - Add workProfileTabContainerBackground toggle for scroll protection - Update DrawableTokens to use custom colors from preferences - Add UI controls in App Drawer preferences - Control tab background visibility on scroll Features: 1. Custom color picker for selected work/personal tab button 2. Toggle to show/hide background protection when scrolling * Fix work profile state detection bug - Query UserManager.isQuietModeEnabled() directly for real-time state - Call updateUserQuietMode() to keep cached state synchronized - Fixes stale quiet mode state causing incorrect UI display Root cause: LoaderTask was using cached UserManagerState values that could become stale if work profile state changed between initialization and app loading. * Fix work profile unpause authentication prompt Skip credential challenge when enabling/disabling work profile by passing null Intent parameter to requestQuietModeEnabled(). This prevents password/biometric prompts for secure folders when toggling work profile state. - Use 3-parameter requestQuietModeEnabled() with null Intent on Android P+ - Fallback to 2-parameter version for older Android versions - Resolves authentication prompt issue when unpausing work profile * Fix work profile pause/unpause without authentication prompts * Fix work profile state detection on initial load Fixed bug where work profile quiet mode flag was not set correctly on initial app load when multiple user profiles exist. Changed direct assignment (=) to OR assignment (|=) to preserve quiet state across all work profiles. This ensures FLAG_WORK_PROFILE_QUIET_MODE_ENABLED is set properly both on initial load (LoaderTask) and during runtime pause/unpause events (PackageUpdatedTask). * Add work profile tab customization features - Add workProfileTabBackgroundColor preference for selected tab color - Add workProfileTabContainerBackground toggle for scroll protection - Update DrawableTokens to use custom colors from preferences - Add UI controls in App Drawer preferences - Control tab background visibility on scroll Features: 1. Custom color picker for selected work/personal tab button 2. Toggle to show/hide background protection when scrolling * Fix work profile state detection bug - Query UserManager.isQuietModeEnabled() directly for real-time state - Call updateUserQuietMode() to keep cached state synchronized - Fixes stale quiet mode state causing incorrect UI display Root cause: LoaderTask was using cached UserManagerState values that could become stale if work profile state changed between initialization and app loading. * Fix spotless formatting in DrawableTokens.kt * fix: cleanup --------- Co-authored-by: Ankit Kushwaha Co-authored-by: Pun Butrach --- lawnchair/res/values/strings.xml | 2 ++ .../preferences2/PreferenceManager2.kt | 14 ++++++++++++++ .../lawnchair/theme/drawable/DrawableTokens.kt | 17 ++++++++++++++++- .../colorpreference/ColorPreferenceModelList.kt | 7 +++++++ .../destinations/AppDrawerPreferences.kt | 7 +++++++ .../allapps/ActivityAllAppsContainerView.java | 7 ++++++- .../launcher3/allapps/WorkProfileManager.java | 17 +++++++++++------ src/com/android/launcher3/model/LoaderTask.java | 9 ++++++--- .../launcher3/model/UserManagerState.java | 9 +++++++++ 9 files changed, 78 insertions(+), 11 deletions(-) diff --git a/lawnchair/res/values/strings.xml b/lawnchair/res/values/strings.xml index 394f899a66..dda8bbf70a 100644 --- a/lawnchair/res/values/strings.xml +++ b/lawnchair/res/values/strings.xml @@ -767,6 +767,8 @@ Row height Horizontal padding Background color + Tabs background color + Separated Tab container background Hide from app drawer diff --git a/lawnchair/src/app/lawnchair/preferences2/PreferenceManager2.kt b/lawnchair/src/app/lawnchair/preferences2/PreferenceManager2.kt index adefb9bcf5..ff44b878b0 100644 --- a/lawnchair/src/app/lawnchair/preferences2/PreferenceManager2.kt +++ b/lawnchair/src/app/lawnchair/preferences2/PreferenceManager2.kt @@ -201,6 +201,20 @@ class PreferenceManager2 @Inject constructor( onSet = { reloadHelper.recreate() }, ) + val workProfileTabBackgroundColor = preference( + key = stringPreferencesKey(name = "work_profile_tab_background_color"), + parse = ColorOption::fromString, + save = ColorOption::toString, + onSet = { reloadHelper.recreate() }, + defaultValue = ColorOption.SystemAccent, + ) + + val workProfileTabContainerBackground = preference( + key = booleanPreferencesKey(name = "work_profile_tab_container_background"), + defaultValue = true, + onSet = { reloadHelper.recreate() }, + ) + val notificationDotColor = preference( key = stringPreferencesKey(name = "notification_dot_color"), parse = ColorOption::fromString, diff --git a/lawnchair/src/app/lawnchair/theme/drawable/DrawableTokens.kt b/lawnchair/src/app/lawnchair/theme/drawable/DrawableTokens.kt index 4ac0fb9c91..6b99403799 100644 --- a/lawnchair/src/app/lawnchair/theme/drawable/DrawableTokens.kt +++ b/lawnchair/src/app/lawnchair/theme/drawable/DrawableTokens.kt @@ -1,6 +1,7 @@ package app.lawnchair.theme.drawable import android.content.res.ColorStateList +import android.graphics.Color import android.graphics.drawable.Drawable import android.graphics.drawable.GradientDrawable import android.graphics.drawable.InsetDrawable @@ -8,8 +9,10 @@ import android.graphics.drawable.LayerDrawable import android.graphics.drawable.RippleDrawable import android.graphics.drawable.StateListDrawable import androidx.appcompat.content.res.AppCompatResources +import app.lawnchair.preferences2.PreferenceManager2 import app.lawnchair.theme.color.tokens.ColorTokens import com.android.launcher3.R +import com.patrykmichalik.opto.core.firstBlocking object DrawableTokens { @@ -146,7 +149,19 @@ object DrawableTokens { context, R.drawable.all_apps_tabs_background, ) - selected?.setTint(ColorTokens.AllAppsTabBackgroundSelected.resolveColor(context, scheme, uiColorMode)) + + // Get custom color from preferences + val prefs2 = PreferenceManager2.getInstance(context) + val colorOption = prefs2.workProfileTabBackgroundColor.firstBlocking() + val customColor = colorOption.colorPreferenceEntry.lightColor.invoke(context) + + val selectedColor = if (customColor != 0) { + customColor + } else { + ColorTokens.AllAppsTabBackgroundSelected.resolveColor(context, scheme, uiColorMode) + } + + selected?.setTint(selectedColor) list.addState(intArrayOf(-android.R.attr.state_selected), unselected) list.addState(intArrayOf(android.R.attr.state_selected), selected) diff --git a/lawnchair/src/app/lawnchair/ui/preferences/components/colorpreference/ColorPreferenceModelList.kt b/lawnchair/src/app/lawnchair/ui/preferences/components/colorpreference/ColorPreferenceModelList.kt index a7e9507168..92f85f02b0 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/components/colorpreference/ColorPreferenceModelList.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/components/colorpreference/ColorPreferenceModelList.kt @@ -45,6 +45,13 @@ class ColorPreferenceModelList @Inject constructor( dynamicEntries = dynamicColorsWithDefault, ), ) + registerModel( + ColorPreferenceModel( + prefObject = prefs.workProfileTabBackgroundColor, + labelRes = R.string.work_profile_tab_background_label, + dynamicEntries = dynamicColors, + ), + ) registerModel( ColorPreferenceModel( prefObject = prefs.notificationDotColor, diff --git a/lawnchair/src/app/lawnchair/ui/preferences/destinations/AppDrawerPreferences.kt b/lawnchair/src/app/lawnchair/ui/preferences/destinations/AppDrawerPreferences.kt index 614c31b648..d7bd835846 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/destinations/AppDrawerPreferences.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/destinations/AppDrawerPreferences.kt @@ -98,6 +98,13 @@ fun AppDrawerPreferences( showAsPercentage = true, ) } + Item { ColorPreference(preference = prefs2.workProfileTabBackgroundColor) } + Item { + SwitchPreference( + label = stringResource(id = R.string.work_profile_tab_container_background_label), + adapter = prefs2.workProfileTabContainerBackground.getAdapter(), + ) + } Item { SwitchPreference( label = stringResource(id = R.string.pref_all_apps_search_bar_background), diff --git a/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java b/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java index 2499c161b8..0cb49d79db 100644 --- a/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java +++ b/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java @@ -834,9 +834,14 @@ public class ActivityAllAppsContainerView protected void updateHeaderScroll(int scrolledOffset) { if (PreferenceExtensionsKt.firstBlocking(pref2.getHideAppDrawerSearchBar())) return; + + // Check if tab container background should be shown + boolean showTabContainerBackground = PreferenceExtensionsKt.firstBlocking( + pref2.getWorkProfileTabContainerBackground()); + float prog = Utilities.boundToRange((float) scrolledOffset / mHeaderThreshold, 0f, 1f); int headerColor = getHeaderColor(prog); - int tabsAlpha = mHeader.getPeripheralProtectionHeight(/* expectedHeight */ false) == 0 ? 0 + int tabsAlpha = (!showTabContainerBackground || mHeader.getPeripheralProtectionHeight(/* expectedHeight */ false) == 0) ? 0 : (int) (Utilities.boundToRange( (scrolledOffset + mHeader.mSnappedScrolledY) / mHeaderThreshold, 0f, 1f) * 255); diff --git a/src/com/android/launcher3/allapps/WorkProfileManager.java b/src/com/android/launcher3/allapps/WorkProfileManager.java index c20833aa4d..aaffb0808e 100644 --- a/src/com/android/launcher3/allapps/WorkProfileManager.java +++ b/src/com/android/launcher3/allapps/WorkProfileManager.java @@ -130,11 +130,13 @@ public class WorkProfileManager extends UserProfileManager * Creates and attaches for profile toggle button to {@link ActivityAllAppsContainerView} */ public boolean attachWorkUtilityViews() { - if (!mAllApps.getAppsStore().hasModelFlag( - FLAG_HAS_SHORTCUT_PERMISSION | FLAG_QUIET_MODE_CHANGE_PERMISSION)) { - Log.e(TAG, "unable to attach work mode switch; Missing required permissions"); - return false; - } + // LC: Skip permission checks - being the default launcher is sufficient for work profile control + // FLAG_HAS_SHORTCUT_PERMISSION and FLAG_QUIET_MODE_CHANGE_PERMISSION are not required +// if (!mAllApps.getAppsStore().hasModelFlag( +// FLAG_HAS_SHORTCUT_PERMISSION | FLAG_QUIET_MODE_CHANGE_PERMISSION)) { +// Log.e(TAG, "unable to attach work mode switch; Missing required permissions"); +// return false; +// } if (mWorkUtilityView == null) { mWorkUtilityView = (WorkUtilityView) mAllApps.getLayoutInflater().inflate( R.layout.work_mode_utility_view, mAllApps, false); @@ -142,8 +144,11 @@ public class WorkProfileManager extends UserProfileManager if (mWorkUtilityView.getParent() == null) { mAllApps.addView(mWorkUtilityView); } - if (mAllApps.getCurrentPage() != WORK) { + int currentPage = mAllApps.getCurrentPage(); + if (currentPage != WORK) { mWorkUtilityView.animateVisibility(false); + } else { + mWorkUtilityView.animateVisibility(true); } if (getAH() != null) { getAH().applyPadding(); diff --git a/src/com/android/launcher3/model/LoaderTask.java b/src/com/android/launcher3/model/LoaderTask.java index 39bdf113ef..8daa3b7989 100644 --- a/src/com/android/launcher3/model/LoaderTask.java +++ b/src/com/android/launcher3/model/LoaderTask.java @@ -625,13 +625,16 @@ public class LoaderTask implements Runnable { if (apps == null || apps.isEmpty()) { return allActivityList; } - boolean quietMode = mUserManagerState.isUserQuiet(user); + // Query UserManager directly for current quiet mode state to avoid stale cached values + boolean quietMode = mUserManager.isQuietModeEnabled(user); + // Update the cached state for consistency + mUserManagerState.updateUserQuietMode(mUserCache, user, quietMode); if (Flags.enablePrivateSpace()) { if (mUserCache.getUserInfo(user).isWork()) { - isWorkProfileQuiet = quietMode; + isWorkProfileQuiet |= quietMode; } else if (mUserCache.getUserInfo(user).isPrivate()) { - isPrivateProfileQuiet = quietMode; + isPrivateProfileQuiet |= quietMode; } } // Create the ApplicationInfos diff --git a/src/com/android/launcher3/model/UserManagerState.java b/src/com/android/launcher3/model/UserManagerState.java index ed3243043b..eab754c594 100644 --- a/src/com/android/launcher3/model/UserManagerState.java +++ b/src/com/android/launcher3/model/UserManagerState.java @@ -69,6 +69,15 @@ public class UserManagerState { return mQuietUsersHashCodeMap.get(user.hashCode()); } + /** + * Updates the quiet mode state for a specific user + */ + public void updateUserQuietMode(UserCache userCache, UserHandle user, boolean isQuiet) { + long serialNo = userCache.getSerialNumberForUser(user); + mQuietUsersHashCodeMap.put(user.hashCode(), isQuiet); + mQuietUsersSerialNoMap.put(serialNo, isQuiet); + } + /** * Returns true if any user profile has quiet mode enabled. *