use of android.service.notification.StatusBarNotification in project android_frameworks_base by AOSPA.
the class NotificationGroupManager method onEntryAdded.
public void onEntryAdded(final NotificationData.Entry added) {
final StatusBarNotification sbn = added.notification;
boolean isGroupChild = isGroupChild(sbn);
String groupKey = getGroupKey(sbn);
NotificationGroup group = mGroupMap.get(groupKey);
if (group == null) {
group = new NotificationGroup();
mGroupMap.put(groupKey, group);
}
if (isGroupChild) {
group.children.add(added);
updateSuppression(group);
} else {
group.summary = added;
group.expanded = added.row.areChildrenExpanded();
updateSuppression(group);
if (!group.children.isEmpty()) {
HashSet<NotificationData.Entry> childrenCopy = (HashSet<NotificationData.Entry>) group.children.clone();
for (NotificationData.Entry child : childrenCopy) {
onEntryBecomingChild(child);
}
mListener.onGroupCreatedFromChildren(group);
}
}
}
use of android.service.notification.StatusBarNotification in project android_frameworks_base by AOSPA.
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);
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;
}
use of android.service.notification.StatusBarNotification in project android_frameworks_base by AOSPA.
the class BaseStatusBar method createIcon.
public StatusBarIconView createIcon(StatusBarNotification sbn) {
// Construct the icon.
Notification n = sbn.getNotification();
final StatusBarIconView iconView = new StatusBarIconView(mContext, sbn.getPackageName() + "/0x" + Integer.toHexString(sbn.getId()), n);
iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
final Icon smallIcon = n.getSmallIcon();
if (smallIcon == null) {
handleNotificationError(sbn, "No small icon in notification from " + sbn.getPackageName());
return null;
}
final StatusBarIcon ic = new StatusBarIcon(sbn.getUser(), sbn.getPackageName(), smallIcon, n.iconLevel, n.number, StatusBarIconView.contentDescForNotification(mContext, n));
if (!iconView.set(ic)) {
handleNotificationError(sbn, "Couldn't create icon: " + ic);
return null;
}
return iconView;
}
use of android.service.notification.StatusBarNotification in project android_frameworks_base by AOSPA.
the class BaseStatusBar method updateNotification.
public void updateNotification(StatusBarNotification notification, RankingMap ranking) {
if (DEBUG)
Log.d(TAG, "updateNotification(" + notification + ")");
final String key = notification.getKey();
Entry entry = mNotificationData.get(key);
if (entry == null) {
return;
} else {
mHeadsUpEntriesToRemoveOnSwitch.remove(entry);
mRemoteInputEntriesToRemoveOnCollapse.remove(entry);
}
Notification n = notification.getNotification();
mNotificationData.updateRanking(ranking);
boolean applyInPlace;
try {
applyInPlace = entry.cacheContentViews(mContext, notification.getNotification());
} catch (RuntimeException e) {
Log.e(TAG, "Unable to get notification remote views", e);
applyInPlace = false;
}
boolean shouldPeek = shouldPeek(entry, notification);
boolean alertAgain = alertAgain(entry, n);
if (DEBUG) {
Log.d(TAG, "applyInPlace=" + applyInPlace + " shouldPeek=" + shouldPeek + " alertAgain=" + alertAgain);
}
final StatusBarNotification oldNotification = entry.notification;
entry.notification = notification;
mGroupManager.onEntryUpdated(entry, oldNotification);
boolean updateSuccessful = false;
if (applyInPlace) {
if (DEBUG)
Log.d(TAG, "reusing notification for key: " + key);
try {
if (entry.icon != null) {
// Update the icon
final StatusBarIcon ic = new StatusBarIcon(notification.getUser(), notification.getPackageName(), n.getSmallIcon(), n.iconLevel, n.number, StatusBarIconView.contentDescForNotification(mContext, n));
entry.icon.setNotification(n);
if (!entry.icon.set(ic)) {
handleNotificationError(notification, "Couldn't update icon: " + ic);
return;
}
}
updateNotificationViews(entry, notification);
updateSuccessful = true;
} catch (RuntimeException e) {
// It failed to apply cleanly.
Log.w(TAG, "Couldn't reapply views for package " + notification.getPackageName(), e);
}
}
if (!updateSuccessful) {
if (DEBUG)
Log.d(TAG, "not reusing notification for key: " + key);
final StatusBarIcon ic = new StatusBarIcon(notification.getUser(), notification.getPackageName(), n.getSmallIcon(), n.iconLevel, n.number, StatusBarIconView.contentDescForNotification(mContext, n));
entry.icon.setNotification(n);
entry.icon.set(ic);
if (!inflateViews(entry, mStackScroller)) {
handleNotificationError(notification, "Couldn't update remote views for: " + notification);
}
}
updateHeadsUp(key, entry, shouldPeek, alertAgain);
updateNotifications();
if (!notification.isClearable()) {
// The user may have performed a dismiss action on the notification, since it's
// not clearable we should snap it back.
mStackScroller.snapViewIfNeeded(entry.row);
}
if (DEBUG) {
// Is this for you?
boolean isForCurrentUser = isNotificationForCurrentProfiles(notification);
Log.d(TAG, "notification is " + (isForCurrentUser ? "" : "not ") + "for you");
}
setAreThereNotifications();
}
use of android.service.notification.StatusBarNotification in project android_frameworks_base by AOSPA.
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);
}
}
});
}
Aggregations