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(...) #define LOGE(...)
#else #else
#ifndef NDEBUG #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 #else
#define LOGD(...) #define LOGD(...)
#define LOGV(...)
#endif #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 LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN, 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__) #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)

View File

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

View File

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