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

Commit a2dfa95e authored by Kenny Guy's avatar Kenny Guy Committed by Android (Google) Code Review
Browse files

Merge "New class to track brightness slider interactions."

parents 0253dd03 22bd044b
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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 android.hardware.display;

parcelable BrightnessChangeEvent;
+103 −0
Original line number Diff line number Diff line
/*
 * Copyright 2017 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 android.hardware.display;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * Data about a brightness settings change.
 * TODO make this SystemAPI
 * @hide
 */
public final class BrightnessChangeEvent implements Parcelable {
    /** Brightness in nits */
    public int brightness;

    /** Timestamp of the change {@see System.currentTimeMillis()} */
    public long timeStamp;

    /** Package name of focused activity when brightness was changed. */
    public String packageName;

    /** User id of of the user running when brightness was changed.
     * @hide */
    public int userId;

    /** Lux values of recent sensor data */
    public float[] luxValues;

    /** Timestamps of the lux sensor readings {@see System.currentTimeMillis()} */
    public long[] luxTimestamps;

    /** Most recent battery level when brightness was changed or Float.NaN */
    public float batteryLevel;

    /** Color filter active to provide night mode */
    public boolean nightMode;

    /** If night mode color filter is active this will be the temperature in kelvin */
    public int colorTemperature;

    /** Brightness level before slider adjustment */
    public int lastBrightness;

    public BrightnessChangeEvent() {
    }

    private BrightnessChangeEvent(Parcel source) {
        brightness = source.readInt();
        timeStamp = source.readLong();
        packageName = source.readString();
        userId = source.readInt();
        luxValues = source.createFloatArray();
        luxTimestamps = source.createLongArray();
        batteryLevel = source.readFloat();
        nightMode = source.readBoolean();
        colorTemperature = source.readInt();
        lastBrightness = source.readInt();
    }

    public static final Creator<BrightnessChangeEvent> CREATOR =
            new Creator<BrightnessChangeEvent>() {
                public BrightnessChangeEvent createFromParcel(Parcel source) {
                    return new BrightnessChangeEvent(source);
                }
                public BrightnessChangeEvent[] newArray(int size) {
                    return new BrightnessChangeEvent[size];
                }
            };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(brightness);
        dest.writeLong(timeStamp);
        dest.writeString(packageName);
        dest.writeInt(userId);
        dest.writeFloatArray(luxValues);
        dest.writeLongArray(luxTimestamps);
        dest.writeFloat(batteryLevel);
        dest.writeBoolean(nightMode);
        dest.writeInt(colorTemperature);
        dest.writeInt(lastBrightness);
    }
}
+16 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.view.Surface;
import android.view.WindowManagerPolicy;

import java.util.ArrayList;
import java.util.List;

/**
 * Manages the properties of attached displays.
@@ -614,6 +615,21 @@ public final class DisplayManager {
        return mGlobal.getStableDisplaySize();
    }

    /**
     * Fetch {@link BrightnessChangeEvent}s.
     * @hide until we make it a system api.
     */
    public List<BrightnessChangeEvent> getBrightnessEvents() {
        return mGlobal.getBrightnessEvents();
    }

    /**
     * @hide STOPSHIP - remove when adaptive brightness accepts curves.
     */
    public void setBrightness(int brightness) {
        mGlobal.setBrightness(brightness);
    }

    /**
     * Listens for changes in available display devices.
     */
+30 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.hardware.display;

import android.content.Context;
import android.content.pm.ParceledListSlice;
import android.content.res.Resources;
import android.graphics.Point;
import android.hardware.display.DisplayManager.DisplayListener;
@@ -37,6 +38,8 @@ import android.view.DisplayInfo;
import android.view.Surface;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Manager communication with the display manager service on behalf of
@@ -456,6 +459,33 @@ public final class DisplayManagerGlobal {
        }
    }

    /**
     * Retrieves brightness change events.
     */
    public List<BrightnessChangeEvent> getBrightnessEvents() {
        try {
            ParceledListSlice<BrightnessChangeEvent> events = mDm.getBrightnessEvents();
            if (events == null) {
                return Collections.emptyList();
            }
            return events.getList();
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
    }

    /**
     * Set brightness but don't add a BrightnessChangeEvent
     * STOPSHIP remove when adaptive brightness accepts curves.
     */
    public void setBrightness(int brightness) {
        try {
            mDm.setBrightness(brightness);
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
    }

    private final class DisplayManagerCallback extends IDisplayManagerCallback.Stub {
        @Override
        public void onDisplayEvent(int displayId, int event) {
+8 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.hardware.display;

import android.content.pm.ParceledListSlice;
import android.graphics.Point;
import android.hardware.display.IDisplayManagerCallback;
import android.hardware.display.IVirtualDisplayCallback;
@@ -81,4 +82,11 @@ interface IDisplayManager {

    // Get a stable metric for the device's display size. No permissions required.
    Point getStableDisplaySize();

    // Requires BRIGHTNESS_SLIDER_USAGE permission.
    ParceledListSlice getBrightnessEvents();

    // STOPSHIP remove when adaptive brightness code is updated to accept curves.
    // Requires BRIGHTNESS_SLIDER_USAGE permission.
    void setBrightness(int brightness);
}
Loading