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

Commit 0e277429 authored by Zaiyue Xue's avatar Zaiyue Xue
Browse files

Fix NullPointerException when full charge unplug a device with work profile

Block BatteryUsageBroadcastReceiver when context is work profile.

Bug: 304441610
Fix: 304441610
Test: manual
Change-Id: I91a41d5570e7cacf77a8d126c7700ee4bd766d40
parent 17354749
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -63,6 +63,10 @@ public final class BatteryUsageBroadcastReceiver extends BroadcastReceiver {
        }
        final String action = intent.getAction();
        Log.d(TAG, "onReceive:" + action);
        if (DatabaseUtils.isWorkProfile(context)) {
            Log.w(TAG, "do nothing for work profile action=" + action);
            return;
        }
        DatabaseUtils.recordDateTime(context, action);
        final String fullChargeIntentAction = FeatureFactory.getFeatureFactory()
                .getPowerUsageFeatureProvider()
+11 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.os.BatteryManager;
import android.os.SystemClock;
import android.text.format.DateUtils;

import com.android.settings.testutils.BatteryTestUtils;
import com.android.settings.testutils.FakeFeatureFactory;

import org.junit.Before;
@@ -67,6 +68,16 @@ public final class BatteryUsageBroadcastReceiverTest {
        assertThat(mBatteryUsageBroadcastReceiver.mFetchBatteryUsageData).isFalse();
    }

    @Test
    public void onReceive_workProfile_doNothing() {
        BatteryTestUtils.setWorkProfile(mContext);

        mBatteryUsageBroadcastReceiver.onReceive(mContext,
                new Intent(BatteryUsageBroadcastReceiver.ACTION_BATTERY_UNPLUGGING));

        assertThat(mBatteryUsageBroadcastReceiver.mFetchBatteryUsageData).isFalse();
    }

    @Test
    public void onReceive_aospNotFullCharged_notFetchUsageData() {
        when(mFakeFeatureFactory.powerUsageFeatureProvider.getFullChargeIntentAction())