use of android.service.notification.StatusBarNotification in project android_frameworks_base by AOSPA.
the class NotificationManagerService method maybeAddAutobundleSummary.
// Posts a 'fake' summary for a package that has exceeded the solo-notification limit.
private void maybeAddAutobundleSummary(Adjustment adjustment) {
if (adjustment.getSignals() != null) {
Bundle.setDefusable(adjustment.getSignals(), true);
if (adjustment.getSignals().getBoolean(Adjustment.NEEDS_AUTOGROUPING_KEY, false)) {
final String newAutoBundleKey = adjustment.getSignals().getString(Adjustment.GROUP_KEY_OVERRIDE_KEY, null);
int userId = -1;
NotificationRecord summaryRecord = null;
synchronized (mNotificationList) {
NotificationRecord notificationRecord = mNotificationsByKey.get(adjustment.getKey());
if (notificationRecord == null) {
// adjustment will post a summary if needed.
return;
}
final StatusBarNotification adjustedSbn = notificationRecord.sbn;
userId = adjustedSbn.getUser().getIdentifier();
ArrayMap<String, String> summaries = mAutobundledSummaries.get(userId);
if (summaries == null) {
summaries = new ArrayMap<>();
}
mAutobundledSummaries.put(userId, summaries);
if (!summaries.containsKey(adjustment.getPackage()) && newAutoBundleKey != null) {
// Add summary
final ApplicationInfo appInfo = adjustedSbn.getNotification().extras.getParcelable(Notification.EXTRA_BUILDER_APPLICATION_INFO);
final Bundle extras = new Bundle();
extras.putParcelable(Notification.EXTRA_BUILDER_APPLICATION_INFO, appInfo);
final Notification summaryNotification = new Notification.Builder(getContext()).setSmallIcon(adjustedSbn.getNotification().getSmallIcon()).setGroupSummary(true).setGroup(newAutoBundleKey).setFlag(Notification.FLAG_AUTOGROUP_SUMMARY, true).setFlag(Notification.FLAG_GROUP_SUMMARY, true).setColor(adjustedSbn.getNotification().color).setLocalOnly(true).build();
summaryNotification.extras.putAll(extras);
Intent appIntent = getContext().getPackageManager().getLaunchIntentForPackage(adjustment.getPackage());
if (appIntent != null) {
summaryNotification.contentIntent = PendingIntent.getActivityAsUser(getContext(), 0, appIntent, 0, null, UserHandle.of(userId));
}
final StatusBarNotification summarySbn = new StatusBarNotification(adjustedSbn.getPackageName(), adjustedSbn.getOpPkg(), Integer.MAX_VALUE, Adjustment.GROUP_KEY_OVERRIDE_KEY, adjustedSbn.getUid(), adjustedSbn.getInitialPid(), summaryNotification, adjustedSbn.getUser(), newAutoBundleKey, System.currentTimeMillis());
summaryRecord = new NotificationRecord(getContext(), summarySbn);
summaries.put(adjustment.getPackage(), summarySbn.getKey());
}
}
if (summaryRecord != null) {
mHandler.post(new EnqueueNotificationRunnable(userId, summaryRecord));
}
}
}
}
use of android.service.notification.StatusBarNotification in project android_frameworks_base by AOSPA.
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);
}
}
use of android.service.notification.StatusBarNotification in project android_frameworks_base by crdroidandroid.
the class BugreportReceiverTest method cancelExistingNotifications.
private void cancelExistingNotifications() {
NotificationManager nm = NotificationManager.from(mContext);
for (StatusBarNotification notification : nm.getActiveNotifications()) {
int id = notification.getId();
Log.i(TAG, "Canceling existing notification (id=" + id + ")");
nm.cancel(id);
}
}
use of android.service.notification.StatusBarNotification in project android_frameworks_base by crdroidandroid.
the class NotificationData method updateRankingAndSort.
private void updateRankingAndSort(RankingMap ranking) {
if (ranking != null) {
mRankingMap = ranking;
synchronized (mEntries) {
final int N = mEntries.size();
for (int i = 0; i < N; i++) {
Entry entry = mEntries.valueAt(i);
final StatusBarNotification oldSbn = entry.notification.clone();
final String overrideGroupKey = getOverrideGroupKey(entry.key);
if (!Objects.equals(oldSbn.getOverrideGroupKey(), overrideGroupKey)) {
entry.notification.setOverrideGroupKey(overrideGroupKey);
mGroupManager.onEntryUpdated(entry, oldSbn);
}
}
}
}
filterAndSort();
}
use of android.service.notification.StatusBarNotification in project android_frameworks_base by ResurrectionRemix.
the class NotificationData method dumpEntry.
private void dumpEntry(PrintWriter pw, String indent, int i, Entry e) {
mRankingMap.getRanking(e.key, mTmpRanking);
pw.print(indent);
pw.println(" [" + i + "] key=" + e.key + " icon=" + e.icon);
StatusBarNotification n = e.notification;
pw.print(indent);
pw.println(" pkg=" + n.getPackageName() + " id=" + n.getId() + " importance=" + mTmpRanking.getImportance());
pw.print(indent);
pw.println(" notification=" + n.getNotification());
pw.print(indent);
pw.println(" tickerText=\"" + n.getNotification().tickerText + "\"");
}
Aggregations