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

Commit 8f01a381 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 28bfdab6 f82f0fe6
Loading
Loading
Loading
Loading
+8 −7
Original line number Original line Diff line number Diff line
@@ -19,8 +19,8 @@ import android.annotation.UserIdInt;


import com.android.server.LocalServices;
import com.android.server.LocalServices;


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


/**
/**
 * Stores a copy of the set of device policies maintained by {@link DevicePolicyManager} that
 * 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();
    public abstract boolean canAdminGrantSensorsPermissions();


    /**
    /**
     * Returns a list of package names for which all launcher shortcuts should be modified to be
     * Returns a map of package names to package names, for which all launcher shortcuts which
     * launched in the managed profile and badged accordingly.
     * 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.
     * Empty implementation.
@@ -95,8 +96,8 @@ public abstract class DevicePolicyCache {
            return false;
            return false;
        }
        }
        @Override
        @Override
        public List<String> getLauncherShortcutOverrides() {
        public Map<String, String>  getLauncherShortcutOverrides() {
            return new ArrayList<>();
            return Collections.EMPTY_MAP;
        }
        }
    }
    }
}
}
+5 −4
Original line number Original line Diff line number Diff line
@@ -1120,12 +1120,12 @@ public class LauncherAppsService extends SystemService {
                    return shortcutOverridesInfo;
                    return shortcutOverridesInfo;
                }
                }


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


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


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


import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.GuardedBy;


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


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


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




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


    @Override
    @Override
    public List<String> getLauncherShortcutOverrides() {
    public Map<String, String> getLauncherShortcutOverrides() {
        synchronized (mLock) {
        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) {
        synchronized (mLock) {
            mLauncherShortcutOverrides = new ArrayList<>(launcherShortcutOverrides);
            mLauncherShortcutOverrides = new ArrayMap<>(launcherShortcutOverrides);
        }
        }
    }
    }


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