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

Commit 2c84cc2e authored by Rubin Xu's avatar Rubin Xu
Browse files

clear caller identify before sending system update notification

Because DeviceAdminReceiver is protected by BIND_DEVICE_ADMIN permission,
in order to send broadcast to it, we need to clear the caller's identity
and call sendBroadcastAsUser() as system.

Bug: 20213644
Change-Id: Icc7b239b9005e286012ade6580ec92a0a57198e0
parent c454f786
Loading
Loading
Loading
Loading
+10 −4
Original line number Diff line number Diff line
@@ -6296,10 +6296,16 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
                return;
            }

            ActivityInfo[] receivers = null;
            try {
                ActivityInfo[] receivers  = mContext.getPackageManager().getPackageInfo(
                receivers  = mContext.getPackageManager().getPackageInfo(
                        deviceOwnerPackage, PackageManager.GET_RECEIVERS).receivers;
            } catch (NameNotFoundException e) {
                Log.e(LOG_TAG, "Cannot find device owner package", e);
            }
            if (receivers != null) {
                long ident = Binder.clearCallingIdentity();
                try {
                    for (int i = 0; i < receivers.length; i++) {
                        if (permission.BIND_DEVICE_ADMIN.equals(receivers[i].permission)) {
                            intent.setComponent(new ComponentName(deviceOwnerPackage,
@@ -6307,9 +6313,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
                            mContext.sendBroadcastAsUser(intent, UserHandle.OWNER);
                        }
                    }
                } finally {
                    Binder.restoreCallingIdentity(ident);
                }
            } catch (NameNotFoundException e) {
                Log.e(LOG_TAG, "Cannot find device owner package", e);
            }
        }
    }