diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index 066c0512d0a19..95aa264639ac2 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -2994,9 +2994,11 @@
false
-
- 67
+
+ - .25
+
+
+ /system/media/audio/ui/InCallNotification.ogg
-1
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index e67884d8e7804..061413c603677 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -3039,7 +3039,8 @@
-
+
+
diff --git a/data/sounds/effects/InCallNotification.ogg b/data/sounds/effects/InCallNotification.ogg
new file mode 100644
index 0000000000000..4481ccb256146
Binary files /dev/null and b/data/sounds/effects/InCallNotification.ogg differ
diff --git a/data/sounds/effects/ogg/InCallNotification.ogg b/data/sounds/effects/ogg/InCallNotification.ogg
new file mode 100644
index 0000000000000..4481ccb256146
Binary files /dev/null and b/data/sounds/effects/ogg/InCallNotification.ogg differ
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index cc9f183fb69ee..c8d8e03bce879 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;
@@ -193,6 +193,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;
@@ -303,12 +304,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();
@@ -946,30 +947,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) {
@@ -1276,6 +1253,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.
@@ -4156,21 +4142,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 835603a9228ba..529ac3a192ae9 100644
--- a/services/tests/notification/src/com/android/server/notification/BuzzBeepBlinkTest.java
+++ b/services/tests/notification/src/com/android/server/notification/BuzzBeepBlinkTest.java
@@ -536,6 +536,21 @@ public class BuzzBeepBlinkTest extends NotificationTestCase {
verifyStopAudio();
}
+ @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();