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

Commit 929c97e6 authored by Julia Reynolds's avatar Julia Reynolds Committed by Android (Google) Code Review
Browse files

Merge "Delete Notification Topics." into nyc-dev

parents 69c5f2a1 ed5c50a9
Loading
Loading
Loading
Loading
+1 −9
Original line number Diff line number Diff line
@@ -5926,12 +5926,6 @@
    <!-- Notification Settings: Title for the option managing notifications per application. [CHAR LIMIT=30] -->
    <string name="app_notifications_title">Notifications</string>
    <!-- Sound & notification > Notification section: Title for the option managing notifications per topic. [CHAR LIMIT=30] -->
    <string name="topic_notifications_title">Topic notifications</string>
    <!-- [CHAR LIMIT=100] Notification topic list header -->
    <string name="notification_topic_categories">Categories</string>
    <!-- [CHAR LIMIT=100] Notification importance slider title -->
    <string name="notification_importance_title">Importance</string>
@@ -6407,9 +6401,7 @@
   <!-- App notification summary with notifications enabled [CHAR LIMIT=40] -->
   <string name="notifications_enabled">Normal</string>
   <!-- App notification summary with notifications disabled [CHAR LIMIT=40] -->
   <string name="notifications_disabled">Fully Blocked</string>
   <!-- App notification summary with notifications disabled [CHAR LIMIT=40] -->
   <string name="notifications_partially_disabled">Partially Blocked</string>
   <string name="notifications_disabled">Blocked</string>
   <!-- App notification summary with 2 items [CHAR LIMIT=15] -->
   <string name="notifications_two_items"><xliff:g id="notif_state" example="Priority">%1$s</xliff:g> / <xliff:g id="notif_state" example="Priority">%2$s</xliff:g></string>
   <!-- App notification summary with 3 items [CHAR LIMIT=15] -->
+0 −14
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@
        android:title="@string/app_notifications_title"
        android:key="app_notification_settings">

    <!-- Apps without topics -->
    <!-- Importance -->
    <com.android.settingslib.RestrictedPreference
            android:key="importance_title"
@@ -47,17 +46,4 @@
            android:summary="@string/app_notification_override_dnd_summary"
            android:order="6" />

    <!-- Apps with topics -->
    <!-- Block -->
    <com.android.settingslib.RestrictedSwitchPreference
            android:key="block"
            android:title="@string/app_notification_block_title"
            android:summary="@string/app_notification_block_summary"
            android:order="7" />

    <PreferenceCategory
            android:key="categories"
            android:title="@string/notification_topic_categories"
            android:order="8" />

</PreferenceScreen>
+1 −1
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ public class AppStateNotificationBridge extends AppStateBaseBridge {
                return false;
            }
            AppRow row = (AppRow) info.extraInfo;
            return row.banned || row.bannedTopics;
            return row.banned;
        }
    };
}
+0 −2
Original line number Diff line number Diff line
@@ -842,8 +842,6 @@ public class InstalledAppDetails extends AppInfoBase
    public static CharSequence getNotificationSummary(AppRow appRow, Context context) {
        if (appRow.banned) {
            return context.getString(R.string.notifications_disabled);
        } else if (appRow.bannedTopics) {
            return context.getString(R.string.notifications_partially_disabled);
        }
        return context.getString(R.string.notifications_enabled);
    }
+34 −71
Original line number Diff line number Diff line
@@ -17,11 +17,14 @@
package com.android.settings.notification;

import android.app.Notification;
import android.app.NotificationManager;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.os.UserHandle;
import android.provider.Settings;
import android.service.notification.NotificationListenerService.Ranking;
import android.support.v7.preference.Preference;
import android.support.v7.preference.Preference.OnPreferenceChangeListener;
@@ -32,6 +35,7 @@ import android.util.Log;

import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.MetricsProto.MetricsEvent;
import com.android.internal.widget.LockPatternUtils;
import com.android.settings.AppHeader;
import com.android.settings.R;
import com.android.settings.Utils;
@@ -50,16 +54,12 @@ public class AppNotificationSettings extends NotificationSettingsBase {
    private static final String TAG = "AppNotificationSettings";
    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);

    private static final String KEY_BLOCK = "block";
    private static final String KEY_CATEGORIES = "categories";

    private static final Intent APP_NOTIFICATION_PREFS_CATEGORY_INTENT
            = new Intent(Intent.ACTION_MAIN)
                .addCategory(Notification.INTENT_CATEGORY_NOTIFICATION_PREFERENCES);

    private RestrictedSwitchPreference mBlock;
    private PreferenceCategory mCategories;
    private AppRow mAppRow;
    private boolean mDndVisualEffectsSuppressed;

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
@@ -79,8 +79,6 @@ public class AppNotificationSettings extends NotificationSettingsBase {
        super.onCreate(savedInstanceState);

        addPreferencesFromResource(R.xml.app_notification_settings);
        mCategories = (PreferenceCategory) findPreference(KEY_CATEGORIES);
        mBlock = (RestrictedSwitchPreference) findPreference(KEY_BLOCK);
        mImportance = (ImportanceSeekBarPreference) findPreference(KEY_IMPORTANCE);
        mImportanceReset = (LayoutPreference) findPreference(KEY_IMPORTANCE_RESET);
        mImportanceTitle = (RestrictedPreference) findPreference(KEY_IMPORTANCE_TITLE);
@@ -91,84 +89,49 @@ public class AppNotificationSettings extends NotificationSettingsBase {

        mAppRow = mBackend.loadAppRow(mPm, mPkgInfo);

        NotificationManager.Policy policy =
                NotificationManager.from(mContext).getNotificationPolicy();
        mDndVisualEffectsSuppressed = policy == null ? false : policy.suppressedVisualEffects != 0;

        // load settings intent
        ArrayMap<String, AppRow> rows = new ArrayMap<String, AppRow>();
        rows.put(mAppRow.pkg, mAppRow);
        collectConfigActivities(rows);

        // Add topics
        List<Notification.Topic> topics = mBackend.getTopics(mPkg, mUid);
        if (topics.size() <= 1) {
            removeAppPrefs();
        setupImportancePrefs(mAppRow.systemApp, mAppRow.appImportance);
        setupPriorityPref(mAppRow.appBypassDnd);
        setupSensitivePref(mAppRow.appSensitive);
        } else {
            removeTopicPrefs();
            setupBlockSwitch();
            for (Notification.Topic topic : topics) {
                RestrictedPreference topicPreference = new RestrictedPreference(getPrefContext());
                topicPreference.setDisabledByAdmin(mSuspendedAppsAdmin);
                topicPreference.setKey(topic.getId());
                topicPreference.setTitle(topic.getLabel());
                // Create intent for this preference.
                Bundle topicArgs = new Bundle();
                topicArgs.putInt(AppInfoBase.ARG_PACKAGE_UID, mUid);
                topicArgs.putParcelable(TopicNotificationSettings.ARG_TOPIC, topic);
                topicArgs.putBoolean(AppHeader.EXTRA_HIDE_INFO_BUTTON, true);
                topicArgs.putString(AppInfoBase.ARG_PACKAGE_NAME, mPkg);
                topicArgs.putParcelable(TopicNotificationSettings.ARG_PACKAGE_INFO, mPkgInfo);

                Intent topicIntent = Utils.onBuildStartFragmentIntent(getActivity(),
                        TopicNotificationSettings.class.getName(),
                        topicArgs, null, R.string.topic_notifications_title, null, false);
                topicPreference.setIntent(topicIntent);
                mCategories.addPreference(topicPreference);
            }
        }
        updateDependents(mAppRow.appImportance);
    }

    @Override
    protected void updateDependents(int progress) {
        updateDependents(progress == Ranking.IMPORTANCE_NONE);
    }
    protected void updateDependents(int importance) {
        final boolean lockscreenSecure = new LockPatternUtils(getActivity()).isSecure(
                UserHandle.myUserId());
        final boolean lockscreenNotificationsEnabled = getLockscreenNotificationsEnabled();
        final boolean allowPrivate = getLockscreenAllowPrivateNotifications();

    private void removeTopicPrefs() {
        setVisible(mImportance, false);
        setVisible(mImportanceReset, false);
        setVisible(mImportanceTitle, false);
        setVisible(mPriority, false);
        setVisible(mSensitive, false);
        setVisible(mPriority, checkCanBeVisible(Ranking.IMPORTANCE_DEFAULT, importance)
                && !mDndVisualEffectsSuppressed);
        setVisible(mSensitive, checkCanBeVisible(Ranking.IMPORTANCE_LOW, importance)
                && lockscreenSecure && lockscreenNotificationsEnabled && allowPrivate);
    }

    private void removeAppPrefs() {
        setVisible(mBlock, false);
        setVisible(mCategories, false);
    protected boolean checkCanBeVisible(int minImportanceVisible, int importance) {
        if (importance == Ranking.IMPORTANCE_UNSPECIFIED) {
            return true;
        }

    private void updateDependents(boolean banned) {
        mBlock.setEnabled(!mAppRow.systemApp);
        mCategories.setEnabled(!banned);
        return importance > minImportanceVisible;
    }

    private void setupBlockSwitch() {
        mBlock.setDisabledByAdmin(mSuspendedAppsAdmin);
        mBlock.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                final boolean banned = (Boolean) newValue;
                if (banned) {
                    MetricsLogger.action(getActivity(), MetricsEvent.ACTION_BAN_APP_NOTES, mPkg);
                }
                final boolean success = mBackend.setNotificationsBanned(mPkg, mUid, banned);
                if (success) {
                    updateDependents(banned);
    private boolean getLockscreenNotificationsEnabled() {
        return Settings.Secure.getInt(getContentResolver(),
                Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0) != 0;
    }
                return success;
            }
        });
        mBlock.setChecked(mAppRow.banned);
        updateDependents(mAppRow.banned);

    private boolean getLockscreenAllowPrivateNotifications() {
        return Settings.Secure.getInt(getContentResolver(),
                Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0) != 0;
    }

    private List<ResolveInfo> queryNotificationConfigActivities() {
Loading