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

Commit 1b3a2d69 authored by Nicolas Sleiman's avatar Nicolas Sleiman Committed by Automerger Merge Worker
Browse files

Merge "Allow specifying the target telephony app home screen overrides" into udc-dev am: f82f0fe6

parents 399241f6 f82f0fe6
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -19,8 +19,8 @@ import android.annotation.UserIdInt;

import com.android.server.LocalServices;

import java.util.ArrayList;
import java.util.List;
import java.util.Collections;
import java.util.Map;

/**
 * Stores a copy of the set of device policies maintained by {@link DevicePolicyManager} that
@@ -64,10 +64,11 @@ public abstract class DevicePolicyCache {
    public abstract boolean canAdminGrantSensorsPermissions();

    /**
     * Returns a list of package names for which all launcher shortcuts should be modified to be
     * launched in the managed profile and badged accordingly.
     * Returns a map of package names to package names, for which all launcher shortcuts which
     * match a key package name should be modified to launch the corresponding value package
     * name in the managed profile. The overridden shortcut should be badged accordingly.
     */
    public abstract List<String> getLauncherShortcutOverrides();
    public abstract Map<String, String> getLauncherShortcutOverrides();

    /**
     * Empty implementation.
@@ -95,8 +96,8 @@ public abstract class DevicePolicyCache {
            return false;
        }
        @Override
        public List<String> getLauncherShortcutOverrides() {
            return new ArrayList<>();
        public Map<String, String>  getLauncherShortcutOverrides() {
            return Collections.EMPTY_MAP;
        }
    }
}
+5 −4
Original line number Diff line number Diff line
@@ -1120,12 +1120,12 @@ public class LauncherAppsService extends SystemService {
                    return shortcutOverridesInfo;
                }

                List<String> packagesToOverride =
                Map<String, String> packagesToOverride =
                        DevicePolicyCache.getInstance().getLauncherShortcutOverrides();
                for (String packageName : packagesToOverride) {
                for (Map.Entry<String, String> packageNames : packagesToOverride.entrySet()) {
                    Intent intent = new Intent(Intent.ACTION_MAIN)
                            .addCategory(Intent.CATEGORY_LAUNCHER)
                            .setPackage(packageName);
                            .setPackage(packageNames.getValue());

                    List<LauncherActivityInfoInternal> possibleShortcutOverrides =
                            queryIntentLauncherActivities(
@@ -1135,7 +1135,8 @@ public class LauncherAppsService extends SystemService {
                            );

                    if (!possibleShortcutOverrides.isEmpty()) {
                        shortcutOverridesInfo.put(packageName, possibleShortcutOverrides.get(0));
                        shortcutOverridesInfo.put(packageNames.getKey(),
                                possibleShortcutOverrides.get(0));
                    }
                }
                return shortcutOverridesInfo;
+10 −9
Original line number Diff line number Diff line
@@ -19,13 +19,13 @@ import android.annotation.UserIdInt;
import android.app.admin.DevicePolicyCache;
import android.app.admin.DevicePolicyManager;
import android.os.UserHandle;
import android.util.ArrayMap;
import android.util.IndentingPrintWriter;
import android.util.SparseIntArray;

import com.android.internal.annotations.GuardedBy;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;

/**
@@ -55,8 +55,7 @@ public class DevicePolicyCacheImpl extends DevicePolicyCache {
    private final SparseIntArray mPermissionPolicy = new SparseIntArray();

    @GuardedBy("mLock")
    private List<String> mLauncherShortcutOverrides =
            new ArrayList<>();
    private ArrayMap<String, String> mLauncherShortcutOverrides = new ArrayMap<>();


    /** Maps to {@code ActiveAdmin.mAdminCanGrantSensorsPermissions}. */
@@ -130,18 +129,20 @@ public class DevicePolicyCacheImpl extends DevicePolicyCache {
    }

    @Override
    public List<String> getLauncherShortcutOverrides() {
    public Map<String, String> getLauncherShortcutOverrides() {
        synchronized (mLock) {
            return new ArrayList<>(mLauncherShortcutOverrides);
            return new ArrayMap<>(mLauncherShortcutOverrides);
        }
    }

    /**
     * Sets a list of packages for which shortcuts should be replaced by their badged version.
     * Sets a map of packages names to package names, for which all launcher shortcuts which
     * match a key package name should be modified to launch the corresponding value package
     * name in the managed profile. The overridden shortcut should be badged accordingly.
     */
    public void setLauncherShortcutOverrides(List<String> launcherShortcutOverrides) {
    public void setLauncherShortcutOverrides(ArrayMap<String, String> launcherShortcutOverrides) {
        synchronized (mLock) {
            mLauncherShortcutOverrides = new ArrayList<>(launcherShortcutOverrides);
            mLauncherShortcutOverrides = new ArrayMap<>(launcherShortcutOverrides);
        }
    }

+4 −5
Original line number Diff line number Diff line
@@ -7721,7 +7721,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
    }
    private void clearLauncherShortcutOverrides() {
        mPolicyCache.setLauncherShortcutOverrides(new ArrayList<>());
        mPolicyCache.setLauncherShortcutOverrides(new ArrayMap<>());
    }
    private void updateTelephonyCrossProfileIntentFilters(int parentUserId, int profileUserId,
@@ -23721,15 +23721,14 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
    private void updateDialerAndSmsManagedShortcutsOverrideCache(
            String defaultDialerPackageName, String defaultSmsPackageName) {
        List<String> shortcutOverrides = new ArrayList<>();
        ArrayMap<String, String> shortcutOverrides = new ArrayMap<>();
        if (defaultDialerPackageName != null) {
            shortcutOverrides.add(defaultDialerPackageName);
            shortcutOverrides.put(defaultDialerPackageName, defaultDialerPackageName);
        }
        if (defaultSmsPackageName != null) {
            shortcutOverrides.add(defaultSmsPackageName);
            shortcutOverrides.put(defaultSmsPackageName, defaultSmsPackageName);
        }
        mPolicyCache.setLauncherShortcutOverrides(shortcutOverrides);
    }