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

Commit 27fd0c30 authored by Diogo Ferreira's avatar Diogo Ferreira Committed by Steve Kondik
Browse files

services: devicepolicy: Restore backup service as system

Restoring the backup service must be performed by either system
or root otherwise it will cause a SecurityException. This patch
clears the uid, performs the call as system and then restores it.

Fixes the following CTS tests:

com.android.cts.devicepolicy.CustomDeviceOwnerTest
  -- testOwnerChangedBroadcast
  -- testSilentPackageInstall

com.android.cts.devicepolicy.DeviceOwnerTest
  -- testCaCertManagement
  -- testCannotSetDeviceOwnerAgain
  -- testDeviceOwnerSetup
  -- testKeyManagement
  -- testLockTask
  -- testSystemUpdatePolicy
  -- testWifiConfigLockdown

com.android.cts.devicepolicy.MixedDeviceOwnerTest
  -- testAccountManagement
  -- testApplicationRestrictions
  -- testDelegatedCertInstaller
  -- testPermissionGrant
  -- testPermissionGrantPreMApp
  -- testPermissionMixedPolicies
  -- testPermissionPolicy
  -- testPermissionPrompts
  -- testPersistentIntentResolving
  -- testScreenCaptureDisabled

Change-Id: Ia26222f1fece14217554459c42679f82f7ceb980
parent c224db64
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -4268,12 +4268,15 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
                mDeviceOwner.writeOwnerFile();
                updateDeviceOwnerLocked();
                // Restore backup manager.
                long ident = Binder.clearCallingIdentity();
                try {
                    IBackupManager ibm = IBackupManager.Stub.asInterface(
                            ServiceManager.getService(Context.BACKUP_SERVICE));
                    ibm.setBackupServiceActive(UserHandle.USER_OWNER, true);
                } catch (RemoteException e) {
                    throw new IllegalStateException("Failed activating backup service.", e);
                } finally {
                    Binder.restoreCallingIdentity(ident);
                }
            }
        }