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

Commit 1bb884a8 authored by Louis Chang's avatar Louis Chang
Browse files

Fix NullPointerException in ActivityStack

Getting previous app's CPU time if the process is alive.

Bug: 117401956
Test: Existing tests pass
Change-Id: I531b367ebc7b963a3c6491dccc3f808ea05fe888
parent a72448e8
Loading
Loading
Loading
Loading
+10 −8
Original line number Diff line number Diff line
@@ -163,7 +163,6 @@ import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Set;
@@ -1681,14 +1680,17 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
        if (prev != null) {
            prev.resumeKeyDispatchingLocked();

            if (prev.hasProcess() && prev.cpuTimeAtResume > 0) {
                final long diff = prev.app.getCpuTime() - prev.cpuTimeAtResume;
            if (prev.hasProcess() && prev.cpuTimeAtResume > 0 && diff > 0) {
                if (diff > 0) {
                    final Runnable r = PooledLambda.obtainRunnable(
                            ActivityManagerInternal::updateForegroundTimeIfOnBattery,
                        mService.mAmInternal, prev.info.packageName, prev.info.applicationInfo.uid,
                            mService.mAmInternal, prev.info.packageName,
                            prev.info.applicationInfo.uid,
                            diff);
                    mService.mH.post(r);
                }
            }
            prev.cpuTimeAtResume = 0; // reset it
        }