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

Commit f58cef41 authored by Alex Mang's avatar Alex Mang
Browse files

Adding automatic option in long press menu

Automatic will be the default selected mode unless the user has
overridden the channel with their preferred alert setting

Test: manually on device
Change-Id: Ia3202725699dcfc3f6bfeb94a91b48025a96c7e9
parent 8c0ef2dc
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
<!--
Copyright (C) 2020 The Android Open Source Project

   Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportWidth="24"
    android:viewportHeight="24">
    <path
        android:fillColor="@android:color/white"
        android:pathData="M15.6 0L4 13.88h8.75L10.04 24L21 10.35h-8.25z" />
</vector>
 No newline at end of file
+52 −1
Original line number Diff line number Diff line
@@ -149,6 +149,58 @@ asked for it -->
            android:layout_height="wrap_content"
            android:gravity="center"
            android:orientation="vertical">
            <com.android.systemui.statusbar.notification.row.ButtonLinearLayout
                android:id="@+id/automatic"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="@dimen/notification_importance_button_separation"
                android:padding="@dimen/notification_importance_button_padding"
                android:clickable="true"
                android:focusable="true"
                android:background="@drawable/notification_guts_priority_button_bg"
                android:orientation="vertical"
                android:visibility="gone">
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:gravity="center"
                >
                    <ImageView
                        android:id="@+id/automatic_icon"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@drawable/ic_notifications_automatic"
                        android:background="@android:color/transparent"
                        android:tint="@color/notification_guts_priority_contents"
                        android:clickable="false"
                        android:focusable="false"/>
                    <TextView
                        android:id="@+id/automatic_label"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="@dimen/notification_importance_drawable_padding"
                        android:layout_weight="1"
                        android:ellipsize="end"
                        android:maxLines="1"
                        android:clickable="false"
                        android:focusable="false"
                        android:textAppearance="@style/TextAppearance.NotificationImportanceButton"
                        android:text="@string/notification_automatic_title"/>
                </LinearLayout>
                <TextView
                    android:id="@+id/automatic_summary"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="@dimen/notification_importance_button_description_top_margin"
                    android:visibility="gone"
                    android:text="@string/notification_channel_summary_automatic"
                    android:clickable="false"
                    android:focusable="false"
                    android:ellipsize="end"
                    android:maxLines="2"
                    android:textAppearance="@style/TextAppearance.NotificationImportanceDetail"/>
            </com.android.systemui.statusbar.notification.row.ButtonLinearLayout>

            <com.android.systemui.statusbar.notification.row.ButtonLinearLayout
                android:id="@+id/alert"
@@ -287,6 +339,5 @@ asked for it -->
                android:maxWidth="125dp"
                style="@style/TextAppearance.NotificationInfo.Button"/>
        </RelativeLayout>

    </LinearLayout>
</com.android.systemui.statusbar.notification.row.NotificationInfo>
+6 −0
Original line number Diff line number Diff line
@@ -1838,6 +1838,9 @@
    <!-- [CHAR LIMIT=100] Notification Importance title -->
    <string name="notification_bubble_title">Bubble</string>

    <!-- [CHAR LIMIT=100] Notification Importance title -->
    <string name="notification_automatic_title">Automatic</string>

    <!-- [CHAR LIMIT=150] Notification Importance title: low importance level summary -->
    <string name="notification_channel_summary_low">No sound or vibration</string>

@@ -1853,6 +1856,9 @@
    <!-- [CHAR LIMIT=150] Notification Importance title: bubble level summary -->
    <string name="notification_channel_summary_bubble">Keeps your attention with a floating shortcut to this content.</string>

    <!-- [CHAR LIMIT=150] Notification Importance title: automatic importance level summary -->
    <string name="notification_channel_summary_automatic">Have the system determine if this notification should make sound or vibration</string>

    <!-- [CHAR LIMIT=150] Notification Importance title: important conversation level summary -->
    <string name="notification_channel_summary_priority">Shows at top of conversation section, appears as floating bubble, displays profile picture on lock screen</string>

+2 −1
Original line number Diff line number Diff line
@@ -390,7 +390,8 @@ public class NotificationGutsManager implements Dumpable, NotificationLifetimeEx
                onAppSettingsClick,
                mDeviceProvisionedController.isDeviceProvisioned(),
                row.getIsNonblockable(),
                mHighPriorityProvider.isHighPriority(row.getEntry()));
                mHighPriorityProvider.isHighPriority(row.getEntry()),
                NotificationViewHierarchyManager.showFeedback(row.getEntry()));
    }

    /**
+60 −10
Original line number Diff line number Diff line
@@ -89,6 +89,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G

    private TextView mPriorityDescriptionView;
    private TextView mSilentDescriptionView;
    private TextView mAutomaticDescriptionView;

    private INotificationManager mINotificationManager;
    private PackageManager mPm;
@@ -107,12 +108,14 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
    private boolean mWasShownHighPriority;
    private boolean mPressedApply;
    private boolean mPresentingChannelEditorDialog = false;
    private boolean mShowAutomaticSetting;

    /**
     * The last importance level chosen by the user.  Null if the user has not chosen an importance
     * level; non-null once the user takes an action which indicates an explicit preference.
     */
    @Nullable private Integer mChosenImportance;
    private boolean mIsAutomaticChosen;
    private boolean mIsSingleDefaultChannel;
    private boolean mIsNonblockable;
    private StatusBarNotification mSbn;
@@ -126,15 +129,23 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
    @VisibleForTesting
    boolean mSkipPost = false;

    // used by standard ui
    private OnClickListener mOnAutomatic = v -> {
        mIsAutomaticChosen = true;
        applyAlertingBehavior(BEHAVIOR_AUTOMATIC, true /* userTriggered */);
    };

    // used by standard ui
    private OnClickListener mOnAlert = v -> {
        mChosenImportance = IMPORTANCE_DEFAULT;
        mIsAutomaticChosen = false;
        applyAlertingBehavior(BEHAVIOR_ALERTING, true /* userTriggered */);
    };

    // used by standard ui
    private OnClickListener mOnSilent = v -> {
        mChosenImportance = IMPORTANCE_LOW;
        mIsAutomaticChosen = false;
        applyAlertingBehavior(BEHAVIOR_SILENT, true /* userTriggered */);
    };

@@ -154,6 +165,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G

        mPriorityDescriptionView = findViewById(R.id.alert_summary);
        mSilentDescriptionView = findViewById(R.id.silence_summary);
        mAutomaticDescriptionView = findViewById(R.id.automatic_summary);
    }

    // Specify a CheckSaveListener to override when/if the user's changes are committed.
@@ -184,7 +196,8 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
            OnAppSettingsClickListener onAppSettingsClick,
            boolean isDeviceProvisioned,
            boolean isNonblockable,
            boolean wasShownHighPriority)
            boolean wasShownHighPriority,
            boolean showAutomaticSetting)
            throws RemoteException {
        mINotificationManager = iNotificationManager;
        mMetricsLogger = Dependency.get(MetricsLogger.class);
@@ -205,6 +218,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
        mAppUid = mSbn.getUid();
        mDelegatePkg = mSbn.getOpPkg();
        mIsDeviceProvisioned = isDeviceProvisioned;
        mShowAutomaticSetting = showAutomaticSetting;

        int numTotalChannels = mINotificationManager.getNumNotificationChannelsForPackage(
                pkg, mAppUid, false /* includeDeleted */);
@@ -257,9 +271,15 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
        silent.setOnClickListener(mOnSilent);
        alert.setOnClickListener(mOnAlert);

        int behavior = mWasShownHighPriority
                        ? BEHAVIOR_ALERTING
                        : BEHAVIOR_SILENT;
        View automatic = findViewById(R.id.automatic);
        if (mShowAutomaticSetting) {
            automatic.setVisibility(VISIBLE);
            automatic.setOnClickListener(mOnAutomatic);
        } else {
            automatic.setVisibility(GONE);
        }

        int behavior = getAlertingBehavior();
        applyAlertingBehavior(behavior, false /* userTriggered */);
    }

@@ -411,7 +431,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
            bgHandler.post(
                    new UpdateImportanceRunnable(mINotificationManager, mPackageName, mAppUid,
                            mNumUniqueChannelsInRow == 1 ? mSingleNotificationChannel : null,
                            mStartingChannelImportance, newImportance));
                            mStartingChannelImportance, newImportance, mIsAutomaticChosen));
            mVisualStabilityManager.temporarilyAllowReordering();
        }
    }
@@ -444,23 +464,39 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G

        View alert = findViewById(R.id.alert);
        View silence = findViewById(R.id.silence);
        View automatic = findViewById(R.id.automatic);

        switch (behavior) {
            case BEHAVIOR_ALERTING:
                mPriorityDescriptionView.setVisibility(VISIBLE);
                mSilentDescriptionView.setVisibility(GONE);
                mAutomaticDescriptionView.setVisibility(GONE);
                post(() -> {
                    alert.setSelected(true);
                    silence.setSelected(false);
                    automatic.setSelected(false);
                });
                break;

            case BEHAVIOR_SILENT:
                mSilentDescriptionView.setVisibility(VISIBLE);
                mPriorityDescriptionView.setVisibility(GONE);
                mAutomaticDescriptionView.setVisibility(GONE);
                post(() -> {
                    alert.setSelected(false);
                    silence.setSelected(true);
                    automatic.setSelected(false);
                });
                break;

            case BEHAVIOR_AUTOMATIC:
                mAutomaticDescriptionView.setVisibility(VISIBLE);
                mPriorityDescriptionView.setVisibility(GONE);
                mSilentDescriptionView.setVisibility(GONE);
                post(() -> {
                    automatic.setSelected(true);
                    alert.setSelected(false);
                    silence.setSelected(false);
                });
                break;

@@ -468,7 +504,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
                throw new IllegalArgumentException("Unrecognized alerting behavior: " + behavior);
        }

        boolean isAChange = mWasShownHighPriority != (behavior == BEHAVIOR_ALERTING);
        boolean isAChange = getAlertingBehavior() != behavior;
        TextView done = findViewById(R.id.done);
        done.setText(isAChange
                ? R.string.inline_ok_button
@@ -594,25 +630,31 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
        private final @Nullable NotificationChannel mChannelToUpdate;
        private final int mCurrentImportance;
        private final int mNewImportance;
        private final boolean mUnlockImportance;


        public UpdateImportanceRunnable(INotificationManager notificationManager,
                String packageName, int appUid, @Nullable NotificationChannel channelToUpdate,
                int currentImportance, int newImportance) {
                int currentImportance, int newImportance, boolean unlockImportance) {
            mINotificationManager = notificationManager;
            mPackageName = packageName;
            mAppUid = appUid;
            mChannelToUpdate = channelToUpdate;
            mCurrentImportance = currentImportance;
            mNewImportance = newImportance;
            mUnlockImportance = unlockImportance;
        }

        @Override
        public void run() {
            try {
                if (mChannelToUpdate != null) {
                    if (mUnlockImportance) {
                        mChannelToUpdate.unlockFields(NotificationChannel.USER_LOCKED_IMPORTANCE);
                    } else {
                        mChannelToUpdate.setImportance(mNewImportance);
                        mChannelToUpdate.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE);
                    }
                    mINotificationManager.updateNotificationChannelForPackage(
                            mPackageName, mAppUid, mChannelToUpdate);
                } else {
@@ -662,9 +704,17 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
                .setSubtype(MetricsEvent.BLOCKING_HELPER_UNKNOWN);
    }

    private @AlertingBehavior int getAlertingBehavior() {
        if (mShowAutomaticSetting && !mSingleNotificationChannel.hasUserSetImportance()) {
            return BEHAVIOR_AUTOMATIC;
        }
        return mWasShownHighPriority ? BEHAVIOR_ALERTING : BEHAVIOR_SILENT;
    }

    @Retention(SOURCE)
    @IntDef({BEHAVIOR_ALERTING, BEHAVIOR_SILENT})
    @IntDef({BEHAVIOR_ALERTING, BEHAVIOR_SILENT, BEHAVIOR_AUTOMATIC})
    private @interface AlertingBehavior {}
    private static final int BEHAVIOR_ALERTING = 0;
    private static final int BEHAVIOR_SILENT = 1;
    private static final int BEHAVIOR_AUTOMATIC = 2;
}
Loading