Skip to content

Commit

Permalink
[Ops] Return Remote server's UID instead of its type
Browse files Browse the repository at this point in the history
Signed-off-by: Muntashir Al-Islam <[email protected]>
  • Loading branch information
MuntashirAkon committed Apr 13, 2024
1 parent 5823eae commit af8e279
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private void onResponseReceived() {
if (mServiceBoundWatcher != null) {
// Should never be null
mServiceBoundWatcher.countDown();
} else throw new RuntimeException("AMService watcher should never be null!");
} else throw new RuntimeException("Service watcher should never be null!");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public void onReceive(Context context, @NonNull Intent intent) {
// Verify token before doing action
String token = intent.getStringExtra(ConfigParams.PARAM_TOKEN);
if (ServerConfig.getLocalToken().equals(token)) {
String type = intent.getStringExtra(ConfigParams.PARAM_TYPE);
Log.d(TAG, "onReceive --> %s %s", action, type);
// TODO: 9/4/24 Could be root, adb, or system types
String uidString = intent.getStringExtra(ConfigParams.PARAM_UID);
Log.d(TAG, "onReceive --> %s %s", action, uidString);
int uid = Integer.parseInt(uidString);

switch (action) {
case ServerActions.ACTION_SERVER_STARTED:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ public final class ConfigParams {
public static final String PARAM_PATH = "path";
public static final String PARAM_RUN_IN_BACKGROUND = "bgrun";
public static final String PARAM_TOKEN = "token";
public static final String PARAM_TYPE = "type";
public static final String PARAM_TYPE_ROOT = "root";
public static final String PARAM_TYPE_ADB = "adb";
public static final String PARAM_UID = "uid";

private boolean mIsDebug;
private String mAppName;
private String mPath;
private boolean mRunInBackground;
private String mToken;
private String mType;
private String mUid;

public ConfigParams() {
}
Expand All @@ -41,8 +39,8 @@ public void put(@NonNull String key, @NonNull String value) {
case PARAM_TOKEN:
mToken = value;
break;
case PARAM_TYPE:
mType = PARAM_TYPE_ADB.equals(value) ? PARAM_TYPE_ADB : PARAM_TYPE_ROOT;
case PARAM_UID:
mUid = value;
}
}

Expand All @@ -66,8 +64,8 @@ public String getToken() {
return mToken;
}

public String getType() {
return mType;
public String getUid() {
return mUid;
}

@NonNull
Expand All @@ -78,7 +76,7 @@ public String toString() {
", mPath='" + mPath + '\'' +
", mRunInBackground=" + mRunInBackground +
", mToken='" + mToken + '\'' +
", mType='" + mType + '\'' +
", mUid='" + mUid + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import io.github.muntashirakon.AppManager.server.common.ServerInfo;

import static io.github.muntashirakon.AppManager.server.common.ConfigParams.PARAM_TOKEN;
import static io.github.muntashirakon.AppManager.server.common.ConfigParams.PARAM_TYPE;
import static io.github.muntashirakon.AppManager.server.common.ConfigParams.PARAM_UID;

// Copyright 2017 Zheng Li
final class LifecycleAgent {
Expand Down Expand Up @@ -50,6 +50,6 @@ private Intent makeIntent(String action) {
return new Intent(action)
.setClassName(mConfigParams.getAppName(), ServerActions.PACKAGE_NAME + ".servermanager.ServerStatusChangeReceiver")
.putExtra(PARAM_TOKEN, mConfigParams.getToken())
.putExtra(PARAM_TYPE, mConfigParams.getType());
.putExtra(PARAM_UID, mConfigParams.getUid());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
import io.github.muntashirakon.AppManager.server.common.Constants;
import io.github.muntashirakon.AppManager.server.common.FLog;

import static io.github.muntashirakon.AppManager.server.common.ConfigParams.PARAM_TYPE;
import static io.github.muntashirakon.AppManager.server.common.ConfigParams.PARAM_TYPE_ADB;
import static io.github.muntashirakon.AppManager.server.common.ConfigParams.PARAM_TYPE_ROOT;
import static io.github.muntashirakon.AppManager.server.common.ConfigParams.PARAM_UID;

/**
* ServerRunner runs the server based on the parameters given. It takes two arguments:
Expand Down Expand Up @@ -70,13 +68,13 @@ public static void main(String[] args) {
String[] param = s.split(":");
configParams.put(param[0], param[1]);
}
configParams.put(PARAM_TYPE, Process.myUid() == 0 ? PARAM_TYPE_ROOT : PARAM_TYPE_ADB);
configParams.put(PARAM_UID, "" + Process.myUid());
// Set server info
LifecycleAgent.sServerInfo.startArgs = paramsStr;
LifecycleAgent.sServerInfo.startTime = System.currentTimeMillis();
LifecycleAgent.sServerInfo.startRealTime = SystemClock.elapsedRealtime();
// Print debug
System.out.println("Type: " + configParams.getType() + ", UID: " + Process.myUid());
System.out.println("UID: " + configParams.getUid() + ", UID: " + Process.myUid());
System.out.println("Params: " + configParams);
// Kill old server if requested
if (oldPid != -1) {
Expand Down

0 comments on commit af8e279

Please sign in to comment.