From 22191648694e3fa10a4d6bc592483f0138f91145 Mon Sep 17 00:00:00 2001 From: Jens Date: Tue, 19 Dec 2023 23:52:28 +0100 Subject: [PATCH] Set location service --- app/src/apkFlavor/AndroidManifest.xml | 8 +- app/src/fdroidFlavor/AndroidManifest.xml | 7 +- app/src/googlePlayFlavor/AndroidManifest.xml | 7 +- .../java/com/jens/automation2/Action.java | 14 ++- .../java/com/jens/automation2/Actions.java | 14 +++ .../ActivityManageActionLocationService.java | 64 +++++++++++ .../jens/automation2/ActivityManageRule.java | 40 +++++++ .../jens/automation2/ActivityPermissions.java | 15 ++- ...tivity_manage_action_location_servicei.xml | 100 ++++++++++++++++++ app/src/main/res/values/strings.xml | 8 ++ .../metadata/android/en-US/changelogs/138.txt | 4 +- 11 files changed, 274 insertions(+), 7 deletions(-) create mode 100644 app/src/main/java/com/jens/automation2/ActivityManageActionLocationService.java create mode 100644 app/src/main/res/layout/activity_manage_action_location_servicei.xml diff --git a/app/src/apkFlavor/AndroidManifest.xml b/app/src/apkFlavor/AndroidManifest.xml index 41dd23ad..026b6701 100644 --- a/app/src/apkFlavor/AndroidManifest.xml +++ b/app/src/apkFlavor/AndroidManifest.xml @@ -1,5 +1,7 @@ - + + + - + + - + + = Build.VERSION_CODES.Q) +// Miscellaneous.messageBox(getResources().getString(R.string.app_name), getResources().getString(R.string.android10WifiToggleNotice), ActivityManageActionWifi.this).show(); + + if(getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.Q) + tvWifiExplanation1.setVisibility(View.VISIBLE); + else + tvWifiExplanation1.setVisibility(View.GONE); + + bActionWifiSave.setOnClickListener(new View.OnClickListener() + { + @Override + public void onClick(View view) + { + Intent response = new Intent(); + response.putExtra(ActivityManageRule.intentNameActionParameter1, rbActionWifiOn.isChecked()); + response.putExtra(ActivityManageRule.intentNameActionParameter2, String.valueOf(chkWifiRunAsRoot.isChecked())); + setResult(RESULT_OK, response); + finish(); + } + }); + } +} diff --git a/app/src/main/java/com/jens/automation2/ActivityManageRule.java b/app/src/main/java/com/jens/automation2/ActivityManageRule.java index b5c62051..f8d5b78d 100644 --- a/app/src/main/java/com/jens/automation2/ActivityManageRule.java +++ b/app/src/main/java/com/jens/automation2/ActivityManageRule.java @@ -141,6 +141,8 @@ public class ActivityManageRule extends Activity final static int requestCodeTriggerCheckVariableEdit = 828; final static int requestCodeActionCopyTextToClipboardAdd = 829; final static int requestCodeActionCopyTextToClipboardEdit = 830; + final static int requestCodeActionSetLocationServiceAdd = 831; + final static int requestCodeActionSetLocationServiceEdit = 832; public static ActivityManageRule getInstance() { @@ -478,6 +480,12 @@ public class ActivityManageRule extends Activity actionCopyToClipboardIntent.putExtra(intentNameActionParameter2, a.getParameter2()); startActivityForResult(actionCopyToClipboardIntent, requestCodeActionCopyTextToClipboardEdit); break; + case setLocationService: + Intent actionSetLocationServiceIntent = new Intent(context, ActivityManageActionLocationService.class); + actionSetLocationServiceIntent.putExtra(intentNameActionParameter1, a.getParameter1()); +// actionSetLocationServiceIntent.putExtra(intentNameActionParameter2, a.getParameter2()); + startActivityForResult(actionSetLocationServiceIntent, requestCodeActionSetLocationServiceEdit); + break; default: Miscellaneous.logEvent("w", "Edit action", "Editing of action type " + a.getAction().toString() + " not implemented, yet.", 4); break; @@ -2047,6 +2055,32 @@ public class ActivityManageRule extends Activity ruleToEdit.getActionSet().get(editIndex).setParameter2(data.getStringExtra(intentNameActionParameter2)); } + this.refreshActionList(); + } + } + else if(requestCode == requestCodeActionSetLocationServiceAdd) + { + if(resultCode == RESULT_OK) + { + newAction.setParentRule(ruleToEdit); + newAction.setParameter1(data.getBooleanExtra(intentNameActionParameter1, false)); +// newAction.setParameter2(data.getStringExtra(intentNameActionParameter2)); + ruleToEdit.getActionSet().add(newAction); + this.refreshActionList(); + } + } + else if(requestCode == requestCodeActionSetLocationServiceEdit) + { + if(resultCode == RESULT_OK) + { + ruleToEdit.getActionSet().get(editIndex).setParentRule(ruleToEdit); + ruleToEdit.getActionSet().get(editIndex).setParameter1(data.getBooleanExtra(intentNameActionParameter1, false)); + +// if(data.hasExtra(intentNameActionParameter2)) +// { +// ruleToEdit.getActionSet().get(editIndex).setParameter2(data.getStringExtra(intentNameActionParameter2)); +// } + this.refreshActionList(); } } @@ -2360,6 +2394,12 @@ public class ActivityManageRule extends Activity ruleToEdit.getActionSet().add(newAction); refreshActionList(); } + else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.setLocationService.toString())) + { + newAction.setAction(Action_Enum.setLocationService); + Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionLocationService.class); + startActivityForResult(intent, requestCodeActionSetLocationServiceAdd); + } } }); diff --git a/app/src/main/java/com/jens/automation2/ActivityPermissions.java b/app/src/main/java/com/jens/automation2/ActivityPermissions.java index bd04ea0e..d3270ddf 100644 --- a/app/src/main/java/com/jens/automation2/ActivityPermissions.java +++ b/app/src/main/java/com/jens/automation2/ActivityPermissions.java @@ -164,7 +164,7 @@ public class ActivityPermissions extends Activity /* Filter location permission and only name it once */ - if(s.equals(Manifest.permission.ACCESS_COARSE_LOCATION) | s.equals(Manifest.permission.ACCESS_FINE_LOCATION)) + if(s.equals(Manifest.permission.ACCESS_COARSE_LOCATION) || s.equals(Manifest.permission.ACCESS_FINE_LOCATION)) { if(!locationPermissionExplained) { @@ -761,6 +761,10 @@ public class ActivityPermissions extends Activity break; case takeScreenshot: addToArrayListUnique(Manifest.permission.BIND_ACCESSIBILITY_SERVICE, requiredPermissions); + break; + case setLocationService: + addToArrayListUnique(Manifest.permission.WRITE_SECURE_SETTINGS, requiredPermissions); + break; default: break; } @@ -1014,6 +1018,10 @@ public class ActivityPermissions extends Activity for(String ruleName : getRulesUsing(Action.Action_Enum.takeScreenshot)) usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName)); break; + case Manifest.permission.WRITE_SECURE_SETTINGS: + for(String ruleName : getRulesUsing(Action.Action_Enum.setLocationService)) + usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName)); + break; } return usingElements; @@ -1104,6 +1112,11 @@ public class ActivityPermissions extends Activity permissionList.add(permission); } } + else if(permissionNames.equals(Manifest.permission.WRITE_SECURE_SETTINGS)) + { + Miscellaneous.messageBox(Miscellaneous.getAnyContext().getResources().getString(R.string.info), Miscellaneous.getAnyContext().getResources().getString(R.string.writeSecureSettingsNotice), Miscellaneous.getAnyContext()).show(); + return; + } else { if(!havePermission(permission, Miscellaneous.getAnyContext())) diff --git a/app/src/main/res/layout/activity_manage_action_location_servicei.xml b/app/src/main/res/layout/activity_manage_action_location_servicei.xml new file mode 100644 index 00000000..c31ec514 --- /dev/null +++ b/app/src/main/res/layout/activity_manage_action_location_servicei.xml @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +