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

Commit 002b29fa authored by Fabrice Di Meglio's avatar Fabrice Di Meglio
Browse files

Fix bug #12957032 Stability-Sys: Java crash in com.android.settings:...

Fix bug #12957032 Stability-Sys: Java crash in com.android.settings: java.lang.NullPointerException:
...Attempt to invoke virtual method 'boolean android.os.Handler.sendEmptyMessage(int)' on a null object reference

- prevent NPE by checking the nullity of the Handler reference
- remove dead code
- rename mHandler to sHandler as it is a static

Change-Id: I7f4101f860f24b0cd49a4656971e9b54e55c1286
parent 1ffab228
Loading
Loading
Loading
Loading
+10 −11
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ public class BatteryEntry {
    static final HashMap<String,UidToDetail> sUidCache = new HashMap<String,UidToDetail>();

    static final ArrayList<BatteryEntry> mRequestQueue = new ArrayList<BatteryEntry>();
    static Handler mHandler;
    static Handler sHandler;

    static private class NameAndIconLoader extends Thread {
        private boolean mAbort = false;
@@ -62,7 +62,9 @@ public class BatteryEntry {
                BatteryEntry be;
                synchronized (mRequestQueue) {
                    if (mRequestQueue.isEmpty() || mAbort) {
                        mHandler.sendEmptyMessage(MSG_REPORT_FULLY_DRAWN);
                        if (sHandler != null) {
                            sHandler.sendEmptyMessage(MSG_REPORT_FULLY_DRAWN);
                        }
                        mRequestQueue.clear();
                        return;
                    }
@@ -76,7 +78,7 @@ public class BatteryEntry {
    private static NameAndIconLoader mRequestThread;

    public static void startRequestQueue() {
        if (mHandler != null) {
        if (sHandler != null) {
            synchronized (mRequestQueue) {
                if (!mRequestQueue.isEmpty()) {
                    if (mRequestThread != null) {
@@ -96,7 +98,7 @@ public class BatteryEntry {
            if (mRequestThread != null) {
                mRequestThread.abort();
                mRequestThread = null;
                mHandler = null;
                sHandler = null;
            }
        }
    }
@@ -120,7 +122,7 @@ public class BatteryEntry {
    }

    public BatteryEntry(Context context, Handler handler, UserManager um, BatterySipper sipper) {
        mHandler = handler;
        sHandler = handler;
        this.context = context;
        this.sipper = sipper;
        switch (sipper.drainType) {
@@ -221,7 +223,7 @@ public class BatteryEntry {
        } else {
            //name = packages[0];
        }
        if (mHandler != null) {
        if (sHandler != null) {
            synchronized (mRequestQueue) {
                mRequestQueue.add(this);
            }
@@ -248,11 +250,8 @@ public class BatteryEntry {
        String[] packageLabels = new String[sipper.mPackages.length];
        System.arraycopy(sipper.mPackages, 0, packageLabels, 0, sipper.mPackages.length);

        int preferredIndex = -1;
        // Convert package names to user-facing labels where possible
        for (int i = 0; i < packageLabels.length; i++) {
            // Check if package matches preferred package
            if (packageLabels[i].equals(name)) preferredIndex = i;
            try {
                ApplicationInfo ai = pm.getApplicationInfo(packageLabels[i], 0);
                CharSequence label = ai.loadLabel(pm);
@@ -298,8 +297,8 @@ public class BatteryEntry {
        utd.icon = icon;
        utd.packageName = defaultPackageName;
        sUidCache.put(uidString, utd);
        if (mHandler != null) {
            mHandler.sendMessage(mHandler.obtainMessage(MSG_UPDATE_NAME_ICON, this));
        if (sHandler != null) {
            sHandler.sendMessage(sHandler.obtainMessage(MSG_UPDATE_NAME_ICON, this));
        }
    }
}