Support HarmonyOS (#1594)

Fix #1592
This commit is contained in:
LoveSy 2022-01-31 23:55:28 +08:00 committed by GitHub
parent cf3a25c2dd
commit 8a53627b43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 35 deletions

View File

@ -35,11 +35,12 @@
#define LOGE(...)
#else
#ifndef NDEBUG
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
#define LOGD(fmt, ...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, "%s:%d#%s" ": " fmt, __FILE_NAME__, __LINE__, __PRETTY_FUNCTION__ __VA_OPT__(,) __VA_ARGS__)
#define LOGV(fmt, ...) __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, "%s:%d#%s" ": " fmt, __FILE_NAME__, __LINE__, __PRETTY_FUNCTION__ __VA_OPT__(,) __VA_ARGS__)
#else
#define LOGD(...)
#define LOGV(...)
#endif
#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)

View File

@ -99,7 +99,7 @@ public class BridgeService {
@SuppressWarnings({"unused", "RedundantSuppression"})
public static boolean onTransact(@NonNull Parcel data, @Nullable Parcel reply, int flags) {
data.enforceInterface(DESCRIPTOR);
if (!ParcelUtils.safeEnforceInterface(data, DESCRIPTOR)) return false;
ACTION action = ACTION.values()[data.readInt()];
@ -174,9 +174,8 @@ public class BridgeService {
}
try {
String descriptor = ParcelUtils.readInterfaceDescriptor(data);
if (!"android.app.IActivityManager".equals(descriptor) &&
!"com.sonymobile.hookservice.HookActivityService".equals(descriptor)) {
if (!ParcelUtils.safeEnforceInterface(data, "android.app.IActivityManager") &&
!ParcelUtils.safeEnforceInterface(data, "com.sonymobile.hookservice.HookActivityService")) {
return false;
}
return ActivityController.replaceActivityController(data);
@ -197,30 +196,23 @@ public class BridgeService {
return false;
}
boolean res = false;
try {
String descriptor = ParcelUtils.readInterfaceDescriptor(data);
data.setDataPosition(0);
if (descriptor.equals(DESCRIPTOR)) {
res = onTransact(data, reply, flags);
}
try {
return onTransact(data, reply, flags);
} catch (Exception e) {
if ((flags & IBinder.FLAG_ONEWAY) != 0) {
Log.w(TAG, "Caught a Exception from the binder stub implementation. " + Log.getStackTraceString(e));
Log.w(TAG, "Caught a Exception from the binder stub implementation. ", e);
} else {
reply.setDataPosition(0);
reply.writeException(e);
}
res = true;
Log.w(TAG, "on transact", e);
return true;
}
if (res) {
} finally {
data.recycle();
reply.recycle();
}
return res;
}
@SuppressWarnings("unused")

View File

@ -20,22 +20,18 @@
package org.lsposed.lspd.service;
import android.annotation.SuppressLint;
import android.os.Build;
import android.os.Parcel;
import java.lang.reflect.Method;
public class ParcelUtils {
public static String readInterfaceDescriptor(Parcel parcel) {
parcel.readInt();
if (Build.VERSION.SDK_INT >= 29) {
parcel.readInt();
public static boolean safeEnforceInterface(Parcel parcel, String descriptor) {
try {
parcel.enforceInterface(descriptor);
return true;
} catch (Throwable e) {
return false;
}
if (Build.VERSION.SDK_INT >= 30) {
parcel.readInt();
}
return parcel.readString();
}
private static Method obtainMethod;