Do not display clone apps in launcher work tab.

This change is only for dogfooding and will not be part of android release.
Guarded by feature flag.

Test: manual
Bug: 266177840
Change-Id: Iee416b43e0864b98f08149c46b7d011271ba8de6
This commit is contained in:
Ankita Vyas
2023-01-20 09:19:29 +00:00
committed by Himanshu Gupta
parent 11c8b4f594
commit 45ef9b6c01
2 changed files with 34 additions and 1 deletions
@@ -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;
}
}