Start other service bugfix attempt

This commit is contained in:
Jens 2023-11-08 00:15:39 +01:00
parent f24c9f99dc
commit 7884358564
5 changed files with 75 additions and 32 deletions

View File

@ -1047,7 +1047,7 @@ public class Actions
try
{
Intent externalActivityIntent;
Intent externalApplicationIntent;
if (!startByAction)
{
@ -1060,15 +1060,13 @@ public class Actions
Miscellaneous.logEvent("i", "StartOtherApp", "Starting app by activity: " + packageName + " " + className, 3);
externalActivityIntent = new Intent(Intent.ACTION_MAIN);
externalActivityIntent.addCategory(Intent.CATEGORY_LAUNCHER);
externalApplicationIntent = new Intent(Intent.ACTION_MAIN);
externalApplicationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
// if(packageName.equals("dummyPkg"))
// externalActivityIntent.setAction(className);
// else
externalActivityIntent.setClassName(packageName, className);
if(packageName.equals("dummyPkg"))
externalApplicationIntent.setAction(className);
if (!Miscellaneous.doesActivityExist(externalActivityIntent, Miscellaneous.getAnyContext()))
if (!Miscellaneous.doesActivityExist(externalApplicationIntent, Miscellaneous.getAnyContext()))
Miscellaneous.logEvent("w", "StartOtherApp", "Activity not found: " + className, 2);
}
else
@ -1076,34 +1074,32 @@ public class Actions
// selected by action
Miscellaneous.logEvent("i", "StartOtherApp", "Starting app by action: " + param, 3);
externalActivityIntent = new Intent();
externalApplicationIntent = new Intent();
if (!params[0].equals(dummyPackageString))
externalActivityIntent.setPackage(params[0]);
externalApplicationIntent.setPackage(params[0]);
externalActivityIntent.setPackage("net.christianbeier.droidvnc_ng");
externalApplicationIntent.setAction(params[1]);
if (params[2].equals(ActivityManageActionStartActivity.startByServiceString))
if (params[2].equals(ActivityManageActionStartActivity.startByServiceString) || params[2].equals(ActivityManageActionStartActivity.startByForegroundServiceString))
{
//externalActivityIntent.setComponent(new ComponentName(params[0], params[1]));
externalActivityIntent.setComponent(new ComponentName("net.christianbeier.droidvnc_ng", ".MainService"));
externalApplicationIntent.setComponent(new ComponentName(params[0], params[2]));
}
externalActivityIntent.setAction(params[1]);
}
externalActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
externalApplicationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// Pack intents
externalActivityIntent = packParametersIntoIntent(externalActivityIntent, params, 3);
externalApplicationIntent = packParametersIntoIntent(externalApplicationIntent, params, 3);
if (params[2].equals(ActivityManageActionStartActivity.startByActivityString))
automationServerRef.startActivity(externalActivityIntent);
if (params[2].equals(ActivityManageActionStartActivity.startByServiceString))
//automationServerRef.startService(externalActivityIntent);
automationServerRef.startForegroundService(externalActivityIntent);
automationServerRef.startActivity(externalApplicationIntent);
else if (params[2].equals(ActivityManageActionStartActivity.startByServiceString))
automationServerRef.startService(externalApplicationIntent);
else if (params[2].equals(ActivityManageActionStartActivity.startByForegroundServiceString))
automationServerRef.startForegroundService(externalApplicationIntent);
else
automationServerRef.sendBroadcast(externalActivityIntent);
automationServerRef.sendBroadcast(externalApplicationIntent);
}
catch (Exception e)
{

View File

@ -48,17 +48,18 @@ public class ActivityManageActionStartActivity extends Activity
*/
ListView lvIntentPairs;
EditText etParameterName, etParameterValue, etPackageName, etActivityOrActionPath;
EditText etParameterName, etParameterValue, etPackageName, etActivityOrActionPath, etClassName;
Button bSelectApp, bAddIntentPair, bSaveActionStartOtherActivity, showStartProgramExamples;
Spinner spinnerParameterType;
boolean edit = false;
ProgressDialog progressDialog = null;
RadioButton rbStartAppSelectByActivity, rbStartAppSelectByAction, rbStartAppByActivity, rbStartAppByBroadcast, rbStartAppByService;
RadioButton rbStartAppSelectByActivity, rbStartAppSelectByAction, rbStartAppByActivity, rbStartAppByBroadcast, rbStartAppByService, rbStartAppByForegroundService;
final String urlShowExamples = "https://server47.de/automation/examples_startProgram.html";
final static String startByActivityString = "0";
final static String startByBroadcastString = "1";
final static String startByServiceString = "2";
final static String startByForegroundServiceString = "3";
final static int requestCodeForRequestQueryAllPackagesPermission = 4711;
@ -72,6 +73,7 @@ public class ActivityManageActionStartActivity extends Activity
lvIntentPairs = (ListView)findViewById(R.id.lvIntentPairs);
etParameterName = (EditText)findViewById(R.id.etParameterName);
etParameterValue = (EditText)findViewById(R.id.etParameterValue);
etClassName = (EditText)findViewById(R.id.etClassName);
bSelectApp = (Button)findViewById(R.id.bSelectApp);
bAddIntentPair = (Button)findViewById(R.id.bAddIntentPair);
bSaveActionStartOtherActivity = (Button)findViewById(R.id.bSaveActionStartOtherActivity);
@ -84,6 +86,7 @@ public class ActivityManageActionStartActivity extends Activity
rbStartAppByActivity = (RadioButton)findViewById(R.id.rbStartAppByActivity);
rbStartAppByBroadcast = (RadioButton)findViewById(R.id.rbStartAppByBroadcast);
rbStartAppByService = (RadioButton)findViewById(R.id.rbStartAppByService);
rbStartAppByForegroundService = (RadioButton)findViewById(R.id.rbStartAppByForegroundService);
intentTypeSpinnerAdapter = new ArrayAdapter<String>(this, R.layout.text_view_for_poi_listview_mediumtextsize, ActivityManageActionStartActivity.supportedIntentTypes);
spinnerParameterType.setAdapter(intentTypeSpinnerAdapter);
@ -227,17 +230,23 @@ public class ActivityManageActionStartActivity extends Activity
if (rbStartAppSelectByActivity.isChecked())
parameter2 += etPackageName.getText().toString() + ";" + etActivityOrActionPath.getText().toString();
else {
else
{
if (etPackageName.getText().toString() != null && etPackageName.getText().toString().length() > 0)
parameter2 += etPackageName.getText().toString() + ";" + etActivityOrActionPath.getText().toString();
else
parameter2 += Actions.dummyPackageString + ";" + etActivityOrActionPath.getText().toString();
// if(etClassName.getText().toString().length() > 0)
parameter2 += ";" + etClassName.getText().toString();
}
if (rbStartAppByActivity.isChecked())
parameter2 += ";" + startByActivityString;
else if(rbStartAppByService.isChecked())
parameter2 += ";" + startByServiceString;
else if(rbStartAppByForegroundService.isChecked())
parameter2 += ";" + startByForegroundServiceString;
else
parameter2 += ";" + startByBroadcastString;
@ -597,9 +606,19 @@ public class ActivityManageActionStartActivity extends Activity
String[] params = input.getStringExtra(ActivityManageRule.intentNameActionParameter2).split(";");
rbStartAppByActivity.setChecked(params[2].equals(startByActivityString));
rbStartAppByBroadcast.setChecked(params[2].equals(startByBroadcastString));
rbStartAppByService.setChecked(params[2].equals(startByServiceString));
if(Miscellaneous.isNumeric(params[2])) // old configuration file
{
rbStartAppByActivity.setChecked(params[2].equals(startByActivityString));
rbStartAppByBroadcast.setChecked(params[2].equals(startByBroadcastString));
rbStartAppByService.setChecked(params[2].equals(startByServiceString));
}
else
{
rbStartAppByActivity.setChecked(params[3].equals(startByActivityString));
rbStartAppByBroadcast.setChecked(params[3].equals(startByBroadcastString));
rbStartAppByService.setChecked(params[3].equals(startByServiceString));
rbStartAppByForegroundService.setChecked(params[3].equals(startByForegroundServiceString));
}
int startIndex = -1;
@ -614,10 +633,11 @@ public class ActivityManageActionStartActivity extends Activity
etPackageName.setText(params[0]);
etActivityOrActionPath.setText(params[1]);
etClassName.setText(params[2]);
}
if (params.length >= 3)
startIndex = 3;
if (params.length >= 4)
startIndex = 4;
if(startIndex > -1 && params.length > startIndex)
{

View File

@ -391,7 +391,7 @@ public class ReceiverCoordinator
}
}
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.headsetPlugged))
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.headsetPlugged))
{
if(!HeadphoneJackListener.isHeadphoneJackListenerActive())
{

View File

@ -135,6 +135,12 @@
android:layout_height="wrap_content"
android:text="@string/startAppByStartService" />
<RadioButton
android:id="@+id/rbStartAppByForegroundService"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/startAppByStartForegroundService" />
</RadioGroup>
</TableRow>
@ -187,6 +193,25 @@
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/className" />
<EditText
android:id="@+id/etClassName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">

View File

@ -887,4 +887,6 @@
<string name="variablesOnlyForTypes">Variables are only available for parameter types String and URI</string>
<string name="intentParametersHint">If you want to specify a parameter you also have to click \"Add intent pair\". Otherwise your changes will not be saved.</string>
<string name="wifiTriggerDisconnectionHint">This trigger will be valid if you just disconnected from the wifi specified above OR while the service is still starting and if you\'re not connected to any wifi. If you want the trigger to fire only when you\'re explicitly disconnecting from a certain wifi, add another trigger \"service is not starting\".</string>
<string name="className">Class full name</string>
<string name="startAppByStartForegroundService">by startForegroundService()</string>
</resources>