Remove call to getComponent(StatusBar) from PowerUI.
Bug: 143224715
Test: atest SystemUITests
Change-Id: Iad2caf359ff2d19b4b43a8859ee4d49b14ad4f59
diff --git a/packages/SystemUI/src/com/android/systemui/power/PowerUI.java b/packages/SystemUI/src/com/android/systemui/power/PowerUI.java
index 98f0b2a..f60d9db 100644
--- a/packages/SystemUI/src/com/android/systemui/power/PowerUI.java
+++ b/packages/SystemUI/src/com/android/systemui/power/PowerUI.java
@@ -55,7 +55,11 @@
import java.util.concurrent.Future;
import javax.inject.Inject;
+import javax.inject.Singleton;
+import dagger.Lazy;
+
+@Singleton
public class PowerUI extends SystemUI {
static final String TAG = "PowerUI";
@@ -101,11 +105,14 @@
private IThermalEventListener mSkinThermalEventListener;
private IThermalEventListener mUsbThermalEventListener;
private final BroadcastDispatcher mBroadcastDispatcher;
+ private final Lazy<StatusBar> mStatusBarLazy;
@Inject
- public PowerUI(Context context, BroadcastDispatcher broadcastDispatcher) {
+ public PowerUI(Context context, BroadcastDispatcher broadcastDispatcher,
+ Lazy<StatusBar> statusBarLazy) {
super(context);
mBroadcastDispatcher = broadcastDispatcher;
+ mStatusBarLazy = statusBarLazy;
}
public void start() {
@@ -663,8 +670,7 @@
int status = temp.getStatus();
if (status >= Temperature.THROTTLING_EMERGENCY) {
- StatusBar statusBar = getComponent(StatusBar.class);
- if (statusBar != null && !statusBar.isDeviceInVrMode()) {
+ if (!mStatusBarLazy.get().isDeviceInVrMode()) {
mWarnings.showHighTemperatureWarning();
Slog.d(TAG, "SkinThermalEventListener: notifyThrottling was called "
+ ", current skin status = " + status
diff --git a/packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java b/packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java
index 8f4de3f..47b35fd 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java
@@ -22,7 +22,6 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.anyObject;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -60,6 +59,8 @@
import java.time.Duration;
import java.util.concurrent.TimeUnit;
+import dagger.Lazy;
+
@RunWith(AndroidTestingRunner.class)
@RunWithLooper
@SmallTest
@@ -86,6 +87,8 @@
private IThermalEventListener mUsbThermalEventListener;
private IThermalEventListener mSkinThermalEventListener;
@Mock private BroadcastDispatcher mBroadcastDispatcher;
+ @Mock private Lazy<StatusBar> mStatusBarLazy;
+ @Mock private StatusBar mStatusBar;
@Before
public void setup() {
@@ -93,7 +96,8 @@
mMockWarnings = mDependency.injectMockDependency(WarningsUI.class);
mEnhancedEstimates = mDependency.injectMockDependency(EnhancedEstimates.class);
- mContext.putComponent(StatusBar.class, mock(StatusBar.class));
+ when(mStatusBarLazy.get()).thenReturn(mStatusBar);
+
mContext.addMockSystemService(Context.POWER_SERVICE, mPowerManager);
createPowerUi();
@@ -682,7 +686,7 @@
}
private void createPowerUi() {
- mPowerUI = new PowerUI(mContext, mBroadcastDispatcher);
+ mPowerUI = new PowerUI(mContext, mBroadcastDispatcher, mStatusBarLazy);
mPowerUI.mComponents = mContext.getComponents();
mPowerUI.mThermalService = mThermalServiceMock;
}