From a4efdf51958a39e6f897b1fcf6c88353753c9c21 Mon Sep 17 00:00:00 2001 From: Pavlin Radoslavov Date: Mon, 6 Feb 2017 15:37:01 -0800 Subject: [PATCH] Catch IllegalStateException when updating Bluetooth A2DP codec info Add an explicit check when calling getResources() inside updateBluetoothA2dpConfigurationValues(). This fixes a potential race condition - the latter could be called in background when processing intent update. Bug: 35021206 Test: Manual UI testing Change-Id: I38117c5b1e08f4b2ecfd7637bb3e34920aa0d296 --- .../android/settings/DevelopmentSettings.java | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/com/android/settings/DevelopmentSettings.java b/src/com/android/settings/DevelopmentSettings.java index 8d97a97cf61..f6c77a436f2 100644 --- a/src/com/android/settings/DevelopmentSettings.java +++ b/src/com/android/settings/DevelopmentSettings.java @@ -1825,6 +1825,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment BluetoothCodecConfig[] codecsLocalCapabilities = null; BluetoothCodecConfig[] codecsSelectableCapabilities = null; String streaming; + Resources resources = null; synchronized (mBluetoothA2dpLock) { if (mBluetoothA2dp != null) { @@ -1839,6 +1840,15 @@ public class DevelopmentSettings extends RestrictedSettingsFragment if (codecConfig == null) return; + try { + resources = getResources(); + } catch (IllegalStateException e) { + return; + } + if (resources == null) { + return; + } + // Update the Codec Type index = -1; switch (codecConfig.getCodecType()) { @@ -1862,8 +1872,8 @@ public class DevelopmentSettings extends RestrictedSettingsFragment break; } if (index >= 0) { - summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_summaries); - streaming = getResources().getString(R.string.bluetooth_select_a2dp_codec_streaming_label, summaries[index]); + summaries = resources.getStringArray(R.array.bluetooth_a2dp_codec_summaries); + streaming = resources.getString(R.string.bluetooth_select_a2dp_codec_streaming_label, summaries[index]); mBluetoothSelectA2dpCodec.setSummary(streaming); } @@ -1889,8 +1899,8 @@ public class DevelopmentSettings extends RestrictedSettingsFragment break; } if (index >= 0) { - summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_sample_rate_summaries); - streaming = getResources().getString(R.string.bluetooth_select_a2dp_codec_streaming_label, summaries[index]); + summaries = resources.getStringArray(R.array.bluetooth_a2dp_codec_sample_rate_summaries); + streaming = resources.getString(R.string.bluetooth_select_a2dp_codec_streaming_label, summaries[index]); mBluetoothSelectA2dpSampleRate.setSummary(streaming); } @@ -1911,8 +1921,8 @@ public class DevelopmentSettings extends RestrictedSettingsFragment break; } if (index >= 0) { - summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_bits_per_sample_summaries); - streaming = getResources().getString(R.string.bluetooth_select_a2dp_codec_streaming_label, summaries[index]); + summaries = resources.getStringArray(R.array.bluetooth_a2dp_codec_bits_per_sample_summaries); + streaming = resources.getString(R.string.bluetooth_select_a2dp_codec_streaming_label, summaries[index]); mBluetoothSelectA2dpBitsPerSample.setSummary(streaming); } @@ -1930,8 +1940,8 @@ public class DevelopmentSettings extends RestrictedSettingsFragment break; } if (index >= 0) { - summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_channel_mode_summaries); - streaming = getResources().getString(R.string.bluetooth_select_a2dp_codec_streaming_label, summaries[index]); + summaries = resources.getStringArray(R.array.bluetooth_a2dp_codec_channel_mode_summaries); + streaming = resources.getString(R.string.bluetooth_select_a2dp_codec_streaming_label, summaries[index]); mBluetoothSelectA2dpChannelMode.setSummary(streaming); } @@ -1956,8 +1966,8 @@ public class DevelopmentSettings extends RestrictedSettingsFragment break; } if (index >= 0) { - summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_ldac_playback_quality_summaries); - streaming = getResources().getString(R.string.bluetooth_select_a2dp_codec_streaming_label, summaries[index]); + summaries = resources.getStringArray(R.array.bluetooth_a2dp_codec_ldac_playback_quality_summaries); + streaming = resources.getString(R.string.bluetooth_select_a2dp_codec_streaming_label, summaries[index]); mBluetoothSelectA2dpLdacPlaybackQuality.setSummary(streaming); } }