use of android.service.notification.StatusBarNotification in project android_frameworks_base by crdroidandroid.
the class RankingHelperTest method setUp.
@Override
public void setUp() {
MockitoAnnotations.initMocks(this);
UserHandle user = UserHandle.ALL;
mHelper = new RankingHelper(getContext(), handler, mUsageStats, new String[] { ImportanceExtractor.class.getName() });
mNotiGroupGSortA = new Notification.Builder(getContext()).setContentTitle("A").setGroup("G").setSortKey("A").setWhen(1205).build();
mRecordGroupGSortA = new NotificationRecord(getContext(), new StatusBarNotification("package", "package", 1, null, 0, 0, 0, mNotiGroupGSortA, user));
mNotiGroupGSortB = new Notification.Builder(getContext()).setContentTitle("B").setGroup("G").setSortKey("B").setWhen(1200).build();
mRecordGroupGSortB = new NotificationRecord(getContext(), new StatusBarNotification("package", "package", 1, null, 0, 0, 0, mNotiGroupGSortB, user));
mNotiNoGroup = new Notification.Builder(getContext()).setContentTitle("C").setWhen(1201).build();
mRecordNoGroup = new NotificationRecord(getContext(), new StatusBarNotification("package", "package", 1, null, 0, 0, 0, mNotiNoGroup, user));
mNotiNoGroup2 = new Notification.Builder(getContext()).setContentTitle("D").setWhen(1202).build();
mRecordNoGroup2 = new NotificationRecord(getContext(), new StatusBarNotification("package", "package", 1, null, 0, 0, 0, mNotiNoGroup2, user));
mNotiNoGroupSortA = new Notification.Builder(getContext()).setContentTitle("E").setWhen(1201).setSortKey("A").build();
mRecordNoGroupSortA = new NotificationRecord(getContext(), new StatusBarNotification("package", "package", 1, null, 0, 0, 0, mNotiNoGroupSortA, user));
}
use of android.service.notification.StatusBarNotification in project android_frameworks_base by AOSPA.
the class NotificationGroupManager method onHeadsUpStateChanged.
@Override
public void onHeadsUpStateChanged(NotificationData.Entry entry, boolean isHeadsUp) {
final StatusBarNotification sbn = entry.notification;
if (entry.row.isHeadsUp()) {
if (shouldIsolate(sbn)) {
// We will be isolated now, so lets update the groups
onEntryRemovedInternal(entry, entry.notification);
mIsolatedEntries.put(sbn.getKey(), sbn);
onEntryAdded(entry);
// We also need to update the suppression of the old group, because this call comes
// even before the groupManager knows about the notification at all.
// When the notification gets added afterwards it is already isolated and therefore
// it doesn't lead to an update.
updateSuppression(mGroupMap.get(entry.notification.getGroupKey()));
mListener.onGroupsChanged();
} else {
handleSuppressedSummaryHeadsUpped(entry);
}
} else {
if (mIsolatedEntries.containsKey(sbn.getKey())) {
// not isolated anymore, we need to update the groups
onEntryRemovedInternal(entry, entry.notification);
mIsolatedEntries.remove(sbn.getKey());
onEntryAdded(entry);
mListener.onGroupsChanged();
}
}
}
use of android.service.notification.StatusBarNotification in project android_frameworks_base by DirtyUnicorns.
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 DirtyUnicorns.
the class BaseStatusBar method bindGuts.
private void bindGuts(final ExpandableNotificationRow row) {
row.inflateGuts();
final StatusBarNotification sbn = row.getStatusBarNotification();
PackageManager pmUser = getPackageManagerForUser(mContext, sbn.getUser().getIdentifier());
row.setTag(sbn.getPackageName());
final NotificationGuts guts = row.getGuts();
guts.setClosedListener(this);
final String pkg = sbn.getPackageName();
String appname = pkg;
Drawable pkgicon = null;
int appUid = -1;
try {
final ApplicationInfo info = pmUser.getApplicationInfo(pkg, PackageManager.GET_UNINSTALLED_PACKAGES | PackageManager.GET_DISABLED_COMPONENTS);
if (info != null) {
appname = String.valueOf(pmUser.getApplicationLabel(info));
pkgicon = pmUser.getApplicationIcon(info);
appUid = info.uid;
}
} catch (NameNotFoundException e) {
// app is gone, just show package name and generic icon
pkgicon = pmUser.getDefaultActivityIcon();
}
((ImageView) guts.findViewById(R.id.app_icon)).setImageDrawable(pkgicon);
((TextView) guts.findViewById(R.id.pkgname)).setText(appname);
final TextView settingsButton = (TextView) guts.findViewById(R.id.more_settings);
if (appUid >= 0) {
final int appUidF = appUid;
settingsButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
MetricsLogger.action(mContext, MetricsEvent.ACTION_NOTE_INFO);
guts.resetFalsingCheck();
startAppNotificationSettingsActivity(pkg, appUidF);
}
});
settingsButton.setText(R.string.notification_more_settings);
} else {
settingsButton.setVisibility(View.GONE);
}
guts.bindImportance(pmUser, sbn, mNonBlockablePkgs, mNotificationData.getImportance(sbn.getKey()));
final TextView doneButton = (TextView) guts.findViewById(R.id.done);
doneButton.setText(R.string.notification_done);
doneButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// If the user has security enabled, show challenge if the setting is changed.
if (guts.hasImportanceChanged() && isLockscreenPublicMode() && (mState == StatusBarState.KEYGUARD || mState == StatusBarState.SHADE_LOCKED)) {
OnDismissAction dismissAction = new OnDismissAction() {
@Override
public boolean onDismiss() {
saveImportanceCloseControls(sbn, row, guts, v);
return true;
}
};
onLockedNotificationImportanceChange(dismissAction);
} else {
saveImportanceCloseControls(sbn, row, guts, v);
}
}
});
}
use of android.service.notification.StatusBarNotification in project android_frameworks_base by AOSPA.
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;
}
Aggregations