Skip to content

Conversation

@AnkitK-NITB
Copy link

@AnkitK-NITB AnkitK-NITB commented Dec 6, 2025

Lawnchair Improvements: Work Profile Fixes & Tab Customization

Overview

This PR includes multiple improvements to Lawnchair:

  1. Work profile pause/unpause without authentication prompts
  2. Work profile state detection bug fix.
  3. Work/Personal tab customization features

Part 1: Fix Work Profile Pause/Unpause Authentication

When using Lawnchair with work profiles (especially Motorola Secure Folder or similar private spaces), attempting to unpause work apps would trigger an authentication prompt requiring the device PIN/password. While the PIN can be skipped, this prompt is annoying and disrupts the user experience.

Additionally, the pause/unpause buttons were not visible due to overly strict permission checks that prevented the WorkModeSwitch from being attached.

Screenshot_20251207-193338_Lawnchair

Solution

1. Skip Authentication for Work Profile Unpause

  • Use the 3-parameter version of requestQuietModeEnabled() with a null Intent (available on Android P+)
  • This bypasses the credential challenge when the launcher is set as the default launcher
  • Falls back to the standard method for older Android versions or if the null Intent approach fails

2. Filter Private Spaces (Secure Folders)

  • Added profile type checking to only process actual work profiles (TYPE_WORK)
  • Skips private spaces/secure folders (TYPE_PRIVATE) that require authentication by design
  • Prevents unnecessary API calls and errors for profiles that shouldn't be modified

3. Remove Overly Strict Permission Checks

  • Removed requirement for FLAG_HAS_SHORTCUT_PERMISSION and FLAG_QUIET_MODE_CHANGE_PERMISSION
  • Being the default launcher is sufficient for work profile control via requestQuietModeEnabled()
  • The permissions were blocking button visibility even though the underlying API calls would succeed

Changes

  • Modified WorkProfileManager.setWorkProfileEnabled() to:

    • Filter profiles using mWorkProfileMatcher to only process work profiles
    • Use requestQuietModeEnabled(!enabled, userProfile, null) to skip authentication
    • Fallback to standard requestQuietModeEnabled(!enabled, userProfile) if needed
  • Modified WorkProfileManager.attachWorkModeSwitch() to:

    • Remove permission checks that were preventing button attachment
    • Allow work mode switch to be created for default launchers
Screenshot_20251207-194226_Lawnchair (Debug)

Part 2: Fix Work Profile State Detection Bug

Problem

Sometimes when work profile was paused, the launcher would still show work app icons (grayed out) instead of showing the unpause card with hidden icons.
Screenshot_20251207-193331_Lawnchair

Root Cause

LoaderTask.loadAllApps() was using cached quiet mode state from mUserManagerState.isUserQuiet(user), but this cache was initialized earlier in queryPinnedShortcutsForUnlockedUsers() and could become stale if the work profile state changed between initialization and app loading.

The updateUserQuietMode() method existed in UserManagerState but was never being called anywhere in the codebase.

Solution

  • Modified LoaderTask.loadAllApps() to query UserManager.isQuietModeEnabled(user) directly for real-time state
  • Call mUserManagerState.updateUserQuietMode() to keep the cached state synchronized
  • This ensures the FLAG_WORK_PROFILE_QUIET_MODE_ENABLED flag is set correctly based on current state

Changes

  • Modified LoaderTask.loadAllApps():
    // Before: Used stale cached value
    boolean quietMode = mUserManagerState.isUserQuiet(user);
    
    // After: Query fresh state and update cache
    boolean quietMode = mUserManager.isQuietModeEnabled(user);
    mUserManagerState.updateUserQuietMode(mUserCache, user, quietMode);
Screenshot_20251207-194216_Lawnchair (Debug)

Part 3: Work/Personal Tab Customization Features

New Features

1. Tabs Background Color

  • Custom color picker for the selected work/personal tab button
  • Located in: Settings → App Drawer → Style → Tabs background color
  • Default: System Accent color

2. Tab Container Background Toggle

  • ON/OFF switch to control the background protection that appears when scrolling
  • Located in: Settings → App Drawer → Style → Separated Tab container background
  • When OFF: No background drawn behind tabs when scrolling (completely transparent)
  • Default: ON
Screenshot_20251207-193323_Lawnchair

Changes

  • Added workProfileTabBackgroundColor preference in PreferenceManager2.kt
  • Added workProfileTabContainerBackground boolean preference in PreferenceManager2.kt
  • Modified DrawableTokens.AllAppsTabsBackground to use custom color from preferences
  • Modified ActivityAllAppsContainerView.updateHeaderScroll() to respect the toggle preference
  • Added UI controls in AppDrawerPreferences.kt
  • Added string resources for labels
Screenshot_20251207-192957_Lawnchair (Debug)

Testing

Tested on Motorola device (Android 16) with:

  • Regular work profile (UserHandle{10}) - Successfully pauses/unpauses without authentication ✅
  • Secure Folder (UserHandle{11}) - Correctly skipped, no errors or prompts ✅
  • Pause/unpause buttons now visible and functional ✅
  • Work profile state correctly detected on launcher restart ✅
  • Tab color customization working ✅
  • Tab background toggle working on scroll ✅

@AnkitK-NITB AnkitK-NITB closed this Dec 6, 2025
@AnkitK-NITB AnkitK-NITB reopened this Dec 7, 2025
Ankit Kushwaha added 2 commits December 7, 2025 13:18
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
@AnkitK-NITB AnkitK-NITB changed the title Fix work profile unpause authentication prompt [BUG] Fix work profile unpause authentication prompt Dec 7, 2025
Ankit Kushwaha added 3 commits December 7, 2025 17:05
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 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
- 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.
@AnkitK-NITB AnkitK-NITB changed the title [BUG] Fix work profile unpause authentication prompt [BUG] Fixing Dec 7, 2025
@AnkitK-NITB AnkitK-NITB changed the title [BUG] Fixing [BUG] Fixes various Work Profile Related Issues Dec 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant