Wrap whole onTransact (#2740)

This commit is contained in:
Nullptr 2023-09-04 01:18:48 +08:00 committed by GitHub
parent 8d73414d2d
commit 134cd71fa0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 32 additions and 28 deletions

View File

@ -100,39 +100,43 @@ public class BridgeService {
public static boolean onTransact(@NonNull Parcel data, @Nullable Parcel reply, int flags) {
if (!ParcelUtils.safeEnforceInterface(data, DESCRIPTOR)) return false;
ACTION action = ACTION.values()[data.readInt()];
try {
ACTION action = ACTION.values()[data.readInt()];
Log.d(TAG, "onTransact: action=" + action + ", callingUid=" + Binder.getCallingUid() + ", callingPid=" + Binder.getCallingPid());
Log.d(TAG, "onTransact: action=" + action + ", callingUid=" + Binder.getCallingUid() + ", callingPid=" + Binder.getCallingPid());
switch (action) {
case ACTION_SEND_BINDER: {
if (Binder.getCallingUid() == 0) {
receiveFromBridge(data.readStrongBinder());
if (reply != null) {
reply.writeNoException();
switch (action) {
case ACTION_SEND_BINDER: {
if (Binder.getCallingUid() == 0) {
receiveFromBridge(data.readStrongBinder());
if (reply != null) {
reply.writeNoException();
}
return true;
}
return true;
break;
}
case ACTION_GET_BINDER: {
IBinder binder = null;
try {
String processName = data.readString();
IBinder heartBeat = data.readStrongBinder();
var applicationService = service == null ? null : service.requestApplicationService(Binder.getCallingUid(), Binder.getCallingPid(), processName, heartBeat);
if (applicationService != null) binder = applicationService.asBinder();
} catch (RemoteException e) {
Log.e(TAG, Log.getStackTraceString(e));
}
if (binder != null && reply != null) {
reply.writeNoException();
Log.d(TAG, "got binder is " + binder);
reply.writeStrongBinder(binder);
return true;
}
return false;
}
break;
}
case ACTION_GET_BINDER: {
IBinder binder = null;
try {
String processName = data.readString();
IBinder heartBeat = data.readStrongBinder();
var applicationService = service == null ? null : service.requestApplicationService(Binder.getCallingUid(), Binder.getCallingPid(), processName, heartBeat);
if (applicationService != null) binder = applicationService.asBinder();
} catch (RemoteException e) {
Log.e(TAG, Log.getStackTraceString(e));
}
if (binder != null && reply != null) {
reply.writeNoException();
Log.d(TAG, "got binder is " + binder);
reply.writeStrongBinder(binder);
return true;
}
return false;
}
} catch (Throwable e) {
Log.e(TAG, "onTransact", e);
}
return false;
}