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

Commit 1c83c082 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Config notifs page updates" into qt-dev

parents 49776845 4fe79c26
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -7974,6 +7974,32 @@
    <!-- Configure Notifications: Title for the option controlling notifications for work profile. [CHAR LIMIT=30] -->
    <string name="locked_work_profile_notification_title">When work profile is locked</string>
    <!-- Configure notifications: Title for determining which notifications appear on the lock screen [CHAR LIMIT=60] -->
    <string name="lock_screen_notifs_title">Notifications on lockscreen</string>
    <!-- Configure notifications: Value for lockscreen notifications: all notifications shown
    regardless of noisiness [CHAR LIMIT=60] -->
    <string name="lock_screen_notifs_show_all">Show alerting and silent notifications</string>
    <!-- Configure notifications: Value for lockscreen notifications: show alerting notifications [CHAR LIMIT=60] -->
    <string name="lock_screen_notifs_show_alerting">Show alerting notifications only</string>
    <!-- Configure notifications: Value for lockscreen notifications: don't show notifications [CHAR LIMIT=60] -->
    <string name="lock_screen_notifs_show_none">Don\u2019t show notifications</string>
    <!-- Configure notifications: Title for redacting sensitive content on lockscreen [CHAR LIMIT=60] -->
    <string name="lock_screen_notifs_redact">Sensitive notifications</string>
    <!-- Configure notifications: Summary for redacting sensitive content on lockscreen [CHAR LIMIT=120] -->
    <string name="lock_screen_notifs_redact_summary">Show sensitive content when locked</string>
    <!-- Configure notifications: Title for redacting sensitive content on lockscreen, work profile [CHAR LIMIT=60] -->
    <string name="lock_screen_notifs_redact_work">Sensitive work profile notifications</string>
    <!-- Configure notifications: Summary for redacting sensitive content on lockscreen, work profile [CHAR LIMIT=120] -->
    <string name="lock_screen_notifs_redact_work_summary">Show sensitive work profile content when locked</string>
    <!-- Configure Notifications: Value for lockscreen notifications:  all information will be
         shown in notifications shown on a secure lock screen
         [CHAR LIMIT=50] -->
+45 −69
Original line number Diff line number Diff line
@@ -26,27 +26,52 @@
        settings:controller="com.android.settings.widget.VideoPreferenceController"
        android:persistent="false" />

    <Preference
        android:key="gentle_notifications"
        android:title="@string/gentle_notifications_title"
        settings:controller="com.android.settings.notification.GentleNotificationsPreferenceController"
        android:fragment="com.android.settings.notification.GentleNotificationSettings"/>
    <!-- Empty category to draw divider -->
    <PreferenceCategory
        android:key="all_notifications_divider"
        android:order="2"/>

    <PreferenceCategory
        android:key="configure_notifications_smart"
        android:title="@string/smart_notifications_title"
        android:key="recent_notifications_category"
        android:title="@string/recent_notifications"
        settings:allowDividerAbove="false"
        android:order="3">
        <!-- Placeholder for a list of recent apps -->

        <!-- See all apps button -->
        <Preference
            android:key="all_notifications"
            android:title="@string/notifications_title"
            android:fragment="com.android.settings.applications.manageapplications.ManageApplications"
            android:order="4">
            <extra
                android:name="classname"
                android:value="com.android.settings.Settings$NotificationAppListActivity"/>
        </Preference>
    </PreferenceCategory>

    <PreferenceCategory
        android:key="configure_notifications_lock"
        android:title="@string/lock_screen_notifications_title"
        android:order="10">
        <!-- When device is locked -->
        <com.android.settings.RestrictedListPreference
            android:key="lock_screen_notifications"
            android:title="@string/lock_screen_notifs_title"
            android:summary="@string/summary_placeholder" />

        <SwitchPreference
            android:key="asst_capability_prioritizer"
            android:title="@string/asst_capability_prioritizer_title"
            android:summary="@string/asst_capability_prioritizer_summary"
            settings:controller="com.android.settings.notification.AssistantCapabilityPreferenceController" />
            android:key="lock_screen_redact"
            android:title="@string/lock_screen_notifs_redact"
            android:summary="@string/lock_screen_notifs_redact_summary"
            settings:controller="com.android.settings.notification.RedactNotificationPreferenceController" />

        <SwitchPreference
            android:key="asst_capabilities_actions_replies"
            android:title="@string/asst_capabilities_actions_replies_title"
            android:summary="@string/asst_capabilities_actions_replies_summary"
            settings:controller="com.android.settings.notification.AssistantCapabilityPreferenceController" />
            android:key="lock_screen_work_redact"
            android:title="@string/lock_screen_notifs_redact_work"
            android:summary="@string/lock_screen_notifs_redact_work_summary"
            settings:controller="com.android.settings.notification.RedactNotificationPreferenceController" />

    </PreferenceCategory>

    <PreferenceCategory
@@ -54,19 +79,11 @@
        android:order="15"
        settings:initialExpandedChildrenCount="0">

        <com.android.settings.RestrictedListPreference
            android:key="swipe"
            android:title="@string/swipe_direction_title"
            android:entries="@array/swipe_direction_titles"
            android:entryValues="@array/swipe_direction_values"
            settings:controller="com.android.settings.notification.SwipeDirectionPreferenceController"/>

        <!-- When device is locked -->
        <com.android.settings.RestrictedListPreference
            android:key="lock_screen_notifications"
            android:title="@string/lock_screen_notifications_title"
            android:summary="@string/summary_placeholder"
            settings:searchable="false"/>
        <SwitchPreference
            android:key="asst_capabilities_actions_replies"
            android:title="@string/asst_capabilities_actions_replies_title"
            android:summary="@string/asst_capabilities_actions_replies_summary"
            settings:controller="com.android.settings.notification.AssistantCapabilityPreferenceController" />

        <!-- Notification badging -->
        <SwitchPreference
@@ -102,45 +119,4 @@
            settings:controller="com.android.settings.notification.ZenModePreferenceController"
            settings:allowDividerAbove="false"/>
    </PreferenceCategory>

    <!-- Empty category to draw divider -->
    <PreferenceCategory
        android:key="all_notifications_divider"
        android:order="20"/>

    <PreferenceCategory
        android:key="recent_notifications_category"
        android:title="@string/recent_notifications"
        settings:allowDividerAbove="false"
        android:order="21">
        <!-- Placeholder for a list of recent apps -->

        <!-- See all apps button -->
        <Preference
            android:key="all_notifications"
            android:title="@string/notifications_title"
            android:fragment="com.android.settings.applications.manageapplications.ManageApplications"
            android:order="22">
            <extra
                android:name="classname"
                android:value="com.android.settings.Settings$NotificationAppListActivity"/>
        </Preference>
    </PreferenceCategory>

    <!-- Place work profile section at the bottom to avoid users thinking that any of the
         above settings are specific to the work profile -->
    <PreferenceCategory
        android:key="lock_screen_notifications_profile_header"
        android:title="@string/profile_section_header"
        android:order="23"
        settings:searchable="false">

        <com.android.settings.RestrictedListPreference
            android:key="lock_screen_notifications_profile"
            android:title="@string/locked_work_profile_notification_title"
            android:summary="@string/summary_placeholder"
            android:order="24"
            settings:searchable="false"/>
    </PreferenceCategory>

</PreferenceScreen>
+6 −21
Original line number Diff line number Diff line
@@ -57,17 +57,9 @@ public class ConfigureNotificationSettings extends DashboardFragment implements
        OnActivityResultListener {
    private static final String TAG = "ConfigNotiSettings";

    @VisibleForTesting
    static final String KEY_LOCKSCREEN = "lock_screen_notifications";
    @VisibleForTesting
    static final String KEY_LOCKSCREEN_WORK_PROFILE_HEADER =
            "lock_screen_notifications_profile_header";
    @VisibleForTesting
    static final String KEY_LOCKSCREEN_WORK_PROFILE = "lock_screen_notifications_profile";
    @VisibleForTesting
    static final String KEY_SWIPE_DOWN = "gesture_swipe_down_fingerprint_notifications";
    @VisibleForTesting
    static final String KEY_NOTIFICATION_ASSISTANT = "notification_assistant";
    static final String KEY_LOCKSCREEN = "lock_screen_notifications";

    private static final String KEY_NOTI_DEFAULT_RINGTONE = "notification_default_ringtone";
    private static final int REQUEST_CODE = 200;
@@ -100,25 +92,18 @@ public class ConfigureNotificationSettings extends DashboardFragment implements
        } else {
            app = null;
        }
        return buildPreferenceControllers(context, getSettingsLifecycle(), app, this);
        return buildPreferenceControllers(context, app, this);
    }

    private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
            Lifecycle lifecycle, Application app, Fragment host) {
            Application app, Fragment host) {
        final List<AbstractPreferenceController> controllers = new ArrayList<>();
        final LockScreenNotificationPreferenceController lockScreenNotificationController =
                new LockScreenNotificationPreferenceController(context,
                        KEY_LOCKSCREEN,
                        KEY_LOCKSCREEN_WORK_PROFILE_HEADER,
                        KEY_LOCKSCREEN_WORK_PROFILE);
        if (lifecycle != null) {
            lifecycle.addObserver(lockScreenNotificationController);
        }
        controllers.add(new RecentNotifyingAppsPreferenceController(
                context, new NotificationBackend(), IUsageStatsManager.Stub.asInterface(
                        ServiceManager.getService(Context.USAGE_STATS_SERVICE)),
                context.getSystemService(UserManager.class), app, host));
        controllers.add(lockScreenNotificationController);
        controllers.add(new ShowOnLockScreenNotificationPreferenceController(
                context, KEY_LOCKSCREEN));
        controllers.add(new NotificationRingtonePreferenceController(context) {
            @Override
            public String getPreferenceKey() {
@@ -245,7 +230,7 @@ public class ConfigureNotificationSettings extends DashboardFragment implements
                @Override
                public List<AbstractPreferenceController> createPreferenceControllers(
                        Context context) {
                    return buildPreferenceControllers(context, null, null, null);
                    return buildPreferenceControllers(context, null, null);
                }

                @Override
+1 −1
Original line number Diff line number Diff line
@@ -71,7 +71,7 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC
    static final String KEY_DIVIDER = "all_notifications_divider";
    @VisibleForTesting
    static final String KEY_SEE_ALL = "all_notifications";
    private static final int SHOW_RECENT_APP_COUNT = 5;
    private static final int SHOW_RECENT_APP_COUNT = 3;
    private static final int DAYS = 3;
    private static final Set<String> SKIP_SYSTEM_PACKAGES = new ArraySet<>();

+130 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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.
 */

package com.android.settings.notification;

import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS;
import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS;
import static android.provider.Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS;

import android.app.KeyguardManager;
import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;

import com.android.internal.widget.LockPatternUtils;
import com.android.settings.Utils;
import com.android.settings.core.TogglePreferenceController;
import com.android.settings.overlay.FeatureFactory;

public class RedactNotificationPreferenceController extends TogglePreferenceController {

    private static final String TAG = "LockScreenNotifPref";

    static final String KEY_LOCKSCREEN_REDACT = "lock_screen_redact";
    static final String KEY_LOCKSCREEN_WORK_PROFILE_REDACT = "lock_screen_work_redact";

    private DevicePolicyManager mDpm;
    private UserManager mUm;
    private KeyguardManager mKm;
    private final int mProfileUserId;

    public RedactNotificationPreferenceController(Context context, String settingKey) {
        super(context, settingKey);

        mUm = context.getSystemService(UserManager.class);
        mDpm = context.getSystemService(DevicePolicyManager.class);
        mKm = context.getSystemService(KeyguardManager.class);

        mProfileUserId = Utils.getManagedProfileId(mUm, UserHandle.myUserId());
    }

    @Override
    public boolean isChecked() {
        int userId = KEY_LOCKSCREEN_REDACT.equals(getPreferenceKey())
                ? UserHandle.myUserId() : mProfileUserId;

        return getAllowPrivateNotifications(userId);
    }

    @Override
    public boolean setChecked(boolean isChecked) {
        int userId = KEY_LOCKSCREEN_REDACT.equals(getPreferenceKey())
                ? UserHandle.myUserId() : mProfileUserId;

        Settings.Secure.putIntForUser(mContext.getContentResolver(),
                Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, isChecked ? 1 : 0, userId);
        return true;
    }

    @Override
    public int getAvailabilityStatus() {
        // hide work profile setting if no work profile
        if (KEY_LOCKSCREEN_WORK_PROFILE_REDACT.equals(getPreferenceKey())
                && mProfileUserId == UserHandle.USER_NULL) {
            return CONDITIONALLY_UNAVAILABLE;
        }

        int userId = KEY_LOCKSCREEN_REDACT.equals(getPreferenceKey())
                ? UserHandle.myUserId() : mProfileUserId;

        // hide if lockscreen isn't secure for this user
        final LockPatternUtils utils = FeatureFactory.getFactory(mContext)
                .getSecurityFeatureProvider()
                .getLockPatternUtils(mContext);
        if (!utils.isSecure(userId)) {
            return CONDITIONALLY_UNAVAILABLE;
        }

        // all notifs hidden? admin doesn't allow notifs or redacted notifs? disabled
        if (!getLockscreenNotificationsEnabled(userId)
                || !adminAllowsNotifications(userId)
                || !adminAllowsUnredactedNotifications(userId)) {
            return DISABLED_DEPENDENT_SETTING;
        }

        // specifically the work profile setting requires the work profile to be unlocked
        if (KEY_LOCKSCREEN_WORK_PROFILE_REDACT.equals(getPreferenceKey())) {
            if (mKm.isDeviceLocked(mProfileUserId)) {
                return DISABLED_DEPENDENT_SETTING;
            }
        }

        return AVAILABLE;
    }

    private boolean adminAllowsNotifications(int userId) {
        final int dpmFlags = mDpm.getKeyguardDisabledFeatures(null/* admin */, userId);
        return (dpmFlags & KEYGUARD_DISABLE_SECURE_NOTIFICATIONS) == 0;
    }

    private boolean adminAllowsUnredactedNotifications(int userId) {
        final int dpmFlags = mDpm.getKeyguardDisabledFeatures(null/* admin */, userId);
        return (dpmFlags & KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS) == 0;
    }

    private boolean getAllowPrivateNotifications(int userId) {
        return Settings.Secure.getIntForUser(mContext.getContentResolver(),
                LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1, userId) != 0;
    }

   private boolean getLockscreenNotificationsEnabled(int userId) {
        return Settings.Secure.getIntForUser(mContext.getContentResolver(),
                Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 1, userId) != 0;
    }
}
Loading