Search in sources :

Example 16 with StatusBarNotification

use of android.service.notification.StatusBarNotification in project android_frameworks_base by DirtyUnicorns.

the class BuzzBeepBlinkTest method getNotificationRecord.

private NotificationRecord getNotificationRecord(int id, boolean insistent, boolean once, boolean noisy, boolean buzzy) {
    final Builder builder = new Builder(getContext()).setContentTitle("foo").setSmallIcon(android.R.drawable.sym_def_app_icon).setPriority(Notification.PRIORITY_HIGH).setOnlyAlertOnce(once);
    int defaults = 0;
    if (noisy) {
        defaults |= Notification.DEFAULT_SOUND;
    }
    if (buzzy) {
        defaults |= Notification.DEFAULT_VIBRATE;
    }
    builder.setDefaults(defaults);
    Notification n = builder.build();
    if (insistent) {
        n.flags |= Notification.FLAG_INSISTENT;
    }
    StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, id, mTag, mUid, mPid, mScore, n, mUser, System.currentTimeMillis());
    return new NotificationRecord(getContext(), sbn);
}
Also used : StatusBarNotification(android.service.notification.StatusBarNotification) Builder(android.app.Notification.Builder) Notification(android.app.Notification) StatusBarNotification(android.service.notification.StatusBarNotification)

Example 17 with StatusBarNotification

use of android.service.notification.StatusBarNotification in project android_frameworks_base by DirtyUnicorns.

the class PhoneStatusBar method maybeEscalateHeadsUp.

@Override
public void maybeEscalateHeadsUp() {
    Collection<HeadsUpManager.HeadsUpEntry> entries = mHeadsUpManager.getAllEntries();
    for (HeadsUpManager.HeadsUpEntry entry : entries) {
        final StatusBarNotification sbn = entry.entry.notification;
        final Notification notification = sbn.getNotification();
        if (notification.fullScreenIntent != null) {
            if (DEBUG) {
                Log.d(TAG, "converting a heads up to fullScreen");
            }
            try {
                EventLog.writeEvent(EventLogTags.SYSUI_HEADS_UP_ESCALATION, sbn.getKey());
                notification.fullScreenIntent.send();
                entry.entry.notifyFullScreenIntentLaunched();
            } catch (PendingIntent.CanceledException e) {
            }
        }
    }
    mHeadsUpManager.releaseAllImmediately();
}
Also used : StatusBarNotification(android.service.notification.StatusBarNotification) PendingIntent(android.app.PendingIntent) HeadsUpManager(com.android.systemui.statusbar.policy.HeadsUpManager) Notification(android.app.Notification) StatusBarNotification(android.service.notification.StatusBarNotification)

Example 18 with StatusBarNotification

use of android.service.notification.StatusBarNotification in project android_frameworks_base by DirtyUnicorns.

the class NotificationManagerService method enqueueNotificationInternal.

void enqueueNotificationInternal(final String pkg, final String opPkg, final int callingUid, final int callingPid, final String tag, final int id, final Notification notification, int[] idOut, int incomingUserId) {
    if (DBG) {
        Slog.v(TAG, "enqueueNotificationInternal: pkg=" + pkg + " id=" + id + " notification=" + notification);
    }
    checkCallerIsSystemOrSameApp(pkg);
    final boolean isSystemNotification = isUidSystem(callingUid) || ("android".equals(pkg));
    final boolean isNotificationFromListener = mListeners.isListenerPackage(pkg);
    final int userId = ActivityManager.handleIncomingUser(callingPid, callingUid, incomingUserId, true, false, "enqueueNotification", pkg);
    final UserHandle user = new UserHandle(userId);
    // Fix the notification as best we can.
    try {
        final ApplicationInfo ai = getContext().getPackageManager().getApplicationInfoAsUser(pkg, PackageManager.MATCH_DEBUG_TRIAGED_MISSING, (userId == UserHandle.USER_ALL) ? UserHandle.USER_SYSTEM : userId);
        Notification.addFieldsFromContext(ai, userId, notification);
    } catch (NameNotFoundException e) {
        Slog.e(TAG, "Cannot create a context for sending app", e);
        return;
    }
    mUsageStats.registerEnqueuedByApp(pkg);
    if (pkg == null || notification == null) {
        throw new IllegalArgumentException("null not allowed: pkg=" + pkg + " id=" + id + " notification=" + notification);
    }
    final StatusBarNotification n = new StatusBarNotification(pkg, opPkg, id, tag, callingUid, callingPid, 0, notification, user);
    // package or a registered listener can enqueue.  Prevents DOS attacks and deals with leaks.
    if (!isSystemNotification && !isNotificationFromListener) {
        synchronized (mNotificationList) {
            if (mNotificationsByKey.get(n.getKey()) != null) {
                // this is an update, rate limit updates only
                final float appEnqueueRate = mUsageStats.getAppEnqueueRate(pkg);
                if (appEnqueueRate > mMaxPackageEnqueueRate) {
                    mUsageStats.registerOverRateQuota(pkg);
                    final long now = SystemClock.elapsedRealtime();
                    if ((now - mLastOverRateLogTime) > MIN_PACKAGE_OVERRATE_LOG_INTERVAL) {
                        Slog.e(TAG, "Package enqueue rate is " + appEnqueueRate + ". Shedding events. package=" + pkg);
                        mLastOverRateLogTime = now;
                    }
                    return;
                }
            }
            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) {
                    if (r.sbn.getId() == id && TextUtils.equals(r.sbn.getTag(), tag)) {
                        // Allow updating existing notification
                        break;
                    }
                    count++;
                    if (count >= MAX_PACKAGE_NOTIFICATIONS) {
                        mUsageStats.registerOverCountQuota(pkg);
                        Slog.e(TAG, "Package has already posted " + count + " notifications.  Not showing more.  package=" + pkg);
                        return;
                    }
                }
            }
        }
    }
    // Whitelist pending intents.
    if (notification.allPendingIntents != null) {
        final int intentCount = notification.allPendingIntents.size();
        if (intentCount > 0) {
            final ActivityManagerInternal am = LocalServices.getService(ActivityManagerInternal.class);
            final long duration = LocalServices.getService(DeviceIdleController.LocalService.class).getNotificationWhitelistDuration();
            for (int i = 0; i < intentCount; i++) {
                PendingIntent pendingIntent = notification.allPendingIntents.valueAt(i);
                if (pendingIntent != null) {
                    am.setPendingIntentWhitelistDuration(pendingIntent.getTarget(), duration);
                }
            }
        }
    }
    // Sanitize inputs
    notification.priority = clamp(notification.priority, Notification.PRIORITY_MIN, Notification.PRIORITY_MAX);
    // setup local book-keeping
    final NotificationRecord r = new NotificationRecord(getContext(), n);
    mHandler.post(new EnqueueNotificationRunnable(userId, r));
    idOut[0] = id;
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ActivityManagerInternal(android.app.ActivityManagerInternal) ApplicationInfo(android.content.pm.ApplicationInfo) StatusBarNotification(android.service.notification.StatusBarNotification) UserHandle(android.os.UserHandle) PendingIntent(android.app.PendingIntent)

Example 19 with StatusBarNotification

use of android.service.notification.StatusBarNotification in project android_frameworks_base by DirtyUnicorns.

the class NotificationManagerService method handleGroupedNotificationLocked.

/**
     * Ensures that grouped notification receive their special treatment.
     *
     * <p>Cancels group children if the new notification causes a group to lose
     * its summary.</p>
     *
     * <p>Updates mSummaryByGroupKey.</p>
     */
private void handleGroupedNotificationLocked(NotificationRecord r, NotificationRecord old, int callingUid, int callingPid) {
    StatusBarNotification sbn = r.sbn;
    Notification n = sbn.getNotification();
    if (n.isGroupSummary() && !sbn.isAppGroup()) {
        // notifications without a group shouldn't be a summary, otherwise autobundling can
        // lead to bugs
        n.flags &= ~Notification.FLAG_GROUP_SUMMARY;
    }
    String group = sbn.getGroupKey();
    boolean isSummary = n.isGroupSummary();
    Notification oldN = old != null ? old.sbn.getNotification() : null;
    String oldGroup = old != null ? old.sbn.getGroupKey() : null;
    boolean oldIsSummary = old != null && oldN.isGroupSummary();
    if (oldIsSummary) {
        NotificationRecord removedSummary = mSummaryByGroupKey.remove(oldGroup);
        if (removedSummary != old) {
            String removedKey = removedSummary != null ? removedSummary.getKey() : "<null>";
            Slog.w(TAG, "Removed summary didn't match old notification: old=" + old.getKey() + ", removed=" + removedKey);
        }
    }
    if (isSummary) {
        mSummaryByGroupKey.put(group, r);
    }
    // notification was a summary and its group key changed.
    if (oldIsSummary && (!isSummary || !oldGroup.equals(group))) {
        cancelGroupChildrenLocked(old, callingUid, callingPid, null, REASON_GROUP_SUMMARY_CANCELED, false);
    }
}
Also used : StatusBarNotification(android.service.notification.StatusBarNotification) ITransientNotification(android.app.ITransientNotification) Notification(android.app.Notification) StatusBarNotification(android.service.notification.StatusBarNotification)

Example 20 with StatusBarNotification

use of android.service.notification.StatusBarNotification in project android_frameworks_base by DirtyUnicorns.

the class NotificationManagerService method dumpImpl.

void dumpImpl(PrintWriter pw, DumpFilter filter) {
    pw.print("Current Notification Manager state");
    if (filter.filtered) {
        pw.print(" (filtered to ");
        pw.print(filter);
        pw.print(")");
    }
    pw.println(':');
    int N;
    final boolean zenOnly = filter.filtered && filter.zen;
    if (!zenOnly) {
        synchronized (mToastQueue) {
            N = mToastQueue.size();
            if (N > 0) {
                pw.println("  Toast Queue:");
                for (int i = 0; i < N; i++) {
                    mToastQueue.get(i).dump(pw, "    ", filter);
                }
                pw.println("  ");
            }
        }
    }
    synchronized (mNotificationList) {
        if (!zenOnly) {
            N = mNotificationList.size();
            if (N > 0) {
                pw.println("  Notification List:");
                for (int i = 0; i < N; i++) {
                    final NotificationRecord nr = mNotificationList.get(i);
                    if (filter.filtered && !filter.matches(nr.sbn))
                        continue;
                    nr.dump(pw, "    ", getContext(), filter.redact);
                }
                pw.println("  ");
            }
            if (!filter.filtered) {
                N = mLights.size();
                if (N > 0) {
                    pw.println("  Lights List:");
                    for (int i = 0; i < N; i++) {
                        if (i == N - 1) {
                            pw.print("  > ");
                        } else {
                            pw.print("    ");
                        }
                        pw.println(mLights.get(i));
                    }
                    pw.println("  ");
                }
                pw.println("  mUseAttentionLight=" + mUseAttentionLight);
                pw.println("  mNotificationPulseEnabled=" + mNotificationPulseEnabled);
                pw.println("  mSoundNotificationKey=" + mSoundNotificationKey);
                pw.println("  mVibrateNotificationKey=" + mVibrateNotificationKey);
                pw.println("  mDisableNotificationEffects=" + mDisableNotificationEffects);
                pw.println("  mCallState=" + callStateToString(mCallState));
                pw.println("  mSystemReady=" + mSystemReady);
                pw.println("  mMaxPackageEnqueueRate=" + mMaxPackageEnqueueRate);
            }
            pw.println("  mArchive=" + mArchive.toString());
            Iterator<StatusBarNotification> iter = mArchive.descendingIterator();
            int i = 0;
            while (iter.hasNext()) {
                final StatusBarNotification sbn = iter.next();
                if (filter != null && !filter.matches(sbn))
                    continue;
                pw.println("    " + sbn);
                if (++i >= 5) {
                    if (iter.hasNext())
                        pw.println("    ...");
                    break;
                }
            }
        }
        if (!zenOnly) {
            pw.println("\n  Usage Stats:");
            mUsageStats.dump(pw, "    ", filter);
        }
        if (!filter.filtered || zenOnly) {
            pw.println("\n  Zen Mode:");
            pw.print("    mInterruptionFilter=");
            pw.println(mInterruptionFilter);
            mZenModeHelper.dump(pw, "    ");
            pw.println("\n  Zen Log:");
            ZenLog.dump(pw, "    ");
        }
        if (!zenOnly) {
            pw.println("\n  Ranking Config:");
            mRankingHelper.dump(pw, "    ", filter);
            pw.println("\n  Notification listeners:");
            mListeners.dump(pw, filter);
            pw.print("    mListenerHints: ");
            pw.println(mListenerHints);
            pw.print("    mListenersDisablingEffects: (");
            N = mListenersDisablingEffects.size();
            for (int i = 0; i < N; i++) {
                final int hint = mListenersDisablingEffects.keyAt(i);
                if (i > 0)
                    pw.print(';');
                pw.print("hint[" + hint + "]:");
                final ArraySet<ManagedServiceInfo> listeners = mListenersDisablingEffects.valueAt(i);
                final int listenerSize = listeners.size();
                for (int j = 0; j < listenerSize; j++) {
                    if (i > 0)
                        pw.print(',');
                    final ManagedServiceInfo listener = listeners.valueAt(i);
                    pw.print(listener.component);
                }
            }
            pw.println(')');
            pw.println("\n  mRankerServicePackageName: " + mRankerServicePackageName);
            pw.println("\n  Notification ranker services:");
            mRankerServices.dump(pw, filter);
        }
        pw.println("\n  Policy access:");
        pw.print("    mPolicyAccess: ");
        pw.println(mPolicyAccess);
        pw.println("\n  Condition providers:");
        mConditionProviders.dump(pw, filter);
        pw.println("\n  Group summaries:");
        for (Entry<String, NotificationRecord> entry : mSummaryByGroupKey.entrySet()) {
            NotificationRecord r = entry.getValue();
            pw.println("    " + entry.getKey() + " -> " + r.getKey());
            if (mNotificationsByKey.get(r.getKey()) != r) {
                pw.println("!!!!!!LEAK: Record not found in mNotificationsByKey.");
                r.dump(pw, "      ", getContext(), filter.redact);
            }
        }
    }
}
Also used : ManagedServiceInfo(com.android.server.notification.ManagedServices.ManagedServiceInfo) StatusBarNotification(android.service.notification.StatusBarNotification)

Aggregations

StatusBarNotification (android.service.notification.StatusBarNotification)188 Notification (android.app.Notification)86 View (android.view.View)24 PendingIntent (android.app.PendingIntent)23 TextView (android.widget.TextView)23 ApplicationInfo (android.content.pm.ApplicationInfo)21 ImageView (android.widget.ImageView)21 NotificationManager (android.app.NotificationManager)20 ArrayList (java.util.ArrayList)18 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)17 StatusBarIcon (com.android.internal.statusbar.StatusBarIcon)16 ITransientNotification (android.app.ITransientNotification)15 RemoteException (android.os.RemoteException)15 NotificationData (com.android.systemui.statusbar.NotificationData)14 Point (android.graphics.Point)13 RemoteViews (android.widget.RemoteViews)12 Entry (com.android.systemui.statusbar.NotificationData.Entry)12 PackageManager (android.content.pm.PackageManager)11 UserHandle (android.os.UserHandle)10 NavigationBarView (com.android.systemui.statusbar.phone.NavigationBarView)10