Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 45ef9b6c authored by Ankita Vyas's avatar Ankita Vyas Committed by Himanshu Gupta
Browse files

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
parent 11c8b4f5
Loading
Loading
Loading
Loading
+30 −1
Original line number Diff line number Diff line
@@ -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;
        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;
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -391,6 +391,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;