From 95b105671e5eb57434303088a0291b81e8de1372 Mon Sep 17 00:00:00 2001 From: "T.J. Mercier" Date: Thu, 3 Aug 2023 17:54:36 +0000 Subject: [PATCH] Return error code when there's an error starting an activity When an error occurs while attempting to start an activity, runStartActivity does not always return an error code like it should. This causes tools like the simpleperf app profiler to have incorrect behavior: $ system/extras/simpleperf/scripts/app_profiler.py -p com.google.android.youtube -a doesntexist 18:08:45,394 [DEBUG] (simpleperf_utils.py:304) run adb cmd: ['adb', 'shell', 'am', 'start', '-n', 'com.google.android.youtube/doesntexist'] [result True] Immediately return an error code in these cases like elsewhere in the function. Bug: 294402973 Test: $ system/extras/simpleperf/scripts/app_profiler.py -p com.google.android.youtube -a doesntexist Test: 17:39:26,843 [DEBUG] (simpleperf_utils.py:304) run adb cmd: ['adb', 'shell', 'am', 'start', '-n', 'com.google.android.youtube/doesntexist'] [result False] Test: Can't start activity com.google.android.youtube/doesntexist Change-Id: If1ebbde6ee77b27b8d6fa7d4097163d3b4594389 --- .../server/am/ActivityManagerShellCommand.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/services/core/java/com/android/server/am/ActivityManagerShellCommand.java b/services/core/java/com/android/server/am/ActivityManagerShellCommand.java index 5d8c3b6c3dd05..e3d31ad35a828 100644 --- a/services/core/java/com/android/server/am/ActivityManagerShellCommand.java +++ b/services/core/java/com/android/server/am/ActivityManagerShellCommand.java @@ -658,37 +658,37 @@ final class ActivityManagerShellCommand extends ShellCommand { out.println( "Error: Activity not started, unable to " + "resolve " + intent.toString()); - break; + return 1; case ActivityManager.START_CLASS_NOT_FOUND: out.println(NO_CLASS_ERROR_CODE); out.println("Error: Activity class " + intent.getComponent().toShortString() + " does not exist."); - break; + return 1; case ActivityManager.START_FORWARD_AND_REQUEST_CONFLICT: out.println( "Error: Activity not started, you requested to " + "both forward and receive its result"); - break; + return 1; case ActivityManager.START_PERMISSION_DENIED: out.println( "Error: Activity not started, you do not " + "have permission to access it."); - break; + return 1; case ActivityManager.START_NOT_VOICE_COMPATIBLE: out.println( "Error: Activity not started, voice control not allowed for: " + intent); - break; + return 1; case ActivityManager.START_NOT_CURRENT_USER_ACTIVITY: out.println( "Error: Not allowed to start background user activity" + " that shouldn't be displayed for all users."); - break; + return 1; default: out.println( "Error: Activity not started, unknown error code " + res); - break; + return 1; } out.flush(); if (mWaitOption && launched) {