Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,5 @@ lint/tmp/
# lint/reports/

# Android Profiling
*.hprof
*.hprof
.idea
22 changes: 0 additions & 22 deletions .idea/compiler.xml

This file was deleted.

3 changes: 0 additions & 3 deletions .idea/copyright/profiles_settings.xml

This file was deleted.

20 changes: 0 additions & 20 deletions .idea/gradle.xml

This file was deleted.

2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.0'
classpath 'com.android.tools.build:gradle:8.8.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
12 changes: 6 additions & 6 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Jul 09 16:28:06 CST 2021
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
#Wed Jun 11 11:21:45 CST 2025
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
19 changes: 9 additions & 10 deletions open.netease.com/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 24
buildToolsVersion "26.0.1"
compileSdk 35
namespace "com.netease.open.pocoservice"

defaultConfig {
minSdkVersion 19
targetSdkVersion 29
minSdkVersion 21
targetSdkVersion 35
versionCode 1
versionName "1.0"

Expand All @@ -22,10 +22,9 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.+'
testCompile 'junit:junit:4.12'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.test:monitor:1.7.2'
implementation 'androidx.test.uiautomator:uiautomator:2.3.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation('androidx.test.espresso:espresso-core:3.6.1')
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.netease.open.libpoco;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;

/**
* Instrumentation test, which will execute on an Android device.
*
Expand Down
4 changes: 1 addition & 3 deletions open.netease.com/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.netease.open.libpoco">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application android:allowBackup="true" android:label="@string/app_name"
android:supportsRtl="true">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.netease.open.libpoco;

import org.junit.Test;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;

import org.junit.Test;

/**
* Example local unit test, which will execute on the development machine (host).
Expand Down
37 changes: 17 additions & 20 deletions pocoservice/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ android {
def cmd = 'git rev-list HEAD --count'
def gitVersion = cmd.execute().text.trim().toInteger()

compileSdkVersion 28
buildToolsVersion "25.0.3"
compileSdk 35
namespace "com.netease.open.pocoservice"
defaultConfig {
applicationId "com.netease.open.pocoservice"
minSdkVersion 19
targetSdkVersion 29
minSdkVersion 21
targetSdkVersion 35
versionCode gitVersion
versionName "1.0.0." + gitVersion
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand All @@ -26,20 +26,17 @@ android {
}

dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'androidx.test.uiautomator:uiautomator:2.2.0'
compile 'com.google.guava:guava:20.0'
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:25.3.1'
testCompile 'junit:junit:4.12'
compile 'com.nanohttpd:nanohttpd-webserver:2.2.0'
compile 'com.android.support:support-annotations:25.3.1'
compile 'com.android.support.test:runner:0.5'
compile 'com.android.support.test:rules:0.5'
compile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
compile 'org.apache.commons:commons-lang3:3.5'
compile project(':open.netease.com')
testImplementation 'junit:junit:4.13.2'
implementation 'androidx.test.uiautomator:uiautomator:2.3.0'
implementation 'com.google.guava:guava:27.0.1-android'
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.7.1'
implementation 'androidx.test:monitor:1.7.2'

implementation 'androidx.test.ext:junit:1.2.1'
implementation 'androidx.test.espresso:espresso-core:3.6.1'

implementation 'com.nanohttpd:nanohttpd-webserver:2.2.0'
implementation 'org.apache.commons:commons-lang3:3.5'
implementation project(':open.netease.com')
}
5 changes: 2 additions & 3 deletions pocoservice/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.netease.open.pocoservice">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Expand All @@ -21,7 +20,7 @@
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:persistent="true" >
<activity android:name=".TestActivity">
<activity android:name=".TestActivity" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
package com.netease.open.hrpc.backend;

import android.util.Log;

import java.util.ArrayList;
import java.util.List;

public class MethodMatcher {
private static final String TAG = "MethodMatcher-CGM";
// 改进的 primitiveTypeAssignableFrom 方法
private static boolean primitiveTypeAssignableFrom(Class<?> parType, Class<?> argType) {
// 如果都不是基本类型或包装类,使用 isAssignableFrom
if (!isPrimitiveOrWrapper(parType) && !isPrimitiveOrWrapper(argType)) {
return parType.isAssignableFrom(argType);
}

// 将包装类转换为对应的基本类型
parType = unwrap(parType);
argType = unwrap(argType);

// 如果目标类型不是基本类型,返回 false
if (!parType.isPrimitive()) {
return false;
}

// 基本类型宽化转换规则 (JLS §5.1.2)
if (parType == double.class) {
return argType == double.class || argType == float.class || argType == long.class ||
argType == int.class || argType == short.class || argType == byte.class;
} else if (parType == float.class) {
return argType == float.class || argType == long.class || argType == int.class ||
argType == short.class || argType == byte.class;
} else if (parType == long.class) {
return argType == long.class || argType == int.class || argType == short.class ||
argType == byte.class;
} else if (parType == int.class) {
return argType == int.class || argType == short.class || argType == byte.class;
} else if (parType == short.class) {
return argType == short.class || argType == byte.class;
} else if (parType == byte.class) {
return argType == byte.class;
} else if (parType == char.class) {
return argType == char.class;
} else if (parType == boolean.class) {
return argType == boolean.class;
}

return false;
}

// 判断是否是基本类型或包装类
private static boolean isPrimitiveOrWrapper(Class<?> type) {
return type.isPrimitive() ||
type == Integer.class || type == Double.class || type == Float.class ||
type == Long.class || type == Short.class || type == Byte.class ||
type == Character.class || type == Boolean.class;
}

// 将包装类转换为对应的基本类型
private static Class<?> unwrap(Class<?> type) {
if (type == Integer.class) return int.class;
if (type == Double.class) return double.class;
if (type == Float.class) return float.class;
if (type == Long.class) return long.class;
if (type == Short.class) return short.class;
if (type == Byte.class) return byte.class;
if (type == Character.class) return char.class;
if (type == Boolean.class) return boolean.class;
return type;
}

// 改进的匹配逻辑
public static java.lang.reflect.Method findMatchingMethod(List<java.lang.reflect.Method> _overloadMethods,
String _overloadMethodName,
List<Object> calcArguments) {
java.lang.reflect.Method func = null;
for (java.lang.reflect.Method m : _overloadMethods) {
Class<?>[] paramTypes = m.getParameterTypes();
if (paramTypes.length == calcArguments.size()) {
boolean matched = true;
Log.d(TAG, "method " + m.getName() + ", paramTypes.length=" + paramTypes.length);
for (int j = 0; j < paramTypes.length; j++) {
Class<?> parType = paramTypes[j];
Class<?> argType = calcArguments.get(j).getClass();
// 调试日志,显示每个参数类型和匹配结果
Log.d(TAG, String.format("Method: %s, Param %d: parType=%s, argType=%s, isAssignableFrom=%b, primitiveAssignable=%b",
_overloadMethodName, j, parType.getSimpleName(), argType.getSimpleName(),
parType.isAssignableFrom(argType), primitiveTypeAssignableFrom(parType, argType)));
// 检查数组类型是否一致
if (parType.isArray() != argType.isArray()) {
Log.d(TAG, String.format("Method: %s, Param %d: Array type mismatch", _overloadMethodName, j));
matched = false;
break;
}
// 检查类型兼容性
if (!parType.isAssignableFrom(argType) && !primitiveTypeAssignableFrom(parType, argType)) {
Log.d(TAG, String.format("Method: %s, Param %d: Type mismatch", _overloadMethodName, j));
matched = false;
break;
}
}
if (matched) {
func = m;
break;
}
} else {
Log.d(TAG, String.format("Method: %s, Parameter count mismatch: expected=%d, actual=%d",
_overloadMethodName, paramTypes.length, calcArguments.size()));
}
}
_overloadMethods.clear();
return func;
}

// 日志标签(根据你的环境定义)

// 测试代码
public static void test(String[] args) throws Exception {
// 模拟目标类
class Inputer {
public void swipe(double x1, double y1, double x2, double y2, double duration) {
System.out.println("Swiping...");
}
}

// 模拟 _overloadMethods
List<java.lang.reflect.Method> _overloadMethods = new ArrayList<>();
_overloadMethods.add(Inputer.class.getDeclaredMethod("swipe", double.class, double.class, double.class, double.class, double.class));

// 模拟 calcArguments(从 JSON 解析)
List<Object> calcArguments = new ArrayList<>();
calcArguments.add(0.5); // Double
calcArguments.add(0.5555555555555556); // Double
calcArguments.add(0.5); // Double
calcArguments.add(0); // Integer (JSON 解析的 0)
calcArguments.add(2); // Integer (JSON 解析的 2)

// 测试
String _overloadMethodName = "swipe";
java.lang.reflect.Method func = findMatchingMethod(_overloadMethods, _overloadMethodName, calcArguments);
System.out.println("Found method: " + (func != null ? func.getName() : "null"));
}
}
Loading