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

Commit dd31a10c authored by Jessica Hummel's avatar Jessica Hummel
Browse files

bug fix: Allow enableSystemApps to be called by profile and device owner.

We had an additional check for managed profile in there, so it wasn't working for device owners. Also needed to look at uninstalled packages.

Change-Id: I4813f23b00d7905e92ade582ce082a6f295a322d
Bug: 17384318
parent 52ee3280
Loading
Loading
Loading
Loading
+15 −13
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.server.devicepolicy;

import static android.Manifest.permission.MANAGE_CA_CERTIFICATES;
import static android.content.pm.PackageManager.GET_UNINSTALLED_PACKAGES;

import android.accessibilityservice.AccessibilityServiceInfo;
import android.accounts.AccountManager;
@@ -4801,17 +4802,17 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
            long id = Binder.clearCallingIdentity();

            try {
                UserManager um = UserManager.get(mContext);
                if (!um.getUserInfo(userId).isManagedProfile()) {
                    throw new IllegalStateException(
                            "Only call this method from a managed profile.");
                if (DBG) {
                    Slog.v(LOG_TAG, "installing " + packageName + " for "
                            + userId);
                }

                UserManager um = UserManager.get(mContext);
                UserInfo primaryUser = um.getProfileParent(userId);

                if (DBG) {
                    Slog.v(LOG_TAG, "installing " + packageName + " for "
                            + userId);
                // Call did not come from a managed profile
                if (primaryUser == null) {
                    primaryUser = um.getUserInfo(userId);
                }

                IPackageManager pm = AppGlobals.getPackageManager();
@@ -4847,13 +4848,13 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {

            try {
                UserManager um = UserManager.get(mContext);
                if (!um.getUserInfo(userId).isManagedProfile()) {
                    throw new IllegalStateException(
                            "Only call this method from a managed profile.");
                }

                UserInfo primaryUser = um.getProfileParent(userId);

                // Call did not come from a managed profile.
                if (primaryUser == null) {
                    primaryUser = um.getUserInfo(userId);
                }

                IPackageManager pm = AppGlobals.getPackageManager();
                List<ResolveInfo> activitiesToEnable = pm.queryIntentActivities(intent,
                        intent.resolveTypeIfNeeded(mContext.getContentResolver()),
@@ -4890,7 +4891,8 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {

    private boolean isSystemApp(IPackageManager pm, String packageName, int userId)
            throws RemoteException {
        ApplicationInfo appInfo = pm.getApplicationInfo(packageName, 0, userId);
        ApplicationInfo appInfo = pm.getApplicationInfo(packageName, GET_UNINSTALLED_PACKAGES,
                userId);
        return (appInfo.flags & ApplicationInfo.FLAG_SYSTEM) > 0;
    }