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

Commit c1d41662 authored by Eric Laurent's avatar Eric Laurent
Browse files

Fix issue 5012047: silent mode mutes music

Implemented different silent mode behaviors for tablets and phones.
The behavior inherited from Honeycomb was for tablets only and
was muting music in silent mode.

Change-Id: Ib053e7b70ca02190debc87648ab8a163f9d39577
parent f55df0e2
Loading
Loading
Loading
Loading
+16 −9
Original line number Diff line number Diff line
@@ -332,10 +332,10 @@ public class AudioService extends IAudioService.Stub {
                SOUND_EFFECT_DEFAULT_VOLUME_DB);

        mVolumePanel = new VolumePanel(context, this);
        mSettingsObserver = new SettingsObserver();
        mForcedUseForComm = AudioSystem.FORCE_NONE;
        createAudioSystemThread();
        readPersistedSettings();
        mSettingsObserver = new SettingsObserver();
        createStreamStates();
        // Call setMode() to initialize mSetModeDeathHandlers
        mMode = AudioSystem.MODE_INVALID;
@@ -427,15 +427,20 @@ public class AudioService extends IAudioService.Stub {

        mVibrateSetting = System.getInt(cr, System.VIBRATE_ON, 0);

        // make sure settings for ringer mode are consistent with device type: non voice capable
        // devices (tablets) include media stream in silent mode whereas phones don't.
        mRingerModeAffectedStreams = Settings.System.getInt(cr,
                Settings.System.MODE_RINGER_STREAMS_AFFECTED,
                ((1 << AudioSystem.STREAM_RING)|(1 << AudioSystem.STREAM_NOTIFICATION)|
                 (1 << AudioSystem.STREAM_SYSTEM)|(1 << AudioSystem.STREAM_SYSTEM_ENFORCED)|
                 (1 << AudioSystem.STREAM_MUSIC)));

        if (!mVoiceCapable) {
                 (1 << AudioSystem.STREAM_SYSTEM)|(1 << AudioSystem.STREAM_SYSTEM_ENFORCED)));
        if (mVoiceCapable) {
            mRingerModeAffectedStreams &= ~(1 << AudioSystem.STREAM_MUSIC);
        } else {
            mRingerModeAffectedStreams |= (1 << AudioSystem.STREAM_MUSIC);
        }
        Settings.System.putInt(cr,
                Settings.System.MODE_RINGER_STREAMS_AFFECTED, mRingerModeAffectedStreams);

        mMuteAffectedStreams = System.getInt(cr,
                System.MUTE_STREAMS_AFFECTED,
                ((1 << AudioSystem.STREAM_MUSIC)|(1 << AudioSystem.STREAM_RING)|(1 << AudioSystem.STREAM_SYSTEM)));
@@ -2167,11 +2172,13 @@ public class AudioService extends IAudioService.Stub {
            synchronized (mSettingsLock) {
                int ringerModeAffectedStreams = Settings.System.getInt(mContentResolver,
                       Settings.System.MODE_RINGER_STREAMS_AFFECTED,
                        0);
                if (!mVoiceCapable) {
                       ((1 << AudioSystem.STREAM_RING)|(1 << AudioSystem.STREAM_NOTIFICATION)|
                       (1 << AudioSystem.STREAM_SYSTEM)|(1 << AudioSystem.STREAM_SYSTEM_ENFORCED)));
                if (mVoiceCapable) {
                    ringerModeAffectedStreams &= ~(1 << AudioSystem.STREAM_MUSIC);
                } else {
                    ringerModeAffectedStreams |= (1 << AudioSystem.STREAM_MUSIC);
                }

                if (ringerModeAffectedStreams != mRingerModeAffectedStreams) {
                    /*
                     * Ensure all stream types that should be affected by ringer mode
+53 −8
Original line number Diff line number Diff line
@@ -63,7 +63,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
    // database gets upgraded properly. At a minimum, please confirm that 'upgradeVersion'
    // is properly propagated through your change.  Not doing so will result in a loss of user
    // settings.
    private static final int DATABASE_VERSION = 66;
    private static final int DATABASE_VERSION = 67;

    private Context mContext;

@@ -861,6 +861,36 @@ public class DatabaseHelper extends SQLiteOpenHelper {
            upgradeVersion = 66;
        }

        if (upgradeVersion == 66) {
            // This upgrade makes sure that MODE_RINGER_STREAMS_AFFECTED and
            // NOTIFICATIONS_USE_RING_VOLUME settings are set according to device voice capability
             db.beginTransaction();
             try {
                 int ringerModeAffectedStreams = (1 << AudioManager.STREAM_RING) |
                                                 (1 << AudioManager.STREAM_NOTIFICATION) |
                                                 (1 << AudioManager.STREAM_SYSTEM) |
                                                 (1 << AudioManager.STREAM_SYSTEM_ENFORCED);
                 if (!mContext.getResources().getBoolean(
                         com.android.internal.R.bool.config_voice_capable)) {
                     ringerModeAffectedStreams |= (1 << AudioManager.STREAM_MUSIC);

                     db.execSQL("DELETE FROM system WHERE name='"
                             + Settings.System.NOTIFICATIONS_USE_RING_VOLUME + "'");
                     db.execSQL("INSERT INTO system ('name', 'value') values ('"
                             + Settings.System.NOTIFICATIONS_USE_RING_VOLUME + "', '1')");
                 }
                 db.execSQL("DELETE FROM system WHERE name='"
                         + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "'");
                 db.execSQL("INSERT INTO system ('name', 'value') values ('"
                         + Settings.System.MODE_RINGER_STREAMS_AFFECTED + "', '"
                         + String.valueOf(ringerModeAffectedStreams) + "')");
                 db.setTransactionSuccessful();
             } finally {
                 db.endTransaction();
             }
             upgradeVersion = 67;
         }

        // *** Remember to update DATABASE_VERSION above!

        if (upgradeVersion != currentVersion) {
@@ -1121,11 +1151,21 @@ public class DatabaseHelper extends SQLiteOpenHelper {
    
            loadVibrateSetting(db, false);
    
            // By default, only the ring/notification, system and music streams are affected
            // By default:
            // - ringtones, notification, system and music streams are affected by ringer mode
            // on non voice capable devices (tablets)
            // - ringtones, notification and system streams are affected by ringer mode
            // on voice capable devices (phones)
            int ringerModeAffectedStreams = (1 << AudioManager.STREAM_RING) |
                                            (1 << AudioManager.STREAM_NOTIFICATION) |
                                            (1 << AudioManager.STREAM_SYSTEM) |
                                            (1 << AudioManager.STREAM_SYSTEM_ENFORCED);
            if (!mContext.getResources().getBoolean(
                    com.android.internal.R.bool.config_voice_capable)) {
                ringerModeAffectedStreams |= (1 << AudioManager.STREAM_MUSIC);
            }
            loadSetting(stmt, Settings.System.MODE_RINGER_STREAMS_AFFECTED,
                    (1 << AudioManager.STREAM_RING) | (1 << AudioManager.STREAM_NOTIFICATION) |
                    (1 << AudioManager.STREAM_SYSTEM) | (1 << AudioManager.STREAM_SYSTEM_ENFORCED) |
                    (1 << AudioManager.STREAM_MUSIC));
                    ringerModeAffectedStreams);

            loadSetting(stmt, Settings.System.MUTE_STREAMS_AFFECTED,
                    ((1 << AudioManager.STREAM_MUSIC) |
@@ -1232,8 +1272,13 @@ public class DatabaseHelper extends SQLiteOpenHelper {
                    R.bool.def_vibrate_in_silent);

            // Set notification volume to follow ringer volume by default
            if (mContext.getResources().getBoolean(
                    com.android.internal.R.bool.config_voice_capable)) {
                loadBooleanSetting(stmt, Settings.System.NOTIFICATIONS_USE_RING_VOLUME,
                        R.bool.def_notifications_use_ring_volume);
            } else {
                loadSetting(stmt, Settings.System.NOTIFICATIONS_USE_RING_VOLUME, "1");
            }

            loadIntegerSetting(stmt, Settings.System.POINTER_SPEED,
                    R.integer.def_pointer_speed);