Skip to content

Commit db82b41

Browse files
t-m-wneobuddy89
authored andcommitted
Launcher3: Work tab adjustments for multiple profiles
* When multiple work profiles are present, always show work apps in the app drawer as opposed to hiding them behind a Paused screen. This allows a particular work profile to be activated individually by attempting to launch one of its apps. * The floating action button for turning off work apps can now turn them all on, too, when all work profiles are turned off. Change-Id: I564c4afb55f47e3d9463790b7c45b94b3303b39a Signed-off-by: Pranav Vashi <[email protected]>
1 parent 16ce1c5 commit db82b41

File tree

6 files changed

+73
-19
lines changed

6 files changed

+73
-19
lines changed

src/com/android/launcher3/allapps/WorkModeSwitch.java

+14-2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public class WorkModeSwitch extends LinearLayout implements Insettable,
5959
private ImageView mIcon;
6060
private TextView mTextView;
6161
private final StatsLogManager mStatsLogManager;
62+
private boolean mDoPause = true;
6263

6364

6465
public WorkModeSwitch(@NonNull Context context) {
@@ -88,7 +89,7 @@ protected void onFinishInflate() {
8889
setWindowInsetsAnimationCallback(keyboardInsetAnimationCallback);
8990

9091
setInsets(mActivityContext.getDeviceProfile().getInsets());
91-
updateStringFromCache();
92+
updatePauseMode();
9293
}
9394

9495
@Override
@@ -209,7 +210,18 @@ public int getScrollThreshold() {
209210
public void updateStringFromCache(){
210211
StringCache cache = mActivityContext.getStringCache();
211212
if (cache != null) {
212-
mTextView.setText(cache.workProfilePauseButton);
213+
mTextView.setText(mDoPause ? cache.workProfilePauseButton :
214+
cache.workProfileEnableButton);
213215
}
214216
}
217+
218+
private void updatePauseMode() {
219+
mIcon.setImageResource(mDoPause ? R.drawable.ic_corp_off : R.drawable.ic_corp);
220+
updateStringFromCache();
221+
}
222+
223+
public void setPauseMode(final boolean doPause) {
224+
mDoPause = doPause;
225+
updatePauseMode();
226+
}
215227
}

src/com/android/launcher3/allapps/WorkProfileManager.java

+25-6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import static com.android.launcher3.allapps.BaseAllAppsAdapter.VIEW_TYPE_WORK_DISABLED_CARD;
2323
import static com.android.launcher3.allapps.BaseAllAppsAdapter.VIEW_TYPE_WORK_EDU_CARD;
2424
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TURN_OFF_WORK_APPS_TAP;
25+
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TURN_ON_WORK_APPS_TAP;
26+
import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_HAS_MULTIPLE_PROFILES;
2527
import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_HAS_SHORTCUT_PERMISSION;
2628
import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_QUIET_MODE_CHANGE_PERMISSION;
2729
import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_QUIET_MODE_ENABLED;
@@ -65,6 +67,8 @@ public class WorkProfileManager extends UserProfileManager
6567
private final UserManager mUserManager;
6668
private final UserCache mUserCache;
6769

70+
private boolean mHasMultipleProfiles;
71+
6872
public WorkProfileManager(
6973
UserManager userManager, ActivityAllAppsContainerView allApps,
7074
StatsLogManager statsLogManager, UserCache userCache) {
@@ -92,7 +96,14 @@ private void updateWorkFAB(int page) {
9296
if (mWorkModeSwitch != null) {
9397
if (page == MAIN || page == SEARCH) {
9498
mWorkModeSwitch.animateVisibility(false);
95-
} else if (page == WORK && getCurrentState() == STATE_ENABLED) {
99+
} else if (page == WORK && shouldShowWorkApps()) {
100+
if (getCurrentState() == STATE_ENABLED) {
101+
mWorkModeSwitch.setPauseMode(true /* doPause */);
102+
mWorkModeSwitch.setOnClickListener(this::onWorkFabClickedTurnOff);
103+
} else if (getCurrentState() == STATE_DISABLED) {
104+
mWorkModeSwitch.setPauseMode(false /* doPause */);
105+
mWorkModeSwitch.setOnClickListener(this::onWorkFabClickedTurnOn);
106+
}
96107
mWorkModeSwitch.animateVisibility(true);
97108
}
98109
}
@@ -118,11 +129,12 @@ public void reset() {
118129
}
119130

120131
private void updateCurrentState(@UserProfileState int currentState) {
132+
mHasMultipleProfiles = mAllApps.getAppsStore().hasModelFlag(FLAG_HAS_MULTIPLE_PROFILES);
121133
setCurrentState(currentState);
122134
if (getAH() != null) {
123135
getAH().mAppsList.updateAdapterItems();
124136
}
125-
if (getCurrentState() == STATE_ENABLED) {
137+
if (shouldShowWorkApps()) {
126138
attachWorkModeSwitch();
127139
} else if (getCurrentState() == STATE_DISABLED) {
128140
detachWorkModeSwitch();
@@ -154,7 +166,6 @@ public boolean attachWorkModeSwitch() {
154166
if (getAH() != null) {
155167
getAH().applyPadding();
156168
}
157-
mWorkModeSwitch.setOnClickListener(this::onWorkFabClicked);
158169
return true;
159170
}
160171
/**
@@ -180,7 +191,8 @@ private ActivityAllAppsContainerView.AdapterHolder getAH() {
180191
* returns whether or not work apps should be visible in work tab.
181192
*/
182193
public boolean shouldShowWorkApps() {
183-
return getCurrentState() != WorkProfileManager.STATE_DISABLED;
194+
return getCurrentState() != WorkProfileManager.STATE_DISABLED
195+
|| mHasMultipleProfiles;
184196
}
185197

186198
public boolean hasWorkApps() {
@@ -191,7 +203,7 @@ public boolean hasWorkApps() {
191203
* Adds work profile specific adapter items to adapterItems and returns number of items added
192204
*/
193205
public int addWorkItems(ArrayList<AdapterItem> adapterItems) {
194-
if (getCurrentState() == WorkProfileManager.STATE_DISABLED) {
206+
if (!shouldShowWorkApps()) {
195207
//add disabled card here.
196208
adapterItems.add(new AdapterItem(VIEW_TYPE_WORK_DISABLED_CARD));
197209
} else if (getCurrentState() == WorkProfileManager.STATE_ENABLED && !isEduSeen()) {
@@ -204,13 +216,20 @@ private boolean isEduSeen() {
204216
return LauncherPrefs.get(mAllApps.getContext()).get(WORK_EDU_STEP) != 0;
205217
}
206218

207-
private void onWorkFabClicked(View view) {
219+
private void onWorkFabClickedTurnOff(View view) {
208220
if (getCurrentState() == STATE_ENABLED && mWorkModeSwitch.isEnabled()) {
209221
logEvents(LAUNCHER_TURN_OFF_WORK_APPS_TAP);
210222
setWorkProfileEnabled(false);
211223
}
212224
}
213225

226+
private void onWorkFabClickedTurnOn(View view) {
227+
if (getCurrentState() == STATE_DISABLED && mWorkModeSwitch.isEnabled()) {
228+
logEvents(LAUNCHER_TURN_ON_WORK_APPS_TAP);
229+
setWorkProfileEnabled(true);
230+
}
231+
}
232+
214233
public RecyclerView.OnScrollListener newScrollListener() {
215234
return new RecyclerView.OnScrollListener() {
216235
int totalDelta = 0;

src/com/android/launcher3/model/BgDataModel.java

+2
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,8 @@ public interface Callbacks {
484484
int FLAG_WORK_PROFILE_QUIET_MODE_ENABLED = 1 << 3;
485485
// If quiet mode is enabled for private profile user
486486
int FLAG_PRIVATE_PROFILE_QUIET_MODE_ENABLED = 1 << 4;
487+
// If user has more than one work profile
488+
int FLAG_HAS_MULTIPLE_PROFILES = 1 << 5;
487489

488490
/**
489491
* Returns an IntSet of page ids to bind first, synchronously if possible

src/com/android/launcher3/model/LoaderTask.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import static com.android.launcher3.LauncherSettings.Favorites.TABLE_NAME;
2525
import static com.android.launcher3.config.FeatureFlags.ENABLE_SMARTSPACE_REMOVAL;
2626
import static com.android.launcher3.config.FeatureFlags.SMARTSPACE_AS_A_WIDGET;
27+
import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_HAS_MULTIPLE_PROFILES;
2728
import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_HAS_SHORTCUT_PERMISSION;
2829
import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_PRIVATE_PROFILE_QUIET_MODE_ENABLED;
2930
import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_QUIET_MODE_CHANGE_PERMISSION;
@@ -723,7 +724,9 @@ private List<LauncherActivityInfo> loadAllApps() {
723724
mBgAllAppsList.setFlags(FLAG_PRIVATE_PROFILE_QUIET_MODE_ENABLED, isPrivateProfileQuiet);
724725
} else {
725726
mBgAllAppsList.setFlags(FLAG_QUIET_MODE_ENABLED,
726-
mUserManagerState.isAnyProfileQuietModeEnabled());
727+
mUserManagerState.isAllProfilesQuietModeEnabled());
728+
mBgAllAppsList.setFlags(FLAG_HAS_MULTIPLE_PROFILES,
729+
mUserManagerState.hasMultipleProfiles());
727730
}
728731
mBgAllAppsList.setFlags(FLAG_HAS_SHORTCUT_PERMISSION,
729732
hasShortcutsPermission(mApp.getContext()));

src/com/android/launcher3/model/PackageUpdatedTask.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.android.launcher3.model;
1717

18+
import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_HAS_MULTIPLE_PROFILES;
1819
import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_PRIVATE_PROFILE_QUIET_MODE_ENABLED;
1920
import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_QUIET_MODE_ENABLED;
2021
import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_WORK_PROFILE_QUIET_MODE_ENABLED;
@@ -183,7 +184,8 @@ public void execute(@NonNull final LauncherAppState app, @NonNull final BgDataMo
183184
}
184185
} else {
185186
// We are not synchronizing here, as int operations are atomic
186-
appsList.setFlags(FLAG_QUIET_MODE_ENABLED, ums.isAnyProfileQuietModeEnabled());
187+
appsList.setFlags(FLAG_QUIET_MODE_ENABLED, ums.isAllProfilesQuietModeEnabled());
188+
appsList.setFlags(FLAG_HAS_MULTIPLE_PROFILES, ums.hasMultipleProfiles());
187189
}
188190
break;
189191
}

src/com/android/launcher3/model/UserManagerState.java

+25-9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.android.launcher3.model;
1717

18+
import android.os.Process;
1819
import android.os.UserHandle;
1920
import android.os.UserManager;
2021
import android.util.LongSparseArray;
@@ -60,17 +61,32 @@ public boolean isUserQuiet(UserHandle user) {
6061
}
6162

6263
/**
63-
* Returns true if any user profile has quiet mode enabled.
64-
* <p>
65-
* Do not use this for determining if a specific profile has quiet mode enabled, as their can
66-
* be more than one profile in quiet mode.
64+
* Returns true if all managed profiles have quiet mode enabled.
6765
*/
68-
public boolean isAnyProfileQuietModeEnabled() {
69-
for (int i = mQuietUsersHashCodeMap.size() - 1; i >= 0; i--) {
70-
if (mQuietUsersHashCodeMap.valueAt(i)) {
71-
return true;
66+
public boolean isAllProfilesQuietModeEnabled() {
67+
// Because the parent user is included, there will always be at least one user returned
68+
// by getUserProfiles and tracked by allUsers, even if there are no managed profiles.
69+
final int numProfilesIncludingParent = allUsers.size();
70+
if (numProfilesIncludingParent <= 1) {
71+
// There are no managed profiles, only the parent user, so we can return early.
72+
return false;
73+
}
74+
for (int i = 0; i < numProfilesIncludingParent; i++) {
75+
if (Process.myUserHandle().equals(allUsers.valueAt(i))) {
76+
// Skip the parent user.
77+
continue;
78+
}
79+
long serialNo = allUsers.keyAt(i);
80+
if (!isUserQuiet(serialNo)) {
81+
return false;
7282
}
7383
}
74-
return false;
84+
// Quiet mode is on for all users.
85+
return true;
86+
}
87+
88+
public boolean hasMultipleProfiles() {
89+
final int numProfiles = allUsers.size() - 1; // not including the parent
90+
return numProfiles > 1;
7591
}
7692
}

0 commit comments

Comments
 (0)