Fix Car Service Test crash.
Safeguard against unregistering a broadcast reciever more than once
caused by calling cleanup successively.
Respect ICarImpl release order - should be the reverse of the init
order.
Bug: b/38046032
Test: runtest -x packages/services/Car/tests/carservice_test/
Change-Id: I79f810292100f579bc10352121c59558f5ceb0e5
diff --git a/service/src/com/android/car/PerUserCarServiceHelper.java b/service/src/com/android/car/PerUserCarServiceHelper.java
index 21958de..db6a10c 100644
--- a/service/src/com/android/car/PerUserCarServiceHelper.java
+++ b/service/src/com/android/car/PerUserCarServiceHelper.java
@@ -27,6 +27,7 @@
import android.os.UserHandle;
import android.util.Log;
+import java.io.PrintWriter;
import java.util.List;
import java.util.ArrayList;
@@ -36,7 +37,7 @@
* 2. Set up a listener to UserSwitch Broadcasts and call clients that have registered callbacks.
*
*/
-public class PerUserCarServiceHelper {
+public class PerUserCarServiceHelper implements CarServiceBase {
private static final String TAG = "PerUserCarSvcHelper";
private static boolean DBG = false;
private Context mContext;
@@ -54,13 +55,16 @@
setupUserSwitchListener();
}
+ @Override
public synchronized void init() {
bindToPerUserCarService();
}
+ @Override
public synchronized void release() {
unbindFromPerUserCarService();
}
+
/**
* Setting up the intent filter for
* 2. UserSwitch events
@@ -163,6 +167,7 @@
// Try binding - if valid connection not obtained, unbind
if (!mContext.bindServiceAsUser(startIntent, mUserServiceConnection,
mContext.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
+ Log.e(TAG, "bindToPerUserCarService() failed to get valid connection");
unbindFromPerUserCarService();
}
}
@@ -219,5 +224,12 @@
// When Service crashed or disconnected
void onServiceDisconnected();
}
+
+ @Override
+ public synchronized void dump(PrintWriter writer) {
+
+ }
+
+
}