Search in sources :

Example 6 with IRingtonePlayer

use of android.media.IRingtonePlayer in project android_frameworks_base by DirtyUnicorns.

the class NotificationManagerService method buzzBeepBlinkLocked.

@VisibleForTesting
void buzzBeepBlinkLocked(NotificationRecord record) {
    boolean buzz = false;
    boolean beep = false;
    boolean blink = false;
    final Notification notification = record.sbn.getNotification();
    final String key = record.getKey();
    final String pkg = record.sbn.getPackageName();
    // Should this notification make noise, vibe, or use the LED?
    final boolean aboveThreshold = record.getImportance() >= IMPORTANCE_DEFAULT;
    final boolean canInterrupt = aboveThreshold && !record.isIntercepted();
    if (DBG || record.isIntercepted())
        Slog.v(TAG, "pkg=" + pkg + " canInterrupt=" + canInterrupt + " intercept=" + record.isIntercepted());
    final int currentUser;
    final long token = Binder.clearCallingIdentity();
    try {
        currentUser = ActivityManager.getCurrentUser();
    } finally {
        Binder.restoreCallingIdentity(token);
    }
    // If we're not supposed to beep, vibrate, etc. then don't.
    final String disableEffects = disableNotificationEffects(record);
    if (disableEffects != null) {
        ZenLog.traceDisableEffects(record, disableEffects);
    }
    // Remember if this notification already owns the notification channels.
    boolean wasBeep = key != null && key.equals(mSoundNotificationKey);
    boolean wasBuzz = key != null && key.equals(mVibrateNotificationKey);
    // These are set inside the conditional if the notification is allowed to make noise.
    boolean hasValidVibrate = false;
    boolean hasValidSound = false;
    if (disableEffects == null && (record.getUserId() == UserHandle.USER_ALL || record.getUserId() == currentUser || mUserProfiles.isCurrentProfile(record.getUserId())) && canInterrupt && mSystemReady && !notificationIsAnnoying(pkg) && mAudioManager != null) {
        if (DBG)
            Slog.v(TAG, "Interrupting!");
        // should we use the default notification sound? (indicated either by
        // DEFAULT_SOUND or because notification.sound is pointing at
        // Settings.System.NOTIFICATION_SOUND)
        final boolean useDefaultSound = (notification.defaults & Notification.DEFAULT_SOUND) != 0 || Settings.System.DEFAULT_NOTIFICATION_URI.equals(notification.sound);
        Uri soundUri = null;
        if (useDefaultSound) {
            soundUri = Settings.System.DEFAULT_NOTIFICATION_URI;
            // check to see if the default notification sound is silent
            hasValidSound = mSystemNotificationSound != null;
        } else if (notification.sound != null) {
            soundUri = notification.sound;
            hasValidSound = (soundUri != null);
        }
        // Does the notification want to specify its own vibration?
        final boolean hasCustomVibrate = notification.vibrate != null;
        // new in 4.2: if there was supposed to be a sound and we're in vibrate
        // mode, and no other vibration is specified, we fall back to vibration
        final boolean convertSoundToVibration = !hasCustomVibrate && hasValidSound && (mAudioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_VIBRATE);
        // The DEFAULT_VIBRATE flag trumps any custom vibration AND the fallback.
        final boolean useDefaultVibrate = (notification.defaults & Notification.DEFAULT_VIBRATE) != 0;
        hasValidVibrate = useDefaultVibrate || convertSoundToVibration || hasCustomVibrate;
        // it once, and we already have, then don't.
        if (!(record.isUpdate && (notification.flags & Notification.FLAG_ONLY_ALERT_ONCE) != 0)) {
            sendAccessibilityEvent(notification, record.sbn.getPackageName());
            if (hasValidSound) {
                boolean looping = (notification.flags & Notification.FLAG_INSISTENT) != 0;
                AudioAttributes audioAttributes = audioAttributesForNotification(notification);
                mSoundNotificationKey = key;
                // ringer mode is silent) or if there is a user of exclusive audio focus
                if ((mAudioManager.getStreamVolume(AudioAttributes.toLegacyStreamType(audioAttributes)) != 0) && !mAudioManager.isAudioFocusExclusive()) {
                    final long identity = Binder.clearCallingIdentity();
                    try {
                        final IRingtonePlayer player = mAudioManager.getRingtonePlayer();
                        if (player != null) {
                            if (DBG)
                                Slog.v(TAG, "Playing sound " + soundUri + " with attributes " + audioAttributes);
                            player.playAsync(soundUri, record.sbn.getUser(), looping, audioAttributes);
                            beep = true;
                        }
                    } catch (RemoteException e) {
                    } finally {
                        Binder.restoreCallingIdentity(identity);
                    }
                }
            }
            if (hasValidVibrate && !(mAudioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_SILENT)) {
                mVibrateNotificationKey = key;
                if (useDefaultVibrate || convertSoundToVibration) {
                    // Escalate privileges so we can use the vibrator even if the
                    // notifying app does not have the VIBRATE permission.
                    long identity = Binder.clearCallingIdentity();
                    try {
                        mVibrator.vibrate(record.sbn.getUid(), record.sbn.getOpPkg(), useDefaultVibrate ? mDefaultVibrationPattern : mFallbackVibrationPattern, ((notification.flags & Notification.FLAG_INSISTENT) != 0) ? 0 : -1, audioAttributesForNotification(notification));
                        buzz = true;
                    } finally {
                        Binder.restoreCallingIdentity(identity);
                    }
                } else if (notification.vibrate.length > 1) {
                    // If you want your own vibration pattern, you need the VIBRATE
                    // permission
                    mVibrator.vibrate(record.sbn.getUid(), record.sbn.getOpPkg(), notification.vibrate, ((notification.flags & Notification.FLAG_INSISTENT) != 0) ? 0 : -1, audioAttributesForNotification(notification));
                    buzz = true;
                }
            }
        }
    }
    // cancel that feedback now
    if (wasBeep && !hasValidSound) {
        clearSoundLocked();
    }
    if (wasBuzz && !hasValidVibrate) {
        clearVibrateLocked();
    }
    // light
    // release the light
    boolean wasShowLights = mLights.remove(key);
    final boolean canInterruptWithLight = canInterrupt || isLedNotificationForcedOn(record) || (!canInterrupt && mZenModeHelper.getAreLightsAllowed());
    if ((notification.flags & Notification.FLAG_SHOW_LIGHTS) != 0 && canInterruptWithLight && ((record.getSuppressedVisualEffects() & NotificationListenerService.SUPPRESSED_EFFECT_SCREEN_OFF) == 0)) {
        mLights.add(key);
        updateLightsLocked();
        if (mUseAttentionLight) {
            mAttentionLight.pulse();
        }
        blink = true;
    } else if (wasShowLights) {
        updateLightsLocked();
    }
    if (buzz || beep || blink) {
        if (((record.getSuppressedVisualEffects() & NotificationListenerService.SUPPRESSED_EFFECT_SCREEN_OFF) != 0)) {
            if (DBG)
                Slog.v(TAG, "Suppressed SystemUI from triggering screen on");
        } else {
            EventLogTags.writeNotificationAlert(key, buzz ? 1 : 0, beep ? 1 : 0, blink ? 1 : 0);
            mHandler.post(mBuzzBeepBlinked);
        }
    }
}
Also used : AudioAttributes(android.media.AudioAttributes) IRingtonePlayer(android.media.IRingtonePlayer) RemoteException(android.os.RemoteException) Uri(android.net.Uri) ITransientNotification(android.app.ITransientNotification) Notification(android.app.Notification) StatusBarNotification(android.service.notification.StatusBarNotification) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 7 with IRingtonePlayer

use of android.media.IRingtonePlayer in project android_frameworks_base by crdroidandroid.

the class NotificationManagerService method clearSoundLocked.

private void clearSoundLocked() {
    mSoundNotificationKey = null;
    long identity = Binder.clearCallingIdentity();
    try {
        final IRingtonePlayer player = mAudioManager.getRingtonePlayer();
        if (player != null) {
            player.stopAsync();
        }
    } catch (RemoteException e) {
    } finally {
        Binder.restoreCallingIdentity(identity);
    }
}
Also used : IRingtonePlayer(android.media.IRingtonePlayer) RemoteException(android.os.RemoteException)

Example 8 with IRingtonePlayer

use of android.media.IRingtonePlayer in project android_frameworks_base by ParanoidAndroid.

the class NotificationManagerService method enqueueNotificationInternal.

// Not exposed via Binder; for system use only (otherwise malicious apps could spoof the
// uid/pid of another application)
public void enqueueNotificationInternal(String pkg, String basePkg, int callingUid, int callingPid, String tag, int id, Notification notification, int[] idOut, int userId) {
    if (DBG) {
        Slog.v(TAG, "enqueueNotificationInternal: pkg=" + pkg + " id=" + id + " notification=" + notification);
    }
    checkCallerIsSystemOrSameApp(pkg);
    final boolean isSystemNotification = isUidSystem(callingUid) || ("android".equals(pkg));
    userId = ActivityManager.handleIncomingUser(callingPid, callingUid, userId, true, false, "enqueueNotification", pkg);
    final UserHandle user = new UserHandle(userId);
    // package can enqueue.  Prevents DOS attacks and deals with leaks.
    if (!isSystemNotification) {
        synchronized (mNotificationList) {
            int count = 0;
            final int N = mNotificationList.size();
            for (int i = 0; i < N; i++) {
                final NotificationRecord r = mNotificationList.get(i);
                if (r.sbn.getPackageName().equals(pkg) && r.sbn.getUserId() == userId) {
                    count++;
                    if (count >= MAX_PACKAGE_NOTIFICATIONS) {
                        Slog.e(TAG, "Package has already posted " + count + " notifications.  Not showing more.  package=" + pkg);
                        return;
                    }
                }
            }
        }
    }
    //     behalf of the download manager without affecting other apps.
    if (!pkg.equals("com.android.providers.downloads") || Log.isLoggable("DownloadManager", Log.VERBOSE)) {
        EventLog.writeEvent(EventLogTags.NOTIFICATION_ENQUEUE, pkg, id, tag, userId, notification.toString());
    }
    if (pkg == null || notification == null) {
        throw new IllegalArgumentException("null not allowed: pkg=" + pkg + " id=" + id + " notification=" + notification);
    }
    if (notification.icon != 0) {
        if (notification.contentView == null) {
            throw new IllegalArgumentException("contentView required: pkg=" + pkg + " id=" + id + " notification=" + notification);
        }
    }
    // === Scoring ===
    // 0. Sanitize inputs
    notification.priority = clamp(notification.priority, Notification.PRIORITY_MIN, Notification.PRIORITY_MAX);
    // Migrate notification flags to scores
    if (0 != (notification.flags & Notification.FLAG_HIGH_PRIORITY)) {
        if (notification.priority < Notification.PRIORITY_MAX)
            notification.priority = Notification.PRIORITY_MAX;
    } else if (SCORE_ONGOING_HIGHER && 0 != (notification.flags & Notification.FLAG_ONGOING_EVENT)) {
        if (notification.priority < Notification.PRIORITY_HIGH)
            notification.priority = Notification.PRIORITY_HIGH;
    }
    // 1. initial score: buckets of 10, around the app 
    //[-20..20]
    int score = notification.priority * NOTIFICATION_PRIORITY_MULTIPLIER;
    // blocked apps
    if (ENABLE_BLOCKED_NOTIFICATIONS && !noteNotificationOp(pkg, callingUid)) {
        if (!isSystemNotification) {
            score = JUNK_SCORE;
            Slog.e(TAG, "Suppressing notification from package " + pkg + " by user request.");
        }
    }
    if (DBG) {
        Slog.v(TAG, "Assigned score=" + score + " to " + notification);
    }
    if (score < SCORE_DISPLAY_THRESHOLD) {
        // Notification will be blocked because the score is too low.
        return;
    }
    // Should this notification make noise, vibe, or use the LED?
    final boolean canInterrupt = (score >= SCORE_INTERRUPTION_THRESHOLD);
    synchronized (mNotificationList) {
        final boolean inQuietHours = inQuietHours();
        final StatusBarNotification n = new StatusBarNotification(pkg, id, tag, callingUid, callingPid, score, notification, user);
        NotificationRecord r = new NotificationRecord(n);
        NotificationRecord old = null;
        int index = indexOfNotificationLocked(pkg, tag, id, userId);
        if (index < 0) {
            mNotificationList.add(r);
        } else {
            old = mNotificationList.remove(index);
            mNotificationList.add(index, r);
            // Make sure we don't lose the foreground service state.
            if (old != null) {
                notification.flags |= old.getNotification().flags & Notification.FLAG_FOREGROUND_SERVICE;
            }
        }
        // flags are set.
        if ((notification.flags & Notification.FLAG_FOREGROUND_SERVICE) != 0) {
            notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;
        }
        final int currentUser;
        final long token = Binder.clearCallingIdentity();
        try {
            currentUser = ActivityManager.getCurrentUser();
        } finally {
            Binder.restoreCallingIdentity(token);
        }
        if (notification.icon != 0) {
            if (old != null && old.statusBarKey != null) {
                r.statusBarKey = old.statusBarKey;
                long identity = Binder.clearCallingIdentity();
                try {
                    mStatusBar.updateNotification(r.statusBarKey, n);
                } finally {
                    Binder.restoreCallingIdentity(identity);
                }
            } else {
                long identity = Binder.clearCallingIdentity();
                try {
                    r.statusBarKey = mStatusBar.addNotification(n);
                    if ((n.getNotification().flags & Notification.FLAG_SHOW_LIGHTS) != 0 && canInterrupt) {
                        mAttentionLight.pulse();
                    }
                } finally {
                    Binder.restoreCallingIdentity(identity);
                }
            }
            // Send accessibility events only for the current user.
            if (currentUser == userId) {
                sendAccessibilityEvent(notification, pkg);
            }
            notifyPostedLocked(r);
        } else {
            Slog.e(TAG, "Not posting notification with icon==0: " + notification);
            if (old != null && old.statusBarKey != null) {
                long identity = Binder.clearCallingIdentity();
                try {
                    mStatusBar.removeNotification(old.statusBarKey);
                } finally {
                    Binder.restoreCallingIdentity(identity);
                }
                notifyRemovedLocked(r);
            }
            // ATTENTION: in a future release we will bail out here
            // so that we do not play sounds, show lights, etc. for invalid notifications
            Slog.e(TAG, "WARNING: In a future release this will crash the app: " + n.getPackageName());
        }
        // If we're not supposed to beep, vibrate, etc. then don't.
        if (((mDisabledNotifications & StatusBarManager.DISABLE_NOTIFICATION_ALERTS) == 0) && (!(old != null && (notification.flags & Notification.FLAG_ONLY_ALERT_ONCE) != 0)) && !isOverNotifSoundThreshold(pkg) && (r.getUserId() == UserHandle.USER_ALL || (r.getUserId() == userId && r.getUserId() == currentUser)) && canInterrupt && mSystemReady) {
            final AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
            // sound
            // should we use the default notification sound? (indicated either by DEFAULT_SOUND
            // or because notification.sound is pointing at Settings.System.NOTIFICATION_SOUND)
            final boolean useDefaultSound = (notification.defaults & Notification.DEFAULT_SOUND) != 0 || Settings.System.DEFAULT_NOTIFICATION_URI.equals(notification.sound);
            Uri soundUri = null;
            boolean hasValidSound = false;
            if (!(inQuietHours && mQuietHoursMute) && useDefaultSound) {
                soundUri = Settings.System.DEFAULT_NOTIFICATION_URI;
                // check to see if the default notification sound is silent
                ContentResolver resolver = mContext.getContentResolver();
                hasValidSound = Settings.System.getString(resolver, Settings.System.NOTIFICATION_SOUND) != null;
            } else if (!(inQuietHours && mQuietHoursMute) && notification.sound != null) {
                soundUri = notification.sound;
                hasValidSound = (soundUri != null);
            }
            if (hasValidSound) {
                boolean looping = (notification.flags & Notification.FLAG_INSISTENT) != 0;
                int audioStreamType;
                if (notification.audioStreamType >= 0) {
                    audioStreamType = notification.audioStreamType;
                } else {
                    audioStreamType = DEFAULT_STREAM_TYPE;
                }
                mSoundNotification = r;
                // (typically because ringer mode is silent) or if speech recognition is active.
                if ((audioManager.getStreamVolume(audioStreamType) != 0) && !audioManager.isSpeechRecognitionActive()) {
                    final long identity = Binder.clearCallingIdentity();
                    try {
                        final IRingtonePlayer player = mAudioService.getRingtonePlayer();
                        if (player != null) {
                            player.playAsync(soundUri, user, looping, audioStreamType);
                        }
                    } catch (RemoteException e) {
                    } finally {
                        Binder.restoreCallingIdentity(identity);
                    }
                }
            }
            // vibrate
            // Does the notification want to specify its own vibration?
            final boolean hasCustomVibrate = notification.vibrate != null;
            // new in 4.2: if there was supposed to be a sound and we're in vibrate mode,
            // and no other vibration is specified, we fall back to vibration
            final boolean convertSoundToVibration = !hasCustomVibrate && (useDefaultSound || notification.sound != null) && (audioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE) && (Settings.System.getInt(mContext.getContentResolver(), Settings.System.NOTIFICATION_CONVERT_SOUND_TO_VIBRATION, 1) != 0);
            // The DEFAULT_VIBRATE flag trumps any custom vibration AND the fallback.
            final boolean useDefaultVibrate = (notification.defaults & Notification.DEFAULT_VIBRATE) != 0;
            if (!(inQuietHours && mQuietHoursStill) && (useDefaultVibrate || convertSoundToVibration || hasCustomVibrate) && !(audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT)) {
                mVibrateNotification = r;
                if (useDefaultVibrate || convertSoundToVibration) {
                    // Escalate privileges so we can use the vibrator even if the notifying app
                    // does not have the VIBRATE permission.
                    long identity = Binder.clearCallingIdentity();
                    try {
                        mVibrator.vibrate(r.sbn.getUid(), r.sbn.getBasePkg(), useDefaultVibrate ? mDefaultVibrationPattern : mFallbackVibrationPattern, ((notification.flags & Notification.FLAG_INSISTENT) != 0) ? 0 : -1);
                    } finally {
                        Binder.restoreCallingIdentity(identity);
                    }
                } else if (notification.vibrate.length > 1) {
                    // If you want your own vibration pattern, you need the VIBRATE permission
                    mVibrator.vibrate(r.sbn.getUid(), r.sbn.getBasePkg(), notification.vibrate, ((notification.flags & Notification.FLAG_INSISTENT) != 0) ? 0 : -1);
                }
            }
        }
        // light
        // the most recent thing gets the light
        mLights.remove(old);
        if (mLedNotification == old) {
            mLedNotification = null;
        }
        //        + ((old.notification.lights.flags & Notification.FLAG_SHOW_LIGHTS) != 0));
        if ((notification.flags & Notification.FLAG_SHOW_LIGHTS) != 0 && canInterrupt) {
            mLights.add(r);
            // force reevaluation of active light
            mLedNotification = null;
            updateLightsLocked();
        } else {
            if (old != null && ((old.getFlags() & Notification.FLAG_SHOW_LIGHTS) != 0)) {
                updateLightsLocked();
            }
        }
    }
    idOut[0] = id;
}
Also used : AudioManager(android.media.AudioManager) StatusBarNotification(android.service.notification.StatusBarNotification) UserHandle(android.os.UserHandle) IRingtonePlayer(android.media.IRingtonePlayer) RemoteException(android.os.RemoteException) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver)

Example 9 with IRingtonePlayer

use of android.media.IRingtonePlayer in project platform_frameworks_base by android.

the class NotificationManagerService method clearSoundLocked.

private void clearSoundLocked() {
    mSoundNotificationKey = null;
    long identity = Binder.clearCallingIdentity();
    try {
        final IRingtonePlayer player = mAudioManager.getRingtonePlayer();
        if (player != null) {
            player.stopAsync();
        }
    } catch (RemoteException e) {
    } finally {
        Binder.restoreCallingIdentity(identity);
    }
}
Also used : IRingtonePlayer(android.media.IRingtonePlayer) RemoteException(android.os.RemoteException)

Example 10 with IRingtonePlayer

use of android.media.IRingtonePlayer in project platform_frameworks_base by android.

the class NotificationManagerService method buzzBeepBlinkLocked.

@VisibleForTesting
void buzzBeepBlinkLocked(NotificationRecord record) {
    boolean buzz = false;
    boolean beep = false;
    boolean blink = false;
    final Notification notification = record.sbn.getNotification();
    final String key = record.getKey();
    // Should this notification make noise, vibe, or use the LED?
    final boolean aboveThreshold = record.getImportance() >= IMPORTANCE_DEFAULT;
    final boolean canInterrupt = aboveThreshold && !record.isIntercepted();
    if (DBG || record.isIntercepted())
        Slog.v(TAG, "pkg=" + record.sbn.getPackageName() + " canInterrupt=" + canInterrupt + " intercept=" + record.isIntercepted());
    final int currentUser;
    final long token = Binder.clearCallingIdentity();
    try {
        currentUser = ActivityManager.getCurrentUser();
    } finally {
        Binder.restoreCallingIdentity(token);
    }
    // If we're not supposed to beep, vibrate, etc. then don't.
    final String disableEffects = disableNotificationEffects(record);
    if (disableEffects != null) {
        ZenLog.traceDisableEffects(record, disableEffects);
    }
    // Remember if this notification already owns the notification channels.
    boolean wasBeep = key != null && key.equals(mSoundNotificationKey);
    boolean wasBuzz = key != null && key.equals(mVibrateNotificationKey);
    // These are set inside the conditional if the notification is allowed to make noise.
    boolean hasValidVibrate = false;
    boolean hasValidSound = false;
    if (disableEffects == null && (record.getUserId() == UserHandle.USER_ALL || record.getUserId() == currentUser || mUserProfiles.isCurrentProfile(record.getUserId())) && canInterrupt && mSystemReady && mAudioManager != null) {
        if (DBG)
            Slog.v(TAG, "Interrupting!");
        // should we use the default notification sound? (indicated either by
        // DEFAULT_SOUND or because notification.sound is pointing at
        // Settings.System.NOTIFICATION_SOUND)
        final boolean useDefaultSound = (notification.defaults & Notification.DEFAULT_SOUND) != 0 || Settings.System.DEFAULT_NOTIFICATION_URI.equals(notification.sound);
        Uri soundUri = null;
        if (useDefaultSound) {
            soundUri = Settings.System.DEFAULT_NOTIFICATION_URI;
            // check to see if the default notification sound is silent
            hasValidSound = mSystemNotificationSound != null;
        } else if (notification.sound != null) {
            soundUri = notification.sound;
            hasValidSound = (soundUri != null);
        }
        // Does the notification want to specify its own vibration?
        final boolean hasCustomVibrate = notification.vibrate != null;
        // new in 4.2: if there was supposed to be a sound and we're in vibrate
        // mode, and no other vibration is specified, we fall back to vibration
        final boolean convertSoundToVibration = !hasCustomVibrate && hasValidSound && (mAudioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_VIBRATE);
        // The DEFAULT_VIBRATE flag trumps any custom vibration AND the fallback.
        final boolean useDefaultVibrate = (notification.defaults & Notification.DEFAULT_VIBRATE) != 0;
        hasValidVibrate = useDefaultVibrate || convertSoundToVibration || hasCustomVibrate;
        // it once, and we already have, then don't.
        if (!(record.isUpdate && (notification.flags & Notification.FLAG_ONLY_ALERT_ONCE) != 0)) {
            sendAccessibilityEvent(notification, record.sbn.getPackageName());
            if (hasValidSound) {
                boolean looping = (notification.flags & Notification.FLAG_INSISTENT) != 0;
                AudioAttributes audioAttributes = audioAttributesForNotification(notification);
                mSoundNotificationKey = key;
                // ringer mode is silent) or if there is a user of exclusive audio focus
                if ((mAudioManager.getStreamVolume(AudioAttributes.toLegacyStreamType(audioAttributes)) != 0) && !mAudioManager.isAudioFocusExclusive()) {
                    final long identity = Binder.clearCallingIdentity();
                    try {
                        final IRingtonePlayer player = mAudioManager.getRingtonePlayer();
                        if (player != null) {
                            if (DBG)
                                Slog.v(TAG, "Playing sound " + soundUri + " with attributes " + audioAttributes);
                            player.playAsync(soundUri, record.sbn.getUser(), looping, audioAttributes);
                            beep = true;
                        }
                    } catch (RemoteException e) {
                    } finally {
                        Binder.restoreCallingIdentity(identity);
                    }
                }
            }
            if (hasValidVibrate && !(mAudioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_SILENT)) {
                mVibrateNotificationKey = key;
                if (useDefaultVibrate || convertSoundToVibration) {
                    // Escalate privileges so we can use the vibrator even if the
                    // notifying app does not have the VIBRATE permission.
                    long identity = Binder.clearCallingIdentity();
                    try {
                        mVibrator.vibrate(record.sbn.getUid(), record.sbn.getOpPkg(), useDefaultVibrate ? mDefaultVibrationPattern : mFallbackVibrationPattern, ((notification.flags & Notification.FLAG_INSISTENT) != 0) ? 0 : -1, audioAttributesForNotification(notification));
                        buzz = true;
                    } finally {
                        Binder.restoreCallingIdentity(identity);
                    }
                } else if (notification.vibrate.length > 1) {
                    // If you want your own vibration pattern, you need the VIBRATE
                    // permission
                    mVibrator.vibrate(record.sbn.getUid(), record.sbn.getOpPkg(), notification.vibrate, ((notification.flags & Notification.FLAG_INSISTENT) != 0) ? 0 : -1, audioAttributesForNotification(notification));
                    buzz = true;
                }
            }
        }
    }
    // cancel that feedback now
    if (wasBeep && !hasValidSound) {
        clearSoundLocked();
    }
    if (wasBuzz && !hasValidVibrate) {
        clearVibrateLocked();
    }
    // light
    // release the light
    boolean wasShowLights = mLights.remove(key);
    if ((notification.flags & Notification.FLAG_SHOW_LIGHTS) != 0 && aboveThreshold && ((record.getSuppressedVisualEffects() & NotificationListenerService.SUPPRESSED_EFFECT_SCREEN_OFF) == 0)) {
        mLights.add(key);
        updateLightsLocked();
        if (mUseAttentionLight) {
            mAttentionLight.pulse();
        }
        blink = true;
    } else if (wasShowLights) {
        updateLightsLocked();
    }
    if (buzz || beep || blink) {
        if (((record.getSuppressedVisualEffects() & NotificationListenerService.SUPPRESSED_EFFECT_SCREEN_OFF) != 0)) {
            if (DBG)
                Slog.v(TAG, "Suppressed SystemUI from triggering screen on");
        } else {
            EventLogTags.writeNotificationAlert(key, buzz ? 1 : 0, beep ? 1 : 0, blink ? 1 : 0);
            mHandler.post(mBuzzBeepBlinked);
        }
    }
}
Also used : AudioAttributes(android.media.AudioAttributes) IRingtonePlayer(android.media.IRingtonePlayer) RemoteException(android.os.RemoteException) Uri(android.net.Uri) ITransientNotification(android.app.ITransientNotification) Notification(android.app.Notification) StatusBarNotification(android.service.notification.StatusBarNotification) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Aggregations

IRingtonePlayer (android.media.IRingtonePlayer)17 RemoteException (android.os.RemoteException)17 PendingIntent (android.app.PendingIntent)6 Uri (android.net.Uri)6 StatusBarNotification (android.service.notification.StatusBarNotification)6 ITransientNotification (android.app.ITransientNotification)5 Notification (android.app.Notification)5 AudioAttributes (android.media.AudioAttributes)5 VisibleForTesting (com.android.internal.annotations.VisibleForTesting)5 ContentResolver (android.content.ContentResolver)1 AudioManager (android.media.AudioManager)1 UserHandle (android.os.UserHandle)1