Merge "Do not display clone apps in launcher work tab." into udc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
64fadf8fba
@@ -44,12 +44,14 @@ import com.android.launcher3.LauncherPrefs;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.allapps.BaseAllAppsAdapter.AdapterItem;
|
||||
import com.android.launcher3.config.FeatureFlags;
|
||||
import com.android.launcher3.logging.StatsLogManager;
|
||||
import com.android.launcher3.model.data.ItemInfo;
|
||||
import com.android.launcher3.workprofile.PersonalWorkSlidingTabStrip;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@@ -93,7 +95,11 @@ public class WorkProfileManager implements PersonalWorkSlidingTabStrip.OnActiveP
|
||||
StatsLogManager statsLogManager) {
|
||||
mUserManager = userManager;
|
||||
mAllApps = allApps;
|
||||
mMatcher = mAllApps.mPersonalMatcher.negate();
|
||||
if (FeatureFlags.ENABLE_APP_CLONING_CHANGES_IN_LAUNCHER.get()) {
|
||||
mMatcher = ofWorkProfileUser(userManager);
|
||||
} else {
|
||||
mMatcher = mAllApps.mPersonalMatcher.negate();
|
||||
}
|
||||
mStatsLogManager = statsLogManager;
|
||||
}
|
||||
|
||||
@@ -260,4 +266,27 @@ public class WorkProfileManager implements PersonalWorkSlidingTabStrip.OnActiveP
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter to only display apps in managed profile in work tab.
|
||||
*/
|
||||
private Predicate<ItemInfo> ofWorkProfileUser(UserManager um) {
|
||||
return info -> info != null && isManagedProfile(um, info.user.hashCode());
|
||||
}
|
||||
|
||||
|
||||
private static boolean isManagedProfile(UserManager um, int userId) {
|
||||
try {
|
||||
// isManagedProfile is a @SystemApi.
|
||||
String methodName = "isManagedProfile";
|
||||
Method method = um.getClass().getDeclaredMethod(methodName, int.class);
|
||||
Object result = method.invoke(um, userId);
|
||||
if (result instanceof Boolean) {
|
||||
return (boolean) result;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Failed to call #isManagedProfile via reflection from Launcher");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -398,6 +398,10 @@ public final class FeatureFlags {
|
||||
"ENABLE_KEYBOARD_QUICK_SWITCH", true,
|
||||
"Enables keyboard quick switching");
|
||||
|
||||
public static final BooleanFlag ENABLE_APP_CLONING_CHANGES_IN_LAUNCHER = getDebugFlag(266177840,
|
||||
"ENABLE_APP_CLONING_CHANGES_IN_LAUNCHER", false,
|
||||
"Removes clone apps from the work profile tab.");
|
||||
|
||||
public static class BooleanFlag {
|
||||
|
||||
private final boolean mCurrentValue;
|
||||
|
||||
Reference in New Issue
Block a user