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

Commit ed4e9d6c authored by Yining Liu's avatar Yining Liu Committed by Android (Google) Code Review
Browse files

Merge "Notification on lockscreen settings: default unseen setting value" into main

parents a1e47ef8 d3a855b6
Loading
Loading
Loading
Loading
+24 −6
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.settings.notification;

import static android.provider.Settings.Secure.LOCK_SCREEN_SHOW_ONLY_UNSEEN_NOTIFICATIONS;

import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
@@ -42,7 +44,8 @@ import com.android.settings.core.TogglePreferenceController;
public class LockScreenNotificationShowSeenController extends TogglePreferenceController
        implements LifecycleEventObserver {

    private static final int UNSET = 0;
    // 0 is the default value for phones, we treat 0 as off as usage
    private static final int UNSET_OFF = 0;
    static final int ON = 1;
    static final int OFF = 2;
    @Nullable private Preference mPreference;
@@ -96,14 +99,24 @@ public class LockScreenNotificationShowSeenController extends TogglePreferenceCo

    @Override
    public int getAvailabilityStatus() {
        if (!Flags.notificationMinimalism()) {
            return CONDITIONALLY_UNAVAILABLE;
        }
        if (Flags.notificationMinimalism()) {
            if (!lockScreenShowNotification()) {
                return CONDITIONALLY_UNAVAILABLE;
            }
            // We want to show the switch when the lock screen notification minimalism flag is on.
            return AVAILABLE;
        }

        int setting = Settings.Secure.getInt(mContext.getContentResolver(),
                LOCK_SCREEN_SHOW_ONLY_UNSEEN_NOTIFICATIONS, UNSET_OFF);
        if (setting == UNSET_OFF) {
            // hide the setting if the minimalism flag is off, and the device is phone
            // UNSET_OFF is the default value for phones
            return CONDITIONALLY_UNAVAILABLE;
        } else {
            return AVAILABLE;
        }
    }

    /**
     * @return Whether showing notifications on the lockscreen is enabled.
@@ -118,9 +131,14 @@ public class LockScreenNotificationShowSeenController extends TogglePreferenceCo
        return lockScreenShowSeenNotifications();
    }

    /**
     * @return whether to show seen notifications on lockscreen
     */
    private boolean lockScreenShowSeenNotifications() {
        // UNSET_OFF is the default value for phone, which is equivalent to off in effect
        // (show seen notification)
        return Settings.Secure.getInt(mContext.getContentResolver(),
                Settings.Secure.LOCK_SCREEN_SHOW_ONLY_UNSEEN_NOTIFICATIONS, UNSET) == OFF;
                Settings.Secure.LOCK_SCREEN_SHOW_ONLY_UNSEEN_NOTIFICATIONS, UNSET_OFF) != ON;
    }

    @Override
+6 −4
Original line number Diff line number Diff line
@@ -31,7 +31,9 @@ import com.android.settings.core.TogglePreferenceController;
public class ShowOnlyUnseenNotificationsOnLockscreenPreferenceController
        extends TogglePreferenceController {

    private static final int UNSET = 0;
    // This is the default value for phones, before notification minimalism, this setting is
    // unavailable to phones, we use this value to hide the toggle on phones.
    private static final int UNSET_UNAVAILABLE = 0;
    @VisibleForTesting
    static final int ON = 1;
    @VisibleForTesting
@@ -46,7 +48,7 @@ public class ShowOnlyUnseenNotificationsOnLockscreenPreferenceController
    @Override
    public boolean isChecked() {
        return Settings.Secure.getInt(mContext.getContentResolver(),
                LOCK_SCREEN_SHOW_ONLY_UNSEEN_NOTIFICATIONS, UNSET) == ON;
                LOCK_SCREEN_SHOW_ONLY_UNSEEN_NOTIFICATIONS, UNSET_UNAVAILABLE) == ON;
    }

    @Override
@@ -69,8 +71,8 @@ public class ShowOnlyUnseenNotificationsOnLockscreenPreferenceController
            return AVAILABLE;
        }
        int setting = Settings.Secure.getInt(mContext.getContentResolver(),
                LOCK_SCREEN_SHOW_ONLY_UNSEEN_NOTIFICATIONS, UNSET);
        if (setting == UNSET) {
                LOCK_SCREEN_SHOW_ONLY_UNSEEN_NOTIFICATIONS, UNSET_UNAVAILABLE);
        if (setting == UNSET_UNAVAILABLE) {
            return CONDITIONALLY_UNAVAILABLE;
        } else {
            return AVAILABLE;