summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/res/res/values/strings.xml15
-rw-r--r--packages/SystemUI/res/values/strings.xml12
-rw-r--r--packages/SystemUI/src/com/android/systemui/volume/CsdWarningDialog.java40
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/volume/CsdWarningDialogTest.java8
-rw-r--r--services/core/java/com/android/server/audio/AudioService.java2
5 files changed, 43 insertions, 34 deletions
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index 027d4f8ab2b5..faaa2e8cc0f5 100644
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -4602,24 +4602,13 @@
<!-- Message shown in dialog when user goes over a multiple of 100% of the safe weekly dose -->
<string name="csd_dose_reached_warning" product="default">
- "Warning,\nYou have exceeded the amount of loud sound signals one can safely listen to in a week over headphones.\n\nGoing over this limit will permanently damage your hearing."
- </string>
-
- <!-- Message shown in dialog when user goes over 500% of the safe weekly dose and volume is
- automatically lowered -->
- <string name="csd_dose_repeat_warning" product="default">
- "Warning,\nYou have exceeded 5 times the amount of loud sound signals one can safely listen to in a week over headphones.\n\nVolume has been lowered to protect your hearing."
- </string>
-
- <!-- Message shown in dialog when user's dose enters RS2 -->
- <string name="csd_entering_RS2_warning" product="default">
- "The level at which you are listening to media can result in hearing damage when sustained over long periods of time.\n\nContinuing to play at this level for long periods of time could damage your hearing."
+ "Keep listening at a high volume?\n\nHeadphone volume has been high for longer than recommended, which can damage your hearing"
</string>
<!-- Message shown in dialog when user is momentarily listening to unsafely loud content
over headphones -->
<string name="csd_momentary_exposure_warning" product="default">
- "Warning,\nYou are currently listening to loud content played at an unsafe level.\n\nContinuing to listen this loud will permanently damage your hearing."
+ "Loud sound detected\n\nHeadphone volume has been higher than recommended, which can damage your hearing"
</string>
<!-- Dialog title for dialog shown when the accessibility shortcut is activated, and we want
diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml
index 70fdc2070b7a..cbc73faa46af 100644
--- a/packages/SystemUI/res/values/strings.xml
+++ b/packages/SystemUI/res/values/strings.xml
@@ -1312,9 +1312,17 @@
<string name="volume_panel_dialog_settings_button">Settings</string>
<!-- Title for notification after audio lowers -->
- <string name="csd_lowered_title" product="default">Lowered to safer volume</string>
+ <string name="csd_lowered_title" product="default">Volume lowered to safer level</string>
<!-- Message shown in notification after system lowers audio -->
- <string name="csd_system_lowered_text" product="default">The volume has been high for longer than recommended</string>
+ <string name="csd_system_lowered_text" product="default">Headphone volume has been high for longer than recommended</string>
+ <!-- Message shown in notification after system lowers audio after 500% of
+ sound dosage is reached.
+ -->
+ <string name="csd_500_system_lowered_text" product="default">Headphone volume has exceeded the safe limit for this week</string>
+ <!-- Message for sound dose warning dialog button to keep listening -->
+ <string name="csd_button_keep_listening" product="default">Keep listening</string>
+ <!-- Message for sound dose warning dialog button to lower volume -->
+ <string name="csd_button_lower_volume" product="default">Lower volume</string>
<!-- content description for audio output chooser [CHAR LIMIT=NONE]-->
diff --git a/packages/SystemUI/src/com/android/systemui/volume/CsdWarningDialog.java b/packages/SystemUI/src/com/android/systemui/volume/CsdWarningDialog.java
index db7fa14b4cff..fb5a71c0b06f 100644
--- a/packages/SystemUI/src/com/android/systemui/volume/CsdWarningDialog.java
+++ b/packages/SystemUI/src/com/android/systemui/volume/CsdWarningDialog.java
@@ -50,7 +50,6 @@ import dagger.assisted.AssistedInject;
* <ul>
* <li>{@link AudioManager#CSD_WARNING_DOSE_REACHED_1X}</li>
* <li>{@link AudioManager#CSD_WARNING_DOSE_REPEATED_5X}</li>
- * <li>{@link AudioManager#CSD_WARNING_ACCUMULATION_START}</li>
* <li>{@link AudioManager#CSD_WARNING_MOMENTARY_EXPOSURE}</li>
* </ul>
* Rather than basing volume safety messages on a fixed volume index, the CSD feature derives its
@@ -123,9 +122,9 @@ public class CsdWarningDialog extends SystemUIDialog
setShowForAllUsers(true);
setMessage(mContext.getString(getStringForWarning(csdWarning)));
setButton(DialogInterface.BUTTON_POSITIVE,
- mContext.getString(com.android.internal.R.string.yes), this);
+ mContext.getString(R.string.csd_button_keep_listening), this);
setButton(DialogInterface.BUTTON_NEGATIVE,
- mContext.getString(com.android.internal.R.string.no), this);
+ mContext.getString(R.string.csd_button_lower_volume), this);
setOnDismissListener(this);
final IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
@@ -138,7 +137,7 @@ public class CsdWarningDialog extends SystemUIDialog
// unlike on the 5x dose repeat, level is only reduced to RS1 when the warning
// is not acknowledged quickly enough
mAudioManager.lowerVolumeToRs1();
- sendNotification();
+ sendNotification(/*for5XCsd=*/false);
}
};
} else {
@@ -152,6 +151,16 @@ public class CsdWarningDialog extends SystemUIDialog
}
}
+ @Override
+ public void show() {
+ if (mCsdWarning == AudioManager.CSD_WARNING_DOSE_REPEATED_5X) {
+ // only show a notification in case we reached 500% of dose
+ show5XNotification();
+ return;
+ }
+ super.show();
+ }
+
// NOT overriding onKeyDown as we're not allowing a dismissal on any key other than
// VOLUME_DOWN, and for this, we don't need to track if it's the start of a new
// key down -> up sequence
@@ -177,8 +186,8 @@ public class CsdWarningDialog extends SystemUIDialog
@Override
public void onClick(DialogInterface dialog, int which) {
- if (which == DialogInterface.BUTTON_POSITIVE) {
- Log.d(TAG, "OK pressed for CSD warning " + mCsdWarning);
+ if (which == DialogInterface.BUTTON_NEGATIVE) {
+ Log.d(TAG, "Lower volume pressed for CSD warning " + mCsdWarning);
dismiss();
}
@@ -235,27 +244,34 @@ public class CsdWarningDialog extends SystemUIDialog
switch (csdWarning) {
case AudioManager.CSD_WARNING_DOSE_REACHED_1X:
return com.android.internal.R.string.csd_dose_reached_warning;
- case AudioManager.CSD_WARNING_DOSE_REPEATED_5X:
- return com.android.internal.R.string.csd_dose_repeat_warning;
case AudioManager.CSD_WARNING_MOMENTARY_EXPOSURE:
return com.android.internal.R.string.csd_momentary_exposure_warning;
- case AudioManager.CSD_WARNING_ACCUMULATION_START:
- return com.android.internal.R.string.csd_entering_RS2_warning;
}
Log.e(TAG, "Invalid CSD warning event " + csdWarning, new Exception());
return com.android.internal.R.string.csd_dose_reached_warning;
}
+ /** When 5X CSD is reached we lower the volume and show a notification. **/
+ private void show5XNotification() {
+ if (mCsdWarning != AudioManager.CSD_WARNING_DOSE_REPEATED_5X) {
+ Log.w(TAG, "Notification dose repeat 5x is not shown for " + mCsdWarning);
+ return;
+ }
+
+ mAudioManager.lowerVolumeToRs1();
+ sendNotification(/*for5XCsd=*/true);
+ }
/**
* In case user did not respond to the dialog, they still need to know volume was lowered.
*/
- private void sendNotification() {
+ private void sendNotification(boolean for5XCsd) {
Intent intent = new Intent(Settings.ACTION_SOUND_SETTINGS);
PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, intent,
FLAG_IMMUTABLE);
- String text = mContext.getString(R.string.csd_system_lowered_text);
+ String text = for5XCsd ? mContext.getString(R.string.csd_500_system_lowered_text)
+ : mContext.getString(R.string.csd_system_lowered_text);
String title = mContext.getString(R.string.csd_lowered_title);
Notification.Builder builder =
diff --git a/packages/SystemUI/tests/src/com/android/systemui/volume/CsdWarningDialogTest.java b/packages/SystemUI/tests/src/com/android/systemui/volume/CsdWarningDialogTest.java
index 9cf3e443320d..b0bd83e1799f 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/volume/CsdWarningDialogTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/volume/CsdWarningDialogTest.java
@@ -22,7 +22,6 @@ import static android.media.AudioManager.CSD_WARNING_DOSE_REPEATED_5X;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import android.app.Notification;
@@ -75,17 +74,14 @@ public class CsdWarningDialogTest extends SysuiTestCase {
}
@Test
- public void create5XCsdDiSalogAndWait_willNotSendNotification() {
+ public void create5XCsdDiSalogAndWait_willSendNotification() {
FakeExecutor executor = new FakeExecutor(new FakeSystemClock());
CsdWarningDialog dialog = new CsdWarningDialog(CSD_WARNING_DOSE_REPEATED_5X, mContext,
mAudioManager, mNotificationManager, executor, null);
dialog.show();
- executor.advanceClockToLast();
- executor.runAllReady();
- dialog.dismiss();
- verify(mNotificationManager, never()).notify(
+ verify(mNotificationManager).notify(
eq(SystemMessageProto.SystemMessage.NOTE_CSD_LOWER_AUDIO), any(Notification.class));
}
}
diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java
index 31403871ac90..a72187399acd 100644
--- a/services/core/java/com/android/server/audio/AudioService.java
+++ b/services/core/java/com/android/server/audio/AudioService.java
@@ -10605,7 +10605,7 @@ public class AudioService extends IAudioService.Stub
new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_MEDIA).build(), true);
final int nativeDeviceType;
final AudioDeviceAttributes ada;
- if (devices.isEmpty()) {
+ if (!devices.isEmpty()) {
ada = devices.get(0);
nativeDeviceType = ada.getInternalType();
} else {