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]
<Blocks forever>

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
This commit is contained in:
T.J. Mercier
2023-08-03 17:54:36 +00:00
parent 6f74b260aa
commit 95b105671e

View File

@@ -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) {