Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 385b8d2b authored by Evan Laird's avatar Evan Laird Committed by Automerger Merge Worker
Browse files

Merge "Use background call for BatteryController#init()" into tm-dev am: 756f7b4e

parents e6745e0d 756f7b4e
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -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;
@@ -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;
@@ -134,7 +136,7 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC
        }
        mDemoModeController.addCallback(this);
        updatePowerSave();
        updateEstimate();
        updateEstimateInBackground();
    }

    @Override
@@ -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);
+12 −1
Original line number Diff line number Diff line
@@ -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)
@@ -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();
    }

@@ -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
    }
}