Force car service crash handling to client
- If client handles car service crash by using ServiceConnection or
CarServiceLifecycleListener, client is left alive.
- If client does not handle it, crash the client when car service crashes. This
was partially done before by throwing RuntimeException for failed binder calls
or some **wrong** disconnection handling in Car*Managers but it will crash
relabily in service connection handler instead.
- All binder call failure will no longer return RuntimeException as service
connection handler will crash the client or client should re-do initialization
anyway.
- Refactored CarManagerBase to provide common utilities so that exception
handling can be done in a single place.
- Client should throw away all old Car*Manager and does not need to make any
cleanup call for old objects. Old Car*Manager objects should clean things up
by itself.
- Car*Manager clean all listeners / callbacks passed from client so that those
are not potentially leaked.
Bug: 142543455
Bug: 142541056
Test: kill car service and check if clients using non-handling clients are
crashed and handling clients are not crashing. Kitchensink carapi page
can be used for this.
Runs all automated tests (car api, unit, car service test).
Change-Id: Id515a42041fb7000d2bcd48af9931b33dc1f9fdd
diff --git a/service/src/com/android/car/CarLocalServices.java b/service/src/com/android/car/CarLocalServices.java
index 6c756b8..ea1b6f1 100644
--- a/service/src/com/android/car/CarLocalServices.java
+++ b/service/src/com/android/car/CarLocalServices.java
@@ -17,6 +17,7 @@
package com.android.car;
import android.annotation.Nullable;
+import android.car.Car;
import android.car.hardware.power.CarPowerManager;
import android.content.Context;
import android.util.ArrayMap;
@@ -90,10 +91,12 @@
*/
@Nullable
public static CarPowerManager createCarPowerManager(Context context) {
+ // This does not require connection as binder will be passed to CarPowerManager directly.
+ Car car = new Car(context, /* service= */null, /* handler= */ null);
CarPowerManagementService service = getService(CarPowerManagementService.class);
if (service == null) {
return null;
}
- return new CarPowerManager(service, context, null);
+ return new CarPowerManager(car, service);
}
}