Set location service

This commit is contained in:
Jens 2023-12-20 23:54:36 +01:00
parent 2219164869
commit 21f4a7fd5c
9 changed files with 83 additions and 53 deletions

View File

@ -185,6 +185,7 @@
<activity android:name=".ActivityManageActionSetVariable" /> <activity android:name=".ActivityManageActionSetVariable" />
<activity android:name=".ActivityManageTriggerCheckVariable" /> <activity android:name=".ActivityManageTriggerCheckVariable" />
<activity android:name=".ActivityManageActionCopyToClipboard" /> <activity android:name=".ActivityManageActionCopyToClipboard" />
<activity android:name=".ActivityManageActionLocationService" />
<activity <activity
android:name=".ActivityMainTabLayout" android:name=".ActivityMainTabLayout"

View File

@ -182,6 +182,8 @@
<activity android:name=".ActivityManageActionSetVariable" /> <activity android:name=".ActivityManageActionSetVariable" />
<activity android:name=".ActivityManageTriggerCheckVariable" /> <activity android:name=".ActivityManageTriggerCheckVariable" />
<activity android:name=".ActivityManageActionCopyToClipboard" /> <activity android:name=".ActivityManageActionCopyToClipboard" />
<activity android:name=".ActivityManageActionLocationService" />
<activity <activity
android:name=".ActivityMainTabLayout" android:name=".ActivityMainTabLayout"
android:launchMode="singleTask"> android:launchMode="singleTask">

View File

@ -167,6 +167,8 @@
<activity android:name=".ActivityManageActionSetVariable" /> <activity android:name=".ActivityManageActionSetVariable" />
<activity android:name=".ActivityManageTriggerCheckVariable" /> <activity android:name=".ActivityManageTriggerCheckVariable" />
<activity android:name=".ActivityManageActionCopyToClipboard" /> <activity android:name=".ActivityManageActionCopyToClipboard" />
<activity android:name=".ActivityManageActionLocationService" />
<activity <activity
android:name=".ActivityMainTabLayout" android:name=".ActivityMainTabLayout"
android:exported="true" android:exported="true"

View File

@ -317,10 +317,22 @@ public class Action
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.takeScreenshot)); returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.takeScreenshot));
break; break;
case setLocationService: case setLocationService:
if (this.getParameter1()) returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.setLocationService) + ": " );
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.actionSetLocationServiceOn)); switch(Integer.parseInt(getParameter2()))
else {
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.actionSetLocationServiceOff)); case android.provider.Settings.Secure.LOCATION_MODE_OFF:
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.off));
break;
case android.provider.Settings.Secure.LOCATION_MODE_SENSORS_ONLY:
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.LOCATION_MODE_SENSOR_ONLY));
break;
case android.provider.Settings.Secure.LOCATION_MODE_BATTERY_SAVING:
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.LOCATION_MODE_BATTERY_SAVING));
break;
case android.provider.Settings.Secure.LOCATION_MODE_HIGH_ACCURACY:
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.LOCATION_MODE_HIGH_ACCURACY));
break;
}
break; break;
default: default:
returnString.append(action.toString()); returnString.append(action.toString());
@ -429,7 +441,7 @@ public class Action
{ {
returnString.append(": " + parameter2.replace(Action.actionParameter2Split, "; ").replace(Action.intentPairSeparator, "/")); returnString.append(": " + parameter2.replace(Action.actionParameter2Split, "; ").replace(Action.intentPairSeparator, "/"));
} }
else if(this.getAction().equals(Action_Enum.setVariable) || this.getAction().equals(Action_Enum.copyToClipboard)) else if(this.getAction().equals(Action_Enum.setVariable) || this.getAction().equals(Action_Enum.copyToClipboard) || this.getAction().equals(Action_Enum.setLocationService))
; // it's completed further above already ; // it's completed further above already
else if (parameter2 != null && parameter2.length() > 0) else if (parameter2 != null && parameter2.length() > 0)
returnString.append(": " + parameter2.replace(Action.actionParameter2Split, "; ")); returnString.append(": " + parameter2.replace(Action.actionParameter2Split, "; "));
@ -651,7 +663,7 @@ public class Action
Actions.takeScreenshot(); Actions.takeScreenshot();
break; break;
case setLocationService: case setLocationService:
Actions.setLocationService(this.getParameter1(), AutomationService.getInstance()); Actions.setLocationService(Integer.parseInt(this.getParameter2()), AutomationService.getInstance());
break; break;
default: default:
Miscellaneous.logEvent("w", "Action", context.getResources().getString(R.string.unknownActionSpecified), 3); Miscellaneous.logEvent("w", "Action", context.getResources().getString(R.string.unknownActionSpecified), 3);

View File

@ -2360,17 +2360,17 @@ public class Actions
} }
} }
public static void setLocationService(boolean desiredState, Context context) public static void setLocationService(int desiredState, Context context)
{ {
if(desiredState) // 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()); // 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 // 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.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_ android.provider.Settings.Secure.putString(context.getContentResolver(), android.provider.Settings.Secure.LOCATION_MODE, String.valueOf(desiredState));
} }
} }

View File

@ -2,22 +2,18 @@ package com.jens.automation2;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.provider.Settings;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.CheckBox;
import android.widget.RadioButton; import android.widget.RadioButton;
import android.widget.TextView;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
public class ActivityManageActionLocationService extends Activity public class ActivityManageActionLocationService extends Activity
{ {
CheckBox chkWifiRunAsRoot; RadioButton rbActionLocationServiceOff, rbActionLocationServiceSensorsOnly, rbActionLocationServiceBatterySaving, rbActionLocationServiceHighAccuracy;
RadioButton rbActionWifiOn, rbActionWifiOff; Button bActionSetLocationServiceSave;
Button bActionWifiSave;
TextView tvWifiExplanation1, tvWifiExplanation2;
@Override @Override
protected void onCreate(@Nullable Bundle savedInstanceState) protected void onCreate(@Nullable Bundle savedInstanceState)
@ -26,36 +22,51 @@ public class ActivityManageActionLocationService extends Activity
Miscellaneous.setDisplayLanguage(this); Miscellaneous.setDisplayLanguage(this);
setContentView(R.layout.activity_manage_action_location_service); setContentView(R.layout.activity_manage_action_location_service);
chkWifiRunAsRoot = (CheckBox)findViewById(R.id.chkWifiRunAsRoot); rbActionLocationServiceOff = (RadioButton) findViewById(R.id.rbActionLocationServiceOff);
rbActionWifiOn = (RadioButton) findViewById(R.id.rbActionWifiOn); rbActionLocationServiceSensorsOnly = (RadioButton)findViewById(R.id.rbActionLocationServiceSensorsOnly);
rbActionWifiOff = (RadioButton)findViewById(R.id.rbActionWifiOff); rbActionLocationServiceBatterySaving = (RadioButton)findViewById(R.id.rbActionLocationServiceBatterySaving);
bActionWifiSave = (Button) findViewById(R.id.bActionWifiSave); rbActionLocationServiceHighAccuracy = (RadioButton)findViewById(R.id.rbActionLocationServiceHighAccuracy);
tvWifiExplanation1 = (TextView)findViewById(R.id.tvWifiExplanation1); bActionSetLocationServiceSave = (Button) findViewById(R.id.bActionSetLocationServiceSave);
tvWifiExplanation2 = (TextView)findViewById(R.id.tvWifiExplanation2);
Intent input = getIntent(); Intent input = getIntent();
if(input.hasExtra(ActivityManageRule.intentNameActionParameter1))
rbActionWifiOn.setChecked(input.getBooleanExtra(ActivityManageRule.intentNameActionParameter1, true));
if(input.hasExtra(ActivityManageRule.intentNameActionParameter2)) if(input.hasExtra(ActivityManageRule.intentNameActionParameter2))
chkWifiRunAsRoot.setChecked(Boolean.parseBoolean(input.getStringExtra(ActivityManageRule.intentNameActionParameter2))); {
String[] params = input.getStringExtra(ActivityManageRule.intentNameActionParameter2).split(Action.actionParameter2Split);
int desiredState = Integer.parseInt(params[0]);
// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) switch(desiredState)
// Miscellaneous.messageBox(getResources().getString(R.string.app_name), getResources().getString(R.string.android10WifiToggleNotice), ActivityManageActionWifi.this).show(); {
case Settings.Secure.LOCATION_MODE_OFF:
rbActionLocationServiceOff.setChecked(true);
break;
case Settings.Secure.LOCATION_MODE_SENSORS_ONLY:
rbActionLocationServiceSensorsOnly.setChecked(true);
break;
case Settings.Secure.LOCATION_MODE_BATTERY_SAVING:
rbActionLocationServiceBatterySaving.setChecked(true);
break;
case Settings.Secure.LOCATION_MODE_HIGH_ACCURACY:
rbActionLocationServiceHighAccuracy.setChecked(true);
break;
}
}
if(getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.Q) bActionSetLocationServiceSave.setOnClickListener(new View.OnClickListener()
tvWifiExplanation1.setVisibility(View.VISIBLE);
else
tvWifiExplanation1.setVisibility(View.GONE);
bActionWifiSave.setOnClickListener(new View.OnClickListener()
{ {
@Override @Override
public void onClick(View view) public void onClick(View view)
{ {
Intent response = new Intent(); Intent response = new Intent();
response.putExtra(ActivityManageRule.intentNameActionParameter1, rbActionWifiOn.isChecked()); if(rbActionLocationServiceOff.isChecked())
response.putExtra(ActivityManageRule.intentNameActionParameter2, String.valueOf(chkWifiRunAsRoot.isChecked())); response.putExtra(ActivityManageRule.intentNameActionParameter2, String.valueOf(Settings.Secure.LOCATION_MODE_OFF));
else if(rbActionLocationServiceSensorsOnly.isChecked())
response.putExtra(ActivityManageRule.intentNameActionParameter2, String.valueOf(Settings.Secure.LOCATION_MODE_SENSORS_ONLY));
else if(rbActionLocationServiceBatterySaving.isChecked())
response.putExtra(ActivityManageRule.intentNameActionParameter2, String.valueOf(Settings.Secure.LOCATION_MODE_BATTERY_SAVING));
else
response.putExtra(ActivityManageRule.intentNameActionParameter2, String.valueOf(Settings.Secure.LOCATION_MODE_HIGH_ACCURACY));
setResult(RESULT_OK, response); setResult(RESULT_OK, response);
finish(); finish();
} }

View File

@ -482,8 +482,8 @@ public class ActivityManageRule extends Activity
break; break;
case setLocationService: case setLocationService:
Intent actionSetLocationServiceIntent = new Intent(context, ActivityManageActionLocationService.class); Intent actionSetLocationServiceIntent = new Intent(context, ActivityManageActionLocationService.class);
actionSetLocationServiceIntent.putExtra(intentNameActionParameter1, a.getParameter1()); // actionSetLocationServiceIntent.putExtra(intentNameActionParameter1, a.getParameter1());
// actionSetLocationServiceIntent.putExtra(intentNameActionParameter2, a.getParameter2()); actionSetLocationServiceIntent.putExtra(intentNameActionParameter2, a.getParameter2());
startActivityForResult(actionSetLocationServiceIntent, requestCodeActionSetLocationServiceEdit); startActivityForResult(actionSetLocationServiceIntent, requestCodeActionSetLocationServiceEdit);
break; break;
default: default:
@ -2063,8 +2063,8 @@ public class ActivityManageRule extends Activity
if(resultCode == RESULT_OK) if(resultCode == RESULT_OK)
{ {
newAction.setParentRule(ruleToEdit); newAction.setParentRule(ruleToEdit);
newAction.setParameter1(data.getBooleanExtra(intentNameActionParameter1, false)); // newAction.setParameter1(data.getBooleanExtra(intentNameActionParameter1, false));
// newAction.setParameter2(data.getStringExtra(intentNameActionParameter2)); newAction.setParameter2(data.getStringExtra(intentNameActionParameter2));
ruleToEdit.getActionSet().add(newAction); ruleToEdit.getActionSet().add(newAction);
this.refreshActionList(); this.refreshActionList();
} }
@ -2074,12 +2074,12 @@ public class ActivityManageRule extends Activity
if(resultCode == RESULT_OK) if(resultCode == RESULT_OK)
{ {
ruleToEdit.getActionSet().get(editIndex).setParentRule(ruleToEdit); ruleToEdit.getActionSet().get(editIndex).setParentRule(ruleToEdit);
ruleToEdit.getActionSet().get(editIndex).setParameter1(data.getBooleanExtra(intentNameActionParameter1, false)); // ruleToEdit.getActionSet().get(editIndex).setParameter1(data.getBooleanExtra(intentNameActionParameter1, false));
// if(data.hasExtra(intentNameActionParameter2)) if(data.hasExtra(intentNameActionParameter2))
// { {
// ruleToEdit.getActionSet().get(editIndex).setParameter2(data.getStringExtra(intentNameActionParameter2)); ruleToEdit.getActionSet().get(editIndex).setParameter2(data.getStringExtra(intentNameActionParameter2));
// } }
this.refreshActionList(); this.refreshActionList();
} }
@ -2162,6 +2162,8 @@ public class ActivityManageRule extends Activity
items.add(new Item(typesLong[i].toString(), R.drawable.clipboard)); items.add(new Item(typesLong[i].toString(), R.drawable.clipboard));
else if(types[i].toString().equals(Action_Enum.takeScreenshot.toString())) else if(types[i].toString().equals(Action_Enum.takeScreenshot.toString()))
items.add(new Item(typesLong[i].toString(), R.drawable.copier)); items.add(new Item(typesLong[i].toString(), R.drawable.copier));
else if(types[i].toString().equals(Action_Enum.setLocationService.toString()))
items.add(new Item(typesLong[i].toString(), R.drawable.compass_small));
else else
items.add(new Item(typesLong[i].toString(), R.drawable.placeholder)); items.add(new Item(typesLong[i].toString(), R.drawable.placeholder));
} }

View File

@ -89,7 +89,7 @@
</TableLayout> </TableLayout>
<Button <Button
android:id="@+id/bActionWifiSave" android:id="@+id/bActionSetLocationServiceSave"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="@dimen/default_margin" android:layout_marginTop="@dimen/default_margin"

View File

@ -4,4 +4,4 @@
* Fixed: Storage permission might be displayed as not granted even if it was * 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: 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 * Added: Location service (GPS) can be toggled between states if WRITE_SECURE_SETTINGS has been granted from a computer