Volume dialog controller: make loading of stream names more robust
The loading of the stream type volume names assumes there are as many read as declared stream types. Verify this is the case, if not, complete the array of names with empty strings, or remove unneeded entries. Test: boot in non en-US language Bug: 33260083 Change-Id: I6632eadd34c4b8af2c8fd01ae7eae45fc513b3e1
This commit is contained in:
@@ -1126,6 +1126,7 @@
|
||||
<item></item> <!-- STREAM_SYSTEM_ENFORCED -->
|
||||
<item></item> <!-- STREAM_DTMF -->
|
||||
<item></item> <!-- STREAM_TTS -->
|
||||
<item>Accessibility</item> <!-- STREAM_ACCESSIBILITY -->
|
||||
</string-array>
|
||||
|
||||
<string name="volume_stream_muted" translatable="false">%s silent</string>
|
||||
|
||||
@@ -78,6 +78,7 @@ public class VolumeDialogController {
|
||||
AudioSystem.STREAM_SYSTEM_ENFORCED,
|
||||
AudioSystem.STREAM_TTS,
|
||||
AudioSystem.STREAM_VOICE_CALL,
|
||||
AudioSystem.STREAM_ACCESSIBILITY,
|
||||
};
|
||||
|
||||
private final HandlerThread mWorkerThread;
|
||||
@@ -119,7 +120,26 @@ public class VolumeDialogController {
|
||||
mObserver = new SettingObserver(mWorker);
|
||||
mObserver.init();
|
||||
mReceiver.init();
|
||||
mStreamTitles = mContext.getResources().getStringArray(R.array.volume_stream_titles);
|
||||
final String[] titles =
|
||||
mContext.getResources().getStringArray(R.array.volume_stream_titles);
|
||||
if (STREAMS.length == titles.length) {
|
||||
mStreamTitles = titles;
|
||||
} else if (STREAMS.length > titles.length) {
|
||||
Log.e(TAG, String.format("Missing stream titles (found %d, expected %d): "
|
||||
+ " invalid resources for volume_stream_titles",
|
||||
titles.length, STREAMS.length));
|
||||
mStreamTitles = new String[STREAMS.length];
|
||||
System.arraycopy(titles, 0, mStreamTitles, 0, titles.length);
|
||||
for (int i = titles.length ; i < STREAMS.length ; i++) {
|
||||
mStreamTitles[i] = "";
|
||||
}
|
||||
} else { // STREAMS.length < titles.length
|
||||
Log.e(TAG, String.format("Too many stream titles (found %d, expected %d): "
|
||||
+ " invalid resources for volume_stream_titles",
|
||||
titles.length, STREAMS.length));
|
||||
mStreamTitles = new String[STREAMS.length];
|
||||
System.arraycopy(titles, 0, mStreamTitles, 0, STREAMS.length);
|
||||
}
|
||||
mVibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
|
||||
mHasVibrator = mVibrator != null && mVibrator.hasVibrator();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user