diff options
5 files changed, 74 insertions, 15 deletions
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 8ed52a1bba59..cab2114f6918 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -4202,9 +4202,22 @@ public class Notification implements Parcelable           * @hide           */          public RemoteViews makePublicContentView() { +            return makePublicView(false /* ambient */); +        } + +        /** +         * Construct a RemoteViews for the display in public contexts like on the lockscreen. +         * +         * @hide +         */ +        public RemoteViews makePublicAmbientNotification() { +            return makePublicView(true /* ambient */); +        } + +        private RemoteViews makePublicView(boolean ambient) {              if (mN.publicVersion != null) {                  final Builder builder = recoverBuilder(mContext, mN.publicVersion); -                return builder.createContentView(); +                return ambient ? builder.makeAmbientNotification() : builder.createContentView();              }              Bundle savedBundle = mN.extras;              Style style = mStyle; @@ -4221,14 +4234,15 @@ public class Notification implements Parcelable              publicExtras.putBoolean(EXTRA_CHRONOMETER_COUNT_DOWN,                      savedBundle.getBoolean(EXTRA_CHRONOMETER_COUNT_DOWN));              publicExtras.putCharSequence(EXTRA_TITLE, -                    mContext.getString(R.string.notification_hidden_text)); +                    mContext.getString(com.android.internal.R.string.notification_hidden_text));              mN.extras = publicExtras; -            final RemoteViews publicView = applyStandardTemplate(getBaseLayoutResource()); +            final RemoteViews view = ambient ? makeAmbientNotification() +                    : applyStandardTemplate(getBaseLayoutResource());              mN.extras = savedBundle;              mN.mLargeIcon = largeIcon;              mN.largeIcon = largeIconLegacy;              mStyle = style; -            return publicView; +            return view;          }          /** diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java index 677642e53d6e..cc9175382903 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java @@ -1115,6 +1115,10 @@ public class ExpandableNotificationRow extends ActivatableNotificationView          mNotificationInflater.setInflateExceptionHandler(inflateExceptionHandler);      } +    public void setNeedsRedaction(boolean needsRedaction) { +        mNotificationInflater.setRedactAmbient(needsRedaction); +    } +      public interface ExpansionLogger {          public void logNotificationExpansion(String key, boolean userAction, boolean expanded);      } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java index 8f160dc0384e..609856522e75 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java @@ -428,6 +428,9 @@ public class NotificationContentView extends FrameLayout {              mAmbientChild.animate().cancel();              removeView(mAmbientChild);          } +        if (child == null) { +            return; +        }          addView(child);          mAmbientChild = child;          mAmbientWrapper = NotificationViewWrapper.wrap(getContext(), child, diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationInflater.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationInflater.java index 73eecbbf2728..2e34f2483a85 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationInflater.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationInflater.java @@ -21,6 +21,8 @@ import android.content.Context;  import android.service.notification.StatusBarNotification;  import android.util.Log;  import android.view.View; +import android.view.ViewGroup; +import android.view.ViewParent;  import android.widget.RemoteViews;  import com.android.internal.annotations.VisibleForTesting; @@ -49,6 +51,7 @@ public class NotificationInflater {      private RemoteViews.OnClickHandler mRemoteViewClickHandler;      private boolean mIsChildInGroup;      private InflationExceptionHandler mInflateExceptionHandler; +    private boolean mRedactAmbient;      public NotificationInflater(ExpandableNotificationRow row) {          mRow = row; @@ -92,6 +95,21 @@ public class NotificationInflater {          mRemoteViewClickHandler = remoteViewClickHandler;      } +    public void setRedactAmbient(boolean redactAmbient) { +        if (mRedactAmbient != redactAmbient) { +            mRedactAmbient = redactAmbient; +            if (mRow.getEntry() == null) { +                return; +            } +            try { +                inflateNotificationViews(FLAG_REINFLATE_AMBIENT_VIEW); +            } catch (InflationException e) { +                mInflateExceptionHandler.handleInflationException( +                        mRow.getStatusBarNotification(), e); +            } +        } +    } +      public void inflateNotificationViews() throws InflationException {          inflateNotificationViews(FLAG_REINFLATE_ALL);      } @@ -123,6 +141,8 @@ public class NotificationInflater {              Notification.Builder builder, Context packageContext) {          NotificationData.Entry entry = mRow.getEntry();          NotificationContentView privateLayout = mRow.getPrivateLayout(); +        NotificationContentView publicLayout = mRow.getPublicLayout(); +          boolean isLowPriority = mIsLowPriority && !mIsChildInGroup;          if ((reInflateFlags & FLAG_REINFLATE_CONTENT_VIEW) != 0) {              final RemoteViews newContentView = createContentView(builder, @@ -190,7 +210,6 @@ public class NotificationInflater {          }          if ((reInflateFlags & FLAG_REINFLATE_PUBLIC_VIEW) != 0) { -            NotificationContentView publicLayout = mRow.getPublicLayout();              final RemoteViews newPublicNotification                      = builder.makePublicContentView();              if (!compareRemoteViews(newPublicNotification, entry.cachedPublicContentView)) { @@ -209,18 +228,24 @@ public class NotificationInflater {          }          if ((reInflateFlags & FLAG_REINFLATE_AMBIENT_VIEW) != 0) { -            final RemoteViews newAmbientNotification -                    = builder.makeAmbientNotification(); -            if (!compareRemoteViews(newAmbientNotification, entry.cachedAmbientContentView)) { +            final RemoteViews newAmbientNotification = mRedactAmbient +                    ? builder.makePublicAmbientNotification() +                    : builder.makeAmbientNotification(); +            NotificationContentView newParent = mRedactAmbient ? publicLayout : privateLayout; +            NotificationContentView otherParent = !mRedactAmbient ? publicLayout : privateLayout; + +            if (newParent.getAmbientChild() == null || +                    !compareRemoteViews(newAmbientNotification, entry.cachedAmbientContentView)) {                  View ambientContentView = newAmbientNotification.apply(                          packageContext, -                        privateLayout, +                        newParent,                          mRemoteViewClickHandler);                  ambientContentView.setIsRootNamespace(true); -                privateLayout.setAmbientChild(ambientContentView); +                newParent.setAmbientChild(ambientContentView); +                otherParent.setAmbientChild(null);              } else {                  newAmbientNotification.reapply(packageContext, -                        privateLayout.getAmbientChild(), +                        newParent.getAmbientChild(),                          mRemoteViewClickHandler);              }              entry.cachedAmbientContentView = newAmbientNotification; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java index aeee6cb8a07c..79191f3c2114 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java @@ -49,10 +49,8 @@ import android.content.Context;  import android.content.Intent;  import android.content.IntentFilter;  import android.content.IntentSender; -import android.content.pm.ActivityInfo;  import android.content.pm.IPackageManager;  import android.content.pm.PackageManager; -import android.content.pm.ResolveInfo;  import android.content.res.Configuration;  import android.content.res.Resources;  import android.database.ContentObserver; @@ -141,7 +139,6 @@ import com.android.systemui.doze.DozeLog;  import com.android.systemui.fragments.FragmentHostManager;  import com.android.systemui.fragments.PluginFragmentListener;  import com.android.systemui.keyguard.KeyguardViewMediator; -import com.android.systemui.pip.phone.PipManager;  import com.android.systemui.plugins.qs.QS;  import com.android.systemui.plugins.ActivityStarter;  import com.android.systemui.plugins.statusbar.NotificationSwipeActionHelper.SnoozeOption; @@ -1814,6 +1811,7 @@ public class StatusBar extends SystemUI implements DemoMode,                  updatePublicContentView(ent, ent.notification);              }              ent.row.setSensitive(sensitive, deviceSensitive); +            ent.row.setNeedsRedaction(needsRedaction(ent));              if (mGroupManager.isChildInGroupWithSummary(ent.row.getStatusBarNotification())) {                  ExpandableNotificationRow summary = mGroupManager.getGroupSummary(                          ent.row.getStatusBarNotification()); @@ -1902,6 +1900,21 @@ public class StatusBar extends SystemUI implements DemoMode,          mNotificationIconAreaController.updateNotificationIcons(mNotificationData);      } +    /** @return true if the entry needs redaction when on the lockscreen. */ +    private boolean needsRedaction(Entry ent) { +        int userId = ent.notification.getUserId(); + +        boolean currentUserWantsRedaction = !userAllowsPrivateNotificationsInPublic(mCurrentUserId); +        boolean notiUserWantsRedaction = !userAllowsPrivateNotificationsInPublic(userId); +        boolean redactedLockscreen = currentUserWantsRedaction || notiUserWantsRedaction; + +        boolean notificationRequestsRedaction = +                ent.notification.getNotification().visibility == Notification.VISIBILITY_PRIVATE; +        boolean userForcesRedaction = packageHasVisibilityOverride(ent.notification.getKey()); + +        return userForcesRedaction || notificationRequestsRedaction && redactedLockscreen; +    } +      /**       * Disable QS if device not provisioned.       * If the user switcher is simple then disable QS during setup because @@ -6166,6 +6179,7 @@ public class StatusBar extends SystemUI implements DemoMode,              }          } +        row.setNeedsRedaction(needsRedaction(entry));          boolean isLowPriority = mNotificationData.isAmbient(sbn.getKey());          row.setIsLowPriority(isLowPriority);          // bind the click event to the content area @@ -6530,7 +6544,6 @@ public class StatusBar extends SystemUI implements DemoMode,          NotificationData.Entry entry = new NotificationData.Entry(sbn);          Dependency.get(LeakDetector.class).trackInstance(entry);          entry.createIcons(mContext, sbn); -          // Construct the expanded view.          inflateViews(entry, mStackScroller);          return entry;  |