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

Commit a7e4d92a authored by Alex Kershaw's avatar Alex Kershaw Committed by Android (Google) Code Review
Browse files

Merge "Allows affiliated profile owners to start activities in the background" into udc-dev

parents 4da9107a 1831723e
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -49,6 +49,14 @@ public abstract class DeviceStateCache {
     */
    public abstract boolean isUserOrganizationManaged(@UserIdInt int userHandle);

    /**
     * Returns whether a user has affiliated IDs.
     */

    public boolean hasAffiliationWithDevice(int userId) {
        return false;
    }

    /**
     * Empty implementation.
     */
+5 −0
Original line number Diff line number Diff line
@@ -584,6 +584,11 @@ public abstract class ActivityTaskManagerInternal {
     */
    public abstract void setDeviceOwnerUid(int uid);

    /**
     * Called by DevicePolicyManagerService to set the uids of the profile owners.
     */
    public abstract void setProfileOwnerUids(Set<Integer> uids);

    /**
     * Set all associated companion app that belongs to a userId.
     * @param userId
+19 −0
Original line number Diff line number Diff line
@@ -158,6 +158,7 @@ import android.app.PictureInPictureUiState;
import android.app.ProfilerInfo;
import android.app.WaitResult;
import android.app.admin.DevicePolicyCache;
import android.app.admin.DeviceStateCache;
import android.app.assist.ActivityId;
import android.app.assist.AssistContent;
import android.app.assist.AssistStructure;
@@ -783,6 +784,8 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {

    private int mDeviceOwnerUid = Process.INVALID_UID;

    private Set<Integer> mProfileOwnerUids = new ArraySet<Integer>();

    private final class SettingObserver extends ContentObserver {
        private final Uri mFontScaleUri = Settings.System.getUriFor(FONT_SCALE);
        private final Uri mHideErrorDialogsUri = Settings.Global.getUriFor(HIDE_ERROR_DIALOGS);
@@ -5360,6 +5363,15 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
        mDeviceOwnerUid = uid;
    }

    boolean isAffiliatedProfileOwner(int uid) {
        return uid >= 0 && mProfileOwnerUids.contains(uid)
            && DeviceStateCache.getInstance().hasAffiliationWithDevice(UserHandle.getUserId(uid));
    }

    void setProfileOwnerUids(Set<Integer> uids) {
        mProfileOwnerUids = uids;
    }

    /**
     * Saves the current activity manager state and includes the saved state in the next dump of
     * activity manager.
@@ -6915,6 +6927,13 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
            }
        }

        @Override
        public void setProfileOwnerUids(Set<Integer> uids) {
            synchronized (mGlobalLock) {
                ActivityTaskManagerService.this.setProfileOwnerUids(uids);
            }
        }

        @Override
        public void setCompanionAppUids(int userId, Set<Integer> companionAppUids) {
            synchronized (mGlobalLock) {
+8 −0
Original line number Diff line number Diff line
@@ -342,6 +342,14 @@ public class BackgroundActivityStartController {
                    /*background*/ true, callingUid, realCallingUid,
                    intent, "Device Owner");
            }
            // don't abort if the callingUid is a affiliated profile owner
            if (mService.isAffiliatedProfileOwner(callingUid)) {
                return logStartAllowedAndReturnCode(
                    BAL_ALLOW_ALLOWLISTED_COMPONENT,
                    resultIfPiSenderAllowsBal, balAllowedByPiSender,
                    /*background*/ true, callingUid, realCallingUid,
                    intent, "Affiliated Profile Owner");
            }
            // don't abort if the callingUid has companion device
            final int callingUserId = UserHandle.getUserId(callingUid);
            if (mService.isAssociatedCompanionApp(callingUserId, callingUid)) {
+17 −1
Original line number Diff line number Diff line
@@ -10329,6 +10329,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
        policy.mSecondaryLockscreenEnabled = false;
        policy.mUserProvisioningState = DevicePolicyManager.STATE_USER_UNMANAGED;
        policy.mAffiliationIds.clear();
        resetAffiliationCacheLocked();
        policy.mLockTaskPackages.clear();
        if (!isPolicyEngineForFinanceFlagEnabled()) {
            updateLockTaskPackagesLocked(mContext, policy.mLockTaskPackages, userId);
@@ -18022,10 +18023,16 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
        synchronized (getLockObject()) {
            getUserData(callingUserId).mAffiliationIds = affiliationIds;
            saveSettingsLocked(callingUserId);
            if (callingUserId != UserHandle.USER_SYSTEM && isDeviceOwner(admin, callingUserId)) {
            mStateCache.setHasAffiliationWithDevice(callingUserId,
                    isUserAffiliatedWithDeviceLocked(callingUserId));
            if (callingUserId == UserHandle.USER_SYSTEM) {
                resetAffiliationCacheLocked();
            } else if (callingUserId != UserHandle.USER_SYSTEM && isDeviceOwner(admin,
                    callingUserId)) {
                // Affiliation ids specified by the device owner are additionally stored in
                // UserHandle.USER_SYSTEM's DevicePolicyData.
                getUserData(UserHandle.USER_SYSTEM).mAffiliationIds = affiliationIds;
                mStateCache.setHasAffiliationWithDevice(UserHandle.USER_SYSTEM, true);
                saveSettingsLocked(UserHandle.USER_SYSTEM);
            }
@@ -18039,6 +18046,15 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
        }
    }
    private void resetAffiliationCacheLocked() {
        mInjector.binderWithCleanCallingIdentity(() -> {
            for (UserInfo user : mUserManager.getUsers()) {
                mStateCache.setHasAffiliationWithDevice(user.id,
                        isUserAffiliatedWithDeviceLocked(user.id));
            }
        });
    }
    @Override
    public List<String> getAffiliationIds(ComponentName admin) {
        if (!mHasFeature) {
Loading