diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml index a49ea0bd55fb0..9af95059465c1 100644 --- a/core/res/res/values/strings.xml +++ b/core/res/res/values/strings.xml @@ -4602,24 +4602,13 @@ - "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." - - - - - "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." - - - - - "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" - "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" - Lowered to safer volume + Volume lowered to safer level - The volume has been high for longer than recommended + Headphone volume has been high for longer than recommended + + Headphone volume has exceeded the safe limit for this week + + Keep listening + + Lower volume diff --git a/packages/SystemUI/src/com/android/systemui/volume/CsdWarningDialog.java b/packages/SystemUI/src/com/android/systemui/volume/CsdWarningDialog.java index db7fa14b4cffb..fb5a71c0b06fe 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; * * 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 9cf3e443320d2..b0bd83e1799f6 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 20393250b5b78..f0c5d4f3322de 100644 --- a/services/core/java/com/android/server/audio/AudioService.java +++ b/services/core/java/com/android/server/audio/AudioService.java @@ -10586,7 +10586,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 {