aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Paik <spaik@google.com>2018-03-16 17:27:43 -0700
committerSteve Paik <spaik@google.com>2018-03-16 18:41:45 -0700
commit47cdf7ba2a0773d2090e797584678935420adccb (patch)
tree5f64364ace10a49dada5a24857e9b426931bcca7
parent7e45b2bad1fa887a160d79738139d3062a1869b2 (diff)
downloadCar-47cdf7ba2a0773d2090e797584678935420adccb.tar.gz
Plumb display brightness from Android to VHAL
Bug: 75322336 Test: Python emulator receives display brightness updates Change-Id: I1a535798ee6e0de40abef999b6026880d3bb8146
-rw-r--r--service/src/com/android/car/CarPowerManagementService.java10
-rw-r--r--service/src/com/android/car/hal/PowerHalService.java20
-rw-r--r--service/src/com/android/car/systeminterface/DisplayInterface.java39
3 files changed, 63 insertions, 6 deletions
diff --git a/service/src/com/android/car/CarPowerManagementService.java b/service/src/com/android/car/CarPowerManagementService.java
index 3aa473caed..57ccf622c8 100644
--- a/service/src/com/android/car/CarPowerManagementService.java
+++ b/service/src/com/android/car/CarPowerManagementService.java
@@ -604,7 +604,7 @@ public class CarPowerManagementService extends ICarPower.Stub implements CarServ
}
private void doHandleMainDisplayStateChange(boolean on) {
- //TODO bug: 32065231
+ Log.w(CarLog.TAG_POWER, "Unimplemented: doHandleMainDisplayStateChange() - on = " + on);
}
public void handleMainDisplayChanged(boolean on) {
@@ -615,6 +615,14 @@ public class CarPowerManagementService extends ICarPower.Stub implements CarServ
handler.handleMainDisplayStateChange(on);
}
+ /**
+ * Send display brightness to VHAL.
+ * @param brightness value 0-100%
+ */
+ public void sendDisplayBrightness(int brightness) {
+ mHal.sendDisplayBrightness(brightness);
+ }
+
public synchronized Handler getHandler() {
return mHandler;
}
diff --git a/service/src/com/android/car/hal/PowerHalService.java b/service/src/com/android/car/hal/PowerHalService.java
index 00c8e6929b..f43e8532dc 100644
--- a/service/src/com/android/car/hal/PowerHalService.java
+++ b/service/src/com/android/car/hal/PowerHalService.java
@@ -204,6 +204,24 @@ public class PowerHalService extends HalServiceBase {
setPowerState(VehicleApPowerSetState.SHUTDOWN_START, wakeupTimeSec);
}
+ /**
+ * Sets the display brightness for the vehicle.
+ * @param brightness value from 0 to 100.
+ */
+ public void sendDisplayBrightness(int brightness) {
+ if (brightness < 0) {
+ brightness = 0;
+ } else if (brightness > 100) {
+ brightness = 100;
+ }
+ try {
+ mHal.set(VehicleProperty.DISPLAY_BRIGHTNESS, 0).to(brightness);
+ Log.i(CarLog.TAG_POWER, "send display brightness = " + brightness);
+ } catch (PropertyTimeoutException e) {
+ Log.e(CarLog.TAG_POWER, "cannot set DISPLAY_BRIGHTNESS", e);
+ }
+ }
+
public void sendDisplayOn() {
Log.i(CarLog.TAG_POWER, "send display on");
setPowerState(VehicleApPowerSetState.DISPLAY_ON, 0);
@@ -217,7 +235,7 @@ public class PowerHalService extends HalServiceBase {
private void setPowerState(int state, int additionalParam) {
int[] values = { state, additionalParam };
try {
- mHal.set(VehicleProperty.AP_POWER_STATE).to(values);
+ mHal.set(VehicleProperty.AP_POWER_STATE, 0).to(values);
Log.i(CarLog.TAG_POWER, "setPowerState=" + state + " param=" + additionalParam);
} catch (PropertyTimeoutException e) {
Log.e(CarLog.TAG_POWER, "cannot set to AP_POWER_STATE", e);
diff --git a/service/src/com/android/car/systeminterface/DisplayInterface.java b/service/src/com/android/car/systeminterface/DisplayInterface.java
index 8ef4aecf35..015f54dc27 100644
--- a/service/src/com/android/car/systeminterface/DisplayInterface.java
+++ b/service/src/com/android/car/systeminterface/DisplayInterface.java
@@ -16,12 +16,17 @@
package com.android.car.systeminterface;
+import android.content.ContentResolver;
import android.content.Context;
+import android.database.ContentObserver;
import android.hardware.display.DisplayManager;
import android.hardware.display.DisplayManager.DisplayListener;
+import android.os.Handler;
+import android.os.Looper;
import android.os.PowerManager;
import android.os.SystemClock;
-import android.provider.Settings;
+import android.provider.Settings.SettingNotFoundException;
+import android.provider.Settings.System;
import android.util.Log;
import android.view.Display;
@@ -41,6 +46,7 @@ public interface DisplayInterface {
void stopDisplayStateMonitoring();
class DefaultImpl implements DisplayInterface {
+ private final ContentResolver mContentResolver;
private final Context mContext;
private final DisplayManager mDisplayManager;
private final int mMaximumBacklight;
@@ -49,6 +55,28 @@ public interface DisplayInterface {
private final WakeLockInterface mWakeLockInterface;
private CarPowerManagementService mService;
private boolean mDisplayStateSet;
+
+ private ContentObserver mBrightnessObserver =
+ new ContentObserver(new Handler(Looper.getMainLooper())) {
+ @Override
+ public void onChange(boolean selfChange) {
+ int brightness = mMinimumBacklight;
+ int range = mMaximumBacklight - mMinimumBacklight;
+
+ try {
+ brightness = System.getInt(mContentResolver, System.SCREEN_BRIGHTNESS);
+ } catch (SettingNotFoundException e) {
+ Log.e(CarLog.TAG_POWER, "Could not get SCREEN_BRIGHTNESS: " + e);
+ }
+ // Convert brightness from 0-255 to 0-100%
+ brightness -= mMinimumBacklight;
+ brightness *= 100;
+ brightness += (range + 1) / 2;
+ brightness /= range;
+ mService.sendDisplayBrightness(brightness);
+ }
+ };
+
private final DisplayManager.DisplayListener mDisplayListener = new DisplayListener() {
@Override
public void onDisplayAdded(int displayId) {
@@ -70,11 +98,12 @@ public interface DisplayInterface {
DefaultImpl(Context context, WakeLockInterface wakeLockInterface) {
mContext = context;
- mWakeLockInterface = wakeLockInterface;
+ mContentResolver = mContext.getContentResolver();
mDisplayManager = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
mPowerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
mMaximumBacklight = mPowerManager.getMaximumScreenBrightnessSetting();
mMinimumBacklight = mPowerManager.getMinimumScreenBrightnessSetting();
+ mWakeLockInterface = wakeLockInterface;
}
private void handleMainDisplayChanged() {
@@ -114,8 +143,7 @@ public interface DisplayInterface {
brightness = mMaximumBacklight;
}
// Set the brightness
- Settings.System.putInt(mContext.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS,
- brightness);
+ System.putInt(mContentResolver, System.SCREEN_BRIGHTNESS, brightness);
}
@Override
@@ -124,12 +152,15 @@ public interface DisplayInterface {
mService = service;
mDisplayStateSet = isMainDisplayOn();
}
+ mContentResolver.registerContentObserver(System.getUriFor(System.SCREEN_BRIGHTNESS),
+ false, mBrightnessObserver);
mDisplayManager.registerDisplayListener(mDisplayListener, service.getHandler());
}
@Override
public void stopDisplayStateMonitoring() {
mDisplayManager.unregisterDisplayListener(mDisplayListener);
+ mContentResolver.unregisterContentObserver(mBrightnessObserver);
}
@Override