Merge "Migrate clients from Binder.waitForService to ServiceManager.waitForService" into rvc-dev am: 8f0b08f178 am: 7bb412a077

Change-Id: Ibed2c8ab7499e7a8bda2286397f61bb259e2acf4
This commit is contained in:
TreeHugger Robot
2020-04-24 21:38:34 +00:00
committed by Automerger Merge Worker
4 changed files with 6 additions and 43 deletions

View File

@@ -1204,13 +1204,4 @@ public class Binder implements IBinder {
StrictMode.clearGatheredViolations();
return res;
}
/**
* Returns the specified service from servicemanager. If the service is not running,
* servicemanager will attempt to start it, and this function will wait for it to be ready.
* Returns nullptr only if there are permission problems or fatal errors.
* @hide
*/
public static final native @Nullable IBinder waitForService(@NonNull String serviceName)
throws RemoteException;
}

View File

@@ -1036,31 +1036,6 @@ static void android_os_Binder_blockUntilThreadAvailable(JNIEnv* env, jobject cla
return IPCThreadState::self()->blockUntilThreadAvailable();
}
static jobject android_os_Binder_waitForService(
JNIEnv *env,
jclass /* clazzObj */,
jstring serviceNameObj) {
const jchar* serviceName = env->GetStringCritical(serviceNameObj, nullptr);
if (!serviceName) {
signalExceptionForError(env, nullptr, BAD_VALUE, true /*canThrowRemoteException*/);
return nullptr;
}
String16 nameCopy = String16(reinterpret_cast<const char16_t *>(serviceName),
env->GetStringLength(serviceNameObj));
env->ReleaseStringCritical(serviceNameObj, serviceName);
auto sm = android::defaultServiceManager();
sp<IBinder> service = sm->waitForService(nameCopy);
if (!service) {
signalExceptionForError(env, nullptr, NAME_NOT_FOUND, true /*canThrowRemoteException*/);
return nullptr;
}
return javaObjectForIBinder(env, service);
}
static jobject android_os_Binder_getExtension(JNIEnv* env, jobject obj) {
JavaBBinderHolder* jbh = (JavaBBinderHolder*) env->GetLongField(obj, gBinderOffsets.mObject);
return javaObjectForIBinder(env, jbh->getExtension());
@@ -1101,7 +1076,6 @@ static const JNINativeMethod gBinderMethods[] = {
{ "getNativeBBinderHolder", "()J", (void*)android_os_Binder_getNativeBBinderHolder },
{ "getNativeFinalizer", "()J", (void*)android_os_Binder_getNativeFinalizer },
{ "blockUntilThreadAvailable", "()V", (void*)android_os_Binder_blockUntilThreadAvailable },
{ "waitForService", "(Ljava/lang/String;)Landroid/os/IBinder;", (void*)android_os_Binder_waitForService },
{ "getExtension", "()Landroid/os/IBinder;", (void*)android_os_Binder_getExtension },
{ "setExtension", "(Landroid/os/IBinder;)V", (void*)android_os_Binder_setExtension },
};

View File

@@ -25,6 +25,7 @@ import android.gsi.IGsiServiceCallback;
import android.os.Environment;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.image.IDynamicSystemService;
@@ -55,7 +56,7 @@ public class DynamicSystemService extends IDynamicSystemService.Stub {
if (mGsiService != null) {
return mGsiService;
}
return IGsiService.Stub.asInterface(waitForService("gsiservice"));
return IGsiService.Stub.asInterface(ServiceManager.waitForService("gsiservice"));
}
private void checkPermission() {

View File

@@ -35,6 +35,7 @@ import android.content.pm.parsing.PackageInfoWithoutStateUtils;
import android.os.Binder;
import android.os.Environment;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.Trace;
import android.sysprop.ApexProperties;
import android.util.ArrayMap;
@@ -398,13 +399,9 @@ public abstract class ApexManager {
*/
@VisibleForTesting
protected IApexService waitForApexService() {
try {
// Since apexd is a trusted platform component, synchronized calls are allowable
return IApexService.Stub.asInterface(
Binder.allowBlocking(Binder.waitForService("apexservice")));
} catch (RemoteException e) {
throw new IllegalStateException("Required service apexservice not available");
}
// Since apexd is a trusted platform component, synchronized calls are allowable
return IApexService.Stub.asInterface(
Binder.allowBlocking(ServiceManager.waitForService("apexservice")));
}
@Override