Search in sources :

Example 61 with StatusBarNotification

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));
}
Also used : StatusBarNotification(android.service.notification.StatusBarNotification) UserHandle(android.os.UserHandle) Notification(android.app.Notification) StatusBarNotification(android.service.notification.StatusBarNotification)

Example 62 with StatusBarNotification

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();
        }
    }
}
Also used : StatusBarNotification(android.service.notification.StatusBarNotification)

Example 63 with StatusBarNotification

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);
    }
}
Also used : NotificationManager(android.app.NotificationManager) StatusBarNotification(android.service.notification.StatusBarNotification)

Example 64 with StatusBarNotification

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);
            }
        }
    });
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Drawable(android.graphics.drawable.Drawable) ApplicationInfo(android.content.pm.ApplicationInfo) OnDismissAction(com.android.keyguard.KeyguardHostView.OnDismissAction) ImageView(android.widget.ImageView) NotificationPanelView(com.android.systemui.statusbar.phone.NotificationPanelView) View(android.view.View) RemoteInputView(com.android.systemui.statusbar.policy.RemoteInputView) TextView(android.widget.TextView) NavigationBarView(com.android.systemui.statusbar.phone.NavigationBarView) StatusBarNotification(android.service.notification.StatusBarNotification) PackageManager(android.content.pm.PackageManager) TextView(android.widget.TextView) ImageView(android.widget.ImageView)

Example 65 with StatusBarNotification

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;
}
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)

Aggregations

StatusBarNotification (android.service.notification.StatusBarNotification)144 Notification (android.app.Notification)61 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 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)17 StatusBarIcon (com.android.internal.statusbar.StatusBarIcon)16 ITransientNotification (android.app.ITransientNotification)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 RemoteInputView (com.android.systemui.statusbar.policy.RemoteInputView)10 Drawable (android.graphics.drawable.Drawable)9 NotificationPanelView (com.android.systemui.statusbar.phone.NotificationPanelView)9