Loading packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryControllerImpl.java +5 −1 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.systemui.statusbar.policy; import static android.os.BatteryManager.EXTRA_PRESENT; import android.annotation.WorkerThread; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; Loading @@ -43,6 +44,7 @@ import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.demomode.DemoMode; import com.android.systemui.demomode.DemoModeController; import com.android.systemui.power.EnhancedEstimates; import com.android.systemui.util.Assert; import java.io.FileDescriptor; import java.io.PrintWriter; Loading Loading @@ -134,7 +136,7 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC } mDemoModeController.addCallback(this); updatePowerSave(); updateEstimate(); updateEstimateInBackground(); } @Override Loading Loading @@ -339,7 +341,9 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC } } @WorkerThread private void updateEstimate() { Assert.isNotMainThread(); // if the estimate has been cached we can just use that, otherwise get a new one and // throw it in the cache. mEstimate = Estimate.getCachedEstimateIfAvailable(mContext); Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/BatteryControllerTest.java +12 −1 Original line number Diff line number Diff line Loading @@ -67,7 +67,7 @@ public class BatteryControllerTest extends SysuiTestCase { private MockitoSession mMockitoSession; @Before public void setUp() { public void setUp() throws IllegalStateException { MockitoAnnotations.initMocks(this); mMockitoSession = mockitoSession() .initMocks(this) Loading @@ -81,6 +81,7 @@ public class BatteryControllerTest extends SysuiTestCase { mDemoModeController, new Handler(), new Handler()); // Can throw if updateEstimate is called on the main thread mBatteryController.init(); } Loading Loading @@ -185,4 +186,14 @@ public class BatteryControllerTest extends SysuiTestCase { Assert.assertNull(mBatteryController.getLastPowerSaverStartView()); } @Test public void testBatteryEstimateFetch_doesNotThrow() throws IllegalStateException { mBatteryController.getEstimatedTimeRemainingString( (String estimate) -> { // don't care about the result }); TestableLooper.get(this).processAllMessages(); // Should not throw an exception } } Loading
packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryControllerImpl.java +5 −1 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.systemui.statusbar.policy; import static android.os.BatteryManager.EXTRA_PRESENT; import android.annotation.WorkerThread; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; Loading @@ -43,6 +44,7 @@ import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.demomode.DemoMode; import com.android.systemui.demomode.DemoModeController; import com.android.systemui.power.EnhancedEstimates; import com.android.systemui.util.Assert; import java.io.FileDescriptor; import java.io.PrintWriter; Loading Loading @@ -134,7 +136,7 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC } mDemoModeController.addCallback(this); updatePowerSave(); updateEstimate(); updateEstimateInBackground(); } @Override Loading Loading @@ -339,7 +341,9 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC } } @WorkerThread private void updateEstimate() { Assert.isNotMainThread(); // if the estimate has been cached we can just use that, otherwise get a new one and // throw it in the cache. mEstimate = Estimate.getCachedEstimateIfAvailable(mContext); Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/BatteryControllerTest.java +12 −1 Original line number Diff line number Diff line Loading @@ -67,7 +67,7 @@ public class BatteryControllerTest extends SysuiTestCase { private MockitoSession mMockitoSession; @Before public void setUp() { public void setUp() throws IllegalStateException { MockitoAnnotations.initMocks(this); mMockitoSession = mockitoSession() .initMocks(this) Loading @@ -81,6 +81,7 @@ public class BatteryControllerTest extends SysuiTestCase { mDemoModeController, new Handler(), new Handler()); // Can throw if updateEstimate is called on the main thread mBatteryController.init(); } Loading Loading @@ -185,4 +186,14 @@ public class BatteryControllerTest extends SysuiTestCase { Assert.assertNull(mBatteryController.getLastPowerSaverStartView()); } @Test public void testBatteryEstimateFetch_doesNotThrow() throws IllegalStateException { mBatteryController.getEstimatedTimeRemainingString( (String estimate) -> { // don't care about the result }); TestableLooper.get(this).processAllMessages(); // Should not throw an exception } }