You've already forked Magisk
mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-09-06 06:36:58 +00:00
Add Superuser settings
This commit is contained in:
@@ -4,12 +4,16 @@ import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import com.topjohnwu.magisk.Global;
|
||||
|
||||
public class RequestActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Global.initSuConfigs(this);
|
||||
|
||||
Intent intent = getIntent();
|
||||
if (intent == null) {
|
||||
finish();
|
||||
|
||||
@@ -6,11 +6,17 @@ import android.content.Intent;
|
||||
import android.os.Process;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.topjohnwu.magisk.Global;
|
||||
import com.topjohnwu.magisk.R;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class SuReceiver extends BroadcastReceiver {
|
||||
|
||||
private static final int NO_NOTIFICATION = 0;
|
||||
private static final int TOAST = 1;
|
||||
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
int fromUid, toUid, pid;
|
||||
@@ -34,9 +40,11 @@ public class SuReceiver extends BroadcastReceiver {
|
||||
return;
|
||||
}
|
||||
|
||||
Global.initSuConfigs(context);
|
||||
|
||||
SuLogEntry log = new SuLogEntry(policy);
|
||||
|
||||
if (policy.notification) {
|
||||
if (policy.notification && Global.Configs.suNotificationType == TOAST) {
|
||||
String message;
|
||||
switch (action) {
|
||||
case "allow":
|
||||
|
||||
@@ -34,6 +34,10 @@ public class SuRequestActivity extends AppCompatActivity {
|
||||
private final static int SU_PROTOCOL_NAME_MAX = 20;
|
||||
private final static int SU_PROTOCOL_VALUE_MAX = 256;
|
||||
|
||||
private static final int PROMPT = 0;
|
||||
private static final int AUTO_DENY = 1;
|
||||
private static final int AUTO_ALLOW = 2;
|
||||
|
||||
@BindView(R.id.su_popup) LinearLayout suPopup;
|
||||
@BindView(R.id.timeout) Spinner timeout;
|
||||
@BindView(R.id.app_icon) ImageView appIcon;
|
||||
@@ -64,24 +68,41 @@ public class SuRequestActivity extends AppCompatActivity {
|
||||
new SocketManager().execute();
|
||||
}
|
||||
|
||||
void updateUI() throws Throwable {
|
||||
void showRequest() {
|
||||
|
||||
packageName = info.packageName;
|
||||
appName = info.applicationInfo.loadLabel(pm).toString();
|
||||
|
||||
switch (Global.Configs.suResponseType) {
|
||||
case AUTO_DENY:
|
||||
handleAction(false, 0);
|
||||
return;
|
||||
case AUTO_ALLOW:
|
||||
handleAction(true, 0);
|
||||
return;
|
||||
case PROMPT:
|
||||
default:
|
||||
}
|
||||
|
||||
setContentView(R.layout.activity_request);
|
||||
ButterKnife.bind(this);
|
||||
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.timeout, android.R.layout.simple_spinner_item);
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
timeout.setAdapter(adapter);
|
||||
|
||||
appIcon.setImageDrawable(info.applicationInfo.loadIcon(pm));
|
||||
appNameView.setText(appName);
|
||||
packageNameView.setText(packageName);
|
||||
|
||||
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.allow_timeout, android.R.layout.simple_spinner_item);
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
timeout.setAdapter(adapter);
|
||||
|
||||
timer = new CountDownTimer(Global.Configs.suRequestTimeout * 1000, 1000) {
|
||||
@Override
|
||||
public void onTick(long millisUntilFinished) {
|
||||
deny_btn.setText(getString(R.string.deny, "(" + millisUntilFinished / 1000 + ")"));
|
||||
deny_btn.setText(getString(R.string.deny_with_str, "(" + millisUntilFinished / 1000 + ")"));
|
||||
}
|
||||
@Override
|
||||
public void onFinish() {
|
||||
deny_btn.setText(getString(R.string.deny, "(0)"));
|
||||
deny_btn.setText(getString(R.string.deny_with_str, "(0)"));
|
||||
handleAction(false, -1);
|
||||
}
|
||||
};
|
||||
@@ -90,16 +111,15 @@ public class SuRequestActivity extends AppCompatActivity {
|
||||
deny_btn.setOnClickListener(v -> handleAction(false, timeoutList[timeout.getSelectedItemPosition()]));
|
||||
suPopup.setOnClickListener((v) -> {
|
||||
timer.cancel();
|
||||
deny_btn.setText(getString(R.string.deny, ""));
|
||||
deny_btn.setText(getString(R.string.deny));
|
||||
});
|
||||
timeout.setOnTouchListener((v, event) -> {
|
||||
timer.cancel();
|
||||
deny_btn.setText(getString(R.string.deny, ""));
|
||||
deny_btn.setText(getString(R.string.deny));
|
||||
return false;
|
||||
});
|
||||
|
||||
timer.start();
|
||||
|
||||
}
|
||||
|
||||
void handleAction(boolean action, int timeout) {
|
||||
@@ -175,14 +195,9 @@ public class SuRequestActivity extends AppCompatActivity {
|
||||
try {
|
||||
if (!result) throw new Throwable();
|
||||
String[] pkgs = pm.getPackagesForUid(uid);
|
||||
if (pkgs != null && pkgs.length > 0) {
|
||||
info = pm.getPackageInfo(pkgs[0], 0);
|
||||
packageName = pkgs[0];
|
||||
appName = info.applicationInfo.loadLabel(pm).toString();
|
||||
updateUI();
|
||||
}
|
||||
else
|
||||
throw new Throwable();
|
||||
if (pkgs == null || pkgs.length == 0) throw new Throwable();
|
||||
info = pm.getPackageInfo(pkgs[0], 0);
|
||||
showRequest();
|
||||
} catch (Throwable e) {
|
||||
handleAction(false, -1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user