Merge "Replace screen broadcast receivers with binder cb" into tm-qpr-dev am: 1797647903

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/20191482

Change-Id: I3d4d3b1d89127620f22685d5c84a8c1dbf47d935
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
TreeHugger Robot
2022-10-15 02:21:38 +00:00
committed by Automerger Merge Worker
4 changed files with 55 additions and 25 deletions

View File

@@ -114,6 +114,7 @@ import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.dagger.qualifiers.Background; import com.android.systemui.dagger.qualifiers.Background;
import com.android.systemui.dagger.qualifiers.DisplayId; import com.android.systemui.dagger.qualifiers.DisplayId;
import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.keyguard.WakefulnessLifecycle;
import com.android.systemui.model.SysUiState; import com.android.systemui.model.SysUiState;
import com.android.systemui.navigationbar.NavigationBarComponent.NavigationBarScope; import com.android.systemui.navigationbar.NavigationBarComponent.NavigationBarScope;
import com.android.systemui.navigationbar.NavigationModeController.ModeChangedListener; import com.android.systemui.navigationbar.NavigationModeController.ModeChangedListener;
@@ -211,6 +212,7 @@ public class NavigationBar extends ViewController<NavigationBarView> implements
private final NotificationShadeDepthController mNotificationShadeDepthController; private final NotificationShadeDepthController mNotificationShadeDepthController;
private final OnComputeInternalInsetsListener mOnComputeInternalInsetsListener; private final OnComputeInternalInsetsListener mOnComputeInternalInsetsListener;
private final UserContextProvider mUserContextProvider; private final UserContextProvider mUserContextProvider;
private final WakefulnessLifecycle mWakefulnessLifecycle;
private final RegionSamplingHelper mRegionSamplingHelper; private final RegionSamplingHelper mRegionSamplingHelper;
private final int mNavColorSampleMargin; private final int mNavColorSampleMargin;
private NavigationBarFrame mFrame; private NavigationBarFrame mFrame;
@@ -451,6 +453,28 @@ public class NavigationBar extends ViewController<NavigationBarView> implements
} }
}; };
private final WakefulnessLifecycle.Observer mWakefulnessObserver =
new WakefulnessLifecycle.Observer() {
private void notifyScreenStateChanged(boolean isScreenOn) {
notifyNavigationBarScreenOn();
mView.onScreenStateChanged(isScreenOn);
}
@Override
public void onStartedWakingUp() {
notifyScreenStateChanged(true);
if (isGesturalModeOnDefaultDisplay(getContext(), mNavBarMode)) {
mRegionSamplingHelper.start(mSamplingBounds);
}
}
@Override
public void onFinishedGoingToSleep() {
notifyScreenStateChanged(false);
mRegionSamplingHelper.stop();
}
};
@Inject @Inject
NavigationBar( NavigationBar(
NavigationBarView navigationBarView, NavigationBarView navigationBarView,
@@ -491,7 +515,8 @@ public class NavigationBar extends ViewController<NavigationBarView> implements
NavigationBarTransitions navigationBarTransitions, NavigationBarTransitions navigationBarTransitions,
EdgeBackGestureHandler edgeBackGestureHandler, EdgeBackGestureHandler edgeBackGestureHandler,
Optional<BackAnimation> backAnimation, Optional<BackAnimation> backAnimation,
UserContextProvider userContextProvider) { UserContextProvider userContextProvider,
WakefulnessLifecycle wakefulnessLifecycle) {
super(navigationBarView); super(navigationBarView);
mFrame = navigationBarFrame; mFrame = navigationBarFrame;
mContext = context; mContext = context;
@@ -529,6 +554,7 @@ public class NavigationBar extends ViewController<NavigationBarView> implements
mTelecomManagerOptional = telecomManagerOptional; mTelecomManagerOptional = telecomManagerOptional;
mInputMethodManager = inputMethodManager; mInputMethodManager = inputMethodManager;
mUserContextProvider = userContextProvider; mUserContextProvider = userContextProvider;
mWakefulnessLifecycle = wakefulnessLifecycle;
mNavColorSampleMargin = getResources() mNavColorSampleMargin = getResources()
.getDimensionPixelSize(R.dimen.navigation_handle_sample_horizontal_margin); .getDimensionPixelSize(R.dimen.navigation_handle_sample_horizontal_margin);
@@ -682,11 +708,10 @@ public class NavigationBar extends ViewController<NavigationBarView> implements
prepareNavigationBarView(); prepareNavigationBarView();
checkNavBarModes(); checkNavBarModes();
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF); IntentFilter filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
filter.addAction(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_USER_SWITCHED);
mBroadcastDispatcher.registerReceiverWithHandler(mBroadcastReceiver, filter, mBroadcastDispatcher.registerReceiverWithHandler(mBroadcastReceiver, filter,
Handler.getMain(), UserHandle.ALL); Handler.getMain(), UserHandle.ALL);
mWakefulnessLifecycle.addObserver(mWakefulnessObserver);
notifyNavigationBarScreenOn(); notifyNavigationBarScreenOn();
mOverviewProxyService.addCallback(mOverviewProxyListener); mOverviewProxyService.addCallback(mOverviewProxyListener);
@@ -737,6 +762,7 @@ public class NavigationBar extends ViewController<NavigationBarView> implements
getBarTransitions().destroy(); getBarTransitions().destroy();
mOverviewProxyService.removeCallback(mOverviewProxyListener); mOverviewProxyService.removeCallback(mOverviewProxyListener);
mBroadcastDispatcher.unregisterReceiver(mBroadcastReceiver); mBroadcastDispatcher.unregisterReceiver(mBroadcastReceiver);
mWakefulnessLifecycle.removeObserver(mWakefulnessObserver);
if (mOrientationHandle != null) { if (mOrientationHandle != null) {
resetSecondaryHandle(); resetSecondaryHandle();
getBarTransitions().removeDarkIntensityListener(mOrientationHandleIntensityListener); getBarTransitions().removeDarkIntensityListener(mOrientationHandleIntensityListener);
@@ -1619,19 +1645,6 @@ public class NavigationBar extends ViewController<NavigationBarView> implements
return; return;
} }
String action = intent.getAction(); String action = intent.getAction();
if (Intent.ACTION_SCREEN_OFF.equals(action)
|| Intent.ACTION_SCREEN_ON.equals(action)) {
notifyNavigationBarScreenOn();
boolean isScreenOn = Intent.ACTION_SCREEN_ON.equals(action);
mView.onScreenStateChanged(isScreenOn);
if (isScreenOn) {
if (isGesturalModeOnDefaultDisplay(getContext(), mNavBarMode)) {
mRegionSamplingHelper.start(mSamplingBounds);
}
} else {
mRegionSamplingHelper.stop();
}
}
if (Intent.ACTION_USER_SWITCHED.equals(action)) { if (Intent.ACTION_USER_SWITCHED.equals(action)) {
// The accessibility settings may be different for the new user // The accessibility settings may be different for the new user
updateAccessibilityStateFlags(); updateAccessibilityStateFlags();

View File

@@ -46,6 +46,7 @@ import com.android.systemui.CoreStartable;
import com.android.systemui.R; import com.android.systemui.R;
import com.android.systemui.broadcast.BroadcastDispatcher; import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.dagger.SysUISingleton; import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.keyguard.WakefulnessLifecycle;
import com.android.systemui.statusbar.CommandQueue; import com.android.systemui.statusbar.CommandQueue;
import com.android.systemui.statusbar.phone.CentralSurfaces; import com.android.systemui.statusbar.phone.CentralSurfaces;
@@ -78,6 +79,7 @@ public class PowerUI implements CoreStartable, CommandQueue.Callbacks {
private final PowerManager mPowerManager; private final PowerManager mPowerManager;
private final WarningsUI mWarnings; private final WarningsUI mWarnings;
private final WakefulnessLifecycle mWakefulnessLifecycle;
private InattentiveSleepWarningView mOverlayView; private InattentiveSleepWarningView mOverlayView;
private final Configuration mLastConfiguration = new Configuration(); private final Configuration mLastConfiguration = new Configuration();
private int mPlugType = 0; private int mPlugType = 0;
@@ -107,11 +109,24 @@ public class PowerUI implements CoreStartable, CommandQueue.Callbacks {
private final BroadcastDispatcher mBroadcastDispatcher; private final BroadcastDispatcher mBroadcastDispatcher;
private final CommandQueue mCommandQueue; private final CommandQueue mCommandQueue;
private final Lazy<Optional<CentralSurfaces>> mCentralSurfacesOptionalLazy; private final Lazy<Optional<CentralSurfaces>> mCentralSurfacesOptionalLazy;
private final WakefulnessLifecycle.Observer mWakefulnessObserver =
new WakefulnessLifecycle.Observer() {
@Override
public void onStartedWakingUp() {
mScreenOffTime = -1;
}
@Override
public void onFinishedGoingToSleep() {
mScreenOffTime = SystemClock.elapsedRealtime();
}
};
@Inject @Inject
public PowerUI(Context context, BroadcastDispatcher broadcastDispatcher, public PowerUI(Context context, BroadcastDispatcher broadcastDispatcher,
CommandQueue commandQueue, Lazy<Optional<CentralSurfaces>> centralSurfacesOptionalLazy, CommandQueue commandQueue, Lazy<Optional<CentralSurfaces>> centralSurfacesOptionalLazy,
WarningsUI warningsUI, EnhancedEstimates enhancedEstimates, WarningsUI warningsUI, EnhancedEstimates enhancedEstimates,
WakefulnessLifecycle wakefulnessLifecycle,
PowerManager powerManager) { PowerManager powerManager) {
mContext = context; mContext = context;
mBroadcastDispatcher = broadcastDispatcher; mBroadcastDispatcher = broadcastDispatcher;
@@ -120,6 +135,7 @@ public class PowerUI implements CoreStartable, CommandQueue.Callbacks {
mWarnings = warningsUI; mWarnings = warningsUI;
mEnhancedEstimates = enhancedEstimates; mEnhancedEstimates = enhancedEstimates;
mPowerManager = powerManager; mPowerManager = powerManager;
mWakefulnessLifecycle = wakefulnessLifecycle;
} }
public void start() { public void start() {
@@ -138,6 +154,7 @@ public class PowerUI implements CoreStartable, CommandQueue.Callbacks {
false, obs, UserHandle.USER_ALL); false, obs, UserHandle.USER_ALL);
updateBatteryWarningLevels(); updateBatteryWarningLevels();
mReceiver.init(); mReceiver.init();
mWakefulnessLifecycle.addObserver(mWakefulnessObserver);
// Check to see if we need to let the user know that the phone previously shut down due // Check to see if we need to let the user know that the phone previously shut down due
// to the temperature being too high. // to the temperature being too high.
@@ -233,8 +250,6 @@ public class PowerUI implements CoreStartable, CommandQueue.Callbacks {
IntentFilter filter = new IntentFilter(); IntentFilter filter = new IntentFilter();
filter.addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED); filter.addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED);
filter.addAction(Intent.ACTION_BATTERY_CHANGED); filter.addAction(Intent.ACTION_BATTERY_CHANGED);
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_USER_SWITCHED); filter.addAction(Intent.ACTION_USER_SWITCHED);
mBroadcastDispatcher.registerReceiverWithHandler(this, filter, mHandler); mBroadcastDispatcher.registerReceiverWithHandler(this, filter, mHandler);
// Force get initial values. Relying on Sticky behavior until API for getting info. // Force get initial values. Relying on Sticky behavior until API for getting info.
@@ -317,10 +332,6 @@ public class PowerUI implements CoreStartable, CommandQueue.Callbacks {
plugged, bucket); plugged, bucket);
}); });
} else if (Intent.ACTION_SCREEN_OFF.equals(action)) {
mScreenOffTime = SystemClock.elapsedRealtime();
} else if (Intent.ACTION_SCREEN_ON.equals(action)) {
mScreenOffTime = -1;
} else if (Intent.ACTION_USER_SWITCHED.equals(action)) { } else if (Intent.ACTION_USER_SWITCHED.equals(action)) {
mWarnings.userSwitched(); mWarnings.userSwitched();
} else { } else {

View File

@@ -80,6 +80,7 @@ import com.android.systemui.accessibility.SystemActions;
import com.android.systemui.assist.AssistManager; import com.android.systemui.assist.AssistManager;
import com.android.systemui.broadcast.BroadcastDispatcher; import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.dump.DumpManager; import com.android.systemui.dump.DumpManager;
import com.android.systemui.keyguard.WakefulnessLifecycle;
import com.android.systemui.model.SysUiState; import com.android.systemui.model.SysUiState;
import com.android.systemui.navigationbar.buttons.ButtonDispatcher; import com.android.systemui.navigationbar.buttons.ButtonDispatcher;
import com.android.systemui.navigationbar.buttons.DeadZone; import com.android.systemui.navigationbar.buttons.DeadZone;
@@ -197,6 +198,8 @@ public class NavigationBarTest extends SysuiTestCase {
@Mock @Mock
private UserContextProvider mUserContextProvider; private UserContextProvider mUserContextProvider;
@Mock @Mock
private WakefulnessLifecycle mWakefulnessLifecycle;
@Mock
private Resources mResources; private Resources mResources;
private FakeExecutor mFakeExecutor = new FakeExecutor(new FakeSystemClock()); private FakeExecutor mFakeExecutor = new FakeExecutor(new FakeSystemClock());
private DeviceConfigProxyFake mDeviceConfigProxyFake = new DeviceConfigProxyFake(); private DeviceConfigProxyFake mDeviceConfigProxyFake = new DeviceConfigProxyFake();
@@ -474,7 +477,8 @@ public class NavigationBarTest extends SysuiTestCase {
mNavigationBarTransitions, mNavigationBarTransitions,
mEdgeBackGestureHandler, mEdgeBackGestureHandler,
Optional.of(mock(BackAnimation.class)), Optional.of(mock(BackAnimation.class)),
mUserContextProvider)); mUserContextProvider,
mWakefulnessLifecycle));
} }
private void processAllMessages() { private void processAllMessages() {

View File

@@ -46,6 +46,7 @@ import com.android.settingslib.fuelgauge.Estimate;
import com.android.systemui.R; import com.android.systemui.R;
import com.android.systemui.SysuiTestCase; import com.android.systemui.SysuiTestCase;
import com.android.systemui.broadcast.BroadcastDispatcher; import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.keyguard.WakefulnessLifecycle;
import com.android.systemui.power.PowerUI.WarningsUI; import com.android.systemui.power.PowerUI.WarningsUI;
import com.android.systemui.statusbar.CommandQueue; import com.android.systemui.statusbar.CommandQueue;
import com.android.systemui.statusbar.phone.CentralSurfaces; import com.android.systemui.statusbar.phone.CentralSurfaces;
@@ -84,6 +85,7 @@ public class PowerUITest extends SysuiTestCase {
private PowerUI mPowerUI; private PowerUI mPowerUI;
@Mock private EnhancedEstimates mEnhancedEstimates; @Mock private EnhancedEstimates mEnhancedEstimates;
@Mock private PowerManager mPowerManager; @Mock private PowerManager mPowerManager;
@Mock private WakefulnessLifecycle mWakefulnessLifecycle;
@Mock private IThermalService mThermalServiceMock; @Mock private IThermalService mThermalServiceMock;
private IThermalEventListener mUsbThermalEventListener; private IThermalEventListener mUsbThermalEventListener;
private IThermalEventListener mSkinThermalEventListener; private IThermalEventListener mSkinThermalEventListener;
@@ -680,7 +682,7 @@ public class PowerUITest extends SysuiTestCase {
private void createPowerUi() { private void createPowerUi() {
mPowerUI = new PowerUI( mPowerUI = new PowerUI(
mContext, mBroadcastDispatcher, mCommandQueue, mCentralSurfacesOptionalLazy, mContext, mBroadcastDispatcher, mCommandQueue, mCentralSurfacesOptionalLazy,
mMockWarnings, mEnhancedEstimates, mPowerManager); mMockWarnings, mEnhancedEstimates, mWakefulnessLifecycle, mPowerManager);
mPowerUI.mThermalService = mThermalServiceMock; mPowerUI.mThermalService = mThermalServiceMock;
} }