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

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

Merge "Remove ColorDisplayController"

parents ef5a6c92 41e6a70d
Loading
Loading
Loading
Loading
+0 −17
Original line number Diff line number Diff line
@@ -8397,15 +8397,6 @@ HPLcom/android/internal/app/AlertController;->setMessage(Ljava/lang/CharSequence
HPLcom/android/internal/app/AssistUtils;->allowDisablingAssistDisclosure(Landroid/content/Context;)Z
HPLcom/android/internal/app/AssistUtils;->isPreinstalledAssistant(Landroid/content/Context;Landroid/content/ComponentName;)Z
HPLcom/android/internal/app/AssistUtils;->shouldDisclose(Landroid/content/Context;Landroid/content/ComponentName;)Z
HPLcom/android/internal/app/ColorDisplayController$1;->onChange(ZLandroid/net/Uri;)V
HPLcom/android/internal/app/ColorDisplayController;-><init>(Landroid/content/Context;I)V
HPLcom/android/internal/app/ColorDisplayController;->getAccessibilityTransformActivated()Z
HPLcom/android/internal/app/ColorDisplayController;->getColorTemperature()I
HPLcom/android/internal/app/ColorDisplayController;->getCustomEndTime()Ljava/time/LocalTime;
HPLcom/android/internal/app/ColorDisplayController;->getCustomStartTime()Ljava/time/LocalTime;
HPLcom/android/internal/app/ColorDisplayController;->getLastActivatedTime()Ljava/time/LocalDateTime;
HPLcom/android/internal/app/ColorDisplayController;->onSettingChanged(Ljava/lang/String;)V
HPLcom/android/internal/app/ColorDisplayController;->setActivated(Z)Z
HPLcom/android/internal/app/IAppOpsActiveCallback$Stub$Proxy;->opActiveChanged(IILjava/lang/String;Z)V
HPLcom/android/internal/app/IAppOpsCallback$Stub;->asInterface(Landroid/os/IBinder;)Lcom/android/internal/app/IAppOpsCallback;
HPLcom/android/internal/app/IAppOpsService$Stub$Proxy;->finishOperation(Landroid/os/IBinder;IILjava/lang/String;)V
@@ -38265,11 +38256,6 @@ HSPLcom/android/internal/app/AssistUtils;-><init>(Landroid/content/Context;)V
HSPLcom/android/internal/app/AssistUtils;->activeServiceSupportsAssistGesture()Z
HSPLcom/android/internal/app/AssistUtils;->getActiveServiceComponentName()Landroid/content/ComponentName;
HSPLcom/android/internal/app/AssistUtils;->getAssistComponentForUser(I)Landroid/content/ComponentName;
HSPLcom/android/internal/app/ColorDisplayController;-><init>(Landroid/content/Context;)V
HSPLcom/android/internal/app/ColorDisplayController;->getAutoMode()I
HSPLcom/android/internal/app/ColorDisplayController;->isActivated()Z
HSPLcom/android/internal/app/ColorDisplayController;->isAvailable(Landroid/content/Context;)Z
HSPLcom/android/internal/app/ColorDisplayController;->setListener(Lcom/android/internal/app/ColorDisplayController$Callback;)V
HSPLcom/android/internal/app/IAppOpsActiveCallback$Stub$Proxy;->asBinder()Landroid/os/IBinder;
HSPLcom/android/internal/app/IAppOpsActiveCallback$Stub;->asInterface(Landroid/os/IBinder;)Lcom/android/internal/app/IAppOpsActiveCallback;
HSPLcom/android/internal/app/IAppOpsActiveCallback;->opActiveChanged(IILjava/lang/String;Z)V
@@ -59959,9 +59945,6 @@ Lcom/android/internal/app/AlertController$CheckedItemAdapter;
Lcom/android/internal/app/AlertController$RecycleListView;
Lcom/android/internal/app/AlertController;
Lcom/android/internal/app/AssistUtils;
Lcom/android/internal/app/ColorDisplayController$1;
Lcom/android/internal/app/ColorDisplayController$Callback;
Lcom/android/internal/app/ColorDisplayController;
Lcom/android/internal/app/IAppOpsActiveCallback$Stub$Proxy;
Lcom/android/internal/app/IAppOpsActiveCallback$Stub;
Lcom/android/internal/app/IAppOpsActiveCallback;
+0 −1
Original line number Diff line number Diff line
@@ -3923,7 +3923,6 @@ com.android.ims.internal.IImsServiceFeatureCallback$Stub
com.android.internal.R$styleable
com.android.internal.app.AlertController
com.android.internal.app.AlertController$AlertParams
com.android.internal.app.ColorDisplayController
com.android.internal.app.IAppOpsCallback
com.android.internal.app.IAppOpsCallback$Stub
com.android.internal.app.IAppOpsService
+0 −298
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 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.internal.app;

import android.annotation.NonNull;
import android.app.ActivityManager;
import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
import android.hardware.display.ColorDisplayManager;
import android.hardware.display.ColorDisplayManager.AutoMode;
import android.hardware.display.ColorDisplayManager.ColorMode;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import android.provider.Settings.Secure;
import android.util.Slog;

import java.time.LocalTime;

/**
 * Controller for managing night display and color mode settings.
 * <p/>
 * Night display tints your screen red at night. This makes it easier to look at your screen in
 * dim light and may help you fall asleep more easily.
 */
public final class ColorDisplayController {

    private static final String TAG = "ColorDisplayController";
    private static final boolean DEBUG = false;

    private final Context mContext;
    private final int mUserId;
    private final ColorDisplayManager mColorDisplayManager;

    private ContentObserver mContentObserver;
    private Callback mCallback;

    public ColorDisplayController(@NonNull Context context) {
        this(context, ActivityManager.getCurrentUser());
    }

    public ColorDisplayController(@NonNull Context context, int userId) {
        mContext = context.getApplicationContext();
        mUserId = userId;
        mColorDisplayManager = mContext.getSystemService(ColorDisplayManager.class);
    }

    /**
     * Returns {@code true} when Night display is activated (the display is tinted red).
     */
    public boolean isActivated() {
        return mColorDisplayManager.isNightDisplayActivated();
    }

    /**
     * Sets whether Night display should be activated. This also sets the last activated time.
     *
     * @param activated {@code true} if Night display should be activated
     * @return {@code true} if the activated value was set successfully
     */
    public boolean setActivated(boolean activated) {
        return mColorDisplayManager.setNightDisplayActivated(activated);
    }

    /**
     * Returns the current auto mode value controlling when Night display will be automatically
     * activated. One of {@link ColorDisplayManager#AUTO_MODE_DISABLED}, {@link
     * ColorDisplayManager#AUTO_MODE_CUSTOM_TIME} or {@link ColorDisplayManager#AUTO_MODE_TWILIGHT}.
     */
    public @AutoMode int getAutoMode() {
        return mColorDisplayManager.getNightDisplayAutoMode();
    }

    /**
     * Returns the current auto mode value, without validation, or {@code 1} if the auto mode has
     * never been set.
     */
    public int getAutoModeRaw() {
        return mColorDisplayManager.getNightDisplayAutoModeRaw();
    }

    /**
     * Sets the current auto mode value controlling when Night display will be automatically
     * activated. One of {@link ColorDisplayManager#AUTO_MODE_DISABLED}, {@link
     * ColorDisplayManager#AUTO_MODE_CUSTOM_TIME} or {@link ColorDisplayManager#AUTO_MODE_TWILIGHT}.
     *
     * @param autoMode the new auto mode to use
     * @return {@code true} if new auto mode was set successfully
     */
    public boolean setAutoMode(@AutoMode int autoMode) {
        return mColorDisplayManager.setNightDisplayAutoMode(autoMode);
    }

    /**
     * Returns the local time when Night display will be automatically activated when using {@link
     * ColorDisplayManager#AUTO_MODE_CUSTOM_TIME}.
     */
    public @NonNull LocalTime getCustomStartTime() {
        return mColorDisplayManager.getNightDisplayCustomStartTime();
    }

    /**
     * Sets the local time when Night display will be automatically activated when using {@link
     * ColorDisplayManager#AUTO_MODE_CUSTOM_TIME}.
     *
     * @param startTime the local time to automatically activate Night display
     * @return {@code true} if the new custom start time was set successfully
     */
    public boolean setCustomStartTime(@NonNull LocalTime startTime) {
        return mColorDisplayManager.setNightDisplayCustomStartTime(startTime);
    }

    /**
     * Returns the local time when Night display will be automatically deactivated when using {@link
     * ColorDisplayManager#AUTO_MODE_CUSTOM_TIME}.
     */
    public @NonNull LocalTime getCustomEndTime() {
        return mColorDisplayManager.getNightDisplayCustomEndTime();
    }

    /**
     * Sets the local time when Night display will be automatically deactivated when using {@link
     * ColorDisplayManager#AUTO_MODE_CUSTOM_TIME}.
     *
     * @param endTime the local time to automatically deactivate Night display
     * @return {@code true} if the new custom end time was set successfully
     */
    public boolean setCustomEndTime(@NonNull LocalTime endTime) {
        return mColorDisplayManager.setNightDisplayCustomEndTime(endTime);
    }

    /**
     * Returns the color temperature (in Kelvin) to tint the display when activated.
     */
    public int getColorTemperature() {
        return mColorDisplayManager.getNightDisplayColorTemperature();
    }

    /**
     * Sets the current temperature.
     *
     * @param colorTemperature the temperature, in Kelvin.
     * @return {@code true} if new temperature was set successfully.
     */
    public boolean setColorTemperature(int colorTemperature) {
        return mColorDisplayManager.setNightDisplayColorTemperature(colorTemperature);
    }

    /**
     * Get the current color mode.
     */
    public int getColorMode() {
        return mColorDisplayManager.getColorMode();
    }

    /**
     * Set the current color mode.
     *
     * @param colorMode the color mode
     */
    public void setColorMode(@ColorMode int colorMode) {
        mColorDisplayManager.setColorMode(colorMode);
    }

    /**
     * Returns the minimum allowed color temperature (in Kelvin) to tint the display when activated.
     */
    public int getMinimumColorTemperature() {
        return ColorDisplayManager.getMinimumColorTemperature(mContext);
    }

    /**
     * Returns the maximum allowed color temperature (in Kelvin) to tint the display when activated.
     */
    public int getMaximumColorTemperature() {
        return ColorDisplayManager.getMaximumColorTemperature(mContext);
    }

    private void onSettingChanged(@NonNull String setting) {
        if (DEBUG) {
            Slog.d(TAG, "onSettingChanged: " + setting);
        }

        if (mCallback != null) {
            switch (setting) {
                case Secure.NIGHT_DISPLAY_ACTIVATED:
                    mCallback.onActivated(isActivated());
                    break;
                case Secure.NIGHT_DISPLAY_AUTO_MODE:
                    mCallback.onAutoModeChanged(getAutoMode());
                    break;
                case Secure.NIGHT_DISPLAY_CUSTOM_START_TIME:
                    mCallback.onCustomStartTimeChanged(getCustomStartTime());
                    break;
                case Secure.NIGHT_DISPLAY_CUSTOM_END_TIME:
                    mCallback.onCustomEndTimeChanged(getCustomEndTime());
                    break;
                case Secure.NIGHT_DISPLAY_COLOR_TEMPERATURE:
                    mCallback.onColorTemperatureChanged(getColorTemperature());
                    break;
            }
        }
    }

    /**
     * Register a callback to be invoked whenever the Night display settings are changed.
     */
    public void setListener(Callback callback) {
        final Callback oldCallback = mCallback;
        if (oldCallback != callback) {
            mCallback = callback;

            if (mContentObserver == null) {
                mContentObserver = new ContentObserver(new Handler(Looper.getMainLooper())) {
                    @Override
                    public void onChange(boolean selfChange, Uri uri) {
                        super.onChange(selfChange, uri);

                        final String setting = uri == null ? null : uri.getLastPathSegment();
                        if (setting != null) {
                            onSettingChanged(setting);
                        }
                    }
                };
            }

            if (callback == null) {
                // Stop listening for changes now that there IS NOT a listener.
                mContext.getContentResolver().unregisterContentObserver(mContentObserver);
            } else if (oldCallback == null) {
                // Start listening for changes now that there IS a listener.
                final ContentResolver cr = mContext.getContentResolver();
                cr.registerContentObserver(Secure.getUriFor(Secure.NIGHT_DISPLAY_ACTIVATED),
                        false /* notifyForDescendants */, mContentObserver, mUserId);
                cr.registerContentObserver(Secure.getUriFor(Secure.NIGHT_DISPLAY_AUTO_MODE),
                        false /* notifyForDescendants */, mContentObserver, mUserId);
                cr.registerContentObserver(Secure.getUriFor(Secure.NIGHT_DISPLAY_CUSTOM_START_TIME),
                        false /* notifyForDescendants */, mContentObserver, mUserId);
                cr.registerContentObserver(Secure.getUriFor(Secure.NIGHT_DISPLAY_CUSTOM_END_TIME),
                        false /* notifyForDescendants */, mContentObserver, mUserId);
                cr.registerContentObserver(Secure.getUriFor(Secure.NIGHT_DISPLAY_COLOR_TEMPERATURE),
                        false /* notifyForDescendants */, mContentObserver, mUserId);
            }
        }
    }

    /**
     * Callback invoked whenever the Night display settings are changed.
     */
    public interface Callback {
        /**
         * Callback invoked when the activated state changes.
         *
         * @param activated {@code true} if Night display is activated
         */
        default void onActivated(boolean activated) {}
        /**
         * Callback invoked when the auto mode changes.
         *
         * @param autoMode the auto mode to use
         */
        default void onAutoModeChanged(int autoMode) {}
        /**
         * Callback invoked when the time to automatically activate Night display changes.
         *
         * @param startTime the local time to automatically activate Night display
         */
        default void onCustomStartTimeChanged(LocalTime startTime) {}
        /**
         * Callback invoked when the time to automatically deactivate Night display changes.
         *
         * @param endTime the local time to automatically deactivate Night display
         */
        default void onCustomEndTimeChanged(LocalTime endTime) {}

        /**
         * Callback invoked when the color temperature changes.
         *
         * @param colorTemperature the color temperature to tint the screen
         */
        default void onColorTemperatureChanged(int colorTemperature) {}
    }
}
+0 −1
Original line number Diff line number Diff line
@@ -10635,7 +10635,6 @@ PLcom/android/server/display/ColorDisplayService$CustomAutoMode;->updateNextAlar
PLcom/android/server/display/ColorDisplayService;-><init>(Landroid/content/Context;)V
PLcom/android/server/display/ColorDisplayService;->access$1000(Lcom/android/server/display/ColorDisplayService;)Ljava/lang/Boolean;
PLcom/android/server/display/ColorDisplayService;->access$602(Lcom/android/server/display/ColorDisplayService;Landroid/animation/ValueAnimator;)Landroid/animation/ValueAnimator;
PLcom/android/server/display/ColorDisplayService;->access$900(Lcom/android/server/display/ColorDisplayService;)Lcom/android/internal/app/ColorDisplayController;
PLcom/android/server/display/ColorDisplayService;->applyTint(Z)V
PLcom/android/server/display/ColorDisplayService;->getDateTimeAfter(Ljava/time/LocalTime;Ljava/time/LocalDateTime;)Ljava/time/LocalDateTime;
PLcom/android/server/display/ColorDisplayService;->getDateTimeBefore(Ljava/time/LocalTime;Ljava/time/LocalDateTime;)Ljava/time/LocalDateTime;