Rename Light to LogicalLight to avoid namespace conflicts when adding

AIDL HAL lights support.

LogicalLight is the internal implementation of Light that used to be
exposed directly from LightsService and consumed by
NotificationManagerService and a few more other places. The new
canonical API is going to be android.hardware.lights.Light, hence
renaming this one.

Bug: 142230898
Test: make checkbuild # (actual tests in followup patch)
Change-Id: I3d31eeee675278cd472a197d3a975add26264bb1
Merged-In: Id5f7bfc74cef6d584c42712fcbea816e456b8b2d
This commit is contained in:
Ivailo Karamanolev
2020-01-16 16:10:42 +01:00
committed by Robin Lee
parent e1cebc7556
commit b19593a5c3
9 changed files with 63 additions and 22 deletions

View File

@@ -66,8 +66,8 @@ import com.android.internal.app.IBatteryStats;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.util.DumpUtils;
import com.android.server.am.BatteryStatsService;
import com.android.server.lights.Light;
import com.android.server.lights.LightsManager;
import com.android.server.lights.LogicalLight;
import java.io.File;
import java.io.FileDescriptor;
@@ -1063,7 +1063,7 @@ public final class BatteryService extends SystemService {
}
private final class Led {
private final Light mBatteryLight;
private final LogicalLight mBatteryLight;
private final int mBatteryLowARGB;
private final int mBatteryMediumARGB;
@@ -1098,7 +1098,7 @@ public final class BatteryService extends SystemService {
mBatteryLight.setColor(mBatteryLowARGB);
} else {
// Flash red when battery is low and not charging
mBatteryLight.setFlashing(mBatteryLowARGB, Light.LIGHT_FLASH_TIMED,
mBatteryLight.setFlashing(mBatteryLowARGB, LogicalLight.LIGHT_FLASH_TIMED,
mBatteryLedOn, mBatteryLedOff);
}
} else if (status == BatteryManager.BATTERY_STATUS_CHARGING

View File

@@ -38,8 +38,8 @@ import android.view.Surface;
import android.view.SurfaceControl;
import com.android.server.LocalServices;
import com.android.server.lights.Light;
import com.android.server.lights.LightsManager;
import com.android.server.lights.LogicalLight;
import java.io.PrintWriter;
import java.util.ArrayList;
@@ -160,7 +160,7 @@ final class LocalDisplayAdapter extends DisplayAdapter {
private final class LocalDisplayDevice extends DisplayDevice {
private final long mPhysicalDisplayId;
private final Light mBacklight;
private final LogicalLight mBacklight;
private final SparseArray<DisplayModeRecord> mSupportedModes = new SparseArray<>();
private final ArrayList<Integer> mSupportedColorModes = new ArrayList<>();
private final boolean mIsInternal;

View File

@@ -29,5 +29,8 @@ public abstract class LightsManager {
public static final int LIGHT_ID_WIFI = Type.WIFI;
public static final int LIGHT_ID_COUNT = Type.COUNT;
public abstract Light getLight(int id);
/**
* Returns the logical light with the given type.
*/
public abstract LogicalLight getLight(int id);
}

View File

@@ -34,7 +34,7 @@ public class LightsService extends SystemService {
final LightImpl mLights[] = new LightImpl[LightsManager.LIGHT_ID_COUNT];
private final class LightImpl extends Light {
private final class LightImpl extends LogicalLight {
private final IBinder mDisplayToken;
private final int mSurfaceControlMaximumBrightness;
@@ -231,7 +231,7 @@ public class LightsService extends SystemService {
private final LightsManager mService = new LightsManager() {
@Override
public Light getLight(int id) {
public LogicalLight getLight(int id) {
if (0 <= id && id < LIGHT_ID_COUNT) {
return mLights[id];
} else {

View File

@@ -19,9 +19,24 @@ package com.android.server.lights;
import android.hardware.light.V2_0.Brightness;
import android.hardware.light.V2_0.Flash;
public abstract class Light {
/**
* Allow control over a logical light of a given type. The mapping of logical lights to physical
* lights is HAL implementation-dependent.
*/
public abstract class LogicalLight {
/**
* Keep the light steady on or off.
*/
public static final int LIGHT_FLASH_NONE = Flash.NONE;
/**
* Flash the light at specified rate.
*/
public static final int LIGHT_FLASH_TIMED = Flash.TIMED;
/**
* Flash the light using hardware assist.
*/
public static final int LIGHT_FLASH_HARDWARE = Flash.HARDWARE;
/**
@@ -49,10 +64,33 @@ public abstract class Light {
*/
public abstract void setBrightness(int brightness, int brightnessMode);
/**
* Set the color of a light.
*/
public abstract void setColor(int color);
/**
* Set the color of a light and control flashing.
*/
public abstract void setFlashing(int color, int mode, int onMS, int offMS);
/**
* Pulses the light.
*/
public abstract void pulse();
/**
* Pulses the light with a specified color for a specified duration.
*/
public abstract void pulse(int color, int onMS);
/**
* Turns off the light.
*/
public abstract void turnOff();
/**
* Set the VR mode of a display.
*/
public abstract void setVrMode(boolean enabled);
}

View File

@@ -233,8 +233,8 @@ import com.android.server.EventLogTags;
import com.android.server.IoThread;
import com.android.server.LocalServices;
import com.android.server.SystemService;
import com.android.server.lights.Light;
import com.android.server.lights.LightsManager;
import com.android.server.lights.LogicalLight;
import com.android.server.notification.ManagedServices.ManagedServiceInfo;
import com.android.server.notification.ManagedServices.UserProfiles;
import com.android.server.pm.PackageManagerService;
@@ -376,8 +376,8 @@ public class NotificationManagerService extends SystemService {
private final HandlerThread mRankingThread = new HandlerThread("ranker",
Process.THREAD_PRIORITY_BACKGROUND);
private Light mNotificationLight;
Light mAttentionLight;
private LogicalLight mNotificationLight;
LogicalLight mAttentionLight;
private long[] mFallbackVibrationPattern;
private boolean mUseAttentionLight;
@@ -1507,7 +1507,7 @@ public class NotificationManagerService extends SystemService {
}
@VisibleForTesting
void setLights(Light light) {
void setLights(LogicalLight light) {
mNotificationLight = light;
mAttentionLight = light;
mNotificationPulseEnabled = true;
@@ -7085,7 +7085,7 @@ public class NotificationManagerService extends SystemService {
NotificationRecord.Light light = ledNotification.getLight();
if (light != null && mNotificationPulseEnabled) {
// pulse repeatedly
mNotificationLight.setFlashing(light.color, Light.LIGHT_FLASH_TIMED,
mNotificationLight.setFlashing(light.color, LogicalLight.LIGHT_FLASH_TIMED,
light.onMs, light.offMs);
}
}

View File

@@ -93,8 +93,8 @@ import com.android.server.SystemService;
import com.android.server.UiThread;
import com.android.server.Watchdog;
import com.android.server.am.BatteryStatsService;
import com.android.server.lights.Light;
import com.android.server.lights.LightsManager;
import com.android.server.lights.LogicalLight;
import com.android.server.policy.WindowManagerPolicy;
import com.android.server.power.batterysaver.BatterySaverController;
import com.android.server.power.batterysaver.BatterySaverPolicy;
@@ -247,7 +247,7 @@ public final class PowerManagerService extends SystemService
private WirelessChargerDetector mWirelessChargerDetector;
private SettingsObserver mSettingsObserver;
private DreamManagerInternal mDreamManager;
private Light mAttentionLight;
private LogicalLight mAttentionLight;
private final Object mLock = LockGuard.installNewLock(LockGuard.INDEX_POWER);
@@ -3130,7 +3130,7 @@ public final class PowerManagerService extends SystemService
}
private void setAttentionLightInternal(boolean on, int color) {
Light light;
LogicalLight light;
synchronized (mLock) {
if (!mSystemReady) {
return;
@@ -3139,7 +3139,7 @@ public final class PowerManagerService extends SystemService
}
// Control light outside of lock.
light.setFlashing(color, Light.LIGHT_FLASH_HARDWARE, (on ? 3 : 0), 0);
light.setFlashing(color, LogicalLight.LIGHT_FLASH_HARDWARE, (on ? 3 : 0), 0);
}
private void setDozeAfterScreenOffInternal(boolean on) {

View File

@@ -72,7 +72,7 @@ import androidx.test.runner.AndroidJUnit4;
import com.android.internal.util.IntPair;
import com.android.server.UiServiceTestCase;
import com.android.server.lights.Light;
import com.android.server.lights.LogicalLight;
import org.junit.Before;
import org.junit.Test;
@@ -89,7 +89,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase {
@Mock AudioManager mAudioManager;
@Mock Vibrator mVibrator;
@Mock android.media.IRingtonePlayer mRingtonePlayer;
@Mock Light mLight;
@Mock LogicalLight mLight;
@Mock
NotificationManagerService.WorkerHandler mHandler;
@Mock

View File

@@ -142,8 +142,8 @@ import com.android.internal.statusbar.NotificationVisibility;
import com.android.server.LocalServices;
import com.android.server.SystemService;
import com.android.server.UiServiceTestCase;
import com.android.server.lights.Light;
import com.android.server.lights.LightsManager;
import com.android.server.lights.LogicalLight;
import com.android.server.notification.NotificationManagerService.NotificationAssistants;
import com.android.server.notification.NotificationManagerService.NotificationListeners;
import com.android.server.uri.UriGrantsManagerInternal;
@@ -351,7 +351,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
.thenReturn(applicationInfo);
when(mPackageManagerClient.getPackageUidAsUser(any(), anyInt())).thenReturn(mUid);
final LightsManager mockLightsManager = mock(LightsManager.class);
when(mockLightsManager.getLight(anyInt())).thenReturn(mock(Light.class));
when(mockLightsManager.getLight(anyInt())).thenReturn(mock(LogicalLight.class));
when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_NORMAL);
when(mPackageManagerClient.hasSystemFeature(FEATURE_WATCH)).thenReturn(false);
when(mUgmInternal.newUriPermissionOwner(anyString())).thenReturn(mPermOwner);