From 330b6f5226a5ea202f103c2a3d4307ac32838450 Mon Sep 17 00:00:00 2001 From: tornaco Date: Sat, 25 Sep 2021 20:40:11 +0800 Subject: [PATCH] Fix ProcessRecord pid/uid field for Android S --- .../thanos/core/process/ProcessRecord.java | 49 ++++++++++++++++--- .../src/main/java/util/XposedHelpersExt.java | 13 +++++ .../patch/common/am/XProcessRecord.kt | 20 +++++++- .../thanos/services/patch/common/wm/XTask.kt | 10 ++-- android/internal/Thanox-Internal | 2 +- 5 files changed, 79 insertions(+), 15 deletions(-) diff --git a/android/android_framework/base/src/main/java/github/tornaco/android/thanos/core/process/ProcessRecord.java b/android/android_framework/base/src/main/java/github/tornaco/android/thanos/core/process/ProcessRecord.java index 0b8631d0b..102799912 100644 --- a/android/android_framework/base/src/main/java/github/tornaco/android/thanos/core/process/ProcessRecord.java +++ b/android/android_framework/base/src/main/java/github/tornaco/android/thanos/core/process/ProcessRecord.java @@ -5,14 +5,8 @@ import java.util.Objects; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.ToString; import util.ObjectsUtils; -@AllArgsConstructor -@Getter -@ToString public class ProcessRecord implements Parcelable { private final String packageName; @@ -43,6 +37,15 @@ public ProcessRecord[] newArray(int size) { } }; + public ProcessRecord(String packageName, String processName, long pid, int uid, boolean notResponding, boolean crashing) { + this.packageName = packageName; + this.processName = processName; + this.pid = pid; + this.uid = uid; + this.notResponding = notResponding; + this.crashing = crashing; + } + @Override public int describeContents() { return 0; @@ -79,4 +82,38 @@ public int hashCode() { public boolean isMainProcess() { return ObjectsUtils.equals(packageName, processName); } + + public String getPackageName() { + return this.packageName; + } + + public String getProcessName() { + return this.processName; + } + + public long getPid() { + return this.pid; + } + + public int getUid() { + return this.uid; + } + + public boolean isNotResponding() { + return this.notResponding; + } + + public boolean isCrashing() { + return this.crashing; + } + + @Override + public String toString() { + return "ProcessRecord{" + + "packageName='" + packageName + '\'' + + ", processName='" + processName + '\'' + + ", pid=" + pid + + ", uid=" + uid + + '}'; + } } diff --git a/android/android_framework/base/src/main/java/util/XposedHelpersExt.java b/android/android_framework/base/src/main/java/util/XposedHelpersExt.java index 0796d077a..7cd5bef41 100644 --- a/android/android_framework/base/src/main/java/util/XposedHelpersExt.java +++ b/android/android_framework/base/src/main/java/util/XposedHelpersExt.java @@ -100,4 +100,17 @@ public static Class anyClassFromNames(ClassLoader classLoader, String... clas } throw new ClassNotFoundException(Arrays.toString(classNames)); } + + public static int getIntFieldWithPotentialNames(Object obj, String... potentialFieldNames) throws NoSuchFieldException { + for (String fieldName: potentialFieldNames) { + try { + int res = XposedHelpers.getIntField(obj, fieldName); + XLog.w("getIntField, find field for name: " + fieldName); + return res; + } catch (Throwable e){ + XLog.w("getIntField, no field for this name: " + fieldName); + } + } + throw new NoSuchFieldException(Arrays.toString(potentialFieldNames)); + } } diff --git a/android/android_framework/patch-common/src/main/java/github/tornaco/android/thanos/services/patch/common/am/XProcessRecord.kt b/android/android_framework/patch-common/src/main/java/github/tornaco/android/thanos/services/patch/common/am/XProcessRecord.kt index 14cba28e1..2b30aeec6 100644 --- a/android/android_framework/patch-common/src/main/java/github/tornaco/android/thanos/services/patch/common/am/XProcessRecord.kt +++ b/android/android_framework/patch-common/src/main/java/github/tornaco/android/thanos/services/patch/common/am/XProcessRecord.kt @@ -1,4 +1,22 @@ package github.tornaco.android.thanos.services.patch.common.am -class XProcessRecord { +import android.content.pm.ApplicationInfo +import github.tornaco.android.thanos.core.process.ProcessRecord +import util.XposedHelpers +import util.XposedHelpersExt + +object XProcessRecordHelper { + + @JvmStatic + fun Any.toXProcessRecord(): ProcessRecord { + val applicationInfo = XposedHelpers + .getObjectField(this, "info") as ApplicationInfo + val processName = XposedHelpers + .getObjectField(this, "processName") as String + val pid = XposedHelpersExt.getIntFieldWithPotentialNames(this, "pid", "mPid") + val uid = XposedHelpersExt.getIntFieldWithPotentialNames(this, "uid", "mUid") + return ProcessRecord( + applicationInfo.packageName, processName, pid.toLong(), uid, false, false + ) + } } \ No newline at end of file diff --git a/android/android_framework/patch-common/src/main/java/github/tornaco/android/thanos/services/patch/common/wm/XTask.kt b/android/android_framework/patch-common/src/main/java/github/tornaco/android/thanos/services/patch/common/wm/XTask.kt index 59ad62604..8c7e9bf39 100644 --- a/android/android_framework/patch-common/src/main/java/github/tornaco/android/thanos/services/patch/common/wm/XTask.kt +++ b/android/android_framework/patch-common/src/main/java/github/tornaco/android/thanos/services/patch/common/wm/XTask.kt @@ -1,8 +1,8 @@ package github.tornaco.android.thanos.services.patch.common.wm import android.content.Intent -import github.tornaco.android.thanos.core.util.OsUtils import util.XposedHelpers +import util.XposedHelpersExt data class XTask(val intent: Intent, val taskId: Int, val userId: Int) @@ -12,12 +12,8 @@ object XTaskHelper { fun Any.toXTask(): XTask { val intent = XposedHelpers.getObjectField(this, "intent") as Intent // TaskRecord class has merge with Task class since R. - val userIdFieldName = if (OsUtils.isROrAbove()) "mUserId" else "userId" - val userId = XposedHelpers.getIntField(this, userIdFieldName) - - val taskIdFieldName = if (OsUtils.isROrAbove()) "mTaskId" else "taskId" - val taskId = XposedHelpers.getIntField(this, taskIdFieldName) - + val userId = XposedHelpersExt.getIntFieldWithPotentialNames(this, "mUserId", "userId") + val taskId = XposedHelpersExt.getIntFieldWithPotentialNames(this, "mTaskId", "taskId") return XTask(intent, taskId, userId) } } diff --git a/android/internal/Thanox-Internal b/android/internal/Thanox-Internal index 44d505fad..a5b90b870 160000 --- a/android/internal/Thanox-Internal +++ b/android/internal/Thanox-Internal @@ -1 +1 @@ -Subproject commit 44d505fad46527edac87913315ffda5370d3daed +Subproject commit a5b90b870d206b1a51b8612c66d5c38348244a76