From 40f5402a32e2de815188194f642afef621e1d72d Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Tue, 11 Feb 2020 12:50:59 -0500 Subject: [PATCH] Fix a11y issues in notification history - crash at large display sizes/landscape - no content description for expand buttons - no call to action on tappable notification rows Test: manual Fixes: 149307144 Change-Id: I63f59de66d96a55c48852e4fbf79c87c7826076f --- res/values/strings.xml | 3 +++ .../history/NotificationHistoryActivity.java | 6 +++++ .../NotificationHistoryViewHolder.java | 16 ++++++++++++ .../history/NotificationSbnAdapter.java | 25 +++++++++++-------- 4 files changed, 40 insertions(+), 10 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 750cd533abd..250bea14ff7 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -8055,6 +8055,9 @@ Notification history is turned off + + view notification settings + Allow notification snoozing diff --git a/src/com/android/settings/notification/history/NotificationHistoryActivity.java b/src/com/android/settings/notification/history/NotificationHistoryActivity.java index 7bd345f9eaf..a02d3aabe6a 100644 --- a/src/com/android/settings/notification/history/NotificationHistoryActivity.java +++ b/src/com/android/settings/notification/history/NotificationHistoryActivity.java @@ -77,12 +77,18 @@ public class NotificationHistoryActivity extends Activity { final View container = viewForPackage.findViewById(R.id.list_container); container.setVisibility(View.GONE); ImageButton expand = viewForPackage.findViewById(R.id.expand); + expand.setContentDescription(container.getVisibility() == View.VISIBLE + ? getString(R.string.condition_expand_hide) + : getString(R.string.condition_expand_show)); expand.setOnClickListener(v -> { container.setVisibility(container.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE); expand.setImageResource(container.getVisibility() == View.VISIBLE ? R.drawable.ic_expand_less : com.android.internal.R.drawable.ic_expand_more); + expand.setContentDescription(container.getVisibility() == View.VISIBLE + ? getString(R.string.condition_expand_hide) + : getString(R.string.condition_expand_show)); }); TextView label = viewForPackage.findViewById(R.id.label); diff --git a/src/com/android/settings/notification/history/NotificationHistoryViewHolder.java b/src/com/android/settings/notification/history/NotificationHistoryViewHolder.java index 35f5615f046..e7caa6af292 100644 --- a/src/com/android/settings/notification/history/NotificationHistoryViewHolder.java +++ b/src/com/android/settings/notification/history/NotificationHistoryViewHolder.java @@ -26,6 +26,9 @@ import android.view.View; import android.widget.DateTimeView; import android.widget.TextView; +import androidx.core.view.AccessibilityDelegateCompat; +import androidx.core.view.ViewCompat; +import androidx.core.view.accessibility.AccessibilityNodeInfoCompat; import androidx.recyclerview.widget.RecyclerView; import com.android.settings.R; @@ -66,5 +69,18 @@ public class NotificationHistoryViewHolder extends RecyclerView.ViewHolder { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); itemView.getContext().startActivityAsUser(intent, UserHandle.of(userId)); }); + ViewCompat.setAccessibilityDelegate(itemView, new AccessibilityDelegateCompat() { + @Override + public void onInitializeAccessibilityNodeInfo(View host, + AccessibilityNodeInfoCompat info) { + super.onInitializeAccessibilityNodeInfo(host, info); + CharSequence description = + host.getResources().getText(R.string.notification_history_view_settings); + AccessibilityNodeInfoCompat.AccessibilityActionCompat customClick = + new AccessibilityNodeInfoCompat.AccessibilityActionCompat( + AccessibilityNodeInfoCompat.ACTION_CLICK, description); + info.addAction(customClick); + } + }); } } diff --git a/src/com/android/settings/notification/history/NotificationSbnAdapter.java b/src/com/android/settings/notification/history/NotificationSbnAdapter.java index 80ba278e257..77740d7be59 100644 --- a/src/com/android/settings/notification/history/NotificationSbnAdapter.java +++ b/src/com/android/settings/notification/history/NotificationSbnAdapter.java @@ -28,6 +28,7 @@ import android.os.UserHandle; import android.service.notification.StatusBarNotification; import android.text.TextUtils; import android.util.Log; +import android.util.Slog; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -70,17 +71,21 @@ public class NotificationSbnAdapter extends public void onBindViewHolder(final @NonNull NotificationSbnViewHolder holder, int position) { final StatusBarNotification sbn = mValues.get(position); - holder.setIcon(loadIcon(sbn)); - holder.setPackageName(loadPackageName(sbn.getPackageName()).toString()); - holder.setTitle(getTitleString(sbn.getNotification())); - holder.setSummary(getTextString(mContext, sbn.getNotification())); - holder.setPostedTime(sbn.getPostTime()); - if (!mUserBadgeCache.containsKey(sbn.getUserId())) { - Drawable profile = mContext.getPackageManager().getUserBadgeForDensity( - UserHandle.of(sbn.getUserId()), -1); - mUserBadgeCache.put(sbn.getUserId(), profile); + if (sbn != null) { + holder.setIcon(loadIcon(sbn)); + holder.setPackageName(loadPackageName(sbn.getPackageName()).toString()); + holder.setTitle(getTitleString(sbn.getNotification())); + holder.setSummary(getTextString(mContext, sbn.getNotification())); + holder.setPostedTime(sbn.getPostTime()); + if (!mUserBadgeCache.containsKey(sbn.getUserId())) { + Drawable profile = mContext.getPackageManager().getUserBadgeForDensity( + UserHandle.of(sbn.getUserId()), -1); + mUserBadgeCache.put(sbn.getUserId(), profile); + } + holder.setProfileBadge(mUserBadgeCache.get(sbn.getUserId())); + } else { + Slog.w(TAG, "null entry in list at position " + position); } - holder.setProfileBadge(mUserBadgeCache.get(sbn.getUserId())); } @Override