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

Commit 3b4a93a3 authored by Nadia Benbernou's avatar Nadia Benbernou
Browse files

Style changes to blocking helper for Q.

Bug:123900539
Test: Manual testing on device and unit tests.

Change-Id: I56951b65139b3bc3ba0118972ba2b1dc09cdeba7
parent 1c0c977c
Loading
Loading
Loading
Loading
+75 −44
Original line number Diff line number Diff line
@@ -71,18 +71,38 @@
            android:maxLines="1"
            android:layout_centerVertical="true"
            android:layout_toEndOf="@id/pkg_divider" />
        <LinearLayout
            android:id="@+id/info_and_settings"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_alignParentEnd="true"
            android:paddingHorizontal="16dp"
            android:orientation="horizontal">
            <!-- Optional link to app. Only appears if the channel is not disabled and the app
asked for it -->
            <ImageButton
                android:id="@+id/app_settings"
                android:layout_width="40dp"
                android:layout_height="56dp"
                android:layout_centerVertical="true"
                android:paddingRight="16dp"
                android:visibility="gone"
                android:background="@drawable/ripple_drawable"
                android:contentDescription="@string/notification_app_settings"
                android:src="@drawable/ic_settings"
                android:tint="?android:attr/colorAccent" />
            <!-- 24 dp icon with 16 dp padding all around to mirror notification content margins -->
            <ImageButton
                android:id="@+id/info"
            android:layout_width="56dp"
                android:layout_width="24dp"
                android:layout_height="56dp"
            android:layout_alignParentEnd="true"
                android:layout_centerVertical="true"
                android:background="@drawable/ripple_drawable"
                android:contentDescription="@string/notification_more_settings"
            android:padding="16dp"
                android:src="@drawable/ic_info"
                android:tint="?android:attr/colorAccent" />
        </LinearLayout>
    </RelativeLayout>

    <LinearLayout
@@ -143,50 +163,61 @@
        </LinearLayout>

        <!-- Settings and Done buttons -->
        <LinearLayout
        <RelativeLayout
            android:id="@+id/block_or_minimize"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/notification_guts_button_spacing"
            android:layout_marginStart="@dimen/notification_guts_button_side_margin"
            android:layout_marginEnd="@dimen/notification_guts_button_side_margin"
            android:gravity="end"
            android:orientation="horizontal">

            <!-- Optional link to app. Only appears if the channel is not disabled and the app
            asked for it -->
            android:clipChildren="false"
            android:clipToPadding="false">
            <TextView
                android:id="@+id/app_settings"
                android:text="@string/notification_app_settings"
                android:id="@+id/done"
                android:text="@string/inline_done_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:visibility="gone"
                android:ellipsize="end"
                android:maxLines="1"
                android:layout_centerVertical="true"
                style="@style/TextAppearance.NotificationInfo.Button"/>

            <LinearLayout
                android:id="@+id/block_buttons"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_alignParentEnd="true"
                android:orientation="horizontal">
                <TextView
                android:id="@+id/block"
                android:text="@string/inline_stop_button"
                    android:id="@+id/deliver_silently"
                    android:text="@string/inline_deliver_silently_button"
                    android:layout_width="wrap_content"
                android:layout_height="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_marginStart="@dimen/notification_guts_button_horizontal_spacing"
                    android:paddingRight="24dp"
                    style="@style/TextAppearance.NotificationInfo.Button"/>
                <TextView
                android:id="@+id/minimize"
                android:text="@string/inline_minimize_button"
                    android:id="@+id/block"
                    android:text="@string/inline_block_button"
                    android:minWidth="48dp"
                    android:layout_width="wrap_content"
                android:layout_height="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_marginStart="@dimen/notification_guts_button_horizontal_spacing"
                    style="@style/TextAppearance.NotificationInfo.Button"/>
                <TextView
                android:id="@+id/keep"
                    android:id="@+id/minimize"
                    android:text="@string/inline_minimize_button"
                    android:minWidth="48dp"
                android:text="@string/inline_keep_button"
                    android:layout_width="wrap_content"
                android:layout_height="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_marginStart="@dimen/notification_guts_button_horizontal_spacing"
                    style="@style/TextAppearance.NotificationInfo.Button"/>
            </LinearLayout>


        </RelativeLayout>
        <LinearLayout
            android:id="@+id/interruptiveness_settings"
            android:layout_width="match_parent"
+6 −0
Original line number Diff line number Diff line
@@ -1573,12 +1573,18 @@
    <string name="inline_blocking_helper">You usually dismiss these notifications.
    \nKeep showing them?</string>

    <!-- Notification Inline controls: button to dismiss the blocking helper [CHAR_LIMIT=25] -->
    <string name="inline_done_button">Done</string>

    <!-- Notification Inline controls: continue receiving notifications prompt, channel level -->
    <string name="inline_keep_showing">Keep showing these notifications?</string>

    <!-- Notification inline controls: block notifications button -->
    <string name="inline_stop_button">Stop notifications</string>

    <!-- Notification inline controls: button to deliver notifications silently from this channel [CHAR_LIMIT=35] -->
    <string name="inline_deliver_silently_button">Deliver Silently</string>

    <!-- Notification inline controls: button to block notifications from this channel [CHAR_LIMIT=35] -->
    <string name="inline_block_button">Block</string>

+3 −0
Original line number Diff line number Diff line
@@ -30,6 +30,9 @@ public class NotificationCounters {
    /** Counter tag for when the user hits 'stop notifications' in the blocking helper. */
    public static final String BLOCKING_HELPER_STOP_NOTIFICATIONS =
            "blocking_helper_stop_notifications";
    /** Counter tag for when the user hits 'deliver silently' in the blocking helper. */
    public static final String BLOCKING_HELPER_DELIVER_SILENTLY =
            "blocking_helper_deliver_silently";
    /** Counter tag for when the user hits 'show silently' in the blocking helper. */
    public static final String BLOCKING_HELPER_TOGGLE_SILENT =
            "blocking_helper_toggle_silent";
+27 −24
Original line number Diff line number Diff line
@@ -84,6 +84,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
    public static final int ACTION_UNDO = 1;
    public static final int ACTION_TOGGLE_SILENT = 2;
    public static final int ACTION_BLOCK = 3;
    public static final int ACTION_DELIVER_SILENTLY = 4;

    private INotificationManager mINotificationManager;
    private PackageManager mPm;
@@ -135,30 +136,26 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
    };

    private OnClickListener mOnToggleSilent = v -> {
        Runnable saveImportance = () -> {
            swapContent(ACTION_TOGGLE_SILENT, true /* animate */);
            if (mIsForBlockingHelper) {
                mMetricsLogger.write(getLogMaker()
                        .setCategory(MetricsEvent.NOTIFICATION_BLOCKING_HELPER)
                        .setType(MetricsEvent.TYPE_ACTION)
                        .setSubtype(MetricsEvent.BLOCKING_HELPER_CLICK_ALERT_ME));
            }
        handleSaveImportance(ACTION_TOGGLE_SILENT, MetricsEvent.BLOCKING_HELPER_CLICK_ALERT_ME);
    };
        if (mCheckSaveListener != null) {
            mCheckSaveListener.checkSave(saveImportance, mSbn);
        } else {
            saveImportance.run();
        }

    private OnClickListener mOnDeliverSilently = v -> {
        handleSaveImportance(
                ACTION_DELIVER_SILENTLY, MetricsEvent.BLOCKING_HELPER_CLICK_STAY_SILENT);
    };

    private OnClickListener mOnStopOrMinimizeNotifications = v -> {
        handleSaveImportance(ACTION_BLOCK, MetricsEvent.BLOCKING_HELPER_CLICK_BLOCKED);
    };

    private void handleSaveImportance(int action, int metricsSubtype) {
        Runnable saveImportance = () -> {
            swapContent(ACTION_BLOCK, true /* animate */);
            swapContent(action, true /* animate */);
            if (mIsForBlockingHelper) {
                mMetricsLogger.write(getLogMaker()
                        .setCategory(MetricsEvent.NOTIFICATION_BLOCKING_HELPER)
                        .setType(MetricsEvent.TYPE_ACTION)
                        .setSubtype(MetricsEvent.BLOCKING_HELPER_CLICK_BLOCKED));
                        .setSubtype(metricsSubtype));
            }
        };
        if (mCheckSaveListener != null) {
@@ -166,7 +163,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
        } else {
            saveImportance.run();
        }
    };
    }

    private OnClickListener mOnUndo = v -> {
        // Reset exit counter that we'll log and record an undo event separately (not an exit event)
@@ -283,8 +280,6 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
        mMetricsLogger.write(notificationControlsLogMaker());
    }



    private void bindHeader() throws RemoteException {
        // Package name
        Drawable pkgicon = null;
@@ -479,17 +474,21 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
            findViewById(R.id.block_or_minimize).setVisibility(VISIBLE);
            findViewById(R.id.interruptiveness_settings).setVisibility(GONE);
            View block = findViewById(R.id.block);
            TextView keep = findViewById(R.id.keep);
            TextView done = findViewById(R.id.done);
            View minimize = findViewById(R.id.minimize);
            View deliverSilently = findViewById(R.id.deliver_silently);


            block.setOnClickListener(mOnStopOrMinimizeNotifications);
            keep.setOnClickListener(mOnKeepShowing);
            done.setOnClickListener(mOnKeepShowing);
            minimize.setOnClickListener(mOnStopOrMinimizeNotifications);
            deliverSilently.setOnClickListener(mOnDeliverSilently);

            if (mIsNonblockable) {
                keep.setText(android.R.string.ok);
                done.setText(android.R.string.ok);
                block.setVisibility(GONE);
                minimize.setVisibility(GONE);
                deliverSilently.setVisibility(GONE);
            } else if (mIsForeground) {
                block.setVisibility(GONE);
                minimize.setVisibility(VISIBLE);
@@ -499,7 +498,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
            }

            // Set up app settings link (i.e. Customize)
            TextView settingsLinkView = findViewById(R.id.app_settings);
            View settingsLinkView = findViewById(R.id.app_settings);
            Intent settingsIntent = getAppSettingsIntent(mPm, mPackageName,
                    mSingleNotificationChannel,
                    mSbn.getId(), mSbn.getTag());
@@ -507,7 +506,6 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
                    && settingsIntent != null
                    && !TextUtils.isEmpty(mSbn.getNotification().getSettingsText())) {
                settingsLinkView.setVisibility(VISIBLE);
                settingsLinkView.setText(mContext.getString(R.string.notification_app_settings));
                settingsLinkView.setOnClickListener((View view) -> {
                    mAppSettingsClickListener.onClick(view, settingsIntent);
                });
@@ -531,6 +529,11 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
            case ACTION_UNDO:
                mChosenImportance = mStartingChannelImportance;
                break;
            case ACTION_DELIVER_SILENTLY:
                mExitReason = NotificationCounters.BLOCKING_HELPER_DELIVER_SILENTLY;
                mChosenImportance = IMPORTANCE_LOW;
                confirmationText.setText(R.string.notification_channel_silenced);
                break;
            case ACTION_TOGGLE_SILENT:
                mExitReason = NotificationCounters.BLOCKING_HELPER_TOGGLE_SILENT;
                if (mWasShownHighPriority) {
+37 −2
Original line number Diff line number Diff line
@@ -738,7 +738,7 @@ public class NotificationInfoTest extends SysuiTestCase {
        guts.setGutsContent(mNotificationInfo);
        mNotificationInfo.setGutsParent(guts);

        mNotificationInfo.findViewById(R.id.keep).performClick();
        mNotificationInfo.findViewById(R.id.done).performClick();

        verify(mBlockingHelperManager).dismissCurrentBlockingHelper();
        mTestableLooper.processAllMessages();
@@ -766,7 +766,7 @@ public class NotificationInfoTest extends SysuiTestCase {
        guts.setGutsContent(mNotificationInfo);
        mNotificationInfo.setGutsParent(guts);

        mNotificationInfo.findViewById(R.id.keep).performClick();
        mNotificationInfo.findViewById(R.id.done).performClick();

        verify(mBlockingHelperManager).dismissCurrentBlockingHelper();
        mTestableLooper.processAllMessages();
@@ -961,6 +961,41 @@ public class NotificationInfoTest extends SysuiTestCase {
        assertEquals(IMPORTANCE_MIN, updated.getValue().getImportance());
    }

    @Test
    public void testSilentlyChangedCallsUpdateNotificationChannel_blockingHelper()
            throws Exception {
        mNotificationChannel.setImportance(IMPORTANCE_LOW);
        mNotificationInfo.bindNotification(
                mMockPackageManager,
                mMockINotificationManager,
                TEST_PACKAGE_NAME,
                mNotificationChannel,
                1 /* numChannels */,
                mSbn,
                null /* checkSaveListener */,
                null /* onSettingsClick */,
                null /* onAppSettingsClick */,
                true /*provisioned */,
                false /* isNonblockable */,
                true /* isForBlockingHelper */,
                true /* isUserSentimentNegative */,
                IMPORTANCE_DEFAULT,
                false);

        mNotificationInfo.findViewById(R.id.deliver_silently).performClick();
        waitForUndoButton();
        mNotificationInfo.handleCloseControls(true, false);

        mTestableLooper.processAllMessages();
        ArgumentCaptor<NotificationChannel> updated =
                ArgumentCaptor.forClass(NotificationChannel.class);
        verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
                anyString(), eq(TEST_UID), updated.capture());
        assertTrue((updated.getValue().getUserLockedFields()
                & USER_LOCKED_IMPORTANCE) != 0);
        assertEquals(IMPORTANCE_LOW, updated.getValue().getImportance());
    }

    @Test
    public void testKeepUpdatesNotificationChannel() throws Exception {
        mNotificationChannel.setImportance(IMPORTANCE_LOW);