OSDN Git Service

Settings : Fix linked volume crash + inconsistent state
authorDanesh M <daneshm90@gmail.com>
Thu, 28 Jan 2016 18:37:44 +0000 (10:37 -0800)
committerGerrit Code Review <gerrit@cyanogenmod.org>
Thu, 28 Jan 2016 20:35:19 +0000 (12:35 -0800)
- Ensure we fetch from Secure, not System
- Don't initialize every time we toggle
- Set the checkbox state from Settings value since
  the preference assumes a default of 0

CYNGNOS-1638

Change-Id: Ia519cef2295a6b6083b2b168f4c16df78f423cee

src/com/android/settings/notification/SoundSettings.java

index 679eb97..bc8eea4 100644 (file)
@@ -139,7 +139,7 @@ public class SoundSettings extends SettingsPreferenceFragment implements Indexab
     private int mLockscreenSelectedValue;
     private ComponentName mSuppressor;
     private int mRingerMode = -1;
-
+    private SwitchPreference mVolumeLinkNotificationSwitch;
     private UserManager mUserManager;
 
     @Override
@@ -174,6 +174,8 @@ public class SoundSettings extends SettingsPreferenceFragment implements Indexab
             mRingPreference =
                     initVolumePreference(KEY_RING_VOLUME, AudioManager.STREAM_RING,
                             com.android.internal.R.drawable.ic_audio_ring_notif_mute);
+            mVolumeLinkNotificationSwitch = (SwitchPreference)
+                    volumes.findPreference(KEY_VOLUME_LINK_NOTIFICATION);
         } else {
             volumes.removePreference(volumes.findPreference(KEY_RING_VOLUME));
             volumes.removePreference(volumes.findPreference(KEY_VOLUME_LINK_NOTIFICATION));
@@ -248,17 +250,17 @@ public class SoundSettings extends SettingsPreferenceFragment implements Indexab
     }
 
     private void updateNotificationPreferenceState() {
-        mNotificationPreference = initVolumePreference(KEY_NOTIFICATION_VOLUME,
-                AudioManager.STREAM_NOTIFICATION,
-                com.android.internal.R.drawable.ic_audio_ring_notif_mute);
+        if (mNotificationPreference == null) {
+            mNotificationPreference = initVolumePreference(KEY_NOTIFICATION_VOLUME,
+                    AudioManager.STREAM_NOTIFICATION,
+                    com.android.internal.R.drawable.ic_audio_ring_notif_mute);
+        }
 
         if (mVoiceCapable) {
-            final boolean enabled = Settings.System.getInt(getContentResolver(),
+            final boolean enabled = Settings.Secure.getInt(getContentResolver(),
                     Settings.Secure.VOLUME_LINK_NOTIFICATION, 1) == 1;
-
-            if (mNotificationPreference != null) {
-                boolean show = !enabled;
-                mNotificationPreference.setEnabled(show);
+            if (mVolumeLinkNotificationSwitch != null){
+                mVolumeLinkNotificationSwitch.setChecked(enabled);
             }
         }
     }