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

Commit bf05e600 authored by Wei Wang's avatar Wei Wang
Browse files

Add mock thermal service in PowerUI test

Thermal event might interfere with unit test.

Bug: 119873861
Test: atest frameworks/base/packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java
Change-Id: If610d53355bf4e2c29b807acce887096489f62c8
parent 37b17544
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -90,7 +90,7 @@ public class PowerUI extends SystemUI {
    private float[] mRecentTemps = new float[MAX_RECENT_TEMPS];
    private int mNumTemps;
    private long mNextLogTime;
    private IThermalService mThermalService;
    @VisibleForTesting IThermalService mThermalService;

    @VisibleForTesting int mBatteryLevel = 100;
    @VisibleForTesting int mBatteryStatus = BatteryManager.BATTERY_STATUS_UNKNOWN;
@@ -394,7 +394,7 @@ public class PowerUI extends SystemUI {
            // Enable push notifications of throttling from vendor thermal
            // management subsystem via thermalservice, in addition to our
            // usual polling, to react to temperature jumps more quickly.
            IBinder b = ServiceManager.getService("thermalservice");
            IBinder b = ServiceManager.getService(Context.THERMAL_SERVICE);

            if (b != null) {
                mThermalService = IThermalService.Stub.asInterface(b);
+8 −4
Original line number Diff line number Diff line
@@ -32,12 +32,13 @@ import android.content.Context;
import android.content.Intent;
import android.os.BatteryManager;
import android.os.HardwarePropertiesManager;
import android.os.IThermalService;
import android.os.PowerManager;
import android.provider.Settings;
import android.test.suitebuilder.annotation.SmallTest;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper.RunWithLooper;
import android.testing.TestableResources;
import android.test.suitebuilder.annotation.SmallTest;

import com.android.settingslib.utils.ThreadUtils;
import com.android.systemui.R;
@@ -45,15 +46,16 @@ import com.android.systemui.SysuiTestCase;
import com.android.systemui.power.PowerUI.WarningsUI;
import com.android.systemui.statusbar.phone.StatusBar;

import java.time.Duration;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import java.time.Duration;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

@RunWith(AndroidTestingRunner.class)
@RunWithLooper
@SmallTest
@@ -76,6 +78,7 @@ public class PowerUITest extends SysuiTestCase {
    private PowerUI mPowerUI;
    private EnhancedEstimates mEnhancedEstimates;
    @Mock private PowerManager mPowerManager;
    @Mock private IThermalService mThermalServiceMock;

    @Before
    public void setup() {
@@ -541,5 +544,6 @@ public class PowerUITest extends SysuiTestCase {
        mPowerUI = new PowerUI();
        mPowerUI.mContext = mContext;
        mPowerUI.mComponents = mContext.getComponents();
        mPowerUI.mThermalService = mThermalServiceMock;
    }
}