diff options
| -rw-r--r-- | core/res/res/values/config.xml | 8 | ||||
| -rw-r--r-- | core/res/res/values/symbols.xml | 3 | ||||
| -rw-r--r-- | data/sounds/effects/InCallNotification.ogg | bin | 0 -> 6275 bytes | |||
| -rw-r--r-- | data/sounds/effects/ogg/InCallNotification.ogg | bin | 0 -> 6275 bytes | |||
| -rw-r--r-- | services/core/java/com/android/server/notification/NotificationManagerService.java | 64 | ||||
| -rw-r--r-- | services/tests/notification/src/com/android/server/notification/BuzzBeepBlinkTest.java | 15 |
6 files changed, 47 insertions, 43 deletions
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index 066c0512d0a1..95aa264639ac 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -2994,9 +2994,11 @@ <!-- Handle volume keys directly in Window Manager without passing them to the foreground app --> <bool name="config_handleVolumeKeysInWindowManager">false</bool> - <!-- Volume level of in-call notification tone playback, - relative to the overall voice call stream volume [0..100] --> - <integer name="config_inCallNotificationVolumeRelative">67</integer> + <!-- Volume level of in-call notification tone playback [0..1] --> + <item name="config_inCallNotificationVolume" format="float" type="dimen">.25</item> + + <!-- URI for in call notification sound --> + <string translatable="false" name="config_inCallNotificationSound">/system/media/audio/ui/InCallNotification.ogg</string> <!-- The OEM specified sensor type for the lift trigger to launch the camera app. --> <integer name="config_cameraLiftTriggerSensorType">-1</integer> diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index e67884d8e780..061413c60367 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -3039,7 +3039,8 @@ <java-symbol type="array" name="config_allowedSecureInstantAppSettings" /> <java-symbol type="bool" name="config_handleVolumeKeysInWindowManager" /> - <java-symbol type="integer" name="config_inCallNotificationVolumeRelative" /> + <java-symbol type="dimen" name="config_inCallNotificationVolume" /> + <java-symbol type="string" name="config_inCallNotificationSound" /> <java-symbol type="bool" name="config_dozeAlwaysOnDisplayAvailable" /> <java-symbol type="bool" name="config_displayBlanksAfterDoze" /> <java-symbol type="bool" name="config_displayBrightnessBucketsInDoze" /> diff --git a/data/sounds/effects/InCallNotification.ogg b/data/sounds/effects/InCallNotification.ogg Binary files differnew file mode 100644 index 000000000000..4481ccb25614 --- /dev/null +++ b/data/sounds/effects/InCallNotification.ogg diff --git a/data/sounds/effects/ogg/InCallNotification.ogg b/data/sounds/effects/ogg/InCallNotification.ogg Binary files differnew file mode 100644 index 000000000000..4481ccb25614 --- /dev/null +++ b/data/sounds/effects/ogg/InCallNotification.ogg diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 704978b9616f..719c36551077 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -93,10 +93,10 @@ import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.ParceledListSlice; import android.content.res.Resources; import android.database.ContentObserver; +import android.media.AudioAttributes; import android.media.AudioManager; import android.media.AudioManagerInternal; import android.media.IRingtonePlayer; -import android.media.ToneGenerator; import android.net.Uri; import android.os.Binder; import android.os.Build; @@ -194,6 +194,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; +import java.net.URI; import java.nio.charset.StandardCharsets; import java.util.ArrayDeque; import java.util.ArrayList; @@ -304,12 +305,12 @@ public class NotificationManagerService extends SystemService { // for enabling and disabling notification pulse behavior private boolean mScreenOn = true; - private boolean mInCall = false; + protected boolean mInCall = false; private boolean mNotificationPulseEnabled; - // for generating notification tones in-call - private ToneGenerator mInCallToneGenerator; - private final Object mInCallToneGeneratorLock = new Object(); + private Uri mInCallNotificationUri; + private AudioAttributes mInCallNotificationAudioAttributes; + private float mInCallNotificationVolume; // used as a mutex for access to all active notifications & listeners final Object mNotificationLock = new Object(); @@ -947,30 +948,6 @@ public class NotificationManagerService extends SystemService { mInCall = TelephonyManager.EXTRA_STATE_OFFHOOK .equals(intent.getStringExtra(TelephonyManager.EXTRA_STATE)); updateNotificationPulse(); - synchronized (mInCallToneGeneratorLock) { - if (mInCall) { - if (mInCallToneGenerator == null) { - int relativeToneVolume = getContext().getResources().getInteger( - R.integer.config_inCallNotificationVolumeRelative); - if (relativeToneVolume < ToneGenerator.MIN_VOLUME - || relativeToneVolume > ToneGenerator.MAX_VOLUME) { - relativeToneVolume = ToneGenerator.MAX_VOLUME; - } - try { - mInCallToneGenerator = new ToneGenerator( - AudioManager.STREAM_VOICE_CALL, relativeToneVolume); - } catch (RuntimeException e) { - Log.e(TAG, "Error creating local tone generator: " + e); - mInCallToneGenerator = null; - } - } - } else { - if (mInCallToneGenerator != null) { - mInCallToneGenerator.release(); - mInCallToneGenerator = null; - } - } - } } else if (action.equals(Intent.ACTION_USER_STOPPED)) { int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1); if (userHandle >= 0) { @@ -1277,6 +1254,15 @@ public class NotificationManagerService extends SystemService { VIBRATE_PATTERN_MAXLEN, DEFAULT_VIBRATE_PATTERN); + mInCallNotificationUri = Uri.parse("file://" + + resources.getString(R.string.config_inCallNotificationSound)); + mInCallNotificationAudioAttributes = new AudioAttributes.Builder() + .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) + .setUsage(AudioAttributes.USAGE_VOICE_COMMUNICATION) + .setFlags(AudioAttributes.FLAG_AUDIBILITY_ENFORCED) + .build(); + mInCallNotificationVolume = resources.getFloat(R.dimen.config_inCallNotificationVolume); + mUseAttentionLight = resources.getBoolean(R.bool.config_useAttentionLight); // Don't start allowing notifications until the setup wizard has run once. @@ -4152,21 +4138,21 @@ public class NotificationManagerService extends SystemService { mUserProfiles.isCurrentProfile(record.getUserId())); } - private void playInCallNotification() { + protected void playInCallNotification() { new Thread() { @Override public void run() { - // If toneGenerator creation fails, just continue the call - // without playing the notification sound. + final long identity = Binder.clearCallingIdentity(); try { - synchronized (mInCallToneGeneratorLock) { - if (mInCallToneGenerator != null) { - // limit this tone to 1 second; BEEP2 should in fact be much shorter - mInCallToneGenerator.startTone(ToneGenerator.TONE_PROP_BEEP2, 1000); - } + final IRingtonePlayer player = mAudioManager.getRingtonePlayer(); + if (player != null) { + player.play(new Binder(), mInCallNotificationUri, + mInCallNotificationAudioAttributes, + mInCallNotificationVolume, false); } - } catch (RuntimeException e) { - Log.w(TAG, "Exception from ToneGenerator: " + e); + } catch (RemoteException e) { + } finally { + Binder.restoreCallingIdentity(identity); } } }.start(); diff --git a/services/tests/notification/src/com/android/server/notification/BuzzBeepBlinkTest.java b/services/tests/notification/src/com/android/server/notification/BuzzBeepBlinkTest.java index 835603a9228b..529ac3a192ae 100644 --- a/services/tests/notification/src/com/android/server/notification/BuzzBeepBlinkTest.java +++ b/services/tests/notification/src/com/android/server/notification/BuzzBeepBlinkTest.java @@ -537,6 +537,21 @@ public class BuzzBeepBlinkTest extends NotificationTestCase { } @Test + public void testInCallNotification() throws Exception { + NotificationRecord r = getBeepyNotification(); + + // set up internal state + mService.buzzBeepBlinkLocked(r); + Mockito.reset(mRingtonePlayer); + + mService.mInCall = true; + mService.buzzBeepBlinkLocked(r); + + //verify(mService, times(1)).playInCallNotification(); + verifyNeverBeep(); // doesn't play normal beep + } + + @Test public void testNoDemoteSoundToVibrateIfVibrateGiven() throws Exception { NotificationRecord r = getBuzzyBeepyNotification(); assertTrue(r.getSound() != null); |