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

Commit a902e5c2 authored by Pavel Grafov's avatar Pavel Grafov Committed by Android (Google) Code Review
Browse files

Merge "Let profile owners also receive OTA notification."

parents dfbfca20 19b3ecb9
Loading
Loading
Loading
Loading
+28 −25
Original line number Original line Diff line number Diff line
@@ -8755,40 +8755,43 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
                    "can broadcast update information.");
                    "can broadcast update information.");
            return;
            return;
        }
        }
        Intent intent = new Intent(DeviceAdminReceiver.ACTION_NOTIFY_PENDING_SYSTEM_UPDATE);
        final Intent intent = new Intent(DeviceAdminReceiver.ACTION_NOTIFY_PENDING_SYSTEM_UPDATE);
        intent.putExtra(DeviceAdminReceiver.EXTRA_SYSTEM_UPDATE_RECEIVED_TIME,
        intent.putExtra(DeviceAdminReceiver.EXTRA_SYSTEM_UPDATE_RECEIVED_TIME,
                updateReceivedTime);
                updateReceivedTime);


        final long ident = mInjector.binderClearCallingIdentity();
        try {
            synchronized (this) {
            synchronized (this) {
            final String deviceOwnerPackage =
                // Broadcast to device owner first if there is one.
                    mOwners.hasDeviceOwner() ? mOwners.getDeviceOwnerComponent().getPackageName()
                if (mOwners.hasDeviceOwner()) {
                            : null;
                    final UserHandle deviceOwnerUser =
            if (deviceOwnerPackage == null) {
                            UserHandle.of(mOwners.getDeviceOwnerUserId());
                return;
                    intent.setComponent(mOwners.getDeviceOwnerComponent());
                    mContext.sendBroadcastAsUser(intent, deviceOwnerUser);
                }
                }
            final UserHandle deviceOwnerUser = new UserHandle(mOwners.getDeviceOwnerUserId());

            ActivityInfo[] receivers = null;
            try {
                receivers  = mInjector.getPackageManager().getPackageInfo(
                        deviceOwnerPackage, PackageManager.GET_RECEIVERS).receivers;
            } catch (NameNotFoundException e) {
                Log.e(LOG_TAG, "Cannot find device owner package", e);
            }
            }
            if (receivers != null) {
            // Get running users.
                long ident = mInjector.binderClearCallingIdentity();
            final int runningUserIds[];
            try {
            try {
                    for (int i = 0; i < receivers.length; i++) {
                runningUserIds = mInjector.getIActivityManager().getRunningUserIds();
                        if (permission.BIND_DEVICE_ADMIN.equals(receivers[i].permission)) {
            } catch (RemoteException e) {
                            intent.setComponent(new ComponentName(deviceOwnerPackage,
                // Shouldn't happen.
                                    receivers[i].name));
                Log.e(LOG_TAG, "Could not retrieve the list of running users", e);
                            mContext.sendBroadcastAsUser(intent, deviceOwnerUser);
                return;
            }
            }
            // Send broadcasts to corresponding profile owners if any.
            for (final int userId : runningUserIds) {
                synchronized (this) {
                    final ComponentName profileOwnerPackage =
                            mOwners.getProfileOwnerComponent(userId);
                    if (profileOwnerPackage != null) {
                        intent.setComponent(profileOwnerPackage);
                        mContext.sendBroadcastAsUser(intent, UserHandle.of(userId));
                    }
                    }
                } finally {
                    mInjector.binderRestoreCallingIdentity(ident);
                }
                }
            }
            }
        } finally {
            mInjector.binderRestoreCallingIdentity(ident);
        }
        }
    }
    }