Set location service

This commit is contained in:
Jens 2023-12-19 23:52:28 +01:00
parent a8646ef61d
commit 2219164869
11 changed files with 274 additions and 7 deletions

View File

@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<supports-screens
android:anyDensity="true"
@ -70,6 +72,10 @@
<uses-permission android:name="android.permission.ANSWER_PHONE_CALLS" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission
android:name="android.permission.WRITE_SECURE_SETTINGS"
tools:ignore="ProtectedPermissions" />
<uses-feature
android:name="android.hardware.telephony"

View File

@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<supports-screens
android:anyDensity="true"
@ -68,6 +70,9 @@
<uses-permission android:name="android.permission.ANSWER_PHONE_CALLS" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission
android:name="android.permission.WRITE_SECURE_SETTINGS"
tools:ignore="ProtectedPermissions" />
<uses-feature
android:name="android.hardware.telephony"

View File

@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<supports-screens
android:anyDensity="true"
@ -65,6 +67,9 @@
<uses-permission android:name="com.wireguard.android.permission.CONTROL_TUNNELS"/>
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission
android:name="android.permission.WRITE_SECURE_SETTINGS"
tools:ignore="ProtectedPermissions" />
<application
android:allowBackup="true"

View File

@ -7,7 +7,6 @@ import android.util.Log;
import android.widget.Toast;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.methods.HttpGet;
import java.util.ArrayList;
import java.util.Locale;
@ -57,6 +56,7 @@ public class Action
stopPhoneCall,
copyToClipboard,
takeScreenshot,
setLocationService,
sendTextMessage;
public String getFullName(Context context)
@ -143,7 +143,8 @@ public class Action
return context.getResources().getString(R.string.copyTextToClipboard);
case takeScreenshot:
return context.getResources().getString(R.string.takeScreenshot);
case setLocationService:
return context.getResources().getString(R.string.setLocationService);
default:
return "Unknown";
}
@ -315,6 +316,12 @@ public class Action
case takeScreenshot:
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.takeScreenshot));
break;
case setLocationService:
if (this.getParameter1())
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.actionSetLocationServiceOn));
else
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.actionSetLocationServiceOff));
break;
default:
returnString.append(action.toString());
}
@ -643,6 +650,9 @@ public class Action
case takeScreenshot:
Actions.takeScreenshot();
break;
case setLocationService:
Actions.setLocationService(this.getParameter1(), AutomationService.getInstance());
break;
default:
Miscellaneous.logEvent("w", "Action", context.getResources().getString(R.string.unknownActionSpecified), 3);
break;

View File

@ -2359,4 +2359,18 @@ public class Actions
MyAccessibilityService.getInstance().performGlobalAction(AccessibilityService.GLOBAL_ACTION_TAKE_SCREENSHOT);
}
}
public static void setLocationService(boolean desiredState, Context context)
{
if(desiredState)
{
android.provider.Settings.Secure.putString(context.getContentResolver(), android.provider.Settings.Secure.LOCATION_MODE, new Integer(android.provider.Settings.Secure.LOCATION_MODE_HIGH_ACCURACY).toString());
}
else
{
android.provider.Settings.Secure.putString(context.getContentResolver(), android.provider.Settings.Secure.LOCATION_MODE, new Integer(android.provider.Settings.Secure.LOCATION_MODE_OFF).toString());
}
android.provider.Settings.Secure.LOCATION_MODE_
}
}

View File

@ -0,0 +1,64 @@
package com.jens.automation2;
import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.RadioButton;
import android.widget.TextView;
import androidx.annotation.Nullable;
public class ActivityManageActionLocationService extends Activity
{
CheckBox chkWifiRunAsRoot;
RadioButton rbActionWifiOn, rbActionWifiOff;
Button bActionWifiSave;
TextView tvWifiExplanation1, tvWifiExplanation2;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Miscellaneous.setDisplayLanguage(this);
setContentView(R.layout.activity_manage_action_location_service);
chkWifiRunAsRoot = (CheckBox)findViewById(R.id.chkWifiRunAsRoot);
rbActionWifiOn = (RadioButton) findViewById(R.id.rbActionWifiOn);
rbActionWifiOff = (RadioButton)findViewById(R.id.rbActionWifiOff);
bActionWifiSave = (Button) findViewById(R.id.bActionWifiSave);
tvWifiExplanation1 = (TextView)findViewById(R.id.tvWifiExplanation1);
tvWifiExplanation2 = (TextView)findViewById(R.id.tvWifiExplanation2);
Intent input = getIntent();
if(input.hasExtra(ActivityManageRule.intentNameActionParameter1))
rbActionWifiOn.setChecked(input.getBooleanExtra(ActivityManageRule.intentNameActionParameter1, true));
if(input.hasExtra(ActivityManageRule.intentNameActionParameter2))
chkWifiRunAsRoot.setChecked(Boolean.parseBoolean(input.getStringExtra(ActivityManageRule.intentNameActionParameter2)));
// if(Build.VERSION.SDK_INT >= 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();
}
});
}
}

View File

@ -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);
}
}
});

View File

@ -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()))

View File

@ -0,0 +1,100 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_margin="@dimen/default_margin" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="2"
android:textSize="25dp"
android:textStyle="bold"
android:layout_marginBottom="@dimen/default_margin"
android:text="@string/actionSetLocationService"/>
<TextView
android:id="@+id/tvWifiExplanation1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/wifiExplanation1" />
<TextView
android:id="@+id/tvWifiExplanation2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/default_margin"
android:text="@string/wifiExplanation2" />
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/default_margin"
android:stretchColumns="1"
android:shrinkColumns="1" >
<TableRow
android:layout_marginTop="@dimen/default_margin">
<TextView
android:layout_gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/default_margin"
android:text="@string/state" />
<RadioGroup
android:layout_gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/rbActionLocationServiceOff"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="@string/off" />
<RadioButton
android:id="@+id/rbActionLocationServiceSensorsOnly"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="@string/LOCATION_MODE_SENSOR_ONLY" />
<RadioButton
android:id="@+id/rbActionLocationServiceBatterySaving"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="@string/LOCATION_MODE_BATTERY_SAVING" />
<RadioButton
android:id="@+id/rbActionLocationServiceHighAccuracy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="@string/LOCATION_MODE_HIGH_ACCURACY" />
</RadioGroup>
</TableRow>
</TableLayout>
<Button
android:id="@+id/bActionWifiSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/default_margin"
android:text="@string/save" />
</LinearLayout>
</ScrollView>

View File

@ -898,4 +898,12 @@
<string name="accessibilityApiPermissionHint">After clicking OK you\'ll be sent to a system dialog. Please select Automation there and allow "Allow accessibility API".</string>
<string name="accessibility_service_explanation">Required for certain actions.</string>
<string name="noticeRestrictedPermissions">If you fail to grant one the following permission and a system message like \"Restricted permission\" you need to go to Android settings first, then applications, choose Automation. Now there should be 3 dots in the upper right corner. Click \"Allow restricted settings\". After that the necessary permission should be grantable. This should only apply to the APK version of the app, not the ones from F-Droid or Play Store.</string>
<string name="setLocationService">Set location service</string>
<string name="actionSetLocationServiceOn">turn location service on</string>
<string name="actionSetLocationServiceOff">turn location service off</string>
<string name="writeSecureSettingsNotice">This permission cannot be requested on your Android device. Instead you need to connect your device to a computer and grant the permission via ADB.</string>
<string name="actionSetLocationService">Location service</string>
<string name="LOCATION_MODE_SENSOR_ONLY">SENSOR_ONLY</string>
<string name="LOCATION_MODE_BATTERY_SAVING">BATTERY_SAVING</string>
<string name="LOCATION_MODE_HIGH_ACCURACY">HIGH_ACCURACY</string>
</resources>

View File

@ -1,5 +1,7 @@
* Fixed: Overlay permission for start other program action only required if startByActivity() is selected
* Fixed: Broadcast receiver trigger would not trigger anything, but crash
* Fixed: Bug in Android 14 (not in Automation!!!) required a change when dialing MMI codes containing a # character.
* Fixed: Storage permission might be displayed as not granted even if it was
* Added: One can now choose between GET and POST when using triggerURL action
* Added: new action -> take screenshot
* Added: new action -> take screenshot
* Added: Location service (GPS) can be turned on or off if WRITE_SECURE_SETTINGS has been granted from a computer