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

Commit 0e3504c0 authored by jackqdyulei's avatar jackqdyulei
Browse files

Add static lock in PowerProfile

Before this cl, there exists nullpointer crash in PowerProfile in
following part:

"sPowerMap.containsKey(key) && (Double) sPowerMap.get(key) > 0"

To my best knowledge, it is because in
PowerUsageSummary.SummaryProvider, we may create batterystats in
meantime:
1. setListening is invoked in worker thread, in which we will force
update the batterystats.
2. In setListening we will register receiver, which may update
batterystats through onReceive in UI thread.

This cl adds static lock in PowerProfile, making the init part can
only be accessed by an thread at a time.

Bug: 64209576
Test: Manual
Change-Id: I00bc094f44416669b4f0e11e647b0fae2ff61013
parent 6a1dad91
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -205,14 +205,18 @@ public class PowerProfile {
    private static final String TAG_ARRAYITEM = "value";
    private static final String ATTR_NAME = "name";

    private static final Object sLock = new Object();

    public PowerProfile(Context context) {
        // Read the XML file for the given profile (normally only one per
        // device)
        synchronized (sLock) {
            if (sPowerMap.size() == 0) {
                readPowerValuesFromXml(context);
            }
            initCpuClusters();
        }
    }

    private void readPowerValuesFromXml(Context context) {
        int id = com.android.internal.R.xml.power_profile;