Compare commits
No commits in common. "master" and "development-stable" have entirely different histories.
master
...
developmen
|
@ -145,7 +145,7 @@ fabric.properties
|
|||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/androidstudio
|
||||
|
||||
output-metadata.json
|
||||
|
||||
/app/app-release.apk
|
||||
Automation_settings.xml
|
||||
/app/googlePlayFlavor/
|
||||
|
|
|
@ -11,8 +11,8 @@ android {
|
|||
compileSdkVersion 31
|
||||
buildToolsVersion '29.0.2'
|
||||
useLibrary 'org.apache.http.legacy'
|
||||
versionCode 133
|
||||
versionName "1.7.17"
|
||||
versionCode 120
|
||||
versionName "1.7.6"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
@ -36,15 +36,9 @@ android {
|
|||
{
|
||||
dimension "version"
|
||||
versionNameSuffix "-googlePlay"
|
||||
targetSdkVersion 31
|
||||
targetSdkVersion 30
|
||||
}
|
||||
|
||||
/*
|
||||
targetSdkVersion is kept at 28 for as long as possible.
|
||||
If raised wifi cannot be switched on or off anymore without root permissions.
|
||||
In the Google version I'm forced to raise the value regularly.
|
||||
*/
|
||||
|
||||
fdroidFlavor
|
||||
{
|
||||
dimension "version"
|
||||
|
@ -78,9 +72,9 @@ dependencies {
|
|||
|
||||
//implementation "androidx.security:security-crypto:1.0.0"
|
||||
//implementation "androidx.security:security-identity-credential:1.0.0-alpha02"
|
||||
implementation 'androidx.appcompat:appcompat:1.4.2'
|
||||
implementation 'com.google.android.material:material:1.6.1'
|
||||
testImplementation 'junit:junit:4'
|
||||
implementation 'androidx.appcompat:appcompat:1.4.1'
|
||||
implementation 'com.google.android.material:material:1.3.0'
|
||||
testImplementation 'junit:junit:4.+'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"version": 3,
|
||||
"artifactType": {
|
||||
"type": "APK",
|
||||
"kind": "Directory"
|
||||
},
|
||||
"applicationId": "com.jens.automation2",
|
||||
"variantName": "googlePlayFlavorRelease",
|
||||
"elements": [
|
||||
{
|
||||
"type": "SINGLE",
|
||||
"filters": [],
|
||||
"attributes": [],
|
||||
"versionCode": 119,
|
||||
"versionName": "1.7.5-googlePlay",
|
||||
"outputFile": "app-googlePlayFlavor-release.apk"
|
||||
}
|
||||
],
|
||||
"elementType": "File"
|
||||
}
|
|
@ -66,10 +66,6 @@
|
|||
<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.QUERY_ALL_PACKAGES"/>
|
||||
<uses-permission android:name="android.permission.CALL_PHONE" />
|
||||
<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-feature
|
||||
android:name="android.hardware.telephony"
|
||||
|
@ -170,16 +166,6 @@
|
|||
<activity android:name=".ActivityManageActionVibrate" />
|
||||
<activity android:name=".ActivityManageActionControlMedia" />
|
||||
<activity android:name=".ActivityManageActionSendBroadcast" />
|
||||
<activity android:name=".ActivityManageActionRunExecutable" />
|
||||
<activity android:name=".ActivityManageActionWifi" />
|
||||
<activity android:name=".ActivityManageTriggerTethering" />
|
||||
<activity android:name=".ActivityManageActionWakeLock" />
|
||||
<activity android:name=".ActivityManageTriggerSubSystemState" />
|
||||
<activity android:name=".ActivityManageActionMakePhoneCall" />
|
||||
<activity android:name=".ActivityManageActionSetVariable" />
|
||||
<activity android:name=".ActivityManageTriggerCheckVariable" />
|
||||
<activity android:name=".ActivityManageActionCopyToClipboard" />
|
||||
|
||||
<activity
|
||||
android:name=".ActivityMainTabLayout"
|
||||
android:launchMode="singleTask">
|
||||
|
|
|
@ -107,7 +107,7 @@ public class Rule implements Comparable<Rule>
|
|||
}
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name.trim();
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public static void readFromFile()
|
||||
|
@ -347,16 +347,7 @@ public class Rule implements Comparable<Rule>
|
|||
if(oneTrigger.getTriggerType().equals(Trigger.Trigger_Enum.timeFrame))
|
||||
{
|
||||
if(oneTrigger.getTimeFrame().repetition > 0)
|
||||
{
|
||||
if(this.getLastExecution() != null)
|
||||
{
|
||||
Calendar now = Calendar.getInstance();
|
||||
if (this.getLastExecution().getTimeInMillis() + oneTrigger.getTimeFrame().getRepetition() * 1000 <= now.getTimeInMillis())
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if(oneTrigger.getTriggerType().equals(Trigger.Trigger_Enum.broadcastReceived))
|
||||
{
|
||||
|
@ -405,7 +396,7 @@ public class Rule implements Comparable<Rule>
|
|||
return true;
|
||||
}
|
||||
|
||||
Miscellaneous.logEvent("i", String.format(context.getResources().getString(R.string.ruleCheckOf), this.getName()), String.format(context.getResources().getString(R.string.ruleIsDeactivatedCantApply), this.getName()), 4);
|
||||
Miscellaneous.logEvent("i", String.format(context.getResources().getString(R.string.ruleCheckOf), this.getName()), String.format(context.getResources().getString(R.string.ruleIsDeactivatedCantApply), this.getName()), 3);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -476,9 +467,7 @@ public class Rule implements Comparable<Rule>
|
|||
{
|
||||
AutomationService service = AutomationService.getInstance();
|
||||
service.speak(messages[0], false);
|
||||
|
||||
if(Settings.showToasts)
|
||||
Toast.makeText(service, messages[0], Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(service, messages[0], Toast.LENGTH_LONG).show();
|
||||
|
||||
super.onProgressUpdate(messages);
|
||||
}
|
||||
|
|
|
@ -64,10 +64,6 @@
|
|||
<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.QUERY_ALL_PACKAGES"/>
|
||||
<uses-permission android:name="android.permission.CALL_PHONE" />
|
||||
<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-feature
|
||||
android:name="android.hardware.telephony"
|
||||
|
@ -168,15 +164,6 @@
|
|||
<activity android:name=".ActivityManageActionVibrate" />
|
||||
<activity android:name=".ActivityManageActionControlMedia" />
|
||||
<activity android:name=".ActivityManageActionSendBroadcast" />
|
||||
<activity android:name=".ActivityManageActionRunExecutable" />
|
||||
<activity android:name=".ActivityManageActionWifi" />
|
||||
<activity android:name=".ActivityManageTriggerTethering" />
|
||||
<activity android:name=".ActivityManageActionWakeLock" />
|
||||
<activity android:name=".ActivityManageTriggerSubSystemState" />
|
||||
<activity android:name=".ActivityManageActionMakePhoneCall" />
|
||||
<activity android:name=".ActivityManageActionSetVariable" />
|
||||
<activity android:name=".ActivityManageTriggerCheckVariable" />
|
||||
<activity android:name=".ActivityManageActionCopyToClipboard" />
|
||||
<activity
|
||||
android:name=".ActivityMainTabLayout"
|
||||
android:launchMode="singleTask">
|
||||
|
|
|
@ -104,7 +104,7 @@ public class Rule implements Comparable<Rule>
|
|||
}
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name.trim();
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public static void readFromFile()
|
||||
|
@ -393,7 +393,7 @@ public class Rule implements Comparable<Rule>
|
|||
return true;
|
||||
}
|
||||
|
||||
Miscellaneous.logEvent("i", String.format(context.getResources().getString(R.string.ruleCheckOf), this.getName()), String.format(context.getResources().getString(R.string.ruleIsDeactivatedCantApply), this.getName()), 4);
|
||||
Miscellaneous.logEvent("i", String.format(context.getResources().getString(R.string.ruleCheckOf), this.getName()), String.format(context.getResources().getString(R.string.ruleIsDeactivatedCantApply), this.getName()), 3);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -440,9 +440,7 @@ public class Rule implements Comparable<Rule>
|
|||
{
|
||||
AutomationService service = AutomationService.getInstance();
|
||||
service.speak(messages[0], false);
|
||||
|
||||
if(Settings.showToasts)
|
||||
Toast.makeText(service, messages[0], Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(service, messages[0], Toast.LENGTH_LONG).show();
|
||||
|
||||
super.onProgressUpdate(messages);
|
||||
}
|
||||
|
|
|
@ -64,8 +64,6 @@
|
|||
<uses-permission android:name="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"/>
|
||||
<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.READ_CALL_LOG" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
|
@ -113,7 +111,6 @@
|
|||
</intent-filter>
|
||||
</receiver>
|
||||
<receiver android:name=".receivers.PackageReplacedReceiver"
|
||||
android:exported="true"
|
||||
android:enabled="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
|
||||
|
@ -125,7 +122,6 @@
|
|||
|
||||
<receiver
|
||||
android:name=".DeviceAdmin"
|
||||
android:exported="true"
|
||||
android:description="@string/app_name"
|
||||
android:label="@string/app_name"
|
||||
android:permission= "android.permission.BIND_DEVICE_ADMIN" >
|
||||
|
@ -155,17 +151,8 @@
|
|||
<activity android:name=".ActivityManageActionVibrate" />
|
||||
<activity android:name=".ActivityManageActionControlMedia" />
|
||||
<activity android:name=".ActivityManageActionSendBroadcast" />
|
||||
<activity android:name=".ActivityManageActionRunExecutable" />
|
||||
<activity android:name=".ActivityManageActionWifi" />
|
||||
<activity android:name=".ActivityManageTriggerTethering" />
|
||||
<activity android:name=".ActivityManageActionWakeLock" />
|
||||
<activity android:name=".ActivityManageTriggerSubSystemState" />
|
||||
<activity android:name=".ActivityManageActionSetVariable" />
|
||||
<activity android:name=".ActivityManageTriggerCheckVariable" />
|
||||
<activity android:name=".ActivityManageActionCopyToClipboard" />
|
||||
<activity
|
||||
android:name=".ActivityMainTabLayout"
|
||||
android:exported="true"
|
||||
android:launchMode="singleTask">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
@ -214,7 +201,6 @@
|
|||
|
||||
<service
|
||||
android:name=".receivers.NotificationListener"
|
||||
android:exported="true"
|
||||
android:label="@string/app_name"
|
||||
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE" >
|
||||
<intent-filter>
|
||||
|
|
|
@ -107,7 +107,7 @@ public class Rule implements Comparable<Rule>
|
|||
}
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name.trim();
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public static void readFromFile()
|
||||
|
@ -396,7 +396,7 @@ public class Rule implements Comparable<Rule>
|
|||
return true;
|
||||
}
|
||||
|
||||
Miscellaneous.logEvent("i", String.format(context.getResources().getString(R.string.ruleCheckOf), this.getName()), String.format(context.getResources().getString(R.string.ruleIsDeactivatedCantApply), this.getName()), 4);
|
||||
Miscellaneous.logEvent("i", String.format(context.getResources().getString(R.string.ruleCheckOf), this.getName()), String.format(context.getResources().getString(R.string.ruleIsDeactivatedCantApply), this.getName()), 3);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -467,9 +467,7 @@ public class Rule implements Comparable<Rule>
|
|||
{
|
||||
AutomationService service = AutomationService.getInstance();
|
||||
service.speak(messages[0], false);
|
||||
|
||||
if(Settings.showToasts)
|
||||
Toast.makeText(service, messages[0], Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(service, messages[0], Toast.LENGTH_LONG).show();
|
||||
|
||||
super.onProgressUpdate(messages);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
|
||||
|
||||
</manifest>
|
|
@ -6,6 +6,8 @@ import android.os.Build;
|
|||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
|
||||
|
@ -50,12 +52,6 @@ public class Action
|
|||
createNotification,
|
||||
closeNotification,
|
||||
sendBroadcast,
|
||||
runExecutable,
|
||||
wakelock,
|
||||
setVariable,
|
||||
startPhoneCall,
|
||||
stopPhoneCall,
|
||||
copyToClipboard,
|
||||
sendTextMessage;
|
||||
|
||||
public String getFullName(Context context)
|
||||
|
@ -128,18 +124,6 @@ public class Action
|
|||
return context.getResources().getString(R.string.closeNotifications);
|
||||
case sendBroadcast:
|
||||
return context.getResources().getString(R.string.sendBroadcast);
|
||||
case runExecutable:
|
||||
return context.getResources().getString(R.string.runExecutable);
|
||||
case wakelock:
|
||||
return context.getResources().getString(R.string.keepDeviceAwake);
|
||||
case setVariable:
|
||||
return context.getResources().getString(R.string.setVariable);
|
||||
case startPhoneCall:
|
||||
return context.getResources().getString(R.string.startPhoneCall);
|
||||
case stopPhoneCall:
|
||||
return context.getResources().getString(R.string.endPhoneCall);
|
||||
case copyToClipboard:
|
||||
return context.getResources().getString(R.string.copyTextToClipboard);
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
|
@ -283,30 +267,6 @@ public class Action
|
|||
case sendBroadcast:
|
||||
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.sendBroadcast));
|
||||
break;
|
||||
case runExecutable:
|
||||
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.runExecutable));
|
||||
break;
|
||||
case wakelock:
|
||||
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.keepDeviceAwake) + " (" + String.valueOf(getParameter1()) + ")");
|
||||
break;
|
||||
case setVariable:
|
||||
String[] variableParams = getParameter2().split(actionParameter2Split);
|
||||
String addition;
|
||||
if (variableParams.length >= 2)
|
||||
addition = " (key: " + variableParams[0] + ", value: " + variableParams[1] + ")";
|
||||
else
|
||||
addition = " (delete key: " + variableParams[0] + ")";
|
||||
|
||||
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.setVariable) + addition);
|
||||
break;
|
||||
case startPhoneCall:
|
||||
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.startPhoneCall));
|
||||
break;
|
||||
case stopPhoneCall:
|
||||
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.endPhoneCall));
|
||||
break;
|
||||
case copyToClipboard:
|
||||
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.copyTextToClipboard));
|
||||
default:
|
||||
returnString.append(action.toString());
|
||||
}
|
||||
|
@ -365,24 +325,8 @@ public class Action
|
|||
if (parts.length > 4 && !StringUtils.isBlank(parts[4]))
|
||||
returnString.append(", " + Miscellaneous.getAnyContext().getResources().getString(R.string.ifString) + " " + Miscellaneous.getAnyContext().getResources().getString(R.string.text) + " " + Trigger.getMatchString(parts[3]) + " " + parts[4]);
|
||||
|
||||
if (parts.length >= 6)
|
||||
{
|
||||
if (!parts[5].equals(ActivityManageActionCloseNotification.dismissRegularString))
|
||||
{
|
||||
returnString.append(" " + String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.withButton), parts[5]));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (this.getAction().equals(Action_Enum.setWifi))
|
||||
{
|
||||
if (!StringUtils.isEmpty(this.parameter2))
|
||||
{
|
||||
boolean useRoot = Boolean.parseBoolean(this.parameter2);
|
||||
if (useRoot)
|
||||
returnString.append(" " + Miscellaneous.getAnyContext().getResources().getString(R.string.usingRoot));
|
||||
}
|
||||
}
|
||||
else if (this.getAction().equals(Action_Enum.controlMediaPlayback))
|
||||
else if(this.getAction().equals(Action_Enum.controlMediaPlayback))
|
||||
{
|
||||
returnString.append(": ");
|
||||
|
||||
|
@ -410,12 +354,6 @@ public class Action
|
|||
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.unknown));
|
||||
}
|
||||
}
|
||||
else if (this.getAction().equals(Action_Enum.sendBroadcast))
|
||||
{
|
||||
returnString.append(": " + parameter2.replace(Action.actionParameter2Split, "; ").replace(Action.intentPairSeparator, "/"));
|
||||
}
|
||||
else if(this.getAction().equals(Action_Enum.setVariable) || this.getAction().equals(Action_Enum.copyToClipboard))
|
||||
; // it's completed further above already
|
||||
else if (parameter2 != null && parameter2.length() > 0)
|
||||
returnString.append(": " + parameter2.replace(Action.actionParameter2Split, "; "));
|
||||
}
|
||||
|
@ -529,7 +467,7 @@ public class Action
|
|||
Actions.setUsbTethering(context, getParameter1(), toggleActionIfPossible);
|
||||
break;
|
||||
case setWifi:
|
||||
Actions.WifiStuff.setWifi(context, getParameter1(), getParameter2(), toggleActionIfPossible);
|
||||
Actions.WifiStuff.setWifi(context, getParameter1(), toggleActionIfPossible);
|
||||
break;
|
||||
case setWifiTethering:
|
||||
Actions.setWifiTethering(context, getParameter1(), toggleActionIfPossible);
|
||||
|
@ -607,31 +545,6 @@ public class Action
|
|||
case sendBroadcast:
|
||||
Actions.sendBroadcast(context, this.getParameter2());
|
||||
break;
|
||||
case runExecutable:
|
||||
String[] execParts = this.getParameter2().split(Action.actionParameter2Split);
|
||||
if(execParts.length == 1)
|
||||
Actions.runExecutable(context, this.getParameter1(), execParts[0], null);
|
||||
else if(execParts.length == 2)
|
||||
Actions.runExecutable(context, this.getParameter1(), execParts[0], execParts[1]);
|
||||
break;
|
||||
case wakelock:
|
||||
if(this.getParameter1())
|
||||
Actions.wakeLockStart(context, Long.parseLong(this.getParameter2()));
|
||||
else
|
||||
Actions.wakeLockStop();
|
||||
break;
|
||||
case setVariable:
|
||||
Actions.setVariable(this.getParameter2());
|
||||
break;
|
||||
case startPhoneCall:
|
||||
Actions.startPhoneCall(context, this.getParameter2());
|
||||
break;
|
||||
case stopPhoneCall:
|
||||
Actions.endPhoneCall(context);
|
||||
break;
|
||||
case copyToClipboard:
|
||||
Actions.copyToClipboard(context, Miscellaneous.replaceVariablesInText(this.getParameter2(), context));
|
||||
break;
|
||||
default:
|
||||
Miscellaneous.logEvent("w", "Action", context.getResources().getString(R.string.unknownActionSpecified), 3);
|
||||
break;
|
||||
|
@ -658,7 +571,7 @@ public class Action
|
|||
password = components[1];
|
||||
url = components[2];
|
||||
}
|
||||
else // compatibility for very old versions which haven't upgraded, yet.
|
||||
else
|
||||
url = components[0];
|
||||
|
||||
try
|
||||
|
|
|
@ -10,10 +10,13 @@ import android.bluetooth.BluetoothAdapter;
|
|||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothProfile;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.media.AudioManager;
|
||||
import android.media.MediaPlayer;
|
||||
import android.media.session.MediaController;
|
||||
import android.media.session.MediaSessionManager;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.Uri;
|
||||
import android.net.wifi.WifiManager;
|
||||
|
@ -23,8 +26,8 @@ import android.os.PowerManager.WakeLock;
|
|||
import android.os.VibrationEffect;
|
||||
import android.os.Vibrator;
|
||||
import android.provider.MediaStore;
|
||||
import android.service.notification.NotificationListenerService;
|
||||
import android.service.notification.StatusBarNotification;
|
||||
import android.telecom.TelecomManager;
|
||||
import android.telephony.SmsManager;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
@ -49,12 +52,7 @@ import org.apache.http.conn.ssl.SSLSocketFactory;
|
|||
import org.apache.http.conn.util.InetAddressUtils;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
@ -64,12 +62,8 @@ import java.net.NetworkInterface;
|
|||
import java.security.KeyStore;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
|
||||
|
@ -80,6 +74,10 @@ public class Actions
|
|||
public static AutomationService automationServerRef;
|
||||
public static Context context;
|
||||
private static Intent playMusicIntent;
|
||||
private static boolean suAvailable = false;
|
||||
private static String suVersion = null;
|
||||
private static String suVersionInternal = null;
|
||||
private static List<String> suResult = null;
|
||||
public final static String smsSeparator = "&sms&";
|
||||
public final static String dummyPackageString = "dummyPkg239asd";
|
||||
|
||||
|
@ -93,7 +91,6 @@ public class Actions
|
|||
|
||||
Miscellaneous.logEvent("w", "createNotification", "Creating notification with title " + elements[0] + " and text " + elements[1], 3);
|
||||
|
||||
// Create a new notification ID each time
|
||||
int notificationId = Math.round(Calendar.getInstance().getTimeInMillis()/1000);
|
||||
|
||||
try
|
||||
|
@ -112,8 +109,8 @@ public class Actions
|
|||
public static void closeNotification(Action action)
|
||||
{
|
||||
NotificationManager nm = (NotificationManager) Miscellaneous.getAnyContext().getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
// for(StatusBarNotification n : nm.getActiveNotifications())
|
||||
// {
|
||||
for(StatusBarNotification n : nm.getActiveNotifications())
|
||||
{
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
|
||||
{
|
||||
String[] params = action.getParameter2().split(Action.actionParameter2Split);
|
||||
|
@ -122,14 +119,11 @@ public class Actions
|
|||
String myTitleDir = params[1];
|
||||
String requiredTitle = params[2];
|
||||
String myTextDir = params[3];
|
||||
String requiredText = "";
|
||||
String method = ActivityManageActionCloseNotification.dismissRegularString;
|
||||
|
||||
if(params.length >= 5)
|
||||
String requiredText;
|
||||
if (params.length >= 5)
|
||||
requiredText = params[4];
|
||||
|
||||
if(params.length >= 6 && !params[5].equals(ActivityManageActionCloseNotification.dismissRegularString))
|
||||
method = params[5];
|
||||
else
|
||||
requiredText = "";
|
||||
|
||||
for (StatusBarNotification sbn : NotificationListener.getInstance().getActiveNotifications())
|
||||
{
|
||||
|
@ -183,82 +177,27 @@ public class Actions
|
|||
|
||||
Miscellaneous.logEvent("i", "NotificationCloseCheck", "All criteria matches. Closing notification: " + sbn.getNotification().toString(), 3);
|
||||
if(NotificationListener.getInstance() != null)
|
||||
{
|
||||
if(method == ActivityManageActionCloseNotification.dismissRegularString)
|
||||
NotificationListener.getInstance().dismissNotification(sbn);
|
||||
else
|
||||
NotificationListener.getInstance().clickNotificationButton(sbn, method);
|
||||
}
|
||||
NotificationListener.getInstance().dismissNotification(sbn);
|
||||
else
|
||||
Miscellaneous.logEvent("i", "NotificationCloseCheck", "NotificationListener instance is null. Can\'t close notification.", 3);
|
||||
}
|
||||
}
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendBroadcast(Context context, String action)
|
||||
{
|
||||
Miscellaneous.logEvent("i", "sendBroadcast", "Sending broadcast with action " + action, 5);
|
||||
Intent broadcastIntent = new Intent();
|
||||
|
||||
if(action.contains(Action.actionParameter2Split))
|
||||
{
|
||||
String[] parts = action.split(Action.actionParameter2Split);
|
||||
broadcastIntent.setAction(parts[0]);
|
||||
|
||||
String[] intentparts = parts[1].split(";");
|
||||
broadcastIntent = packParametersIntoIntent(broadcastIntent, intentparts, 0);
|
||||
}
|
||||
else
|
||||
broadcastIntent.setAction(action);
|
||||
|
||||
broadcastIntent.setAction(action);
|
||||
context.sendBroadcast(broadcastIntent);
|
||||
}
|
||||
|
||||
public static void setVariable(String parameter2)
|
||||
public static class WifiStuff
|
||||
{
|
||||
String[] parts = parameter2.split(Action.actionParameter2Split);
|
||||
|
||||
if(AutomationService.isMyServiceRunning(Miscellaneous.getAnyContext()))
|
||||
public static Boolean setWifi(Context context, Boolean desiredState, boolean toggleActionIfPossible)
|
||||
{
|
||||
Map<String,String> map = AutomationService.getInstance().getVariableMap();
|
||||
|
||||
if(parts.length > 1)
|
||||
map.put(parts[0], parts[1]);
|
||||
else
|
||||
map.remove(parts[0]);
|
||||
}
|
||||
|
||||
Miscellaneous.logEvent("i", "Variable", "Checking for applicable rules after variable has been set or deleted.", 2);
|
||||
List<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.checkVariable);
|
||||
for(int i=0; i<ruleCandidates.size(); i++)
|
||||
{
|
||||
if(ruleCandidates.get(i).haveEnoughPermissions() && ruleCandidates.get(i).getsGreenLight(AutomationService.getInstance()))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "Variable", "Rule " + ruleCandidates.get(i).getName() + " applies after variable has been set or deleted.", 2);
|
||||
ruleCandidates.get(i).activate(AutomationService.getInstance(), false);
|
||||
}
|
||||
}
|
||||
Miscellaneous.logEvent("i", "Variable", "Done checking for applicable rules after variable has been set or deleted.", 2);
|
||||
|
||||
}
|
||||
|
||||
public static class WifiStuff
|
||||
{
|
||||
public static Boolean setWifi(Context context, Boolean desiredState, String parameter2, boolean toggleActionIfPossible)
|
||||
{
|
||||
boolean forceUseRoot = false;
|
||||
|
||||
try
|
||||
{
|
||||
forceUseRoot = Boolean.parseBoolean(parameter2);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
if(context.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.Q || forceUseRoot)
|
||||
if(context.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.Q)
|
||||
return setWifiWithRoot(context, desiredState, toggleActionIfPossible);
|
||||
else
|
||||
return setWifiOldFashioned(context, desiredState, toggleActionIfPossible);
|
||||
|
@ -294,15 +233,8 @@ public class Actions
|
|||
{
|
||||
Miscellaneous.logEvent("i", "Wifi", "Changing wifi to " + String.valueOf(desiredState), 4);
|
||||
|
||||
try
|
||||
{
|
||||
if (desiredState && Settings.useWifiForPositioning)
|
||||
WifiBroadcastReceiver.startWifiReceiver(automationServerRef.getLocationProvider());
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Miscellaneous.logEvent("w", "setWifiOldFashioned()", Log.getStackTraceString(e), 4);
|
||||
}
|
||||
if (desiredState && Settings.useWifiForPositioning)
|
||||
WifiBroadcastReceiver.startWifiReceiver(automationServerRef.getLocationProvider());
|
||||
|
||||
WifiManager myWifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||
|
||||
|
@ -830,21 +762,29 @@ public class Actions
|
|||
return false;
|
||||
}
|
||||
|
||||
public static void setDoNotDisturb(Context context, int desiredDndMode)
|
||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||
public static void setDoNotDisturb(Context context, int desiredSetting)
|
||||
{
|
||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
||||
{
|
||||
/*
|
||||
if (!notificationManager.isNotificationPolicyAccessGranted())
|
||||
--> done externally
|
||||
*/
|
||||
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
|
||||
Miscellaneous.logEvent("i", context.getResources().getString(R.string.soundSettings), "Changing DND to " + String.valueOf(desiredDndMode), 4);
|
||||
NotificationManager mNotificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
mNotificationManager.setInterruptionFilter(desiredDndMode);
|
||||
// Check if the notification policy access has been granted for the app.
|
||||
/* if (!notificationManager.isNotificationPolicyAccessGranted())
|
||||
{
|
||||
Intent intent = new Intent(android.provider.Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS);
|
||||
startActivity(intent);
|
||||
return;
|
||||
}*/
|
||||
|
||||
notificationManager.setInterruptionFilter(desiredSetting);
|
||||
|
||||
/*if (notificationManager.getCurrentInterruptionFilter() == NotificationManager.INTERRUPTION_FILTER_ALL)
|
||||
{
|
||||
notificationManager.setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_NONE);
|
||||
}
|
||||
else
|
||||
Miscellaneous.logEvent("w", context.getResources().getString(R.string.soundSettings), "Cannot change DND to " + String.valueOf(desiredDndMode) + ". This Android version is too and doesn\'t have that feature, yet.", 4);
|
||||
{
|
||||
notificationManager.setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_ALL);
|
||||
}*/
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||
|
@ -981,6 +921,18 @@ public class Actions
|
|||
}
|
||||
}
|
||||
|
||||
public static void setDND(Context context, int desiredDndMode)
|
||||
{
|
||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
||||
{
|
||||
Miscellaneous.logEvent("i", context.getResources().getString(R.string.soundSettings), "Changing DND to " + String.valueOf(desiredDndMode), 4);
|
||||
NotificationManager mNotificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
mNotificationManager.setInterruptionFilter(desiredDndMode);
|
||||
}
|
||||
else
|
||||
Miscellaneous.logEvent("w", context.getResources().getString(R.string.soundSettings), "Cannot change DND to " + String.valueOf(desiredDndMode) + ". This Android version is too and doesn\'t have that feature, yet.", 4);
|
||||
}
|
||||
|
||||
public void useDownloadedWebpage(String result)
|
||||
{
|
||||
// Toast.makeText(context, "Result: " + result, Toast.LENGTH_LONG).show();
|
||||
|
@ -1048,6 +1000,8 @@ public class Actions
|
|||
{
|
||||
Intent externalActivityIntent;
|
||||
|
||||
int paramsStartIndex;
|
||||
|
||||
if (!startByAction)
|
||||
{
|
||||
// selected by activity
|
||||
|
@ -1059,6 +1013,8 @@ public class Actions
|
|||
|
||||
Miscellaneous.logEvent("i", "StartOtherApp", "Starting app by activity: " + packageName + " " + className, 3);
|
||||
|
||||
paramsStartIndex = 2;
|
||||
|
||||
externalActivityIntent = new Intent(Intent.ACTION_MAIN);
|
||||
externalActivityIntent.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
|
||||
|
@ -1086,27 +1042,9 @@ public class Actions
|
|||
externalActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
|
||||
// Pack intents
|
||||
externalActivityIntent = packParametersIntoIntent(externalActivityIntent, params, 3);
|
||||
|
||||
if (params[2].equals(ActivityManageActionStartActivity.startByActivityString))
|
||||
automationServerRef.startActivity(externalActivityIntent);
|
||||
if (params[2].equals(ActivityManageActionStartActivity.startByServiceString))
|
||||
automationServerRef.startService(externalActivityIntent);
|
||||
else
|
||||
automationServerRef.sendBroadcast(externalActivityIntent);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Miscellaneous.logEvent("e", "StartOtherApp", automationServerRef.getResources().getString(R.string.errorStartingOtherActivity) + ": " + Log.getStackTraceString(e), 2);
|
||||
Toast.makeText(automationServerRef, automationServerRef.getResources().getString(R.string.errorStartingOtherActivity) + ": " + e.getMessage(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
public static Intent packParametersIntoIntent(Intent intent, String[] params, int startIndex)
|
||||
{
|
||||
for (int i = startIndex; i < params.length; i++)
|
||||
{
|
||||
String[] singleParam = params[i].split(Action.intentPairSeparator);
|
||||
for (int i = 3; i < params.length; i++)
|
||||
{
|
||||
String[] singleParam = params[i].split(Action.intentPairSeparator);
|
||||
|
||||
/*Class c = Class.forName(singleParam[0]);
|
||||
for(Method m : c.getMethods())
|
||||
|
@ -1118,89 +1056,83 @@ public class Actions
|
|||
}
|
||||
}*/
|
||||
|
||||
if (singleParam[0].equals("boolean"))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3);
|
||||
intent.putExtra(singleParam[1], Boolean.parseBoolean(singleParam[2]));
|
||||
}
|
||||
else if (singleParam[0].equals("byte"))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3);
|
||||
intent.putExtra(singleParam[1], Byte.parseByte(singleParam[2]));
|
||||
}
|
||||
else if (singleParam[0].equals("char"))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3);
|
||||
intent.putExtra(singleParam[1], singleParam[2].charAt(0));
|
||||
}
|
||||
else if (singleParam[0].equals("CharSequence"))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3);
|
||||
intent.putExtra(singleParam[1], (CharSequence) singleParam[2]);
|
||||
}
|
||||
else if (singleParam[0].equals("double"))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3);
|
||||
intent.putExtra(singleParam[1], Double.parseDouble(singleParam[2]));
|
||||
}
|
||||
else if (singleParam[0].equals("float"))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3);
|
||||
intent.putExtra(singleParam[1], Float.parseFloat(singleParam[2]));
|
||||
}
|
||||
else if (singleParam[0].equals("int"))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3);
|
||||
intent.putExtra(singleParam[1], Integer.parseInt(singleParam[2]));
|
||||
}
|
||||
else if (singleParam[0].equals("long"))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3);
|
||||
intent.putExtra(singleParam[1], Long.parseLong(singleParam[2]));
|
||||
}
|
||||
else if (singleParam[0].equals("short"))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3);
|
||||
intent.putExtra(singleParam[1], Short.parseShort(singleParam[2]));
|
||||
}
|
||||
else if (singleParam[0].equals("Uri"))
|
||||
{
|
||||
try
|
||||
if (singleParam[0].equals("boolean"))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3);
|
||||
externalActivityIntent.putExtra(singleParam[1], Boolean.parseBoolean(singleParam[2]));
|
||||
}
|
||||
else if (singleParam[0].equals("byte"))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3);
|
||||
externalActivityIntent.putExtra(singleParam[1], Byte.parseByte(singleParam[2]));
|
||||
}
|
||||
else if (singleParam[0].equals("char"))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3);
|
||||
externalActivityIntent.putExtra(singleParam[1], singleParam[2].charAt(0));
|
||||
}
|
||||
else if (singleParam[0].equals("CharSequence"))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3);
|
||||
externalActivityIntent.putExtra(singleParam[1], (CharSequence) singleParam[2]);
|
||||
}
|
||||
else if (singleParam[0].equals("double"))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3);
|
||||
externalActivityIntent.putExtra(singleParam[1], Double.parseDouble(singleParam[2]));
|
||||
}
|
||||
else if (singleParam[0].equals("float"))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3);
|
||||
externalActivityIntent.putExtra(singleParam[1], Float.parseFloat(singleParam[2]));
|
||||
}
|
||||
else if (singleParam[0].equals("int"))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3);
|
||||
externalActivityIntent.putExtra(singleParam[1], Integer.parseInt(singleParam[2]));
|
||||
}
|
||||
else if (singleParam[0].equals("long"))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3);
|
||||
externalActivityIntent.putExtra(singleParam[1], Long.parseLong(singleParam[2]));
|
||||
}
|
||||
else if (singleParam[0].equals("short"))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3);
|
||||
externalActivityIntent.putExtra(singleParam[1], Short.parseShort(singleParam[2]));
|
||||
}
|
||||
else if (singleParam[0].equals("Uri"))
|
||||
{
|
||||
if (singleParam[1].equalsIgnoreCase("IntentData"))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with value " + singleParam[2] + " as standard data parameter.", 3);
|
||||
intent.setData(Uri.parse(Miscellaneous.replaceVariablesInText(singleParam[2], context)));
|
||||
|
||||
externalActivityIntent.setData(Uri.parse(singleParam[2]));
|
||||
}
|
||||
else
|
||||
{
|
||||
Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3);
|
||||
intent.putExtra(singleParam[1], Uri.parse(Miscellaneous.replaceVariablesInText(singleParam[2], context)));
|
||||
externalActivityIntent.putExtra(singleParam[1], Uri.parse(singleParam[2]));
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
else if (singleParam[0].equals("String"))
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3);
|
||||
externalActivityIntent.putExtra(singleParam[1], singleParam[2]);
|
||||
}
|
||||
else
|
||||
Miscellaneous.logEvent("w", "StartOtherApp", "Unknown type of parameter " + singleParam[0] + " found. Name " + singleParam[1] + " and value " + singleParam[2], 3);
|
||||
}
|
||||
else if (singleParam[0].equals("String"))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "StartOtherApp", "Adding parameter of type " + singleParam[0] + " with name " + singleParam[1] + " and value " + singleParam[2], 3);
|
||||
try
|
||||
{
|
||||
intent.putExtra(singleParam[1], Miscellaneous.replaceVariablesInText(singleParam[2], context));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
intent.putExtra(singleParam[1], singleParam[2]);
|
||||
}
|
||||
}
|
||||
else
|
||||
Miscellaneous.logEvent("w", "StartOtherApp", "Unknown type of parameter " + singleParam[0] + " found. Name " + singleParam[1] + " and value " + singleParam[2], 3);
|
||||
}
|
||||
|
||||
return intent;
|
||||
if (params[2].equals(ActivityManageActionStartActivity.startByActivityString))
|
||||
automationServerRef.startActivity(externalActivityIntent);
|
||||
else
|
||||
automationServerRef.sendBroadcast(externalActivityIntent);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Miscellaneous.logEvent("e", "StartOtherApp", automationServerRef.getResources().getString(R.string.errorStartingOtherActivity) + ": " + Log.getStackTraceString(e), 2);
|
||||
Toast.makeText(automationServerRef, automationServerRef.getResources().getString(R.string.errorStartingOtherActivity) + ": " + e.getMessage(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
public static void waitBeforeNextAction(Long waitTime)
|
||||
|
@ -1239,37 +1171,21 @@ public class Actions
|
|||
|
||||
public static void sendTextMessage(Context context, String[] parametersArray)
|
||||
{
|
||||
String phoneNumber, message, messageType = ActivityManageActionSendTextMessage.messageTypeSms, filePath = null;
|
||||
String phoneNumber, message;
|
||||
|
||||
phoneNumber = parametersArray[0];
|
||||
message = parametersArray[1];
|
||||
|
||||
if(parametersArray.length > 2)
|
||||
{
|
||||
messageType = parametersArray[2];
|
||||
|
||||
if(parametersArray.length > 3)
|
||||
filePath = parametersArray[3];
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
String textToSend = Miscellaneous.replaceVariablesInText(message, context);
|
||||
if(messageType.equals("sms"))
|
||||
sendSmsMessage(phoneNumber, textToSend);
|
||||
else
|
||||
sendMmsMessage(phoneNumber, textToSend, filePath);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Miscellaneous.logEvent("e", Miscellaneous.getAnyContext().getString(R.string.sendTextMessage), "Error in sendTextMessage: " + Log.getStackTraceString(e), 3);
|
||||
}
|
||||
}
|
||||
|
||||
private static void sendSmsMessage(String phoneNumber, String textToSend)
|
||||
{
|
||||
try
|
||||
{
|
||||
/*
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("sms:" + phoneNumber));
|
||||
intent.putExtra("sms_body", message);
|
||||
AutomationService.getInstance().startActivity(intent);
|
||||
*/
|
||||
|
||||
PendingIntent pi = PendingIntent.getActivity(context, 0, new Intent(context, Actions.class), 0);
|
||||
SmsManager sms = SmsManager.getDefault();
|
||||
sms.sendTextMessage(phoneNumber, null, textToSend, pi, null);
|
||||
|
@ -1280,26 +1196,6 @@ public class Actions
|
|||
}
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
private static void sendMmsMessage(String phoneNumber, String textToSend, String fileToBeAttached)
|
||||
{
|
||||
try
|
||||
{
|
||||
Miscellaneous.logEvent("i", "sendMmsMessage()", "Sending MMS message...", 2);
|
||||
// Uri contentUri = Uri.fromFile(new File(fileToBeAttached));
|
||||
String str2 = "send." + String.valueOf(Math.abs(new Random().nextLong())) + ".dat";
|
||||
Uri contentUri = new Uri.Builder().authority(context.getPackageName() + ".MmsFileProvider").path(str2).scheme("content").build();
|
||||
|
||||
// Bundle a3 = C3326a.m16196a(new C8792q("enableGroupMms", true), new C8792q("maxMessageSize", Integer.valueOf(C3664a.m17428d())));
|
||||
|
||||
SmsManager.getDefault().sendMultimediaMessage(context, contentUri, phoneNumber, null, null);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Miscellaneous.logEvent("e", "sendMmsMessage()", "Error in sendMmsMessage(): " + Log.getStackTraceString(e), 3);
|
||||
}
|
||||
}
|
||||
|
||||
private static class WakeUpDeviceClass implements Runnable
|
||||
{
|
||||
private long awakeTime;
|
||||
|
@ -1966,12 +1862,6 @@ public class Actions
|
|||
|
||||
protected static boolean executeCommandViaSu(String[] commands)
|
||||
{
|
||||
boolean suAvailable = false;
|
||||
String suVersion = null;
|
||||
String suVersionInternal = null;
|
||||
// List<String> suResult = null;
|
||||
int suResult;
|
||||
|
||||
boolean success = false;
|
||||
|
||||
try
|
||||
|
@ -1981,30 +1871,17 @@ public class Actions
|
|||
{
|
||||
suVersion = Shell.SU.version(false);
|
||||
suVersionInternal = Shell.SU.version(true);
|
||||
suResult = Shell.SU.run(commands);
|
||||
|
||||
Miscellaneous.logEvent("i", "executeCommandViaSu()", "suVersion: " + suVersion + ", suVersionInternal: " + suVersionInternal, 5);
|
||||
|
||||
// suResult = Shell.SU.run(commands);
|
||||
suResult = Shell.Pool.SU.run(commands);
|
||||
|
||||
// if (suResult != null)
|
||||
// success = true;
|
||||
|
||||
Miscellaneous.logEvent("i", "executeCommandViaSu()", "RC=" + String.valueOf(suResult), 3);
|
||||
|
||||
if(suResult == 0)
|
||||
if (suResult != null)
|
||||
success = true;
|
||||
}
|
||||
else
|
||||
Miscellaneous.logEvent("w", "executeCommandViaSu()", "su not available.", 4);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
success = false;
|
||||
}
|
||||
|
||||
Miscellaneous.logEvent("i", "executeCommandViaSu()", "Returning " + String.valueOf(success), 4);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
|
@ -2030,300 +1907,4 @@ public class Actions
|
|||
return android.provider.Settings.Global.getInt(context.getContentResolver(), android.provider.Settings.Global.AIRPLANE_MODE_ON, 0) != 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean runExecutable(Context context, boolean runAsRoot, String path, String parameters)
|
||||
{
|
||||
if(runAsRoot)
|
||||
{
|
||||
if(!StringUtils.isEmpty(parameters))
|
||||
return executeCommandViaSu(new String[] { path + " " + parameters });
|
||||
else
|
||||
return executeCommandViaSu(new String[] { path });
|
||||
}
|
||||
else
|
||||
{
|
||||
Object[] result;
|
||||
|
||||
File executable = new File(path);
|
||||
File workingDir = new File(executable.getParent());
|
||||
|
||||
if(!StringUtils.isEmpty(parameters))
|
||||
result = runExternalApplication(path, 0, workingDir, parameters);
|
||||
else
|
||||
result = runExternalApplication(path, 0, workingDir, null);
|
||||
|
||||
boolean execResult = (boolean) result[0];
|
||||
|
||||
return execResult;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param commandToExecute
|
||||
* @param timeout
|
||||
* @param params
|
||||
* @return Returns an array: 0=exit code, 1=cmdline output
|
||||
*/
|
||||
public static Object[] runExternalApplication(String commandToExecute, long timeout, File workingDirectory, String params)
|
||||
{
|
||||
/*
|
||||
* Classes stolen from https://github.com/stleary/JSON-java
|
||||
*/
|
||||
|
||||
String fullCommand;
|
||||
|
||||
if(!StringUtils.isEmpty(params))
|
||||
fullCommand = commandToExecute + " " + params;
|
||||
else
|
||||
fullCommand = commandToExecute;
|
||||
|
||||
Miscellaneous.logEvent("i", "Running executable", "Running external application " + fullCommand, 4);
|
||||
|
||||
Object[] returnObject = new Object[2];
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
String line = null;
|
||||
OutputStream stdin = null;
|
||||
InputStream stderr = null;
|
||||
InputStream stdout = null;
|
||||
|
||||
try
|
||||
{
|
||||
Process process = null;
|
||||
|
||||
if(workingDirectory != null)
|
||||
process = Runtime.getRuntime().exec(fullCommand, null, workingDirectory);
|
||||
else
|
||||
process = Runtime.getRuntime().exec(fullCommand);
|
||||
stdin = process.getOutputStream ();
|
||||
stderr = process.getErrorStream ();
|
||||
stdout = process.getInputStream ();
|
||||
|
||||
// "write" the parms into stdin
|
||||
/*line = "param1" + "\n";
|
||||
stdin.write(line.getBytes() );
|
||||
stdin.flush();
|
||||
|
||||
line = "param2" + "\n";
|
||||
stdin.write(line.getBytes() );
|
||||
stdin.flush();
|
||||
|
||||
line = "param3" + "\n";
|
||||
stdin.write(line.getBytes() );
|
||||
stdin.flush();*/
|
||||
|
||||
stdin.close();
|
||||
|
||||
// clean up if any output in stdout
|
||||
BufferedReader brCleanUp = new BufferedReader (new InputStreamReader (stdout));
|
||||
while ((line = brCleanUp.readLine ()) != null)
|
||||
{
|
||||
Miscellaneous.logEvent ("i", "Running executable", "[Stdout] " + line, 4);
|
||||
output.append(line);
|
||||
}
|
||||
brCleanUp.close();
|
||||
|
||||
// clean up if any output in stderr
|
||||
brCleanUp = new BufferedReader (new InputStreamReader(stderr));
|
||||
while ((line = brCleanUp.readLine ()) != null)
|
||||
{
|
||||
Miscellaneous.logEvent ("i", "Running executable", "[Stderr] " + line, 4);
|
||||
output.append(line);
|
||||
}
|
||||
brCleanUp.close();
|
||||
|
||||
try
|
||||
{
|
||||
// Wait for the process to exit, we want the return code
|
||||
if(timeout > 0 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(!process.waitFor(timeout, TimeUnit.MILLISECONDS))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "Running executable", "Timeout of " + String.valueOf(timeout) + " ms reached. Killing check attempt.", 3);
|
||||
process.destroyForcibly();
|
||||
}
|
||||
}
|
||||
catch(NoSuchMethodError e)
|
||||
{
|
||||
process.waitFor();
|
||||
}
|
||||
}
|
||||
else
|
||||
process.waitFor();
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
Miscellaneous.logEvent("i", "Running executable", "Waiting for process failed: " + Log.getStackTraceString(e), 4);
|
||||
Miscellaneous.logEvent("i", "Running executable", Log.getStackTraceString(e), 1);
|
||||
}
|
||||
|
||||
if(process.exitValue() == 0)
|
||||
Miscellaneous.logEvent("i", "Running executable", "ReturnCode: " + String.valueOf(process.exitValue()), 4);
|
||||
else
|
||||
Miscellaneous.logEvent("i", "Running executable", "External execution (RC=" + String.valueOf(process.exitValue()) + ") returned error: " + output.toString(), 3);
|
||||
|
||||
returnObject[0] = process.exitValue();
|
||||
returnObject[1] = output.toString();
|
||||
|
||||
return returnObject;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
Miscellaneous.logEvent("e", "Running executable", Log.getStackTraceString(e), 1);
|
||||
}
|
||||
|
||||
Miscellaneous.logEvent("i", "Running executable", "Error running external application.", 1);
|
||||
|
||||
// if(slotMap != null)
|
||||
// for(String key : slotMap.keySet())
|
||||
// System.clearProperty(key);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isTetheringActive1(Context context)
|
||||