Skip to content

Commit

Permalink
Ask and exit gracefully when service could not be run with sufficient…
Browse files Browse the repository at this point in the history
… privileges
  • Loading branch information
Xtr126 committed Feb 21, 2024
1 parent bbcfde5 commit 860471d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/src/main/java/xtr/keymapper/TouchPointer.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ private void connectRemoteService(KeymapProfile profile) {
}
Log.e("startServer", e.toString(), e);
}

});
}

Expand Down
18 changes: 17 additions & 1 deletion app/src/main/java/xtr/keymapper/activity/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import xtr.keymapper.databinding.ActivityMainBinding;
import xtr.keymapper.editor.EditorActivity;
import xtr.keymapper.fragment.SettingsFragment;
import xtr.keymapper.server.RemoteServiceHelper;

public class MainActivity extends AppCompatActivity {
public TouchPointer pointerOverlay;
Expand Down Expand Up @@ -89,6 +90,8 @@ public void startPointer(){
setButtonState(false);
requestNotificationPermission();
}
if (!RemoteServiceHelper.isRootService)
alertRootAccessAndExit();
}

private void setButtonState(boolean start) {
Expand Down Expand Up @@ -144,13 +147,26 @@ public void alertRootAccessNotFound() {
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(this);
builder.setTitle(R.string.root_not_found_title)
.setMessage(R.string.root_not_found_message)
.setPositiveButton("OK", (dialog, which) -> {
.setPositiveButton(R.string.ok, (dialog, which) -> {
Intent launchIntent = MainActivity.this.getPackageManager().getLaunchIntentForPackage("me.weishu.kernelsu");
if (launchIntent != null) startActivity(launchIntent);
});
runOnUiThread(() -> builder.create().show());
}

public void alertRootAccessAndExit() {
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(MainActivity.this);
builder.setTitle(R.string.root_no_privileges_title)
.setMessage(R.string.root_no_privileges_message)
.setPositiveButton(R.string.ok, (dialog, which) -> {
finishAffinity();
System.exit(0);
})
.setNegativeButton(R.string.cancel, (dialog, which) -> {});
runOnUiThread(() -> builder.create().show());
}


@Override
protected void onDestroy() {
super.onDestroy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
public class RemoteServiceHelper {

private static IRemoteService service = null;
public static boolean isRootService = true;

public static void pauseKeymap(Context context){
RemoteServiceHelper.getInstance(context, service -> {
Expand Down Expand Up @@ -92,7 +93,8 @@ public static void getInstance(Context context, RootRemoteServiceCallback cb){
getInstance();
if (service != null) cb.onConnection(service);
else {
if (!Shell.isAppGrantedRoot()) System.exit(1);
Boolean hasRootAccess = Shell.isAppGrantedRoot();
if (hasRootAccess != null) isRootService = hasRootAccess;
RemoteServiceConnection connection = new RemoteServiceConnection(cb);
Intent intent = new Intent(context, RootRemoteService.class);
RootService.bind(intent, connection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import xtr.keymapper.server.RemoteServiceHelper;

public class InputListenerService extends InputMethodService {
// Input method to detect when user is inputting text
@Override
public void onDestroy() {
super.onDestroy();
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@
<string name="swipe_delay_ms">Swipe delay %d milliseconds</string>
<string name="profile_name">Profile Name</string>
<string name="root_not_found_title">Root access not found</string>
<string name="root_not_found_message">Root access is required for the keymapper to function. \n Please grant root access to XtMapper from KernelSU manager app:</string>
<string name="root_not_found_message">Root access is required for the keymapper to function. \n Please grant superuser to XtMapper from KernelSU manager app:</string>
<string name="root_no_privileges_title">Service failed to start as root</string>
<string name="root_no_privileges_message">
Unable to obtain privileges. Do you want to exit the application?\n
If you already granted superuser privileges, it might work after exiting and opening the app.
</string>
<string name="disable_auto_profile">Disable auto profiling</string>
<string name="touchpad_input">Touchpad Input</string>
<string name="launch_app">Launch App</string>
Expand Down

0 comments on commit 860471d

Please sign in to comment.