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

Commit 72137f3a authored by Pavel Grafov's avatar Pavel Grafov
Browse files

Remove "don't show" option from work notifications settings

Option to not show notifications is still available for
device-wide locks screen notification settings.

Also s/On lock screen/When work profile is locked/ for work
notifications since it applies not only to lock screen but to
notification shade as well.

Bug: 64829587
Test: make RunSettingsRoboTests
Change-Id: Ie3ec461f4c8887a5a49cd92b5350ea683f701027
parent 7ac7d7b6
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -7170,6 +7170,9 @@
    <!-- Configure Notifications: Title for the option controlling notifications on the lockscreen. [CHAR LIMIT=30] -->
    <string name="lock_screen_notifications_title">On lock screen</string>
    <!-- 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: Value for lockscreen notifications:  all information will be
         shown in notifications shown on a secure lock screen
         [CHAR LIMIT=50] -->
@@ -7200,10 +7203,6 @@
         [CHAR LIMIT=50] -->
    <string name="lock_screen_notifications_summary_hide_profile">Hide sensitive work content</string>
    <!-- Configure Notifications: Value for lockscreen notifications: work notifications will not appear on a secure lock screen
         [CHAR LIMIT=50] -->
    <string name="lock_screen_notifications_summary_disable_profile">Don\u2019t show work notifications at all</string>
    <!-- Security > Choose PIN/PW/Pattern > Notification redaction interstitial: Message asking the user how they want their profile notifications to appear when the device is locked [CHAR LIMIT=NONE] -->
    <string name="lock_screen_notifications_interstitial_message_profile">When your device is locked, how do you want profile notifications to show?</string>
+1 −2
Original line number Diff line number Diff line
@@ -89,10 +89,9 @@

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

    </PreferenceCategory>

</PreferenceScreen>
+1 −1
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@

        <com.android.settings.RestrictedListPreference
            android:key="security_setting_lock_screen_notif_work"
            android:title="@string/lock_screen_notifications_title"
            android:title="@string/locked_work_profile_notification_title"
            android:summary="@string/summary_placeholder" />

    </PreferenceCategory>
+32 −42
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ 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 android.app.admin.DevicePolicyManager;
import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
@@ -59,7 +60,7 @@ public class LockScreenNotificationPreferenceController extends AbstractPreferen
    private RestrictedListPreference mLockscreen;
    private RestrictedListPreference mLockscreenProfile;

    private final int mProfileChallengeUserId;
    private final int mProfileUserId;
    private final boolean mSecure;
    private final boolean mSecureProfile;

@@ -78,29 +79,24 @@ public class LockScreenNotificationPreferenceController extends AbstractPreferen
        mWorkSettingCategoryKey = workSettingCategoryKey;
        mWorkSettingKey = workSettingKey;

        mProfileChallengeUserId = Utils.getManagedProfileId(
                UserManager.get(context), UserHandle.myUserId());
        mProfileUserId = Utils.getManagedProfileId(UserManager.get(context), UserHandle.myUserId());
        final LockPatternUtils utils = FeatureFactory.getFactory(context)
                .getSecurityFeatureProvider()
                .getLockPatternUtils(context);
        mSecure = utils.isSecure(UserHandle.myUserId());
        mSecureProfile = (mProfileChallengeUserId != UserHandle.USER_NULL)
                && (utils.isSecure(mProfileChallengeUserId)
                || (!utils.isSeparateProfileChallengeEnabled(mProfileChallengeUserId) && mSecure));
        mSecureProfile = (mProfileUserId != UserHandle.USER_NULL) && utils.isSecure(mProfileUserId);
    }

    @Override
    public void displayPreference(PreferenceScreen screen) {
        super.displayPreference(screen);
        mLockscreen =
                (RestrictedListPreference) screen.findPreference(mSettingKey);
        mLockscreen = (RestrictedListPreference) screen.findPreference(mSettingKey);
        if (mLockscreen == null) {
            Log.i(TAG, "Preference not found: " + mSettingKey);
            return;
        }
        if (mProfileChallengeUserId != UserHandle.USER_NULL) {
            mLockscreenProfile = (RestrictedListPreference) screen.findPreference(
                    mWorkSettingKey);
        if (mProfileUserId != UserHandle.USER_NULL) {
            mLockscreenProfile = (RestrictedListPreference) screen.findPreference(mWorkSettingKey);
        } else {
            setVisible(screen, mWorkSettingKey, false /* visible */);
            setVisible(screen, mWorkSettingCategoryKey, false /* visible */);
@@ -178,9 +174,6 @@ public class LockScreenNotificationPreferenceController extends AbstractPreferen
                    KEYGUARD_DISABLE_SECURE_NOTIFICATIONS);
        }

        entries.add(mContext.getString(R.string.lock_screen_notifications_summary_disable_profile));
        values.add(Integer.toString(R.string.lock_screen_notifications_summary_disable_profile));

        mLockscreenProfile.setEntries(entries.toArray(new CharSequence[entries.size()]));
        mLockscreenProfile.setEntryValues(values.toArray(new CharSequence[values.size()]));
        updateLockscreenNotificationsForProfile();
@@ -221,23 +214,17 @@ public class LockScreenNotificationPreferenceController extends AbstractPreferen
        final String key = preference.getKey();
        if (TextUtils.equals(mWorkSettingKey, key)) {
            if (Utils.startQuietModeDialogIfNecessary(mContext, UserManager.get(mContext),
                    mProfileChallengeUserId)) {
                    mProfileUserId)) {
                return false;
            }
            final int val = Integer.parseInt((String) newValue);
            if (val == mLockscreenSelectedValueProfile) {
                return false;
            }
            final boolean enabled =
                    val != R.string.lock_screen_notifications_summary_disable_profile;
            final boolean show =
                    val == R.string.lock_screen_notifications_summary_show_profile;
            final boolean show = val == R.string.lock_screen_notifications_summary_show_profile;
            Settings.Secure.putIntForUser(mContext.getContentResolver(),
                    Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS,
                    show ? 1 : 0, mProfileChallengeUserId);
            Settings.Secure.putIntForUser(mContext.getContentResolver(),
                    Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS,
                    enabled ? 1 : 0, mProfileChallengeUserId);
                    show ? 1 : 0, mProfileUserId);
            mLockscreenSelectedValueProfile = val;
            return true;
        } else if (TextUtils.equals(mSettingKey, key)) {
@@ -245,8 +232,7 @@ public class LockScreenNotificationPreferenceController extends AbstractPreferen
            if (val == mLockscreenSelectedValue) {
                return false;
            }
            final boolean enabled =
                    val != R.string.lock_screen_notifications_summary_disable;
            final boolean enabled = val != R.string.lock_screen_notifications_summary_disable;
            final boolean show = val == R.string.lock_screen_notifications_summary_show;
            Settings.Secure.putInt(mContext.getContentResolver(),
                    Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, show ? 1 : 0);
@@ -268,10 +254,10 @@ public class LockScreenNotificationPreferenceController extends AbstractPreferen
                    new RestrictedListPreference.RestrictedItem(entry, entryValue, admin);
            mLockscreen.addRestrictedItem(item);
        }
        if (mProfileChallengeUserId != UserHandle.USER_NULL) {
        if (mProfileUserId != UserHandle.USER_NULL) {
            RestrictedLockUtils.EnforcedAdmin profileAdmin =
                    RestrictedLockUtils.checkIfKeyguardFeaturesDisabled(
                            mContext, keyguardNotificationFeatures, mProfileChallengeUserId);
                            mContext, keyguardNotificationFeatures, mProfileUserId);
            if (profileAdmin != null && mLockscreenProfile != null) {
                RestrictedListPreference.RestrictedItem item =
                        new RestrictedListPreference.RestrictedItem(
@@ -282,13 +268,13 @@ public class LockScreenNotificationPreferenceController extends AbstractPreferen
    }

    public static int getSummaryResource(Context context) {
        final boolean enabled = getLockscreenNotificationsEnabled(context, UserHandle.myUserId());
        final boolean enabled = getLockscreenNotificationsEnabled(context);
        final boolean secure = FeatureFactory.getFactory(context)
                .getSecurityFeatureProvider()
                .getLockPatternUtils(context)
                .isSecure(UserHandle.myUserId());
        final boolean allowPrivate = !secure
            || getLockscreenAllowPrivateNotifications(context, UserHandle.myUserId());
            || getAllowPrivateNotifications(context, UserHandle.myUserId());
        return !enabled ? R.string.lock_screen_notifications_summary_disable :
            allowPrivate ? R.string.lock_screen_notifications_summary_show :
                R.string.lock_screen_notifications_summary_hide;
@@ -303,30 +289,34 @@ public class LockScreenNotificationPreferenceController extends AbstractPreferen
        mLockscreen.setValue(Integer.toString(mLockscreenSelectedValue));
    }

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

    private void updateLockscreenNotificationsForProfile() {
        if (mProfileChallengeUserId == UserHandle.USER_NULL) {
        if (mProfileUserId == UserHandle.USER_NULL) {
            return;
        }
        if (mLockscreenProfile == null) {
            return;
        }
        final boolean enabled = getLockscreenNotificationsEnabled(mContext,mProfileChallengeUserId);
        final boolean allowPrivate = !mSecureProfile
                || getLockscreenAllowPrivateNotifications(mContext, mProfileChallengeUserId);
        final boolean allowPrivate = adminAllowsUnredactedNotifications(mProfileUserId) &&
                (!mSecureProfile || getAllowPrivateNotifications(mContext, mProfileUserId));
        mLockscreenProfile.setSummary("%s");
        mLockscreenSelectedValueProfile = !enabled
                ? R.string.lock_screen_notifications_summary_disable_profile
                : (allowPrivate ? R.string.lock_screen_notifications_summary_show_profile
                        : R.string.lock_screen_notifications_summary_hide_profile);
        mLockscreenSelectedValueProfile = allowPrivate
                        ? R.string.lock_screen_notifications_summary_show_profile
                        : R.string.lock_screen_notifications_summary_hide_profile;
        mLockscreenProfile.setValue(Integer.toString(mLockscreenSelectedValueProfile));
    }

    private static boolean getLockscreenNotificationsEnabled(Context context, int userId) {
        return Settings.Secure.getIntForUser(context.getContentResolver(),
                Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0, userId) != 0;
    private static boolean getLockscreenNotificationsEnabled(Context context) {
        return Settings.Secure.getInt(context.getContentResolver(),
                Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0) != 0;
    }

    private static boolean getLockscreenAllowPrivateNotifications(Context context, int userId) {
    private static boolean getAllowPrivateNotifications(Context context, int userId) {
        return Settings.Secure.getIntForUser(context.getContentResolver(),
                Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0, userId) != 0;
    }
@@ -356,7 +346,7 @@ public class LockScreenNotificationPreferenceController extends AbstractPreferen
            super.onChange(selfChange, uri);
            if (LOCK_SCREEN_PRIVATE_URI.equals(uri) || LOCK_SCREEN_SHOW_URI.equals(uri)) {
                updateLockscreenNotifications();
                if (mProfileChallengeUserId != UserHandle.USER_NULL) {
                if (mProfileUserId != UserHandle.USER_NULL) {
                    updateLockscreenNotificationsForProfile();
                }
            }
+8 −7
Original line number Diff line number Diff line
@@ -123,8 +123,8 @@ public class RedactionInterstitial extends SettingsActivity {
                mShowAllButton.setText(R.string.lock_screen_notifications_summary_show_profile);
                mRedactSensitiveButton
                        .setText(R.string.lock_screen_notifications_summary_hide_profile);
                ((RadioButton) view.findViewById(R.id.hide_all))
                    .setText(R.string.lock_screen_notifications_summary_disable_profile);

                ((RadioButton) view.findViewById(R.id.hide_all)).setVisibility(View.GONE);
            }

            final Button button = (Button) view.findViewById(R.id.redaction_done_button);
@@ -164,7 +164,8 @@ public class RedactionInterstitial extends SettingsActivity {
        }

        private void loadFromSettings() {
            final boolean enabled = Settings.Secure.getIntForUser(getContentResolver(),
            final boolean managed = UserManager.get(getContext()).isManagedProfile(mUserId);
            final boolean enabled = !managed || Settings.Secure.getIntForUser(getContentResolver(),
                    Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0, mUserId) != 0;
            final boolean show = Settings.Secure.getIntForUser(getContentResolver(),
                    Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1, mUserId) != 0;