Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 12018312 authored by Daniel Sandler's avatar Daniel Sandler Committed by android-build-merger
Browse files

Merge "Enable notifications during an ongoing call" into oc-dev

am: b94abe5e

Change-Id: I9d65601fff941d5a3764cde34f9c658ea1d2a435
parents 966f6d71 b94abe5e
Loading
Loading
Loading
Loading
+3 −0
Original line number Original line Diff line number Diff line
@@ -2919,4 +2919,7 @@
    <!-- Handle volume keys directly in Window Manager without passing them to the foreground app -->
    <!-- Handle volume keys directly in Window Manager without passing them to the foreground app -->
    <bool name="config_handleVolumeKeysInWindowManager">false</bool>
    <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>
</resources>
</resources>
+2 −0
Original line number Original line Diff line number Diff line
@@ -3019,4 +3019,6 @@
  <java-symbol type="array" name="config_allowedSecureInstantAppSettings" />
  <java-symbol type="array" name="config_allowedSecureInstantAppSettings" />


  <java-symbol type="bool" name="config_handleVolumeKeysInWindowManager" />
  <java-symbol type="bool" name="config_handleVolumeKeysInWindowManager" />

  <java-symbol type="integer" name="config_inCallNotificationVolumeRelative" />
</resources>
</resources>
+60 −4
Original line number Original line Diff line number Diff line
@@ -96,6 +96,7 @@ import android.database.ContentObserver;
import android.media.AudioManager;
import android.media.AudioManager;
import android.media.AudioManagerInternal;
import android.media.AudioManagerInternal;
import android.media.IRingtonePlayer;
import android.media.IRingtonePlayer;
import android.media.ToneGenerator;
import android.net.Uri;
import android.net.Uri;
import android.os.Binder;
import android.os.Binder;
import android.os.Build;
import android.os.Build;
@@ -301,6 +302,10 @@ public class NotificationManagerService extends SystemService {
    private boolean mInCall = false;
    private boolean mInCall = false;
    private boolean mNotificationPulseEnabled;
    private boolean mNotificationPulseEnabled;


    // for generating notification tones in-call
    private ToneGenerator mInCallToneGenerator;
    private final Object mInCallToneGeneratorLock = new Object();

    // used as a mutex for access to all active notifications & listeners
    // used as a mutex for access to all active notifications & listeners
    final Object mNotificationLock = new Object();
    final Object mNotificationLock = new Object();
    final ArrayList<NotificationRecord> mNotificationList =
    final ArrayList<NotificationRecord> mNotificationList =
@@ -854,6 +859,30 @@ public class NotificationManagerService extends SystemService {
                mInCall = TelephonyManager.EXTRA_STATE_OFFHOOK
                mInCall = TelephonyManager.EXTRA_STATE_OFFHOOK
                        .equals(intent.getStringExtra(TelephonyManager.EXTRA_STATE));
                        .equals(intent.getStringExtra(TelephonyManager.EXTRA_STATE));
                updateNotificationPulse();
                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)) {
            } else if (action.equals(Intent.ACTION_USER_STOPPED)) {
                int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
                int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
                if (userHandle >= 0) {
                if (userHandle >= 0) {
@@ -3723,14 +3752,21 @@ public class NotificationManagerService extends SystemService {
            hasValidVibrate = vibration != null;
            hasValidVibrate = vibration != null;


            if (!shouldMuteNotificationLocked(record)) {
            if (!shouldMuteNotificationLocked(record)) {

                sendAccessibilityEvent(notification, record.sbn.getPackageName());
                sendAccessibilityEvent(notification, record.sbn.getPackageName());

                if (hasValidSound) {
                if (hasValidSound) {
                    mSoundNotificationKey = key;
                    mSoundNotificationKey = key;
                    if (mInCall) {
                        playInCallNotification();
                        beep = true;
                    } else {
                        beep = playSound(record, soundUri);
                        beep = playSound(record, soundUri);
                    }
                    }
                if (hasValidVibrate && !(mAudioManager.getRingerModeInternal()
                }
                        == AudioManager.RINGER_MODE_SILENT)) {

                final boolean ringerModeSilent =
                        mAudioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_SILENT;
                if (!mInCall && hasValidVibrate && !ringerModeSilent) {
                    mVibrateNotificationKey = key;
                    mVibrateNotificationKey = key;


                    buzz = playVibration(record, vibration);
                    buzz = playVibration(record, vibration);
@@ -3839,6 +3875,26 @@ public class NotificationManagerService extends SystemService {
        }
        }
    }
    }


    private void playInCallNotification() {
        new Thread() {
            @Override
            public void run() {
                // If toneGenerator creation fails, just continue the call
                // without playing the notification sound.
                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);
                        }
                    }
                } catch (RuntimeException e) {
                    Log.w(TAG, "Exception from ToneGenerator: " + e);
                }
            }
        }.start();
    }

    void showNextToastLocked() {
    void showNextToastLocked() {
        ToastRecord record = mToastQueue.get(0);
        ToastRecord record = mToastQueue.get(0);
        while (record != null) {
        while (record != null) {