Skip to content

Commit

Permalink
Fix ProcessRecord pid/uid field for Android S
Browse files Browse the repository at this point in the history
  • Loading branch information
Tornaco committed Sep 25, 2021
1 parent bda54a9 commit 330b6f5
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
@@ -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
)
}
}
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion android/internal/Thanox-Internal

0 comments on commit 330b6f5

Please sign in to comment.