health: Drop HealthServiceWrapperHidl.init.

Having a separate init function is a bad contract because
the client may not call it. Replace it with the constructor.

This reduces technical debt.

Test: pass
Change-Id: I3828903b006c32eb6898d36e64326520ef601ba8
This commit is contained in:
Yifan Hong
2021-11-05 16:16:06 -07:00
parent 8902c87ea9
commit 9d57df9e82
2 changed files with 3 additions and 10 deletions

View File

@@ -102,8 +102,7 @@ public abstract class HealthServiceWrapper {
@NonNull HealthServiceWrapperHidl.IServiceManagerSupplier hidlServiceManagerSupplier,
@NonNull HealthServiceWrapperHidl.IHealthSupplier hidlHealthSupplier)
throws RemoteException, NoSuchElementException {
HealthServiceWrapperHidl service = new HealthServiceWrapperHidl();
service.init(hidlRegCallback, hidlServiceManagerSupplier, hidlHealthSupplier);
return service;
return new HealthServiceWrapperHidl(
hidlRegCallback, hidlServiceManagerSupplier, hidlHealthSupplier);
}
}

View File

@@ -56,12 +56,6 @@ final class HealthServiceWrapperHidl extends HealthServiceWrapper {
// Last IHealth service received.
private final AtomicReference<IHealth> mLastService = new AtomicReference<>();
/**
* init should be called after constructor. For testing purposes, init is not called by
* constructor.
*/
HealthServiceWrapperHidl() {}
private static void traceBegin(String name) {
Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, name);
}
@@ -181,7 +175,7 @@ final class HealthServiceWrapperHidl extends HealthServiceWrapper {
* @throws NullPointerException when supplier is null
*/
@VisibleForTesting
void init(
HealthServiceWrapperHidl(
@Nullable Callback callback,
@NonNull IServiceManagerSupplier managerSupplier,
@NonNull IHealthSupplier healthSupplier)