Limit relaunch retry if it keeps failing
- Limit it to 5 times with 500ms delay (about 2 secs for total duration)
- Being alive for more than 2 mins reset the crash counter.
- Retry for user switching, power ON (including wakeup from sleep),
and package update.
- Added always crashing Activity and other Activities in kietchensink for testing.
- Add shell command to test fixed mode start and stopping in easier way:
$ adb shell dumpsys car_service start-fixed-activity-mode 1 com.google.android.car.kitchensink com.google.android.car.kitchensink.AlwaysCrashingActivity
$ adb shell dumpsys car_service stop-fixed-activity-mode 1
- Added test script to test all recovery cases: fixed_activity_mode_test.sh
* give up after retry
* retry after package update
* retry after suspend - resume
* successfully launch for NoCrashActivity
* Re-launch the Activity if other Activity launched
* Re-launch after package update
Bug: 141721242
Test: $ ./packages/services/Car/tests/fixed_activity_mode_test/fixed_activity_mode_test.sh
Change-Id: I86cdc80705d936c47323be985d6daa1d4ac4d9f4
(cherry picked from commit dd163af6f4034d93dccc279a7f611813c81d922e)
diff --git a/service/src/com/android/car/ICarImpl.java b/service/src/com/android/car/ICarImpl.java
index dfdee04..05943fc 100644
--- a/service/src/com/android/car/ICarImpl.java
+++ b/service/src/com/android/car/ICarImpl.java
@@ -19,12 +19,15 @@
import android.annotation.MainThread;
import android.annotation.Nullable;
import android.app.ActivityManager;
+import android.app.ActivityOptions;
import android.app.UiModeManager;
import android.car.Car;
import android.car.ICar;
import android.car.cluster.renderer.IInstrumentClusterNavigation;
import android.car.userlib.CarUserManagerHelper;
+import android.content.ComponentName;
import android.content.Context;
+import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.hardware.automotive.vehicle.V2_0.IVehicle;
@@ -609,6 +612,8 @@
private static final String COMMAND_ENABLE_TRUSTED_DEVICE = "enable-trusted-device";
private static final String COMMAND_REMOVE_TRUSTED_DEVICES = "remove-trusted-devices";
private static final String COMMAND_SET_UID_TO_ZONE = "set-zoneid-for-uid";
+ private static final String COMMAND_START_FIXED_ACTIVITY_MODE = "start-fixed-activity-mode";
+ private static final String COMMAND_STOP_FIXED_ACTIVITY_MODE = "stop-fixed-activity-mode";
private static final String PARAM_DAY_MODE = "day";
private static final String PARAM_NIGHT_MODE = "night";
@@ -683,6 +688,11 @@
pw.println("\t When used with dumpsys, only metrics will be in the dumpsys output.");
pw.println("\tset-zoneid-for-uid [zoneid] [uid]");
pw.println("\t Maps the audio zoneid to uid.");
+ pw.println("\tstart-fixed-activity displayId packageName activityName");
+ pw.println("\t Start an Activity the specified display as fixed mode");
+ pw.println("\tstop-fixed-mode displayId");
+ pw.println("\t Stop fixed Activity mode for the given display. "
+ + "The Activity will not be restarted upon crash.");
}
private int dumpInvalidArguments(PrintWriter pw) {
@@ -820,6 +830,12 @@
dumpHelp(writer);
}
break;
+ case COMMAND_START_FIXED_ACTIVITY_MODE:
+ handleStartFixedActivity(args, writer);
+ break;
+ case COMMAND_STOP_FIXED_ACTIVITY_MODE:
+ handleStopFixedMode(args, writer);
+ break;
default:
writer.println("Unknown command: \"" + arg + "\"");
dumpHelp(writer);
@@ -828,6 +844,50 @@
return RESULT_OK;
}
+ private void handleStartFixedActivity(String[] args, PrintWriter writer) {
+ if (args.length != 4) {
+ writer.println("Incorrect number of arguments");
+ dumpHelp(writer);
+ return;
+ }
+ int displayId;
+ try {
+ displayId = Integer.parseInt(args[1]);
+ } catch (NumberFormatException e) {
+ writer.println("Wrong display id:" + args[1]);
+ return;
+ }
+ String packageName = args[2];
+ String activityName = args[3];
+ Intent intent = new Intent();
+ intent.setComponent(new ComponentName(packageName, activityName));
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
+ ActivityOptions options = ActivityOptions.makeBasic();
+ options.setLaunchDisplayId(displayId);
+ if (!mFixedActivityService.startFixedActivityModeForDisplayAndUser(intent, options,
+ displayId, ActivityManager.getCurrentUser())) {
+ writer.println("Failed to start");
+ return;
+ }
+ writer.println("Succeeded");
+ }
+
+ private void handleStopFixedMode(String[] args, PrintWriter writer) {
+ if (args.length != 2) {
+ writer.println("Incorrect number of arguments");
+ dumpHelp(writer);
+ return;
+ }
+ int displayId;
+ try {
+ displayId = Integer.parseInt(args[1]);
+ } catch (NumberFormatException e) {
+ writer.println("Wrong display id:" + args[1]);
+ return;
+ }
+ mFixedActivityService.stopFixedActivityMode(displayId);
+ }
+
private void forceDayNightMode(String arg, PrintWriter writer) {
int mode;
switch (arg) {