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

Commit a8528c64 authored by Julia Reynolds's avatar Julia Reynolds Committed by Android (Google) Code Review
Browse files

Merge "Audio/Micrphone user restriction/multiuser updates." into lmp-dev

parents 2db754ac b53453fa
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -2112,6 +2112,13 @@ public final class Settings {
         */
        public static final String VOLUME_MASTER_MUTE = "volume_master_mute";

        /**
         * Microphone mute (int 1 = mute, 0 = not muted).
         *
         * @hide
         */
        public static final String MICROPHONE_MUTE = "microphone_mute";

        /**
         * Whether the notifications should use the ring volume (value of 1) or
         * a separate notification volume (value of 0). In most cases, users
+16 −5
Original line number Diff line number Diff line
@@ -200,6 +200,7 @@ public class AudioService extends IAudioService.Stub {
    private static final int MSG_UNLOAD_SOUND_EFFECTS = 20;
    private static final int MSG_SYSTEM_READY = 21;
    private static final int MSG_PERSIST_MUSIC_ACTIVE_MS = 22;
    private static final int MSG_PERSIST_MICROPHONE_MUTE = 23;
    // start of messages handled under wakelock
    //   these messages can only be queued, i.e. sent with queueMsgUnderWakeLock(),
    //   and not with sendMsg(..., ..., SENDMSG_QUEUE, ...)
@@ -873,6 +874,10 @@ public class AudioService extends IAudioService.Stub {
        AudioSystem.setMasterMute(masterMute);
        broadcastMasterMuteStatus(masterMute);

        boolean microphoneMute =
                System.getIntForUser(cr, System.MICROPHONE_MUTE, 0, UserHandle.USER_CURRENT) == 1;
        AudioSystem.muteMicrophone(microphoneMute);

        // Each stream will read its own persisted settings

        // Broadcast the sticky intent
@@ -1447,17 +1452,15 @@ public class AudioService extends IAudioService.Stub {
        if (mUseFixedVolume) {
            return;
        }

        if (mAppOps.noteOp(AppOpsManager.OP_AUDIO_MASTER_VOLUME, Binder.getCallingUid(),
                callingPackage) != AppOpsManager.MODE_ALLOWED) {
            return;
        }

        if (state != AudioSystem.getMasterMute()) {
            AudioSystem.setMasterMute(state);
            // Post a persist master volume msg
            sendMsg(mAudioHandler, MSG_PERSIST_MASTER_VOLUME_MUTE, SENDMSG_REPLACE, state ? 1
                    : 0, 0, null, PERSIST_DELAY);
                    : 0, UserHandle.getCallingUserId(), null, PERSIST_DELAY);
            sendMasterMuteUpdate(state, flags);
        }
    }
@@ -1563,6 +1566,9 @@ public class AudioService extends IAudioService.Stub {
        }

        AudioSystem.muteMicrophone(on);
        // Post a persist microphone msg.
        sendMsg(mAudioHandler, MSG_PERSIST_MICROPHONE_MUTE, SENDMSG_REPLACE, on ? 1
                : 0, UserHandle.getCallingUserId(), null, PERSIST_DELAY);
    }

    /** @see AudioManager#getRingerMode() */
@@ -3834,7 +3840,6 @@ public class AudioService extends IAudioService.Stub {

        @Override
        public void handleMessage(Message msg) {

            switch (msg.what) {

                case MSG_SET_DEVICE_VOLUME:
@@ -3866,7 +3871,7 @@ public class AudioService extends IAudioService.Stub {
                    Settings.System.putIntForUser(mContentResolver,
                                                 Settings.System.VOLUME_MASTER_MUTE,
                                                 msg.arg1,
                                                 UserHandle.USER_CURRENT);
                                                 msg.arg2);
                    break;

                case MSG_PERSIST_RINGER_MODE:
@@ -4061,6 +4066,12 @@ public class AudioService extends IAudioService.Stub {
                            Settings.Secure.UNSAFE_VOLUME_MUSIC_ACTIVE_MS, musicActiveMs,
                            UserHandle.USER_CURRENT);
                    break;
                case MSG_PERSIST_MICROPHONE_MUTE:
                    Settings.System.putIntForUser(mContentResolver,
                                                 Settings.System.MICROPHONE_MUTE,
                                                 msg.arg1,
                                                 msg.arg2);
                    break;
            }
        }
    }
+5 −5
Original line number Diff line number Diff line
@@ -318,10 +318,10 @@ public class SettingsProvider extends ContentProvider {
        }
    }

    private void checkUserRestrictions(String setting) {
    private void checkUserRestrictions(String setting, int userId) {
        String userRestriction = sRestrictedKeys.get(setting);
        if (!TextUtils.isEmpty(userRestriction)
            && mUserManager.hasUserRestriction(userRestriction)) {
            && mUserManager.hasUserRestriction(userRestriction, new UserHandle(userId))) {
            throw new SecurityException(
                    "Permission denial: user is restricted from changing this setting.");
        }
@@ -936,7 +936,7 @@ public class SettingsProvider extends ContentProvider {
        try {
            int numValues = values.length;
            for (int i = 0; i < numValues; i++) {
                checkUserRestrictions(values[i].getAsString(Settings.Secure.NAME));
                checkUserRestrictions(values[i].getAsString(Settings.Secure.NAME), callingUser);
                if (db.insert(args.table, null, values[i]) < 0) return 0;
                SettingsCache.populate(cache, values[i]);
                if (LOCAL_LOGV) Log.v(TAG, args.table + " <- " + values[i]);
@@ -1067,7 +1067,7 @@ public class SettingsProvider extends ContentProvider {
        // Check write permissions only after determining which table the insert will touch
        checkWritePermissions(args);

        checkUserRestrictions(name);
        checkUserRestrictions(name, desiredUserHandle);

        // The global table is stored under the owner, always
        if (TABLE_GLOBAL.equals(args.table)) {
@@ -1143,7 +1143,7 @@ public class SettingsProvider extends ContentProvider {
            callingUser = UserHandle.USER_OWNER;
        }
        checkWritePermissions(args);
        checkUserRestrictions(initialValues.getAsString(Settings.Secure.NAME));
        checkUserRestrictions(initialValues.getAsString(Settings.Secure.NAME), callingUser);

        final AtomicInteger mutationCount = sKnownMutationsInFlight.get(callingUser);
        mutationCount.incrementAndGet();
+28 −17
Original line number Diff line number Diff line
@@ -4600,7 +4600,6 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
    @Override
    public void setUserRestriction(ComponentName who, String key, boolean enabled) {
        final UserHandle userHandle = new UserHandle(UserHandle.getCallingUserId());

        synchronized (this) {
            if (who == null) {
                throw new NullPointerException("ComponentName is null");
@@ -4611,13 +4610,28 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
            if (!isDeviceOwner && DEVICE_OWNER_USER_RESTRICTIONS.contains(key)) {
                throw new SecurityException("Profile owners cannot set user restriction " + key);
            }
            boolean alreadyRestricted = mUserManager.hasUserRestriction(key, userHandle);

            IAudioService iAudioService = null;
            if (UserManager.DISALLOW_UNMUTE_MICROPHONE.equals(key)
                    || UserManager.DISALLOW_ADJUST_VOLUME.equals(key)) {
                iAudioService = IAudioService.Stub.asInterface(
                        ServiceManager.getService(Context.AUDIO_SERVICE));
            }

            if (enabled && !alreadyRestricted) {
                try {
                    if (UserManager.DISALLOW_UNMUTE_MICROPHONE.equals(key)) {
                        iAudioService.setMicrophoneMute(true, who.getPackageName());
                    } else if (UserManager.DISALLOW_ADJUST_VOLUME.equals(key)) {
                        iAudioService.setMasterMute(true, 0, who.getPackageName(), null);
                    }
                } catch (RemoteException re) {
                    Slog.e(LOG_TAG, "Failed to talk to AudioService.", re);
                }
            }
            long id = Binder.clearCallingIdentity();
            try {
                AudioManager audioManager =
                        (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
                boolean alreadyRestricted = mUserManager.hasUserRestriction(key);

                if (enabled && !alreadyRestricted) {
                    if (UserManager.DISALLOW_CONFIG_WIFI.equals(key)) {
                        Settings.Secure.putIntForUser(mContext.getContentResolver(),
@@ -4648,25 +4662,22 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
                        Settings.Secure.putIntForUser(mContext.getContentResolver(),
                                Settings.Secure.INSTALL_NON_MARKET_APPS, 0,
                                userHandle.getIdentifier());
                    } else if (UserManager.DISALLOW_UNMUTE_MICROPHONE.equals(key)) {
                        audioManager.setMicrophoneMute(true);
                    } else if (UserManager.DISALLOW_ADJUST_VOLUME.equals(key)) {
                        audioManager.setMasterMute(true);
                    }
                }

                mUserManager.setUserRestriction(key, enabled, userHandle);

            } finally {
                restoreCallingIdentity(id);
            }
            if (!enabled && alreadyRestricted) {
                try {
                    if (UserManager.DISALLOW_UNMUTE_MICROPHONE.equals(key)) {
                        audioManager.setMicrophoneMute(false);
                        iAudioService.setMicrophoneMute(false, who.getPackageName());
                    } else if (UserManager.DISALLOW_ADJUST_VOLUME.equals(key)) {
                        audioManager.setMasterMute(false);
                        iAudioService.setMasterMute(false, 0, who.getPackageName(), null);
                    }
                } catch (RemoteException re) {
                    Slog.e(LOG_TAG, "Failed to talk to AudioService.", re);
                }

            } finally {
                restoreCallingIdentity(id);
            }
        }
    }