Merge "Remove DozeFactory. Add DozeComponent/DozeScope."
This commit is contained in:
@@ -24,6 +24,7 @@ import com.android.keyguard.KeyguardUpdateMonitor;
|
||||
import com.android.systemui.BootCompleteCache;
|
||||
import com.android.systemui.BootCompleteCacheImpl;
|
||||
import com.android.systemui.assist.AssistModule;
|
||||
import com.android.systemui.doze.dagger.DozeComponent;
|
||||
import com.android.systemui.dump.DumpManager;
|
||||
import com.android.systemui.log.dagger.LogModule;
|
||||
import com.android.systemui.model.SysUiState;
|
||||
@@ -68,6 +69,7 @@ import dagger.Provides;
|
||||
},
|
||||
subcomponents = {StatusBarComponent.class,
|
||||
NotificationRowComponent.class,
|
||||
DozeComponent.class,
|
||||
ExpandableNotificationRowComponent.class})
|
||||
public abstract class SystemUIModule {
|
||||
|
||||
|
||||
@@ -51,6 +51,14 @@ public class AlwaysOnDisplayPolicy {
|
||||
static final String KEY_WALLPAPER_VISIBILITY_MS = "wallpaper_visibility_timeout";
|
||||
static final String KEY_WALLPAPER_FADE_OUT_MS = "wallpaper_fade_out_duration";
|
||||
|
||||
|
||||
/**
|
||||
* Integer used to dim the screen while dozing.
|
||||
*
|
||||
* @see R.integer.config_screenBrightnessDoze
|
||||
*/
|
||||
public int defaultDozeBrightness;
|
||||
|
||||
/**
|
||||
* Integer array to map ambient brightness type to real screen brightness.
|
||||
*
|
||||
@@ -165,6 +173,8 @@ public class AlwaysOnDisplayPolicy {
|
||||
DEFAULT_WALLPAPER_FADE_OUT_MS);
|
||||
wallpaperVisibilityDuration = mParser.getLong(KEY_WALLPAPER_VISIBILITY_MS,
|
||||
DEFAULT_WALLPAPER_VISIBILITY_MS);
|
||||
defaultDozeBrightness = resources.getInteger(
|
||||
com.android.internal.R.integer.config_screenBrightnessDoze);
|
||||
screenBrightnessArray = mParser.getIntArray(KEY_SCREEN_BRIGHTNESS_ARRAY,
|
||||
resources.getIntArray(
|
||||
R.array.config_doze_brightness_sensor_to_brightness));
|
||||
|
||||
@@ -16,20 +16,22 @@
|
||||
|
||||
package com.android.systemui.doze;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.keyguard.KeyguardUpdateMonitor;
|
||||
import com.android.systemui.Dependency;
|
||||
import com.android.systemui.doze.dagger.DozeScope;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* Controls removing Keyguard authorization when the phone goes to sleep.
|
||||
*/
|
||||
@DozeScope
|
||||
public class DozeAuthRemover implements DozeMachine.Part {
|
||||
|
||||
private final KeyguardUpdateMonitor mKeyguardUpdateMonitor;
|
||||
|
||||
public DozeAuthRemover(Context context) {
|
||||
mKeyguardUpdateMonitor = Dependency.get(KeyguardUpdateMonitor.class);
|
||||
@Inject
|
||||
public DozeAuthRemover(KeyguardUpdateMonitor keyguardUpdateMonitor) {
|
||||
mKeyguardUpdateMonitor = keyguardUpdateMonitor;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -22,32 +22,40 @@ import android.util.Log;
|
||||
|
||||
import com.android.systemui.dock.DockManager;
|
||||
import com.android.systemui.doze.DozeMachine.State;
|
||||
import com.android.systemui.doze.dagger.DozeScope;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* Handles dock events for ambient state changes.
|
||||
*/
|
||||
@DozeScope
|
||||
public class DozeDockHandler implements DozeMachine.Part {
|
||||
|
||||
private static final String TAG = "DozeDockHandler";
|
||||
private static final boolean DEBUG = DozeService.DEBUG;
|
||||
|
||||
private final AmbientDisplayConfiguration mConfig;
|
||||
private final DozeMachine mMachine;
|
||||
private DozeMachine mMachine;
|
||||
private final DockManager mDockManager;
|
||||
private final DockEventListener mDockEventListener;
|
||||
|
||||
private int mDockState = DockManager.STATE_NONE;
|
||||
|
||||
DozeDockHandler(AmbientDisplayConfiguration config, DozeMachine machine,
|
||||
DockManager dockManager) {
|
||||
mMachine = machine;
|
||||
@Inject
|
||||
DozeDockHandler(AmbientDisplayConfiguration config, DockManager dockManager) {
|
||||
mConfig = config;
|
||||
mDockManager = dockManager;
|
||||
mDockEventListener = new DockEventListener();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDozeMachine(DozeMachine dozeMachine) {
|
||||
mMachine = dozeMachine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transitionTo(DozeMachine.State oldState, DozeMachine.State newState) {
|
||||
switch (newState) {
|
||||
|
||||
@@ -1,157 +0,0 @@
|
||||
/*
|
||||
* 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.systemui.doze;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.app.AlarmManager;
|
||||
import android.app.IWallpaperManager;
|
||||
import android.content.Context;
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorManager;
|
||||
import android.hardware.display.AmbientDisplayConfiguration;
|
||||
import android.os.Handler;
|
||||
|
||||
import com.android.keyguard.KeyguardUpdateMonitor;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.broadcast.BroadcastDispatcher;
|
||||
import com.android.systemui.dagger.qualifiers.Main;
|
||||
import com.android.systemui.dock.DockManager;
|
||||
import com.android.systemui.keyguard.WakefulnessLifecycle;
|
||||
import com.android.systemui.plugins.FalsingManager;
|
||||
import com.android.systemui.statusbar.phone.BiometricUnlockController;
|
||||
import com.android.systemui.statusbar.phone.DozeParameters;
|
||||
import com.android.systemui.statusbar.policy.BatteryController;
|
||||
import com.android.systemui.util.sensors.AsyncSensorManager;
|
||||
import com.android.systemui.util.sensors.ProximitySensor;
|
||||
import com.android.systemui.util.wakelock.DelayedWakeLock;
|
||||
import com.android.systemui.util.wakelock.WakeLock;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class DozeFactory {
|
||||
|
||||
private final FalsingManager mFalsingManager;
|
||||
private final DozeLog mDozeLog;
|
||||
private final DozeParameters mDozeParameters;
|
||||
private final BatteryController mBatteryController;
|
||||
private final AsyncSensorManager mAsyncSensorManager;
|
||||
private final AlarmManager mAlarmManager;
|
||||
private final WakefulnessLifecycle mWakefulnessLifecycle;
|
||||
private final KeyguardUpdateMonitor mKeyguardUpdateMonitor;
|
||||
private final DockManager mDockManager;
|
||||
private final IWallpaperManager mWallpaperManager;
|
||||
private final ProximitySensor mProximitySensor;
|
||||
private final ProximitySensor.ProximityCheck mProximityCheck;
|
||||
private final DelayedWakeLock.Builder mDelayedWakeLockBuilder;
|
||||
private final Handler mHandler;
|
||||
private final BiometricUnlockController mBiometricUnlockController;
|
||||
private final BroadcastDispatcher mBroadcastDispatcher;
|
||||
private final DozeHost mDozeHost;
|
||||
|
||||
@Inject
|
||||
public DozeFactory(FalsingManager falsingManager, DozeLog dozeLog,
|
||||
DozeParameters dozeParameters, BatteryController batteryController,
|
||||
AsyncSensorManager asyncSensorManager, AlarmManager alarmManager,
|
||||
WakefulnessLifecycle wakefulnessLifecycle, KeyguardUpdateMonitor keyguardUpdateMonitor,
|
||||
DockManager dockManager, @Nullable IWallpaperManager wallpaperManager,
|
||||
ProximitySensor proximitySensor, ProximitySensor.ProximityCheck proximityCheck,
|
||||
DelayedWakeLock.Builder delayedWakeLockBuilder, @Main Handler handler,
|
||||
BiometricUnlockController biometricUnlockController,
|
||||
BroadcastDispatcher broadcastDispatcher, DozeHost dozeHost) {
|
||||
mFalsingManager = falsingManager;
|
||||
mDozeLog = dozeLog;
|
||||
mDozeParameters = dozeParameters;
|
||||
mBatteryController = batteryController;
|
||||
mAsyncSensorManager = asyncSensorManager;
|
||||
mAlarmManager = alarmManager;
|
||||
mWakefulnessLifecycle = wakefulnessLifecycle;
|
||||
mKeyguardUpdateMonitor = keyguardUpdateMonitor;
|
||||
mDockManager = dockManager;
|
||||
mWallpaperManager = wallpaperManager;
|
||||
mProximitySensor = proximitySensor;
|
||||
mProximityCheck = proximityCheck;
|
||||
mDelayedWakeLockBuilder = delayedWakeLockBuilder;
|
||||
mHandler = handler;
|
||||
mBiometricUnlockController = biometricUnlockController;
|
||||
mBroadcastDispatcher = broadcastDispatcher;
|
||||
mDozeHost = dozeHost;
|
||||
}
|
||||
|
||||
/** Creates a DozeMachine with its parts for {@code dozeService}. */
|
||||
DozeMachine assembleMachine(DozeService dozeService) {
|
||||
AmbientDisplayConfiguration config = new AmbientDisplayConfiguration(dozeService);
|
||||
WakeLock wakeLock = mDelayedWakeLockBuilder.setHandler(mHandler).setTag("Doze").build();
|
||||
|
||||
DozeMachine.Service wrappedService = dozeService;
|
||||
wrappedService = new DozeBrightnessHostForwarder(wrappedService, mDozeHost);
|
||||
wrappedService = DozeScreenStatePreventingAdapter.wrapIfNeeded(
|
||||
wrappedService, mDozeParameters);
|
||||
wrappedService = DozeSuspendScreenStatePreventingAdapter.wrapIfNeeded(
|
||||
wrappedService, mDozeParameters);
|
||||
|
||||
DozeMachine machine = new DozeMachine(wrappedService, config, wakeLock,
|
||||
mWakefulnessLifecycle, mBatteryController, mDozeLog, mDockManager,
|
||||
mDozeHost);
|
||||
machine.setParts(new DozeMachine.Part[]{
|
||||
new DozePauser(mHandler, machine, mAlarmManager, mDozeParameters.getPolicy()),
|
||||
new DozeFalsingManagerAdapter(mFalsingManager),
|
||||
createDozeTriggers(dozeService, mAsyncSensorManager, mDozeHost,
|
||||
mAlarmManager, config, mDozeParameters, wakeLock,
|
||||
machine, mDockManager, mDozeLog, mProximityCheck),
|
||||
createDozeUi(dozeService, mDozeHost, wakeLock, machine, mHandler,
|
||||
mAlarmManager, mDozeParameters, mDozeLog),
|
||||
new DozeScreenState(wrappedService, mHandler, mDozeHost, mDozeParameters,
|
||||
wakeLock),
|
||||
createDozeScreenBrightness(dozeService, wrappedService, mAsyncSensorManager,
|
||||
mDozeHost, mDozeParameters, mHandler),
|
||||
new DozeWallpaperState(mWallpaperManager, mBiometricUnlockController,
|
||||
mDozeParameters),
|
||||
new DozeDockHandler(config, machine, mDockManager),
|
||||
new DozeAuthRemover(dozeService)
|
||||
});
|
||||
|
||||
return machine;
|
||||
}
|
||||
|
||||
private DozeMachine.Part createDozeScreenBrightness(Context context,
|
||||
DozeMachine.Service service, SensorManager sensorManager, DozeHost host,
|
||||
DozeParameters params, Handler handler) {
|
||||
Sensor sensor = DozeSensors.findSensorWithType(sensorManager,
|
||||
context.getString(R.string.doze_brightness_sensor_type));
|
||||
return new DozeScreenBrightness(context, service, sensorManager, sensor,
|
||||
mBroadcastDispatcher, host, handler, params.getPolicy());
|
||||
}
|
||||
|
||||
private DozeTriggers createDozeTriggers(Context context, AsyncSensorManager sensorManager,
|
||||
DozeHost host, AlarmManager alarmManager, AmbientDisplayConfiguration config,
|
||||
DozeParameters params, WakeLock wakeLock,
|
||||
DozeMachine machine, DockManager dockManager, DozeLog dozeLog,
|
||||
ProximitySensor.ProximityCheck proximityCheck) {
|
||||
boolean allowPulseTriggers = true;
|
||||
return new DozeTriggers(context, machine, host, alarmManager, config, params,
|
||||
sensorManager, wakeLock, allowPulseTriggers, dockManager,
|
||||
mProximitySensor, proximityCheck, dozeLog, mBroadcastDispatcher);
|
||||
|
||||
}
|
||||
|
||||
private DozeMachine.Part createDozeUi(Context context, DozeHost host, WakeLock wakeLock,
|
||||
DozeMachine machine, Handler handler, AlarmManager alarmManager,
|
||||
DozeParameters params, DozeLog dozeLog) {
|
||||
return new DozeUi(context, alarmManager, machine, wakeLock, host, handler, params,
|
||||
mKeyguardUpdateMonitor, dozeLog);
|
||||
}
|
||||
}
|
||||
@@ -16,15 +16,20 @@
|
||||
|
||||
package com.android.systemui.doze;
|
||||
|
||||
import com.android.systemui.doze.dagger.DozeScope;
|
||||
import com.android.systemui.plugins.FalsingManager;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* Notifies FalsingManager of whether or not AOD is showing.
|
||||
*/
|
||||
@DozeScope
|
||||
public class DozeFalsingManagerAdapter implements DozeMachine.Part {
|
||||
|
||||
private final FalsingManager mFalsingManager;
|
||||
|
||||
@Inject
|
||||
public DozeFalsingManagerAdapter(FalsingManager falsingManager) {
|
||||
mFalsingManager = falsingManager;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,8 @@ import android.view.Display;
|
||||
|
||||
import com.android.internal.util.Preconditions;
|
||||
import com.android.systemui.dock.DockManager;
|
||||
import com.android.systemui.doze.dagger.DozeScope;
|
||||
import com.android.systemui.doze.dagger.WrappedService;
|
||||
import com.android.systemui.keyguard.WakefulnessLifecycle;
|
||||
import com.android.systemui.keyguard.WakefulnessLifecycle.Wakefulness;
|
||||
import com.android.systemui.statusbar.phone.DozeParameters;
|
||||
@@ -38,6 +40,8 @@ import com.android.systemui.util.wakelock.WakeLock;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* Orchestrates all things doze.
|
||||
*
|
||||
@@ -46,6 +50,7 @@ import java.util.ArrayList;
|
||||
*
|
||||
* During state transitions and in certain states, DozeMachine holds a wake lock.
|
||||
*/
|
||||
@DozeScope
|
||||
public class DozeMachine {
|
||||
|
||||
static final String TAG = "DozeMachine";
|
||||
@@ -146,9 +151,11 @@ public class DozeMachine {
|
||||
private boolean mWakeLockHeldForCurrentState = false;
|
||||
private DockManager mDockManager;
|
||||
|
||||
public DozeMachine(Service service, AmbientDisplayConfiguration config, WakeLock wakeLock,
|
||||
WakefulnessLifecycle wakefulnessLifecycle, BatteryController batteryController,
|
||||
DozeLog dozeLog, DockManager dockManager, DozeHost dozeHost) {
|
||||
@Inject
|
||||
public DozeMachine(@WrappedService Service service, AmbientDisplayConfiguration config,
|
||||
WakeLock wakeLock, WakefulnessLifecycle wakefulnessLifecycle,
|
||||
BatteryController batteryController, DozeLog dozeLog, DockManager dockManager,
|
||||
DozeHost dozeHost, Part[] parts) {
|
||||
mDozeService = service;
|
||||
mConfig = config;
|
||||
mWakefulnessLifecycle = wakefulnessLifecycle;
|
||||
@@ -157,6 +164,10 @@ public class DozeMachine {
|
||||
mDozeLog = dozeLog;
|
||||
mDockManager = dockManager;
|
||||
mDozeHost = dozeHost;
|
||||
mParts = parts;
|
||||
for (Part part : parts) {
|
||||
part.setDozeMachine(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -168,12 +179,6 @@ public class DozeMachine {
|
||||
}
|
||||
}
|
||||
|
||||
/** Initializes the set of {@link Part}s. Must be called exactly once after construction. */
|
||||
public void setParts(Part[] parts) {
|
||||
Preconditions.checkState(mParts == null);
|
||||
mParts = parts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests transitioning to {@code requestedState}.
|
||||
*
|
||||
@@ -432,6 +437,9 @@ public class DozeMachine {
|
||||
|
||||
/** Alerts that the screenstate is being changed. */
|
||||
default void onScreenState(int state) {}
|
||||
|
||||
/** Sets the {@link DozeMachine} when this Part is associated with one. */
|
||||
default void setDozeMachine(DozeMachine dozeMachine) {}
|
||||
}
|
||||
|
||||
/** A wrapper interface for {@link android.service.dreams.DreamService} */
|
||||
|
||||
@@ -19,24 +19,34 @@ package com.android.systemui.doze;
|
||||
import android.app.AlarmManager;
|
||||
import android.os.Handler;
|
||||
|
||||
import com.android.systemui.dagger.qualifiers.Main;
|
||||
import com.android.systemui.doze.dagger.DozeScope;
|
||||
import com.android.systemui.util.AlarmTimeout;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* Moves the doze machine from the pausing to the paused state after a timeout.
|
||||
*/
|
||||
@DozeScope
|
||||
public class DozePauser implements DozeMachine.Part {
|
||||
public static final String TAG = DozePauser.class.getSimpleName();
|
||||
private final AlarmTimeout mPauseTimeout;
|
||||
private final DozeMachine mMachine;
|
||||
private DozeMachine mMachine;
|
||||
private final AlwaysOnDisplayPolicy mPolicy;
|
||||
|
||||
public DozePauser(Handler handler, DozeMachine machine, AlarmManager alarmManager,
|
||||
@Inject
|
||||
public DozePauser(@Main Handler handler, AlarmManager alarmManager,
|
||||
AlwaysOnDisplayPolicy policy) {
|
||||
mMachine = machine;
|
||||
mPauseTimeout = new AlarmTimeout(alarmManager, this::onTimeout, TAG, handler);
|
||||
mPolicy = policy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDozeMachine(DozeMachine dozeMachine) {
|
||||
mMachine = dozeMachine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transitionTo(DozeMachine.State oldState, DozeMachine.State newState) {
|
||||
switch (newState) {
|
||||
|
||||
@@ -19,7 +19,6 @@ package com.android.systemui.doze;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorEvent;
|
||||
import android.hardware.SensorEventListener;
|
||||
@@ -31,12 +30,17 @@ import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.view.Display;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.systemui.broadcast.BroadcastDispatcher;
|
||||
import com.android.systemui.doze.dagger.BrightnessSensor;
|
||||
import com.android.systemui.doze.dagger.DozeScope;
|
||||
import com.android.systemui.doze.dagger.WrappedService;
|
||||
import com.android.systemui.util.sensors.AsyncSensorManager;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* Controls the screen brightness when dozing.
|
||||
*/
|
||||
@DozeScope
|
||||
public class DozeScreenBrightness extends BroadcastReceiver implements DozeMachine.Part,
|
||||
SensorEventListener {
|
||||
private static final boolean DEBUG_AOD_BRIGHTNESS = SystemProperties
|
||||
@@ -51,10 +55,8 @@ public class DozeScreenBrightness extends BroadcastReceiver implements DozeMachi
|
||||
private final Handler mHandler;
|
||||
private final SensorManager mSensorManager;
|
||||
private final Sensor mLightSensor;
|
||||
private final BroadcastDispatcher mBroadcastDispatcher;
|
||||
private final int[] mSensorToBrightness;
|
||||
private final int[] mSensorToScrimOpacity;
|
||||
private final boolean mDebuggable;
|
||||
|
||||
private boolean mRegistered;
|
||||
private int mDefaultDozeBrightness;
|
||||
@@ -71,40 +73,20 @@ public class DozeScreenBrightness extends BroadcastReceiver implements DozeMachi
|
||||
private int mDebugBrightnessBucket = -1;
|
||||
private DozeMachine.State mState;
|
||||
|
||||
@VisibleForTesting
|
||||
public DozeScreenBrightness(Context context, DozeMachine.Service service,
|
||||
SensorManager sensorManager, Sensor lightSensor,
|
||||
BroadcastDispatcher broadcastDispatcher, DozeHost host,
|
||||
Handler handler, int defaultDozeBrightness, int[] sensorToBrightness,
|
||||
int[] sensorToScrimOpacity, boolean debuggable) {
|
||||
@Inject
|
||||
public DozeScreenBrightness(Context context, @WrappedService DozeMachine.Service service,
|
||||
AsyncSensorManager sensorManager, @BrightnessSensor Sensor lightSensor,
|
||||
DozeHost host, Handler handler, AlwaysOnDisplayPolicy alwaysOnDisplayPolicy) {
|
||||
mContext = context;
|
||||
mDozeService = service;
|
||||
mSensorManager = sensorManager;
|
||||
mLightSensor = lightSensor;
|
||||
mBroadcastDispatcher = broadcastDispatcher;
|
||||
mDozeHost = host;
|
||||
mHandler = handler;
|
||||
mDebuggable = debuggable;
|
||||
|
||||
mDefaultDozeBrightness = defaultDozeBrightness;
|
||||
mSensorToBrightness = sensorToBrightness;
|
||||
mSensorToScrimOpacity = sensorToScrimOpacity;
|
||||
|
||||
if (mDebuggable) {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(ACTION_AOD_BRIGHTNESS);
|
||||
mBroadcastDispatcher.registerReceiverWithHandler(this, filter, handler, UserHandle.ALL);
|
||||
}
|
||||
}
|
||||
|
||||
public DozeScreenBrightness(Context context, DozeMachine.Service service,
|
||||
SensorManager sensorManager, Sensor lightSensor,
|
||||
BroadcastDispatcher broadcastDispatcher, DozeHost host, Handler handler,
|
||||
AlwaysOnDisplayPolicy policy) {
|
||||
this(context, service, sensorManager, lightSensor, broadcastDispatcher, host, handler,
|
||||
context.getResources().getInteger(
|
||||
com.android.internal.R.integer.config_screenBrightnessDoze),
|
||||
policy.screenBrightnessArray, policy.dimmingScrimArray, DEBUG_AOD_BRIGHTNESS);
|
||||
mDefaultDozeBrightness = alwaysOnDisplayPolicy.defaultDozeBrightness;
|
||||
mSensorToBrightness = alwaysOnDisplayPolicy.screenBrightnessArray;
|
||||
mSensorToScrimOpacity = alwaysOnDisplayPolicy.dimmingScrimArray;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -139,9 +121,6 @@ public class DozeScreenBrightness extends BroadcastReceiver implements DozeMachi
|
||||
|
||||
private void onDestroy() {
|
||||
setLightSensorEnabled(false);
|
||||
if (mDebuggable) {
|
||||
mBroadcastDispatcher.unregisterReceiver(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -26,13 +26,19 @@ import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.view.Display;
|
||||
|
||||
import com.android.systemui.dagger.qualifiers.Main;
|
||||
import com.android.systemui.doze.dagger.DozeScope;
|
||||
import com.android.systemui.doze.dagger.WrappedService;
|
||||
import com.android.systemui.statusbar.phone.DozeParameters;
|
||||
import com.android.systemui.util.wakelock.SettableWakeLock;
|
||||
import com.android.systemui.util.wakelock.WakeLock;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* Controls the screen when dozing.
|
||||
*/
|
||||
@DozeScope
|
||||
public class DozeScreenState implements DozeMachine.Part {
|
||||
|
||||
private static final boolean DEBUG = DozeService.DEBUG;
|
||||
@@ -59,8 +65,9 @@ public class DozeScreenState implements DozeMachine.Part {
|
||||
private int mPendingScreenState = Display.STATE_UNKNOWN;
|
||||
private SettableWakeLock mWakeLock;
|
||||
|
||||
public DozeScreenState(DozeMachine.Service service, Handler handler, DozeHost host,
|
||||
DozeParameters parameters, WakeLock wakeLock) {
|
||||
@Inject
|
||||
public DozeScreenState(@WrappedService DozeMachine.Service service, @Main Handler handler,
|
||||
DozeHost host, DozeParameters parameters, WakeLock wakeLock) {
|
||||
mDozeService = service;
|
||||
mHandler = handler;
|
||||
mParameters = parameters;
|
||||
|
||||
@@ -21,7 +21,6 @@ import static com.android.systemui.plugins.SensorManagerPlugin.Sensor.TYPE_WAKE_
|
||||
|
||||
import android.annotation.AnyThread;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.AlarmManager;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.database.ContentObserver;
|
||||
@@ -64,10 +63,8 @@ public class DozeSensors {
|
||||
private static final UiEventLogger UI_EVENT_LOGGER = new UiEventLoggerImpl();
|
||||
|
||||
private final Context mContext;
|
||||
private final AlarmManager mAlarmManager;
|
||||
private final AsyncSensorManager mSensorManager;
|
||||
private final ContentResolver mResolver;
|
||||
private final DozeParameters mDozeParameters;
|
||||
private final AmbientDisplayConfiguration mConfig;
|
||||
private final WakeLock mWakeLock;
|
||||
private final Consumer<Boolean> mProxCallback;
|
||||
@@ -98,14 +95,12 @@ public class DozeSensors {
|
||||
}
|
||||
}
|
||||
|
||||
public DozeSensors(Context context, AlarmManager alarmManager, AsyncSensorManager sensorManager,
|
||||
DozeSensors(Context context, AsyncSensorManager sensorManager,
|
||||
DozeParameters dozeParameters, AmbientDisplayConfiguration config, WakeLock wakeLock,
|
||||
Callback callback, Consumer<Boolean> proxCallback, DozeLog dozeLog,
|
||||
ProximitySensor proximitySensor) {
|
||||
mContext = context;
|
||||
mAlarmManager = alarmManager;
|
||||
mSensorManager = sensorManager;
|
||||
mDozeParameters = dozeParameters;
|
||||
mConfig = config;
|
||||
mWakeLock = wakeLock;
|
||||
mProxCallback = proxCallback;
|
||||
@@ -206,7 +201,10 @@ public class DozeSensors {
|
||||
return findSensorWithType(mSensorManager, type);
|
||||
}
|
||||
|
||||
static Sensor findSensorWithType(SensorManager sensorManager, String type) {
|
||||
/**
|
||||
* Utility method to find a {@link Sensor} for the supplied string type.
|
||||
*/
|
||||
public static Sensor findSensorWithType(SensorManager sensorManager, String type) {
|
||||
if (TextUtils.isEmpty(type)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.os.SystemClock;
|
||||
import android.service.dreams.DreamService;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.systemui.doze.dagger.DozeComponent;
|
||||
import com.android.systemui.plugins.DozeServicePlugin;
|
||||
import com.android.systemui.plugins.DozeServicePlugin.RequestDoze;
|
||||
import com.android.systemui.plugins.PluginListener;
|
||||
@@ -36,16 +37,16 @@ public class DozeService extends DreamService
|
||||
implements DozeMachine.Service, RequestDoze, PluginListener<DozeServicePlugin> {
|
||||
private static final String TAG = "DozeService";
|
||||
static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
|
||||
private final DozeFactory mDozeFactory;
|
||||
private final DozeComponent.Builder mDozeComponentBuilder;
|
||||
|
||||
private DozeMachine mDozeMachine;
|
||||
private DozeServicePlugin mDozePlugin;
|
||||
private PluginManager mPluginManager;
|
||||
|
||||
@Inject
|
||||
public DozeService(DozeFactory dozeFactory, PluginManager pluginManager) {
|
||||
public DozeService(DozeComponent.Builder dozeComponentBuilder, PluginManager pluginManager) {
|
||||
mDozeComponentBuilder = dozeComponentBuilder;
|
||||
setDebug(DEBUG);
|
||||
mDozeFactory = dozeFactory;
|
||||
mPluginManager = pluginManager;
|
||||
}
|
||||
|
||||
@@ -56,7 +57,8 @@ public class DozeService extends DreamService
|
||||
setWindowless(true);
|
||||
|
||||
mPluginManager.addPluginListener(this, DozeServicePlugin.class, false /* allowMultiple */);
|
||||
mDozeMachine = mDozeFactory.assembleMachine(this);
|
||||
DozeComponent dozeComponent = mDozeComponentBuilder.build(this);
|
||||
mDozeMachine = dozeComponent.getDozeMachine();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -41,6 +41,7 @@ import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.systemui.Dependency;
|
||||
import com.android.systemui.broadcast.BroadcastDispatcher;
|
||||
import com.android.systemui.dock.DockManager;
|
||||
import com.android.systemui.doze.dagger.DozeScope;
|
||||
import com.android.systemui.statusbar.phone.DozeParameters;
|
||||
import com.android.systemui.util.Assert;
|
||||
import com.android.systemui.util.sensors.AsyncSensorManager;
|
||||
@@ -51,9 +52,12 @@ import java.io.PrintWriter;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* Handles triggers for ambient state changes.
|
||||
*/
|
||||
@DozeScope
|
||||
public class DozeTriggers implements DozeMachine.Part {
|
||||
|
||||
private static final String TAG = "DozeTriggers";
|
||||
@@ -73,7 +77,7 @@ public class DozeTriggers implements DozeMachine.Part {
|
||||
private static final int PROXIMITY_TIMEOUT_DELAY_MS = 500;
|
||||
|
||||
private final Context mContext;
|
||||
private final DozeMachine mMachine;
|
||||
private DozeMachine mMachine;
|
||||
private final DozeLog mDozeLog;
|
||||
private final DozeSensors mDozeSensors;
|
||||
private final DozeHost mDozeHost;
|
||||
@@ -153,21 +157,21 @@ public class DozeTriggers implements DozeMachine.Part {
|
||||
}
|
||||
}
|
||||
|
||||
public DozeTriggers(Context context, DozeMachine machine, DozeHost dozeHost,
|
||||
@Inject
|
||||
public DozeTriggers(Context context, DozeHost dozeHost,
|
||||
AlarmManager alarmManager, AmbientDisplayConfiguration config,
|
||||
DozeParameters dozeParameters, AsyncSensorManager sensorManager,
|
||||
WakeLock wakeLock, boolean allowPulseTriggers, DockManager dockManager,
|
||||
WakeLock wakeLock, DockManager dockManager,
|
||||
ProximitySensor proximitySensor, ProximitySensor.ProximityCheck proxCheck,
|
||||
DozeLog dozeLog, BroadcastDispatcher broadcastDispatcher) {
|
||||
mContext = context;
|
||||
mMachine = machine;
|
||||
mDozeHost = dozeHost;
|
||||
mConfig = config;
|
||||
mDozeParameters = dozeParameters;
|
||||
mSensorManager = sensorManager;
|
||||
mWakeLock = wakeLock;
|
||||
mAllowPulseTriggers = allowPulseTriggers;
|
||||
mDozeSensors = new DozeSensors(context, alarmManager, mSensorManager, dozeParameters,
|
||||
mAllowPulseTriggers = true;
|
||||
mDozeSensors = new DozeSensors(context, mSensorManager, dozeParameters,
|
||||
config, wakeLock, this::onSensor, this::onProximityFar, dozeLog, proximitySensor);
|
||||
mUiModeManager = mContext.getSystemService(UiModeManager.class);
|
||||
mDockManager = dockManager;
|
||||
@@ -176,6 +180,11 @@ public class DozeTriggers implements DozeMachine.Part {
|
||||
mBroadcastDispatcher = broadcastDispatcher;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDozeMachine(DozeMachine dozeMachine) {
|
||||
mMachine = dozeMachine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
mDozeSensors.destroy();
|
||||
|
||||
@@ -29,15 +29,20 @@ import android.util.Log;
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.keyguard.KeyguardUpdateMonitor;
|
||||
import com.android.keyguard.KeyguardUpdateMonitorCallback;
|
||||
import com.android.systemui.dagger.qualifiers.Main;
|
||||
import com.android.systemui.doze.dagger.DozeScope;
|
||||
import com.android.systemui.statusbar.phone.DozeParameters;
|
||||
import com.android.systemui.util.AlarmTimeout;
|
||||
import com.android.systemui.util.wakelock.WakeLock;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* The policy controlling doze.
|
||||
*/
|
||||
@DozeScope
|
||||
public class DozeUi implements DozeMachine.Part {
|
||||
|
||||
private static final long TIME_TICK_DEADLINE_MILLIS = 90 * 1000; // 1.5min
|
||||
@@ -45,7 +50,7 @@ public class DozeUi implements DozeMachine.Part {
|
||||
private final DozeHost mHost;
|
||||
private final Handler mHandler;
|
||||
private final WakeLock mWakeLock;
|
||||
private final DozeMachine mMachine;
|
||||
private DozeMachine mMachine;
|
||||
private final AlarmTimeout mTimeTicker;
|
||||
private final boolean mCanAnimateTransition;
|
||||
private final DozeParameters mDozeParameters;
|
||||
@@ -64,12 +69,12 @@ public class DozeUi implements DozeMachine.Part {
|
||||
|
||||
private long mLastTimeTickElapsed = 0;
|
||||
|
||||
public DozeUi(Context context, AlarmManager alarmManager, DozeMachine machine,
|
||||
WakeLock wakeLock, DozeHost host, Handler handler,
|
||||
@Inject
|
||||
public DozeUi(Context context, AlarmManager alarmManager,
|
||||
WakeLock wakeLock, DozeHost host, @Main Handler handler,
|
||||
DozeParameters params, KeyguardUpdateMonitor keyguardUpdateMonitor,
|
||||
DozeLog dozeLog) {
|
||||
mContext = context;
|
||||
mMachine = machine;
|
||||
mWakeLock = wakeLock;
|
||||
mHost = host;
|
||||
mHandler = handler;
|
||||
@@ -80,6 +85,11 @@ public class DozeUi implements DozeMachine.Part {
|
||||
mDozeLog = dozeLog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDozeMachine(DozeMachine dozeMachine) {
|
||||
mMachine = dozeMachine;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decide if we're taking over the screen-off animation
|
||||
* when the device was configured to skip doze after screen off.
|
||||
|
||||
@@ -21,15 +21,19 @@ import android.app.IWallpaperManager;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.systemui.doze.dagger.DozeScope;
|
||||
import com.android.systemui.statusbar.notification.stack.StackStateAnimator;
|
||||
import com.android.systemui.statusbar.phone.BiometricUnlockController;
|
||||
import com.android.systemui.statusbar.phone.DozeParameters;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* Propagates doze state to wallpaper engine.
|
||||
*/
|
||||
@DozeScope
|
||||
public class DozeWallpaperState implements DozeMachine.Part {
|
||||
|
||||
private static final String TAG = "DozeWallpaperState";
|
||||
@@ -41,8 +45,9 @@ public class DozeWallpaperState implements DozeMachine.Part {
|
||||
private final BiometricUnlockController mBiometricUnlockController;
|
||||
private boolean mIsAmbientMode;
|
||||
|
||||
@Inject
|
||||
public DozeWallpaperState(
|
||||
IWallpaperManager wallpaperManagerService,
|
||||
@Nullable IWallpaperManager wallpaperManagerService,
|
||||
BiometricUnlockController biometricUnlockController,
|
||||
DozeParameters parameters) {
|
||||
mWallpaperManagerService = wallpaperManagerService;
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.systemui.doze.dagger;
|
||||
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
|
||||
import javax.inject.Qualifier;
|
||||
|
||||
@Qualifier
|
||||
@Documented
|
||||
@Retention(RUNTIME)
|
||||
public @interface BrightnessSensor {
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.systemui.doze.dagger;
|
||||
|
||||
import com.android.systemui.doze.DozeMachine;
|
||||
import com.android.systemui.doze.DozeService;
|
||||
|
||||
import dagger.BindsInstance;
|
||||
import dagger.Subcomponent;
|
||||
|
||||
/**
|
||||
* Dagger component for items that require a {@link DozeService}.
|
||||
*/
|
||||
@Subcomponent(modules = {DozeModule.class})
|
||||
@DozeScope
|
||||
public interface DozeComponent {
|
||||
/** Simple Builder for {@link DozeComponent}. */
|
||||
@Subcomponent.Factory
|
||||
interface Builder {
|
||||
DozeComponent build(@BindsInstance DozeService dozeService);
|
||||
}
|
||||
|
||||
/** Supply a {@link DozeMachine}. */
|
||||
@DozeScope
|
||||
DozeMachine getDozeMachine();
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.systemui.doze.dagger;
|
||||
|
||||
import android.content.Context;
|
||||
import android.hardware.Sensor;
|
||||
import android.os.Handler;
|
||||
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.dagger.qualifiers.Main;
|
||||
import com.android.systemui.doze.DozeAuthRemover;
|
||||
import com.android.systemui.doze.DozeBrightnessHostForwarder;
|
||||
import com.android.systemui.doze.DozeDockHandler;
|
||||
import com.android.systemui.doze.DozeFalsingManagerAdapter;
|
||||
import com.android.systemui.doze.DozeHost;
|
||||
import com.android.systemui.doze.DozeMachine;
|
||||
import com.android.systemui.doze.DozePauser;
|
||||
import com.android.systemui.doze.DozeScreenBrightness;
|
||||
import com.android.systemui.doze.DozeScreenState;
|
||||
import com.android.systemui.doze.DozeScreenStatePreventingAdapter;
|
||||
import com.android.systemui.doze.DozeSensors;
|
||||
import com.android.systemui.doze.DozeService;
|
||||
import com.android.systemui.doze.DozeSuspendScreenStatePreventingAdapter;
|
||||
import com.android.systemui.doze.DozeTriggers;
|
||||
import com.android.systemui.doze.DozeUi;
|
||||
import com.android.systemui.doze.DozeWallpaperState;
|
||||
import com.android.systemui.statusbar.phone.DozeParameters;
|
||||
import com.android.systemui.util.sensors.AsyncSensorManager;
|
||||
import com.android.systemui.util.wakelock.DelayedWakeLock;
|
||||
import com.android.systemui.util.wakelock.WakeLock;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
/** Dagger module for use with {@link com.android.systemui.doze.dagger.DozeComponent}. */
|
||||
@Module
|
||||
public abstract class DozeModule {
|
||||
@Provides
|
||||
@DozeScope
|
||||
@WrappedService
|
||||
static DozeMachine.Service providesWrappedService(DozeService dozeService, DozeHost dozeHost,
|
||||
DozeParameters dozeParameters) {
|
||||
DozeMachine.Service wrappedService = dozeService;
|
||||
wrappedService = new DozeBrightnessHostForwarder(wrappedService, dozeHost);
|
||||
wrappedService = DozeScreenStatePreventingAdapter.wrapIfNeeded(
|
||||
wrappedService, dozeParameters);
|
||||
wrappedService = DozeSuspendScreenStatePreventingAdapter.wrapIfNeeded(
|
||||
wrappedService, dozeParameters);
|
||||
|
||||
return wrappedService;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@DozeScope
|
||||
static WakeLock providesDozeWakeLock(DelayedWakeLock.Builder delayedWakeLockBuilder,
|
||||
@Main Handler handler) {
|
||||
return delayedWakeLockBuilder.setHandler(handler).setTag("Doze").build();
|
||||
}
|
||||
|
||||
@Provides
|
||||
static DozeMachine.Part[] providesDozeMachinePartes(DozePauser dozePauser,
|
||||
DozeFalsingManagerAdapter dozeFalsingManagerAdapter, DozeTriggers dozeTriggers,
|
||||
DozeUi dozeUi, DozeScreenState dozeScreenState,
|
||||
DozeScreenBrightness dozeScreenBrightness, DozeWallpaperState dozeWallpaperState,
|
||||
DozeDockHandler dozeDockHandler, DozeAuthRemover dozeAuthRemover) {
|
||||
return new DozeMachine.Part[]{
|
||||
dozePauser,
|
||||
dozeFalsingManagerAdapter,
|
||||
dozeTriggers,
|
||||
dozeUi,
|
||||
dozeScreenState,
|
||||
dozeScreenBrightness,
|
||||
dozeWallpaperState,
|
||||
dozeDockHandler,
|
||||
dozeAuthRemover
|
||||
};
|
||||
}
|
||||
|
||||
@Provides
|
||||
@BrightnessSensor
|
||||
static Sensor providesBrightnessSensor(AsyncSensorManager sensorManager, Context context) {
|
||||
return DozeSensors.findSensorWithType(sensorManager,
|
||||
context.getString(R.string.doze_brightness_sensor_type));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.systemui.doze.dagger;
|
||||
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
|
||||
import javax.inject.Scope;
|
||||
|
||||
/**
|
||||
* Scope annotation for singleton items within the StatusBarComponent.
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RUNTIME)
|
||||
@Scope
|
||||
public @interface DozeScope {}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.systemui.doze.dagger;
|
||||
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
|
||||
import javax.inject.Qualifier;
|
||||
|
||||
@Qualifier
|
||||
@Documented
|
||||
@Retention(RUNTIME)
|
||||
public @interface WrappedService {
|
||||
}
|
||||
@@ -211,8 +211,4 @@ public class DozeParameters implements TunerService.Tunable,
|
||||
public void onTuningChanged(String key, String newValue) {
|
||||
mDozeAlwaysOn = mAmbientDisplayConfiguration.alwaysOnEnabled(UserHandle.USER_CURRENT);
|
||||
}
|
||||
|
||||
public AlwaysOnDisplayPolicy getPolicy() {
|
||||
return mAlwaysOnPolicy;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,13 +16,13 @@
|
||||
|
||||
package com.android.systemui.doze;
|
||||
|
||||
import android.hardware.display.AmbientDisplayConfiguration;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.Mockito.withSettings;
|
||||
|
||||
import android.hardware.display.AmbientDisplayConfiguration;
|
||||
|
||||
import com.android.systemui.statusbar.phone.DozeParameters;
|
||||
import com.android.systemui.util.sensors.FakeSensorManager;
|
||||
|
||||
@@ -37,7 +37,6 @@ public class DozeConfigurationUtil {
|
||||
when(params.getPulseOnSigMotion()).thenReturn(false);
|
||||
when(params.getPickupVibrationThreshold()).thenReturn(0);
|
||||
when(params.getProxCheckBeforePulse()).thenReturn(true);
|
||||
when(params.getPolicy()).thenReturn(mock(AlwaysOnDisplayPolicy.class));
|
||||
when(params.doubleTapReportsTouchCoordinates()).thenReturn(false);
|
||||
when(params.getDisplayNeedsBlanking()).thenReturn(false);
|
||||
|
||||
|
||||
@@ -57,7 +57,8 @@ public class DozeDockHandlerTest extends SysuiTestCase {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mConfig = DozeConfigurationUtil.createMockConfig();
|
||||
mDockManagerFake = spy(new DockManagerFake());
|
||||
mDockHandler = new DozeDockHandler(mConfig, mMachine, mDockManagerFake);
|
||||
mDockHandler = new DozeDockHandler(mConfig, mDockManagerFake);
|
||||
mDockHandler.setDozeMachine(mMachine);
|
||||
|
||||
when(mMachine.getState()).thenReturn(State.DOZE_AOD);
|
||||
doReturn(true).when(mConfig).alwaysOnEnabled(anyInt());
|
||||
|
||||
@@ -88,8 +88,7 @@ public class DozeMachineTest extends SysuiTestCase {
|
||||
|
||||
mMachine = new DozeMachine(mServiceFake, mConfigMock, mWakeLockFake,
|
||||
mWakefulnessLifecycle, mock(BatteryController.class), mDozeLog, mDockManager,
|
||||
mHost);
|
||||
mMachine.setParts(new DozeMachine.Part[]{mPartMock});
|
||||
mHost, new DozeMachine.Part[]{mPartMock});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -40,14 +40,17 @@ import android.content.Intent;
|
||||
import android.os.PowerManager;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.view.Display;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
import com.android.systemui.broadcast.BroadcastDispatcher;
|
||||
import com.android.systemui.util.concurrency.FakeExecutor;
|
||||
import com.android.systemui.util.concurrency.FakeThreadFactory;
|
||||
import com.android.systemui.util.sensors.AsyncSensorManager;
|
||||
import com.android.systemui.util.sensors.FakeSensorManager;
|
||||
import com.android.systemui.util.time.FakeSystemClock;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -55,22 +58,24 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@SmallTest
|
||||
@RunWith(AndroidTestingRunner.class)
|
||||
public class DozeScreenBrightnessTest extends SysuiTestCase {
|
||||
|
||||
static final int DEFAULT_BRIGHTNESS = 10;
|
||||
static final int[] SENSOR_TO_BRIGHTNESS = new int[]{-1, 1, 2, 3, 4};
|
||||
static final int[] SENSOR_TO_OPACITY = new int[]{-1, 10, 0, 0, 0};
|
||||
private static final int DEFAULT_BRIGHTNESS = 10;
|
||||
private static final int[] SENSOR_TO_BRIGHTNESS = new int[]{-1, 1, 2, 3, 4};
|
||||
private static final int[] SENSOR_TO_OPACITY = new int[]{-1, 10, 0, 0, 0};
|
||||
|
||||
DozeServiceFake mServiceFake;
|
||||
FakeSensorManager.FakeGenericSensor mSensor;
|
||||
FakeSensorManager mSensorManager;
|
||||
private DozeServiceFake mServiceFake;
|
||||
private FakeSensorManager.FakeGenericSensor mSensor;
|
||||
private AsyncSensorManager mSensorManager;
|
||||
private AlwaysOnDisplayPolicy mAlwaysOnDisplayPolicy;
|
||||
@Mock
|
||||
DozeHost mDozeHost;
|
||||
@Mock
|
||||
BroadcastDispatcher mBroadcastDispatcher;
|
||||
DozeScreenBrightness mScreen;
|
||||
private FakeExecutor mFakeExecutor = new FakeExecutor(new FakeSystemClock());
|
||||
private FakeThreadFactory mFakeThreadFactory = new FakeThreadFactory(mFakeExecutor);
|
||||
|
||||
private DozeScreenBrightness mScreen;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@@ -83,12 +88,17 @@ public class DozeScreenBrightnessTest extends SysuiTestCase {
|
||||
return null;
|
||||
}).when(mDozeHost).prepareForGentleSleep(any());
|
||||
mServiceFake = new DozeServiceFake();
|
||||
mSensorManager = new FakeSensorManager(mContext);
|
||||
mSensor = mSensorManager.getFakeLightSensor();
|
||||
FakeSensorManager fakeSensorManager = new FakeSensorManager(mContext);
|
||||
mSensorManager = new AsyncSensorManager(fakeSensorManager, mFakeThreadFactory, null);
|
||||
|
||||
mAlwaysOnDisplayPolicy = new AlwaysOnDisplayPolicy(mContext);
|
||||
mAlwaysOnDisplayPolicy.defaultDozeBrightness = DEFAULT_BRIGHTNESS;
|
||||
mAlwaysOnDisplayPolicy.screenBrightnessArray = SENSOR_TO_BRIGHTNESS;
|
||||
mAlwaysOnDisplayPolicy.dimmingScrimArray = SENSOR_TO_OPACITY;
|
||||
mSensor = fakeSensorManager.getFakeLightSensor();
|
||||
mScreen = new DozeScreenBrightness(mContext, mServiceFake, mSensorManager,
|
||||
mSensor.getSensor(), mBroadcastDispatcher, mDozeHost, null /* handler */,
|
||||
DEFAULT_BRIGHTNESS, SENSOR_TO_BRIGHTNESS, SENSOR_TO_OPACITY,
|
||||
true /* debuggable */);
|
||||
mSensor.getSensor(), mDozeHost, null /* handler */,
|
||||
mAlwaysOnDisplayPolicy);
|
||||
|
||||
mScreen.onScreenState(Display.STATE_ON);
|
||||
}
|
||||
@@ -106,6 +116,7 @@ public class DozeScreenBrightnessTest extends SysuiTestCase {
|
||||
mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
|
||||
mScreen.transitionTo(INITIALIZED, DOZE_AOD);
|
||||
mScreen.onScreenState(Display.STATE_DOZE);
|
||||
waitForSensorManager();
|
||||
|
||||
mSensor.sendSensorEvent(3);
|
||||
|
||||
@@ -116,6 +127,8 @@ public class DozeScreenBrightnessTest extends SysuiTestCase {
|
||||
public void testAod_usesDebugValue() throws Exception {
|
||||
mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
|
||||
mScreen.transitionTo(INITIALIZED, DOZE_AOD);
|
||||
mScreen.onScreenState(Display.STATE_DOZE);
|
||||
waitForSensorManager();
|
||||
|
||||
Intent intent = new Intent(DozeScreenBrightness.ACTION_AOD_BRIGHTNESS);
|
||||
intent.putExtra(DozeScreenBrightness.BRIGHTNESS_BUCKET, 1);
|
||||
@@ -141,6 +154,7 @@ public class DozeScreenBrightnessTest extends SysuiTestCase {
|
||||
mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
|
||||
mScreen.transitionTo(INITIALIZED, DOZE_AOD);
|
||||
mScreen.onScreenState(Display.STATE_DOZE);
|
||||
waitForSensorManager();
|
||||
|
||||
mSensor.sendSensorEvent(1);
|
||||
|
||||
@@ -153,9 +167,8 @@ public class DozeScreenBrightnessTest extends SysuiTestCase {
|
||||
@Test
|
||||
public void testPulsing_withoutLightSensor_setsAoDDimmingScrimTransparent() throws Exception {
|
||||
mScreen = new DozeScreenBrightness(mContext, mServiceFake, mSensorManager,
|
||||
null /* sensor */, mBroadcastDispatcher, mDozeHost, null /* handler */,
|
||||
DEFAULT_BRIGHTNESS, SENSOR_TO_BRIGHTNESS, SENSOR_TO_OPACITY,
|
||||
true /* debuggable */);
|
||||
null /* sensor */, mDozeHost, null /* handler */,
|
||||
mAlwaysOnDisplayPolicy);
|
||||
mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
|
||||
mScreen.transitionTo(INITIALIZED, DOZE);
|
||||
reset(mDozeHost);
|
||||
@@ -174,6 +187,7 @@ public class DozeScreenBrightnessTest extends SysuiTestCase {
|
||||
mScreen.transitionTo(DOZE_PULSING, DOZE_PULSE_DONE);
|
||||
mScreen.transitionTo(DOZE_PULSE_DONE, DOZE);
|
||||
mScreen.onScreenState(Display.STATE_DOZE);
|
||||
waitForSensorManager();
|
||||
|
||||
mSensor.sendSensorEvent(1);
|
||||
|
||||
@@ -183,9 +197,8 @@ public class DozeScreenBrightnessTest extends SysuiTestCase {
|
||||
@Test
|
||||
public void testNullSensor() throws Exception {
|
||||
mScreen = new DozeScreenBrightness(mContext, mServiceFake, mSensorManager,
|
||||
null /* sensor */, mBroadcastDispatcher, mDozeHost, null /* handler */,
|
||||
DEFAULT_BRIGHTNESS, SENSOR_TO_BRIGHTNESS, SENSOR_TO_OPACITY,
|
||||
true /* debuggable */);
|
||||
null /* sensor */, mDozeHost, null /* handler */,
|
||||
mAlwaysOnDisplayPolicy);
|
||||
|
||||
mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
|
||||
mScreen.transitionTo(INITIALIZED, DOZE_AOD);
|
||||
@@ -198,6 +211,7 @@ public class DozeScreenBrightnessTest extends SysuiTestCase {
|
||||
mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
|
||||
mScreen.transitionTo(INITIALIZED, DOZE_AOD);
|
||||
mScreen.transitionTo(DOZE_AOD, FINISH);
|
||||
waitForSensorManager();
|
||||
|
||||
mSensor.sendSensorEvent(1);
|
||||
|
||||
@@ -205,10 +219,11 @@ public class DozeScreenBrightnessTest extends SysuiTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonPositiveBrightness_keepsPreviousBrightnessAndScrim() throws Exception {
|
||||
public void testNonPositiveBrightness_keepsPreviousBrightnessAndScrim() {
|
||||
mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
|
||||
mScreen.transitionTo(INITIALIZED, DOZE_AOD);
|
||||
mScreen.onScreenState(Display.STATE_DOZE);
|
||||
waitForSensorManager();
|
||||
|
||||
mSensor.sendSensorEvent(1);
|
||||
mSensor.sendSensorEvent(0);
|
||||
@@ -222,6 +237,7 @@ public class DozeScreenBrightnessTest extends SysuiTestCase {
|
||||
mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
|
||||
mScreen.transitionTo(INITIALIZED, DOZE_AOD);
|
||||
mScreen.onScreenState(Display.STATE_DOZE);
|
||||
waitForSensorManager();
|
||||
|
||||
mSensor.sendSensorEvent(2);
|
||||
|
||||
@@ -233,6 +249,7 @@ public class DozeScreenBrightnessTest extends SysuiTestCase {
|
||||
reset(mDozeHost);
|
||||
mScreen.transitionTo(DOZE_AOD_PAUSED, DOZE_AOD);
|
||||
mScreen.onScreenState(Display.STATE_DOZE);
|
||||
waitForSensorManager();
|
||||
mSensor.sendSensorEvent(2);
|
||||
verify(mDozeHost).setAodDimmingScrim(eq(0f));
|
||||
}
|
||||
@@ -242,6 +259,7 @@ public class DozeScreenBrightnessTest extends SysuiTestCase {
|
||||
mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
|
||||
mScreen.transitionTo(INITIALIZED, DOZE_AOD);
|
||||
mScreen.onScreenState(Display.STATE_DOZE);
|
||||
waitForSensorManager();
|
||||
|
||||
mSensor.sendSensorEvent(2);
|
||||
mScreen.transitionTo(DOZE_AOD, DOZE_AOD_PAUSING);
|
||||
@@ -251,4 +269,8 @@ public class DozeScreenBrightnessTest extends SysuiTestCase {
|
||||
mScreen.transitionTo(DOZE_AOD_PAUSED, DOZE_AOD);
|
||||
verify(mDozeHost).setAodDimmingScrim(eq(0f));
|
||||
}
|
||||
|
||||
private void waitForSensorManager() {
|
||||
mFakeExecutor.runAllReady();
|
||||
}
|
||||
}
|
||||
@@ -152,7 +152,7 @@ public class DozeSensorsTest extends SysuiTestCase {
|
||||
private class TestableDozeSensors extends DozeSensors {
|
||||
|
||||
TestableDozeSensors() {
|
||||
super(getContext(), mAlarmManager, mSensorManager, mDozeParameters,
|
||||
super(getContext(), mSensorManager, mDozeParameters,
|
||||
mAmbientDisplayConfiguration, mWakeLock, mCallback, mProxCallback, mDozeLog,
|
||||
mProximitySensor);
|
||||
for (TriggerSensor sensor : mSensors) {
|
||||
|
||||
@@ -97,9 +97,10 @@ public class DozeTriggersTest extends SysuiTestCase {
|
||||
thresholdSensor.setLoaded(true);
|
||||
mProximitySensor = new FakeProximitySensor(thresholdSensor, null, mExecutor);
|
||||
|
||||
mTriggers = new DozeTriggers(mContext, mMachine, mHost, mAlarmManager, config, parameters,
|
||||
asyncSensorManager, wakeLock, true, mDockManager, mProximitySensor,
|
||||
mTriggers = new DozeTriggers(mContext, mHost, mAlarmManager, config, parameters,
|
||||
asyncSensorManager, wakeLock, mDockManager, mProximitySensor,
|
||||
mProximityCheck, mock(DozeLog.class), mBroadcastDispatcher);
|
||||
mTriggers.setDozeMachine(mMachine);
|
||||
waitForSensorManager();
|
||||
}
|
||||
|
||||
|
||||
@@ -81,8 +81,9 @@ public class DozeUiTest extends SysuiTestCase {
|
||||
mWakeLock = new WakeLockFake();
|
||||
mHandler = mHandlerThread.getThreadHandler();
|
||||
|
||||
mDozeUi = new DozeUi(mContext, mAlarmManager, mMachine, mWakeLock, mHost, mHandler,
|
||||
mDozeUi = new DozeUi(mContext, mAlarmManager, mWakeLock, mHost, mHandler,
|
||||
mDozeParameters, mKeyguardUpdateMonitor, mDozeLog);
|
||||
mDozeUi.setDozeMachine(mMachine);
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -136,8 +137,9 @@ public class DozeUiTest extends SysuiTestCase {
|
||||
reset(mDozeParameters);
|
||||
reset(mHost);
|
||||
when(mDozeParameters.getDisplayNeedsBlanking()).thenReturn(true);
|
||||
mDozeUi = new DozeUi(mContext, mAlarmManager, mMachine, mWakeLock, mHost, mHandler,
|
||||
mDozeUi = new DozeUi(mContext, mAlarmManager, mWakeLock, mHost, mHandler,
|
||||
mDozeParameters, mKeyguardUpdateMonitor, mDozeLog);
|
||||
mDozeUi.setDozeMachine(mMachine);
|
||||
|
||||
// Never animate if display doesn't support it.
|
||||
mDozeUi.getKeyguardCallback().onKeyguardVisibilityChanged(true);
|
||||
|
||||
Reference in New Issue
Block a user