Improve multiuser settings and notification

This commit is contained in:
topjohnwu 2017-05-28 00:16:10 +08:00
parent 2a7d996881
commit 44e36feb09
4 changed files with 47 additions and 24 deletions

View File

@ -83,6 +83,12 @@ public class SettingsActivity extends Activity {
setSummary(); setSummary();
// Disable dangerous settings in user mode if selected owner manage
if (getActivity().getApplicationInfo().uid > 99999) {
prefScreen.removePreference(magiskCategory);
prefScreen.removePreference(suCategory);
}
findPreference("clear").setOnPreferenceClickListener((pref) -> { findPreference("clear").setOnPreferenceClickListener((pref) -> {
Utils.clearRepoCache(getActivity()); Utils.clearRepoCache(getActivity());
return true; return true;

View File

@ -17,11 +17,13 @@ public class SuReceiver extends BroadcastReceiver {
private static final int NO_NOTIFICATION = 0; private static final int NO_NOTIFICATION = 0;
private static final int TOAST = 1; private static final int TOAST = 1;
private static final int NOTIFY_NORMAL_LOG = 0;
private static final int NOTIFY_USER_TOASTS = 1;
private static final int NOTIFY_USER_TO_OWNER = 2;
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
int fromUid, toUid, pid; int fromUid, toUid, pid, mode;
String command, action; String command, action;
Policy policy; Policy policy;
@ -29,6 +31,14 @@ public class SuReceiver extends BroadcastReceiver {
if (intent == null) return; if (intent == null) return;
mode = intent.getIntExtra("mode", -1);
if (mode < 0) return;
if (mode == NOTIFY_USER_TO_OWNER) {
magiskManager.toast(R.string.multiuser_hint_owner_request, Toast.LENGTH_LONG);
return;
}
fromUid = intent.getIntExtra("from.uid", -1); fromUid = intent.getIntExtra("from.uid", -1);
if (fromUid < 0) return; if (fromUid < 0) return;
if (fromUid == Process.myUid()) return; // Don't show anything if it's Magisk Manager if (fromUid == Process.myUid()) return; // Don't show anything if it's Magisk Manager
@ -64,10 +74,11 @@ public class SuReceiver extends BroadcastReceiver {
return; return;
} }
if (policy.notification && magiskManager.suNotificationType == TOAST) if (policy.notification && magiskManager.suNotificationType == TOAST) {
Toast.makeText(context, message, Toast.LENGTH_SHORT).show(); magiskManager.toast(message, Toast.LENGTH_SHORT);
}
if (policy.logging) { if (mode == NOTIFY_NORMAL_LOG && policy.logging) {
toUid = intent.getIntExtra("to.uid", -1); toUid = intent.getIntExtra("to.uid", -1);
if (toUid < 0) return; if (toUid < 0) return;
pid = intent.getIntExtra("pid", -1); pid = intent.getIntExtra("pid", -1);

View File

@ -55,6 +55,7 @@ public class SuRequestActivity extends Activity implements CallbackEvent.Listene
private MagiskManager magiskManager; private MagiskManager magiskManager;
private int uid; private int uid;
private boolean hasTimeout;
private Policy policy; private Policy policy;
private CountDownTimer timer; private CountDownTimer timer;
private CallbackEvent.Listener<Policy> self; private CallbackEvent.Listener<Policy> self;
@ -70,6 +71,7 @@ public class SuRequestActivity extends Activity implements CallbackEvent.Listene
Intent intent = getIntent(); Intent intent = getIntent();
socketPath = intent.getStringExtra("socket"); socketPath = intent.getStringExtra("socket");
hasTimeout = intent.getBooleanExtra("timeout", true);
self = this; self = this;
new FileObserver(socketPath) { new FileObserver(socketPath) {
@ -87,7 +89,13 @@ public class SuRequestActivity extends Activity implements CallbackEvent.Listene
new SocketManager(this).exec(); new SocketManager(this).exec();
} }
void showRequest() { private boolean cancelTimeout() {
timer.cancel();
deny_btn.setText(getString(R.string.deny));
return false;
}
private void showRequest() {
switch (magiskManager.suResponseType) { switch (magiskManager.suResponseType) {
case AUTO_DENY: case AUTO_DENY:
@ -126,17 +134,14 @@ public class SuRequestActivity extends Activity implements CallbackEvent.Listene
grant_btn.setOnClickListener(v -> handleAction(Policy.ALLOW)); grant_btn.setOnClickListener(v -> handleAction(Policy.ALLOW));
deny_btn.setOnClickListener(v -> handleAction(Policy.DENY)); deny_btn.setOnClickListener(v -> handleAction(Policy.DENY));
suPopup.setOnClickListener((v) -> { suPopup.setOnClickListener((v) -> cancelTimeout());
timer.cancel(); timeout.setOnTouchListener((v, event) -> cancelTimeout());
deny_btn.setText(getString(R.string.deny));
});
timeout.setOnTouchListener((v, event) -> {
timer.cancel();
deny_btn.setText(getString(R.string.deny));
return false;
});
if (hasTimeout) {
timer.start(); timer.start();
} else {
cancelTimeout();
}
} }
@Override @Override

View File

@ -162,6 +162,15 @@
<string name="superuser_notification">Superuser Notification</string> <string name="superuser_notification">Superuser Notification</string>
<string name="request_timeout_summary">%1$s seconds</string> <string name="request_timeout_summary">%1$s seconds</string>
<string name="multiuser_mode">Multiuser Mode</string>
<string name="settings_owner_only">Device Owner Only</string>
<string name="settings_owner_manage">Device Owner Managed</string>
<string name="settings_user_independent">User Independent</string>
<string name="owner_only_summary">Only owner has root access</string>
<string name="owner_manage_summary">Only owner can manage root access and receive request prompts</string>
<string name="user_indepenent_summary">Each user has its own separate root rules</string>
<string name="multiuser_hint_owner_request">A request has been sent to the device owner. Please switch to the owner and grant the permission</string>
<string name="settings_development_category">App Development</string> <string name="settings_development_category">App Development</string>
<string name="settings_developer_logging_title">Enable advanced debug logging</string> <string name="settings_developer_logging_title">Enable advanced debug logging</string>
<string name="settings_developer_logging_summary">Check this to enable verbose logging</string> <string name="settings_developer_logging_summary">Check this to enable verbose logging</string>
@ -201,12 +210,4 @@
<string name="target_uid">Target UID:\u0020</string> <string name="target_uid">Target UID:\u0020</string>
<string name="command">Command:\u0020</string> <string name="command">Command:\u0020</string>
<string name="multiuser_mode">Multiuser Mode</string>
<string name="settings_owner_only">Device Owner Only</string>
<string name="settings_owner_manage">Device Owner Managed</string>
<string name="settings_user_independent">User Independent</string>
<string name="owner_only_summary">Only owner has root access</string>
<string name="owner_manage_summary">Only owner can manage root access and receive request prompts</string>
<string name="user_indepenent_summary">Each user has its own separate root rules</string>
</resources> </resources>