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

Commit 04bf5ff4 authored by Lais Andrade's avatar Lais Andrade Committed by Automerger Merge Worker
Browse files

Merge "Fix NPE in ShutdownCheckPoints dumpDetails method." into udc-dev am: b2c2f641

parents 6186d732 b2c2f641
Loading
Loading
Loading
Loading
+12 −5
Original line number Diff line number Diff line
@@ -295,13 +295,20 @@ public final class ShutdownCheckPoints {
        @Nullable
        String getProcessName() {
            try {
                List<ActivityManager.RunningAppProcessInfo> runningProcesses =
                        mActivityManager.getRunningAppProcesses();
                List<ActivityManager.RunningAppProcessInfo> runningProcesses = null;
                if (mActivityManager != null) {
                    runningProcesses = mActivityManager.getRunningAppProcesses();
                } else {
                    Slog.v(TAG, "No ActivityManager available to find process name with pid="
                            + mCallerProcessId);
                }
                if (runningProcesses != null) {
                    for (ActivityManager.RunningAppProcessInfo processInfo : runningProcesses) {
                        if (processInfo.pid == mCallerProcessId) {
                            return processInfo.processName;
                        }
                    }
                }
            } catch (RemoteException e) {
                Slog.e(TAG, "Failed to get running app processes from ActivityManager", e);
            }
+27 −3
Original line number Diff line number Diff line
@@ -103,21 +103,45 @@ public class ShutdownCheckPointsTest {
    }

    @Test
    public void testCallerProcessBinderEntry() throws RemoteException {
    public void testCallerProcessBinderEntries() throws RemoteException {
        List<ActivityManager.RunningAppProcessInfo> runningAppProcessInfos = new ArrayList<>();
        runningAppProcessInfos.add(
                new ActivityManager.RunningAppProcessInfo("process_name", 1, new String[0]));
        when(mActivityManager.getRunningAppProcesses()).thenReturn(runningAppProcessInfos);

        mTestInjector.setCurrentTime(1000);
        // Matching pid in getRunningAppProcesses
        mInstance.recordCheckPointInternal(1, "reason1");
        // Mising pid in getRunningAppProcesses
        mInstance.recordCheckPointInternal(2, "reason2");

        assertEquals(
                "Shutdown request from BINDER for reason reason1 "
                        + "at 1970-01-01 00:00:01.000 UTC (epoch=1000)\n"
                        + "com.android.server.power.ShutdownCheckPointsTest"
                        + ".testCallerProcessBinderEntry\n"
                        + "From process process_name (pid=1)\n\n",
                        + ".testCallerProcessBinderEntries\n"
                        + "From process process_name (pid=1)\n\n"
                        + "Shutdown request from BINDER for reason reason2 "
                        + "at 1970-01-01 00:00:01.000 UTC (epoch=1000)\n"
                        + "com.android.server.power.ShutdownCheckPointsTest"
                        + ".testCallerProcessBinderEntries\n"
                        + "From process ? (pid=2)\n\n",
                dumpToString());
    }

    @Test
    public void testNullCallerProcessBinderEntries() throws RemoteException {
        when(mActivityManager.getRunningAppProcesses()).thenReturn(null);

        mTestInjector.setCurrentTime(1000);
        mInstance.recordCheckPointInternal(1, "reason1");

        assertEquals(
                "Shutdown request from BINDER for reason reason1 "
                        + "at 1970-01-01 00:00:01.000 UTC (epoch=1000)\n"
                        + "com.android.server.power.ShutdownCheckPointsTest"
                        + ".testNullCallerProcessBinderEntries\n"
                        + "From process ? (pid=1)\n\n",
                dumpToString());
    }