Merge "Pleasant sound implemented for in-call notif." into oc-mr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
2593d707f7
@@ -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>
|
||||
|
||||
@@ -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" />
|
||||
|
||||
BIN
data/sounds/effects/InCallNotification.ogg
Normal file
BIN
data/sounds/effects/InCallNotification.ogg
Normal file
Binary file not shown.
BIN
data/sounds/effects/ogg/InCallNotification.ogg
Normal file
BIN
data/sounds/effects/ogg/InCallNotification.ogg
Normal file
Binary file not shown.
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user