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

Commit eb44ae4c authored by Yan Zhu's avatar Yan Zhu
Browse files

Allows setting affiliation to support DO setup flow on auto

1. build  aosp_car_x86 so it will use CarProvision which is AOSP verision setup wizard
2. deprovision the device
adb shell settings put global device_provisioned 0 && adb shell rm /data/system/device_owner_2.xml /data/system/device_policies.xml
3. reset user
adb shell rm /data/system/users/10/device_policies.xml && adb shell settings put secure --user 10 user_setup_complete 0 && adb shell settings put secure --user 0 user_setup_complete 0 && adb shell rm /data/system/users/10/profile_owner.xml
4. adb push frameworks/native/data/etc/android.software.device_admin.xml /vendor/etc/permissions/
5. install TestDPC app: https://github.com/googlesamples/android-testdpc
Setup DO from reference SUW

Bug: 171336247
Bug: 172691310
Test: manual with steps above
Change-Id: I5891150fdd53a3345f60aa1e810f63cc4d10343f
parent bc34eb88
Loading
Loading
Loading
Loading
+47 −25
Original line number Diff line number Diff line
@@ -7430,6 +7430,12 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                    admin.getPackageName(), userId, "set-device-owner");
            Slog.i(LOG_TAG, "Device owner set: " + admin + " on user " + userId);
            if (mInjector.userManagerIsHeadlessSystemUserMode()) {
                Slog.i(LOG_TAG, "manageUser: " + admin + " on user " + userId);
                manageUser(admin, admin, caller.getUserId(), null);
            }
            return true;
        }
    }
@@ -9493,29 +9499,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        final long id = mInjector.binderClearCallingIdentity();
        try {
            final String adminPkg = admin.getPackageName();
            try {
                // Install the profile owner if not present.
                if (!mIPackageManager.isPackageAvailable(adminPkg, userHandle)) {
                    mIPackageManager.installExistingPackageAsUser(adminPkg, userHandle,
                            PackageManager.INSTALL_ALL_WHITELIST_RESTRICTED_PERMISSIONS,
                            PackageManager.INSTALL_REASON_POLICY, null);
                }
            } catch (RemoteException e) {
                // Does not happen, same process
            }
            // Set admin.
            setActiveAdmin(profileOwner, true, userHandle);
            final String ownerName = getProfileOwnerName(Process.myUserHandle().getIdentifier());
            setProfileOwner(profileOwner, ownerName, userHandle);
            synchronized (getLockObject()) {
                DevicePolicyData policyData = getUserData(userHandle);
                policyData.mInitBundle = adminExtras;
                policyData.mAdminBroadcastPending = true;
                saveSettingsLocked(userHandle);
            }
            manageUser(admin, profileOwner, userHandle, adminExtras);
            if ((flags & DevicePolicyManager.SKIP_SETUP_WIZARD) != 0) {
                Settings.Secure.putIntForUser(mContext.getContentResolver(),
@@ -9536,6 +9520,46 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        }
    }
    private void manageUser(ComponentName admin, ComponentName profileOwner,
            @UserIdInt int userId, PersistableBundle adminExtras) {
        // Check for permission
        final CallerIdentity caller = getCallerIdentity();
        Preconditions.checkCallAuthorization(canManageUsers(caller));
        Preconditions.checkCallAuthorization(
                hasCallingOrSelfPermission(permission.MANAGE_PROFILE_AND_DEVICE_OWNERS));
        mInjector.binderWithCleanCallingIdentity(() ->
                    manageUserNoCheck(admin, profileOwner, userId, adminExtras));
    }
    private void manageUserNoCheck(ComponentName admin, ComponentName profileOwner,
            int user, PersistableBundle adminExtras) {
        final String adminPkg = admin.getPackageName();
        try {
            // Install the profile owner if not present.
            if (!mIPackageManager.isPackageAvailable(adminPkg, user)) {
                mIPackageManager.installExistingPackageAsUser(adminPkg, user,
                        PackageManager.INSTALL_ALL_WHITELIST_RESTRICTED_PERMISSIONS,
                        PackageManager.INSTALL_REASON_POLICY, null);
            }
        } catch (RemoteException e) {
            // Does not happen, same process
        }
        // Set admin.
        setActiveAdmin(profileOwner, true, user);
        final String ownerName = getProfileOwnerName(Process.myUserHandle().getIdentifier());
        setProfileOwner(profileOwner, ownerName, user);
        synchronized (getLockObject()) {
            DevicePolicyData policyData = getUserData(user);
            policyData.mInitBundle = adminExtras;
            policyData.mAdminBroadcastPending = true;
            saveSettingsLocked(user);
        }
    }
    @Override
    public boolean removeUser(ComponentName who, UserHandle userHandle) {
        Objects.requireNonNull(who, "ComponentName is null");
@@ -12184,8 +12208,6 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                if (hasUserSetupCompleted(UserHandle.USER_SYSTEM)) {
                    return CODE_USER_SETUP_COMPLETED;
                }
            }  else {
                // STOPSHIP Do proper check in split user mode
            }
            return CODE_OK;
        }