Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 62b51e4a authored by Jeff DeCew's avatar Jeff DeCew Committed by Android (Google) Code Review
Browse files

Merge "Remove FSI_FORCE_DEMOTE and SHOW_STICKY_HUN_FOR_DENIED_FSI" into main

parents 204f79c0 990877ef
Loading
Loading
Loading
Loading
+0 −12
Original line number Diff line number Diff line
@@ -54,18 +54,6 @@ public class SystemUiSystemPropertiesFlags {
     */
    public static final class NotificationFlags {

        /**
         * FOR DEVELOPMENT / TESTING ONLY!!!
         * Forcibly demote *ALL* FSI notifications as if no apps have the app op permission.
         * NOTE: enabling this implies SHOW_STICKY_HUN_FOR_DENIED_FSI in SystemUI
         */
        public static final Flag FSI_FORCE_DEMOTE =
                devFlag("persist.sysui.notification.fsi_force_demote");

        /** Gating the feature which shows FSI-denied notifications as Sticky HUNs */
        public static final Flag SHOW_STICKY_HUN_FOR_DENIED_FSI =
                releasedFlag("persist.sysui.notification.show_sticky_hun_for_denied_fsi");

        /** Gating the logging of DND state change events. */
        public static final Flag LOG_DND_STATE_EVENTS =
                releasedFlag("persist.sysui.notification.log_dnd_state_events");
+14 −40
Original line number Diff line number Diff line
@@ -4021,11 +4021,8 @@ public class NotificationManagerService extends SystemService {
                Slog.e(TAG, "Failed to getApplicationInfo() in canUseFullScreenIntent()", e);
                return false;
            }
            final boolean showStickyHunIfDenied = mFlagResolver.isEnabled(
                    SystemUiSystemPropertiesFlags.NotificationFlags
                            .SHOW_STICKY_HUN_FOR_DENIED_FSI);
            return checkUseFullScreenIntentPermission(attributionSource, applicationInfo,
                    showStickyHunIfDenied /* isAppOpPermission */, false /* forDataDelivery */);
                    false /* forDataDelivery */);
        }
        @Override
@@ -7274,28 +7271,12 @@ public class NotificationManagerService extends SystemService {
        notification.flags &= ~FLAG_FSI_REQUESTED_BUT_DENIED;
        if (notification.fullScreenIntent != null) {
            final boolean forceDemoteFsiToStickyHun = mFlagResolver.isEnabled(
                    SystemUiSystemPropertiesFlags.NotificationFlags.FSI_FORCE_DEMOTE);
            if (forceDemoteFsiToStickyHun) {
                makeStickyHun(notification, pkg, userId);
            } else {
            final AttributionSource attributionSource =
                    new AttributionSource.Builder(notificationUid).setPackageName(pkg).build();
                final boolean showStickyHunIfDenied = mFlagResolver.isEnabled(
                        SystemUiSystemPropertiesFlags.NotificationFlags
                                .SHOW_STICKY_HUN_FOR_DENIED_FSI);
            final boolean canUseFullScreenIntent = checkUseFullScreenIntentPermission(
                        attributionSource, ai, showStickyHunIfDenied /* isAppOpPermission */,
                        true /* forDataDelivery */);
                    attributionSource, ai, true /* forDataDelivery */);
            if (!canUseFullScreenIntent) {
                    if (showStickyHunIfDenied) {
                makeStickyHun(notification, pkg, userId);
                    } else {
                        notification.fullScreenIntent = null;
                        Slog.w(TAG, "Package " + pkg + ": Use of fullScreenIntent requires the"
                                + "USE_FULL_SCREEN_INTENT permission");
                    }
                }
            }
        }
@@ -7402,12 +7383,11 @@ public class NotificationManagerService extends SystemService {
    }
    private boolean checkUseFullScreenIntentPermission(@NonNull AttributionSource attributionSource,
            @NonNull ApplicationInfo applicationInfo, boolean isAppOpPermission,
            @NonNull ApplicationInfo applicationInfo,
            boolean forDataDelivery) {
        if (applicationInfo.targetSdkVersion < Build.VERSION_CODES.Q) {
            return true;
        }
        if (isAppOpPermission) {
        final int permissionResult;
        if (forDataDelivery) {
            permissionResult = mPermissionManager.checkPermissionForDataDelivery(
@@ -7417,12 +7397,6 @@ public class NotificationManagerService extends SystemService {
                    permission.USE_FULL_SCREEN_INTENT, attributionSource);
        }
        return permissionResult == PermissionManager.PERMISSION_GRANTED;
        } else {
            final int permissionResult = getContext().checkPermission(
                    permission.USE_FULL_SCREEN_INTENT, attributionSource.getPid(),
                    attributionSource.getUid());
            return permissionResult == PERMISSION_GRANTED;
        }
    }
    private void checkRemoteViews(String pkg, String tag, int id, Notification notification) {
+3 −9
Original line number Diff line number Diff line
@@ -530,16 +530,13 @@ interface NotificationRecordLogger {
            this.timeout_millis = p.r.getSbn().getNotification().getTimeoutAfter();
            this.is_non_dismissible = NotificationRecordLogger.isNonDismissible(p.r);

            final boolean isStickyHunFlagEnabled = SystemUiSystemPropertiesFlags.getResolver()
                    .isEnabled(NotificationFlags.SHOW_STICKY_HUN_FOR_DENIED_FSI);

            final boolean hasFullScreenIntent =
                    p.r.getSbn().getNotification().fullScreenIntent != null;

            final boolean hasFsiRequestedButDeniedFlag =  (p.r.getSbn().getNotification().flags
                    & Notification.FLAG_FSI_REQUESTED_BUT_DENIED) != 0;

            this.fsi_state = NotificationRecordLogger.getFsiState(isStickyHunFlagEnabled,
            this.fsi_state = NotificationRecordLogger.getFsiState(
                    hasFullScreenIntent, hasFsiRequestedButDeniedFlag, eventType);

            this.is_locked = p.r.isLocked();
@@ -587,13 +584,10 @@ interface NotificationRecordLogger {
     * @return FrameworkStatsLog enum of the state of the full screen intent posted with this
     * notification.
     */
    static int getFsiState(boolean isStickyHunFlagEnabled,
                           boolean hasFullScreenIntent,
    static int getFsiState(boolean hasFullScreenIntent,
                           boolean hasFsiRequestedButDeniedFlag,
                           NotificationReportedEvent eventType) {

        if (!isStickyHunFlagEnabled
                || eventType == NotificationReportedEvent.NOTIFICATION_UPDATED) {
        if (eventType == NotificationReportedEvent.NOTIFICATION_UPDATED) {
            // Zeroes in protos take zero bandwidth, but non-zero numbers take bandwidth,
            // so we should log 0 when possible.
            return 0;
+6 −15
Original line number Diff line number Diff line
@@ -2143,10 +2143,7 @@ public class PreferencesHelper implements RankingConfig {
     * @return State of the full screen intent permission for this package.
     */
    @VisibleForTesting
    int getFsiState(String pkg, int uid, boolean requestedFSIPermission, boolean isFlagEnabled) {
        if (!isFlagEnabled) {
            return 0;
        }
    int getFsiState(String pkg, int uid, boolean requestedFSIPermission) {
        if (!requestedFSIPermission) {
            return PACKAGE_NOTIFICATION_PREFERENCES__FSI_STATE__NOT_REQUESTED;
        }
@@ -2167,10 +2164,8 @@ public class PreferencesHelper implements RankingConfig {
     * the user.
     */
    @VisibleForTesting
    boolean isFsiPermissionUserSet(String pkg, int uid, int fsiState, int currentPermissionFlags,
                                   boolean isStickyHunFlagEnabled) {
        if (!isStickyHunFlagEnabled
                || fsiState == PACKAGE_NOTIFICATION_PREFERENCES__FSI_STATE__NOT_REQUESTED) {
    boolean isFsiPermissionUserSet(String pkg, int uid, int fsiState, int currentPermissionFlags) {
        if (fsiState == PACKAGE_NOTIFICATION_PREFERENCES__FSI_STATE__NOT_REQUESTED) {
            return false;
        }
        return (currentPermissionFlags & PackageManager.FLAG_PERMISSION_USER_SET) != 0;
@@ -2213,22 +2208,18 @@ public class PreferencesHelper implements RankingConfig {
                    pkgsWithPermissionsToHandle.remove(key);
                }

                final boolean isStickyHunFlagEnabled = SystemUiSystemPropertiesFlags.getResolver()
                        .isEnabled(NotificationFlags.SHOW_STICKY_HUN_FOR_DENIED_FSI);

                final boolean requestedFSIPermission = mPermissionHelper.hasRequestedPermission(
                        android.Manifest.permission.USE_FULL_SCREEN_INTENT, r.pkg, r.uid);

                final int fsiState = getFsiState(r.pkg, r.uid, requestedFSIPermission,
                        isStickyHunFlagEnabled);
                final int fsiState = getFsiState(r.pkg, r.uid, requestedFSIPermission);

                final int currentPermissionFlags = mPm.getPermissionFlags(
                        android.Manifest.permission.USE_FULL_SCREEN_INTENT, r.pkg,
                        UserHandle.getUserHandleForUid(r.uid));

                final boolean fsiIsUserSet =
                        isFsiPermissionUserSet(r.pkg, r.uid, fsiState, currentPermissionFlags,
                                isStickyHunFlagEnabled);
                        isFsiPermissionUserSet(r.pkg, r.uid, fsiState,
                                currentPermissionFlags);

                events.add(FrameworkStatsLog.buildStatsEvent(
                        PACKAGE_NOTIFICATION_PREFERENCES,
+5 −43
Original line number Diff line number Diff line
@@ -87,8 +87,6 @@ import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.Display.INVALID_DISPLAY;
import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
import static com.android.internal.config.sysui.SystemUiSystemPropertiesFlags.NotificationFlags.FSI_FORCE_DEMOTE;
import static com.android.internal.config.sysui.SystemUiSystemPropertiesFlags.NotificationFlags.SHOW_STICKY_HUN_FOR_DENIED_FSI;
import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN;
import static com.android.server.am.PendingIntentRecord.FLAG_ACTIVITY_SENDER;
import static com.android.server.am.PendingIntentRecord.FLAG_BROADCAST_SENDER;
@@ -739,9 +737,6 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        clearInvocations(mRankingHandler);
        when(mPermissionHelper.hasPermission(mUid)).thenReturn(true);
        mTestFlagResolver.setFlagOverride(FSI_FORCE_DEMOTE, false);
        mTestFlagResolver.setFlagOverride(SHOW_STICKY_HUN_FOR_DENIED_FSI, false);
        var checker = mock(TestableNotificationManagerService.ComponentPermissionChecker.class);
        mService.permissionChecker = checker;
        when(checker.check(anyString(), anyInt(), anyInt(), anyBoolean()))
@@ -11472,14 +11467,12 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        verify(mMockNm, never()).notify(anyString(), anyInt(), any(Notification.class));
    }
    private void verifyStickyHun(Flag flag, int permissionState, boolean appRequested,
    private void verifyStickyHun(int permissionState, boolean appRequested,
            boolean isSticky) throws Exception {
        when(mPermissionHelper.hasRequestedPermission(Manifest.permission.USE_FULL_SCREEN_INTENT,
                PKG, mUserId)).thenReturn(appRequested);
        mTestFlagResolver.setFlagOverride(flag, true);
        when(mPermissionManager.checkPermissionForDataDelivery(
                eq(Manifest.permission.USE_FULL_SCREEN_INTENT), any(), any()))
                .thenReturn(permissionState);
@@ -11503,8 +11496,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
    public void testFixNotification_flagEnableStickyHun_fsiPermissionHardDenied_showStickyHun()
            throws Exception {
        verifyStickyHun(/* flag= */ SHOW_STICKY_HUN_FOR_DENIED_FSI,
                /* permissionState= */ PermissionManager.PERMISSION_HARD_DENIED, true,
        verifyStickyHun(/* permissionState= */ PermissionManager.PERMISSION_HARD_DENIED, true,
                /* isSticky= */ true);
    }
@@ -11512,16 +11504,14 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
    public void testFixNotification_flagEnableStickyHun_fsiPermissionSoftDenied_showStickyHun()
            throws Exception {
        verifyStickyHun(/* flag= */ SHOW_STICKY_HUN_FOR_DENIED_FSI,
                /* permissionState= */ PermissionManager.PERMISSION_SOFT_DENIED, true,
        verifyStickyHun(/* permissionState= */ PermissionManager.PERMISSION_SOFT_DENIED, true,
                /* isSticky= */ true);
    }
    @Test
    public void testFixNotification_fsiPermissionSoftDenied_appNotRequest_noShowStickyHun()
            throws Exception {
        verifyStickyHun(/* flag= */ SHOW_STICKY_HUN_FOR_DENIED_FSI,
                /* permissionState= */ PermissionManager.PERMISSION_SOFT_DENIED, false,
        verifyStickyHun(/* permissionState= */ PermissionManager.PERMISSION_SOFT_DENIED, false,
                /* isSticky= */ false);
    }
@@ -11530,38 +11520,10 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
    public void testFixNotification_flagEnableStickyHun_fsiPermissionGranted_showFsi()
            throws Exception {
        verifyStickyHun(/* flag= */ SHOW_STICKY_HUN_FOR_DENIED_FSI,
                /* permissionState= */ PermissionManager.PERMISSION_GRANTED, true,
        verifyStickyHun(/* permissionState= */ PermissionManager.PERMISSION_GRANTED, true,
                /* isSticky= */ false);
    }
    @Test
    public void testFixNotification_flagForceStickyHun_fsiPermissionHardDenied_showStickyHun()
            throws Exception {
        verifyStickyHun(/* flag= */ FSI_FORCE_DEMOTE,
                /* permissionState= */ PermissionManager.PERMISSION_HARD_DENIED, true,
                /* isSticky= */ true);
    }
    @Test
    public void testFixNotification_flagForceStickyHun_fsiPermissionSoftDenied_showStickyHun()
            throws Exception {
        verifyStickyHun(/* flag= */ FSI_FORCE_DEMOTE,
                /* permissionState= */ PermissionManager.PERMISSION_SOFT_DENIED, true,
                /* isSticky= */ true);
    }
    @Test
    public void testFixNotification_flagForceStickyHun_fsiPermissionGranted_showStickyHun()
            throws Exception {
        verifyStickyHun(/* flag= */ FSI_FORCE_DEMOTE,
                /* permissionState= */ PermissionManager.PERMISSION_GRANTED, true,
                /* isSticky= */ true);
    }
    @Test
    public void fixNotification_withFgsFlag_butIsNotFgs() throws Exception {
        final ApplicationInfo applicationInfo = new ApplicationInfo();
Loading