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

Commit 5649922b authored by Christine Franks's avatar Christine Franks Committed by Android (Google) Code Review
Browse files

Merge "Support forced Night Display auto mode"

parents fcfc116a 8ad6f6d6
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -8827,6 +8827,14 @@ public final class Settings {
        */
       public static final String NETWORK_SCORER_APP = "network_scorer_app";

        /**
         * Whether night display forced auto mode is available.
         * 0 = unavailable, 1 = available.
         * @hide
         */
        public static final String NIGHT_DISPLAY_FORCED_AUTO_MODE_AVAILABLE =
                "night_display_forced_auto_mode_available";

       /**
        * If the NITZ_UPDATE_DIFF time is exceeded then an automatic adjustment
        * to SystemClock will be allowed even if NITZ_UPDATE_SPACING has not been
+33 −1
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.app.ActivityManager;
import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
import android.metrics.LogMaker;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
@@ -31,6 +32,8 @@ import android.provider.Settings.System;
import android.util.Slog;

import com.android.internal.R;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -109,10 +112,10 @@ public final class ColorDisplayController {

    private final Context mContext;
    private final int mUserId;

    private final ContentObserver mContentObserver;

    private Callback mCallback;
    private MetricsLogger mMetricsLogger;

    public ColorDisplayController(@NonNull Context context) {
        this(context, ActivityManager.getCurrentUser());
@@ -208,6 +211,15 @@ public final class ColorDisplayController {
        return autoMode;
    }

    /**
     * Returns the current auto mode value, without validation, or {@code 1} if the auto mode has
     * never been set.
     */
    public int getAutoModeRaw() {
        return Secure.getIntForUser(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_AUTO_MODE,
                -1, mUserId);
    }

    /**
     * Sets the current auto mode value controlling when Night display will be automatically
     * activated. One of {@link #AUTO_MODE_DISABLED}, {@link #AUTO_MODE_CUSTOM}, or
@@ -228,7 +240,12 @@ public final class ColorDisplayController {
                    Secure.NIGHT_DISPLAY_LAST_ACTIVATED_TIME,
                    null,
                    mUserId);
            getMetricsLogger().write(new LogMaker(
                    MetricsEvent.ACTION_NIGHT_DISPLAY_AUTO_MODE_CHANGED)
                    .setType(MetricsEvent.TYPE_ACTION)
                    .setSubtype(autoMode));
        }

        return Secure.putIntForUser(mContext.getContentResolver(),
                Secure.NIGHT_DISPLAY_AUTO_MODE, autoMode, mUserId);
    }
@@ -263,6 +280,10 @@ public final class ColorDisplayController {
        if (startTime == null) {
            throw new IllegalArgumentException("startTime cannot be null");
        }
        getMetricsLogger().write(new LogMaker(
                MetricsEvent.ACTION_NIGHT_DISPLAY_AUTO_MODE_CUSTOM_TIME_CHANGED)
                .setType(MetricsEvent.TYPE_ACTION)
                .setSubtype(0));
        return Secure.putIntForUser(mContext.getContentResolver(),
                Secure.NIGHT_DISPLAY_CUSTOM_START_TIME, startTime.toSecondOfDay() * 1000, mUserId);
    }
@@ -297,6 +318,10 @@ public final class ColorDisplayController {
        if (endTime == null) {
            throw new IllegalArgumentException("endTime cannot be null");
        }
        getMetricsLogger().write(new LogMaker(
                MetricsEvent.ACTION_NIGHT_DISPLAY_AUTO_MODE_CUSTOM_TIME_CHANGED)
                .setType(MetricsEvent.TYPE_ACTION)
                .setSubtype(1));
        return Secure.putIntForUser(mContext.getContentResolver(),
                Secure.NIGHT_DISPLAY_CUSTOM_END_TIME, endTime.toSecondOfDay() * 1000, mUserId);
    }
@@ -450,6 +475,13 @@ public final class ColorDisplayController {
        }
    }

    private MetricsLogger getMetricsLogger() {
        if (mMetricsLogger == null) {
            mMetricsLogger = new MetricsLogger();
        }
        return mMetricsLogger;
    }

    /**
     * Returns {@code true} if Night display is supported by the device.
     */
+1 −0
Original line number Diff line number Diff line
@@ -305,6 +305,7 @@ public class SettingsBackupTest {
                    Settings.Global.NETWORK_SWITCH_NOTIFICATION_RATE_LIMIT_MILLIS,
                    Settings.Global.NETWORK_WATCHLIST_ENABLED,
                    Settings.Global.NEW_CONTACT_AGGREGATOR,
                    Settings.Global.NIGHT_DISPLAY_FORCED_AUTO_MODE_AVAILABLE,
                    Settings.Global.NITZ_UPDATE_DIFF,
                    Settings.Global.NITZ_UPDATE_SPACING,
                    Settings.Global.NOTIFICATION_SNOOZE_OPTIONS,
+18 −0
Original line number Diff line number Diff line
@@ -16,12 +16,16 @@

package com.android.systemui.qs.tiles;

import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_QS_MODE;

import android.annotation.Nullable;
import android.app.ActivityManager;
import android.content.Intent;
import android.metrics.LogMaker;
import android.provider.Settings;
import android.service.quicksettings.Tile;
import android.support.annotation.StringRes;
import android.util.Log;
import android.widget.Switch;

import com.android.internal.app.ColorDisplayController;
@@ -65,6 +69,15 @@ public class NightDisplayTile extends QSTileImpl<BooleanState>

    @Override
    protected void handleClick() {
        // Enroll in forced auto mode if eligible.
        if ("1".equals(Settings.Global.getString(mContext.getContentResolver(),
                Settings.Global.NIGHT_DISPLAY_FORCED_AUTO_MODE_AVAILABLE))
                && mController.getAutoModeRaw() == -1) {
            mController.setAutoMode(ColorDisplayController.AUTO_MODE_CUSTOM);
            Log.i("NightDisplayTile", "Enrolled in forced night display auto mode");
        }

        // Change current activation state.
        final boolean activated = !mState.value;
        mController.setActivated(activated);
    }
@@ -146,6 +159,11 @@ public class NightDisplayTile extends QSTileImpl<BooleanState>
        return MetricsEvent.QS_NIGHT_DISPLAY;
    }

    @Override
    public LogMaker populate(LogMaker logMaker) {
        return super.populate(logMaker).addTaggedData(FIELD_QS_MODE, mController.getAutoModeRaw());
    }

    @Override
    public Intent getLongClickIntent() {
        return new Intent(Settings.ACTION_NIGHT_DISPLAY_SETTINGS);