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

Commit 2362bdf2 authored by Andy Hung's avatar Andy Hung Committed by Android (Google) Code Review
Browse files

Merge "Make master mono controlled through settings" into nyc-dev

parents 7006b01f 7b98e9a7
Loading
Loading
Loading
Loading
+0 −43
Original line number Diff line number Diff line
@@ -176,16 +176,6 @@ public class AudioManager {
    public static final String MASTER_MUTE_CHANGED_ACTION =
        "android.media.MASTER_MUTE_CHANGED_ACTION";

    /**
     * @hide Broadcast intent when the master mono state changes.
     * Includes the new mono state
     *
     * @see #EXTRA_MASTER_MONO
     */
    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    public static final String MASTER_MONO_CHANGED_ACTION =
        "android.media.MASTER_MONO_CHANGED_ACTION";

    /**
     * The new vibrate setting for a particular type.
     *
@@ -264,13 +254,6 @@ public class AudioManager {
    public static final String EXTRA_STREAM_VOLUME_MUTED =
        "android.media.EXTRA_STREAM_VOLUME_MUTED";

    /**
     * @hide The new master mono state for the master mono changed intent.
     * Value is boolean
     */
    public static final String EXTRA_MASTER_MONO =
        "android.media.EXTRA_MASTER_MONO";

    /**
     * Broadcast Action: Wired Headset plugged in or unplugged.
     *
@@ -898,17 +881,6 @@ public class AudioManager {
        }
    }

    /** @hide */
    public void setMasterMono(boolean mono) {
        IAudioService service = getService();
        try {
            service.setMasterMono(mono, getContext().getOpPackageName(),
                    UserHandle.getCallingUserId());
        } catch (RemoteException e) {
            Log.e(TAG, "Dead object in setMasterMono", e);
        }
    }

    /**
     * Returns the current ringtone mode.
     *
@@ -1170,21 +1142,6 @@ public class AudioManager {
        }
    }

    /**
     * get master mono state.
     *
     * @hide
     */
    public boolean isMasterMono() {
        IAudioService service = getService();
        try {
            return service.isMasterMono();
        } catch (RemoteException e) {
            Log.e(TAG, "Dead object in isMasterMono", e);
            return false;
        }
    }

    /**
     * forces the stream controlled by hard volume keys
     * specifying streamType == -1 releases control to the
+0 −4
Original line number Diff line number Diff line
@@ -54,10 +54,6 @@ interface IAudioService {

    void setMasterMute(boolean mute, int flags, String callingPackage, int userId);

    boolean isMasterMono();

    void setMasterMono(boolean mute, String callingPackage, int userId);

    int getStreamVolume(int streamType);

    int getStreamMinVolume(int streamType);
+15 −65
Original line number Diff line number Diff line
@@ -222,7 +222,6 @@ public class AudioService extends IAudioService.Stub {
    private static final int MSG_UNMUTE_STREAM = 24;
    private static final int MSG_DYN_POLICY_MIX_STATE_UPDATE = 25;
    private static final int MSG_INDICATE_SYSTEM_READY = 26;
    private static final int MSG_PERSIST_MASTER_MONO = 27;
    // start of messages handled under wakelock
    //   these messages can only be queued, i.e. sent with queueMsgUnderWakeLock(),
    //   and not with sendMsg(..., ..., SENDMSG_QUEUE, ...)
@@ -827,10 +826,7 @@ public class AudioService extends IAudioService.Stub {
        }

        // Restore mono mode
        final boolean masterMono = System.getIntForUser(
                mContentResolver, System.MASTER_MONO,
                0 /* default */, UserHandle.USER_CURRENT) == 1;
        AudioSystem.setMasterMono(masterMono);
        updateMasterMono(mContentResolver);

        // Restore ringer mode
        setRingerModeInt(getRingerModeInternal(), false);
@@ -1015,6 +1011,16 @@ public class AudioService extends IAudioService.Stub {
                0);
    }

    private void updateMasterMono(ContentResolver cr)
    {
        final boolean masterMono = System.getIntForUser(
                cr, System.MASTER_MONO, 0 /* default */, UserHandle.USER_CURRENT) == 1;
        if (DEBUG_VOL) {
            Log.d(TAG, String.format("Master mono %b", masterMono));
        }
        AudioSystem.setMasterMono(masterMono);
    }

    private void readPersistedSettings() {
        final ContentResolver cr = mContentResolver;

@@ -1091,13 +1097,7 @@ public class AudioService extends IAudioService.Stub {
        }
        AudioSystem.muteMicrophone(microphoneMute);

        final boolean masterMono = System.getIntForUser(
                cr, System.MASTER_MONO, 0 /* default */, UserHandle.USER_CURRENT) == 1;
        if (DEBUG_VOL) {
            Log.d(TAG, String.format("Master mono %b, user=%d", masterMono, currentUser));
        }
        AudioSystem.setMasterMono(masterMono);
        broadcastMasterMonoStatus(masterMono);
        updateMasterMono(cr);

        // Each stream will read its own persisted settings

@@ -1855,52 +1855,6 @@ public class AudioService extends IAudioService.Stub {
                userId);
    }

    /** @hide */
    public boolean isMasterMono() {
        return AudioSystem.getMasterMono();
    }

    /** @hide */
    public void setMasterMono(boolean mono, String callingPackage, int userId) {
        int callingUid = Binder.getCallingUid();
        // If we are being called by the system check for user we are going to change
        // so we handle user restrictions correctly.
        if (callingUid == android.os.Process.SYSTEM_UID) {
            callingUid = UserHandle.getUid(userId, UserHandle.getAppId(callingUid));
        }

        if (userId != UserHandle.getCallingUserId() &&
                mContext.checkCallingOrSelfPermission(
                        android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
                != PackageManager.PERMISSION_GRANTED) {
            return;
        }
        if (DEBUG_VOL) {
            Log.d(TAG, String.format("Master mono %b, user=%d", mono, userId));
        }

        if (getCurrentUserId() == userId) {
            if (mono != AudioSystem.getMasterMono()) {
                AudioSystem.setMasterMono(mono);
                // Post a persist master mono msg
                sendMsg(mAudioHandler, MSG_PERSIST_MASTER_MONO, SENDMSG_REPLACE, mono ? 1
                        : 0 /* value */, userId, null /* obj */, 0 /* delay */);
                // notify apps and settings
                broadcastMasterMonoStatus(mono);
            }
        } else {
            // Post a persist master mono msg
            sendMsg(mAudioHandler, MSG_PERSIST_MASTER_MONO, SENDMSG_REPLACE, mono ? 1
                    : 0 /* value */, userId, null /* obj */, 0 /* delay */);
        }
    }

    private void broadcastMasterMonoStatus(boolean mono) {
        Intent intent = new Intent(AudioManager.MASTER_MONO_CHANGED_ACTION);
        intent.putExtra(AudioManager.EXTRA_MASTER_MONO, mono);
        sendBroadcastToAll(intent);
    }

    /** @see AudioManager#getStreamVolume(int) */
    public int getStreamVolume(int streamType) {
        ensureValidStreamType(streamType);
@@ -4641,13 +4595,6 @@ public class AudioService extends IAudioService.Stub {
                case MSG_DYN_POLICY_MIX_STATE_UPDATE:
                    onDynPolicyMixStateUpdate((String) msg.obj, msg.arg1);
                    break;

                case MSG_PERSIST_MASTER_MONO:
                    Settings.System.putIntForUser(mContentResolver,
                                                 Settings.System.MASTER_MONO,
                                                 msg.arg1 /* value */,
                                                 msg.arg2 /* userHandle */);
                    break;
            }
        }
    }
@@ -4660,6 +4607,8 @@ public class AudioService extends IAudioService.Stub {
                Settings.System.MODE_RINGER_STREAMS_AFFECTED), false, this);
            mContentResolver.registerContentObserver(Settings.Global.getUriFor(
                Settings.Global.DOCK_AUDIO_MEDIA_ENABLED), false, this);
            mContentResolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.MASTER_MONO), false, this);
        }

        @Override
@@ -4678,6 +4627,7 @@ public class AudioService extends IAudioService.Stub {
                    setRingerModeInt(getRingerModeInternal(), false);
                }
                readDockAudioSettings(mContentResolver);
                updateMasterMono(mContentResolver);
            }
        }
    }