Search in sources :

Example 11 with StatusBarNotification

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

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 12 with StatusBarNotification

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

the class NotificationChildrenContainer method recreateNotificationHeader.

public void recreateNotificationHeader(OnClickListener listener, StatusBarNotification notification) {
    final Notification.Builder builder = Notification.Builder.recoverBuilder(getContext(), mNotificationParent.getStatusBarNotification().getNotification());
    final RemoteViews header = builder.makeNotificationHeader();
    if (mNotificationHeader == null) {
        mNotificationHeader = (NotificationHeaderView) header.apply(getContext(), this);
        final View expandButton = mNotificationHeader.findViewById(com.android.internal.R.id.expand_button);
        expandButton.setVisibility(VISIBLE);
        mNotificationHeader.setOnClickListener(listener);
        mNotificationHeaderWrapper = NotificationViewWrapper.wrap(getContext(), mNotificationHeader, mNotificationParent);
        addView(mNotificationHeader, 0);
        invalidate();
    } else {
        header.reapply(getContext(), mNotificationHeader);
        mNotificationHeaderWrapper.notifyContentUpdated(notification);
    }
    updateChildrenHeaderAppearance();
}
Also used : RemoteViews(android.widget.RemoteViews) View(android.view.View) HybridNotificationView(com.android.systemui.statusbar.notification.HybridNotificationView) TextView(android.widget.TextView) NotificationPanelView(com.android.systemui.statusbar.phone.NotificationPanelView) NotificationHeaderView(android.view.NotificationHeaderView) Notification(android.app.Notification) StatusBarNotification(android.service.notification.StatusBarNotification)

Example 13 with StatusBarNotification

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

the class BaseStatusBar method inflateViews.

protected boolean inflateViews(Entry entry, ViewGroup parent) {
    PackageManager pmUser = getPackageManagerForUser(mContext, entry.notification.getUser().getIdentifier());
    final StatusBarNotification sbn = entry.notification;
    try {
        entry.cacheContentViews(mContext, null);
    } catch (RuntimeException e) {
        Log.e(TAG, "Unable to get notification remote views", e);
        return false;
    }
    final RemoteViews contentView = entry.cachedContentView;
    final RemoteViews bigContentView = entry.cachedBigContentView;
    final RemoteViews headsUpContentView = entry.cachedHeadsUpContentView;
    final RemoteViews publicContentView = entry.cachedPublicContentView;
    if (contentView == null) {
        Log.v(TAG, "no contentView for: " + sbn.getNotification());
        return false;
    }
    if (DEBUG) {
        Log.v(TAG, "publicContentView: " + publicContentView);
    }
    ExpandableNotificationRow row;
    // Stash away previous user expansion state so we can restore it at
    // the end.
    boolean hasUserChangedExpansion = false;
    boolean userExpanded = false;
    boolean userLocked = false;
    if (entry.row != null) {
        row = entry.row;
        hasUserChangedExpansion = row.hasUserChangedExpansion();
        userExpanded = row.isUserExpanded();
        userLocked = row.isUserLocked();
        entry.reset();
        if (hasUserChangedExpansion) {
            row.setUserExpanded(userExpanded);
        }
    } else {
        // create the row view
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        // cannot use isMediaNotification()
        if (sbn.getNotification().category != null && sbn.getNotification().category.equals(Notification.CATEGORY_TRANSPORT)) {
            Log.d("ro", "inflating media notification");
            row = (MediaExpandableNotificationRow) inflater.inflate(R.layout.status_bar_notification_row_media, parent, false);
            ((MediaExpandableNotificationRow) row).setMediaController(getCurrentMediaController());
        } else {
            row = (ExpandableNotificationRow) inflater.inflate(R.layout.status_bar_notification_row, parent, false);
        }
        row.setExpansionLogger(this, entry.notification.getKey());
        row.setGroupManager(mGroupManager);
        row.setHeadsUpManager(mHeadsUpManager);
        row.setRemoteInputController(mRemoteInputController);
        row.setOnExpandClickListener(this);
        // Get the app name.
        // Note that Notification.Builder#bindHeaderAppName has similar logic
        // but since this field is used in the guts, it must be accurate.
        // Therefore we will only show the application label, or, failing that, the
        // package name. No substitutions.
        final String pkg = sbn.getPackageName();
        String appname = pkg;
        try {
            final ApplicationInfo info = pmUser.getApplicationInfo(pkg, PackageManager.GET_UNINSTALLED_PACKAGES | PackageManager.GET_DISABLED_COMPONENTS);
            if (info != null) {
                appname = String.valueOf(pmUser.getApplicationLabel(info));
            }
        } catch (NameNotFoundException e) {
        // Do nothing
        }
        row.setAppName(appname);
    }
    workAroundBadLayerDrawableOpacity(row);
    bindDismissListener(row);
    // NB: the large icon is now handled entirely by the template
    // bind the click event to the content area
    NotificationContentView contentContainer = row.getPrivateLayout();
    NotificationContentView contentContainerPublic = row.getPublicLayout();
    row.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
    if (ENABLE_REMOTE_INPUT) {
        row.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
    }
    mNotificationClicker.register(row, sbn);
    // set up the adaptive layout
    View contentViewLocal = null;
    View bigContentViewLocal = null;
    View headsUpContentViewLocal = null;
    View publicViewLocal = null;
    try {
        contentViewLocal = contentView.apply(sbn.getPackageContext(mContext), contentContainer, mOnClickHandler);
        if (bigContentView != null) {
            bigContentViewLocal = bigContentView.apply(sbn.getPackageContext(mContext), contentContainer, mOnClickHandler);
        }
        if (headsUpContentView != null) {
            headsUpContentViewLocal = headsUpContentView.apply(sbn.getPackageContext(mContext), contentContainer, mOnClickHandler);
        }
        if (publicContentView != null) {
            publicViewLocal = publicContentView.apply(sbn.getPackageContext(mContext), contentContainerPublic, mOnClickHandler);
        }
        if (contentViewLocal != null) {
            contentViewLocal.setIsRootNamespace(true);
            contentContainer.setContractedChild(contentViewLocal);
        }
        if (bigContentViewLocal != null) {
            bigContentViewLocal.setIsRootNamespace(true);
            contentContainer.setExpandedChild(bigContentViewLocal);
        }
        if (headsUpContentViewLocal != null) {
            headsUpContentViewLocal.setIsRootNamespace(true);
            contentContainer.setHeadsUpChild(headsUpContentViewLocal);
        }
        if (publicViewLocal != null) {
            publicViewLocal.setIsRootNamespace(true);
            contentContainerPublic.setContractedChild(publicViewLocal);
        }
    } catch (RuntimeException e) {
        final String ident = sbn.getPackageName() + "/0x" + Integer.toHexString(sbn.getId());
        Log.e(TAG, "couldn't inflate view for notification " + ident, e);
        return false;
    }
    // Extract target SDK version.
    try {
        ApplicationInfo info = pmUser.getApplicationInfo(sbn.getPackageName(), 0);
        entry.targetSdk = info.targetSdkVersion;
    } catch (NameNotFoundException ex) {
        Log.e(TAG, "Failed looking up ApplicationInfo for " + sbn.getPackageName(), ex);
    }
    entry.autoRedacted = entry.notification.getNotification().publicVersion == null;
    if (MULTIUSER_DEBUG) {
        TextView debug = (TextView) row.findViewById(R.id.debug_info);
        if (debug != null) {
            debug.setVisibility(View.VISIBLE);
            debug.setText("CU " + mCurrentUserId + " NU " + entry.notification.getUserId());
        }
    }
    entry.row = row;
    entry.row.setOnActivatedListener(this);
    entry.row.setExpandable(bigContentViewLocal != null);
    applyColorsAndBackgrounds(sbn, entry);
    // Restore previous flags.
    if (hasUserChangedExpansion) {
        // Note: setUserExpanded() conveniently ignores calls with
        //       userExpanded=true if !isExpandable().
        row.setUserExpanded(userExpanded);
    }
    row.setUserLocked(userLocked);
    row.onNotificationUpdated(entry);
    return true;
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ApplicationInfo(android.content.pm.ApplicationInfo) GestureAnywhereView(com.android.systemui.chaos.lab.gestureanywhere.GestureAnywhereView) 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) RemoteViews(android.widget.RemoteViews) PackageManager(android.content.pm.PackageManager) StatusBarNotification(android.service.notification.StatusBarNotification) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView)

Example 14 with StatusBarNotification

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

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);
            }
        }
        long now = SystemClock.elapsedRealtime();
        pw.println("\n  Last notification sound timestamps:");
        for (Map.Entry<String, Long> entry : mLastSoundTimestamps.entrySet()) {
            pw.print("    " + entry.getKey() + " -> ");
            TimeUtils.formatDuration(entry.getValue(), now, pw);
            pw.println(" ago");
        }
    }
}
Also used : ManagedServiceInfo(com.android.server.notification.ManagedServices.ManagedServiceInfo) StatusBarNotification(android.service.notification.StatusBarNotification) Map(java.util.Map) HashMap(java.util.HashMap) ArrayMap(android.util.ArrayMap)

Example 15 with StatusBarNotification

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

the class PhoneStatusBar method removeNotification.

@Override
public void removeNotification(String key, RankingMap ranking) {
    boolean deferRemoval = false;
    if (mHeadsUpManager.isHeadsUp(key)) {
        // A cancel() in repsonse to a remote input shouldn't be delayed, as it makes the
        // sending look longer than it takes.
        // Also we should not defer the removal if reordering isn't allowed since otherwise
        // some notifications can't disappear before the panel is closed.
        boolean ignoreEarliestRemovalTime = mRemoteInputController.isSpinning(key) && !FORCE_REMOTE_INPUT_HISTORY || !mVisualStabilityManager.isReorderingAllowed();
        deferRemoval = !mHeadsUpManager.removeNotification(key, ignoreEarliestRemovalTime);
    }
    if (key.equals(mMediaNotificationKey)) {
        clearCurrentMediaNotification();
        updateMediaMetaData(true, true);
    }
    if (FORCE_REMOTE_INPUT_HISTORY && mRemoteInputController.isSpinning(key)) {
        Entry entry = mNotificationData.get(key);
        StatusBarNotification sbn = entry.notification;
        Notification.Builder b = Notification.Builder.recoverBuilder(mContext, sbn.getNotification().clone());
        CharSequence[] oldHistory = sbn.getNotification().extras.getCharSequenceArray(Notification.EXTRA_REMOTE_INPUT_HISTORY);
        CharSequence[] newHistory;
        if (oldHistory == null) {
            newHistory = new CharSequence[1];
        } else {
            newHistory = new CharSequence[oldHistory.length + 1];
            for (int i = 0; i < oldHistory.length; i++) {
                newHistory[i + 1] = oldHistory[i];
            }
        }
        newHistory[0] = String.valueOf(entry.remoteInputText);
        b.setRemoteInputHistory(newHistory);
        Notification newNotification = b.build();
        // Undo any compatibility view inflation
        newNotification.contentView = sbn.getNotification().contentView;
        newNotification.bigContentView = sbn.getNotification().bigContentView;
        newNotification.headsUpContentView = sbn.getNotification().headsUpContentView;
        StatusBarNotification newSbn = new StatusBarNotification(sbn.getPackageName(), sbn.getOpPkg(), sbn.getId(), sbn.getTag(), sbn.getUid(), sbn.getInitialPid(), 0, newNotification, sbn.getUser(), sbn.getPostTime());
        updateNotification(newSbn, null);
        mKeysKeptForRemoteInput.add(entry.key);
        return;
    }
    if (deferRemoval) {
        mLatestRankingMap = ranking;
        mHeadsUpEntriesToRemoveOnSwitch.add(mHeadsUpManager.getEntry(key));
        return;
    }
    Entry entry = mNotificationData.get(key);
    if (entry != null && mRemoteInputController.isRemoteInputActive(entry) && (entry.row != null && !entry.row.isDismissed())) {
        mLatestRankingMap = ranking;
        mRemoteInputEntriesToRemoveOnCollapse.add(entry);
        return;
    }
    if (entry != null && entry.row != null) {
        entry.row.setRemoved();
    }
    // Let's remove the children if this was a summary
    handleGroupSummaryRemoved(key, ranking);
    StatusBarNotification old = removeNotificationViews(key, ranking);
    if (SPEW)
        Log.d(TAG, "removeNotification key=" + key + " old=" + old);
    if (old != null) {
        // Cancel the ticker if it's still running
        if (mTickerEnabled != 0) {
            mTicker.removeEntry(old);
        }
        if (CLOSE_PANEL_WHEN_EMPTIED && !hasActiveNotifications() && !mNotificationPanel.isTracking() && !mNotificationPanel.isQsExpanded()) {
            if (mState == StatusBarState.SHADE) {
                animateCollapsePanels();
            } else if (mState == StatusBarState.SHADE_LOCKED && !isCollapsing()) {
                goToKeyguard();
            }
        }
    }
    setAreThereNotifications();
}
Also used : Entry(com.android.systemui.statusbar.NotificationData.Entry) StatusBarNotification(android.service.notification.StatusBarNotification) Notification(android.app.Notification) StatusBarNotification(android.service.notification.StatusBarNotification) Point(android.graphics.Point)

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