Merge "Hide notification content in history" into security-aosp-25Q2-staging

This commit is contained in:
Julia Reynolds
2025-06-10 12:07:15 -07:00
committed by Android (Google) Code Review
3 changed files with 52 additions and 11 deletions

View File

@@ -16,6 +16,7 @@
package com.android.settings.notification.history; package com.android.settings.notification.history;
import static android.provider.Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS;
import static android.provider.Settings.Secure.NOTIFICATION_HISTORY_ENABLED; import static android.provider.Settings.Secure.NOTIFICATION_HISTORY_ENABLED;
import static android.view.View.GONE; import static android.view.View.GONE;
import static android.view.View.VISIBLE; import static android.view.View.VISIBLE;
@@ -28,9 +29,11 @@ import android.annotation.DrawableRes;
import android.app.ActionBar; import android.app.ActionBar;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.app.INotificationManager; import android.app.INotificationManager;
import android.app.KeyguardManager;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.content.res.Resources; import android.content.res.Resources;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.os.Bundle; import android.os.Bundle;
@@ -58,6 +61,7 @@ import androidx.recyclerview.widget.RecyclerView;
import com.android.internal.logging.UiEvent; import com.android.internal.logging.UiEvent;
import com.android.internal.logging.UiEventLogger; import com.android.internal.logging.UiEventLogger;
import com.android.internal.logging.UiEventLoggerImpl; import com.android.internal.logging.UiEventLoggerImpl;
import com.android.internal.widget.LockPatternUtils;
import com.android.internal.widget.NotificationExpandButton; import com.android.internal.widget.NotificationExpandButton;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.notification.NotificationBackend; import com.android.settings.notification.NotificationBackend;
@@ -68,6 +72,7 @@ import com.android.settingslib.widget.MainSwitchBar;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@@ -98,6 +103,8 @@ public class NotificationHistoryActivity extends CollapsingToolbarBaseActivity {
private UiEventLogger mUiEventLogger = new UiEventLoggerImpl(); private UiEventLogger mUiEventLogger = new UiEventLoggerImpl();
private ArrayList<Integer> mContentRestrictedUsers = new ArrayList<>();
enum NotificationHistoryEvent implements UiEventLogger.UiEventEnum { enum NotificationHistoryEvent implements UiEventLogger.UiEventEnum {
@UiEvent(doc = "User turned on notification history") @UiEvent(doc = "User turned on notification history")
NOTIFICATION_HISTORY_ON(504), NOTIFICATION_HISTORY_ON(504),
@@ -205,14 +212,14 @@ public class NotificationHistoryActivity extends CollapsingToolbarBaseActivity {
final NotificationHistoryRecyclerView rv = final NotificationHistoryRecyclerView rv =
viewForPackage.findViewById(R.id.notification_list); viewForPackage.findViewById(R.id.notification_list);
rv.setAdapter(new NotificationHistoryAdapter(mNm, rv, rv.setAdapter(new NotificationHistoryAdapter(NotificationHistoryActivity.this, mNm, rv,
newCount -> { newCount -> {
count.setText(StringUtil.getIcuPluralsString(this, newCount, count.setText(StringUtil.getIcuPluralsString(this, newCount,
R.string.notification_history_count)); R.string.notification_history_count));
if (newCount == 0) { if (newCount == 0) {
viewForPackage.setVisibility(GONE); viewForPackage.setVisibility(GONE);
} }
}, mUiEventLogger)); }, mUiEventLogger, mContentRestrictedUsers));
((NotificationHistoryAdapter) rv.getAdapter()).onRebuildComplete( ((NotificationHistoryAdapter) rv.getAdapter()).onRebuildComplete(
new ArrayList<>(nhp.notifications)); new ArrayList<>(nhp.notifications));
@@ -249,6 +256,19 @@ public class NotificationHistoryActivity extends CollapsingToolbarBaseActivity {
mPm = getPackageManager(); mPm = getPackageManager();
mUm = getSystemService(UserManager.class); mUm = getSystemService(UserManager.class);
List<UserInfo> users = mUm.getProfiles(getUserId());
for (UserInfo user : users) {
if (Settings.Secure.getIntForUser(getContentResolver(),
LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0, user.id) == 0) {
LockPatternUtils lpu = new LockPatternUtils(this);
KeyguardManager km = getSystemService(KeyguardManager.class);
if (lpu.isSecure(user.id) && km.isDeviceLocked(user.id)) {
mContentRestrictedUsers.add(user.id);
}
}
}
// wait for history loading and recent/snooze loading // wait for history loading and recent/snooze loading
mCountdownLatch = new CountDownLatch(2); mCountdownLatch = new CountDownLatch(2);
@@ -419,7 +439,7 @@ public class NotificationHistoryActivity extends CollapsingToolbarBaseActivity {
mSnoozedRv.setLayoutManager(lm); mSnoozedRv.setLayoutManager(lm);
mSnoozedRv.setAdapter( mSnoozedRv.setAdapter(
new NotificationSbnAdapter(NotificationHistoryActivity.this, mPm, mUm, new NotificationSbnAdapter(NotificationHistoryActivity.this, mPm, mUm,
true, mUiEventLogger)); true, mUiEventLogger, mContentRestrictedUsers));
mSnoozedRv.setNestedScrollingEnabled(false); mSnoozedRv.setNestedScrollingEnabled(false);
if (snoozed == null || snoozed.length == 0) { if (snoozed == null || snoozed.length == 0) {
@@ -435,7 +455,7 @@ public class NotificationHistoryActivity extends CollapsingToolbarBaseActivity {
mDismissedRv.setLayoutManager(dismissLm); mDismissedRv.setLayoutManager(dismissLm);
mDismissedRv.setAdapter( mDismissedRv.setAdapter(
new NotificationSbnAdapter(NotificationHistoryActivity.this, mPm, mUm, new NotificationSbnAdapter(NotificationHistoryActivity.this, mPm, mUm,
false, mUiEventLogger)); false, mUiEventLogger, mContentRestrictedUsers));
mDismissedRv.setNestedScrollingEnabled(false); mDismissedRv.setNestedScrollingEnabled(false);
if (dismissed == null || dismissed.length == 0) { if (dismissed == null || dismissed.length == 0) {

View File

@@ -22,6 +22,7 @@ import static android.provider.Settings.EXTRA_CONVERSATION_ID;
import android.app.INotificationManager; import android.app.INotificationManager;
import android.app.NotificationHistory.HistoricalNotification; import android.app.NotificationHistory.HistoricalNotification;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.RemoteException; import android.os.RemoteException;
@@ -53,16 +54,23 @@ public class NotificationHistoryAdapter extends
private List<HistoricalNotification> mValues; private List<HistoricalNotification> mValues;
private OnItemDeletedListener mListener; private OnItemDeletedListener mListener;
private UiEventLogger mUiEventLogger; private UiEventLogger mUiEventLogger;
public NotificationHistoryAdapter(INotificationManager nm, private ArrayList<Integer> mContentRestrictedUsers = new ArrayList<>();
Context mContext;
public NotificationHistoryAdapter(Context context,
INotificationManager nm,
NotificationHistoryRecyclerView listView, NotificationHistoryRecyclerView listView,
OnItemDeletedListener listener, OnItemDeletedListener listener,
UiEventLogger uiEventLogger) { UiEventLogger uiEventLogger,
ArrayList<Integer> contentRestrictedUsers) {
mContext = context;
mValues = new ArrayList<>(); mValues = new ArrayList<>();
setHasStableIds(true); setHasStableIds(true);
listView.setOnItemSwipeDeleteListener(this); listView.setOnItemSwipeDeleteListener(this);
mNm = nm; mNm = nm;
mListener = listener; mListener = listener;
mUiEventLogger = uiEventLogger; mUiEventLogger = uiEventLogger;
mContentRestrictedUsers = contentRestrictedUsers;
} }
@Override @Override
@@ -81,8 +89,13 @@ public class NotificationHistoryAdapter extends
public void onBindViewHolder(final @NonNull NotificationHistoryViewHolder holder, public void onBindViewHolder(final @NonNull NotificationHistoryViewHolder holder,
int position) { int position) {
final HistoricalNotification hn = mValues.get(position); final HistoricalNotification hn = mValues.get(position);
holder.setTitle(hn.getTitle()); if (mContentRestrictedUsers.contains(hn.getUserId())) {
holder.setSummary(hn.getText()); holder.setSummary(mContext.getString(
com.android.internal.R.string.notification_hidden_text));
} else {
holder.setTitle(hn.getTitle());
holder.setSummary(hn.getText());
}
holder.setPostedTime(hn.getPostedTimeMs()); holder.setPostedTime(hn.getPostedTimeMs());
final View.OnClickListener onClick = v -> { final View.OnClickListener onClick = v -> {
mUiEventLogger.logWithPosition(NotificationHistoryActivity.NotificationHistoryEvent mUiEventLogger.logWithPosition(NotificationHistoryActivity.NotificationHistoryEvent

View File

@@ -78,9 +78,11 @@ public class NotificationSbnAdapter extends
private List<Integer> mEnabledProfiles = new ArrayList<>(); private List<Integer> mEnabledProfiles = new ArrayList<>();
private boolean mIsSnoozed; private boolean mIsSnoozed;
private UiEventLogger mUiEventLogger; private UiEventLogger mUiEventLogger;
private ArrayList<Integer> mContentRestrictedUsers = new ArrayList<>();
public NotificationSbnAdapter(Context context, PackageManager pm, UserManager um, public NotificationSbnAdapter(Context context, PackageManager pm, UserManager um,
boolean isSnoozed, UiEventLogger uiEventLogger) { boolean isSnoozed, UiEventLogger uiEventLogger,
ArrayList<Integer> contentRestrictedUsers) {
mContext = context; mContext = context;
mPm = pm; mPm = pm;
mUserBadgeCache = new HashMap<>(); mUserBadgeCache = new HashMap<>();
@@ -101,6 +103,7 @@ public class NotificationSbnAdapter extends
// If true, this is the panel for snoozed notifs, otherwise the one for dismissed notifs. // If true, this is the panel for snoozed notifs, otherwise the one for dismissed notifs.
mIsSnoozed = isSnoozed; mIsSnoozed = isSnoozed;
mUiEventLogger = uiEventLogger; mUiEventLogger = uiEventLogger;
mContentRestrictedUsers = contentRestrictedUsers;
} }
@Override @Override
@@ -128,8 +131,13 @@ public class NotificationSbnAdapter extends
holder.setIconBackground(loadBackground(sbn)); holder.setIconBackground(loadBackground(sbn));
holder.setIcon(loadIcon(sbn)); holder.setIcon(loadIcon(sbn));
holder.setPackageLabel(loadPackageLabel(sbn.getPackageName()).toString()); holder.setPackageLabel(loadPackageLabel(sbn.getPackageName()).toString());
holder.setTitle(getTitleString(sbn.getNotification())); if (mContentRestrictedUsers.contains(sbn.getNormalizedUserId())) {
holder.setSummary(getTextString(mContext, sbn.getNotification())); holder.setSummary(mContext.getString(
com.android.internal.R.string.notification_hidden_text));
} else {
holder.setTitle(getTitleString(sbn.getNotification()));
holder.setSummary(getTextString(mContext, sbn.getNotification()));
}
holder.setPostedTime(sbn.getPostTime()); holder.setPostedTime(sbn.getPostTime());
int userId = normalizeUserId(sbn); int userId = normalizeUserId(sbn);
if (!mUserBadgeCache.containsKey(userId)) { if (!mUserBadgeCache.containsKey(userId)) {