Compare commits
No commits in common. "master" and "master" have entirely different histories.
2
.gitignore
vendored
@ -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/
|
||||
|
@ -8,11 +8,11 @@ android {
|
||||
defaultConfig {
|
||||
applicationId "com.jens.automation2"
|
||||
minSdkVersion 16
|
||||
compileSdkVersion 33
|
||||
compileSdkVersion 31
|
||||
buildToolsVersion '29.0.2'
|
||||
useLibrary 'org.apache.http.legacy'
|
||||
versionCode 142
|
||||
versionName "1.8.1"
|
||||
versionCode 119
|
||||
versionName "1.7.5"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
@ -28,6 +28,7 @@ android {
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
|
||||
flavorDimensions "version"
|
||||
|
||||
productFlavors
|
||||
@ -36,15 +37,9 @@ android {
|
||||
{
|
||||
dimension "version"
|
||||
versionNameSuffix "-googlePlay"
|
||||
targetSdkVersion 33
|
||||
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"
|
||||
@ -62,7 +57,6 @@ android {
|
||||
abortOnError false
|
||||
checkReleaseBuilds false
|
||||
}
|
||||
namespace 'com.jens.automation2'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@ -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'
|
||||
}
|
20
app/googlePlayFlavor/release/output-metadata.json
Normal file
@ -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"
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.jens.automation2">
|
||||
|
||||
<supports-screens
|
||||
android:anyDensity="true"
|
||||
@ -52,6 +51,7 @@
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
|
||||
<!-- <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />-->
|
||||
<uses-permission android:name="android.permission.GET_TASKS" />
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||
<uses-permission android:name="android.permission.NFC" />
|
||||
@ -67,18 +67,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-permission android:name="android.permission.READ_CALENDAR" />
|
||||
<uses-permission
|
||||
android:name="android.permission.WRITE_SECURE_SETTINGS"
|
||||
tools:ignore="ProtectedPermissions" />
|
||||
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/>
|
||||
<!--android:maxSdkVersion="32" />
|
||||
<uses-permission android:name="android.permission.USE_EXACT_ALARM" />-->
|
||||
|
||||
|
||||
<uses-feature
|
||||
android:name="android.hardware.telephony"
|
||||
@ -96,7 +84,7 @@
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:allowClearUserData="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:icon="@drawable/gears"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme"
|
||||
android:networkSecurityConfig="@xml/network_security_config">
|
||||
@ -139,7 +127,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" />
|
||||
@ -148,11 +135,9 @@
|
||||
<receiver android:name=".receivers.DateTimeListener" />
|
||||
<receiver android:name=".receivers.ConnectivityReceiver" />
|
||||
<receiver android:name=".receivers.TimeZoneListener" />
|
||||
<receiver android:name=".receivers.CalendarReceiver" />
|
||||
|
||||
<receiver
|
||||
android:name=".DeviceAdmin"
|
||||
android:exported="true"
|
||||
android:description="@string/app_name"
|
||||
android:label="@string/app_name"
|
||||
android:permission= "android.permission.BIND_DEVICE_ADMIN" >
|
||||
@ -174,29 +159,14 @@
|
||||
<activity android:name=".ActivityManageTriggerTimeFrame" />
|
||||
<activity android:name=".ActivityControlCenter" />
|
||||
<activity android:name=".ActivityManageTriggerPhoneCall" />
|
||||
<activity android:name=".ActivityManageTriggerBroadcast" />
|
||||
<activity android:name=".ActivityManageActionBrightnessSetting" />
|
||||
<activity android:name=".ActivityManageActionCreateNotification" />
|
||||
<activity android:name=".ActivityManageTriggerDeviceOrientation" />
|
||||
<activity android:name=".ActivityHelp" />
|
||||
<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=".ActivityManageActionLocationService" />
|
||||
<activity android:name=".ActivityManageTriggerCharging" />
|
||||
|
||||
<activity
|
||||
android:name=".ActivityMainTabLayout"
|
||||
android:exported="true"
|
||||
android:launchMode="singleTask">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
@ -242,11 +212,9 @@
|
||||
<activity android:name=".ActivityVolumeTest" />
|
||||
<activity android:name=".ActivityPermissions"></activity>
|
||||
<activity android:name=".ActivityManageTriggerNotification" />
|
||||
<activity android:name=".ActivityManageTriggerCalendar" />
|
||||
|
||||
<service
|
||||
android:name=".receivers.NotificationListener"
|
||||
android:exported="true"
|
||||
android:label="@string/app_name"
|
||||
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE" >
|
||||
<intent-filter>
|
||||
@ -278,17 +246,6 @@
|
||||
android:exported="true"
|
||||
/>
|
||||
|
||||
<service android:name=".MyAccessibilityService"
|
||||
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
|
||||
<intent-filter>
|
||||
<action android:name="android.accessibilityservice.AccessibilityService" />
|
||||
</intent-filter>
|
||||
|
||||
<meta-data
|
||||
android:name="android.accessibilityservice"
|
||||
android:resource="@xml/config_accessibility_service" />
|
||||
</service>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
@ -18,7 +18,7 @@ public class MyGoogleApiClient
|
||||
public com.google.android.gms.appindexing.Action getIndexApiAction()
|
||||
{
|
||||
Thing object = new Thing.Builder()
|
||||
.setName("ActivityMainScreen Page")
|
||||
.setName("ActivityMainScreen Page") // TODO: Define a title for the content shown.
|
||||
// TODO: Make sure this auto-generated URL is correct.
|
||||
.setUrl(Uri.parse("http://[ENTER-YOUR-URL-HERE]"))
|
||||
.build();
|
||||
|
@ -10,12 +10,8 @@ import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.google.android.gms.location.DetectedActivity;
|
||||
import com.jens.automation2.receivers.ActivityDetectionReceiver;
|
||||
import com.jens.automation2.receivers.BroadcastListener;
|
||||
import com.jens.automation2.receivers.CalendarReceiver;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
@ -110,7 +106,7 @@ public class Rule implements Comparable<Rule>
|
||||
}
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name.trim();
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public static void readFromFile()
|
||||
@ -350,20 +346,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;
|
||||
}
|
||||
}
|
||||
else if(oneTrigger.getTriggerType().equals(Trigger.Trigger_Enum.broadcastReceived))
|
||||
{
|
||||
return oneTrigger.getTriggerParameter() == BroadcastListener.getInstance().hasBroadcastOccurredSince(oneTrigger.getTriggerParameter2(), getLastExecution());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -376,28 +359,23 @@ public class Rule implements Comparable<Rule>
|
||||
{
|
||||
if(hasNotAppliedSinceLastExecution())
|
||||
{
|
||||
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule \"" + getName() + "\" applies and has flipped since its last execution.", 4);
|
||||
return true;
|
||||
}
|
||||
else if(hasTriggerOfType(Trigger.Trigger_Enum.calendarEvent) && CalendarReceiver.mayRuleStillBeActivatedForPendingCalendarEvents(this))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule \"" + getName() + "\" applies, has not flipped since its last execution, but may still be executed for other calendar events.", 4);
|
||||
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule " + getName() + " applies and has flipped since its last execution.", 4);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule \"" + getName() + "\" has not flipped since its last execution.", 4);
|
||||
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule " + getName() + " has not flipped since its last execution.", 4);
|
||||
}
|
||||
else
|
||||
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule \"" + getName() + "\" does not apply.", 4);
|
||||
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule " + getName() + " does not apply.", 4);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean applies(Context context)
|
||||
{
|
||||
if(AutomationService.getInstance() == null)
|
||||
{
|
||||
Miscellaneous.logEvent("i", "RuleCheck", "Automation service not running. Rule \"" + getName() + "\" cannot apply.", 3);
|
||||
Miscellaneous.logEvent("i", "RuleCheck", "Automation service not running. Rule " + getName() + " cannot apply.", 3);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -408,12 +386,11 @@ public class Rule implements Comparable<Rule>
|
||||
if (!oneTrigger.applies(null, context))
|
||||
return false;
|
||||
}
|
||||
|
||||
Miscellaneous.logEvent("i", String.format(context.getResources().getString(R.string.ruleCheckOf), this.getName()), String.format("Rule \"%1$s\" generally applies currently. Checking if it's really due, yet will be done separately.", this.getName()), 3);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -484,9 +461,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);
|
||||
}
|
||||
@ -515,7 +490,7 @@ public class Rule implements Comparable<Rule>
|
||||
{
|
||||
boolean isActuallyToggleable = isActuallyToggable();
|
||||
|
||||
// boolean notLastActive = getLastActivatedRule() == null || !getLastActivatedRule().equals(Rule.this);
|
||||
boolean notLastActive = getLastActivatedRule() == null || !getLastActivatedRule().equals(Rule.this);
|
||||
boolean doToggle = ruleToggle && isActuallyToggleable;
|
||||
|
||||
String message;
|
||||
@ -529,29 +504,6 @@ public class Rule implements Comparable<Rule>
|
||||
if(Settings.startNewThreadForRuleActivation)
|
||||
publishProgress(message);
|
||||
|
||||
/*
|
||||
Make a note of Rule/CalendarEvent executed combinations
|
||||
*/
|
||||
if(Rule.this.hasTriggerOfType(Trigger.Trigger_Enum.calendarEvent))
|
||||
{
|
||||
for(CalendarReceiver.CalendarEvent event : CalendarReceiver.getApplyingCalendarEvents(Rule.this))
|
||||
{
|
||||
if(!CalendarReceiver.hasEventBeenUsedInRule(Rule.this, event))
|
||||
{
|
||||
/*
|
||||
Record only the first calendar event that matched because the rule may
|
||||
be executed once for every matching event.
|
||||
*/
|
||||
Miscellaneous.logEvent("i", "Rule", "Executing this rule run for calender event: " + event, 5);
|
||||
CalendarReceiver.addUsedPair(new CalendarReceiver.RuleEventPair(Rule.this, event));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Run actions one after another
|
||||
*/
|
||||
for(int i = 0; i< Rule.this.getActionSet().size(); i++)
|
||||
{
|
||||
try
|
||||
@ -811,71 +763,4 @@ public class Rule implements Comparable<Rule>
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object obj)
|
||||
{
|
||||
return this.getName().equals(((Rule)obj).getName());
|
||||
}
|
||||
|
||||
public boolean hasTriggerOfType(Trigger.Trigger_Enum queryType)
|
||||
{
|
||||
for(Trigger t : getTriggerSet())
|
||||
{
|
||||
if(t.getTriggerType().equals(queryType))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasActionOfType(Action.Action_Enum queryType)
|
||||
{
|
||||
for(Action a : getActionSet())
|
||||
{
|
||||
if(a.getAction().equals(queryType))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getAmountOfTriggersForType(Trigger.Trigger_Enum type)
|
||||
{
|
||||
int amount = 0;
|
||||
|
||||
for(Trigger t : getTriggerSet())
|
||||
{
|
||||
if(t.getTriggerType().equals(type))
|
||||
amount++;
|
||||
}
|
||||
|
||||
return amount;
|
||||
}
|
||||
|
||||
public int getAmountOfActionsForType(Action.Action_Enum type)
|
||||
{
|
||||
int amount = 0;
|
||||
|
||||
for(Action a : getActionSet())
|
||||
{
|
||||
if(a.getAction().equals(type))
|
||||
amount++;
|
||||
}
|
||||
|
||||
return amount;
|
||||
}
|
||||
|
||||
public static int getAmountOfActivatedRules()
|
||||
{
|
||||
int amount = 0;
|
||||
|
||||
for(Rule r : Rule.getRuleCollection())
|
||||
{
|
||||
if(r.isRuleActive())
|
||||
amount++;
|
||||
}
|
||||
|
||||
return amount;
|
||||
}
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.jens.automation2">
|
||||
|
||||
<supports-screens
|
||||
android:anyDensity="true"
|
||||
@ -52,6 +51,7 @@
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
|
||||
<!-- <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />-->
|
||||
<uses-permission android:name="android.permission.GET_TASKS" />
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||
<uses-permission android:name="android.permission.NFC" />
|
||||
@ -65,17 +65,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-permission android:name="android.permission.READ_CALENDAR" />
|
||||
<uses-permission
|
||||
android:name="android.permission.WRITE_SECURE_SETTINGS"
|
||||
tools:ignore="ProtectedPermissions" />
|
||||
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/>
|
||||
<!--android:maxSdkVersion="32" />
|
||||
<uses-permission android:name="android.permission.USE_EXACT_ALARM" />-->
|
||||
|
||||
<uses-feature
|
||||
android:name="android.hardware.telephony"
|
||||
@ -93,7 +82,7 @@
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:allowClearUserData="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:icon="@drawable/gears"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme"
|
||||
android:networkSecurityConfig="@xml/network_security_config">
|
||||
@ -136,7 +125,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" />
|
||||
@ -145,11 +133,9 @@
|
||||
<receiver android:name=".receivers.DateTimeListener" />
|
||||
<receiver android:name=".receivers.ConnectivityReceiver" />
|
||||
<receiver android:name=".receivers.TimeZoneListener" />
|
||||
<receiver android:name=".receivers.CalendarReceiver" />
|
||||
|
||||
<receiver
|
||||
android:name=".DeviceAdmin"
|
||||
android:exported="true"
|
||||
android:description="@string/app_name"
|
||||
android:label="@string/app_name"
|
||||
android:permission= "android.permission.BIND_DEVICE_ADMIN" >
|
||||
@ -171,29 +157,14 @@
|
||||
<activity android:name=".ActivityManageTriggerTimeFrame" />
|
||||
<activity android:name=".ActivityControlCenter" />
|
||||
<activity android:name=".ActivityManageTriggerPhoneCall" />
|
||||
<activity android:name=".ActivityManageTriggerBroadcast" />
|
||||
<activity android:name=".ActivityManageActionBrightnessSetting" />
|
||||
<activity android:name=".ActivityManageActionCreateNotification" />
|
||||
<activity android:name=".ActivityManageTriggerDeviceOrientation" />
|
||||
<activity android:name=".ActivityHelp" />
|
||||
<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=".ActivityManageActionLocationService" />
|
||||
<activity android:name=".ActivityManageTriggerCharging" />
|
||||
|
||||
<activity
|
||||
android:name=".ActivityMainTabLayout"
|
||||
android:exported="true"
|
||||
android:launchMode="singleTask">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
@ -239,11 +210,9 @@
|
||||
<activity android:name=".ActivityVolumeTest" />
|
||||
<activity android:name=".ActivityPermissions"></activity>
|
||||
<activity android:name=".ActivityManageTriggerNotification" />
|
||||
<activity android:name=".ActivityManageTriggerCalendar" />
|
||||
|
||||
<service
|
||||
android:name=".receivers.NotificationListener"
|
||||
android:exported="true"
|
||||
android:label="@string/app_name"
|
||||
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE" >
|
||||
<intent-filter>
|
||||
@ -263,17 +232,6 @@
|
||||
android:exported="true"
|
||||
/>
|
||||
|
||||
<service android:name=".MyAccessibilityService"
|
||||
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
|
||||
<intent-filter>
|
||||
<action android:name="android.accessibilityservice.AccessibilityService" />
|
||||
</intent-filter>
|
||||
|
||||
<meta-data
|
||||
android:name="android.accessibilityservice"
|
||||
android:resource="@xml/config_accessibility_service" />
|
||||
</service>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
@ -10,10 +10,6 @@ import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import com.jens.automation2.receivers.BroadcastListener;
|
||||
import com.jens.automation2.receivers.CalendarReceiver;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
@ -107,7 +103,7 @@ public class Rule implements Comparable<Rule>
|
||||
}
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name.trim();
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public static void readFromFile()
|
||||
@ -347,20 +343,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;
|
||||
}
|
||||
}
|
||||
else if(oneTrigger.getTriggerType().equals(Trigger.Trigger_Enum.broadcastReceived))
|
||||
{
|
||||
return oneTrigger.getTriggerParameter() == BroadcastListener.getInstance().hasBroadcastOccurredSince(oneTrigger.getTriggerParameter2(), getLastExecution());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -373,28 +356,23 @@ public class Rule implements Comparable<Rule>
|
||||
{
|
||||
if(hasNotAppliedSinceLastExecution())
|
||||
{
|
||||
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule \"" + getName() + "\" applies and has flipped since its last execution.", 4);
|
||||
return true;
|
||||
}
|
||||
else if(hasTriggerOfType(Trigger.Trigger_Enum.calendarEvent) && CalendarReceiver.mayRuleStillBeActivatedForPendingCalendarEvents(this))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule \"" + getName() + "\" applies, has not flipped since its last execution, but may still be executed for other calendar events.", 4);
|
||||
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule " + getName() + " applies and has flipped since its last execution.", 4);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule \"" + getName() + "\" has not flipped since its last execution.", 4);
|
||||
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule " + getName() + " has not flipped since its last execution.", 4);
|
||||
}
|
||||
else
|
||||
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule \"" + getName() + "\" does not apply.", 4);
|
||||
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule " + getName() + " does not apply.", 4);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean applies(Context context)
|
||||
{
|
||||
if(AutomationService.getInstance() == null)
|
||||
{
|
||||
Miscellaneous.logEvent("i", "RuleCheck", "Automation service not running. Rule \"" + getName() + "\" cannot apply.", 3);
|
||||
Miscellaneous.logEvent("i", "RuleCheck", "Automation service not running. Rule " + getName() + " cannot apply.", 3);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -405,12 +383,11 @@ public class Rule implements Comparable<Rule>
|
||||
if (!oneTrigger.applies(null, context))
|
||||
return false;
|
||||
}
|
||||
|
||||
Miscellaneous.logEvent("i", String.format(context.getResources().getString(R.string.ruleCheckOf), this.getName()), String.format("Rule \"%1$s\" generally applies currently. Checking if it's really due, yet will be done separately.", this.getName()), 3);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -457,9 +434,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);
|
||||
}
|
||||
@ -488,7 +463,7 @@ public class Rule implements Comparable<Rule>
|
||||
{
|
||||
boolean isActuallyToggleable = isActuallyToggable();
|
||||
|
||||
// boolean notLastActive = getLastActivatedRule() == null || !getLastActivatedRule().equals(Rule.this);
|
||||
boolean notLastActive = getLastActivatedRule() == null || !getLastActivatedRule().equals(Rule.this);
|
||||
boolean doToggle = ruleToggle && isActuallyToggleable;
|
||||
|
||||
String message;
|
||||
@ -502,29 +477,6 @@ public class Rule implements Comparable<Rule>
|
||||
if(Settings.startNewThreadForRuleActivation)
|
||||
publishProgress(message);
|
||||
|
||||
/*
|
||||
Make a note of Rule/CalendarEvent executed combinations
|
||||
*/
|
||||
if(Rule.this.hasTriggerOfType(Trigger.Trigger_Enum.calendarEvent))
|
||||
{
|
||||
for(CalendarReceiver.CalendarEvent event : CalendarReceiver.getApplyingCalendarEvents(Rule.this))
|
||||
{
|
||||
if(!CalendarReceiver.hasEventBeenUsedInRule(Rule.this, event))
|
||||
{
|
||||
/*
|
||||
Record only the first calendar event that matched because the rule may
|
||||
be executed once for every matching event.
|
||||
*/
|
||||
Miscellaneous.logEvent("i", "Rule", "Executing this rule run for calender event: " + event, 5);
|
||||
CalendarReceiver.addUsedPair(new CalendarReceiver.RuleEventPair(Rule.this, event));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Run actions one after another
|
||||
*/
|
||||
for(int i = 0; i< Rule.this.getActionSet().size(); i++)
|
||||
{
|
||||
try
|
||||
@ -784,71 +736,4 @@ public class Rule implements Comparable<Rule>
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object obj)
|
||||
{
|
||||
return this.getName().equals(((Rule)obj).getName());
|
||||
}
|
||||
|
||||
public boolean hasTriggerOfType(Trigger.Trigger_Enum queryType)
|
||||
{
|
||||
for(Trigger t : getTriggerSet())
|
||||
{
|
||||
if(t.getTriggerType().equals(queryType))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasActionOfType(Action.Action_Enum queryType)
|
||||
{
|
||||
for(Action a : getActionSet())
|
||||
{
|
||||
if(a.getAction().equals(queryType))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getAmountOfTriggersForType(Trigger.Trigger_Enum type)
|
||||
{
|
||||
int amount = 0;
|
||||
|
||||
for(Trigger t : getTriggerSet())
|
||||
{
|
||||
if(t.getTriggerType().equals(type))
|
||||
amount++;
|
||||
}
|
||||
|
||||
return amount;
|
||||
}
|
||||
|
||||
public int getAmountOfActionsForType(Action.Action_Enum type)
|
||||
{
|
||||
int amount = 0;
|
||||
|
||||
for(Action a : getActionSet())
|
||||
{
|
||||
if(a.getAction().equals(type))
|
||||
amount++;
|
||||
}
|
||||
|
||||
return amount;
|
||||
}
|
||||
|
||||
public static int getAmountOfActivatedRules()
|
||||
{
|
||||
int amount = 0;
|
||||
|
||||
for(Rule r : Rule.getRuleCollection())
|
||||
{
|
||||
if(r.isRuleActive())
|
||||
amount++;
|
||||
}
|
||||
|
||||
return amount;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.jens.automation2">
|
||||
|
||||
<supports-screens
|
||||
android:anyDensity="true"
|
||||
@ -51,6 +50,7 @@
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
|
||||
<!-- <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />-->
|
||||
<uses-permission android:name="android.permission.GET_TASKS" />
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||
<uses-permission android:name="android.permission.NFC" />
|
||||
@ -65,19 +65,12 @@
|
||||
<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.WRITE_SECURE_SETTINGS"
|
||||
tools:ignore="ProtectedPermissions" />
|
||||
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/>
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
<!--android:maxSdkVersion="32" />
|
||||
<uses-permission android:name="android.permission.USE_EXACT_ALARM" />-->
|
||||
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:allowClearUserData="true"
|
||||
android:icon="@drawable/crane"
|
||||
android:icon="@drawable/gears"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme"
|
||||
android:networkSecurityConfig="@xml/network_security_config">
|
||||
@ -107,9 +100,7 @@
|
||||
android:exported="false"
|
||||
android:label="@string/app_name" />
|
||||
|
||||
<receiver android:name=".receivers.StartupIntentReceiver"
|
||||
android:enabled="true"
|
||||
android:exported="true">
|
||||
<receiver android:name=".receivers.StartupIntentReceiver" android:enabled="true" android:exported="true">
|
||||
<intent-filter>
|
||||
<!--<action android:name="android.intent.action.SCREEN_ON" />-->
|
||||
<!--<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />-->
|
||||
@ -122,7 +113,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" />
|
||||
@ -131,11 +121,9 @@
|
||||
<receiver android:name=".receivers.DateTimeListener" />
|
||||
<receiver android:name=".receivers.ConnectivityReceiver" />
|
||||
<receiver android:name=".receivers.TimeZoneListener" />
|
||||
<receiver android:name=".receivers.CalendarReceiver" />
|
||||
|
||||
<receiver
|
||||
android:name=".DeviceAdmin"
|
||||
android:exported="true"
|
||||
android:description="@string/app_name"
|
||||
android:label="@string/app_name"
|
||||
android:permission= "android.permission.BIND_DEVICE_ADMIN" >
|
||||
@ -157,28 +145,14 @@
|
||||
<activity android:name=".ActivityManageTriggerTimeFrame" />
|
||||
<activity android:name=".ActivityControlCenter" />
|
||||
<activity android:name=".ActivityManageTriggerPhoneCall" />
|
||||
<activity android:name=".ActivityManageTriggerBroadcast" />
|
||||
<activity android:name=".ActivityManageActionBrightnessSetting" />
|
||||
<activity android:name=".ActivityManageActionCreateNotification" />
|
||||
<activity android:name=".ActivityManageTriggerDeviceOrientation" />
|
||||
<activity android:name=".ActivityHelp" />
|
||||
<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=".ActivityManageActionLocationService" />
|
||||
<activity android:name=".ActivityManageTriggerCharging" />
|
||||
|
||||
<activity
|
||||
android:name=".ActivityMainTabLayout"
|
||||
android:exported="true"
|
||||
android:launchMode="singleTask">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
@ -216,6 +190,7 @@
|
||||
<activity android:name=".ActivityManageActionStartActivity" />
|
||||
<activity android:name=".ActivityManageTriggerNfc" />
|
||||
<activity android:name=".ActivityManageActionSpeakText" />
|
||||
<activity android:name=".ActivityManageActionPlaySound" />
|
||||
<activity android:name=".ActivityManageTriggerBluetooth" />
|
||||
<activity android:name=".ActivityMainProfiles" />
|
||||
<activity android:name=".ActivityManageProfile" />
|
||||
@ -223,11 +198,9 @@
|
||||
<activity android:name=".ActivityVolumeTest" />
|
||||
<activity android:name=".ActivityPermissions"></activity>
|
||||
<activity android:name=".ActivityManageTriggerNotification" />
|
||||
<activity android:name=".ActivityManageTriggerCalendar" />
|
||||
|
||||
<service
|
||||
android:name=".receivers.NotificationListener"
|
||||
android:exported="true"
|
||||
android:label="@string/app_name"
|
||||
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE" >
|
||||
<intent-filter>
|
||||
@ -236,6 +209,8 @@
|
||||
|
||||
</service>
|
||||
|
||||
<activity android:name=".ActivityPermissions" />
|
||||
|
||||
<!-- https://developer.android.com/about/versions/pie/android-9.0-changes-28#apache-p-->
|
||||
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
|
||||
|
||||
|
@ -10,12 +10,8 @@ import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.google.android.gms.location.DetectedActivity;
|
||||
import com.jens.automation2.receivers.ActivityDetectionReceiver;
|
||||
import com.jens.automation2.receivers.BroadcastListener;
|
||||
import com.jens.automation2.receivers.CalendarReceiver;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
@ -110,7 +106,7 @@ public class Rule implements Comparable<Rule>
|
||||
}
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name.trim();
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public static void readFromFile()
|
||||
@ -350,20 +346,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;
|
||||
}
|
||||
}
|
||||
else if(oneTrigger.getTriggerType().equals(Trigger.Trigger_Enum.broadcastReceived))
|
||||
{
|
||||
return oneTrigger.getTriggerParameter() == BroadcastListener.getInstance().hasBroadcastOccurredSince(oneTrigger.getTriggerParameter2(), getLastExecution());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -376,28 +359,23 @@ public class Rule implements Comparable<Rule>
|
||||
{
|
||||
if(hasNotAppliedSinceLastExecution())
|
||||
{
|
||||
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule \"" + getName() + "\" applies and has flipped since its last execution.", 4);
|
||||
return true;
|
||||
}
|
||||
else if(hasTriggerOfType(Trigger.Trigger_Enum.calendarEvent) && CalendarReceiver.mayRuleStillBeActivatedForPendingCalendarEvents(this))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule \"" + getName() + "\" applies, has not flipped since its last execution, but may still be executed for other calendar events.", 4);
|
||||
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule " + getName() + " applies and has flipped since its last execution.", 4);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule \"" + getName() + "\" has not flipped since its last execution.", 4);
|
||||
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule " + getName() + " has not flipped since its last execution.", 4);
|
||||
}
|
||||
else
|
||||
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule \"" + getName() + "\" does not apply.", 4);
|
||||
Miscellaneous.logEvent("i", "getsGreenLight()", "Rule " + getName() + " does not apply.", 4);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean applies(Context context)
|
||||
{
|
||||
if(AutomationService.getInstance() == null)
|
||||
{
|
||||
Miscellaneous.logEvent("i", "RuleCheck", "Automation service not running. Rule \"" + getName() + "\" cannot apply.", 3);
|
||||
Miscellaneous.logEvent("i", "RuleCheck", "Automation service not running. Rule " + getName() + " cannot apply.", 3);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -408,12 +386,11 @@ public class Rule implements Comparable<Rule>
|
||||
if (!oneTrigger.applies(null, context))
|
||||
return false;
|
||||
}
|
||||
|
||||
Miscellaneous.logEvent("i", String.format(context.getResources().getString(R.string.ruleCheckOf), this.getName()), String.format("Rule \"%1$s\" generally applies currently. Checking if it's really due, yet will be done separately.", this.getName()), 3);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -484,9 +461,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);
|
||||
}
|
||||
@ -515,7 +490,7 @@ public class Rule implements Comparable<Rule>
|
||||
{
|
||||
boolean isActuallyToggleable = isActuallyToggable();
|
||||
|
||||
// boolean notLastActive = getLastActivatedRule() == null || !getLastActivatedRule().equals(Rule.this);
|
||||
boolean notLastActive = getLastActivatedRule() == null || !getLastActivatedRule().equals(Rule.this);
|
||||
boolean doToggle = ruleToggle && isActuallyToggleable;
|
||||
|
||||
String message;
|
||||
@ -529,29 +504,6 @@ public class Rule implements Comparable<Rule>
|
||||
if(Settings.startNewThreadForRuleActivation)
|
||||
publishProgress(message);
|
||||
|
||||
/*
|
||||
Make a note of Rule/CalendarEvent executed combinations
|
||||
*/
|
||||
if(Rule.this.hasTriggerOfType(Trigger.Trigger_Enum.calendarEvent))
|
||||
{
|
||||
for(CalendarReceiver.CalendarEvent event : CalendarReceiver.getApplyingCalendarEvents(Rule.this))
|
||||
{
|
||||
if(!CalendarReceiver.hasEventBeenUsedInRule(Rule.this, event))
|
||||
{
|
||||
/*
|
||||
Record only the first calendar event that matched because the rule may
|
||||
be executed once for every matching event.
|
||||
*/
|
||||
Miscellaneous.logEvent("i", "Rule", "Executing this rule run for calender event: " + event, 5);
|
||||
CalendarReceiver.addUsedPair(new CalendarReceiver.RuleEventPair(Rule.this, event));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Run actions one after another
|
||||
*/
|
||||
for(int i = 0; i< Rule.this.getActionSet().size(); i++)
|
||||
{
|
||||
try
|
||||
@ -811,71 +763,4 @@ public class Rule implements Comparable<Rule>
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object obj)
|
||||
{
|
||||
return this.getName().equals(((Rule)obj).getName());
|
||||
}
|
||||
|
||||
public boolean hasTriggerOfType(Trigger.Trigger_Enum queryType)
|
||||
{
|
||||
for(Trigger t : getTriggerSet())
|
||||
{
|
||||
if(t.getTriggerType().equals(queryType))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasActionOfType(Action.Action_Enum queryType)
|
||||
{
|
||||
for(Action a : getActionSet())
|
||||
{
|
||||
if(a.getAction().equals(queryType))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getAmountOfTriggersForType(Trigger.Trigger_Enum type)
|
||||
{
|
||||
int amount = 0;
|
||||
|
||||
for(Trigger t : getTriggerSet())
|
||||
{
|
||||
if(t.getTriggerType().equals(type))
|
||||
amount++;
|
||||
}
|
||||
|
||||
return amount;
|
||||
}
|
||||
|
||||
public int getAmountOfActionsForType(Action.Action_Enum type)
|
||||
{
|
||||
int amount = 0;
|
||||
|
||||
for(Action a : getActionSet())
|
||||
{
|
||||
if(a.getAction().equals(type))
|
||||
amount++;
|
||||
}
|
||||
|
||||
return amount;
|
||||
}
|
||||
|
||||
public static int getAmountOfActivatedRules()
|
||||
{
|
||||
int amount = 0;
|
||||
|
||||
for(Rule r : Rule.getRuleCollection())
|
||||
{
|
||||
if(r.isRuleActive())
|
||||
amount++;
|
||||
}
|
||||
|
||||
return amount;
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,6 @@
|
||||
<?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" package="com.jens.automation2">
|
||||
|
||||
|
||||
|
||||
</manifest>
|
@ -7,11 +7,10 @@ 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.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class Action
|
||||
@ -20,141 +19,110 @@ public class Action
|
||||
|
||||
public static final String actionParameter2Split = "ap2split";
|
||||
public static final String intentPairSeparator = "intPairSplit";
|
||||
public static final String actionParameters2SeparatorInner = "a2splitInner";
|
||||
public static final String actionParameters2SeparatorOuter = "a2splitOuter";
|
||||
public static final String vibrateSeparator = ",";
|
||||
public static final String httpErrorDefaultText = "HTTP_ERROR";
|
||||
|
||||
public enum Action_Enum
|
||||
{
|
||||
setWifi,
|
||||
setBluetooth,
|
||||
setUsbTethering,
|
||||
setWifiTethering,
|
||||
setBluetoothTethering,
|
||||
setDisplayRotation,
|
||||
turnWifiOn,turnWifiOff,
|
||||
turnBluetoothOn,turnBluetoothOff,
|
||||
triggerUrl,
|
||||
changeSoundProfile,
|
||||
turnUsbTetheringOn,turnUsbTetheringOff,
|
||||
turnWifiTetheringOn,turnWifiTetheringOff,
|
||||
enableScreenRotation,disableScreenRotation,
|
||||
startOtherActivity,
|
||||
waitBeforeNextAction,
|
||||
turnScreenOnOrOff,
|
||||
setAirplaneMode,
|
||||
setDataConnection,
|
||||
speakText,
|
||||
playMusic,
|
||||
controlMediaPlayback,
|
||||
setScreenBrightness,
|
||||
playSound,
|
||||
vibrate,
|
||||
createNotification,
|
||||
closeNotification,
|
||||
sendBroadcast,
|
||||
runExecutable,
|
||||
wakelock,
|
||||
setVariable,
|
||||
startPhoneCall,
|
||||
stopPhoneCall,
|
||||
copyToClipboard,
|
||||
takeScreenshot,
|
||||
setLocationService,
|
||||
sendTextMessage;
|
||||
|
||||
public String getFullName(Context context)
|
||||
{
|
||||
switch(this)
|
||||
{
|
||||
case setWifi:
|
||||
return context.getResources().getString(R.string.actionSetWifi);
|
||||
case setBluetooth:
|
||||
return context.getResources().getString(R.string.actionSetBluetooth);
|
||||
case setWifiTethering:
|
||||
return context.getResources().getString(R.string.actionSetWifiTethering);
|
||||
case setBluetoothTethering:
|
||||
return context.getResources().getString(R.string.actionSetBluetoothTethering);
|
||||
case setUsbTethering:
|
||||
return context.getResources().getString(R.string.actionSetUsbTethering);
|
||||
case setDisplayRotation:
|
||||
return context.getResources().getString(R.string.actionSetDisplayRotation);
|
||||
case turnWifiOn:
|
||||
return context.getResources().getString(R.string.actionTurnWifiOn);
|
||||
case turnWifiOff:
|
||||
return context.getResources().getString(R.string.actionTurnWifiOff);
|
||||
case turnBluetoothOn:
|
||||
return context.getResources().getString(R.string.actionTurnBluetoothOn);
|
||||
case turnBluetoothOff:
|
||||
return context.getResources().getString(R.string.actionTurnBluetoothOff);
|
||||
case triggerUrl:
|
||||
return context.getResources().getString(R.string.actionTriggerUrl);
|
||||
case changeSoundProfile:
|
||||
return context.getResources().getString(R.string.actionChangeSoundProfile);
|
||||
case turnUsbTetheringOn:
|
||||
return context.getResources().getString(R.string.actionTurnUsbTetheringOn);
|
||||
case turnUsbTetheringOff:
|
||||
return context.getResources().getString(R.string.actionTurnUsbTetheringOff);
|
||||
case turnWifiTetheringOn:
|
||||
return context.getResources().getString(R.string.actionTurnWifiTetheringOn);
|
||||
case turnWifiTetheringOff:
|
||||
return context.getResources().getString(R.string.actionTurnWifiTetheringOff);
|
||||
case enableScreenRotation:
|
||||
return context.getResources().getString(R.string.actionEnableScreenRotation);
|
||||
case disableScreenRotation:
|
||||
return context.getResources().getString(R.string.actionDisableScreenRotation);
|
||||
case startOtherActivity:
|
||||
return context.getResources().getString(R.string.startOtherActivity);
|
||||
case waitBeforeNextAction:
|
||||
return context.getResources().getString(R.string.waitBeforeNextAction);
|
||||
case turnScreenOnOrOff:
|
||||
return context.getResources().getString(R.string.turnScreenOnOrOff);
|
||||
case vibrate:
|
||||
return context.getResources().getString(R.string.vibrate);
|
||||
case setAirplaneMode:
|
||||
return context.getResources().getString(R.string.airplaneMode);
|
||||
case setDataConnection:
|
||||
return context.getResources().getString(R.string.actionDataConnection);
|
||||
case speakText:
|
||||
return context.getResources().getString(R.string.actionSpeakText);
|
||||
case playMusic:
|
||||
return context.getResources().getString(R.string.actionPlayMusic);
|
||||
case controlMediaPlayback:
|
||||
return context.getResources().getString(R.string.actionMediaControl);
|
||||
case playSound:
|
||||
return context.getResources().getString(R.string.playSound);
|
||||
case sendTextMessage:
|
||||
return context.getResources().getString(R.string.sendTextMessage);
|
||||
case setScreenBrightness:
|
||||
return context.getResources().getString(R.string.setScreenBrightness);
|
||||
case createNotification:
|
||||
return context.getResources().getString(R.string.createNotification);
|
||||
case closeNotification:
|
||||
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);
|
||||
case takeScreenshot:
|
||||
return context.getResources().getString(R.string.takeScreenshot);
|
||||
case setLocationService:
|
||||
return context.getResources().getString(R.string.setLocationServiceCapital);
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
};
|
||||
public enum Action_Enum {
|
||||
setWifi,
|
||||
setBluetooth,
|
||||
setUsbTethering,
|
||||
setWifiTethering,
|
||||
setBluetoothTethering,
|
||||
setDisplayRotation,
|
||||
turnWifiOn,turnWifiOff,
|
||||
turnBluetoothOn,turnBluetoothOff,
|
||||
triggerUrl,
|
||||
changeSoundProfile,
|
||||
turnUsbTetheringOn,turnUsbTetheringOff,
|
||||
turnWifiTetheringOn,turnWifiTetheringOff,
|
||||
enableScreenRotation,disableScreenRotation,
|
||||
startOtherActivity,
|
||||
waitBeforeNextAction,
|
||||
turnScreenOnOrOff,
|
||||
setAirplaneMode,
|
||||
setDataConnection,
|
||||
speakText,
|
||||
playMusic,
|
||||
controlMediaPlayback,
|
||||
setScreenBrightness,
|
||||
playSound,
|
||||
vibrate,
|
||||
createNotification,
|
||||
closeNotification,
|
||||
sendTextMessage;
|
||||
|
||||
public String getFullName(Context context)
|
||||
{
|
||||
switch(this)
|
||||
{
|
||||
case setWifi:
|
||||
return context.getResources().getString(R.string.actionSetWifi);
|
||||
case setBluetooth:
|
||||
return context.getResources().getString(R.string.actionSetBluetooth);
|
||||
case setWifiTethering:
|
||||
return context.getResources().getString(R.string.actionSetWifiTethering);
|
||||
case setBluetoothTethering:
|
||||
return context.getResources().getString(R.string.actionSetBluetoothTethering);
|
||||
case setUsbTethering:
|
||||
return context.getResources().getString(R.string.actionSetUsbTethering);
|
||||
case setDisplayRotation:
|
||||
return context.getResources().getString(R.string.actionSetDisplayRotation);
|
||||
case turnWifiOn:
|
||||
return context.getResources().getString(R.string.actionTurnWifiOn);
|
||||
case turnWifiOff:
|
||||
return context.getResources().getString(R.string.actionTurnWifiOff);
|
||||
case turnBluetoothOn:
|
||||
return context.getResources().getString(R.string.actionTurnBluetoothOn);
|
||||
case turnBluetoothOff:
|
||||
return context.getResources().getString(R.string.actionTurnBluetoothOff);
|
||||
case triggerUrl:
|
||||
return context.getResources().getString(R.string.actionTriggerUrl);
|
||||
case changeSoundProfile:
|
||||
return context.getResources().getString(R.string.actionChangeSoundProfile);
|
||||
case turnUsbTetheringOn:
|
||||
return context.getResources().getString(R.string.actionTurnUsbTetheringOn);
|
||||
case turnUsbTetheringOff:
|
||||
return context.getResources().getString(R.string.actionTurnUsbTetheringOff);
|
||||
case turnWifiTetheringOn:
|
||||
return context.getResources().getString(R.string.actionTurnWifiTetheringOn);
|
||||
case turnWifiTetheringOff:
|
||||
return context.getResources().getString(R.string.actionTurnWifiTetheringOff);
|
||||
case enableScreenRotation:
|
||||
return context.getResources().getString(R.string.actionEnableScreenRotation);
|
||||
case disableScreenRotation:
|
||||
return context.getResources().getString(R.string.actionDisableScreenRotation);
|
||||
case startOtherActivity:
|
||||
return context.getResources().getString(R.string.startOtherActivity);
|
||||
case waitBeforeNextAction:
|
||||
return context.getResources().getString(R.string.waitBeforeNextAction);
|
||||
case turnScreenOnOrOff:
|
||||
return context.getResources().getString(R.string.turnScreenOnOrOff);
|
||||
case vibrate:
|
||||
return context.getResources().getString(R.string.vibrate);
|
||||
case setAirplaneMode:
|
||||
return context.getResources().getString(R.string.airplaneMode);
|
||||
case setDataConnection:
|
||||
return context.getResources().getString(R.string.actionDataConnection);
|
||||
case speakText:
|
||||
return context.getResources().getString(R.string.actionSpeakText);
|
||||
case playMusic:
|
||||
return context.getResources().getString(R.string.actionPlayMusic);
|
||||
case controlMediaPlayback:
|
||||
return context.getResources().getString(R.string.actionMediaControl);
|
||||
case playSound:
|
||||
return context.getResources().getString(R.string.playSound);
|
||||
case sendTextMessage:
|
||||
return context.getResources().getString(R.string.sendTextMessage);
|
||||
case setScreenBrightness:
|
||||
return context.getResources().getString(R.string.setScreenBrightness);
|
||||
case createNotification:
|
||||
return context.getResources().getString(R.string.createNotification);
|
||||
case closeNotification:
|
||||
return context.getResources().getString(R.string.closeNotifications);
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private Action_Enum action;
|
||||
private boolean parameter1 = false;
|
||||
@ -290,88 +258,22 @@ public class Action
|
||||
case closeNotification:
|
||||
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.closeNotifications));
|
||||
break;
|
||||
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));
|
||||
break;
|
||||
case takeScreenshot:
|
||||
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.takeScreenshot));
|
||||
break;
|
||||
case setLocationService:
|
||||
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.setLocationService) + ": " );
|
||||
switch(Integer.parseInt(getParameter2()))
|
||||
{
|
||||
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;
|
||||
default:
|
||||
returnString.append(action.toString());
|
||||
}
|
||||
|
||||
if (this.getAction().equals(Action_Enum.triggerUrl))
|
||||
{
|
||||
String[] components;
|
||||
if(parameter2.contains(Action.actionParameter2Split))
|
||||
components = parameter2.split(Action.actionParameter2Split);
|
||||
else
|
||||
components = parameter2.split(";");
|
||||
|
||||
String[] components = parameter2.split(";");
|
||||
if (components.length >= 3)
|
||||
{
|
||||
returnString.append(" (");
|
||||
if(components.length >= 4)
|
||||
returnString.append(components[3]);
|
||||
else
|
||||
returnString.append(ActivityManageActionTriggerUrl.methodGet);
|
||||
returnString.append(")");
|
||||
|
||||
returnString.append(": " + components[2]);
|
||||
|
||||
if (parameter1)
|
||||
returnString.append(" " + Miscellaneous.getAnyContext().getResources().getString(R.string.usingAuthentication) + ".");
|
||||
}
|
||||
else
|
||||
{
|
||||
returnString.append(" (");
|
||||
returnString.append(ActivityManageActionTriggerUrl.methodGet);;
|
||||
returnString.append(")");
|
||||
returnString.append(": " + components[0]);
|
||||
}
|
||||
}
|
||||
else if (this.getAction().equals(Action_Enum.startOtherActivity))
|
||||
{
|
||||
@ -414,24 +316,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(": ");
|
||||
|
||||
@ -459,12 +345,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) || this.getAction().equals(Action_Enum.setLocationService))
|
||||
; // it's completed further above already
|
||||
else if (parameter2 != null && parameter2.length() > 0)
|
||||
returnString.append(": " + parameter2.replace(Action.actionParameter2Split, "; "));
|
||||
}
|
||||
@ -550,7 +430,7 @@ public class Action
|
||||
|
||||
return (String[])actionTypesList.toArray(new String[actionTypesList.size()]);
|
||||
}
|
||||
|
||||
|
||||
public void run(Context context, boolean toggleActionIfPossible)
|
||||
{
|
||||
try
|
||||
@ -578,7 +458,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);
|
||||
@ -653,40 +533,6 @@ public class Action
|
||||
else
|
||||
Miscellaneous.logEvent("w", "Close notification", "Close notification was requested, but OS version is too low: " + String.valueOf(Build.VERSION.SDK_INT), 2);
|
||||
break;
|
||||
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;
|
||||
case takeScreenshot:
|
||||
Actions.takeScreenshot();
|
||||
break;
|
||||
case setLocationService:
|
||||
Actions.setLocationService(Integer.parseInt(this.getParameter2()), AutomationService.getInstance());
|
||||
break;
|
||||
default:
|
||||
Miscellaneous.logEvent("w", "Action", context.getResources().getString(R.string.unknownActionSpecified), 3);
|
||||
break;
|
||||
@ -700,55 +546,34 @@ public class Action
|
||||
}
|
||||
|
||||
private void triggerUrl(Context context)
|
||||
{
|
||||
//TODO: Check if data needs to be escaped
|
||||
{
|
||||
String username = null;
|
||||
String password = null;
|
||||
String method = ActivityManageActionTriggerUrl.methodGet;
|
||||
String url;
|
||||
String params = null;
|
||||
|
||||
String[] components;
|
||||
if(getParameter2().contains(Action.actionParameter2Split))
|
||||
components = getParameter2().split(Action.actionParameter2Split, -1);
|
||||
else
|
||||
components = getParameter2().split(";", -1);
|
||||
String[] components = getParameter2().split(";");
|
||||
|
||||
if(components.length >= 3)
|
||||
{
|
||||
username = components[0];
|
||||
password = components[1];
|
||||
url = components[2];
|
||||
|
||||
if(components.length >= 4)
|
||||
method = components[3];
|
||||
|
||||
if(components.length >= 5)
|
||||
{
|
||||
params = components[4];
|
||||
}
|
||||
}
|
||||
else // compatibility for very old versions which haven't upgraded, yet.
|
||||
else
|
||||
url = components[0];
|
||||
|
||||
try
|
||||
{
|
||||
url = Miscellaneous.replaceVariablesInText(url, context);
|
||||
if(!StringUtils.isEmpty(params))
|
||||
params = Miscellaneous.replaceVariablesInText(params, context);
|
||||
|
||||
Actions myAction = new Actions();
|
||||
|
||||
Miscellaneous.logEvent("i", "HTTP", "Attempting download of " + url, 4); //getResources().getString("attemptingDownloadOf");
|
||||
|
||||
/*
|
||||
Theoretically credentials could be saved, but authentication has been turned off afterwards.
|
||||
The following if clause is there to force username and password to be null.
|
||||
*/
|
||||
|
||||
if(this.getParameter1()) // use authentication
|
||||
new DownloadTask().execute(url, username, password, method, params);
|
||||
new DownloadTask().execute(url, username, password);
|
||||
else
|
||||
new DownloadTask().execute(url, null, null, method, params);
|
||||
new DownloadTask().execute(url, null, null);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
@ -763,49 +588,32 @@ public class Action
|
||||
{
|
||||
Thread.setDefaultUncaughtExceptionHandler(Miscellaneous.uncaughtExceptionHandler);
|
||||
|
||||
int attempts = 1;
|
||||
int attempts=1;
|
||||
String urlString=parameters[0];
|
||||
|
||||
String urlUsername = null;
|
||||
String urlPassword = null;
|
||||
String method = ActivityManageActionTriggerUrl.methodGet;
|
||||
Map<String,String> httpParams = new HashMap<>();
|
||||
|
||||
if(parameters.length >= 3)
|
||||
{
|
||||
urlUsername = parameters[1];
|
||||
urlPassword = parameters[2];
|
||||
|
||||
if(parameters.length >= 4)
|
||||
method = parameters[3];
|
||||
|
||||
if(parameters.length >= 5 && parameters[4] != null)
|
||||
{
|
||||
// has params
|
||||
String[] paramPairs = parameters[4].split(Action.actionParameters2SeparatorOuter);
|
||||
for(String pair : paramPairs)
|
||||
{
|
||||
String[] pieces = pair.split(Action.actionParameters2SeparatorInner);
|
||||
httpParams.put(pieces[0], pieces[1]);
|
||||
}
|
||||
}
|
||||
|
||||
urlUsername=parameters[1];
|
||||
urlPassword=parameters[2];
|
||||
}
|
||||
|
||||
String response = httpErrorDefaultText;
|
||||
|
||||
if(Settings.httpAttempts < 1)
|
||||
String response = "httpError";
|
||||
HttpGet post;
|
||||
|
||||
if(Settings.httpAttempts < 1)
|
||||
Miscellaneous.logEvent("w", "HTTP Request", Miscellaneous.getAnyContext().getResources().getString(R.string.cantDownloadTooFewRequestsInSettings), 3);
|
||||
|
||||
while(attempts <= Settings.httpAttempts && response.equals(httpErrorDefaultText))
|
||||
while(attempts <= Settings.httpAttempts && response.equals("httpError"))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "HTTP Request", "Attempt " + String.valueOf(attempts++) + " of " + String.valueOf(Settings.httpAttempts), 3);
|
||||
|
||||
// Either thorough checking or no encryption
|
||||
if(!Settings.httpAcceptAllCertificates || !urlString.toLowerCase(Locale.getDefault()).contains("https"))
|
||||
response = Miscellaneous.downloadURL(urlString, urlUsername, urlPassword, method, httpParams);
|
||||
response = Miscellaneous.downloadURL(urlString, urlUsername, urlPassword);
|
||||
else
|
||||
response = Miscellaneous.downloadUrlWithoutCertificateChecking(urlString, urlUsername, urlPassword, method, httpParams);
|
||||
response = Miscellaneous.downloadURLwithoutCertificateChecking(urlString, urlUsername, urlPassword);
|
||||
|
||||
try
|
||||
{
|
||||
@ -828,7 +636,7 @@ public class Action
|
||||
//Do something with result
|
||||
//Toast.makeText(context, text, duration) result;
|
||||
Miscellaneous.logEvent("i", "HTTP RESULT", result, 3);
|
||||
Actions myAction = new Actions();
|
||||
Actions myAction=new Actions();
|
||||
myAction.useDownloadedWebpage(result);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.jens.automation2;
|
||||
|
||||
import android.Manifest;
|
||||
import android.accessibilityservice.AccessibilityService;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.NotificationManager;
|
||||
@ -16,6 +15,8 @@ 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;
|
||||
@ -25,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;
|
||||
@ -51,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;
|
||||
@ -66,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;
|
||||
|
||||
@ -82,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";
|
||||
|
||||
@ -95,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
|
||||
@ -114,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);
|
||||
@ -124,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())
|
||||
{
|
||||
@ -185,91 +177,19 @@ 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);
|
||||
|
||||
context.sendBroadcast(broadcastIntent);
|
||||
}
|
||||
|
||||
public static void setVariable(String parameter2)
|
||||
{
|
||||
String[] parts = parameter2.split(Action.actionParameter2Split);
|
||||
|
||||
if(AutomationService.isMyServiceRunning(Miscellaneous.getAnyContext()))
|
||||
{
|
||||
Map<String,String> map = AutomationService.getInstance().getVariableMap();
|
||||
|
||||
if(parts.length > 1)
|
||||
{
|
||||
try
|
||||
{
|
||||
map.put(parts[0], Miscellaneous.replaceVariablesInText(parts[1], Miscellaneous.getAnyContext()));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
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)
|
||||
public static Boolean setWifi(Context context, Boolean desiredState, 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);
|
||||
@ -305,15 +225,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);
|
||||
|
||||
@ -735,6 +648,7 @@ public class Actions
|
||||
if (method == null)
|
||||
throw new NoSuchMethodException();
|
||||
|
||||
|
||||
/*
|
||||
* For some reason this doesn't work, throws NoSuchMethodExpection even if the method is present.
|
||||
*/
|
||||
@ -840,21 +754,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)
|
||||
@ -991,10 +913,21 @@ 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();
|
||||
Actions.setVariable("last_triggerurl_result" + Action.actionParameter2Split + result);
|
||||
}
|
||||
|
||||
public static HttpClient getInsecureSslClient(HttpClient client)
|
||||
@ -1053,16 +986,13 @@ public class Actions
|
||||
{
|
||||
Miscellaneous.logEvent("i", "StartOtherActivity", "Starting other Activity...", 4);
|
||||
|
||||
String params[];
|
||||
|
||||
if(param.contains(Action.actionParameter2Split))
|
||||
params = param.split(Action.actionParameter2Split);
|
||||
else
|
||||
params = param.split(";");
|
||||
String params[] = param.split(";");
|
||||
|
||||
try
|
||||
{
|
||||
Intent externalApplicationIntent;
|
||||
Intent externalActivityIntent;
|
||||
|
||||
int paramsStartIndex;
|
||||
|
||||
if (!startByAction)
|
||||
{
|
||||
@ -1075,15 +1005,17 @@ public class Actions
|
||||
|
||||
Miscellaneous.logEvent("i", "StartOtherApp", "Starting app by activity: " + packageName + " " + className, 3);
|
||||
|
||||
externalApplicationIntent = new Intent(Intent.ACTION_MAIN);
|
||||
externalApplicationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
paramsStartIndex = 2;
|
||||
|
||||
if(packageName.equals("dummyPkg"))
|
||||
externalApplicationIntent.setAction(className);
|
||||
externalActivityIntent = new Intent(Intent.ACTION_MAIN);
|
||||
externalActivityIntent.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
|
||||
externalApplicationIntent.setClassName(packageName, className);
|
||||
// if(packageName.equals("dummyPkg"))
|
||||
// externalActivityIntent.setAction(className);
|
||||
// else
|
||||
externalActivityIntent.setClassName(packageName, className);
|
||||
|
||||
if (!Miscellaneous.doesActivityExist(externalApplicationIntent, Miscellaneous.getAnyContext()))
|
||||
if (!Miscellaneous.doesActivityExist(externalActivityIntent, Miscellaneous.getAnyContext()))
|
||||
Miscellaneous.logEvent("w", "StartOtherApp", "Activity not found: " + className, 2);
|
||||
}
|
||||
else
|
||||
@ -1091,51 +1023,20 @@ public class Actions
|
||||
// selected by action
|
||||
Miscellaneous.logEvent("i", "StartOtherApp", "Starting app by action: " + param, 3);
|
||||
|
||||
externalApplicationIntent = new Intent();
|
||||
externalActivityIntent = new Intent();
|
||||
|
||||
if (!params[0].equals(dummyPackageString))
|
||||
externalApplicationIntent.setPackage(params[0]);
|
||||
externalActivityIntent.setPackage(params[0]);
|
||||
|
||||
externalApplicationIntent.setAction(params[1]);
|
||||
|
||||
if (params[2].equals(ActivityManageActionStartActivity.startByServiceString) || params[2].equals(ActivityManageActionStartActivity.startByForegroundServiceString))
|
||||
{
|
||||
externalApplicationIntent.setComponent(new ComponentName(params[0], params[2]));
|
||||
}
|
||||
externalActivityIntent.setAction(params[1]);
|
||||
}
|
||||
|
||||
externalApplicationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
externalActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
|
||||
// Pack intents
|
||||
if(params.length >= 4)
|
||||
for (int i = 3; i < params.length; i++)
|
||||
{
|
||||
if(Miscellaneous.isNumeric(params[3]))
|
||||
externalApplicationIntent = packParametersIntoIntent(externalApplicationIntent, params, 4);
|
||||
else
|
||||
externalApplicationIntent = packParametersIntoIntent(externalApplicationIntent, params, 3);
|
||||
}
|
||||
|
||||
if (params[2].equals(ActivityManageActionStartActivity.startByActivityString))
|
||||
automationServerRef.startActivity(externalApplicationIntent);
|
||||
else if (params[2].equals(ActivityManageActionStartActivity.startByServiceString))
|
||||
automationServerRef.startService(externalApplicationIntent);
|
||||
else if (params[2].equals(ActivityManageActionStartActivity.startByForegroundServiceString) && Build.VERSION.SDK_INT >= 26)
|
||||
automationServerRef.startForegroundService(externalApplicationIntent);
|
||||
else
|
||||
automationServerRef.sendBroadcast(externalApplicationIntent);
|
||||
}
|
||||
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);
|
||||
String[] singleParam = params[i].split(Action.intentPairSeparator);
|
||||
|
||||
/*Class c = Class.forName(singleParam[0]);
|
||||
for(Method m : c.getMethods())
|
||||
@ -1147,89 +1048,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)
|
||||
@ -1268,37 +1163,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);
|
||||
@ -1309,26 +1188,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;
|
||||
@ -1995,11 +1854,6 @@ public class Actions
|
||||
|
||||
protected static boolean executeCommandViaSu(String[] commands)
|
||||
{
|
||||
boolean suAvailable = false;
|
||||
String suVersion = null;
|
||||
String suVersionInternal = null;
|
||||
int suResult;
|
||||
|
||||
boolean success = false;
|
||||
|
||||
try
|
||||
@ -2009,33 +1863,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);
|
||||
Miscellaneous.logEvent("i", "executeCommandViaSu()", "calling method: " + Miscellaneous.getCallingMethodName(), 5);
|
||||
|
||||
suResult = Shell.Pool.SU.run(commands);
|
||||
|
||||
if(Miscellaneous.getCallingMethodName().equals("runExecutable"))
|
||||
{
|
||||
Actions.setVariable("last_run_executable_exit_code" + Action.actionParameter2Split + String.valueOf(suResult));
|
||||
// Actions.setVariable("last_run_executable_output" + Action.actionParameter2Split + (String) result[1]);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -2061,320 +1899,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 = ((int) result[0] == 0);
|
||||
|
||||
Actions.setVariable("last_run_executable_exit_code" + Action.actionParameter2Split + String.valueOf((int) result[0]));
|
||||
Actions.setVariable("last_run_executable_output" + Action.actionParameter2Split + (String) result[1]);
|
||||
|
||||
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 ();
|
||||
|
||||
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);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isTetheringActive1(Context context)
|
||||
{
|
||||
try
|
||||
{
|
||||
for(Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();)
|
||||
{
|
||||
NetworkInterface intf = en.nextElement();
|
||||
|
||||
for(Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();)
|
||||
{
|
||||
InetAddress inetAddress = enumIpAddr.nextElement();
|
||||
|
||||
if(!intf.isLoopback())
|
||||
{
|
||||
if(intf.getName().contains("rndis"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Miscellaneous.logEvent("e", "isTetheringActive()", Log.getStackTraceString(e), 3);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public final static int wakeLockTimeoutDisabled = -1;
|
||||
static boolean wakeLockStopRequested = false;
|
||||
public static void wakeLockStart(Context context, long duration)
|
||||
{
|
||||
Thread lockThread = new Thread(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
wakeLockStopRequested = false;
|
||||
|
||||
long waited = 0;
|
||||
int step = 2000;
|
||||
|
||||
try
|
||||
{
|
||||
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||
PowerManager.WakeLock fullWakeLock = powerManager.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "Loneworker - FULL WAKE LOCK");
|
||||
fullWakeLock.acquire(); // turn on
|
||||
|
||||
do
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
Thread.sleep(step); // turn on duration
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if(duration > 0)
|
||||
waited += step;
|
||||
|
||||
if(wakeLockStopRequested) //stop requested
|
||||
Miscellaneous.logEvent("i", "WakeLockStart", "Stop requested.", 4);
|
||||
}
|
||||
while(!wakeLockStopRequested && (duration < 0 || waited <= duration));
|
||||
|
||||
fullWakeLock.release();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
lockThread.start();
|
||||
}
|
||||
|
||||
public static void wakeLockStop()
|
||||
{
|
||||
Miscellaneous.logEvent("i", "WakeLockStart", "Requesting stop.", 4);
|
||||
wakeLockStopRequested = true;
|
||||
}
|
||||
|
||||
public static void startPhoneCall(Context context, String phoneNumber)
|
||||
{
|
||||
Intent intent;
|
||||
|
||||
/*
|
||||
Bug in Android 14 makes it necessary to add double quotes around MMI code.
|
||||
More precisely it's required for codes containing the # character.
|
||||
*/
|
||||
|
||||
if(Build.VERSION.SDK_INT >= 34)
|
||||
intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + Uri.encode("\"" + phoneNumber + "\"")));
|
||||
else
|
||||
intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + Uri.encode(phoneNumber)));
|
||||
|
||||
// intent.setClassName("com.android.phone","com.android.phone.OutgoingCallBroadcaster");
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.addFlags(Intent.FLAG_FROM_BACKGROUND);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
public static void endPhoneCall(Context context)
|
||||
{
|
||||
if(Build.VERSION.SDK_INT < 21)
|
||||
{
|
||||
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
try
|
||||
{
|
||||
Class c = Class.forName(tm.getClass().getName());
|
||||
Method m = c.getDeclaredMethod("getITelephony");
|
||||
m.setAccessible(true);
|
||||
Object telephonyService = m.invoke(tm);
|
||||
|
||||
c = Class.forName(telephonyService.getClass().getName());
|
||||
m = c.getDeclaredMethod("endCall");
|
||||
m.setAccessible(true);
|
||||
m.invoke(telephonyService);
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
TelecomManager mgr = (TelecomManager) context.getSystemService(context.TELECOM_SERVICE);
|
||||
mgr.endCall();
|
||||
}
|
||||
}
|
||||
|
||||
public static void copyToClipboard(Context context, String text)
|
||||
{
|
||||
Miscellaneous.logEvent("i", "Clipboard", "Copying data to clipboard: " + text, 4);
|
||||
|
||||
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB)
|
||||
{
|
||||
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
clipboard.setText(text);
|
||||
}
|
||||
else
|
||||
{
|
||||
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
android.content.ClipData clip = android.content.ClipData.newPlainText("Data-from-Automation", text);
|
||||
clipboard.setPrimaryClip(clip);
|
||||
}
|
||||
}
|
||||
|
||||
public static void takeScreenshot()
|
||||
{
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
|
||||
{
|
||||
if(!BuildConfig.FLAVOR.equals(AutomationService.flavor_name_googleplay))
|
||||
MyAccessibilityService.getInstance().performGlobalAction(AccessibilityService.GLOBAL_ACTION_TAKE_SCREENSHOT);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setLocationService(int 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.putString(context.getContentResolver(), android.provider.Settings.Secure.LOCATION_MODE, String.valueOf(desiredState));
|
||||
}
|
||||
|
||||
}
|
@ -39,10 +39,8 @@ public class ActivityControlCenter extends Activity
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
setContentView(R.layout.activity_control_center);
|
||||
|
||||
|
||||
bVolumeTest = (Button) findViewById(R.id.bVolumeTest);
|
||||
bVolumeTest.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@ -355,15 +353,11 @@ public class ActivityControlCenter extends Activity
|
||||
systemInfoText.append("Device details" + Miscellaneous.lineSeparator);
|
||||
systemInfoText.append("OS version: " + System.getProperty("os.version") + Miscellaneous.lineSeparator);
|
||||
systemInfoText.append("API Level: " + android.os.Build.VERSION.SDK + Miscellaneous.lineSeparator);
|
||||
systemInfoText.append("Target SDK: " + Miscellaneous.getAnyContext().getApplicationInfo().targetSdkVersion + Miscellaneous.lineSeparator);
|
||||
systemInfoText.append("Device: " + android.os.Build.DEVICE + Miscellaneous.lineSeparator);
|
||||
systemInfoText.append("Model: " + android.os.Build.MODEL + Miscellaneous.lineSeparator);
|
||||
systemInfoText.append("Product: " + android.os.Build.PRODUCT + Miscellaneous.lineSeparator);
|
||||
systemInfoText.append("Rooted: " + String.valueOf(Miscellaneous.isPhoneRooted()) + Miscellaneous.lineSeparator);
|
||||
systemInfoText.append("Country: " + Miscellaneous.getUserCountry(Miscellaneous.getAnyContext()) + Miscellaneous.lineSeparator);
|
||||
systemInfoText.append("OS language: " + Locale.getDefault().getDisplayName() + Miscellaneous.lineSeparator);
|
||||
systemInfoText.append("Logfile written: " + String.valueOf(Settings.writeLogFile) + Miscellaneous.lineSeparator);
|
||||
systemInfoText.append("Log level: " + String.valueOf(Settings.logLevel));
|
||||
systemInfoText.append("OS language: " + Locale.getDefault().getDisplayName());
|
||||
|
||||
/*
|
||||
I've checked the Locale methods on my Android 4.1.2 device, and the results:
|
||||
@ -386,7 +380,6 @@ public class ActivityControlCenter extends Activity
|
||||
protected void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
|
||||
String folder = Miscellaneous.getWriteableFolder();
|
||||
if (folder != null && folder.length() > 0)
|
||||
|
@ -21,7 +21,6 @@ public class ActivityDisplayLongMessage extends Activity
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
setContentView(R.layout.activity_display_long_message);
|
||||
|
||||
tvMessageTitle = (TextView)findViewById(R.id.tvMessageTitle);
|
||||
|
@ -13,8 +13,7 @@ public class ActivityHelp extends Activity
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
setContentView(layout.activity_help_text);
|
||||
setContentView(layout.help_text);
|
||||
|
||||
TextView tvHelpTextEnergySaving = (TextView) findViewById(R.id.tvHelpTextEnergySaving);
|
||||
tvHelpTextEnergySaving.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
|
@ -44,7 +44,6 @@ public class ActivityMainPoi extends ActivityGeneric
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
setContentView(R.layout.main_poi_layout);
|
||||
|
||||
instance = this;
|
||||
@ -108,13 +107,6 @@ public class ActivityMainPoi extends ActivityGeneric
|
||||
this.storeServiceReferenceInVariable();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
}
|
||||
|
||||
private void buttonAddPoi()
|
||||
{
|
||||
poiToEdit = null;
|
||||
@ -198,27 +190,8 @@ public class ActivityMainPoi extends ActivityGeneric
|
||||
startActivityForResult(manageSpecificPoiIntent, 2000);
|
||||
break;
|
||||
case 1:
|
||||
AlertDialog.Builder deleteDialog = new AlertDialog.Builder(ActivityMainPoi.this);
|
||||
deleteDialog.setMessage(getResources().getString(R.string.areYouSure));
|
||||
deleteDialog.setPositiveButton(getResources().getString(R.string.yes), new DialogInterface.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i)
|
||||
{
|
||||
if(pointOfInterest.delete(Miscellaneous.getAnyContext()))
|
||||
updateListView();
|
||||
}
|
||||
});
|
||||
deleteDialog.setNegativeButton(getResources().getString(R.string.no), new DialogInterface.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i)
|
||||
{
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
deleteDialog.show();
|
||||
if(pointOfInterest.delete(Miscellaneous.getAnyContext()))
|
||||
updateListView();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,6 @@ public class ActivityMainProfiles extends ActivityGeneric
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
setContentView(R.layout.main_profile_layout);
|
||||
|
||||
instance = this;
|
||||
@ -155,13 +154,6 @@ public class ActivityMainProfiles extends ActivityGeneric
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
}
|
||||
|
||||
private AlertDialog getProfileDialog(final Profile profile)
|
||||
{
|
||||
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
|
||||
@ -195,29 +187,10 @@ public class ActivityMainProfiles extends ActivityGeneric
|
||||
Rule user = profile.isInUseByRules();
|
||||
if(user == null)
|
||||
{
|
||||
AlertDialog.Builder deleteDialog = new AlertDialog.Builder(ActivityMainProfiles.this);
|
||||
deleteDialog.setMessage(getResources().getString(R.string.areYouSure));
|
||||
deleteDialog.setPositiveButton(getResources().getString(R.string.yes), new DialogInterface.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i)
|
||||
{
|
||||
if (profile.delete(ActivityMainProfiles.this))
|
||||
updateListView();
|
||||
else
|
||||
Toast.makeText(ActivityMainProfiles.this, getResources().getString(R.string.profileCouldNotBeDeleted), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
deleteDialog.setNegativeButton(getResources().getString(R.string.no), new DialogInterface.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i)
|
||||
{
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
deleteDialog.show();
|
||||
if (profile.delete(ActivityMainProfiles.this))
|
||||
updateListView();
|
||||
else
|
||||
Toast.makeText(ActivityMainProfiles.this, getResources().getString(R.string.profileCouldNotBeDeleted), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
else
|
||||
Toast.makeText(ActivityMainProfiles.this, String.format(getResources().getString(R.string.ruleXIsUsingProfileY), user.getName(), profile.getName()), Toast.LENGTH_LONG).show();
|
||||
|
@ -18,7 +18,6 @@ import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import com.jens.automation2.AutomationService.serviceCommands;
|
||||
import com.jens.automation2.receivers.DateTimeListener;
|
||||
|
||||
@ -47,8 +46,7 @@ public class ActivityMainRules extends ActivityGeneric
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.main_rule_layout);
|
||||
|
||||
instance = this;
|
||||
@ -154,13 +152,6 @@ public class ActivityMainRules extends ActivityGeneric
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data)
|
||||
@ -222,30 +213,11 @@ public class ActivityMainRules extends ActivityGeneric
|
||||
startActivityForResult(manageSpecificRuleIntent, requestCodeChangeRule);
|
||||
break;
|
||||
case 2:
|
||||
AlertDialog.Builder deleteDialog = new AlertDialog.Builder(ActivityMainRules.this);
|
||||
deleteDialog.setMessage(getResources().getString(R.string.areYouSure));
|
||||
deleteDialog.setPositiveButton(getResources().getString(R.string.yes), new DialogInterface.OnClickListener()
|
||||
if(ruleThisIsAbout.delete())
|
||||
{
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i)
|
||||
{
|
||||
if(ruleThisIsAbout.delete())
|
||||
{
|
||||
ruleToEdit = null; //clear cache
|
||||
updateListView();
|
||||
}
|
||||
}
|
||||
});
|
||||
deleteDialog.setNegativeButton(getResources().getString(R.string.no), new DialogInterface.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i)
|
||||
{
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
deleteDialog.show();
|
||||
ruleToEdit = null; //clear cache
|
||||
updateListView();
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
ruleToEdit = ruleThisIsAbout;
|
||||
|
@ -6,12 +6,9 @@ import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
@ -34,7 +31,6 @@ import com.jens.automation2.location.LocationProvider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Locale;
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
public class ActivityMainScreen extends ActivityGeneric
|
||||
@ -55,7 +51,6 @@ public class ActivityMainScreen extends ActivityGeneric
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
setContentView(R.layout.main_overview_layout);
|
||||
|
||||
activityMainScreenInstance = this;
|
||||
@ -82,9 +77,10 @@ public class ActivityMainScreen extends ActivityGeneric
|
||||
tvLockSoundDuration = (TextView)findViewById(R.id.tvlockSoundDuration);
|
||||
tbLockSound = (ToggleButton) findViewById(R.id.tbLockSound);
|
||||
toggleService = (ToggleButton) findViewById(R.id.tbArmMastListener);
|
||||
|
||||
bDonate = (Button)findViewById(R.id.bDonate);
|
||||
|
||||
if(!BuildConfig.FLAVOR.equalsIgnoreCase(AutomationService.flavor_name_googleplay))
|
||||
if(!BuildConfig.FLAVOR.equalsIgnoreCase("googlePlayFlavor"))
|
||||
bDonate.setVisibility(View.VISIBLE);
|
||||
|
||||
toggleService.setChecked(AutomationService.isMyServiceRunning(this));
|
||||
@ -275,14 +271,9 @@ public class ActivityMainScreen extends ActivityGeneric
|
||||
activityMainScreenInstance.tvMainScreenNotePermissions.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if(BuildConfig.FLAVOR.equals(AutomationService.flavor_name_fdroid) && Miscellaneous.restrictedFeaturesConfiguredFdroid())
|
||||
if(Miscellaneous.restrictedFeaturesConfigured())
|
||||
{
|
||||
activityMainScreenInstance.tvMainScreenNoteFeaturesFromOtherFlavor.setText(R.string.settingsReferringToRestrictedFeaturesInFdroid);
|
||||
activityMainScreenInstance.tvMainScreenNoteFeaturesFromOtherFlavor.setVisibility(View.VISIBLE);
|
||||
}
|
||||
else if(BuildConfig.FLAVOR.equals(AutomationService.flavor_name_googleplay) && Miscellaneous.restrictedFeaturesConfiguredGoogle())
|
||||
{
|
||||
activityMainScreenInstance.tvMainScreenNoteFeaturesFromOtherFlavor.setText(R.string.settingsReferringToRestrictedFeaturesInGoogle);
|
||||
activityMainScreenInstance.tvMainScreenNoteFeaturesFromOtherFlavor.setText(R.string.settingsReferringToRestrictedFeatures);
|
||||
activityMainScreenInstance.tvMainScreenNoteFeaturesFromOtherFlavor.setVisibility(View.VISIBLE);
|
||||
}
|
||||
else
|
||||
@ -293,6 +284,14 @@ public class ActivityMainScreen extends ActivityGeneric
|
||||
|
||||
if(Miscellaneous.googleToBlameForLocation(true))
|
||||
{
|
||||
// Intent intent = new Intent(AutomationService.this, ActivityDisplayLongMessage.class);
|
||||
// intent.putExtra("longMessage", getResources().getString(R.string.locationEngineDisabledLong));
|
||||
// PendingIntent pi = PendingIntent.getActivity(AutomationService.this, 0, intent, 0);
|
||||
// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1)
|
||||
// Miscellaneous.createDismissableNotificationWithDelay(2200, getResources().getString(R.string.featuresDisabled), notificationIdLocationRestriction, pi);
|
||||
// else
|
||||
// Miscellaneous.createDismissableNotification(getResources().getString(R.string.featuresDisabled), notificationIdLocationRestriction, pi);
|
||||
|
||||
activityMainScreenInstance.tvMainScreenNoteLocationImpossibleBlameGoogle.setText(R.string.locationEngineDisabledShort);
|
||||
activityMainScreenInstance.tvMainScreenNoteLocationImpossibleBlameGoogle.setVisibility(View.VISIBLE);
|
||||
activityMainScreenInstance.tvMainScreenNoteLocationImpossibleBlameGoogle.setOnClickListener(new OnClickListener()
|
||||
@ -317,7 +316,8 @@ public class ActivityMainScreen extends ActivityGeneric
|
||||
uiUpdateRunning = true;
|
||||
activityMainScreenInstance.toggleService.setChecked(true);
|
||||
uiUpdateRunning = false;
|
||||
|
||||
// if(activityMainScreenInstance.hasWindowFocus())
|
||||
// {
|
||||
try
|
||||
{
|
||||
PointOfInterest activePoi = PointOfInterest.getActivePoi();
|
||||
@ -434,7 +434,7 @@ public class ActivityMainScreen extends ActivityGeneric
|
||||
else
|
||||
activityMainScreenInstance.checkForNews();
|
||||
|
||||
if(BuildConfig.FLAVOR.equals(AutomationService.flavor_name_apk) && Settings.automaticUpdateCheck)
|
||||
if(BuildConfig.FLAVOR.equals("apkFlavor") && Settings.automaticUpdateCheck)
|
||||
{
|
||||
Calendar now = Calendar.getInstance();
|
||||
if (Settings.lastUpdateCheck == Settings.default_lastUpdateCheck || now.getTimeInMillis() >= Settings.lastUpdateCheck + (long)(Settings.updateCheckFrequencyDays * 24 * 60 * 60 * 1000))
|
||||
@ -526,23 +526,15 @@ public class ActivityMainScreen extends ActivityGeneric
|
||||
{
|
||||
if (Rule.getRuleCollection().size() > 0)
|
||||
{
|
||||
if(Rule.getAmountOfActivatedRules() == 0)
|
||||
{
|
||||
Toast.makeText(context, context.getResources().getString(R.string.serviceWontStartNoActivatedRules), Toast.LENGTH_LONG).show();
|
||||
activityMainScreenInstance.toggleService.setChecked(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!AutomationService.isMyServiceRunning(context))
|
||||
{
|
||||
// if(myServiceIntent == null) //do we need that line?????
|
||||
myServiceIntent = new Intent(context, AutomationService.class);
|
||||
myServiceIntent.putExtra("startAtBoot", startAtBoot);
|
||||
context.startService(myServiceIntent);
|
||||
}
|
||||
else
|
||||
} else
|
||||
Miscellaneous.logEvent("w", "Service", context.getResources().getString(R.string.logServiceAlreadyRunning), 3);
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
Toast.makeText(context, context.getResources().getString(R.string.serviceWontStart), Toast.LENGTH_LONG).show();
|
||||
activityMainScreenInstance.toggleService.setChecked(false);
|
||||
@ -579,7 +571,6 @@ public class ActivityMainScreen extends ActivityGeneric
|
||||
protected void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
toggleService.setChecked(AutomationService.isMyServiceRunning(this));
|
||||
ActivityMainScreen.updateMainScreen();
|
||||
|
||||
|
@ -3,17 +3,12 @@ package com.jens.automation2;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.TabActivity;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.widget.TabHost;
|
||||
import android.widget.TabHost.TabSpec;
|
||||
|
||||
import com.jens.automation2.receivers.NfcReceiver;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
public class ActivityMainTabLayout extends TabActivity
|
||||
@ -22,8 +17,8 @@ public class ActivityMainTabLayout extends TabActivity
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Settings.readFromPersistentStorage(ActivityMainTabLayout.this);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
|
||||
if(Settings.tabsPlacement == 1)
|
||||
setContentView(R.layout.main_tab_layout_tabs_at_bottom);
|
||||
@ -65,7 +60,6 @@ public class ActivityMainTabLayout extends TabActivity
|
||||
protected void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
// Miscellaneous.logEvent("i", "NFC", "ActivityMainTabLayout.onResume().", 5);
|
||||
NfcReceiver.checkIntentForNFC(this, getIntent());
|
||||
// NfcReceiver.checkIntentForNFC(this, new Intent(this.getApplicationContext(), this.getClass()));
|
||||
|
@ -26,7 +26,6 @@ public class ActivityManageActionBrightnessSetting extends Activity
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
setContentView(R.layout.activity_manage_action_brightness_settings);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
chkAutoBrightness = (CheckBox)findViewById(R.id.chkAutoBrightness);
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.jens.automation2;
|
||||
|
||||
import static com.jens.automation2.Trigger.triggerParameter2Split;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.ProgressDialog;
|
||||
@ -16,12 +18,11 @@ import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
@ -42,15 +43,13 @@ public class ActivityManageActionCloseNotification extends Activity
|
||||
boolean edit = false;
|
||||
ProgressDialog progressDialog = null;
|
||||
|
||||
EditText etNotificationTitle, etNotificationText, etNotificationDismissalButtonText;
|
||||
EditText etNotificationTitle, etNotificationText;
|
||||
Button bSelectApp, bSaveActionCloseNotification;
|
||||
Spinner spinnerTitleDirection, spinnerTextDirection;
|
||||
TextView tvSelectedApplication;
|
||||
RadioButton rbNotificationDismissSimple, rbNotificationDismissButton;
|
||||
|
||||
private static List<PackageInfo> pInfos = null;
|
||||
|
||||
final static String dismissRegularString = "p0815DismissString";
|
||||
public static Trigger resultingTrigger;
|
||||
|
||||
private static String[] directions;
|
||||
|
||||
@ -259,7 +258,6 @@ public class ActivityManageActionCloseNotification extends Activity
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
setContentView(R.layout.activity_manage_action_close_notification);
|
||||
|
||||
etNotificationTitle = (EditText)findViewById(R.id.etNotificationTitle);
|
||||
@ -269,14 +267,10 @@ public class ActivityManageActionCloseNotification extends Activity
|
||||
spinnerTitleDirection = (Spinner)findViewById(R.id.spinnerTitleDirection);
|
||||
spinnerTextDirection = (Spinner)findViewById(R.id.spinnerTextDirection);
|
||||
tvSelectedApplication = (TextView)findViewById(R.id.etActivityOrActionPath);
|
||||
etNotificationDismissalButtonText = (EditText)findViewById(R.id.etNotificationDismissalButtonText);
|
||||
rbNotificationDismissSimple = (RadioButton)findViewById(R.id.rbNotificationDismissSimple);
|
||||
rbNotificationDismissButton = (RadioButton)findViewById(R.id.rbNotificationDismissButton);
|
||||
|
||||
directions = new String[] {
|
||||
getResources().getString(R.string.directionStringEquals),
|
||||
getResources().getString(R.string.directionStringContains),
|
||||
getResources().getString(R.string.directionStringDoesNotContain),
|
||||
getResources().getString(R.string.directionStringStartsWith),
|
||||
getResources().getString(R.string.directionStringEndsWith),
|
||||
getResources().getString(R.string.directionStringNotEquals)
|
||||
@ -304,7 +298,7 @@ public class ActivityManageActionCloseNotification extends Activity
|
||||
public void onClick(View v)
|
||||
{
|
||||
String app;
|
||||
if (tvSelectedApplication.getText().toString().equalsIgnoreCase(getResources().getString(R.string.anyApp)))
|
||||
if(tvSelectedApplication.getText().toString().equalsIgnoreCase(getResources().getString(R.string.anyApp)))
|
||||
app = Trigger.anyAppString;
|
||||
else
|
||||
app = tvSelectedApplication.getText().toString();
|
||||
@ -315,44 +309,34 @@ public class ActivityManageActionCloseNotification extends Activity
|
||||
String text = etNotificationText.getText().toString();
|
||||
|
||||
Intent responseData = new Intent();
|
||||
|
||||
String dismissMethod;
|
||||
if (rbNotificationDismissSimple.isChecked())
|
||||
dismissMethod = dismissRegularString;
|
||||
if(edit)
|
||||
{
|
||||
// editedNotificationAction.setTriggerParameter(chkNotificationDirection.isChecked());
|
||||
responseData.putExtra(ActivityManageRule.intentNameActionParameter2, app + Action.actionParameter2Split + titleDir + Action.actionParameter2Split + title + Action.actionParameter2Split + textDir + Action.actionParameter2Split + text);
|
||||
ActivityManageActionCloseNotification.this.setResult(RESULT_OK, responseData);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(StringUtils.isEmpty(etNotificationDismissalButtonText.getText().toString()))
|
||||
{
|
||||
Toast.makeText(ActivityManageActionCloseNotification.this, getResources().getString(R.string.enterText), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
else
|
||||
dismissMethod = etNotificationDismissalButtonText.getText().toString();
|
||||
// data.putExtra(intentNameNotificationDirection, chkNotificationDirection.isChecked());
|
||||
responseData.putExtra(ActivityManageRule.intentNameActionParameter2,
|
||||
app + Action.actionParameter2Split +
|
||||
titleDir + Action.actionParameter2Split +
|
||||
title + Action.actionParameter2Split +
|
||||
textDir + Action.actionParameter2Split +
|
||||
text
|
||||
);
|
||||
// data.putExtra(intentNameNotificationApp, app);
|
||||
// data.putExtra(intentNameNotificationTitleDir, titleDir);
|
||||
// data.putExtra(intentNameNotificationTitle, title);
|
||||
// data.putExtra(intentNameNotificationTextDir, textDir);
|
||||
// data.putExtra(intentNameNotificationText, text);
|
||||
ActivityManageActionCloseNotification.this.setResult(RESULT_OK, responseData);
|
||||
}
|
||||
|
||||
responseData.putExtra(ActivityManageRule.intentNameActionParameter2,
|
||||
app + Action.actionParameter2Split +
|
||||
titleDir + Action.actionParameter2Split +
|
||||
title + Action.actionParameter2Split +
|
||||
textDir + Action.actionParameter2Split +
|
||||
text + Action.actionParameter2Split +
|
||||
dismissMethod
|
||||
);
|
||||
|
||||
ActivityManageActionCloseNotification.this.setResult(RESULT_OK, responseData);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
rbNotificationDismissSimple.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
|
||||
{
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean b)
|
||||
{
|
||||
etNotificationDismissalButtonText.setEnabled(!b);
|
||||
}
|
||||
});
|
||||
|
||||
Intent i = getIntent();
|
||||
if(!StringUtils.isBlank(i.getStringExtra(ActivityManageRule.intentNameActionParameter2)))
|
||||
{
|
||||
@ -375,24 +359,6 @@ public class ActivityManageActionCloseNotification extends Activity
|
||||
else
|
||||
text = "";
|
||||
|
||||
/*
|
||||
That's not reliable, yet. Last parameter may be empty, hence the method might
|
||||
be incorrectly interpreted as a text notification text.
|
||||
*/
|
||||
|
||||
if (params.length >= 6 && !params[5].equals(dismissRegularString))
|
||||
{
|
||||
rbNotificationDismissButton.setChecked(true);
|
||||
etNotificationDismissalButtonText.setText(params[5]);
|
||||
etNotificationDismissalButtonText.setEnabled(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
rbNotificationDismissSimple.setChecked(true);
|
||||
etNotificationDismissalButtonText.setText("");
|
||||
etNotificationDismissalButtonText.setEnabled(false);
|
||||
}
|
||||
|
||||
if(!app.equals(Trigger.anyAppString))
|
||||
tvSelectedApplication.setText(app);
|
||||
|
||||
|
@ -19,7 +19,6 @@ public class ActivityManageActionControlMedia extends Activity
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
setContentView(R.layout.activity_manage_action_control_media);
|
||||
|
||||
rbMediaPlayPause = (RadioButton)findViewById(R.id.rbMediaPlayPause);
|
||||
|
@ -1,53 +0,0 @@
|
||||
package com.jens.automation2;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class ActivityManageActionCopyToClipboard extends Activity
|
||||
{
|
||||
private Button bSaveCopyToClipboard;
|
||||
private EditText etCopyToClipboard;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
this.setContentView(R.layout.activity_manage_action_copy_to_clipboard);
|
||||
|
||||
bSaveCopyToClipboard = (Button) findViewById(R.id.bSaveCopyToClipboard);
|
||||
etCopyToClipboard = (EditText)findViewById(R.id.etCopyToClipboard);
|
||||
|
||||
bSaveCopyToClipboard.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
if(StringUtils.isEmpty(etCopyToClipboard.getText().toString()))
|
||||
{
|
||||
Toast.makeText(ActivityManageActionCopyToClipboard.this, getResources().getString(R.string.enterText), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
else
|
||||
{
|
||||
Intent response = new Intent();
|
||||
response.putExtra(ActivityManageRule.intentNameActionParameter2, etCopyToClipboard.getText().toString());
|
||||
setResult(RESULT_OK, response);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if(getIntent().hasExtra(ActivityManageRule.intentNameActionParameter2))
|
||||
{
|
||||
String text = getIntent().getStringExtra(ActivityManageRule.intentNameActionParameter2);
|
||||
etCopyToClipboard.setText(text);
|
||||
}
|
||||
}
|
||||
}
|
@ -24,7 +24,6 @@ public class ActivityManageActionCreateNotification extends Activity
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
setContentView(R.layout.activity_manage_action_create_notification);
|
||||
|
||||
etNotificationTitle = (EditText) findViewById(R.id.etNotificationTitle);
|
||||
|
@ -1,75 +0,0 @@
|
||||
package com.jens.automation2;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.RadioButton;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
public class ActivityManageActionLocationService extends Activity
|
||||
{
|
||||
RadioButton rbActionLocationServiceOff, rbActionLocationServiceSensorsOnly, rbActionLocationServiceBatterySaving, rbActionLocationServiceHighAccuracy;
|
||||
Button bActionSetLocationServiceSave;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
setContentView(R.layout.activity_manage_action_location_service);
|
||||
|
||||
rbActionLocationServiceOff = (RadioButton) findViewById(R.id.rbActionLocationServiceOff);
|
||||
rbActionLocationServiceSensorsOnly = (RadioButton)findViewById(R.id.rbActionLocationServiceSensorsOnly);
|
||||
rbActionLocationServiceBatterySaving = (RadioButton)findViewById(R.id.rbActionLocationServiceBatterySaving);
|
||||
rbActionLocationServiceHighAccuracy = (RadioButton)findViewById(R.id.rbActionLocationServiceHighAccuracy);
|
||||
bActionSetLocationServiceSave = (Button) findViewById(R.id.bActionSetLocationServiceSave);
|
||||
|
||||
Intent input = getIntent();
|
||||
|
||||
if(input.hasExtra(ActivityManageRule.intentNameActionParameter2))
|
||||
{
|
||||
String[] params = input.getStringExtra(ActivityManageRule.intentNameActionParameter2).split(Action.actionParameter2Split);
|
||||
int desiredState = Integer.parseInt(params[0]);
|
||||
|
||||
switch(desiredState)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
bActionSetLocationServiceSave.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View view)
|
||||
{
|
||||
Intent response = new Intent();
|
||||
if(rbActionLocationServiceOff.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);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
package com.jens.automation2;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class ActivityManageActionMakePhoneCall extends Activity
|
||||
{
|
||||
EditText etTargetPhoneNumber;
|
||||
Button bActionMakePhoneCallSave;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
setContentView(R.layout.activity_manage_action_make_phone_call);
|
||||
|
||||
etTargetPhoneNumber = (EditText)findViewById(R.id.etTargetPhoneNumber);
|
||||
bActionMakePhoneCallSave = (Button) findViewById(R.id.bActionMakePhoneCallSave);
|
||||
|
||||
Intent input = getIntent();
|
||||
/*if(input.hasExtra(ActivityManageRule.intentNameActionParameter1))
|
||||
rbActionWifiOn.setChecked(input.getBooleanExtra(ActivityManageRule.intentNameActionParameter1, true));
|
||||
*/
|
||||
if(input.hasExtra(ActivityManageRule.intentNameActionParameter2))
|
||||
etTargetPhoneNumber.setText(input.getStringExtra(ActivityManageRule.intentNameActionParameter2));
|
||||
|
||||
bActionMakePhoneCallSave.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View view)
|
||||
{
|
||||
if(!StringUtils.isEmpty(etTargetPhoneNumber.getText()))
|
||||
{
|
||||
Intent response = new Intent();
|
||||
response.putExtra(ActivityManageRule.intentNameActionParameter1, false);
|
||||
response.putExtra(ActivityManageRule.intentNameActionParameter2, etTargetPhoneNumber.getText().toString());
|
||||
setResult(RESULT_OK, response);
|
||||
finish();
|
||||
}
|
||||
else
|
||||
Toast.makeText(ActivityManageActionMakePhoneCall.this, getResources().getText(R.string.enterPhoneNumber), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -26,7 +26,6 @@ public class ActivityManageActionPlaySound extends Activity
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
setContentView(R.layout.activity_manage_action_play_sound);
|
||||
|
||||
chkPlaySoundAlwaysPlay = (CheckBox)findViewById(R.id.chkPlaySoundAlwaysPlay);
|
||||
|
@ -1,124 +0,0 @@
|
||||
package com.jens.automation2;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class ActivityManageActionRunExecutable extends Activity
|
||||
{
|
||||
final static int PICKFILE_RESULT_CODE = 4711;
|
||||
|
||||
CheckBox chkRunExecAsRoot;
|
||||
EditText etRunExecutablePath, etRunExecutableParameters;
|
||||
Button bChooseExecutable, bSaveActionRunExec;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
setContentView(R.layout.activity_manage_action_run_executable);
|
||||
|
||||
chkRunExecAsRoot = (CheckBox)findViewById(R.id.chkRunExecAsRoot);
|
||||
etRunExecutablePath = (EditText) findViewById(R.id.etRunExecutablePath);
|
||||
etRunExecutableParameters = (EditText) findViewById(R.id.etRunExecutableParameters);
|
||||
bChooseExecutable = (Button) findViewById(R.id.bChooseExecutable);
|
||||
bSaveActionRunExec = (Button) findViewById(R.id.bSaveActionRunExec);
|
||||
|
||||
bChooseExecutable.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
//Need to check for storage permissions
|
||||
Intent chooseFile = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
chooseFile.setType("*/*");
|
||||
chooseFile = Intent.createChooser(chooseFile, getResources().getString(R.string.selectSoundFile));
|
||||
startActivityForResult(chooseFile, PICKFILE_RESULT_CODE);
|
||||
}
|
||||
});
|
||||
|
||||
bSaveActionRunExec.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View view)
|
||||
{
|
||||
saveExecSettings();
|
||||
}
|
||||
});
|
||||
|
||||
if(getIntent().hasExtra(ActivityManageRule.intentNameActionParameter2))
|
||||
{
|
||||
String[] parts = getIntent().getStringExtra(ActivityManageRule.intentNameActionParameter2).split(Action.actionParameter2Split);
|
||||
etRunExecutablePath.setText(parts[0]);
|
||||
|
||||
if(parts.length > 1)
|
||||
etRunExecutableParameters.setText(parts[1]);
|
||||
}
|
||||
}
|
||||
|
||||
void saveExecSettings()
|
||||
{
|
||||
if(etRunExecutablePath.getText().toString() == null || etRunExecutablePath.getText().toString().length() == 0)
|
||||
{
|
||||
Toast.makeText(ActivityManageActionRunExecutable.this, getResources().getString(R.string.selectValidExecutable), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
File executableFile = new File(etRunExecutablePath.getText().toString());
|
||||
if(!executableFile.exists())
|
||||
{
|
||||
Toast.makeText(ActivityManageActionRunExecutable.this, getResources().getString(R.string.fileDoesNotExist), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!chkRunExecAsRoot.isChecked() && !executableFile.canExecute())
|
||||
{
|
||||
Toast.makeText(ActivityManageActionRunExecutable.this, getResources().getString(R.string.fileNotExecutable), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Intent returnData = new Intent();
|
||||
returnData.putExtra(ActivityManageRule.intentNameActionParameter1, chkRunExecAsRoot.isChecked());
|
||||
|
||||
if(etRunExecutableParameters.getText() != null && !StringUtils.isEmpty(etRunExecutableParameters.getText().toString()))
|
||||
returnData.putExtra(ActivityManageRule.intentNameActionParameter2, etRunExecutablePath.getText().toString() + Action.actionParameter2Split + etRunExecutableParameters.getText().toString());
|
||||
else
|
||||
returnData.putExtra(ActivityManageRule.intentNameActionParameter2, etRunExecutablePath.getText().toString());
|
||||
|
||||
setResult(RESULT_OK, returnData);
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data)
|
||||
{
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
if(requestCode == PICKFILE_RESULT_CODE)
|
||||
{
|
||||
Uri fileUri = data.getData();
|
||||
String filePath = CompensateCrappyAndroidPaths.getPath(ActivityManageActionRunExecutable.this, fileUri);
|
||||
etRunExecutablePath.setText(filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,280 +0,0 @@
|
||||
package com.jens.automation2;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.InputType;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ActivityManageActionSendBroadcast extends Activity
|
||||
{
|
||||
EditText etBroadcastToSend;
|
||||
Button bBroadcastSendShowSuggestions, bSaveSendBroadcast, bAddIntentPair;
|
||||
ListView lvIntentPairs;
|
||||
EditText etParameterName, etParameterValue;
|
||||
Spinner spinnerParameterType;
|
||||
ArrayAdapter<String> intentTypeSpinnerAdapter, intentPairAdapter;
|
||||
private static final String[] supportedIntentTypes = { "boolean", "byte", "char", "double", "float", "int", "long", "short", "String", "Uri" };
|
||||
private ArrayList<String> intentPairList = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
setContentView(R.layout.activity_manage_action_send_broadcast);
|
||||
|
||||
etBroadcastToSend = (EditText)findViewById(R.id.etBroadcastToSend);
|
||||
bBroadcastSendShowSuggestions = (Button)findViewById(R.id.bBroadcastSendShowSuggestions);
|
||||
bSaveSendBroadcast = (Button)findViewById(R.id.bSaveSendBroadcast);
|
||||
bAddIntentPair = (Button)findViewById(R.id.bAddIntentPair);
|
||||
lvIntentPairs = (ListView) findViewById(R.id.lvIntentPairs);
|
||||
etParameterName = (EditText) findViewById(R.id.etParameterName);
|
||||
etParameterValue = (EditText) findViewById(R.id.etParameterValue);
|
||||
spinnerParameterType = (Spinner) findViewById(R.id.spinnerParameterType);
|
||||
|
||||
intentTypeSpinnerAdapter = new ArrayAdapter<String>(this, R.layout.text_view_for_poi_listview_mediumtextsize, ActivityManageActionSendBroadcast.supportedIntentTypes);
|
||||
spinnerParameterType.setAdapter(intentTypeSpinnerAdapter);
|
||||
intentTypeSpinnerAdapter.notifyDataSetChanged();
|
||||
intentPairAdapter = new ArrayAdapter<String>(this, R.layout.text_view_for_poi_listview_mediumtextsize, intentPairList);
|
||||
|
||||
bSaveSendBroadcast.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View view)
|
||||
{
|
||||
if(checkInput())
|
||||
{
|
||||
Intent answer = new Intent();
|
||||
|
||||
String param2 = etBroadcastToSend.getText().toString();
|
||||
|
||||
if(intentPairList.size() > 0)
|
||||
{
|
||||
param2 += Action.actionParameter2Split;
|
||||
|
||||
for (String s : intentPairList)
|
||||
param2 += s + ";";
|
||||
|
||||
param2 = param2.substring(0, param2.length() - 1);
|
||||
}
|
||||
|
||||
answer.putExtra(ActivityManageRule.intentNameActionParameter2, param2);
|
||||
setResult(RESULT_OK, answer);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
bBroadcastSendShowSuggestions.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(ActivityManageActionSendBroadcast.this);
|
||||
builder.setTitle(getResources().getString(R.string.selectBroadcast));
|
||||
builder.setItems(ActivityManageTriggerBroadcast.broadcastSuggestions, new DialogInterface.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int which)
|
||||
{
|
||||
etBroadcastToSend.setText(ActivityManageTriggerBroadcast.broadcastSuggestions[which]);
|
||||
}
|
||||
});
|
||||
builder.create().show();
|
||||
}
|
||||
});
|
||||
|
||||
Intent input = getIntent();
|
||||
|
||||
if(input.hasExtra(ActivityManageRule.intentNameActionParameter2))
|
||||
{
|
||||
String param2 = input.getStringExtra(ActivityManageRule.intentNameActionParameter2);
|
||||
if(!param2.contains(Action.actionParameter2Split))
|
||||
etBroadcastToSend.setText(input.getStringExtra(ActivityManageRule.intentNameActionParameter2));
|
||||
else
|
||||
{
|
||||
String[] param2Parts = param2.split(Action.actionParameter2Split);
|
||||
etBroadcastToSend.setText(param2Parts[0]);
|
||||
|
||||
String[] params = param2Parts[1].split(";");
|
||||
|
||||
intentPairList.clear();
|
||||
|
||||
for(int i = 0; i < params.length; i++)
|
||||
{
|
||||
if(lvIntentPairs.getVisibility() != View.VISIBLE)
|
||||
lvIntentPairs.setVisibility(View.VISIBLE);
|
||||
|
||||
intentPairList.add(params[i]);
|
||||
}
|
||||
|
||||
updateIntentPairList();
|
||||
}
|
||||
}
|
||||
|
||||
bAddIntentPair.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
// type;name;value
|
||||
if(spinnerParameterType.getSelectedItem().toString().length() == 0)
|
||||
{
|
||||
Toast.makeText(ActivityManageActionSendBroadcast.this, getResources().getString(R.string.selectTypeOfIntentPair), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
if(etParameterName.getText().toString().length() == 0)
|
||||
{
|
||||
Toast.makeText(ActivityManageActionSendBroadcast.this, getResources().getString(R.string.enterNameForIntentPair), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
else if(etParameterName.getText().toString().contains(Action.intentPairSeparator))
|
||||
{
|
||||
Toast.makeText(ActivityManageActionSendBroadcast.this, String.format(getResources().getString(R.string.stringNotAllowed), Action.intentPairSeparator), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
else if(etParameterName.getText().toString().contains(";"))
|
||||
{
|
||||
Toast.makeText(ActivityManageActionSendBroadcast.this, String.format(getResources().getString(R.string.stringNotAllowed), ";"), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
if(etParameterValue.getText().toString().length() == 0)
|
||||
{
|
||||
Toast.makeText(ActivityManageActionSendBroadcast.this, getResources().getString(R.string.enterValueForIntentPair), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
else if(etParameterValue.getText().toString().contains(Action.intentPairSeparator))
|
||||
{
|
||||
Toast.makeText(ActivityManageActionSendBroadcast.this, String.format(getResources().getString(R.string.stringNotAllowed), Action.intentPairSeparator), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
else if(etParameterValue.getText().toString().contains(";"))
|
||||
{
|
||||
Toast.makeText(ActivityManageActionSendBroadcast.this, String.format(getResources().getString(R.string.stringNotAllowed), ";"), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
switch(supportedIntentTypes[spinnerParameterType.getSelectedItemPosition()])
|
||||
{
|
||||
case "int":
|
||||
case "long":
|
||||
case "short":
|
||||
if(!Miscellaneous.isNumeric(etParameterValue.getText().toString()))
|
||||
{
|
||||
Toast.makeText(ActivityManageActionSendBroadcast.this, getResources().getString(R.string.enter_a_number), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case "double":
|
||||
case "float":
|
||||
if(!Miscellaneous.isNumericDecimal(etParameterValue.getText().toString()))
|
||||
{
|
||||
Toast.makeText(ActivityManageActionSendBroadcast.this, getResources().getString(R.string.enter_a_number), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ActivityManageActionSendBroadcast.this.etParameterValue.setInputType(InputType.TYPE_CLASS_TEXT);
|
||||
}
|
||||
|
||||
String param = supportedIntentTypes[spinnerParameterType.getSelectedItemPosition()] + Action.intentPairSeparator + etParameterName.getText().toString() + Action.intentPairSeparator + etParameterValue.getText().toString();
|
||||
intentPairList.add(param);
|
||||
|
||||
spinnerParameterType.setSelection(0);
|
||||
etParameterName.setText("");
|
||||
etParameterValue.setText("");
|
||||
|
||||
updateIntentPairList();
|
||||
|
||||
if(lvIntentPairs.getVisibility() != View.VISIBLE)
|
||||
lvIntentPairs.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
|
||||
lvIntentPairs.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener()
|
||||
{
|
||||
@Override
|
||||
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)
|
||||
{
|
||||
getIntentPairDialog(arg2).show();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
spinnerParameterType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
|
||||
{
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3)
|
||||
{
|
||||
if(supportedIntentTypes[arg2].equals("int") || supportedIntentTypes[arg2].equals("long") || supportedIntentTypes[arg2].equals("short"))
|
||||
ActivityManageActionSendBroadcast.this.etParameterValue.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED);
|
||||
else if(supportedIntentTypes[arg2].equals("double") || supportedIntentTypes[arg2].equals("float"))
|
||||
ActivityManageActionSendBroadcast.this.etParameterValue.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
|
||||
else
|
||||
ActivityManageActionSendBroadcast.this.etParameterValue.setInputType(InputType.TYPE_CLASS_TEXT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> arg0)
|
||||
{
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
boolean checkInput()
|
||||
{
|
||||
String broadcastToSend = etBroadcastToSend.getText().toString();
|
||||
if(StringUtils.isEmpty(broadcastToSend))
|
||||
{
|
||||
Toast.makeText(ActivityManageActionSendBroadcast.this, getResources().getString(R.string.enterBroadcast), Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void updateIntentPairList()
|
||||
{
|
||||
if(lvIntentPairs.getAdapter() == null)
|
||||
lvIntentPairs.setAdapter(intentPairAdapter);
|
||||
|
||||
intentPairAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private AlertDialog getIntentPairDialog(final int itemPosition)
|
||||
{
|
||||
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ActivityManageActionSendBroadcast.this);
|
||||
alertDialogBuilder.setTitle(getResources().getString(R.string.whatToDoWithIntentPair));
|
||||
alertDialogBuilder.setItems(new String[]{getResources().getString(R.string.delete)}, new DialogInterface.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
// Only 1 choice at the moment, no need to check
|
||||
ActivityManageActionSendBroadcast.this.intentPairList.remove(itemPosition);
|
||||
updateIntentPairList();
|
||||
}
|
||||
});
|
||||
AlertDialog alertDialog = alertDialogBuilder.create();
|
||||
return alertDialog;
|
||||
}
|
||||
}
|
@ -9,37 +9,26 @@ import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.provider.ContactsContract;
|
||||
import android.provider.MediaStore;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.RadioGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.jens.automation2.Action.Action_Enum;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
|
||||
public class ActivityManageActionSendTextMessage extends Activity
|
||||
{
|
||||
Button bSaveSendTextMessage, bImportNumberFromContacts, bMmsAttachment;
|
||||
Button bSaveSendTextMessage, bImportNumberFromContacts;
|
||||
EditText etPhoneNumber, etSendTextMessage;
|
||||
RadioButton rbMessageTypeSms, rbMessageTypeMms;
|
||||
TextView tvSendMmsFileAttachment;
|
||||
|
||||
protected final static int requestCodeForContactsPermissions = 9876;
|
||||
protected final static int requestCodeGetContact = 3235;
|
||||
protected final static int requestCodeGetMMSattachment = 3236;
|
||||
|
||||
public static final String messageTypeSms = "sms";
|
||||
public static final String messageTypeMms = "mms";
|
||||
|
||||
// private String existingUrl = "";
|
||||
|
||||
public static boolean edit = false;
|
||||
public static Action resultingAction = null;
|
||||
@ -48,17 +37,12 @@ public class ActivityManageActionSendTextMessage extends Activity
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
this.setContentView(R.layout.activity_manage_action_send_textmessage);
|
||||
|
||||
etSendTextMessage = (EditText)findViewById(R.id.etSendTextMessage);
|
||||
etPhoneNumber = (EditText)findViewById(R.id.etPhoneNumber);
|
||||
bSaveSendTextMessage = (Button)findViewById(R.id.bSaveSendTextMessage);
|
||||
bImportNumberFromContacts = (Button)findViewById(R.id.bImportNumberFromContacts);
|
||||
rbMessageTypeSms = (RadioButton)findViewById(R.id.rbMessageTypeSms);
|
||||
rbMessageTypeMms = (RadioButton) findViewById(R.id.rbMessageTypeMms);
|
||||
bMmsAttachment = (Button)findViewById(R.id.bMmsAttachment);
|
||||
tvSendMmsFileAttachment = (TextView)findViewById(R.id.tvSendMmsFileAttachment);
|
||||
|
||||
bSaveSendTextMessage.setOnClickListener(new OnClickListener()
|
||||
{
|
||||
@ -67,29 +51,13 @@ public class ActivityManageActionSendTextMessage extends Activity
|
||||
{
|
||||
if(etSendTextMessage.getText().toString().length() > 0 && etPhoneNumber.getText().toString().length() > 0)
|
||||
{
|
||||
if(rbMessageTypeMms.isChecked() && StringUtils.isEmpty(tvSendMmsFileAttachment.getText().toString()))
|
||||
Toast.makeText(getBaseContext(), getResources().getString(R.string.chooseFile), Toast.LENGTH_LONG).show();
|
||||
else
|
||||
if(resultingAction == null)
|
||||
{
|
||||
if (resultingAction == null)
|
||||
{
|
||||
resultingAction = new Action();
|
||||
resultingAction.setAction(Action_Enum.sendTextMessage);
|
||||
String messageType = null;
|
||||
String path = "";
|
||||
|
||||
if(rbMessageTypeSms.isChecked())
|
||||
messageType = messageTypeSms;
|
||||
else
|
||||
{
|
||||
messageType = messageTypeMms;
|
||||
path = Actions.smsSeparator + tvSendMmsFileAttachment.getText().toString();
|
||||
}
|
||||
|
||||
resultingAction.setParameter2(etPhoneNumber.getText().toString() + Actions.smsSeparator + etSendTextMessage.getText().toString() + Actions.smsSeparator + messageType + path);
|
||||
}
|
||||
backToRuleManager();
|
||||
resultingAction = new Action();
|
||||
resultingAction.setAction(Action_Enum.sendTextMessage);
|
||||
resultingAction.setParameter2(etPhoneNumber.getText().toString() + Actions.smsSeparator + etSendTextMessage.getText().toString());
|
||||
}
|
||||
backToRuleManager();
|
||||
}
|
||||
else
|
||||
Toast.makeText(getBaseContext(), getResources().getString(R.string.enterPhoneNumberAndText), Toast.LENGTH_LONG).show();
|
||||
@ -110,28 +78,6 @@ public class ActivityManageActionSendTextMessage extends Activity
|
||||
}
|
||||
});
|
||||
|
||||
RadioButton.OnCheckedChangeListener checkedChangedListener = new RadioButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean b)
|
||||
{
|
||||
bMmsAttachment.setEnabled(rbMessageTypeMms.isChecked());
|
||||
}
|
||||
};
|
||||
rbMessageTypeSms.setOnCheckedChangeListener(checkedChangedListener);
|
||||
rbMessageTypeMms.setOnCheckedChangeListener(checkedChangedListener);
|
||||
|
||||
bMmsAttachment.setOnClickListener(new OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View view)
|
||||
{
|
||||
Intent chooseFileIntent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
chooseFileIntent.setType("*/*");
|
||||
chooseFileIntent = Intent.createChooser(chooseFileIntent, getResources().getString(R.string.chooseFile));
|
||||
startActivityForResult(chooseFileIntent, requestCodeGetMMSattachment);
|
||||
}
|
||||
});
|
||||
|
||||
ActivityManageActionSendTextMessage.edit = getIntent().getBooleanExtra("edit", false);
|
||||
if(edit)
|
||||
{
|
||||
@ -198,10 +144,10 @@ public class ActivityManageActionSendTextMessage extends Activity
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data)
|
||||
{
|
||||
if(resultCode == Activity.RESULT_OK)
|
||||
{
|
||||
if(requestCode == requestCodeGetContact)
|
||||
{
|
||||
if(requestCode == requestCodeGetContact)
|
||||
{
|
||||
if(resultCode == Activity.RESULT_OK)
|
||||
{
|
||||
String phoneNo = null;
|
||||
String name = null;
|
||||
|
||||
@ -219,12 +165,6 @@ public class ActivityManageActionSendTextMessage extends Activity
|
||||
etPhoneNumber.setText(phoneNo);
|
||||
}
|
||||
}
|
||||
else if (requestCode == requestCodeGetMMSattachment)
|
||||
{
|
||||
Uri fileUri = data.getData();
|
||||
String filePath = fileUri.getPath();
|
||||
tvSendMmsFileAttachment.setText(filePath);
|
||||
}
|
||||
}
|
||||
//super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
@ -1,65 +0,0 @@
|
||||
package com.jens.automation2;
|
||||
|
||||
//import static com.jens.automation2.ActivityManageActionTriggerUrl.edit;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.jens.automation2.Action.Action_Enum;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class ActivityManageActionSetVariable extends Activity
|
||||
{
|
||||
private Button bSaveVariable;
|
||||
private EditText etVariableSetKey, etVariableSetValue;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
this.setContentView(R.layout.activity_manage_action_set_variable);
|
||||
|
||||
etVariableSetKey = (EditText)findViewById(R.id.etVariableSetKey);
|
||||
etVariableSetValue = (EditText)findViewById(R.id.etVariableSetValue);
|
||||
bSaveVariable = (Button)findViewById(R.id.bSaveVariable);
|
||||
bSaveVariable.setOnClickListener(new OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
if(StringUtils.isEmpty(etVariableSetKey.getText().toString()))
|
||||
{
|
||||
Toast.makeText(ActivityManageActionSetVariable.this, getResources().getString(R.string.enterVariableKey), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
else
|
||||
{
|
||||
Intent response = new Intent();
|
||||
|
||||
if(StringUtils.isEmpty(etVariableSetValue.getText().toString()))
|
||||
response.putExtra(ActivityManageRule.intentNameActionParameter2, etVariableSetKey.getText().toString());
|
||||
else
|
||||
response.putExtra(ActivityManageRule.intentNameActionParameter2, etVariableSetKey.getText().toString() + Action.actionParameter2Split + etVariableSetValue.getText().toString());
|
||||
|
||||
setResult(RESULT_OK, response);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if(getIntent().hasExtra(ActivityManageRule.intentNameActionParameter2))
|
||||
{
|
||||
String[] input = getIntent().getStringExtra(ActivityManageRule.intentNameActionParameter2).split(Action.actionParameter2Split);
|
||||
etVariableSetKey.setText(input[0]);
|
||||
if(input.length > 1)
|
||||
etVariableSetValue.setText(input[1]);
|
||||
}
|
||||
}
|
||||
}
|
@ -15,6 +15,8 @@ public class ActivityManageActionSpeakText extends Activity
|
||||
private Button bSaveSpeakText;
|
||||
private EditText etSpeakText;
|
||||
|
||||
// private String existingUrl = "";
|
||||
|
||||
public static boolean edit = false;
|
||||
public static Action resultingAction = null;
|
||||
|
||||
@ -22,11 +24,10 @@ public class ActivityManageActionSpeakText extends Activity
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
this.setContentView(R.layout.activity_manage_action_speak_text);
|
||||
|
||||
etSpeakText = (EditText)findViewById(R.id.etTextToSpeak);
|
||||
bSaveSpeakText = (Button)findViewById(R.id.bSaveSpeakText);
|
||||
bSaveSpeakText = (Button)findViewById(R.id.bSaveTriggerUrl);
|
||||
bSaveSpeakText.setOnClickListener(new OnClickListener()
|
||||
{
|
||||
@Override
|
||||
|
@ -29,7 +29,6 @@ import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ListView;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.RadioGroup;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.Toast;
|
||||
|
||||
@ -49,294 +48,18 @@ public class ActivityManageActionStartActivity extends Activity
|
||||
*/
|
||||
|
||||
ListView lvIntentPairs;
|
||||
EditText etParameterName, etParameterValue, etPackageName, etActivityOrActionPath, etClassName;
|
||||
EditText etParameterName, etParameterValue, etPackageName, etActivityOrActionPath;
|
||||
Button bSelectApp, bAddIntentPair, bSaveActionStartOtherActivity, showStartProgramExamples;
|
||||
Spinner spinnerParameterType;
|
||||
RadioGroup rgAppStartupType;
|
||||
boolean edit = false;
|
||||
ProgressDialog progressDialog = null;
|
||||
RadioButton rbStartAppSelectByActivity, rbStartAppSelectByAction, rbStartAppByActivity, rbStartAppByBroadcast, rbStartAppByService, rbStartAppByForegroundService;
|
||||
RadioButton rbStartAppSelectByActivity, rbStartAppSelectByAction, rbStartAppByActivity, rbStartAppByBroadcast;
|
||||
|
||||
final String urlShowExamples = "https://server47.de/automation/examples_startProgram.html";
|
||||
public final static String startByActivityString = "0";
|
||||
public final static String startByBroadcastString = "1";
|
||||
public final static String startByServiceString = "2";
|
||||
public final static String startByForegroundServiceString = "3";
|
||||
final static String startByActivityString = "0";
|
||||
final static String startByBroadcastString = "1";
|
||||
|
||||
final static int requestCodeForRequestQueryAllPackagesPermission = 4711;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
setContentView(R.layout.activity_manage_action_start_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);
|
||||
spinnerParameterType = (Spinner)findViewById(R.id.spinnerParameterType);
|
||||
etPackageName = (EditText) findViewById(R.id.etPackageName);
|
||||
etActivityOrActionPath = (EditText) findViewById(R.id.etActivityOrActionPath);
|
||||
rbStartAppSelectByActivity = (RadioButton)findViewById(R.id.rbStartAppSelectByActivity);
|
||||
rbStartAppSelectByAction = (RadioButton)findViewById(R.id.rbStartAppSelectByAction);
|
||||
showStartProgramExamples = (Button)findViewById(R.id.showStartProgramExamples);
|
||||
rbStartAppByActivity = (RadioButton)findViewById(R.id.rbStartAppByActivity);
|
||||
rbStartAppByBroadcast = (RadioButton)findViewById(R.id.rbStartAppByBroadcast);
|
||||
rbStartAppByService = (RadioButton)findViewById(R.id.rbStartAppByService);
|
||||
rbStartAppByForegroundService = (RadioButton)findViewById(R.id.rbStartAppByForegroundService);
|
||||
rgAppStartupType = (RadioGroup)findViewById(R.id.rgAppStartupType);
|
||||
|
||||
intentTypeSpinnerAdapter = new ArrayAdapter<String>(this, R.layout.text_view_for_poi_listview_mediumtextsize, ActivityManageActionStartActivity.supportedIntentTypes);
|
||||
spinnerParameterType.setAdapter(intentTypeSpinnerAdapter);
|
||||
intentTypeSpinnerAdapter.notifyDataSetChanged();
|
||||
|
||||
etClassName.setEnabled(false);
|
||||
|
||||
intentPairAdapter = new ArrayAdapter<String>(this, R.layout.text_view_for_poi_listview_mediumtextsize, intentPairList);
|
||||
bSelectApp.setOnClickListener(new OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
int targetSdkVersion = getApplicationContext().getApplicationInfo().targetSdkVersion;
|
||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && targetSdkVersion >= 30 && !ActivityPermissions.havePermission(Manifest.permission.QUERY_ALL_PACKAGES, ActivityManageActionStartActivity.this))// && shouldShowRequestPermissionRationale(Manifest.permission.QUERY_ALL_PACKAGES))
|
||||
{
|
||||
if(BuildConfig.FLAVOR.equals(AutomationService.flavor_name_googleplay))
|
||||
{
|
||||
// This ain't possible anymore.
|
||||
Miscellaneous.messageBox(getResources().getString(R.string.info), getResources().getString(R.string.featureNotInGooglePlayVersion) + Miscellaneous.lineSeparator + Miscellaneous.lineSeparator + getResources().getString(R.string.startActivityInsertManually), ActivityManageActionStartActivity.this).show();
|
||||
}
|
||||
else
|
||||
requestPermissions(new String[] {Manifest.permission.QUERY_ALL_PACKAGES}, requestCodeForRequestQueryAllPackagesPermission);
|
||||
}
|
||||
else
|
||||
getAppList();
|
||||
}
|
||||
});
|
||||
|
||||
bAddIntentPair.setOnClickListener(new OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
// type;name;value
|
||||
if(spinnerParameterType.getSelectedItem().toString().length() == 0)
|
||||
{
|
||||
Toast.makeText(ActivityManageActionStartActivity.this, getResources().getString(R.string.selectTypeOfIntentPair), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
if(etParameterName.getText().toString().length() == 0)
|
||||
{
|
||||
Toast.makeText(ActivityManageActionStartActivity.this, getResources().getString(R.string.enterNameForIntentPair), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
else if(etParameterName.getText().toString().contains(Action.intentPairSeparator))
|
||||
{
|
||||
Toast.makeText(ActivityManageActionStartActivity.this, String.format(getResources().getString(R.string.stringNotAllowed), Action.intentPairSeparator), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
else if(etParameterName.getText().toString().contains(";"))
|
||||
{
|
||||
Toast.makeText(ActivityManageActionStartActivity.this, String.format(getResources().getString(R.string.stringNotAllowed), ";"), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
if(etParameterValue.getText().toString().length() == 0)
|
||||
{
|
||||
Toast.makeText(ActivityManageActionStartActivity.this, getResources().getString(R.string.enterValueForIntentPair), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
else if(etParameterValue.getText().toString().contains(Action.intentPairSeparator))
|
||||
{
|
||||
Toast.makeText(ActivityManageActionStartActivity.this, String.format(getResources().getString(R.string.stringNotAllowed), Action.intentPairSeparator), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
else if(etParameterValue.getText().toString().contains(";"))
|
||||
{
|
||||
Toast.makeText(ActivityManageActionStartActivity.this, String.format(getResources().getString(R.string.stringNotAllowed), ";"), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
switch(supportedIntentTypes[spinnerParameterType.getSelectedItemPosition()])
|
||||
{
|
||||
case "int":
|
||||
case "long":
|
||||
case "short":
|
||||
if(!Miscellaneous.isNumeric(etParameterValue.getText().toString()))
|
||||
{
|
||||
Toast.makeText(ActivityManageActionStartActivity.this, getResources().getString(R.string.enter_a_number), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case "double":
|
||||
case "float":
|
||||
if(!Miscellaneous.isNumericDecimal(etParameterValue.getText().toString()))
|
||||
{
|
||||
Toast.makeText(ActivityManageActionStartActivity.this, getResources().getString(R.string.enter_a_number), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ActivityManageActionStartActivity.this.etParameterValue.setInputType(InputType.TYPE_CLASS_TEXT);
|
||||
}
|
||||
|
||||
String param = supportedIntentTypes[spinnerParameterType.getSelectedItemPosition()] + Action.intentPairSeparator + etParameterName.getText().toString() + Action.intentPairSeparator + etParameterValue.getText().toString();
|
||||
intentPairList.add(param);
|
||||
|
||||
spinnerParameterType.setSelection(0);
|
||||
etParameterName.setText("");
|
||||
etParameterValue.setText("");
|
||||
|
||||
updateIntentPairList();
|
||||
|
||||
if(lvIntentPairs.getVisibility() != View.VISIBLE)
|
||||
lvIntentPairs.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
|
||||
showStartProgramExamples.setOnClickListener(new OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlShowExamples));
|
||||
startActivity(browserIntent);
|
||||
}
|
||||
});
|
||||
|
||||
lvIntentPairs.setOnItemLongClickListener(new OnItemLongClickListener()
|
||||
{
|
||||
@Override
|
||||
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)
|
||||
{
|
||||
getIntentPairDialog(arg2).show();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
bSaveActionStartOtherActivity.setOnClickListener(new OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
if(checkInput())
|
||||
{
|
||||
Intent returnData = new Intent();
|
||||
|
||||
returnData.putExtra(ActivityManageRule.intentNameActionParameter1, rbStartAppSelectByAction.isChecked());
|
||||
|
||||
String parameter2 = "";
|
||||
|
||||
if (rbStartAppSelectByActivity.isChecked())
|
||||
parameter2 += etPackageName.getText().toString() + Action.actionParameter2Split + etActivityOrActionPath.getText().toString();
|
||||
else
|
||||
{
|
||||
if (etPackageName.getText().toString() != null && etPackageName.getText().toString().length() > 0)
|
||||
parameter2 += etPackageName.getText().toString() + Action.actionParameter2Split + etActivityOrActionPath.getText().toString();
|
||||
else
|
||||
parameter2 += Actions.dummyPackageString + Action.actionParameter2Split + etActivityOrActionPath.getText().toString();
|
||||
|
||||
parameter2 += Action.actionParameter2Split + etClassName.getText().toString();
|
||||
}
|
||||
|
||||
if (rbStartAppByActivity.isChecked())
|
||||
parameter2 += Action.actionParameter2Split + startByActivityString;
|
||||
else if(rbStartAppByService.isChecked())
|
||||
parameter2 += Action.actionParameter2Split + startByServiceString;
|
||||
else if(rbStartAppByForegroundService.isChecked())
|
||||
parameter2 += Action.actionParameter2Split + startByForegroundServiceString;
|
||||
else
|
||||
parameter2 += Action.actionParameter2Split + startByBroadcastString;
|
||||
|
||||
for (String s : intentPairList)
|
||||
parameter2 += Action.actionParameter2Split + s;
|
||||
|
||||
returnData.putExtra(ActivityManageRule.intentNameActionParameter2, parameter2);
|
||||
|
||||
setResult(RESULT_OK, returnData);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
lvIntentPairs.setOnTouchListener(new OnTouchListener()
|
||||
{
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event)
|
||||
{
|
||||
v.getParent().requestDisallowInterceptTouchEvent(true);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
spinnerParameterType.setOnItemSelectedListener(new OnItemSelectedListener()
|
||||
{
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3)
|
||||
{
|
||||
if(supportedIntentTypes[arg2].equals("int") || supportedIntentTypes[arg2].equals("long") || supportedIntentTypes[arg2].equals("short"))
|
||||
ActivityManageActionStartActivity.this.etParameterValue.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED);
|
||||
else if(supportedIntentTypes[arg2].equals("double") || supportedIntentTypes[arg2].equals("float"))
|
||||
ActivityManageActionStartActivity.this.etParameterValue.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
|
||||
else
|
||||
ActivityManageActionStartActivity.this.etParameterValue.setInputType(InputType.TYPE_CLASS_TEXT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> arg0)
|
||||
{
|
||||
}
|
||||
});
|
||||
|
||||
rbStartAppSelectByActivity.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
|
||||
{
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
|
||||
{
|
||||
if(isChecked)
|
||||
{
|
||||
bSelectApp.setEnabled(isChecked);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
rbStartAppSelectByAction.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
|
||||
{
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
|
||||
{
|
||||
if(isChecked)
|
||||
bSelectApp.setEnabled(!isChecked);
|
||||
}
|
||||
});
|
||||
|
||||
rgAppStartupType.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
|
||||
{
|
||||
@Override
|
||||
public void onCheckedChanged(RadioGroup radioGroup, int i)
|
||||
{
|
||||
if(rbStartAppByActivity.isChecked())
|
||||
etClassName.setEnabled(false);
|
||||
else if (rbStartAppByBroadcast.isChecked())
|
||||
etClassName.setEnabled(false);
|
||||
else if(rbStartAppByService.isChecked())
|
||||
etClassName.setEnabled(true);
|
||||
else if(rbStartAppByForegroundService.isChecked())
|
||||
etClassName.setEnabled(true);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Intent i = getIntent();
|
||||
if(i.hasExtra(ActivityManageRule.intentNameActionParameter1))
|
||||
loadValuesIntoGui(i);
|
||||
}
|
||||
|
||||
private class CustomPackageInfo extends PackageInfo implements Comparable<CustomPackageInfo>
|
||||
{
|
||||
@ -359,9 +82,11 @@ public class ActivityManageActionStartActivity extends Activity
|
||||
|
||||
return name1.compareTo(name2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static List<PackageInfo> pInfos = null;
|
||||
public static Action resultingAction;
|
||||
|
||||
private static final String[] supportedIntentTypes = { "boolean", "byte", "char", "double", "float", "int", "long", "short", "String", "Uri" };
|
||||
private ArrayList<String> intentPairList = new ArrayList<String>();
|
||||
@ -618,34 +343,208 @@ public class ActivityManageActionStartActivity extends Activity
|
||||
getActivityListTask.execute();
|
||||
progressDialog = ProgressDialog.show(ActivityManageActionStartActivity.this, "", ActivityManageActionStartActivity.this.getResources().getString(R.string.gettingListOfInstalledApplications));
|
||||
}
|
||||
|
||||
private void loadValuesIntoGui(Intent input)
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
boolean selectionByAction = input.getBooleanExtra(ActivityManageRule.intentNameActionParameter1, true);
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_manage_action_start_activity);
|
||||
|
||||
lvIntentPairs = (ListView)findViewById(R.id.lvIntentPairs);
|
||||
etParameterName = (EditText)findViewById(R.id.etParameterName);
|
||||
etParameterValue = (EditText)findViewById(R.id.etParameterValue);
|
||||
bSelectApp = (Button)findViewById(R.id.bSelectApp);
|
||||
bAddIntentPair = (Button)findViewById(R.id.bAddIntentPair);
|
||||
bSaveActionStartOtherActivity = (Button)findViewById(R.id.bSaveActionStartOtherActivity);
|
||||
spinnerParameterType = (Spinner)findViewById(R.id.spinnerParameterType);
|
||||
etPackageName = (EditText) findViewById(R.id.etPackageName);
|
||||
etActivityOrActionPath = (EditText) findViewById(R.id.etActivityOrActionPath);
|
||||
rbStartAppSelectByActivity = (RadioButton)findViewById(R.id.rbStartAppSelectByActivity);
|
||||
rbStartAppSelectByAction = (RadioButton)findViewById(R.id.rbStartAppSelectByAction);
|
||||
showStartProgramExamples = (Button)findViewById(R.id.showStartProgramExamples);
|
||||
|
||||
rbStartAppByActivity = (RadioButton)findViewById(R.id.rbStartAppByActivity);
|
||||
rbStartAppByBroadcast = (RadioButton)findViewById(R.id.rbStartAppByBroadcast);
|
||||
|
||||
intentTypeSpinnerAdapter = new ArrayAdapter<String>(this, R.layout.text_view_for_poi_listview_mediumtextsize, ActivityManageActionStartActivity.supportedIntentTypes);
|
||||
spinnerParameterType.setAdapter(intentTypeSpinnerAdapter);
|
||||
intentTypeSpinnerAdapter.notifyDataSetChanged();
|
||||
|
||||
intentPairAdapter = new ArrayAdapter<String>(this, R.layout.text_view_for_poi_listview_mediumtextsize, intentPairList);
|
||||
|
||||
bSelectApp.setOnClickListener(new OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
int targetSdkVersion = getApplicationContext().getApplicationInfo().targetSdkVersion;
|
||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && targetSdkVersion >= 30 && !ActivityPermissions.havePermission(Manifest.permission.QUERY_ALL_PACKAGES, ActivityManageActionStartActivity.this))// && shouldShowRequestPermissionRationale(Manifest.permission.QUERY_ALL_PACKAGES))
|
||||
{
|
||||
requestPermissions(new String[] {Manifest.permission.QUERY_ALL_PACKAGES}, requestCodeForRequestQueryAllPackagesPermission);
|
||||
}
|
||||
else
|
||||
getAppList();
|
||||
}
|
||||
});
|
||||
|
||||
bAddIntentPair.setOnClickListener(new OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
// type;name;value
|
||||
if(spinnerParameterType.getSelectedItem().toString().length() == 0)
|
||||
{
|
||||
Toast.makeText(ActivityManageActionStartActivity.this, getResources().getString(R.string.selectTypeOfIntentPair), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
if(etParameterName.getText().toString().length() == 0)
|
||||
{
|
||||
Toast.makeText(ActivityManageActionStartActivity.this, getResources().getString(R.string.enterNameForIntentPair), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
else if(etParameterName.getText().toString().contains(Action.intentPairSeparator))
|
||||
{
|
||||
Toast.makeText(ActivityManageActionStartActivity.this, String.format(getResources().getString(R.string.stringNotAllowed), Action.intentPairSeparator), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
else if(etParameterName.getText().toString().contains(";"))
|
||||
{
|
||||
Toast.makeText(ActivityManageActionStartActivity.this, String.format(getResources().getString(R.string.stringNotAllowed), ";"), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
if(etParameterValue.getText().toString().length() == 0)
|
||||
{
|
||||
Toast.makeText(ActivityManageActionStartActivity.this, getResources().getString(R.string.enterValueForIntentPair), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
else if(etParameterValue.getText().toString().contains(Action.intentPairSeparator))
|
||||
{
|
||||
Toast.makeText(ActivityManageActionStartActivity.this, String.format(getResources().getString(R.string.stringNotAllowed), Action.intentPairSeparator), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
else if(etParameterValue.getText().toString().contains(";"))
|
||||
{
|
||||
Toast.makeText(ActivityManageActionStartActivity.this, String.format(getResources().getString(R.string.stringNotAllowed), ";"), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
String param = supportedIntentTypes[spinnerParameterType.getSelectedItemPosition()] + Action.intentPairSeparator + etParameterName.getText().toString() + Action.intentPairSeparator + etParameterValue.getText().toString();
|
||||
intentPairList.add(param);
|
||||
|
||||
spinnerParameterType.setSelection(0);
|
||||
etParameterName.setText("");
|
||||
etParameterValue.setText("");
|
||||
|
||||
updateIntentPairList();
|
||||
|
||||
if(lvIntentPairs.getVisibility() != View.VISIBLE)
|
||||
lvIntentPairs.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
|
||||
showStartProgramExamples.setOnClickListener(new OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlShowExamples));
|
||||
startActivity(browserIntent);
|
||||
}
|
||||
});
|
||||
|
||||
lvIntentPairs.setOnItemLongClickListener(new OnItemLongClickListener()
|
||||
{
|
||||
@Override
|
||||
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)
|
||||
{
|
||||
getIntentPairDialog(arg2).show();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
bSaveActionStartOtherActivity.setOnClickListener(new OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
if(saveAction())
|
||||
{
|
||||
ActivityManageActionStartActivity.this.setResult(RESULT_OK);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
lvIntentPairs.setOnTouchListener(new OnTouchListener()
|
||||
{
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event)
|
||||
{
|
||||
v.getParent().requestDisallowInterceptTouchEvent(true);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
spinnerParameterType.setOnItemSelectedListener(new OnItemSelectedListener()
|
||||
{
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3)
|
||||
{
|
||||
if(supportedIntentTypes[arg2].equals("double") | supportedIntentTypes[arg2].equals("float") | supportedIntentTypes[arg2].equals("int") | supportedIntentTypes[arg2].equals("long") | supportedIntentTypes[arg2].equals("short"))
|
||||
ActivityManageActionStartActivity.this.etParameterValue.setInputType(InputType.TYPE_CLASS_NUMBER);
|
||||
else
|
||||
ActivityManageActionStartActivity.this.etParameterValue.setInputType(InputType.TYPE_CLASS_TEXT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> arg0)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
rbStartAppSelectByActivity.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
|
||||
{
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
|
||||
{
|
||||
if(isChecked)
|
||||
bSelectApp.setEnabled(isChecked);
|
||||
}
|
||||
});
|
||||
|
||||
rbStartAppSelectByAction.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
|
||||
{
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
|
||||
{
|
||||
if(isChecked)
|
||||
bSelectApp.setEnabled(!isChecked);
|
||||
}
|
||||
});
|
||||
|
||||
Intent i = getIntent();
|
||||
if(i.getBooleanExtra("edit", false) == true)
|
||||
{
|
||||
edit = true;
|
||||
loadValuesIntoGui();
|
||||
}
|
||||
}
|
||||
|
||||
private void loadValuesIntoGui()
|
||||
{
|
||||
boolean selectionByAction = resultingAction.getParameter1();
|
||||
rbStartAppSelectByActivity.setChecked(!selectionByAction);
|
||||
rbStartAppSelectByAction.setChecked(selectionByAction);
|
||||
|
||||
String[] params;
|
||||
String partsString = input.getStringExtra(ActivityManageRule.intentNameActionParameter2);
|
||||
String[] params = resultingAction.getParameter2().split(";");
|
||||
|
||||
if(partsString.contains(Action.actionParameter2Split))
|
||||
params = partsString.split(Action.actionParameter2Split);
|
||||
else
|
||||
params = partsString.split(";");
|
||||
|
||||
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));
|
||||
}
|
||||
rbStartAppByActivity.setChecked(params[2].equals(startByActivityString));
|
||||
rbStartAppByBroadcast.setChecked(params[2].equals(startByBroadcastString));
|
||||
|
||||
int startIndex = -1;
|
||||
|
||||
@ -660,11 +559,10 @@ public class ActivityManageActionStartActivity extends Activity
|
||||
etPackageName.setText(params[0]);
|
||||
|
||||
etActivityOrActionPath.setText(params[1]);
|
||||
etClassName.setText(params[2]);
|
||||
}
|
||||
|
||||
if (params.length >= 4)
|
||||
startIndex = 4;
|
||||
if (params.length >= 3)
|
||||
startIndex = 3;
|
||||
|
||||
if(startIndex > -1 && params.length > startIndex)
|
||||
{
|
||||
@ -689,8 +587,8 @@ public class ActivityManageActionStartActivity extends Activity
|
||||
|
||||
intentPairAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
boolean checkInput()
|
||||
|
||||
private boolean saveAction()
|
||||
{
|
||||
if(rbStartAppSelectByActivity.isChecked())
|
||||
{
|
||||
@ -713,7 +611,36 @@ public class ActivityManageActionStartActivity extends Activity
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if(resultingAction == null)
|
||||
resultingAction = new Action();
|
||||
|
||||
resultingAction.setParameter1(rbStartAppSelectByAction.isChecked());
|
||||
|
||||
resultingAction.setAction(Action_Enum.startOtherActivity);
|
||||
|
||||
String parameter2 = "";
|
||||
|
||||
if(rbStartAppSelectByActivity.isChecked())
|
||||
parameter2 += etPackageName.getText().toString() + ";" + etActivityOrActionPath.getText().toString();
|
||||
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(rbStartAppByActivity.isChecked())
|
||||
parameter2 += ";" + startByActivityString;
|
||||
else
|
||||
parameter2 += ";" + startByBroadcastString;
|
||||
|
||||
for(String s : intentPairList)
|
||||
parameter2 += ";" + s;
|
||||
|
||||
resultingAction.setParameter2(parameter2);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,6 @@
|
||||
package com.jens.automation2;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
@ -17,43 +13,32 @@ import android.widget.CompoundButton;
|
||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ListView;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.TableLayout;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.jens.automation2.Action.Action_Enum;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
public class ActivityManageActionTriggerUrl extends Activity
|
||||
{
|
||||
Button bSaveTriggerUrl, bAddHttpParam;
|
||||
EditText etTriggerUrl, etTriggerUrlUsername, etTriggerUrlPassword, etParameterName, etParameterValue;
|
||||
Button bSaveTriggerUrl;
|
||||
EditText etTriggerUrl, etTriggerUrlUsername, etTriggerUrlPassword;
|
||||
ListView lvTriggerUrlPostParameters;
|
||||
CheckBox chkTriggerUrlUseAuthentication;
|
||||
RadioButton rbTriggerUrlMethodGet, rbTriggerUrlMethodPost;
|
||||
TableLayout tlTriggerUrlAuthentication;
|
||||
ArrayAdapter<String> httpParametersAdapter;
|
||||
|
||||
private ArrayList<String> httpParamsList = new ArrayList<>();
|
||||
ArrayAdapter<Map<String,String>> lvTriggerUrlPostParametersAdapter;
|
||||
|
||||
public static final String methodGet = "GET";
|
||||
public static final String methodPost = "POST";
|
||||
|
||||
// public static boolean edit = false;
|
||||
// public static Action resultingAction = null;
|
||||
ArrayAdapter<Map<String,String>> lvTriggerUrlPostParametersAdapter;
|
||||
|
||||
// private String existingUrl = "";
|
||||
|
||||
public static boolean edit = false;
|
||||
public static Action resultingAction = null;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
this.setContentView(R.layout.activity_manage_action_trigger_url);
|
||||
|
||||
etTriggerUrl = (EditText)findViewById(R.id.etTriggerUrl);
|
||||
@ -62,33 +47,7 @@ public class ActivityManageActionTriggerUrl extends Activity
|
||||
chkTriggerUrlUseAuthentication = (CheckBox)findViewById(R.id.chkTriggerUrlUseAuthentication);
|
||||
lvTriggerUrlPostParameters = (ListView)findViewById(R.id.lvTriggerUrlPostParameters);
|
||||
tlTriggerUrlAuthentication = (TableLayout)findViewById(R.id.tlTriggerUrlAuthentication);
|
||||
bSaveTriggerUrl = (Button)findViewById(R.id.bSaveSpeakText);
|
||||
rbTriggerUrlMethodGet = (RadioButton) findViewById(R.id.rbTriggerUrlMethodGet);
|
||||
rbTriggerUrlMethodPost = (RadioButton) findViewById(R.id.rbTriggerUrlMethodPost);
|
||||
etTriggerUrl = (EditText) findViewById(R.id.etTriggerUrl);
|
||||
etParameterName = (EditText) findViewById(R.id.etParameterName);
|
||||
etParameterValue = (EditText)findViewById(R.id.etParameterValue);
|
||||
bAddHttpParam = (Button)findViewById(R.id.bAddHttpParam);
|
||||
|
||||
etParameterName.setEnabled(false);
|
||||
etParameterValue.setEnabled(false);
|
||||
bAddHttpParam.setEnabled(false);
|
||||
|
||||
rbTriggerUrlMethodPost.setOnCheckedChangeListener(new OnCheckedChangeListener()
|
||||
{
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked)
|
||||
{
|
||||
etParameterName.setEnabled(checked);
|
||||
etParameterValue.setEnabled(checked);
|
||||
bAddHttpParam.setEnabled(checked);
|
||||
if(checked)
|
||||
lvTriggerUrlPostParameters.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
|
||||
httpParametersAdapter = new ArrayAdapter<String>(this, R.layout.text_view_for_poi_listview_mediumtextsize, httpParamsList);
|
||||
|
||||
bSaveTriggerUrl = (Button)findViewById(R.id.bSaveTriggerUrl);
|
||||
bSaveTriggerUrl.setOnClickListener(new OnClickListener()
|
||||
{
|
||||
@Override
|
||||
@ -96,64 +55,44 @@ public class ActivityManageActionTriggerUrl extends Activity
|
||||
{
|
||||
if(etTriggerUrl.getText().toString().length() > 0)
|
||||
{
|
||||
Intent returnIntent = new Intent();
|
||||
|
||||
returnIntent.putExtra(ActivityManageRule.intentNameActionParameter1, chkTriggerUrlUseAuthentication.isChecked());
|
||||
|
||||
String username = etTriggerUrlUsername.getText().toString();
|
||||
String password = etTriggerUrlPassword.getText().toString();
|
||||
|
||||
if(username == null)
|
||||
username = "";
|
||||
|
||||
if(password == null)
|
||||
password = "";
|
||||
|
||||
String method = methodGet;
|
||||
if(rbTriggerUrlMethodPost.isChecked())
|
||||
method = methodPost;
|
||||
|
||||
String httpParams = "";
|
||||
for (String s : httpParamsList)
|
||||
httpParams += Action.actionParameters2SeparatorOuter + s;
|
||||
if(httpParams.length() > 0)
|
||||
httpParams = httpParams.substring(Action.actionParameters2SeparatorOuter.length());
|
||||
|
||||
returnIntent.putExtra(ActivityManageRule.intentNameActionParameter2,
|
||||
username + Action.actionParameter2Split +
|
||||
password + Action.actionParameter2Split +
|
||||
etTriggerUrl.getText().toString().trim() + Action.actionParameter2Split +
|
||||
method + Action.actionParameter2Split +
|
||||
httpParams
|
||||
);
|
||||
|
||||
setResult(RESULT_OK, returnIntent);
|
||||
finish();
|
||||
if(resultingAction == null)
|
||||
{
|
||||
resultingAction = new Action();
|
||||
resultingAction.setAction(Action_Enum.triggerUrl);
|
||||
resultingAction.setParameter1(chkTriggerUrlUseAuthentication.isChecked());
|
||||
|
||||
String username = etTriggerUrlUsername.getText().toString();
|
||||
String password = etTriggerUrlPassword.getText().toString();
|
||||
|
||||
if(username == null)
|
||||
username = "";
|
||||
|
||||
if(password == null)
|
||||
password = "";
|
||||
|
||||
ActivityManageActionTriggerUrl.resultingAction.setParameter2(
|
||||
username + ";" +
|
||||
password + ";" +
|
||||
etTriggerUrl.getText().toString().trim()
|
||||
);
|
||||
}
|
||||
backToRuleManager();
|
||||
}
|
||||
else
|
||||
Toast.makeText(getBaseContext(), getResources().getString(R.string.urlTooShort), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
chkTriggerUrlUseAuthentication.setOnCheckedChangeListener(new OnCheckedChangeListener()
|
||||
{
|
||||
{
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
|
||||
{
|
||||
if(isChecked)
|
||||
{
|
||||
tlTriggerUrlAuthentication.setVisibility(View.VISIBLE);
|
||||
rbTriggerUrlMethodGet.setChecked(false);
|
||||
rbTriggerUrlMethodPost.setChecked(true);
|
||||
rbTriggerUrlMethodGet.setEnabled(false);
|
||||
rbTriggerUrlMethodPost.setEnabled(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
tlTriggerUrlAuthentication.setVisibility(View.GONE);
|
||||
rbTriggerUrlMethodGet.setEnabled(true);
|
||||
rbTriggerUrlMethodPost.setEnabled(true);
|
||||
}
|
||||
|
||||
etTriggerUrlUsername.setEnabled(isChecked);
|
||||
etTriggerUrlPassword.setEnabled(isChecked);
|
||||
@ -170,86 +109,52 @@ public class ActivityManageActionTriggerUrl extends Activity
|
||||
});
|
||||
updateListView();
|
||||
|
||||
if(getIntent().hasExtra(ActivityManageRule.intentNameActionParameter2))
|
||||
|
||||
ActivityManageActionTriggerUrl.edit = getIntent().getBooleanExtra("edit", false);
|
||||
if(edit)
|
||||
{
|
||||
// username,password,URL,etc.
|
||||
String[] components;
|
||||
|
||||
if(getIntent().getStringExtra(ActivityManageRule.intentNameActionParameter2).contains(Action.actionParameter2Split))
|
||||
components = getIntent().getStringExtra(ActivityManageRule.intentNameActionParameter2).split(Action.actionParameter2Split, -1);
|
||||
else
|
||||
components = getIntent().getStringExtra(ActivityManageRule.intentNameActionParameter2).split(";", -1);
|
||||
// username,password,URL
|
||||
String[] components = ActivityManageActionTriggerUrl.resultingAction.getParameter2().split(";");
|
||||
|
||||
if(components.length >= 3)
|
||||
{
|
||||
etTriggerUrl.setText(components[2]);
|
||||
chkTriggerUrlUseAuthentication.setChecked(getIntent().getBooleanExtra(ActivityManageRule.intentNameActionParameter1, false));
|
||||
etTriggerUrl.setText(components[2]);
|
||||
chkTriggerUrlUseAuthentication.setChecked(ActivityManageActionTriggerUrl.resultingAction.getParameter1());
|
||||
etTriggerUrlUsername.setText(components[0]);
|
||||
etTriggerUrlPassword.setText(components[1]);
|
||||
|
||||
if(components.length >= 4)
|
||||
{
|
||||
switch(components[3])
|
||||
{
|
||||
case methodPost:
|
||||
rbTriggerUrlMethodPost.setChecked(true);
|
||||
break;
|
||||
case methodGet:
|
||||
default:
|
||||
rbTriggerUrlMethodGet.setChecked(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(components.length >= 5)
|
||||
{
|
||||
if(!StringUtils.isEmpty(components[4]) && components[4].contains(Action.actionParameters2SeparatorInner))
|
||||
{
|
||||
String httpParams[] = components[4].split(Action.actionParameters2SeparatorOuter);
|
||||
for (String paramPair : httpParams)
|
||||
httpParamsList.add(paramPair);
|
||||
|
||||
updateHttpParamsList();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
etTriggerUrl.setText(components[0]);
|
||||
}
|
||||
|
||||
bAddHttpParam.setOnClickListener(new OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View view)
|
||||
{
|
||||
if(StringUtils.isEmpty(etParameterName.getText()) || StringUtils.isEmpty(etParameterValue.getText()))
|
||||
{
|
||||
Toast.makeText(ActivityManageActionTriggerUrl.this, getResources().getString(R.string.enterValidDataIntoParametersFields), Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
httpParamsList.add(etParameterName.getText() + Action.actionParameters2SeparatorInner + etParameterValue.getText());
|
||||
|
||||
updateHttpParamsList();
|
||||
etParameterName.setText("");
|
||||
etParameterValue.setText("");
|
||||
|
||||
if(lvTriggerUrlPostParameters.getVisibility() != View.VISIBLE)
|
||||
lvTriggerUrlPostParameters.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
|
||||
lvTriggerUrlPostParameters.setOnItemLongClickListener(new OnItemLongClickListener()
|
||||
{
|
||||
@Override
|
||||
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)
|
||||
{
|
||||
getHttpParamsDialog(arg2).show();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void backToRuleManager()
|
||||
{
|
||||
if(edit && resultingAction != null)
|
||||
{
|
||||
String username = etTriggerUrlUsername.getText().toString();
|
||||
String password = etTriggerUrlPassword.getText().toString();
|
||||
|
||||
if(username == null)
|
||||
username = "";
|
||||
|
||||
if(password == null)
|
||||
password = "";
|
||||
|
||||
ActivityManageActionTriggerUrl.resultingAction.setParameter1(chkTriggerUrlUseAuthentication.isChecked());
|
||||
|
||||
ActivityManageActionTriggerUrl.resultingAction.setParameter2(
|
||||
username + ";" +
|
||||
password + ";" +
|
||||
etTriggerUrl.getText().toString()
|
||||
);
|
||||
}
|
||||
|
||||
setResult(RESULT_OK);
|
||||
|
||||
this.finish();
|
||||
}
|
||||
|
||||
private void updateListView()
|
||||
{
|
||||
Miscellaneous.logEvent("i", "ListView", "Attempting to update lvTriggerUrlPostParameters", 4);
|
||||
@ -257,36 +162,10 @@ public class ActivityManageActionTriggerUrl extends Activity
|
||||
{
|
||||
if(lvTriggerUrlPostParameters.getAdapter() == null)
|
||||
lvTriggerUrlPostParameters.setAdapter(lvTriggerUrlPostParametersAdapter);
|
||||
|
||||
|
||||
lvTriggerUrlPostParametersAdapter.notifyDataSetChanged();
|
||||
}
|
||||
catch(NullPointerException e)
|
||||
{}
|
||||
}
|
||||
|
||||
private void updateHttpParamsList()
|
||||
{
|
||||
if(lvTriggerUrlPostParameters.getAdapter() == null)
|
||||
lvTriggerUrlPostParameters.setAdapter(httpParametersAdapter);
|
||||
|
||||
httpParametersAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private AlertDialog getHttpParamsDialog(final int itemPosition)
|
||||
{
|
||||
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ActivityManageActionTriggerUrl.this);
|
||||
alertDialogBuilder.setTitle(getResources().getString(R.string.whatToDoWithIntentPair));
|
||||
alertDialogBuilder.setItems(new String[]{getResources().getString(R.string.delete)}, new DialogInterface.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
// Only 1 choice at the moment, no need to check
|
||||
ActivityManageActionTriggerUrl.this.httpParamsList.remove(itemPosition);
|
||||
updateHttpParamsList();
|
||||
}
|
||||
});
|
||||
AlertDialog alertDialog = alertDialogBuilder.create();
|
||||
return alertDialog;
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,6 @@ public class ActivityManageActionVibrate extends Activity
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
setContentView(R.layout.activity_manage_action_vibrate);
|
||||
|
||||
etVibratePattern = (EditText)findViewById(R.id.etVibratePattern);
|
||||
|
@ -1,100 +0,0 @@
|
||||
package com.jens.automation2;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.provider.MediaStore;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class ActivityManageActionWakeLock extends Activity
|
||||
{
|
||||
RadioButton rbWakeLockActivate, rbWakeLockDeactivate;
|
||||
CheckBox chkWakeLockTimeout;
|
||||
EditText etWakeLockDuration;
|
||||
Button bSaveWakelock;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
setContentView(R.layout.activity_manage_action_wakelock);
|
||||
|
||||
rbWakeLockActivate = (RadioButton)findViewById(R.id.rbWakeLockActivate);
|
||||
rbWakeLockDeactivate = (RadioButton)findViewById(R.id.rbWakeLockDeactivate);
|
||||
chkWakeLockTimeout = (CheckBox)findViewById(R.id.chkWakeLockTimeout);
|
||||
etWakeLockDuration = (EditText)findViewById(R.id.etWakeLockDuration);
|
||||
bSaveWakelock = (Button)findViewById(R.id.bSaveWakelock);
|
||||
|
||||
etWakeLockDuration.setEnabled(chkWakeLockTimeout.isChecked());
|
||||
|
||||
chkWakeLockTimeout.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
|
||||
{
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean wakeLockTimeoutSet)
|
||||
{
|
||||
etWakeLockDuration.setEnabled(wakeLockTimeoutSet);
|
||||
|
||||
if(wakeLockTimeoutSet)
|
||||
etWakeLockDuration.setText(String.valueOf(Actions.wakeLockTimeoutDisabled));
|
||||
}
|
||||
});
|
||||
|
||||
if(getIntent().hasExtra(ActivityManageRule.intentNameActionParameter1))
|
||||
{
|
||||
rbWakeLockActivate.setChecked(getIntent().getBooleanExtra(ActivityManageRule.intentNameActionParameter1, true));
|
||||
rbWakeLockDeactivate.setChecked(!getIntent().getBooleanExtra(ActivityManageRule.intentNameActionParameter1, false));
|
||||
|
||||
if(getIntent().hasExtra(ActivityManageRule.intentNameActionParameter2))
|
||||
{
|
||||
if(Miscellaneous.isNumeric(getIntent().getStringExtra(ActivityManageRule.intentNameActionParameter2)))
|
||||
{
|
||||
long timeout = Long.parseLong((getIntent().getStringExtra(ActivityManageRule.intentNameActionParameter2)));
|
||||
chkWakeLockTimeout.setChecked(timeout != Actions.wakeLockTimeoutDisabled);
|
||||
etWakeLockDuration.setText(String.valueOf(timeout));
|
||||
}
|
||||
else
|
||||
{
|
||||
chkWakeLockTimeout.setChecked(false);
|
||||
etWakeLockDuration.setText(String.valueOf(Actions.wakeLockTimeoutDisabled));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bSaveWakelock.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View view)
|
||||
{
|
||||
if(chkWakeLockTimeout.isChecked())
|
||||
{
|
||||
if((StringUtils.isEmpty(etWakeLockDuration.getText().toString()) || Integer.parseInt(etWakeLockDuration.getText().toString()) <= 0))
|
||||
{
|
||||
Toast.makeText(ActivityManageActionWakeLock.this, getResources().getString(R.string.enterAPositiveValidNonDecimalNumber), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Intent response = new Intent();
|
||||
response.putExtra(ActivityManageRule.intentNameActionParameter1, rbWakeLockActivate.isChecked());
|
||||
if(chkWakeLockTimeout.isChecked())
|
||||
response.putExtra(ActivityManageRule.intentNameActionParameter2, etWakeLockDuration.getText().toString());
|
||||
else
|
||||
response.putExtra(ActivityManageRule.intentNameActionParameter2, String.valueOf(Actions.wakeLockTimeoutDisabled));
|
||||
setResult(RESULT_OK, response);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
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 ActivityManageActionWifi 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_wifi);
|
||||
|
||||
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();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -59,7 +59,6 @@ public class ActivityManagePoi extends Activity
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
this.setContentView(R.layout.activity_manage_specific_poi);
|
||||
|
||||
myLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
|
||||
@ -411,16 +410,22 @@ public class ActivityManagePoi extends Activity
|
||||
@Override
|
||||
public void onProviderDisabled(String provider)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProviderEnabled(String provider)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStatusChanged(String provider, int status, Bundle extras)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -448,16 +453,22 @@ public class ActivityManagePoi extends Activity
|
||||
@Override
|
||||
public void onProviderDisabled(String provider)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProviderEnabled(String provider)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStatusChanged(String provider, int status, Bundle extras)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,37 +47,37 @@ public class ActivityManageProfile extends Activity
|
||||
|
||||
boolean guiUpdate = false;
|
||||
|
||||
String incomingCallsRingtone = null, notificationsRingtone = null;
|
||||
File incomingCallsRingtone = null, notificationsRingtone = null;
|
||||
|
||||
ArrayAdapter<String> soundModeAdapter;
|
||||
ArrayAdapter<String> dndModeAdapter;
|
||||
|
||||
public void setIncomingCallsRingtone(String incomingCallsRingtone)
|
||||
public void setIncomingCallsRingtone(File incomingCallsRingtone)
|
||||
{
|
||||
this.incomingCallsRingtone = incomingCallsRingtone;
|
||||
|
||||
if(incomingCallsRingtone != null)
|
||||
tvIncomingCallsRingtone.setText(this.incomingCallsRingtone);
|
||||
tvIncomingCallsRingtone.setText(this.incomingCallsRingtone.getAbsolutePath());
|
||||
else
|
||||
tvIncomingCallsRingtone.setText(getResources().getString(R.string.none));
|
||||
}
|
||||
|
||||
public String getIncomingCallsRingtone()
|
||||
public File getIncomingCallsRingtone()
|
||||
{
|
||||
return incomingCallsRingtone;
|
||||
}
|
||||
|
||||
public void setNotificationsRingtone(String notificationsRingtone)
|
||||
public void setNotificationsRingtone(File notificationsRingtone)
|
||||
{
|
||||
this.notificationsRingtone = notificationsRingtone;
|
||||
|
||||
if(this.notificationsRingtone != null)
|
||||
tvNotificationsRingtone.setText(this.notificationsRingtone);
|
||||
tvNotificationsRingtone.setText(this.notificationsRingtone.getAbsolutePath());
|
||||
else
|
||||
tvNotificationsRingtone.setText(getResources().getString(R.string.none));
|
||||
}
|
||||
|
||||
public String getNotificationsRingtone()
|
||||
public File getNotificationsRingtone()
|
||||
{
|
||||
return notificationsRingtone;
|
||||
}
|
||||
@ -86,7 +86,6 @@ public class ActivityManageProfile extends Activity
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
this.setContentView(R.layout.activity_manage_specific_profile);
|
||||
|
||||
checkBoxChangeSoundMode = (CheckBox)findViewById(R.id.checkBoxChangeSoundMode);
|
||||
@ -285,26 +284,26 @@ public class ActivityManageProfile extends Activity
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
// try
|
||||
// {
|
||||
// Intent fileIntent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
// fileIntent.setType("audio/*");
|
||||
// startActivityForResult(Intent.createChooser(fileIntent, "Select a ringtone"), intentCodeRingtonePickerCallsFile);
|
||||
// }
|
||||
// catch(ActivityNotFoundException e)
|
||||
// {
|
||||
try
|
||||
{
|
||||
Intent fileIntent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
fileIntent.setType("audio/*");
|
||||
startActivityForResult(Intent.createChooser(fileIntent, "Select a ringtone"), intentCodeRingtonePickerCallsFile);
|
||||
}
|
||||
catch(ActivityNotFoundException e)
|
||||
{
|
||||
// Use media browser instead
|
||||
Intent fileSelectionIntent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
|
||||
|
||||
if(ActivityMainProfiles.profileToEdit != null)
|
||||
{
|
||||
Uri currenturi = Uri.parse(ActivityMainProfiles.profileToEdit.incomingCallsRingtone);
|
||||
Uri currenturi = Uri.parse(ActivityMainProfiles.profileToEdit.incomingCallsRingtone.getAbsolutePath());
|
||||
if(ActivityMainProfiles.profileToEdit.changeIncomingCallsRingtone)
|
||||
fileSelectionIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, currenturi);
|
||||
}
|
||||
|
||||
startActivityForResult(fileSelectionIntent, intentCodeRingtonePickerCallsRingtone);
|
||||
// }
|
||||
}
|
||||
}
|
||||
});
|
||||
bChangeSoundNotifications.setOnClickListener(new OnClickListener()
|
||||
@ -325,7 +324,7 @@ public class ActivityManageProfile extends Activity
|
||||
|
||||
if(ActivityMainProfiles.profileToEdit != null)
|
||||
{
|
||||
Uri currenturi = Uri.parse(ActivityMainProfiles.profileToEdit.notificationRingtone);
|
||||
Uri currenturi = Uri.parse(ActivityMainProfiles.profileToEdit.notificationRingtone.getAbsolutePath());
|
||||
if(ActivityMainProfiles.profileToEdit.changeNotificationRingtone)
|
||||
fileSelectionIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, currenturi);
|
||||
}
|
||||
@ -496,20 +495,15 @@ public class ActivityManageProfile extends Activity
|
||||
Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
|
||||
if (uri != null)
|
||||
{
|
||||
// if(Build.VERSION.SDK_INT < 26)
|
||||
// {
|
||||
// String ringTonePath = CompensateCrappyAndroidPaths.getPath(ActivityManageProfile.this, uri);
|
||||
// setIncomingCallsRingtone(ringTonePath);
|
||||
// }
|
||||
// else
|
||||
setIncomingCallsRingtone(uri.toString());
|
||||
String ringTonePath = CompensateCrappyAndroidPaths.getPath(ActivityManageProfile.this, uri);
|
||||
setIncomingCallsRingtone(new File(ringTonePath));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case intentCodeRingtonePickerCallsFile:
|
||||
{
|
||||
String ringTonePath = CompensateCrappyAndroidPaths.getPath(ActivityManageProfile.this, data.getData());
|
||||
setIncomingCallsRingtone(ringTonePath);
|
||||
setIncomingCallsRingtone(new File(ringTonePath));
|
||||
break;
|
||||
}
|
||||
case intentCodeRingtonePickerNotificationsRingtone: // notifications
|
||||
@ -517,20 +511,15 @@ public class ActivityManageProfile extends Activity
|
||||
Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
|
||||
if (uri != null)
|
||||
{
|
||||
// if(Build.VERSION.SDK_INT < 26)
|
||||
// {
|
||||
// String ringTonePath = CompensateCrappyAndroidPaths.getPath(ActivityManageProfile.this, uri);
|
||||
// setNotificationsRingtone(ringTonePath);
|
||||
// }
|
||||
// else
|
||||
setNotificationsRingtone(uri.toString());
|
||||
String ringTonePath = CompensateCrappyAndroidPaths.getPath(ActivityManageProfile.this, data.getData());
|
||||
setNotificationsRingtone(new File(ringTonePath));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case intentCodeRingtonePickerNotificationsFile:
|
||||
{
|
||||
String ringTonePath = CompensateCrappyAndroidPaths.getPath(ActivityManageProfile.this, data.getData());
|
||||
setNotificationsRingtone(ringTonePath);
|
||||
setNotificationsRingtone(new File(ringTonePath));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -119,35 +119,7 @@ public class ActivityManageRule extends Activity
|
||||
final static int requestCodeActionCloseNotificationEdit = 806;
|
||||
final static int requestCodeActionControlMediaAdd = 807;
|
||||
final static int requestCodeActionControlMediaEdit = 808;
|
||||
final static int requestCodeTriggerBroadcastReceivedAdd = 809;
|
||||
final static int requestCodeTriggerBroadcastReceivedEdit = 810;
|
||||
final static int requestCodeActionSendBroadcastAdd = 811;
|
||||
final static int requestCodeActionSendBroadcastEdit = 812;
|
||||
final static int requestCodeActionRunExecutableAdd = 813;
|
||||
final static int requestCodeActionRunExecutableEdit = 814;
|
||||
final static int requestCodeActionSetWifiAdd = 815;
|
||||
final static int requestCodeActionSetWifiEdit = 816;
|
||||
final static int requestCodeTriggerTetheringAdd = 817;
|
||||
final static int requestCodeTriggerTetheringEdit = 818;
|
||||
final static int requestCodeActionWakeLockAdd = 819;
|
||||
final static int requestCodeActionWakeLockEdit = 820;
|
||||
final static int requestCodeTriggerSubSystemStateAdd = 821;
|
||||
final static int requestCodeTriggerSubSystemStateEdit = 822;
|
||||
final static int requestCodeActionMakePhoneCallAdd = 823;
|
||||
final static int requestCodeActionMakePhoneCallEdit = 824;
|
||||
final static int requestCodeActionSetVariableAdd = 825;
|
||||
final static int requestCodeActionSetVariableEdit = 826;
|
||||
final static int requestCodeTriggerCheckVariableAdd = 827;
|
||||
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;
|
||||
final static int requestCodeTriggerCalendarEventAdd = 833;
|
||||
final static int requestCodeTriggerCalendarEventEdit = 834;
|
||||
final static int requestCodeTriggerChargingAdd = 835;
|
||||
final static int requestCodeTriggerChargingEdit = 836;
|
||||
|
||||
|
||||
public static ActivityManageRule getInstance()
|
||||
{
|
||||
if(instance == null)
|
||||
@ -160,7 +132,6 @@ public class ActivityManageRule extends Activity
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
setContentView(R.layout.activity_manage_specific_rule);
|
||||
|
||||
context = this;
|
||||
@ -327,42 +298,6 @@ public class ActivityManageRule extends Activity
|
||||
devicePositionEditor.putExtra(ActivityManageTriggerDeviceOrientation.vectorFieldName, selectedTrigger.getTriggerParameter2());
|
||||
startActivityForResult(devicePositionEditor, requestCodeTriggerDeviceOrientationEdit);
|
||||
break;
|
||||
case broadcastReceived:
|
||||
Intent broadcastEditor = new Intent(ActivityManageRule.this, ActivityManageTriggerBroadcast.class);
|
||||
broadcastEditor.putExtra(intentNameTriggerParameter1, selectedTrigger.getTriggerParameter());
|
||||
broadcastEditor.putExtra(intentNameTriggerParameter2, selectedTrigger.getTriggerParameter2());
|
||||
startActivityForResult(broadcastEditor, requestCodeTriggerBroadcastReceivedEdit);
|
||||
break;
|
||||
case tethering:
|
||||
Intent tetheringEditor = new Intent(ActivityManageRule.this, ActivityManageTriggerTethering.class);
|
||||
tetheringEditor.putExtra(intentNameTriggerParameter1, selectedTrigger.getTriggerParameter());
|
||||
tetheringEditor.putExtra(intentNameTriggerParameter2, selectedTrigger.getTriggerParameter2());
|
||||
startActivityForResult(tetheringEditor, requestCodeTriggerTetheringEdit);
|
||||
break;
|
||||
case subSystemState:
|
||||
Intent subSystemStateEditor = new Intent(ActivityManageRule.this, ActivityManageTriggerSubSystemState.class);
|
||||
subSystemStateEditor.putExtra(intentNameTriggerParameter1, selectedTrigger.getTriggerParameter());
|
||||
subSystemStateEditor.putExtra(intentNameTriggerParameter2, selectedTrigger.getTriggerParameter2());
|
||||
startActivityForResult(subSystemStateEditor, requestCodeTriggerSubSystemStateEdit);
|
||||
break;
|
||||
case checkVariable:
|
||||
Intent variableStateEditor = new Intent(ActivityManageRule.this, ActivityManageTriggerCheckVariable.class);
|
||||
variableStateEditor.putExtra(intentNameTriggerParameter1, selectedTrigger.getTriggerParameter());
|
||||
variableStateEditor.putExtra(intentNameTriggerParameter2, selectedTrigger.getTriggerParameter2());
|
||||
startActivityForResult(variableStateEditor, requestCodeTriggerCheckVariableEdit);
|
||||
break;
|
||||
case calendarEvent:
|
||||
Intent calendarStateEditor = new Intent(ActivityManageRule.this, ActivityManageTriggerCalendar.class);
|
||||
calendarStateEditor.putExtra(intentNameTriggerParameter1, selectedTrigger.getTriggerParameter());
|
||||
calendarStateEditor.putExtra(intentNameTriggerParameter2, selectedTrigger.getTriggerParameter2());
|
||||
startActivityForResult(calendarStateEditor, requestCodeTriggerCalendarEventEdit);
|
||||
break;
|
||||
case charging:
|
||||
Intent chargingStateEditor = new Intent(ActivityManageRule.this, ActivityManageTriggerCharging.class);
|
||||
chargingStateEditor.putExtra(intentNameTriggerParameter1, selectedTrigger.getTriggerParameter());
|
||||
chargingStateEditor.putExtra(intentNameTriggerParameter2, selectedTrigger.getTriggerParameter2());
|
||||
startActivityForResult(chargingStateEditor, requestCodeTriggerChargingEdit);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -398,14 +333,15 @@ public class ActivityManageRule extends Activity
|
||||
{
|
||||
case startOtherActivity:
|
||||
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionStartActivity.class);
|
||||
intent.putExtra(intentNameActionParameter1, a.getParameter1());
|
||||
intent.putExtra(intentNameActionParameter2, a.getParameter2());
|
||||
ActivityManageActionStartActivity.resultingAction = a;
|
||||
intent.putExtra("edit", true);
|
||||
startActivityForResult(intent, requestCodeActionStartActivityEdit);
|
||||
break;
|
||||
case triggerUrl:
|
||||
Intent activityEditTriggerUrlIntent = new Intent(ActivityManageRule.this, ActivityManageActionTriggerUrl.class);
|
||||
activityEditTriggerUrlIntent.putExtra(intentNameActionParameter1, a.getParameter1());
|
||||
activityEditTriggerUrlIntent.putExtra(intentNameActionParameter2, a.getParameter2());
|
||||
ActivityManageActionTriggerUrl.resultingAction = a;
|
||||
ActivityManageActionTriggerUrl.resultingAction.setParentRule(ruleToEdit);
|
||||
activityEditTriggerUrlIntent.putExtra("edit", true);
|
||||
startActivityForResult(activityEditTriggerUrlIntent, requestCodeActionTriggerUrlEdit);
|
||||
break;
|
||||
case speakText:
|
||||
@ -431,40 +367,6 @@ public class ActivityManageRule extends Activity
|
||||
activityEditVibrateIntent.putExtra("vibratePattern", a.getParameter2());
|
||||
startActivityForResult(activityEditVibrateIntent, requestCodeActionVibrateEdit);
|
||||
break;
|
||||
case sendBroadcast:
|
||||
Intent activityEditSendBroadcastIntent = new Intent(ActivityManageRule.this, ActivityManageActionSendBroadcast.class);
|
||||
activityEditSendBroadcastIntent.putExtra(intentNameActionParameter2, a.getParameter2());
|
||||
startActivityForResult(activityEditSendBroadcastIntent, requestCodeActionSendBroadcastEdit);
|
||||
break;
|
||||
case wakelock:
|
||||
Intent activityEditWakeLockIntent = new Intent(ActivityManageRule.this, ActivityManageActionWakeLock.class);
|
||||
activityEditWakeLockIntent.putExtra(intentNameActionParameter1, a.getParameter1());
|
||||
activityEditWakeLockIntent.putExtra(intentNameActionParameter2, a.getParameter2());
|
||||
startActivityForResult(activityEditWakeLockIntent, requestCodeActionWakeLockEdit);
|
||||
break;
|
||||
case runExecutable:
|
||||
Intent activityEditRunExecutableIntent = new Intent(ActivityManageRule.this, ActivityManageActionRunExecutable.class);
|
||||
activityEditRunExecutableIntent.putExtra(intentNameActionParameter1, a.getParameter1());
|
||||
activityEditRunExecutableIntent.putExtra(intentNameActionParameter2, a.getParameter2());
|
||||
startActivityForResult(activityEditRunExecutableIntent, requestCodeActionRunExecutableEdit);
|
||||
break;
|
||||
case startPhoneCall:
|
||||
Intent activityEditMakePhoneCallIntent = new Intent(ActivityManageRule.this, ActivityManageActionMakePhoneCall.class);
|
||||
activityEditMakePhoneCallIntent.putExtra(intentNameActionParameter1, a.getParameter1());
|
||||
activityEditMakePhoneCallIntent.putExtra(intentNameActionParameter2, a.getParameter2());
|
||||
startActivityForResult(activityEditMakePhoneCallIntent, requestCodeActionMakePhoneCallEdit);
|
||||
break;
|
||||
case setVariable:
|
||||
Intent activityEditSetVariableIntent = new Intent(ActivityManageRule.this, ActivityManageActionSetVariable.class);
|
||||
activityEditSetVariableIntent.putExtra(intentNameActionParameter2, a.getParameter2());
|
||||
startActivityForResult(activityEditSetVariableIntent, requestCodeActionSetVariableEdit);
|
||||
break;
|
||||
case setWifi:
|
||||
Intent activityEditSetWifiIntent = new Intent(ActivityManageRule.this, ActivityManageActionWifi.class);
|
||||
activityEditSetWifiIntent.putExtra(intentNameActionParameter1, a.getParameter1());
|
||||
activityEditSetWifiIntent.putExtra(intentNameActionParameter2, a.getParameter2());
|
||||
startActivityForResult(activityEditSetWifiIntent, requestCodeActionSetWifiEdit);
|
||||
break;
|
||||
case controlMediaPlayback:
|
||||
Intent activityEditControlMediaIntent = new Intent(ActivityManageRule.this, ActivityManageActionControlMedia.class);
|
||||
activityEditControlMediaIntent.putExtra(ActivityManageRule.intentNameActionParameter2, a.getParameter2());
|
||||
@ -489,18 +391,6 @@ public class ActivityManageRule extends Activity
|
||||
actionPlaySoundIntent.putExtra(intentNameActionParameter2, a.getParameter2());
|
||||
startActivityForResult(actionPlaySoundIntent, requestCodeActionPlaySoundEdit);
|
||||
break;
|
||||
case copyToClipboard:
|
||||
Intent actionCopyToClipboardIntent = new Intent(context, ActivityManageActionCopyToClipboard.class);
|
||||
actionCopyToClipboardIntent.putExtra(intentNameActionParameter1, a.getParameter1());
|
||||
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;
|
||||
@ -618,11 +508,9 @@ public class ActivityManageRule extends Activity
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.plane));
|
||||
else if(types[i].toString().equals(Trigger_Enum.roaming.toString()))
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.roaming));
|
||||
else if(types[i].toString().equals(Trigger_Enum.broadcastReceived.toString()))
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.megaphone));
|
||||
else if(types[i].toString().equals(Trigger_Enum.phoneCall.toString()))
|
||||
{
|
||||
if(ActivityPermissions.isPermissionDeclaratedInManifest(ActivityManageRule.this, Manifest.permission.SEND_SMS))
|
||||
if(ActivityPermissions.isPermissionDeclaratedInManifest(ActivityManageRule.this, "android.permission.SEND_SMS"))
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.phone));
|
||||
}
|
||||
else if(types[i].toString().equals(Trigger_Enum.nfcTag.toString()))
|
||||
@ -643,21 +531,6 @@ public class ActivityManageRule extends Activity
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.sound));
|
||||
else if(types[i].toString().equals(Trigger_Enum.screenState.toString()))
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.smartphone));
|
||||
else if(types[i].toString().equals(Trigger_Enum.deviceStarts.toString()))
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.alarm));
|
||||
else if(types[i].toString().equals(Trigger_Enum.serviceStarts.toString()))
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.alarm));
|
||||
else if(types[i].toString().equals(Trigger_Enum.tethering.toString()))
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.router));
|
||||
else if(types[i].toString().equals(Trigger_Enum.subSystemState.toString()))
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.subsystemstate));
|
||||
else if(types[i].toString().equals(Trigger_Enum.checkVariable.toString()))
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.variable));
|
||||
else if(types[i].toString().equals(Trigger_Enum.calendarEvent.toString()))
|
||||
{
|
||||
if(ActivityPermissions.isPermissionDeclaratedInManifest(ActivityManageRule.this, Manifest.permission.READ_CALENDAR))
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.calendar));
|
||||
}
|
||||
else
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.placeholder));
|
||||
}
|
||||
@ -666,15 +539,15 @@ public class ActivityManageRule extends Activity
|
||||
{
|
||||
public View getView(int position, View convertView, ViewGroup parent)
|
||||
{
|
||||
// User super class to create the View
|
||||
//User super class to create the View
|
||||
View v = super.getView(position, convertView, parent);
|
||||
|
||||
TextView tv = (TextView)v.findViewById(android.R.id.text1);
|
||||
|
||||
// Put the image on the TextView
|
||||
//Put the image on the TextView
|
||||
tv.setCompoundDrawablesWithIntrinsicBounds(items.get(position).icon, 0, 0, 0);
|
||||
|
||||
// Add margin between image and text (support various screen densities)
|
||||
//Add margin between image and text (support various screen densities)
|
||||
int dp5 = (int) (5 * getResources().getDisplayMetrics().density + 0.5f);
|
||||
tv.setCompoundDrawablePadding(dp5);
|
||||
|
||||
@ -718,18 +591,11 @@ public class ActivityManageRule extends Activity
|
||||
startActivityForResult(timeFrameEditor, requestCodeTriggerTimeframeAdd);
|
||||
return;
|
||||
}
|
||||
else if(triggerType == Trigger_Enum.charging)
|
||||
{
|
||||
newTrigger.setTriggerType(Trigger_Enum.charging);
|
||||
Intent triggerChargingIntent = new Intent(myContext, ActivityManageTriggerCharging.class);
|
||||
startActivityForResult(triggerChargingIntent, requestCodeTriggerChargingAdd);
|
||||
return;
|
||||
}
|
||||
else if(triggerType == Trigger_Enum.musicPlaying)
|
||||
else if(triggerType == Trigger_Enum.charging || triggerType == Trigger_Enum.musicPlaying)
|
||||
booleanChoices = new String[]{getResources().getString(R.string.started), getResources().getString(R.string.stopped)};
|
||||
else if(triggerType == Trigger_Enum.usb_host_connection)
|
||||
booleanChoices = new String[]{getResources().getString(R.string.connected), getResources().getString(R.string.disconnected)};
|
||||
else if(triggerType == Trigger_Enum.speed || triggerType == Trigger_Enum.noiseLevel || triggerType == Trigger_Enum.batteryLevel)
|
||||
else if(triggerType == Trigger_Enum.speed | triggerType == Trigger_Enum.noiseLevel | triggerType == Trigger_Enum.batteryLevel)
|
||||
booleanChoices = new String[]{getResources().getString(R.string.exceeds), getResources().getString(R.string.dropsBelow)};
|
||||
else if(triggerType == Trigger_Enum.wifiConnection)
|
||||
{
|
||||
@ -819,41 +685,21 @@ public class ActivityManageRule extends Activity
|
||||
}
|
||||
else if(triggerType == Trigger_Enum.bluetoothConnection)
|
||||
{
|
||||
// if(!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH))
|
||||
// //Miscellaneous.messageBox("Bluetooth", getResources().getString(R.string.deviceDoesNotHaveBluetooth), ActivityManageRule.this).show();
|
||||
// Toast.makeText(ActivityManageRule.this, getResources().getString(R.string.deviceDoesNotHaveBluetooth), Toast.LENGTH_LONG).show();
|
||||
if(!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH))
|
||||
Miscellaneous.messageBox("Bluetooth", getResources().getString(R.string.deviceDoesNotHaveBluetooth), ActivityManageRule.this).show();;
|
||||
|
||||
newTrigger.setTriggerType(Trigger_Enum.bluetoothConnection);
|
||||
ActivityManageTriggerBluetooth.editedBluetoothTrigger = newTrigger;
|
||||
Intent bluetoothEditor = new Intent(myContext, ActivityManageTriggerBluetooth.class);
|
||||
startActivityForResult(bluetoothEditor, requestCodeTriggerBluetoothAdd);
|
||||
|
||||
return;
|
||||
}
|
||||
else if(triggerType == Trigger_Enum.screenState)
|
||||
{
|
||||
newTrigger.setTriggerType(Trigger_Enum.screenState);
|
||||
getTriggerScreenStateDialog().show();
|
||||
Miscellaneous.messageBox(getResources().getString(R.string.info), getResources().getString(R.string.lockedCommentScreenMustBeOff), ActivityManageRule.this).show();
|
||||
return;
|
||||
}
|
||||
/*else if(triggerType == Trigger_Enum.deviceStarts)
|
||||
{
|
||||
newTrigger.setTriggerType(Trigger_Enum.deviceStarts);
|
||||
ruleToEdit.getTriggerSet().add(newTrigger);
|
||||
refreshTriggerList();
|
||||
return;
|
||||
}*/
|
||||
else if(triggerType == Trigger_Enum.deviceStarts || triggerType == Trigger_Enum.serviceStarts)
|
||||
{
|
||||
// newTrigger.setTriggerType(Trigger_Enum.serviceStarts);
|
||||
// ruleToEdit.getTriggerSet().add(newTrigger);
|
||||
|
||||
booleanChoices = new String[]{getResources().getString(R.string.yes), getResources().getString(R.string.no)};
|
||||
|
||||
// refreshTriggerList();
|
||||
// return;
|
||||
}
|
||||
else if(triggerType == Trigger_Enum.headsetPlugged)
|
||||
booleanChoices = new String[]{getResources().getString(R.string.connected), getResources().getString(R.string.disconnected)};
|
||||
|
||||
@ -862,41 +708,6 @@ public class ActivityManageRule extends Activity
|
||||
if (NfcReceiver.checkNfcRequirements(ActivityManageRule.this, true))
|
||||
getTriggerParameterDialog(context, booleanChoices).show();
|
||||
}
|
||||
else if(triggerType == Trigger_Enum.broadcastReceived)
|
||||
{
|
||||
newTrigger.setTriggerType(Trigger_Enum.broadcastReceived);
|
||||
Intent broadcastTriggerEditor = new Intent(myContext, ActivityManageTriggerBroadcast.class);
|
||||
startActivityForResult(broadcastTriggerEditor, requestCodeTriggerBroadcastReceivedAdd);
|
||||
return;
|
||||
}
|
||||
else if(triggerType == Trigger_Enum.tethering)
|
||||
{
|
||||
newTrigger.setTriggerType(Trigger_Enum.tethering);
|
||||
Intent tetheringTriggerEditor = new Intent(myContext, ActivityManageTriggerTethering.class);
|
||||
startActivityForResult(tetheringTriggerEditor, requestCodeTriggerTetheringAdd);
|
||||
return;
|
||||
}
|
||||
else if(triggerType == Trigger_Enum.subSystemState)
|
||||
{
|
||||
newTrigger.setTriggerType(Trigger_Enum.subSystemState);
|
||||
Intent subSystemStateTriggerEditor = new Intent(myContext, ActivityManageTriggerSubSystemState.class);
|
||||
startActivityForResult(subSystemStateTriggerEditor, requestCodeTriggerSubSystemStateAdd);
|
||||
return;
|
||||
}
|
||||
else if(triggerType == Trigger_Enum.checkVariable)
|
||||
{
|
||||
newTrigger.setTriggerType(Trigger_Enum.checkVariable);
|
||||
Intent variableTriggerEditor = new Intent(myContext, ActivityManageTriggerCheckVariable.class);
|
||||
startActivityForResult(variableTriggerEditor, requestCodeTriggerCheckVariableAdd);
|
||||
return;
|
||||
}
|
||||
else if(triggerType == Trigger_Enum.calendarEvent)
|
||||
{
|
||||
newTrigger.setTriggerType(Trigger_Enum.calendarEvent);
|
||||
Intent calendarTriggerEditor = new Intent(myContext, ActivityManageTriggerCalendar.class);
|
||||
startActivityForResult(calendarTriggerEditor, requestCodeTriggerCalendarEventAdd);
|
||||
return;
|
||||
}
|
||||
else
|
||||
getTriggerParameterDialog(context, booleanChoices).show();
|
||||
|
||||
@ -988,7 +799,6 @@ public class ActivityManageRule extends Activity
|
||||
|
||||
return alertDialog;
|
||||
}
|
||||
|
||||
private AlertDialog getTriggerBatteryDialog(final Context myContext, final String[] choices)
|
||||
{
|
||||
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
|
||||
@ -1003,7 +813,6 @@ public class ActivityManageRule extends Activity
|
||||
triggerBattery = (which+1);
|
||||
newTrigger.setTriggerType(Trigger_Enum.batteryLevel);
|
||||
newTrigger.setBatteryLevel(triggerBattery);
|
||||
newTrigger.setTriggerParameter2(String.valueOf(triggerBattery));
|
||||
// Log.i("test", newTrigger.toString());
|
||||
// Log.i("test", String.valueOf(newTrigger.getBatteryLevel()));
|
||||
ruleToEdit.getTriggerSet().add(newTrigger);
|
||||
@ -1138,7 +947,7 @@ public class ActivityManageRule extends Activity
|
||||
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
|
||||
|
||||
alertDialog.setTitle(myContext.getResources().getString(R.string.phoneNumber));
|
||||
alertDialog.setMessage(myContext.getResources().getString(R.string.enterPhoneNumberBlankForAny));
|
||||
alertDialog.setMessage(myContext.getResources().getString(R.string.enterPhoneNumber));
|
||||
|
||||
// Set an EditText view to get user input
|
||||
final EditText input = new EditText(this);
|
||||
@ -1235,9 +1044,7 @@ public class ActivityManageRule extends Activity
|
||||
String[] choices = {
|
||||
Miscellaneous.getAnyContext().getResources().getString(R.string.off),
|
||||
Miscellaneous.getAnyContext().getResources().getString(R.string.on),
|
||||
Miscellaneous.getAnyContext().getResources().getString(R.string.unlocked),
|
||||
Miscellaneous.getAnyContext().getResources().getString(R.string.lockedWithoutSecurity),
|
||||
Miscellaneous.getAnyContext().getResources().getString(R.string.lockedWithSecurity)
|
||||
Miscellaneous.getAnyContext().getResources().getString(R.string.unlocked)
|
||||
};
|
||||
|
||||
alertDialog.setItems(choices, new DialogInterface.OnClickListener()
|
||||
@ -1245,7 +1052,6 @@ public class ActivityManageRule extends Activity
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
newTrigger.setTriggerParameter(true);
|
||||
newTrigger.setTriggerParameter2(String.valueOf(which));
|
||||
ruleToEdit.getTriggerSet().add(newTrigger);
|
||||
refreshTriggerList();
|
||||
@ -1399,11 +1205,9 @@ public class ActivityManageRule extends Activity
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
newAction.setParentRule(ruleToEdit);
|
||||
newAction.setAction(Action_Enum.triggerUrl);
|
||||
newAction.setParameter1(data.getBooleanExtra(intentNameActionParameter1, true));
|
||||
newAction.setParameter2(data.getStringExtra(intentNameActionParameter2));
|
||||
ruleToEdit.getActionSet().add(newAction);
|
||||
//add TriggerUrl
|
||||
ActivityManageActionTriggerUrl.resultingAction.setParentRule(ruleToEdit);
|
||||
ruleToEdit.getActionSet().add(ActivityManageActionTriggerUrl.resultingAction);
|
||||
this.refreshActionList();
|
||||
}
|
||||
}
|
||||
@ -1411,14 +1215,7 @@ public class ActivityManageRule extends Activity
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
ruleToEdit.getActionSet().get(editIndex).setParentRule(ruleToEdit);
|
||||
|
||||
if(data.hasExtra(intentNameActionParameter1))
|
||||
ruleToEdit.getActionSet().get(editIndex).setParameter1(data.getBooleanExtra(intentNameActionParameter1, true));
|
||||
|
||||
if(data.hasExtra(intentNameActionParameter2))
|
||||
ruleToEdit.getActionSet().get(editIndex).setParameter2(data.getStringExtra(intentNameActionParameter2));
|
||||
|
||||
//edit TriggerUrl
|
||||
this.refreshActionList();
|
||||
}
|
||||
}
|
||||
@ -1475,39 +1272,13 @@ public class ActivityManageRule extends Activity
|
||||
this.refreshTriggerList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeTriggerChargingAdd)
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
newTrigger.setTriggerParameter(data.getBooleanExtra(ActivityManageRule.intentNameTriggerParameter1, false));
|
||||
newTrigger.setTriggerParameter2(data.getStringExtra(ActivityManageRule.intentNameTriggerParameter2));
|
||||
newTrigger.setParentRule(ruleToEdit);
|
||||
ruleToEdit.getTriggerSet().add(newTrigger);
|
||||
this.refreshTriggerList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeTriggerChargingEdit)
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
Trigger responseTimeFrame = new Trigger();
|
||||
responseTimeFrame.setTriggerType(Trigger_Enum.charging);
|
||||
responseTimeFrame.setTriggerParameter(data.getBooleanExtra(intentNameTriggerParameter1, true));
|
||||
responseTimeFrame.setTriggerParameter2(data.getStringExtra(intentNameTriggerParameter2));
|
||||
responseTimeFrame.setParentRule(ruleToEdit);
|
||||
ruleToEdit.getTriggerSet().set(editIndex, responseTimeFrame);
|
||||
this.refreshTriggerList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeActionStartActivityAdd)
|
||||
{
|
||||
// manage start of other activity
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
newAction = ActivityManageActionStartActivity.resultingAction;
|
||||
newAction.setParentRule(ruleToEdit);
|
||||
newAction.setAction(Action_Enum.startOtherActivity);
|
||||
newAction.setParameter1(data.getBooleanExtra(intentNameActionParameter1, true));
|
||||
newAction.setParameter2(data.getStringExtra(intentNameActionParameter2));
|
||||
ruleToEdit.getActionSet().add(newAction);
|
||||
this.refreshActionList();
|
||||
}
|
||||
@ -1517,14 +1288,9 @@ public class ActivityManageRule extends Activity
|
||||
// manage start of other activity
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
ruleToEdit.getActionSet().get(editIndex).setParentRule(ruleToEdit);
|
||||
|
||||
if(data.hasExtra(intentNameActionParameter1))
|
||||
ruleToEdit.getActionSet().get(editIndex).setParameter1(data.getBooleanExtra(intentNameActionParameter1, true));
|
||||
|
||||
if(data.hasExtra(intentNameActionParameter2))
|
||||
ruleToEdit.getActionSet().get(editIndex).setParameter2(data.getStringExtra(intentNameActionParameter2));
|
||||
|
||||
newAction = ActivityManageActionStartActivity.resultingAction;
|
||||
newAction.setParentRule(ruleToEdit);
|
||||
// ruleToEdit.getActionSet().add(newAction);
|
||||
this.refreshActionList();
|
||||
}
|
||||
}
|
||||
@ -1564,18 +1330,8 @@ public class ActivityManageRule extends Activity
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
Trigger editedTrigger = new Trigger();
|
||||
editedTrigger.setTriggerType(Trigger_Enum.notification);
|
||||
editedTrigger.setTriggerParameter(data.getBooleanExtra(ActivityManageTriggerNotification.intentNameNotificationDirection, false));
|
||||
editedTrigger.setTriggerParameter2(
|
||||
data.getStringExtra(ActivityManageTriggerNotification.intentNameNotificationApp) + Trigger.triggerParameter2Split +
|
||||
data.getStringExtra(ActivityManageTriggerNotification.intentNameNotificationTitleDir) + Trigger.triggerParameter2Split +
|
||||
data.getStringExtra(ActivityManageTriggerNotification.intentNameNotificationTitle) + Trigger.triggerParameter2Split +
|
||||
data.getStringExtra(ActivityManageTriggerNotification.intentNameNotificationTextDir) + Trigger.triggerParameter2Split +
|
||||
data.getStringExtra(ActivityManageTriggerNotification.intentNameNotificationText)
|
||||
);
|
||||
editedTrigger.setParentRule(ruleToEdit);
|
||||
ruleToEdit.getTriggerSet().set(editIndex, editedTrigger);
|
||||
newTrigger = ActivityManageTriggerNotification.resultingTrigger;
|
||||
newTrigger.setParentRule(ruleToEdit);
|
||||
this.refreshTriggerList();
|
||||
}
|
||||
}
|
||||
@ -1585,7 +1341,7 @@ public class ActivityManageRule extends Activity
|
||||
{
|
||||
newTrigger.setParentRule(ruleToEdit);
|
||||
ruleToEdit.getTriggerSet().add(newTrigger);
|
||||
newTrigger.setTriggerParameter2(data.getStringExtra(intentNameTriggerParameter2));
|
||||
newTrigger.setTriggerParameter2(data.getStringExtra("triggerParameter2"));
|
||||
this.refreshTriggerList();
|
||||
}
|
||||
}
|
||||
@ -1656,11 +1412,11 @@ public class ActivityManageRule extends Activity
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
if(data.hasExtra(ActivityManageActionBrightnessSetting.intentNameAutoBrightness))
|
||||
ruleToEdit.getActionSet().get(editIndex).setParameter1(data.getBooleanExtra(ActivityManageActionBrightnessSetting.intentNameAutoBrightness, false));
|
||||
if(data.hasExtra("autoBrightness"))
|
||||
ruleToEdit.getActionSet().get(editIndex).setParameter1(data.getBooleanExtra("autoBrightness", false));
|
||||
|
||||
if(data.hasExtra(ActivityManageActionBrightnessSetting.intentNameBrightnessValue))
|
||||
ruleToEdit.getActionSet().get(editIndex).setParameter2(String.valueOf(data.getIntExtra(ActivityManageActionBrightnessSetting.intentNameBrightnessValue, 0)));
|
||||
if(data.hasExtra("brightnessValue"))
|
||||
ruleToEdit.getActionSet().get(editIndex).setParameter2(String.valueOf(data.getIntExtra("brightnessValue", 0)));
|
||||
|
||||
ruleToEdit.getActionSet().get(editIndex).setParentRule(ruleToEdit);
|
||||
|
||||
@ -1677,59 +1433,6 @@ public class ActivityManageRule extends Activity
|
||||
this.refreshActionList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeActionSendBroadcastAdd)
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
newAction.setParentRule(ruleToEdit);
|
||||
newAction.setParameter2(data.getStringExtra(intentNameActionParameter2));
|
||||
ruleToEdit.getActionSet().add(newAction);
|
||||
this.refreshActionList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeActionRunExecutableAdd)
|
||||
{
|
||||
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 == requestCodeActionMakePhoneCallAdd)
|
||||
{
|
||||
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 == requestCodeActionSetVariableAdd)
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
newAction.setParentRule(ruleToEdit);
|
||||
newAction.setParameter2(data.getStringExtra(intentNameActionParameter2));
|
||||
ruleToEdit.getActionSet().add(newAction);
|
||||
this.refreshActionList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeActionWakeLockAdd)
|
||||
{
|
||||
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 == requestCodeActionControlMediaAdd)
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
@ -1740,17 +1443,6 @@ public class ActivityManageRule extends Activity
|
||||
this.refreshActionList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeActionSetWifiAdd)
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
newAction.setParentRule(ruleToEdit);
|
||||
newAction.setParameter1(data.getBooleanExtra(ActivityManageRule.intentNameActionParameter1, true));
|
||||
newAction.setParameter2(data.getStringExtra(ActivityManageRule.intentNameActionParameter2));
|
||||
ruleToEdit.getActionSet().add(newAction);
|
||||
this.refreshActionList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeActionCreateNotificationAdd)
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
@ -1787,92 +1479,6 @@ public class ActivityManageRule extends Activity
|
||||
this.refreshActionList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeActionSendBroadcastEdit)
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
ruleToEdit.getActionSet().get(editIndex).setParentRule(ruleToEdit);
|
||||
|
||||
if(data.hasExtra(intentNameActionParameter2))
|
||||
ruleToEdit.getActionSet().get(editIndex).setParameter2(data.getStringExtra(intentNameActionParameter2));
|
||||
|
||||
this.refreshActionList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeActionWakeLockEdit)
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
ruleToEdit.getActionSet().get(editIndex).setParentRule(ruleToEdit);
|
||||
|
||||
if(data.hasExtra(intentNameActionParameter1))
|
||||
ruleToEdit.getActionSet().get(editIndex).setParameter1(data.getBooleanExtra(intentNameActionParameter1, true));
|
||||
|
||||
if(data.hasExtra(intentNameActionParameter2))
|
||||
ruleToEdit.getActionSet().get(editIndex).setParameter2(data.getStringExtra(intentNameActionParameter2));
|
||||
|
||||
this.refreshActionList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeActionRunExecutableEdit)
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
ruleToEdit.getActionSet().get(editIndex).setParentRule(ruleToEdit);
|
||||
|
||||
if(data.hasExtra(intentNameActionParameter1) && data.hasExtra(intentNameActionParameter2))
|
||||
{
|
||||
ruleToEdit.getActionSet().get(editIndex).setParameter1(data.getBooleanExtra(intentNameActionParameter1, false));
|
||||
ruleToEdit.getActionSet().get(editIndex).setParameter2(data.getStringExtra(intentNameActionParameter2));
|
||||
}
|
||||
|
||||
this.refreshActionList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeActionMakePhoneCallEdit)
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
ruleToEdit.getActionSet().get(editIndex).setParentRule(ruleToEdit);
|
||||
|
||||
if(data.hasExtra(intentNameActionParameter1) && data.hasExtra(intentNameActionParameter2))
|
||||
{
|
||||
ruleToEdit.getActionSet().get(editIndex).setParameter1(data.getBooleanExtra(intentNameActionParameter1, false));
|
||||
ruleToEdit.getActionSet().get(editIndex).setParameter2(data.getStringExtra(intentNameActionParameter2));
|
||||
}
|
||||
|
||||
this.refreshActionList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeActionSetVariableEdit)
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
ruleToEdit.getActionSet().get(editIndex).setParentRule(ruleToEdit);
|
||||
|
||||
if(data.hasExtra(intentNameActionParameter2))
|
||||
{
|
||||
ruleToEdit.getActionSet().get(editIndex).setParameter2(data.getStringExtra(intentNameActionParameter2));
|
||||
}
|
||||
|
||||
this.refreshActionList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeActionSetWifiEdit)
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
ruleToEdit.getActionSet().get(editIndex).setParentRule(ruleToEdit);
|
||||
|
||||
if(data.hasExtra(intentNameActionParameter1) && data.hasExtra(intentNameActionParameter2))
|
||||
{
|
||||
ruleToEdit.getActionSet().get(editIndex).setParameter1(data.getBooleanExtra(intentNameActionParameter1, false));
|
||||
ruleToEdit.getActionSet().get(editIndex).setParameter2(data.getStringExtra(intentNameActionParameter2));
|
||||
}
|
||||
|
||||
this.refreshActionList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeActionControlMediaEdit)
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
@ -2006,177 +1612,6 @@ public class ActivityManageRule extends Activity
|
||||
this.refreshTriggerList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeTriggerBroadcastReceivedAdd)
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
newTrigger.setTriggerParameter(data.getBooleanExtra(ActivityManageRule.intentNameTriggerParameter1, true));
|
||||
newTrigger.setTriggerParameter2(data.getStringExtra(ActivityManageRule.intentNameTriggerParameter2));
|
||||
newTrigger.setParentRule(ruleToEdit);
|
||||
ruleToEdit.getTriggerSet().add(newTrigger);
|
||||
this.refreshTriggerList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeTriggerBroadcastReceivedEdit)
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
Trigger editedTrigger = new Trigger();
|
||||
editedTrigger.setTriggerType(Trigger_Enum.broadcastReceived);
|
||||
editedTrigger.setTriggerParameter(data.getBooleanExtra(ActivityManageRule.intentNameTriggerParameter1, true));
|
||||
editedTrigger.setTriggerParameter2(data.getStringExtra(ActivityManageRule.intentNameTriggerParameter2));
|
||||
editedTrigger.setParentRule(ruleToEdit);
|
||||
ruleToEdit.getTriggerSet().set(editIndex, editedTrigger);
|
||||
this.refreshTriggerList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeTriggerTetheringAdd)
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
newTrigger.setTriggerParameter(data.getBooleanExtra(intentNameTriggerParameter1, true));
|
||||
newTrigger.setTriggerParameter2(data.getStringExtra(intentNameTriggerParameter2));
|
||||
newTrigger.setParentRule(ruleToEdit);
|
||||
ruleToEdit.getTriggerSet().add(newTrigger);
|
||||
this.refreshTriggerList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeTriggerSubSystemStateAdd)
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
newTrigger.setTriggerParameter(data.getBooleanExtra(intentNameTriggerParameter1, true));
|
||||
newTrigger.setTriggerParameter2(data.getStringExtra(intentNameTriggerParameter2));
|
||||
newTrigger.setParentRule(ruleToEdit);
|
||||
ruleToEdit.getTriggerSet().add(newTrigger);
|
||||
this.refreshTriggerList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeTriggerCheckVariableAdd)
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
newTrigger.setTriggerParameter(data.getBooleanExtra(intentNameTriggerParameter1, true));
|
||||
newTrigger.setTriggerParameter2(data.getStringExtra(intentNameTriggerParameter2));
|
||||
newTrigger.setParentRule(ruleToEdit);
|
||||
ruleToEdit.getTriggerSet().add(newTrigger);
|
||||
this.refreshTriggerList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeTriggerCalendarEventAdd)
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
newTrigger.setTriggerParameter(data.getBooleanExtra(intentNameTriggerParameter1, true));
|
||||
newTrigger.setTriggerParameter2(data.getStringExtra(intentNameTriggerParameter2));
|
||||
newTrigger.setParentRule(ruleToEdit);
|
||||
ruleToEdit.getTriggerSet().add(newTrigger);
|
||||
this.refreshTriggerList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeTriggerTetheringEdit)
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
Trigger editedTrigger = new Trigger();
|
||||
editedTrigger.setTriggerType(Trigger_Enum.tethering);
|
||||
editedTrigger.setTriggerParameter(data.getBooleanExtra(intentNameTriggerParameter1, true));
|
||||
editedTrigger.setTriggerParameter2(data.getStringExtra(intentNameTriggerParameter2));
|
||||
editedTrigger.setParentRule(ruleToEdit);
|
||||
ruleToEdit.getTriggerSet().set(editIndex, editedTrigger);
|
||||
this.refreshTriggerList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeTriggerSubSystemStateEdit)
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
Trigger editedTrigger = new Trigger();
|
||||
editedTrigger.setTriggerType(Trigger_Enum.subSystemState);
|
||||
editedTrigger.setTriggerParameter(data.getBooleanExtra(intentNameTriggerParameter1, true));
|
||||
editedTrigger.setTriggerParameter2(data.getStringExtra(intentNameTriggerParameter2));
|
||||
editedTrigger.setParentRule(ruleToEdit);
|
||||
ruleToEdit.getTriggerSet().set(editIndex, editedTrigger);
|
||||
this.refreshTriggerList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeTriggerCheckVariableEdit)
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
Trigger editedTrigger = new Trigger();
|
||||
editedTrigger.setTriggerType(Trigger_Enum.checkVariable);
|
||||
editedTrigger.setTriggerParameter(data.getBooleanExtra(intentNameTriggerParameter1, true));
|
||||
editedTrigger.setTriggerParameter2(data.getStringExtra(intentNameTriggerParameter2));
|
||||
editedTrigger.setParentRule(ruleToEdit);
|
||||
ruleToEdit.getTriggerSet().set(editIndex, editedTrigger);
|
||||
this.refreshTriggerList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeTriggerCalendarEventEdit)
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
Trigger editedTrigger = new Trigger();
|
||||
editedTrigger.setTriggerType(Trigger_Enum.calendarEvent);
|
||||
editedTrigger.setTriggerParameter(data.getBooleanExtra(intentNameTriggerParameter1, true));
|
||||
editedTrigger.setTriggerParameter2(data.getStringExtra(intentNameTriggerParameter2));
|
||||
editedTrigger.setParentRule(ruleToEdit);
|
||||
ruleToEdit.getTriggerSet().set(editIndex, editedTrigger);
|
||||
this.refreshTriggerList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeActionCopyTextToClipboardAdd)
|
||||
{
|
||||
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 == requestCodeActionCopyTextToClipboardEdit)
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
ruleToEdit.getActionSet().get(editIndex).setParentRule(ruleToEdit);
|
||||
|
||||
if(data.hasExtra(intentNameActionParameter2))
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected AlertDialog getActionTypeDialog()
|
||||
@ -2230,38 +1665,12 @@ public class ActivityManageRule extends Activity
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.notification));
|
||||
else if(types[i].toString().equals(Action_Enum.closeNotification.toString()))
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.notification));
|
||||
else if(types[i].toString().equals(Action_Enum.sendBroadcast.toString()))
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.megaphone));
|
||||
else if(types[i].toString().equals(Action_Enum.wakelock.toString()))
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.coffee));
|
||||
else if(types[i].toString().equals(Action_Enum.runExecutable.toString()))
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.script));
|
||||
else if(types[i].toString().equals(Action_Enum.startPhoneCall.toString()))
|
||||
{
|
||||
if(ActivityPermissions.isPermissionDeclaratedInManifest(ActivityManageRule.this, Manifest.permission.CALL_PHONE))
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.phone));
|
||||
}
|
||||
else if(types[i].toString().equals(Action_Enum.stopPhoneCall.toString()))
|
||||
{
|
||||
if(ActivityPermissions.isPermissionDeclaratedInManifest(ActivityManageRule.this, Manifest.permission.ANSWER_PHONE_CALLS))
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.phone));
|
||||
}
|
||||
else if(types[i].toString().equals(Action_Enum.sendTextMessage.toString()))
|
||||
{
|
||||
// if(ActivityPermissions.isPermissionDeclaratedInManifest(ActivityManageSpecificRule.this, "android.permission.SEND_SMS") && !Miscellaneous.isGooglePlayInstalled(ActivityManageSpecificRule.this))
|
||||
if(ActivityPermissions.isPermissionDeclaratedInManifest(ActivityManageRule.this, Manifest.permission.SEND_SMS))
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.message));
|
||||
}
|
||||
else if(types[i].toString().equals(Action_Enum.copyToClipboard.toString()))
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.clipboard));
|
||||
else if(types[i].toString().equals(Action_Enum.setVariable.toString()))
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.variable));
|
||||
else if(types[i].toString().equals(Action_Enum.setLocationService.toString()))
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.compass_small));
|
||||
else if(types[i].toString().equals(Action_Enum.takeScreenshot.toString()))
|
||||
{
|
||||
if(ActivityPermissions.isPermissionDeclaratedInManifest(ActivityManageRule.this, Manifest.permission.BIND_ACCESSIBILITY_SERVICE))
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.copier));
|
||||
}
|
||||
else
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.placeholder));
|
||||
}
|
||||
@ -2298,15 +1707,17 @@ public class ActivityManageRule extends Activity
|
||||
{
|
||||
//launch other activity to enter a url and parameters;
|
||||
newAction.setAction(Action_Enum.triggerUrl);
|
||||
// ActivityManageActionTriggerUrl.resultingAction = null;
|
||||
ActivityManageActionTriggerUrl.resultingAction = null;
|
||||
Intent editTriggerIntent = new Intent(context, ActivityManageActionTriggerUrl.class);
|
||||
startActivityForResult(editTriggerIntent, requestCodeActionTriggerUrlAdd);
|
||||
}
|
||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.setWifi.toString()))
|
||||
{
|
||||
newAction.setAction(Action_Enum.setWifi);
|
||||
Intent editSetWifiIntent = new Intent(context, ActivityManageActionWifi.class);
|
||||
startActivityForResult(editSetWifiIntent, requestCodeActionSetWifiAdd);
|
||||
getActionParameter1Dialog(ActivityManageRule.this).show();
|
||||
|
||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
|
||||
Miscellaneous.messageBox(context.getResources().getString(R.string.app_name), context.getResources().getString(R.string.android10WifiToggleNotice), context).show();
|
||||
}
|
||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.setBluetooth.toString()))
|
||||
{
|
||||
@ -2416,42 +1827,6 @@ public class ActivityManageRule extends Activity
|
||||
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionVibrate.class);
|
||||
startActivityForResult(intent, requestCodeActionVibrateAdd);
|
||||
}
|
||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.sendBroadcast.toString()))
|
||||
{
|
||||
newAction.setAction(Action_Enum.sendBroadcast);
|
||||
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionSendBroadcast.class);
|
||||
startActivityForResult(intent, requestCodeActionSendBroadcastAdd);
|
||||
}
|
||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.runExecutable.toString()))
|
||||
{
|
||||
newAction.setAction(Action_Enum.runExecutable);
|
||||
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionRunExecutable.class);
|
||||
startActivityForResult(intent, requestCodeActionRunExecutableAdd);
|
||||
}
|
||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.startPhoneCall.toString()))
|
||||
{
|
||||
newAction.setAction(Action_Enum.startPhoneCall);
|
||||
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionMakePhoneCall.class);
|
||||
startActivityForResult(intent, requestCodeActionMakePhoneCallAdd);
|
||||
}
|
||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.setVariable.toString()))
|
||||
{
|
||||
newAction.setAction(Action_Enum.setVariable);
|
||||
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionSetVariable.class);
|
||||
startActivityForResult(intent, requestCodeActionSetVariableAdd);
|
||||
}
|
||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.stopPhoneCall.toString()))
|
||||
{
|
||||
newAction.setAction(Action_Enum.stopPhoneCall);
|
||||
ruleToEdit.getActionSet().add(newAction);
|
||||
refreshActionList();
|
||||
}
|
||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.wakelock.toString()))
|
||||
{
|
||||
newAction.setAction(Action_Enum.wakelock);
|
||||
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionWakeLock.class);
|
||||
startActivityForResult(intent, requestCodeActionWakeLockAdd);
|
||||
}
|
||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.controlMediaPlayback.toString()))
|
||||
{
|
||||
newAction.setAction(Action_Enum.controlMediaPlayback);
|
||||
@ -2482,24 +1857,6 @@ public class ActivityManageRule extends Activity
|
||||
Intent actionPlaySoundIntent = new Intent(context, ActivityManageActionPlaySound.class);
|
||||
startActivityForResult(actionPlaySoundIntent, requestCodeActionPlaySoundAdd);
|
||||
}
|
||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.copyToClipboard.toString()))
|
||||
{
|
||||
newAction.setAction(Action_Enum.copyToClipboard);
|
||||
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionCopyToClipboard.class);
|
||||
startActivityForResult(intent, requestCodeActionCopyTextToClipboardAdd);
|
||||
}
|
||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.takeScreenshot.toString()))
|
||||
{
|
||||
newAction.setAction(Action_Enum.takeScreenshot);
|
||||
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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -2,7 +2,6 @@ package com.jens.automation2;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
@ -13,7 +12,6 @@ import android.widget.CompoundButton;
|
||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.jens.automation2.receivers.BluetoothReceiver;
|
||||
@ -24,7 +22,6 @@ public class ActivityManageTriggerBluetooth extends Activity
|
||||
RadioButton radioAnyBluetoothDevice, radioNoDevice, radioDeviceFromList, radioBluetoothConnected, radioBluetoothDisconnected, radioBluetoothInRange, radioBluetoothOutRange;
|
||||
Button bSaveBluetoothTrigger;
|
||||
Spinner spinnerBluetoothDevices;
|
||||
TextView tvBluetoothNotPresentNotice;
|
||||
|
||||
ArrayAdapter<String> bluetoothDevicesSpinnerAdapter;
|
||||
|
||||
@ -32,7 +29,6 @@ public class ActivityManageTriggerBluetooth extends Activity
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
setContentView(R.layout.activity_manage_trigger_bluetooth);
|
||||
|
||||
radioAnyBluetoothDevice = (RadioButton)findViewById(R.id.radioAnyBluetoothDevice);
|
||||
@ -44,15 +40,9 @@ public class ActivityManageTriggerBluetooth extends Activity
|
||||
radioBluetoothOutRange = (RadioButton)findViewById(R.id.radioBluetoothOutRange);
|
||||
bSaveBluetoothTrigger = (Button)findViewById(R.id.bSaveBluetoothTrigger);
|
||||
spinnerBluetoothDevices = (Spinner)findViewById(R.id.spinnerBluetoothDevices);
|
||||
tvBluetoothNotPresentNotice = (TextView)findViewById(R.id.tvBluetoothNotPresentNotice);
|
||||
|
||||
bluetoothDevicesSpinnerAdapter = new ArrayAdapter<String>(this, R.layout.text_view_for_poi_listview_mediumtextsize, BluetoothReceiver.getAllPairedBluetoothDevicesStrings());
|
||||
|
||||
if(!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH))
|
||||
tvBluetoothNotPresentNotice.setVisibility(View.VISIBLE);
|
||||
else
|
||||
tvBluetoothNotPresentNotice.setVisibility(View.GONE);
|
||||
|
||||
|
||||
radioDeviceFromList.setOnCheckedChangeListener(new OnCheckedChangeListener()
|
||||
{
|
||||
@Override
|
||||
|
@ -1,422 +0,0 @@
|
||||
package com.jens.automation2;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class ActivityManageTriggerBroadcast extends Activity
|
||||
{
|
||||
RadioButton rbBroadcastReceived, rbBroadcastNotReceived;
|
||||
EditText etBroadcastTriggerAction;
|
||||
Button bBroadcastShowSuggestions, bSaveTriggerBroadcast;
|
||||
TextView tvBroadcastUrl;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
setContentView(R.layout.activity_manage_trigger_broadcasts);
|
||||
|
||||
bBroadcastShowSuggestions = findViewById(R.id.bBroadcastShowSuggestions);
|
||||
bSaveTriggerBroadcast = findViewById(R.id.bSaveTriggerBroadcast);
|
||||
etBroadcastTriggerAction = findViewById(R.id.etBroadcastTriggerAction);
|
||||
rbBroadcastReceived = findViewById(R.id.rbBroadcastReceived);
|
||||
rbBroadcastNotReceived = findViewById(R.id.rbBroadcastNotReceived);
|
||||
tvBroadcastUrl = findViewById(R.id.tvBroadcastUrl);
|
||||
|
||||
if(getIntent().hasExtra(ActivityManageRule.intentNameTriggerParameter1) && getIntent().hasExtra(ActivityManageRule.intentNameTriggerParameter2))
|
||||
{
|
||||
if(getIntent().getBooleanExtra(ActivityManageRule.intentNameTriggerParameter1, true))
|
||||
rbBroadcastReceived.setChecked(true);
|
||||
else
|
||||
rbBroadcastNotReceived.setChecked(true);
|
||||
|
||||
etBroadcastTriggerAction.setText(getIntent().getStringExtra(ActivityManageRule.intentNameTriggerParameter2));
|
||||
}
|
||||
|
||||
tvBroadcastUrl.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View view)
|
||||
{
|
||||
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(getResources().getString(R.string.broadcastListUrl)));
|
||||
startActivity(browserIntent);
|
||||
}
|
||||
});
|
||||
|
||||
bBroadcastShowSuggestions.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View view)
|
||||
{
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(ActivityManageTriggerBroadcast.this);
|
||||
builder.setTitle(getResources().getString(R.string.selectBroadcast));
|
||||
builder.setItems(broadcastSuggestions, new DialogInterface.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int which)
|
||||
{
|
||||
etBroadcastTriggerAction.setText(broadcastSuggestions[which]);
|
||||
}
|
||||
});
|
||||
builder.create().show();
|
||||
}
|
||||
});
|
||||
|
||||
bSaveTriggerBroadcast.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
if(etBroadcastTriggerAction.getText() != null && !StringUtils.isEmpty(etBroadcastTriggerAction.getText().toString()))
|
||||
{
|
||||
Intent data = new Intent();
|
||||
data.putExtra(ActivityManageRule.intentNameTriggerParameter1, rbBroadcastReceived.isChecked());
|
||||
data.putExtra(ActivityManageRule.intentNameTriggerParameter2, etBroadcastTriggerAction.getText().toString());
|
||||
ActivityManageTriggerBroadcast.this.setResult(RESULT_OK, data);
|
||||
|
||||
finish();
|
||||
}
|
||||
else
|
||||
Toast.makeText(ActivityManageTriggerBroadcast.this, getResources().getString(R.string.enterText), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static String[] broadcastSuggestions = {
|
||||
"android.accounts.LOGIN_ACCOUNTS_CHANGED",
|
||||
"android.accounts.action.ACCOUNT_REMOVED",
|
||||
"android.app.action.ACTION_PASSWORD_CHANGED",
|
||||
"android.app.action.ACTION_PASSWORD_EXPIRING",
|
||||
"android.app.action.ACTION_PASSWORD_FAILED",
|
||||
"android.app.action.ACTION_PASSWORD_SUCCEEDED",
|
||||
"android.app.action.AFFILIATED_PROFILE_TRANSFER_OWNERSHIP_COMPLETE",
|
||||
"android.app.action.APPLICATION_DELEGATION_SCOPES_CHANGED",
|
||||
"android.app.action.APP_BLOCK_STATE_CHANGED",
|
||||
"android.app.action.AUTOMATIC_ZEN_RULE_STATUS_CHANGED",
|
||||
"android.app.action.BUGREPORT_FAILED",
|
||||
"android.app.action.BUGREPORT_SHARE",
|
||||
"android.app.action.BUGREPORT_SHARING_DECLINED",
|
||||
"android.app.action.DATA_SHARING_RESTRICTION_APPLIED",
|
||||
"android.app.action.DATA_SHARING_RESTRICTION_CHANGED",
|
||||
"android.app.action.DEVICE_ADMIN_DISABLED",
|
||||
"android.app.action.DEVICE_ADMIN_DISABLE_REQUESTED",
|
||||
"android.app.action.DEVICE_ADMIN_ENABLED",
|
||||
"android.app.action.DEVICE_OWNER_CHANGED",
|
||||
"android.app.action.INTERRUPTION_FILTER_CHANGED",
|
||||
"android.app.action.INTERRUPTION_FILTER_CHANGED_INTERNAL",
|
||||
"android.app.action.LOCK_TASK_ENTERING",
|
||||
"android.app.action.LOCK_TASK_EXITING",
|
||||
"android.app.action.MANAGED_USER_CREATED",
|
||||
"android.app.action.NETWORK_LOGS_AVAILABLE",
|
||||
"android.app.action.NEXT_ALARM_CLOCK_CHANGED",
|
||||
"android.app.action.NOTIFICATION_CHANNEL_BLOCK_STATE_CHANGED",
|
||||
"android.app.action.NOTIFICATION_CHANNEL_GROUP_BLOCK_STATE_CHANGED",
|
||||
"android.app.action.NOTIFICATION_POLICY_ACCESS_GRANTED_CHANGED",
|
||||
"android.app.action.NOTIFICATION_POLICY_CHANGED",
|
||||
"android.app.action.NOTIFY_PENDING_SYSTEM_UPDATE",
|
||||
"android.app.action.PROFILE_OWNER_CHANGED",
|
||||
"android.app.action.PROFILE_PROVISIONING_COMPLETE",
|
||||
"android.app.action.SECURITY_LOGS_AVAILABLE",
|
||||
"android.app.action.SYSTEM_UPDATE_POLICY_CHANGED",
|
||||
"android.app.action.TRANSFER_OWNERSHIP_COMPLETE",
|
||||
"android.app.action.USER_ADDED",
|
||||
"android.app.action.USER_REMOVED",
|
||||
"android.app.action.USER_STARTED",
|
||||
"android.app.action.USER_STOPPED",
|
||||
"android.app.action.USER_SWITCHED",
|
||||
"android.appwidget.action.APPWIDGET_DELETED",
|
||||
"android.appwidget.action.APPWIDGET_DISABLED",
|
||||
"android.appwidget.action.APPWIDGET_ENABLED",
|
||||
"android.appwidget.action.APPWIDGET_HOST_RESTORED",
|
||||
"android.appwidget.action.APPWIDGET_RESTORED",
|
||||
"android.appwidget.action.APPWIDGET_UPDATE",
|
||||
"android.appwidget.action.APPWIDGET_UPDATE_OPTIONS",
|
||||
"android.bluetooth.a2dp.profile.action.ACTIVE_DEVICE_CHANGED",
|
||||
"android.bluetooth.a2dp.profile.action.AVRCP_CONNECTION_STATE_CHANGED",
|
||||
"android.bluetooth.a2dp.profile.action.CODEC_CONFIG_CHANGED",
|
||||
"android.bluetooth.a2dp.profile.action.CONNECTION_STATE_CHANGED",
|
||||
"android.bluetooth.a2dp.profile.action.PLAYING_STATE_CHANGED",
|
||||
"android.bluetooth.adapter.action.CONNECTION_STATE_CHANGED",
|
||||
"android.bluetooth.adapter.action.DISCOVERY_FINISHED",
|
||||
"android.bluetooth.adapter.action.DISCOVERY_STARTED",
|
||||
"android.bluetooth.adapter.action.LOCAL_NAME_CHANGED",
|
||||
"android.bluetooth.adapter.action.SCAN_MODE_CHANGED",
|
||||
"android.bluetooth.adapter.action.STATE_CHANGED",
|
||||
"android.bluetooth.device.action.ACL_CONNECTED",
|
||||
"android.bluetooth.device.action.ACL_DISCONNECTED",
|
||||
"android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED",
|
||||
"android.bluetooth.device.action.ALIAS_CHANGED",
|
||||
"android.bluetooth.device.action.BATTERY_LEVEL_CHANGED",
|
||||
"android.bluetooth.device.action.BOND_STATE_CHANGED",
|
||||
"android.bluetooth.device.action.CLASS_CHANGED",
|
||||
"android.bluetooth.device.action.CONNECTION_ACCESS_CANCEL",
|
||||
"android.bluetooth.device.action.CONNECTION_ACCESS_REPLY",
|
||||
"android.bluetooth.device.action.CONNECTION_ACCESS_REQUEST",
|
||||
"android.bluetooth.device.action.FOUND",
|
||||
"android.bluetooth.device.action.MAS_INSTANCE",
|
||||
"android.bluetooth.device.action.NAME_CHANGED",
|
||||
"android.bluetooth.device.action.NAME_FAILED",
|
||||
"android.bluetooth.device.action.PAIRING_CANCEL",
|
||||
"android.bluetooth.device.action.PAIRING_REQUEST",
|
||||
"android.bluetooth.device.action.SDP_RECORD",
|
||||
"android.bluetooth.device.action.SILENCE_MODE_CHANGED",
|
||||
"android.bluetooth.device.action.UUID",
|
||||
"android.bluetooth.devicepicker.action.DEVICE_SELECTED",
|
||||
"android.bluetooth.devicepicker.action.LAUNCH",
|
||||
"android.bluetooth.headset.action.VENDOR_SPECIFIC_HEADSET_EVENT",
|
||||
"android.bluetooth.headset.profile.action.ACTIVE_DEVICE_CHANGED",
|
||||
"android.bluetooth.headset.profile.action.AUDIO_STATE_CHANGED",
|
||||
"android.bluetooth.headset.profile.action.CONNECTION_STATE_CHANGED",
|
||||
"android.bluetooth.hearingaid.profile.action.ACTIVE_DEVICE_CHANGED",
|
||||
"android.bluetooth.hearingaid.profile.action.CONNECTION_STATE_CHANGED",
|
||||
"android.bluetooth.hiddevice.profile.action.CONNECTION_STATE_CHANGED",
|
||||
"android.bluetooth.input.profile.action.CONNECTION_STATE_CHANGED",
|
||||
"android.bluetooth.input.profile.action.HANDSHAKE",
|
||||
"android.bluetooth.input.profile.action.IDLE_TIME_CHANGED",
|
||||
"android.bluetooth.input.profile.action.PROTOCOL_MODE_CHANGED",
|
||||
"android.bluetooth.input.profile.action.REPORT",
|
||||
"android.bluetooth.input.profile.action.VIRTUAL_UNPLUG_STATUS",
|
||||
"android.bluetooth.pan.profile.action.CONNECTION_STATE_CHANGED",
|
||||
"android.bluetooth.pbap.profile.action.CONNECTION_STATE_CHANGED",
|
||||
"android.content.pm.action.SESSION_COMMITTED",
|
||||
"android.content.pm.action.SESSION_UPDATED",
|
||||
"android.hardware.action.NEW_PICTURE",
|
||||
"android.hardware.action.NEW_VIDEO",
|
||||
"android.hardware.hdmi.action.OSD_MESSAGE",
|
||||
"android.hardware.input.action.QUERY_KEYBOARD_LAYOUTS",
|
||||
"android.hardware.usb.action.USB_ACCESSORY_ATTACHED",
|
||||
"android.hardware.usb.action.USB_ACCESSORY_DETACHED",
|
||||
"android.hardware.usb.action.USB_DEVICE_ATTACHED",
|
||||
"android.hardware.usb.action.USB_DEVICE_DETACHED",
|
||||
"android.intent.action.ACTION_IDLE_MAINTENANCE_END",
|
||||
"android.intent.action.ACTION_IDLE_MAINTENANCE_START",
|
||||
"android.intent.action.ACTION_POWER_CONNECTED",
|
||||
"android.intent.action.ACTION_POWER_DISCONNECTED",
|
||||
"android.intent.action.ACTION_PREFERRED_ACTIVITY_CHANGED",
|
||||
"android.intent.action.ACTION_SHUTDOWN",
|
||||
"android.intent.action.AIRPLANE_MODE",
|
||||
"android.intent.action.ALARM_CHANGED",
|
||||
"android.intent.action.APPLICATION_RESTRICTIONS_CHANGED",
|
||||
"android.intent.action.BATTERY_CHANGED",
|
||||
"android.intent.action.BATTERY_LOW",
|
||||
"android.intent.action.BATTERY_OKAY",
|
||||
"android.intent.action.BOOT_COMPLETED",
|
||||
"android.intent.action.CALL_DISCONNECT_CAUSE",
|
||||
"android.intent.action.CAMERA_BUTTON",
|
||||
"android.intent.action.CANCEL_ENABLE_ROLLBACK",
|
||||
"android.intent.action.CLEAR_DNS_CACHE",
|
||||
"android.intent.action.CLOSE_SYSTEM_DIALOGS",
|
||||
"android.intent.action.CONFIGURATION_CHANGED",
|
||||
"android.intent.action.CONTENT_CHANGED",
|
||||
"android.intent.action.DATA_SMS_RECEIVED",
|
||||
"android.intent.action.DATA_STALL_DETECTED",
|
||||
"android.intent.action.DATE_CHANGED",
|
||||
"android.intent.action.DEVICE_STORAGE_FULL",
|
||||
"android.intent.action.DEVICE_STORAGE_LOW",
|
||||
"android.intent.action.DEVICE_STORAGE_NOT_FULL",
|
||||
"android.intent.action.DEVICE_STORAGE_OK",
|
||||
"android.intent.action.DISTRACTING_PACKAGES_CHANGED",
|
||||
"android.intent.action.DOCK_EVENT",
|
||||
"android.intent.action.DOWNLOAD_COMPLETE",
|
||||
"android.intent.action.DOWNLOAD_NOTIFICATION_CLICKED",
|
||||
"android.intent.action.DREAMING_STARTED",
|
||||
"android.intent.action.DREAMING_STOPPED",
|
||||
"android.intent.action.DROPBOX_ENTRY_ADDED",
|
||||
"android.intent.action.DYNAMIC_SENSOR_CHANGED",
|
||||
"android.intent.action.EMERGENCY_CALLBACK_MODE_CHANGED",
|
||||
"android.intent.action.EMERGENCY_CALL_STATE_CHANGED",
|
||||
"android.intent.action.EXTERNAL_APPLICATIONS_AVAILABLE",
|
||||
"android.intent.action.EXTERNAL_APPLICATIONS_UNAVAILABLE",
|
||||
"android.intent.action.FACTORY_RESET",
|
||||
"android.intent.action.FETCH_VOICEMAIL",
|
||||
"android.intent.action.GTALK_CONNECTED",
|
||||
"android.intent.action.GTALK_DISCONNECTED",
|
||||
"android.intent.action.HEADSET_PLUG",
|
||||
"android.intent.action.HEADSET_PLUG",
|
||||
"android.intent.action.INPUT_METHOD_CHANGED",
|
||||
"android.intent.action.INTENT_FILTER_NEEDS_VERIFICATION",
|
||||
"android.intent.action.LOCALE_CHANGED",
|
||||
"android.intent.action.LOCKED_BOOT_COMPLETED",
|
||||
"android.intent.action.MANAGE_PACKAGE_STORAGE",
|
||||
"android.intent.action.MASTER_CLEAR_NOTIFICATION",
|
||||
"android.intent.action.MEDIA_BAD_REMOVAL",
|
||||
"android.intent.action.MEDIA_BUTTON",
|
||||
"android.intent.action.MEDIA_CHECKING",
|
||||
"android.intent.action.MEDIA_EJECT",
|
||||
"android.intent.action.MEDIA_MOUNTED",
|
||||
"android.intent.action.MEDIA_NOFS",
|
||||
"android.intent.action.MEDIA_REMOVED",
|
||||
"android.intent.action.MEDIA_SCANNER_FINISHED",
|
||||
"android.intent.action.MEDIA_SCANNER_SCAN_FILE",
|
||||
"android.intent.action.MEDIA_SCANNER_STARTED",
|
||||
"android.intent.action.MEDIA_SHARED",
|
||||
"android.intent.action.MEDIA_UNMOUNTABLE",
|
||||
"android.intent.action.MEDIA_UNMOUNTED",
|
||||
"android.intent.action.MY_PACKAGE_REPLACED",
|
||||
"android.intent.action.MY_PACKAGE_SUSPENDED",
|
||||
"android.intent.action.MY_PACKAGE_UNSUSPENDED",
|
||||
"android.intent.action.NEW_OUTGOING_CALL",
|
||||
"android.intent.action.NEW_VOICEMAIL",
|
||||
"android.intent.action.PACKAGES_SUSPENDED",
|
||||
"android.intent.action.PACKAGES_UNSUSPENDED",
|
||||
"android.intent.action.PACKAGE_ADDED",
|
||||
"android.intent.action.PACKAGE_CHANGED",
|
||||
"android.intent.action.PACKAGE_DATA_CLEARED",
|
||||
"android.intent.action.PACKAGE_ENABLE_ROLLBACK",
|
||||
"android.intent.action.PACKAGE_FIRST_LAUNCH",
|
||||
"android.intent.action.PACKAGE_FULLY_REMOVED",
|
||||
"android.intent.action.PACKAGE_INSTALL",
|
||||
"android.intent.action.PACKAGE_NEEDS_INTEGRITY_VERIFICATION",
|
||||
"android.intent.action.PACKAGE_NEEDS_VERIFICATION",
|
||||
"android.intent.action.PACKAGE_REMOVED",
|
||||
"android.intent.action.PACKAGE_REPLACED",
|
||||
"android.intent.action.PACKAGE_RESTARTED",
|
||||
"android.intent.action.PACKAGE_UNSUSPENDED_MANUALLY",
|
||||
"android.intent.action.PACKAGE_VERIFIED",
|
||||
"android.intent.action.PHONE_STATE",
|
||||
"android.intent.action.PROVIDER_CHANGED",
|
||||
"android.intent.action.PROXY_CHANGE",
|
||||
"android.intent.action.QUERY_PACKAGE_RESTART",
|
||||
"android.intent.action.REBOOT",
|
||||
"android.intent.action.ROLLBACK_COMMITTED",
|
||||
"android.intent.action.SCREEN_OFF",
|
||||
"android.intent.action.SCREEN_ON",
|
||||
"android.intent.action.SERVICE_STATE",
|
||||
"android.intent.action.SIM_STATE_CHANGED",
|
||||
"android.intent.action.SPLIT_CONFIGURATION_CHANGED",
|
||||
"android.intent.action.SUB_DEFAULT_CHANGED",
|
||||
"android.intent.action.TIMEZONE_CHANGED",
|
||||
"android.intent.action.TIME_SET",
|
||||
"android.intent.action.TIME_TICK",
|
||||
"android.intent.action.UID_REMOVED",
|
||||
"android.intent.action.UMS_CONNECTED",
|
||||
"android.intent.action.UMS_DISCONNECTED",
|
||||
"android.intent.action.USER_PRESENT",
|
||||
"android.intent.action.USER_UNLOCKED",
|
||||
"android.intent.action.WALLPAPER_CHANGED",
|
||||
"android.media.ACTION_SCO_AUDIO_STATE_UPDATED",
|
||||
"android.media.AUDIO_BECOMING_NOISY",
|
||||
"android.media.INTERNAL_RINGER_MODE_CHANGED_ACTION",
|
||||
"android.media.MASTER_MUTE_CHANGED_ACTION",
|
||||
"android.media.RINGER_MODE_CHANGED",
|
||||
"android.media.SCO_AUDIO_STATE_CHANGED",
|
||||
"android.media.STREAM_DEVICES_CHANGED_ACTION",
|
||||
"android.media.STREAM_MUTE_CHANGED_ACTION",
|
||||
"android.media.VIBRATE_SETTING_CHANGED",
|
||||
"android.media.VOLUME_CHANGED_ACTION",
|
||||
"android.media.action.CLOSE_AUDIO_EFFECT_CONTROL_SESSION",
|
||||
"android.media.action.HDMI_AUDIO_PLUG",
|
||||
"android.media.action.MICROPHONE_MUTE_CHANGED",
|
||||
"android.media.action.OPEN_AUDIO_EFFECT_CONTROL_SESSION",
|
||||
"android.media.action.SPEAKERPHONE_STATE_CHANGED",
|
||||
"android.media.tv.action.CHANNEL_BROWSABLE_REQUESTED",
|
||||
"android.media.tv.action.INITIALIZE_PROGRAMS",
|
||||
"android.media.tv.action.PREVIEW_PROGRAM_ADDED_TO_WATCH_NEXT",
|
||||
"android.media.tv.action.PREVIEW_PROGRAM_BROWSABLE_DISABLED",
|
||||
"android.media.tv.action.WATCH_NEXT_PROGRAM_BROWSABLE_DISABLED",
|
||||
"android.net.conn.BACKGROUND_DATA_SETTING_CHANGED",
|
||||
"android.net.conn.CAPTIVE_PORTAL_TEST_COMPLETED",
|
||||
"android.net.conn.CONNECTIVITY_CHANGE",
|
||||
"android.net.conn.DATA_ACTIVITY_CHANGE",
|
||||
"android.net.conn.INET_CONDITION_ACTION",
|
||||
"android.net.conn.RESTRICT_BACKGROUND_CHANGED",
|
||||
"android.net.conn.TETHER_STATE_CHANGED",
|
||||
"android.net.nsd.STATE_CHANGED",
|
||||
"android.net.scoring.SCORER_CHANGED",
|
||||
"android.net.scoring.SCORE_NETWORKS",
|
||||
"android.net.sip.action.SIP_CALL_OPTION_CHANGED",
|
||||
"android.net.sip.action.SIP_INCOMING_CALL",
|
||||
"android.net.sip.action.SIP_REMOVE_PROFILE",
|
||||
"android.net.sip.action.SIP_SERVICE_UP",
|
||||
"android.net.sip.action.START_SIP",
|
||||
"android.net.wifi.BATCHED_RESULTS",
|
||||
"android.net.wifi.NETWORK_IDS_CHANGED",
|
||||
"android.net.wifi.RSSI_CHANGED",
|
||||
"android.net.wifi.SCAN_RESULTS",
|
||||
"android.net.wifi.STATE_CHANGE",
|
||||
"android.net.wifi.WIFI_STATE_CHANGED",
|
||||
"android.net.wifi.action.WIFI_NETWORK_SUGGESTION_POST_CONNECTION",
|
||||
"android.net.wifi.action.WIFI_SCAN_AVAILABILITY_CHANGED",
|
||||
"android.net.wifi.aware.action.WIFI_AWARE_STATE_CHANGED",
|
||||
"android.net.wifi.p2p.CONNECTION_STATE_CHANGE",
|
||||
"android.net.wifi.p2p.DISCOVERY_STATE_CHANGE",
|
||||
"android.net.wifi.p2p.PEERS_CHANGED",
|
||||
"android.net.wifi.p2p.STATE_CHANGED",
|
||||
"android.net.wifi.p2p.THIS_DEVICE_CHANGED",
|
||||
"android.net.wifi.rtt.action.WIFI_RTT_STATE_CHANGED",
|
||||
"android.net.wifi.supplicant.CONNECTION_CHANGE",
|
||||
"android.net.wifi.supplicant.STATE_CHANGE",
|
||||
"android.nfc.action.ADAPTER_STATE_CHANGED",
|
||||
"android.nfc.action.PREFERRED_PAYMENT_CHANGED",
|
||||
"android.nfc.action.TRANSACTION_DETECTED",
|
||||
"android.os.action.ACTION_EFFECTS_SUPPRESSOR_CHANGED",
|
||||
"android.os.action.DEVICE_IDLE_MODE_CHANGED",
|
||||
"android.os.action.LIGHT_DEVICE_IDLE_MODE_CHANGED",
|
||||
"android.os.action.POWER_SAVE_MODE_CHANGED",
|
||||
"android.os.action.POWER_SAVE_MODE_CHANGED_INTERNAL",
|
||||
"android.os.action.POWER_SAVE_MODE_CHANGING",
|
||||
"android.os.action.POWER_SAVE_TEMP_WHITELIST_CHANGED",
|
||||
"android.os.action.POWER_SAVE_WHITELIST_CHANGED",
|
||||
"android.os.action.UPDATE_EMERGENCY_NUMBER_DB",
|
||||
"android.provider.Telephony.MMS_DOWNLOADED",
|
||||
"android.provider.Telephony.SECRET_CODE",
|
||||
"android.provider.Telephony.SIM_FULL",
|
||||
"android.provider.Telephony.SMS_CARRIER_PROVISION",
|
||||
"android.provider.Telephony.SMS_CB_RECEIVED",
|
||||
"android.provider.Telephony.SMS_DELIVER",
|
||||
"android.provider.Telephony.SMS_RECEIVED",
|
||||
"android.provider.Telephony.SMS_REJECTED",
|
||||
"android.provider.Telephony.SMS_SERVICE_CATEGORY_PROGRAM_DATA_RECEIVED",
|
||||
"android.provider.Telephony.WAP_PUSH_DELIVER",
|
||||
"android.provider.Telephony.WAP_PUSH_RECEIVED",
|
||||
"android.provider.action.DEFAULT_SMS_PACKAGE_CHANGED",
|
||||
"android.provider.action.EXTERNAL_PROVIDER_CHANGE",
|
||||
"android.provider.action.SMS_EMERGENCY_CB_RECEIVED",
|
||||
"android.provider.action.SMS_MMS_DB_CREATED",
|
||||
"android.provider.action.SMS_MMS_DB_LOST",
|
||||
"android.provider.action.SYNC_VOICEMAIL",
|
||||
"android.security.STORAGE_CHANGED",
|
||||
"android.security.action.KEYCHAIN_CHANGED",
|
||||
"android.security.action.KEY_ACCESS_CHANGED",
|
||||
"android.security.action.TRUST_STORE_CHANGED",
|
||||
"android.service.controls.action.ADD_CONTROL",
|
||||
"android.settings.ENABLE_MMS_DATA_REQUEST",
|
||||
"android.speech.tts.TTS_QUEUE_PROCESSING_COMPLETED",
|
||||
"android.speech.tts.engine.TTS_DATA_INSTALLED",
|
||||
"android.telephony.action.AREA_INFO_UPDATED",
|
||||
"android.telephony.action.DEFAULT_SMS_SUBSCRIPTION_CHANGED",
|
||||
"android.telephony.action.DEFAULT_SUBSCRIPTION_CHANGED",
|
||||
"android.telephony.action.PRIMARY_SUBSCRIPTION_LIST_CHANGED",
|
||||
"android.telephony.action.REFRESH_SUBSCRIPTION_PLANS",
|
||||
"android.telephony.action.SECRET_CODE",
|
||||
"android.telephony.action.SERVICE_PROVIDERS_UPDATED",
|
||||
"android.telephony.action.SIM_APPLICATION_STATE_CHANGED",
|
||||
"android.telephony.action.SIM_CARD_STATE_CHANGED",
|
||||
"android.telephony.action.SIM_SLOT_STATUS_CHANGED",
|
||||
"android.telephony.action.SUBSCRIPTION_CARRIER_IDENTITY_CHANGED",
|
||||
"android.telephony.action.SUBSCRIPTION_PLANS_CHANGED",
|
||||
"android.telephony.action.SUBSCRIPTION_SPECIFIC_CARRIER_IDENTITY_CHANGED",
|
||||
"android.telephony.euicc.action.NOTIFY_CARRIER_SETUP_INCOMPLETE",
|
||||
"android.telephony.euicc.action.OTA_STATUS_CHANGED",
|
||||
"android.telephony.ims.action.WFC_IMS_REGISTRATION_ERROR",
|
||||
"com.android.intent.action.DISMISS_KEYBOARD_SHORTCUTS",
|
||||
"com.android.intent.action.SHOW_KEYBOARD_SHORTCUTS",
|
||||
"com.android.internal.intent.action.ACTION_FORBIDDEN_NO_SERVICE_AUTHORIZATION",
|
||||
"com.android.internal.provider.action.VOICEMAIL_SMS_RECEIVED"
|
||||
};
|
||||
}
|
@ -1,404 +0,0 @@
|
||||
package com.jens.automation2;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.provider.CalendarContract;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.jens.automation2.receivers.CalendarReceiver;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ActivityManageTriggerCalendar extends Activity
|
||||
{
|
||||
CheckBox chkCalendarEventActive, chkCalendarAvailabilityBusy, chkCalendarAvailabilityFree, chkCalendarAvailabilityTentative, chkCalendarAvailabilityOutOfOffice, chkCalendarAvailabilityWorkingElsewhere, chkCalendarAllDayEvent, chkCalendarEvaluateAllDayEvent, chkCalendarEvaluateReoccurring, chkCalendarReoccurring;
|
||||
Spinner spinnerCalendarTitleDirection, spinnerCalendarLocationDirection, spinnerCalendarDescriptionDirection;
|
||||
EditText etCalendarTitle, etCalendarLocation, etCalendarDescription;
|
||||
LinearLayout llCalendarSelection;
|
||||
Button bSaveTriggerCalendar;
|
||||
List<CheckBox> checkboxesCalendars = new ArrayList<>();
|
||||
final static String separator = ",";
|
||||
TextView tvMissingCalendarHint;
|
||||
|
||||
private static String[] directions;
|
||||
ArrayAdapter<String> directionSpinnerAdapter;
|
||||
public static int requestCodePermissionReadCalendar = 815;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
setContentView(R.layout.activity_manage_trigger_calendar);
|
||||
|
||||
chkCalendarEventActive = (CheckBox) findViewById(R.id.chkCalendarEventActive);
|
||||
spinnerCalendarTitleDirection = (Spinner)findViewById(R.id.spinnerCalendarTitleDirection);
|
||||
spinnerCalendarLocationDirection = (Spinner)findViewById(R.id.spinnerCalendarLocationDirection);
|
||||
spinnerCalendarDescriptionDirection = (Spinner)findViewById(R.id.spinnerCalendarDescriptionDirection);
|
||||
chkCalendarAllDayEvent = (CheckBox)findViewById(R.id.chkCalendarAllDayEvent);
|
||||
chkCalendarAvailabilityBusy = (CheckBox)findViewById(R.id.chkCalendarAvailabilityBusy);
|
||||
chkCalendarAvailabilityFree = (CheckBox)findViewById(R.id.chkCalendarAvailabilityFree);
|
||||
chkCalendarAvailabilityTentative = (CheckBox)findViewById(R.id.chkCalendarAvailabilityTentative);
|
||||
chkCalendarAvailabilityOutOfOffice = (CheckBox)findViewById(R.id.chkCalendarAvailabilityOutOfOffice);
|
||||
chkCalendarAvailabilityWorkingElsewhere = (CheckBox)findViewById(R.id.chkCalendarAvailabilityWorkingElsewhere);
|
||||
chkCalendarEvaluateAllDayEvent = (CheckBox)findViewById(R.id.chkCalendarEvaluateAllDayEvent);
|
||||
chkCalendarEvaluateReoccurring = (CheckBox)findViewById(R.id.chkCalendarEvaluateReoccurring);
|
||||
chkCalendarReoccurring = (CheckBox)findViewById(R.id.chkCalendarReoccurring);
|
||||
|
||||
tvMissingCalendarHint = (TextView) findViewById(R.id.tvMissingCalendarHint);
|
||||
|
||||
llCalendarSelection = (LinearLayout)findViewById(R.id.llCalendarSelection);
|
||||
|
||||
etCalendarTitle = (EditText)findViewById(R.id.etCalendarTitle);
|
||||
etCalendarLocation = (EditText)findViewById(R.id.etCalendarLocation);
|
||||
etCalendarDescription = (EditText)findViewById(R.id.etCalendarDescription);
|
||||
|
||||
bSaveTriggerCalendar = (Button)findViewById(R.id.bSaveTriggerCalendar);
|
||||
|
||||
directions = new String[] {
|
||||
getResources().getString(R.string.directionStringEquals),
|
||||
getResources().getString(R.string.directionStringContains),
|
||||
getResources().getString(R.string.directionStringDoesNotContain),
|
||||
getResources().getString(R.string.directionStringStartsWith),
|
||||
getResources().getString(R.string.directionStringEndsWith),
|
||||
getResources().getString(R.string.directionStringNotEquals)
|
||||
};
|
||||
directionSpinnerAdapter = new ArrayAdapter<>(this, R.layout.text_view_for_poi_listview_mediumtextsize, ActivityManageTriggerCalendar.directions);
|
||||
spinnerCalendarTitleDirection.setAdapter(directionSpinnerAdapter);
|
||||
spinnerCalendarLocationDirection.setAdapter(directionSpinnerAdapter);
|
||||
spinnerCalendarDescriptionDirection.setAdapter(directionSpinnerAdapter);
|
||||
directionSpinnerAdapter.notifyDataSetChanged();
|
||||
|
||||
chkCalendarEvaluateAllDayEvent.setChecked(false);
|
||||
chkCalendarAllDayEvent.setEnabled(false);
|
||||
chkCalendarEvaluateAllDayEvent.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
|
||||
{
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked)
|
||||
{
|
||||
chkCalendarAllDayEvent.setEnabled(checked);
|
||||
}
|
||||
});
|
||||
|
||||
chkCalendarEvaluateReoccurring.setChecked(false);
|
||||
chkCalendarReoccurring.setEnabled(false);
|
||||
chkCalendarEvaluateReoccurring.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
|
||||
{
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked)
|
||||
{
|
||||
chkCalendarReoccurring.setEnabled(checked);
|
||||
}
|
||||
});
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
||||
{
|
||||
if(ActivityPermissions.havePermission(Manifest.permission.READ_CALENDAR, ActivityManageTriggerCalendar.this) || ActivityPermissions.havePermission(Manifest.permission.WRITE_CALENDAR, ActivityManageTriggerCalendar.this))
|
||||
populateCalenderCheckboxes();
|
||||
else
|
||||
{
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(ActivityManageTriggerCalendar.this);
|
||||
builder.setTitle(getResources().getString(R.string.info));
|
||||
builder.setMessage(getResources().getString(R.string.permissionCalendarRequired));
|
||||
builder.setNegativeButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i)
|
||||
{
|
||||
ActivityManageTriggerCalendar.this.finish();
|
||||
}
|
||||
});
|
||||
builder.setPositiveButton(getResources().getString(R.string.ok), new DialogInterface.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i)
|
||||
{
|
||||
requestPermissions(new String[]{ Manifest.permission.READ_CALENDAR } , requestCodePermissionReadCalendar);
|
||||
}
|
||||
});
|
||||
builder.show();
|
||||
}
|
||||
}
|
||||
else
|
||||
populateCalenderCheckboxes();
|
||||
|
||||
chkCalendarEventActive.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
|
||||
{
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked)
|
||||
{
|
||||
if(checked)
|
||||
chkCalendarEventActive.setText(R.string.eventIsCurrentlyHappening);
|
||||
else
|
||||
chkCalendarEventActive.setText(R.string.eventIsCurrentlyNotHappening);
|
||||
}
|
||||
});
|
||||
|
||||
chkCalendarAllDayEvent.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
|
||||
{
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked)
|
||||
{
|
||||
if(checked)
|
||||
chkCalendarAllDayEvent.setText(getResources().getString(R.string.allDayEventTrue));
|
||||
else
|
||||
chkCalendarAllDayEvent.setText(getResources().getString(R.string.allDayEventFalse));
|
||||
}
|
||||
});
|
||||
|
||||
chkCalendarReoccurring.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
|
||||
{
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked)
|
||||
{
|
||||
if(checked)
|
||||
chkCalendarReoccurring.setText(R.string.reoccurringTrue);
|
||||
else
|
||||
chkCalendarReoccurring.setText(R.string.reoccurringFalse);
|
||||
}
|
||||
});
|
||||
|
||||
bSaveTriggerCalendar.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View view)
|
||||
{
|
||||
String titleDir = Trigger.getMatchCode(spinnerCalendarTitleDirection.getSelectedItem().toString());
|
||||
String title = etCalendarTitle.getText().toString();
|
||||
String descriptionDir = Trigger.getMatchCode(spinnerCalendarDescriptionDirection.getSelectedItem().toString());
|
||||
String description = etCalendarDescription.getText().toString();
|
||||
String locationDir = Trigger.getMatchCode(spinnerCalendarLocationDirection.getSelectedItem().toString());
|
||||
String location = etCalendarLocation.getText().toString();
|
||||
|
||||
List<String> availabilityList = new ArrayList<>();
|
||||
if(chkCalendarAvailabilityBusy.isChecked())
|
||||
availabilityList.add(String.valueOf(CalendarContract.Events.AVAILABILITY_BUSY));
|
||||
|
||||
if(chkCalendarAvailabilityFree.isChecked())
|
||||
availabilityList.add(String.valueOf(CalendarContract.Events.AVAILABILITY_FREE));
|
||||
|
||||
if(chkCalendarAvailabilityTentative.isChecked())
|
||||
availabilityList.add(String.valueOf(CalendarContract.Events.AVAILABILITY_TENTATIVE));
|
||||
|
||||
if(chkCalendarAvailabilityOutOfOffice.isChecked())
|
||||
availabilityList.add(String.valueOf(CalendarReceiver.AVAILABILITY_OUT_OF_OFFICE));
|
||||
|
||||
if(chkCalendarAvailabilityWorkingElsewhere.isChecked())
|
||||
availabilityList.add(String.valueOf(CalendarReceiver.AVAILABILITY_WORKING_ELSEWHERE));
|
||||
|
||||
List<CalendarReceiver.AndroidCalendar> selectedCalendarsList = new ArrayList<>();
|
||||
for(CheckBox calCheckbox : checkboxesCalendars)
|
||||
{
|
||||
if(calCheckbox.isChecked())
|
||||
selectedCalendarsList.add((CalendarReceiver.AndroidCalendar) calCheckbox.getTag());
|
||||
}
|
||||
List<String> selectedCalendarsIdArray = new ArrayList<>();
|
||||
for(CalendarReceiver.AndroidCalendar cal : selectedCalendarsList)
|
||||
selectedCalendarsIdArray.add(String.valueOf(cal.calendarId));
|
||||
|
||||
String returnString =
|
||||
titleDir + Trigger.triggerParameter2Split + title + Trigger.triggerParameter2Split +
|
||||
descriptionDir + Trigger.triggerParameter2Split + description + Trigger.triggerParameter2Split +
|
||||
locationDir + Trigger.triggerParameter2Split + location + Trigger.triggerParameter2Split +
|
||||
String.valueOf(chkCalendarEvaluateAllDayEvent.isChecked()) + Trigger.triggerParameter2Split +
|
||||
String.valueOf(chkCalendarAllDayEvent.isChecked()) + Trigger.triggerParameter2Split +
|
||||
String.valueOf(chkCalendarEvaluateReoccurring.isChecked()) + Trigger.triggerParameter2Split +
|
||||
String.valueOf(chkCalendarReoccurring.isChecked()) + Trigger.triggerParameter2Split +
|
||||
Miscellaneous.explode(separator, availabilityList.toArray(new String[availabilityList.size()])) + Trigger.triggerParameter2Split +
|
||||
Miscellaneous.explode(separator, selectedCalendarsIdArray.toArray(new String[selectedCalendarsIdArray.size()]));
|
||||
|
||||
Intent data = new Intent();
|
||||
data.putExtra(ActivityManageRule.intentNameTriggerParameter1, chkCalendarEventActive.isChecked());
|
||||
data.putExtra(ActivityManageRule.intentNameTriggerParameter2, returnString);
|
||||
ActivityManageTriggerCalendar.this.setResult(RESULT_OK, data);
|
||||
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
Intent inputIntent = getIntent();
|
||||
if(inputIntent.hasExtra(ActivityManageRule.intentNameTriggerParameter1))
|
||||
loadValuesIntoGui(inputIntent);
|
||||
}
|
||||
|
||||
private void populateCalenderCheckboxes()
|
||||
{
|
||||
List<CalendarReceiver.AndroidCalendar> calList = CalendarReceiver.readCalendars(ActivityManageTriggerCalendar.this);
|
||||
|
||||
if(calList != null)
|
||||
{
|
||||
if(calList.size() > 0)
|
||||
{
|
||||
for (CalendarReceiver.AndroidCalendar cal : calList)
|
||||
{
|
||||
CheckBox oneCalCheckbox = new CheckBox(ActivityManageTriggerCalendar.this);
|
||||
oneCalCheckbox.setText(cal.toString());
|
||||
oneCalCheckbox.setTag(cal);
|
||||
llCalendarSelection.addView(oneCalCheckbox);
|
||||
checkboxesCalendars.add(oneCalCheckbox);
|
||||
}
|
||||
}
|
||||
else
|
||||
Miscellaneous.messageBox(getResources().getString(R.string.warning), getResources().getString(R.string.noCalendarsOnYourDevice), ActivityManageTriggerCalendar.this).show();
|
||||
}
|
||||
else
|
||||
Miscellaneous.messageBox(getResources().getString(R.string.warning), getResources().getString(R.string.errorReadingCalendars), ActivityManageTriggerCalendar.this).show();
|
||||
}
|
||||
|
||||
void loadValuesIntoGui(Intent data)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (data.hasExtra(ActivityManageRule.intentNameTriggerParameter1))
|
||||
chkCalendarEventActive.setChecked(data.getBooleanExtra(ActivityManageRule.intentNameTriggerParameter1, true));
|
||||
|
||||
if (data.hasExtra(ActivityManageRule.intentNameTriggerParameter2))
|
||||
{
|
||||
String input[] = data.getStringExtra(ActivityManageRule.intentNameTriggerParameter2).split(Trigger.triggerParameter2Split, -1);
|
||||
/*
|
||||
0 = titleDir
|
||||
1 = title
|
||||
2 = descriptionDir
|
||||
3 = description
|
||||
4 = locationDir
|
||||
5 = location
|
||||
6 = evaluate all day event
|
||||
7 = all day event
|
||||
8 = evaluate reoccurring
|
||||
9 = reoccurring
|
||||
10 = availability list
|
||||
11 = calendars list
|
||||
*/
|
||||
|
||||
for (int i = 0; i < directions.length; i++)
|
||||
{
|
||||
if (Trigger.getMatchCode(directions[i]).equalsIgnoreCase(input[0]))
|
||||
spinnerCalendarTitleDirection.setSelection(i);
|
||||
|
||||
if (Trigger.getMatchCode(directions[i]).equalsIgnoreCase(input[2]))
|
||||
spinnerCalendarDescriptionDirection.setSelection(i);
|
||||
|
||||
if (Trigger.getMatchCode(directions[i]).equalsIgnoreCase(input[4]))
|
||||
spinnerCalendarLocationDirection.setSelection(i);
|
||||
}
|
||||
|
||||
etCalendarTitle.setText(input[1]);
|
||||
etCalendarDescription.setText(input[3]);
|
||||
etCalendarLocation.setText(input[5]);
|
||||
|
||||
chkCalendarEvaluateAllDayEvent.setChecked(Boolean.parseBoolean(input[6]));
|
||||
chkCalendarAllDayEvent.setChecked(Boolean.parseBoolean(input[7]));
|
||||
|
||||
chkCalendarEvaluateReoccurring.setChecked(Boolean.parseBoolean(input[8]));
|
||||
chkCalendarReoccurring.setChecked(Boolean.parseBoolean(input[9]));
|
||||
|
||||
String[] availabilities = null;
|
||||
if (!StringUtils.isEmpty(input[10]))
|
||||
availabilities = input[10].split(separator);
|
||||
|
||||
if (availabilities != null)
|
||||
{
|
||||
for (String avail : availabilities)
|
||||
{
|
||||
if (Integer.parseInt(avail) == CalendarContract.Events.AVAILABILITY_BUSY)
|
||||
chkCalendarAvailabilityBusy.setChecked(true);
|
||||
else if (Integer.parseInt(avail) == CalendarContract.Events.AVAILABILITY_FREE)
|
||||
chkCalendarAvailabilityFree.setChecked(true);
|
||||
else if (Integer.parseInt(avail) == CalendarContract.Events.AVAILABILITY_TENTATIVE)
|
||||
chkCalendarAvailabilityTentative.setChecked(true);
|
||||
else if (Integer.parseInt(avail) == CalendarReceiver.AVAILABILITY_OUT_OF_OFFICE)
|
||||
chkCalendarAvailabilityOutOfOffice.setChecked(true);
|
||||
else if (Integer.parseInt(avail) == CalendarReceiver.AVAILABILITY_WORKING_ELSEWHERE)
|
||||
chkCalendarAvailabilityWorkingElsewhere.setChecked(true);
|
||||
}
|
||||
}
|
||||
|
||||
String[] calendars = null;
|
||||
if (!StringUtils.isEmpty(input[11]))
|
||||
calendars = input[11].split(separator);
|
||||
|
||||
if (calendars != null)
|
||||
{
|
||||
List<String> usedCalendarIDs = new ArrayList<>();
|
||||
List<String> unusedCalendarIDs = new ArrayList<>();
|
||||
for (CheckBox checkbox : checkboxesCalendars)
|
||||
{
|
||||
int id = ((CalendarReceiver.AndroidCalendar) checkbox.getTag()).calendarId;
|
||||
for (String calId : calendars)
|
||||
{
|
||||
if (calId.equals(String.valueOf(id)))
|
||||
{
|
||||
usedCalendarIDs.add(String.valueOf(id));
|
||||
checkbox.setChecked(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (String calId : calendars)
|
||||
{
|
||||
if (!Miscellaneous.arraySearch((ArrayList<String>) usedCalendarIDs, calId, false, true))
|
||||
unusedCalendarIDs.add(calId);
|
||||
}
|
||||
if (unusedCalendarIDs.size() > 0)
|
||||
{
|
||||
/*
|
||||
A calendar has been configured that has been deleted since. We cannot resolve it.
|
||||
It will be removed with the next save, but we should inform this user
|
||||
of these circumstances.
|
||||
*/
|
||||
|
||||
tvMissingCalendarHint.setText(String.format(getResources().getString(R.string.calendarsMissingHint), Miscellaneous.explode(", ", (ArrayList<String>) unusedCalendarIDs)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Miscellaneous.logEvent("e", "ActivityManagerTriggerCalender", "Error loading values into GUI: " + Log.getStackTraceString(e), 1);
|
||||
Toast.makeText(ActivityManageTriggerCalendar.this, getResources().getString(R.string.errorLoadingValues), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults)
|
||||
{
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
|
||||
if(requestCode == requestCodePermissionReadCalendar)
|
||||
{
|
||||
if(
|
||||
permissions[0].equals(Manifest.permission.READ_CALENDAR)
|
||||
||
|
||||
permissions[0].equals(Manifest.permission.WRITE_CALENDAR)
|
||||
)
|
||||
{
|
||||
if(grantResults[0] == PackageManager.PERMISSION_GRANTED)
|
||||
populateCalenderCheckboxes();
|
||||
else
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
package com.jens.automation2;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.RadioButton;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.jens.automation2.ActivityManageRule;
|
||||
import com.jens.automation2.Miscellaneous;
|
||||
import com.jens.automation2.R;
|
||||
import com.jens.automation2.Trigger;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class ActivityManageTriggerCharging extends Activity
|
||||
{
|
||||
RadioButton rbChargingOn, rbChargingOff, rbChargingTypeAny, rbChargingTypeAc, rbChargingTypeUsb, rbChargingTypeWireless;
|
||||
Button bTriggerChargingSave;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
setContentView(R.layout.activity_manage_trigger_charging);
|
||||
|
||||
rbChargingOn = (RadioButton) findViewById(R.id.rbChargingOn);
|
||||
rbChargingOff = (RadioButton) findViewById(R.id.rbChargingOff);
|
||||
rbChargingTypeAny = (RadioButton) findViewById(R.id.rbChargingTypeAny);
|
||||
rbChargingTypeAc = (RadioButton) findViewById(R.id.rbChargingTypeAc);
|
||||
rbChargingTypeUsb = (RadioButton) findViewById(R.id.rbChargingTypeUsb);
|
||||
rbChargingTypeWireless = (RadioButton) findViewById(R.id.rbChargingTypeWireless);
|
||||
|
||||
bTriggerChargingSave = (Button) findViewById(R.id.bTriggerChargingSave);
|
||||
|
||||
Intent input = getIntent();
|
||||
if(input.hasExtra(ActivityManageRule.intentNameTriggerParameter1))
|
||||
{
|
||||
|
||||
rbChargingOn.setChecked(input.getBooleanExtra(ActivityManageRule.intentNameTriggerParameter1, true));
|
||||
rbChargingOff.setChecked(!input.getBooleanExtra(ActivityManageRule.intentNameTriggerParameter1, false));
|
||||
|
||||
if(input.hasExtra(ActivityManageRule.intentNameTriggerParameter2))
|
||||
{
|
||||
|
||||
String[] params2 = input.getStringExtra(ActivityManageRule.intentNameTriggerParameter2).split(Trigger.triggerParameter2Split);
|
||||
int chargingType = Integer.parseInt(params2[0]);
|
||||
|
||||
rbChargingTypeAny.setChecked(chargingType == 0);
|
||||
rbChargingTypeAc.setChecked(chargingType == BatteryManager.BATTERY_PLUGGED_AC);
|
||||
rbChargingTypeUsb.setChecked(chargingType == BatteryManager.BATTERY_PLUGGED_USB);
|
||||
rbChargingTypeWireless.setChecked(chargingType == BatteryManager.BATTERY_PLUGGED_WIRELESS);
|
||||
}
|
||||
}
|
||||
|
||||
bTriggerChargingSave.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View view)
|
||||
{
|
||||
Intent response = new Intent();
|
||||
response.putExtra(ActivityManageRule.intentNameTriggerParameter1, rbChargingOn.isChecked());
|
||||
|
||||
String param2 = "";
|
||||
|
||||
if(rbChargingTypeAny.isChecked())
|
||||
param2 = "0";
|
||||
else if(rbChargingTypeAc.isChecked())
|
||||
param2 = String.valueOf(BatteryManager.BATTERY_PLUGGED_AC);
|
||||
else if(rbChargingTypeUsb.isChecked())
|
||||
param2 = String.valueOf(BatteryManager.BATTERY_PLUGGED_USB);
|
||||
else if(rbChargingTypeWireless.isChecked())
|
||||
param2 = String.valueOf(BatteryManager.BATTERY_PLUGGED_WIRELESS);
|
||||
|
||||
response.putExtra(ActivityManageRule.intentNameTriggerParameter2, param2);
|
||||
|
||||
setResult(RESULT_OK, response);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
package com.jens.automation2;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class ActivityManageTriggerCheckVariable extends Activity
|
||||
{
|
||||
EditText etVariableKeyTrigger, etVariableValueTrigger;
|
||||
Button bTriggerVariableSave;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
setContentView(R.layout.activity_manage_trigger_check_variable);
|
||||
|
||||
etVariableKeyTrigger = (EditText) findViewById(R.id.etVariableKeyTrigger);
|
||||
etVariableValueTrigger = (EditText) findViewById(R.id.etVariableValueTrigger);
|
||||
bTriggerVariableSave = (Button) findViewById(R.id.bTriggerVariableSave);
|
||||
|
||||
Intent input = getIntent();
|
||||
if(input.hasExtra(ActivityManageRule.intentNameTriggerParameter2))
|
||||
{
|
||||
String[] conditions = input.getStringExtra(ActivityManageRule.intentNameTriggerParameter2).split(Trigger.triggerParameter2Split);
|
||||
etVariableKeyTrigger.setText(conditions[0]);
|
||||
if(conditions.length > 1)
|
||||
etVariableValueTrigger.setText(conditions[1]);
|
||||
}
|
||||
|
||||
bTriggerVariableSave.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View view)
|
||||
{
|
||||
Intent response = new Intent();
|
||||
// response.putExtra(ActivityManageRule.intentNameTriggerParameter1, rbTetheringOn.isChecked());
|
||||
|
||||
if(StringUtils.isEmpty(etVariableValueTrigger.getText().toString()))
|
||||
response.putExtra(ActivityManageRule.intentNameTriggerParameter2, etVariableKeyTrigger.getText().toString());
|
||||
else
|
||||
response.putExtra(ActivityManageRule.intentNameTriggerParameter2, etVariableKeyTrigger.getText().toString() + Trigger.triggerParameter2Split + etVariableValueTrigger.getText().toString());
|
||||
|
||||
setResult(RESULT_OK, response);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -104,7 +104,6 @@ public class ActivityManageTriggerDeviceOrientation extends Activity
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
setContentView(R.layout.activity_manage_trigger_device_orientation);
|
||||
|
||||
currentAzimuth = (TextView) findViewById(R.id.tvCurrentAzimuth);
|
||||
|
@ -39,7 +39,6 @@ public class ActivityManageTriggerNfc extends Activity
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
setContentView(R.layout.activity_manage_trigger_nfc);
|
||||
|
||||
etNewNfcIdValue = (EditText)findViewById(R.id.etNewNfcIdValue);
|
||||
|
@ -258,7 +258,6 @@ public class ActivityManageTriggerNotification extends Activity
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
setContentView(R.layout.activity_manage_trigger_notification);
|
||||
|
||||
etNotificationTitle = (EditText)findViewById(R.id.etNotificationTitle);
|
||||
@ -273,7 +272,6 @@ public class ActivityManageTriggerNotification extends Activity
|
||||
directions = new String[] {
|
||||
getResources().getString(R.string.directionStringEquals),
|
||||
getResources().getString(R.string.directionStringContains),
|
||||
getResources().getString(R.string.directionStringDoesNotContain),
|
||||
getResources().getString(R.string.directionStringStartsWith),
|
||||
getResources().getString(R.string.directionStringEndsWith),
|
||||
getResources().getString(R.string.directionStringNotEquals)
|
||||
@ -323,14 +321,23 @@ public class ActivityManageTriggerNotification extends Activity
|
||||
String textDir = Trigger.getMatchCode(spinnerTextDirection.getSelectedItem().toString());
|
||||
String text = etNotificationText.getText().toString();
|
||||
|
||||
Intent data = new Intent();
|
||||
data.putExtra(intentNameNotificationDirection, chkNotificationDirection.isChecked());
|
||||
data.putExtra(intentNameNotificationApp, app);
|
||||
data.putExtra(intentNameNotificationTitleDir, titleDir);
|
||||
data.putExtra(intentNameNotificationTitle, title);
|
||||
data.putExtra(intentNameNotificationTextDir, textDir);
|
||||
data.putExtra(intentNameNotificationText, text);
|
||||
ActivityManageTriggerNotification.this.setResult(RESULT_OK, data);
|
||||
if(edit)
|
||||
{
|
||||
editedNotificationTrigger.setTriggerParameter(chkNotificationDirection.isChecked());
|
||||
editedNotificationTrigger.setTriggerParameter2(app + triggerParameter2Split + titleDir + triggerParameter2Split + title + triggerParameter2Split + textDir + triggerParameter2Split + text);
|
||||
ActivityManageTriggerNotification.this.setResult(RESULT_OK);
|
||||
}
|
||||
else
|
||||
{
|
||||
Intent data = new Intent();
|
||||
data.putExtra(intentNameNotificationDirection, chkNotificationDirection.isChecked());
|
||||
data.putExtra(intentNameNotificationApp, app);
|
||||
data.putExtra(intentNameNotificationTitleDir, titleDir);
|
||||
data.putExtra(intentNameNotificationTitle, title);
|
||||
data.putExtra(intentNameNotificationTextDir, textDir);
|
||||
data.putExtra(intentNameNotificationText, text);
|
||||
ActivityManageTriggerNotification.this.setResult(RESULT_OK, data);
|
||||
}
|
||||
|
||||
finish();
|
||||
}
|
||||
|
@ -35,7 +35,6 @@ public class ActivityManageTriggerPhoneCall extends Activity
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
setContentView(R.layout.activity_manage_trigger_phone_call);
|
||||
|
||||
etTriggerPhoneCallPhoneNumber = (EditText)findViewById(R.id.etTriggerPhoneCallPhoneNumber);
|
||||
@ -87,8 +86,8 @@ public class ActivityManageTriggerPhoneCall extends Activity
|
||||
else
|
||||
{
|
||||
Intent data = new Intent();
|
||||
data.putExtra(ActivityManageRule.intentNameTriggerParameter1, false);
|
||||
data.putExtra(ActivityManageRule.intentNameTriggerParameter2, tp2Result);
|
||||
data.putExtra("triggerParameter", false);
|
||||
data.putExtra("triggerParameter2", tp2Result);
|
||||
ActivityManageTriggerPhoneCall.this.setResult(RESULT_OK, data);
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,6 @@ public class ActivityManageTriggerProfile extends Activity
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
setContentView(R.layout.activity_manage_trigger_profile);
|
||||
|
||||
bSaveTriggerProfile = (Button)findViewById(R.id.bSaveTriggerProfile);
|
||||
|
@ -1,73 +0,0 @@
|
||||
package com.jens.automation2;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.RadioButton;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.jens.automation2.Trigger.subSystemStates;
|
||||
|
||||
public class ActivityManageTriggerSubSystemState extends Activity
|
||||
{
|
||||
RadioButton rbSubSystemStateWifi, rbSubSystemStateBluetooth;
|
||||
RadioButton rbSubSystemStateEnabled, rbSubSystemStateDisabled;
|
||||
Button bSubSystemStateSave;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
setContentView(R.layout.activity_manage_trigger_subsystemstate);
|
||||
|
||||
rbSubSystemStateWifi = (RadioButton)findViewById(R.id.rbSubSystemStateWifi);
|
||||
rbSubSystemStateBluetooth = (RadioButton)findViewById(R.id.rbSubSystemStateBluetooth);
|
||||
rbSubSystemStateEnabled = (RadioButton)findViewById(R.id.rbSubSystemStateEnabled);
|
||||
rbSubSystemStateDisabled = (RadioButton)findViewById(R.id.rbSubSystemStateDisabled);
|
||||
bSubSystemStateSave = (Button)findViewById(R.id.bSubSystemStateSave);
|
||||
|
||||
if(getIntent().hasExtra(ActivityManageRule.intentNameTriggerParameter1) && getIntent().hasExtra(ActivityManageRule.intentNameTriggerParameter2))
|
||||
{
|
||||
subSystemStates desiredState = subSystemStates.valueOf(getIntent().getStringExtra(ActivityManageRule.intentNameTriggerParameter2));
|
||||
|
||||
switch(desiredState)
|
||||
{
|
||||
case wifi:
|
||||
rbSubSystemStateWifi.setChecked(true);
|
||||
break;
|
||||
case bluetooth:
|
||||
rbSubSystemStateBluetooth.setChecked(true);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
if(getIntent().getBooleanExtra(ActivityManageRule.intentNameTriggerParameter1, true))
|
||||
rbSubSystemStateEnabled.setChecked(true);
|
||||
else
|
||||
rbSubSystemStateDisabled.setChecked(true);
|
||||
}
|
||||
|
||||
bSubSystemStateSave.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View view)
|
||||
{
|
||||
Intent data = new Intent();
|
||||
|
||||
data.putExtra(ActivityManageRule.intentNameTriggerParameter1, rbSubSystemStateEnabled.isChecked());
|
||||
|
||||
if(rbSubSystemStateWifi.isChecked())
|
||||
data.putExtra(ActivityManageRule.intentNameTriggerParameter2, subSystemStates.wifi.name());
|
||||
else if(rbSubSystemStateBluetooth.isChecked())
|
||||
data.putExtra(ActivityManageRule.intentNameTriggerParameter2, subSystemStates.bluetooth.name());
|
||||
|
||||
ActivityManageTriggerSubSystemState.this.setResult(RESULT_OK, data);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -1,102 +0,0 @@
|
||||
package com.jens.automation2;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.RadioButton;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class ActivityManageTriggerTethering extends Activity
|
||||
{
|
||||
RadioButton rbTetheringOn, rbTetheringOff, rbTetheringTypeAny, rbTetheringTypeWifi, rbTetheringTypeBluetooth, rbTetheringTypeUsb, rbTetheringTypeCable;
|
||||
Button bTriggerTetheringSave;
|
||||
|
||||
public final static String tetheringTypeAny = "tetheringTypeAny";
|
||||
public final static String tetheringTypeWifi = "tetheringTypeWifi";
|
||||
public final static String tetheringTypeBluetooth = "tetheringTypeBluetooth";
|
||||
public final static String tetheringTypeUsb = "tetheringTypeUsb";
|
||||
public final static String tetheringTypeCable = "tetheringTypeCable";
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
setContentView(R.layout.activity_manage_trigger_tethering);
|
||||
|
||||
rbTetheringOn = (RadioButton) findViewById(R.id.rbTetheringOn);
|
||||
rbTetheringOff = (RadioButton)findViewById(R.id.rbTetheringOff);
|
||||
rbTetheringTypeAny = (RadioButton) findViewById(R.id.rbTetheringTypeAny);
|
||||
rbTetheringTypeWifi = (RadioButton) findViewById(R.id.rbTetheringTypeWifi);
|
||||
rbTetheringTypeBluetooth = (RadioButton) findViewById(R.id.rbTetheringTypeBluetooth);
|
||||
rbTetheringTypeUsb = (RadioButton) findViewById(R.id.rbTetheringTypeUsb);
|
||||
rbTetheringTypeCable = (RadioButton) findViewById(R.id.rbTetheringTypeCable);
|
||||
bTriggerTetheringSave = (Button) findViewById(R.id.bTriggerTetheringSave);
|
||||
|
||||
Intent input = getIntent();
|
||||
if(input.hasExtra(ActivityManageRule.intentNameTriggerParameter1))
|
||||
{
|
||||
rbTetheringOn.setChecked(input.getBooleanExtra(ActivityManageRule.intentNameTriggerParameter1, true));
|
||||
rbTetheringOff.setChecked(!input.getBooleanExtra(ActivityManageRule.intentNameTriggerParameter1, false));
|
||||
}
|
||||
|
||||
if(input.hasExtra(ActivityManageRule.intentNameTriggerParameter2))
|
||||
{
|
||||
String type = input.getStringExtra(ActivityManageRule.intentNameTriggerParameter2);
|
||||
|
||||
if(!StringUtils.isEmpty(type))
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case tetheringTypeAny:
|
||||
rbTetheringTypeAny.setChecked(true);
|
||||
break;
|
||||
case tetheringTypeWifi:
|
||||
rbTetheringTypeWifi.setChecked(true);
|
||||
break;
|
||||
case tetheringTypeBluetooth:
|
||||
rbTetheringTypeBluetooth.setChecked(true);
|
||||
break;
|
||||
case tetheringTypeUsb:
|
||||
rbTetheringTypeUsb.setChecked(true);
|
||||
break;
|
||||
case tetheringTypeCable:
|
||||
rbTetheringTypeCable.setChecked(true);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
rbTetheringTypeAny.setChecked(true);
|
||||
|
||||
bTriggerTetheringSave.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View view)
|
||||
{
|
||||
Intent response = new Intent();
|
||||
response.putExtra(ActivityManageRule.intentNameTriggerParameter1, rbTetheringOn.isChecked());
|
||||
|
||||
if(rbTetheringTypeAny.isChecked())
|
||||
response.putExtra(ActivityManageRule.intentNameTriggerParameter2, tetheringTypeAny);
|
||||
else if(rbTetheringTypeWifi.isChecked())
|
||||
response.putExtra(ActivityManageRule.intentNameTriggerParameter2, tetheringTypeWifi);
|
||||
else if(rbTetheringTypeBluetooth.isChecked())
|
||||
response.putExtra(ActivityManageRule.intentNameTriggerParameter2, tetheringTypeBluetooth);
|
||||
else if(rbTetheringTypeUsb.isChecked())
|
||||
response.putExtra(ActivityManageRule.intentNameTriggerParameter2, tetheringTypeUsb);
|
||||
else if(rbTetheringTypeCable.isChecked())
|
||||
response.putExtra(ActivityManageRule.intentNameTriggerParameter2, tetheringTypeCable);
|
||||
|
||||
setResult(RESULT_OK, response);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -10,13 +10,13 @@ import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.TextView;
|
||||
import android.widget.TimePicker;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.sql.Time;
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
|
||||
@ -27,7 +27,6 @@ public class ActivityManageTriggerTimeFrame extends Activity
|
||||
CheckBox checkMonday, checkTuesday, checkWednesday, checkThursday, checkFriday, checkSaturday, checkSunday, chkRepeat;
|
||||
RadioButton radioTimeFrameEntering, radioTimeFrameLeaving;
|
||||
EditText etRepeatEvery;
|
||||
TextView tvDaysHint;
|
||||
|
||||
static Trigger editedTimeFrameTrigger = null;
|
||||
|
||||
@ -35,7 +34,6 @@ public class ActivityManageTriggerTimeFrame extends Activity
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
setContentView(R.layout.activity_manage_trigger_timeframe);
|
||||
|
||||
startPicker = (TimePicker)findViewById(R.id.tpTimeFrameStart);
|
||||
@ -55,18 +53,17 @@ public class ActivityManageTriggerTimeFrame extends Activity
|
||||
radioTimeFrameLeaving = (RadioButton)findViewById(R.id.radioTimeFrameLeaving);
|
||||
chkRepeat = (CheckBox)findViewById(R.id.chkRepeat);
|
||||
etRepeatEvery = (EditText)findViewById(R.id.etRepeatEvery);
|
||||
tvDaysHint = (TextView)findViewById(R.id.tvDaysHint);
|
||||
|
||||
bSaveTimeFrame.setOnClickListener(new OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
TimeObject startTime = new TimeObject();
|
||||
Time startTime = new Time(0);
|
||||
startTime.setHours(startPicker.getCurrentHour());
|
||||
startTime.setMinutes(startPicker.getCurrentMinute());
|
||||
|
||||
TimeObject stopTime = new TimeObject();
|
||||
Time stopTime = new Time(0);
|
||||
stopTime.setHours(stopPicker.getCurrentHour());
|
||||
stopTime.setMinutes(stopPicker.getCurrentMinute());
|
||||
|
||||
@ -184,31 +181,6 @@ public class ActivityManageTriggerTimeFrame extends Activity
|
||||
editedTimeFrameTrigger.setTimeFrame(new TimeFrame(editedTimeFrameTrigger.getTriggerParameter2()));
|
||||
loadVariableIntoGui();
|
||||
}
|
||||
|
||||
TimePicker.OnTimeChangedListener pickerListener = new TimePicker.OnTimeChangedListener()
|
||||
{
|
||||
@Override
|
||||
public void onTimeChanged(TimePicker timePicker, int i, int i1)
|
||||
{
|
||||
if(
|
||||
startPicker.getCurrentHour() > stopPicker.getCurrentHour()
|
||||
||
|
||||
(
|
||||
startPicker.getCurrentHour() == stopPicker.getCurrentHour()
|
||||
&&
|
||||
startPicker.getCurrentMinute() >= stopPicker.getCurrentMinute()
|
||||
)
|
||||
)
|
||||
tvDaysHint.setText(getResources().getString(R.string.timeFrameDaysHint));
|
||||
else
|
||||
tvDaysHint.setText("");
|
||||
}
|
||||
};
|
||||
startPicker.setOnTimeChangedListener(pickerListener);
|
||||
stopPicker.setOnTimeChangedListener(pickerListener);
|
||||
|
||||
// Perform check once
|
||||
pickerListener.onTimeChanged(null, 0, 0);
|
||||
}
|
||||
|
||||
private void loadVariableIntoGui()
|
||||
|
@ -12,25 +12,23 @@ import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
|
||||
import com.jens.automation2.receivers.BluetoothReceiver;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@ -43,41 +41,28 @@ public class ActivityManageTriggerWifi extends Activity
|
||||
RadioButton rbTriggerWifiConnected, rbTriggerWifiDisconnected;
|
||||
EditText etTriggerWifiName;
|
||||
Spinner spinnerWifiList;
|
||||
Button bTriggerWifiSave, bLoadWifiList;
|
||||
Button btriggerWifiSave, bLoadWifiList;
|
||||
List<String> wifiList = new ArrayList<>();
|
||||
ArrayAdapter<String> wifiSpinnerAdapter;
|
||||
private final static int requestCodeLocationPermission = 124;
|
||||
TextView tvWifiTriggerNameLocationNotice, tvWifiTriggerDisconnectionHint;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
setContentView(R.layout.activity_manage_trigger_wifi);
|
||||
|
||||
rbTriggerWifiConnected = (RadioButton) findViewById(R.id.rbTriggerWifiConnected);
|
||||
rbTriggerWifiDisconnected = (RadioButton) findViewById(R.id.rbTriggerWifiDisconnected);
|
||||
etTriggerWifiName = (EditText) findViewById(R.id.etTriggerWifiName);
|
||||
spinnerWifiList = (Spinner) findViewById(R.id.spinnerWifiList);
|
||||
bTriggerWifiSave = (Button) findViewById(R.id.bTriggerWifiSave);
|
||||
btriggerWifiSave = (Button) findViewById(R.id.btriggerWifiSave);
|
||||
bLoadWifiList = (Button) findViewById(R.id.bLoadWifiList);
|
||||
tvWifiTriggerNameLocationNotice = (TextView)findViewById(R.id.tvWifiTriggerNameLocationNotice);
|
||||
tvWifiTriggerDisconnectionHint = (TextView)findViewById(R.id.tvWifiTriggerDisconnectionHint);
|
||||
|
||||
tvWifiTriggerDisconnectionHint.setVisibility(View.GONE);
|
||||
|
||||
wifiSpinnerAdapter = new ArrayAdapter<String>(this, R.layout.text_view_for_poi_listview_mediumtextsize, wifiList);
|
||||
spinnerWifiList.setAdapter(wifiSpinnerAdapter);
|
||||
spinnerWifiList.setEnabled(false); // bug in Android; this only works when done in code, not in xml
|
||||
|
||||
if(
|
||||
Miscellaneous.getTargetSDK(Miscellaneous.getAnyContext()) >= 29
|
||||
&&
|
||||
!ActivityPermissions.isPermissionDeclaratedInManifest(Miscellaneous.getAnyContext(), Manifest.permission.ACCESS_BACKGROUND_LOCATION)
|
||||
)
|
||||
tvWifiTriggerNameLocationNotice.setVisibility(View.VISIBLE);
|
||||
|
||||
if (getIntent().hasExtra("edit"))
|
||||
{
|
||||
boolean connected = getIntent().getBooleanExtra("wifiState", false);
|
||||
@ -89,7 +74,7 @@ public class ActivityManageTriggerWifi extends Activity
|
||||
etTriggerWifiName.setText(wifiName);
|
||||
}
|
||||
|
||||
bTriggerWifiSave.setOnClickListener(new View.OnClickListener()
|
||||
btriggerWifiSave.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
@ -108,11 +93,6 @@ public class ActivityManageTriggerWifi extends Activity
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
|
||||
{
|
||||
etTriggerWifiName.setText(wifiList.get(position));
|
||||
|
||||
if(etTriggerWifiName.getText().toString().length() > 0 && rbTriggerWifiDisconnected.isChecked())
|
||||
tvWifiTriggerDisconnectionHint.setVisibility(View.VISIBLE);
|
||||
else
|
||||
tvWifiTriggerDisconnectionHint.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -130,41 +110,6 @@ public class ActivityManageTriggerWifi extends Activity
|
||||
loadWifis();
|
||||
}
|
||||
});
|
||||
|
||||
rbTriggerWifiDisconnected.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
|
||||
{
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean b)
|
||||
{
|
||||
if(etTriggerWifiName.getText().toString().length() > 0 && b)
|
||||
tvWifiTriggerDisconnectionHint.setVisibility(View.VISIBLE);
|
||||
else
|
||||
tvWifiTriggerDisconnectionHint.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
etTriggerWifiName.addTextChangedListener(new TextWatcher()
|
||||
{
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2)
|
||||
{
|
||||
if(etTriggerWifiName.getText().toString().length() > 0 && rbTriggerWifiDisconnected.isChecked())
|
||||
tvWifiTriggerDisconnectionHint.setVisibility(View.VISIBLE);
|
||||
else
|
||||
tvWifiTriggerDisconnectionHint.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable editable)
|
||||
{
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void loadWifis()
|
||||
|
@ -18,8 +18,6 @@ import android.os.Bundle;
|
||||
import android.os.PowerManager;
|
||||
import android.provider.Settings;
|
||||
import android.text.Html;
|
||||
import android.text.TextUtils;
|
||||
import android.text.util.Linkify;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
@ -27,8 +25,6 @@ import android.widget.TextView;
|
||||
|
||||
import com.jens.automation2.receivers.NotificationListener;
|
||||
|
||||
import org.w3c.dom.DOMImplementationSource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@ -51,16 +47,12 @@ public class ActivityPermissions extends Activity
|
||||
private static final int requestCodeForPermissionsNotifications = 12046;
|
||||
private static final int requestCodeForPermissionsDeviceAdmin = 12047;
|
||||
private static final int requestCodeForPermissionsBatteryOptimization = 12048;
|
||||
private static final int requestCodeForPermissionNotificationAccessAndroid13 = 12049;
|
||||
private static final int requestCodeForPermissionsManageOverlay = 12050;
|
||||
private static final int requestCodeForPermissionsAccessibility = 12051;
|
||||
private static final int requestCodeForPermissionsScheduleExactAlarms = 12052;
|
||||
protected String[] specificPermissionsToRequest = null;
|
||||
|
||||
public static String intentExtraName = "permissionsToBeRequested";
|
||||
|
||||
Button bCancelPermissions, bRequestPermissions;
|
||||
TextView tvPermissionsExplanation, tvPermissionsExplanationSystemSettings, tvPermissionsExplanationLong, tvRestrictionPermissionsNotice;
|
||||
TextView tvPermissionsExplanation, tvPermissionsExplanationSystemSettings, tvPermissionsExplanationLong;
|
||||
static ActivityPermissions instance = null;
|
||||
|
||||
public final static String permissionNameWireguard = "com.wireguard.android.permission.CONTROL_TUNNELS";
|
||||
@ -83,7 +75,6 @@ public class ActivityPermissions extends Activity
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
setContentView(R.layout.permissions_activity);
|
||||
|
||||
bCancelPermissions = (Button)findViewById(R.id.bCancelPermissions);
|
||||
@ -91,7 +82,6 @@ public class ActivityPermissions extends Activity
|
||||
tvPermissionsExplanation = (TextView)findViewById(R.id.tvPermissionsExplanation);
|
||||
tvPermissionsExplanationSystemSettings = (TextView)findViewById(R.id.tvPermissionsExplanationSystemSettings);
|
||||
tvPermissionsExplanationLong = (TextView)findViewById(R.id.tvPermissionsExplanationLong);
|
||||
tvRestrictionPermissionsNotice = (TextView)findViewById(R.id.tvRestrictionPermissionsNotice);
|
||||
|
||||
bCancelPermissions.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@ -166,7 +156,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)
|
||||
{
|
||||
@ -234,7 +224,7 @@ public class ActivityPermissions extends Activity
|
||||
}
|
||||
}
|
||||
|
||||
public static void addToArrayListUnique(String value, List<String> list)
|
||||
protected static void addToArrayListUnique(String value, ArrayList<String> list)
|
||||
{
|
||||
if (!list.contains(value))
|
||||
list.add(value);
|
||||
@ -258,17 +248,14 @@ public class ActivityPermissions extends Activity
|
||||
if (!havePermission(s, context))
|
||||
return true;
|
||||
}
|
||||
else if((s.equalsIgnoreCase(Manifest.permission.CALL_PHONE) || s.equalsIgnoreCase(Manifest.permission.ANSWER_PHONE_CALLS)) && BuildConfig.FLAVOR.equalsIgnoreCase(AutomationService.flavor_name_googleplay))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if(s.equalsIgnoreCase(Manifest.permission.ACTIVITY_RECOGNITION) || s.equalsIgnoreCase(permissionNameGoogleActivityDetection))
|
||||
{
|
||||
if(!BuildConfig.FLAVOR.equalsIgnoreCase(AutomationService.flavor_name_fdroid))
|
||||
if(!BuildConfig.FLAVOR.equalsIgnoreCase("fdroidFlavor"))
|
||||
if (!havePermission(s, context))
|
||||
return true;
|
||||
}
|
||||
else if (!havePermission(s, context))
|
||||
else
|
||||
if (!havePermission(s, context))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -306,14 +293,6 @@ public class ActivityPermissions extends Activity
|
||||
String packageName = context.getApplicationContext().getPackageName();
|
||||
return pm.isIgnoringBatteryOptimizations(packageName);
|
||||
}
|
||||
else if (s.equals(Manifest.permission.SYSTEM_ALERT_WINDOW))
|
||||
{
|
||||
return android.provider.Settings.canDrawOverlays(Miscellaneous.getAnyContext());
|
||||
}
|
||||
else if(s.equals(Manifest.permission.BIND_ACCESSIBILITY_SERVICE))
|
||||
{
|
||||
return haveAccessibilityAccess(Miscellaneous.getAnyContext());
|
||||
}
|
||||
else
|
||||
{
|
||||
int res = context.checkCallingOrSelfPermission(s);
|
||||
@ -332,59 +311,6 @@ public class ActivityPermissions extends Activity
|
||||
return active;
|
||||
}
|
||||
|
||||
public static boolean haveAccessibilityAccess(Context mContext)
|
||||
{
|
||||
int accessibilityEnabled = 0;
|
||||
|
||||
final String service = mContext.getPackageName() + "/" + BuildConfig.APPLICATION_ID + ".MyAccessibilityService";
|
||||
|
||||
boolean accessibilityFound = false;
|
||||
try
|
||||
{
|
||||
accessibilityEnabled = Settings.Secure.getInt(mContext.getApplicationContext().getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED);
|
||||
// Log.v(TAG, "accessibilityEnabled = " + accessibilityEnabled);
|
||||
}
|
||||
catch (Settings.SettingNotFoundException e)
|
||||
{
|
||||
// Log.e(TAG, "Error finding setting, default accessibility to not found: " + e.getMessage());
|
||||
}
|
||||
TextUtils.SimpleStringSplitter mStringColonSplitter = new TextUtils.SimpleStringSplitter(':');
|
||||
|
||||
if (accessibilityEnabled == 1)
|
||||
{
|
||||
String settingValue = Settings.Secure.getString(mContext.getApplicationContext().getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
|
||||
if (settingValue != null)
|
||||
{
|
||||
TextUtils.SimpleStringSplitter splitter = mStringColonSplitter;
|
||||
splitter.setString(settingValue);
|
||||
while (splitter.hasNext())
|
||||
{
|
||||
String accessibilityService = splitter.next();
|
||||
|
||||
if (accessibilityService.equalsIgnoreCase(service))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return accessibilityFound;
|
||||
}
|
||||
|
||||
public static void requestOverlay()
|
||||
{
|
||||
Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
|
||||
ActivityPermissions.getInstance().startActivityForResult(intent, requestCodeForPermissionsManageOverlay);
|
||||
}
|
||||
|
||||
public static void requestBindAccessibilityService()
|
||||
{
|
||||
Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
ActivityPermissions.getInstance().startActivityForResult(intent, requestCodeForPermissionsAccessibility);
|
||||
}
|
||||
|
||||
public static void requestDeviceAdmin()
|
||||
{
|
||||
if(!haveDeviceAdmin())
|
||||
@ -427,19 +353,10 @@ public class ActivityPermissions extends Activity
|
||||
if(!havePermission(Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, workingContext))
|
||||
addToArrayListUnique(Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, requiredPermissions);
|
||||
|
||||
if(Build.VERSION.SDK_INT >= 33 && BuildConfig.FLAVOR.equals(AutomationService.flavor_name_googleplay))
|
||||
for(Profile p : Profile.getProfileCollection())
|
||||
{
|
||||
if (!havePermission(android.Manifest.permission.POST_NOTIFICATIONS, workingContext))
|
||||
addToArrayListUnique(android.Manifest.permission.POST_NOTIFICATIONS, requiredPermissions);
|
||||
}
|
||||
|
||||
if(!havePermission(Manifest.permission.READ_EXTERNAL_STORAGE, workingContext))
|
||||
{
|
||||
for (Profile p : Profile.getProfileCollection())
|
||||
{
|
||||
if (p.changeIncomingCallsRingtone || p.changeNotificationRingtone)
|
||||
addToArrayListUnique(Manifest.permission.READ_EXTERNAL_STORAGE, requiredPermissions);
|
||||
}
|
||||
if(p.changeIncomingCallsRingtone || p.changeNotificationRingtone)
|
||||
addToArrayListUnique(Manifest.permission.READ_EXTERNAL_STORAGE, requiredPermissions);
|
||||
}
|
||||
|
||||
if (!onlyGeneral)
|
||||
@ -464,7 +381,7 @@ public class ActivityPermissions extends Activity
|
||||
}
|
||||
else if (singlePermission.equalsIgnoreCase(Manifest.permission.ACTIVITY_RECOGNITION) || singlePermission.equalsIgnoreCase(permissionNameGoogleActivityDetection))
|
||||
{
|
||||
if (!BuildConfig.FLAVOR.equalsIgnoreCase(AutomationService.flavor_name_fdroid))
|
||||
if (!BuildConfig.FLAVOR.equalsIgnoreCase("fdroidFlavor"))
|
||||
addToArrayListUnique(singlePermission, requiredPermissions);
|
||||
}
|
||||
else
|
||||
@ -473,6 +390,27 @@ public class ActivityPermissions extends Activity
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Not all permissions need to be asked for.
|
||||
*/
|
||||
|
||||
/*if(shouldShowRequestPermissionRationale("android.permission.RECORD_AUDIO"))
|
||||
Toast.makeText(ActivityMainScreen.this, "shouldShowRequestPermissionRationale", Toast.LENGTH_LONG).show();
|
||||
else
|
||||
Toast.makeText(ActivityMainScreen.this, "not shouldShowRequestPermissionRationale", Toast.LENGTH_LONG).show();*/
|
||||
|
||||
// addToArrayListUnique("Manifest.permission.RECORD_AUDIO", requiredPermissions);
|
||||
/*int hasPermission = checkSelfPermission(Manifest.permission.RECORD_AUDIO);
|
||||
if (hasPermission == PackageManager.PERMISSION_DENIED)
|
||||
{
|
||||
Toast.makeText(ActivityMainScreen.this, "Don't have record_audio. Requesting...", Toast.LENGTH_LONG).show();
|
||||
// requestPermissions(new String[]{"Manifest.permission.CAMERA"}, requestCodeForPermissions);
|
||||
ActivityCompat.requestPermissions(ActivityMainScreen.this, new String[]{"Manifest.permission.CAMERA"}, requestCodeForPermissions);
|
||||
}
|
||||
else
|
||||
Toast.makeText(ActivityMainScreen.this, "Have record_audio.", Toast.LENGTH_LONG).show();*/
|
||||
|
||||
}
|
||||
|
||||
return requiredPermissions.toArray(new String[requiredPermissions.size()]);
|
||||
@ -501,8 +439,7 @@ public class ActivityPermissions extends Activity
|
||||
{
|
||||
case activityDetection:
|
||||
addToArrayListUnique(permissionNameGoogleActivityDetection, requiredPermissions);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
|
||||
addToArrayListUnique(Manifest.permission.ACTIVITY_RECOGNITION, requiredPermissions);
|
||||
addToArrayListUnique(Manifest.permission.ACTIVITY_RECOGNITION, requiredPermissions);
|
||||
break;
|
||||
case airplaneMode:
|
||||
addToArrayListUnique(Manifest.permission.ACCESS_NETWORK_STATE, requiredPermissions);
|
||||
@ -532,7 +469,6 @@ public class ActivityPermissions extends Activity
|
||||
case phoneCall:
|
||||
addToArrayListUnique(Manifest.permission.READ_PHONE_STATE, requiredPermissions);
|
||||
addToArrayListUnique(Manifest.permission.PROCESS_OUTGOING_CALLS, requiredPermissions);
|
||||
addToArrayListUnique(Manifest.permission.READ_CALL_LOG, requiredPermissions);
|
||||
break;
|
||||
case pointOfInterest:
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
|
||||
@ -565,8 +501,6 @@ public class ActivityPermissions extends Activity
|
||||
addToArrayListUnique(Manifest.permission.INTERNET, requiredPermissions);
|
||||
break;
|
||||
case timeFrame:
|
||||
if(Build.VERSION.SDK_INT >= 31 && Miscellaneous.getTargetSDK(Miscellaneous.getAnyContext()) >= 31)
|
||||
addToArrayListUnique(Manifest.permission.SCHEDULE_EXACT_ALARM, requiredPermissions);
|
||||
break;
|
||||
case usb_host_connection:
|
||||
addToArrayListUnique(Manifest.permission.READ_PHONE_STATE, requiredPermissions);
|
||||
@ -575,25 +509,10 @@ public class ActivityPermissions extends Activity
|
||||
case wifiConnection:
|
||||
addToArrayListUnique(Manifest.permission.ACCESS_NETWORK_STATE, requiredPermissions);
|
||||
addToArrayListUnique(Manifest.permission.ACCESS_WIFI_STATE, requiredPermissions);
|
||||
if(
|
||||
(
|
||||
Miscellaneous.getTargetSDK(Miscellaneous.getAnyContext()) >= 29
|
||||
&&
|
||||
isPermissionDeclaratedInManifest(Miscellaneous.getAnyContext(), Manifest.permission.ACCESS_BACKGROUND_LOCATION)
|
||||
)
|
||||
||
|
||||
Build.VERSION.SDK_INT >= 33
|
||||
)
|
||||
addToArrayListUnique(Manifest.permission.ACCESS_BACKGROUND_LOCATION, requiredPermissions);
|
||||
break;
|
||||
case notification:
|
||||
addToArrayListUnique(Manifest.permission.BIND_NOTIFICATION_LISTENER_SERVICE, requiredPermissions);
|
||||
break;
|
||||
case calendarEvent:
|
||||
addToArrayListUnique(Manifest.permission.READ_CALENDAR, requiredPermissions);
|
||||
if(Build.VERSION.SDK_INT >= 31 && Miscellaneous.getTargetSDK(Miscellaneous.getAnyContext()) >= 31)
|
||||
addToArrayListUnique(Manifest.permission.SCHEDULE_EXACT_ALARM, requiredPermissions);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -701,19 +620,6 @@ public class ActivityPermissions extends Activity
|
||||
// action.getParameter2().contains("eu.faircode.netguard.STOP_PORT_FORWARD")
|
||||
// )
|
||||
// addToArrayListUnique("net.kollnig.missioncontrol.permission.ADMIN", requiredPermissions);
|
||||
if(Build.VERSION.SDK_INT >= 29)
|
||||
{
|
||||
String parts[];
|
||||
if(action.getParameter2().contains(Action.actionParameter2Split))
|
||||
parts = action.getParameter2().split(Action.actionParameter2Split);
|
||||
else
|
||||
parts = action.getParameter2().split(";");
|
||||
|
||||
// Permission only required for starts of activity, not broadcasts or services
|
||||
|
||||
if(parts[2].equals(ActivityManageActionStartActivity.startByActivityString))
|
||||
addToArrayListUnique(Manifest.permission.SYSTEM_ALERT_WINDOW, requiredPermissions);
|
||||
}
|
||||
break;
|
||||
case triggerUrl:
|
||||
addToArrayListUnique(Manifest.permission.INTERNET, requiredPermissions);
|
||||
@ -767,19 +673,6 @@ public class ActivityPermissions extends Activity
|
||||
else
|
||||
addToArrayListUnique(Manifest.permission.BIND_DEVICE_ADMIN, requiredPermissions);
|
||||
break;
|
||||
case startPhoneCall:
|
||||
addToArrayListUnique(Manifest.permission.CALL_PHONE, requiredPermissions);
|
||||
addToArrayListUnique(Manifest.permission.SYSTEM_ALERT_WINDOW, requiredPermissions);
|
||||
break;
|
||||
case stopPhoneCall:
|
||||
addToArrayListUnique(Manifest.permission.ANSWER_PHONE_CALLS, requiredPermissions);
|
||||
break;
|
||||
case takeScreenshot:
|
||||
addToArrayListUnique(Manifest.permission.BIND_ACCESSIBILITY_SERVICE, requiredPermissions);
|
||||
break;
|
||||
case setLocationService:
|
||||
addToArrayListUnique(Manifest.permission.WRITE_SECURE_SETTINGS, requiredPermissions);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -842,19 +735,14 @@ public class ActivityPermissions extends Activity
|
||||
case Manifest.permission.WRITE_EXTERNAL_STORAGE:
|
||||
usingElements.add(getResources().getString(R.string.storeSettings));
|
||||
break;
|
||||
case Manifest.permission.SCHEDULE_EXACT_ALARM:
|
||||
for(String ruleName : getRulesUsing(Trigger.Trigger_Enum.timeFrame))
|
||||
usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName));
|
||||
for(String ruleName : getRulesUsing(Trigger.Trigger_Enum.calendarEvent))
|
||||
usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName));
|
||||
break;
|
||||
case Manifest.permission.BIND_NOTIFICATION_LISTENER_SERVICE:
|
||||
for(String ruleName : getRulesUsing(Trigger.Trigger_Enum.notification))
|
||||
usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName));
|
||||
for(String ruleName : getRulesUsing(Action.Action_Enum.closeNotification))
|
||||
usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName));
|
||||
break;
|
||||
case permissionNameGoogleActivityDetection:
|
||||
for(String ruleName : getRulesUsing(Trigger.Trigger_Enum.activityDetection))
|
||||
usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName));
|
||||
break;
|
||||
case Manifest.permission.ACTIVITY_RECOGNITION:
|
||||
for(String ruleName : getRulesUsing(Trigger.Trigger_Enum.activityDetection))
|
||||
usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName));
|
||||
@ -869,7 +757,6 @@ public class ActivityPermissions extends Activity
|
||||
break;
|
||||
case Manifest.permission.ACCESS_BACKGROUND_LOCATION:
|
||||
usingElements.add(getResources().getString(R.string.googleLocationChicanery));
|
||||
usingElements.add(getResources().getString(R.string.wifiMonitoringAlsoRequiresThis));
|
||||
for(String ruleName : getRulesUsing(Trigger.Trigger_Enum.pointOfInterest))
|
||||
usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName));
|
||||
for(String ruleName : getRulesUsing(Trigger.Trigger_Enum.speed))
|
||||
@ -954,7 +841,6 @@ public class ActivityPermissions extends Activity
|
||||
usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName));
|
||||
break;
|
||||
case Manifest.permission.PROCESS_OUTGOING_CALLS:
|
||||
case Manifest.permission.READ_CALL_LOG:
|
||||
for(String ruleName : getRulesUsing(Trigger.Trigger_Enum.phoneCall))
|
||||
usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName));
|
||||
break;
|
||||
@ -978,20 +864,6 @@ public class ActivityPermissions extends Activity
|
||||
for(String ruleName : getRulesUsing(Action.Action_Enum.sendTextMessage))
|
||||
usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName));
|
||||
break;
|
||||
case Manifest.permission.CALL_PHONE:
|
||||
for(String ruleName : getRulesUsing(Action.Action_Enum.startPhoneCall))
|
||||
usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName));
|
||||
break;
|
||||
case Manifest.permission.SYSTEM_ALERT_WINDOW:
|
||||
for(String ruleName : getRulesUsing(Action.Action_Enum.startOtherActivity))
|
||||
usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName));
|
||||
for(String ruleName : getRulesUsing(Action.Action_Enum.startPhoneCall))
|
||||
usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName));
|
||||
break;
|
||||
case Manifest.permission.ANSWER_PHONE_CALLS:
|
||||
for(String ruleName : getRulesUsing(Action.Action_Enum.stopPhoneCall))
|
||||
usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName));
|
||||
break;
|
||||
case Manifest.permission.FOREGROUND_SERVICE:
|
||||
usingElements.add(getResources().getString(R.string.startAutomationAsService));
|
||||
break;
|
||||
@ -1035,18 +907,6 @@ public class ActivityPermissions extends Activity
|
||||
case Manifest.permission.QUERY_ALL_PACKAGES:
|
||||
usingElements.add(getResources().getString(R.string.queryAllPackages));
|
||||
break;
|
||||
case Manifest.permission.BIND_ACCESSIBILITY_SERVICE:
|
||||
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;
|
||||
case Manifest.permission.READ_CALENDAR:
|
||||
for(String ruleName : getRulesUsing(Trigger.Trigger_Enum.calendarEvent))
|
||||
usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName));
|
||||
break;
|
||||
}
|
||||
|
||||
return usingElements;
|
||||
@ -1055,15 +915,6 @@ public class ActivityPermissions extends Activity
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data)
|
||||
{
|
||||
/*
|
||||
All of the following permissions need to be "manually" activated by the user in some
|
||||
buried system menu.
|
||||
In my opinion by mistake the function will be called when the user has just landed
|
||||
on one of those screens, not when he exits it again. To compensate for that onResume()
|
||||
is overridden. This enables the permission screen to automatically close after all
|
||||
required permissions have been granted.
|
||||
*/
|
||||
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
||||
@ -1107,18 +958,6 @@ public class ActivityPermissions extends Activity
|
||||
if (requestCode == requestCodeForPermissionsBatteryOptimization)
|
||||
if(havePermission(Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, ActivityPermissions.this))
|
||||
requestPermissions(cachedPermissionsToRequest, true);
|
||||
|
||||
if (requestCode == requestCodeForPermissionsManageOverlay)
|
||||
if(havePermission(Manifest.permission.SYSTEM_ALERT_WINDOW, ActivityPermissions.this))
|
||||
requestPermissions(cachedPermissionsToRequest, true);
|
||||
|
||||
if (requestCode == requestCodeForPermissionsAccessibility)
|
||||
if(havePermission(Manifest.permission.BIND_ACCESSIBILITY_SERVICE, ActivityPermissions.this))
|
||||
requestPermissions(cachedPermissionsToRequest, true);
|
||||
|
||||
if (requestCode == requestCodeForPermissionsScheduleExactAlarms)
|
||||
if(havePermission(Manifest.permission.SCHEDULE_EXACT_ALARM, ActivityPermissions.this))
|
||||
requestPermissions(cachedPermissionsToRequest, true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1169,7 +1008,7 @@ public class ActivityPermissions extends Activity
|
||||
startActivityForResult(intent, requestCodeForPermissionsWriteSettings);
|
||||
return;
|
||||
}
|
||||
else if (s.equalsIgnoreCase(Manifest.permission.BIND_DEVICE_ADMIN))
|
||||
if (s.equalsIgnoreCase(Manifest.permission.BIND_DEVICE_ADMIN))
|
||||
{
|
||||
requiredPermissions.remove(s);
|
||||
cachedPermissionsToRequest = requiredPermissions;
|
||||
@ -1178,88 +1017,18 @@ public class ActivityPermissions extends Activity
|
||||
}
|
||||
else if (s.equalsIgnoreCase(Manifest.permission.ACCESS_NOTIFICATION_POLICY))
|
||||
{
|
||||
if(BuildConfig.FLAVOR.equals(AutomationService.flavor_name_apk))
|
||||
Miscellaneous.messageBox(getResources().getString(R.string.info), getResources().getString(R.string.noticeRestrictedPermissions), ActivityPermissions.this).show();
|
||||
|
||||
requiredPermissions.remove(s);
|
||||
cachedPermissionsToRequest = requiredPermissions;
|
||||
Intent intent = new Intent(android.provider.Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS);
|
||||
startActivityForResult(intent, requestCodeForPermissionsNotificationPolicy);
|
||||
|
||||
return;
|
||||
}
|
||||
else if (s.equalsIgnoreCase(Manifest.permission.SYSTEM_ALERT_WINDOW))
|
||||
{
|
||||
AlertDialog diag = Miscellaneous.messageBox(getResources().getString(R.string.info), getResources().getString(R.string.overlayPermissionHint), ActivityPermissions.this);
|
||||
diag.setOnDismissListener(new DialogInterface.OnDismissListener()
|
||||
{
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialogInterface)
|
||||
{
|
||||
requiredPermissions.remove(s);
|
||||
cachedPermissionsToRequest = requiredPermissions;
|
||||
requestOverlay();
|
||||
}
|
||||
});
|
||||
diag.show();
|
||||
return;
|
||||
}
|
||||
else if (s.equalsIgnoreCase(Manifest.permission.BIND_ACCESSIBILITY_SERVICE))
|
||||
{
|
||||
AlertDialog diag = Miscellaneous.messageBox(getResources().getString(R.string.info), getResources().getString(R.string.accessibilityApiPermissionHint), ActivityPermissions.this);
|
||||
diag.setOnDismissListener(new DialogInterface.OnDismissListener()
|
||||
{
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialogInterface)
|
||||
{
|
||||
requiredPermissions.remove(s);
|
||||
cachedPermissionsToRequest = requiredPermissions;
|
||||
requestBindAccessibilityService();
|
||||
}
|
||||
});
|
||||
diag.show();
|
||||
return;
|
||||
}
|
||||
else if (s.equalsIgnoreCase(Manifest.permission.BIND_NOTIFICATION_LISTENER_SERVICE))
|
||||
{
|
||||
if(Build.VERSION.SDK_INT >= 33)
|
||||
{
|
||||
AlertDialog dialog = Miscellaneous.messageBox(getResources().getString(R.string.info), getResources().getString(R.string.notificationAccessAndroid13), ActivityPermissions.this);
|
||||
dialog.setOnDismissListener(new DialogInterface.OnDismissListener()
|
||||
{
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialogInterface)
|
||||
{
|
||||
requiredPermissions.remove(s);
|
||||
cachedPermissionsToRequest = requiredPermissions;
|
||||
requestNotificationAccess();
|
||||
}
|
||||
});
|
||||
dialog.show();
|
||||
}
|
||||
else
|
||||
{
|
||||
requiredPermissions.remove(s);
|
||||
cachedPermissionsToRequest = requiredPermissions;
|
||||
requestNotificationAccess();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
else if (s.equalsIgnoreCase(Manifest.permission.SCHEDULE_EXACT_ALARM))
|
||||
{
|
||||
AlertDialog diag = Miscellaneous.messageBox(getResources().getString(R.string.info), getResources().getString(R.string.alarmsPermissionHint), ActivityPermissions.this);
|
||||
diag.setOnDismissListener(new DialogInterface.OnDismissListener()
|
||||
{
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialogInterface)
|
||||
{
|
||||
requiredPermissions.remove(s);
|
||||
cachedPermissionsToRequest = requiredPermissions;
|
||||
requestScheduleExactAlarms();
|
||||
}
|
||||
});
|
||||
diag.show();
|
||||
requiredPermissions.remove(s);
|
||||
cachedPermissionsToRequest = requiredPermissions;
|
||||
Intent intent = new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS);
|
||||
startActivityForResult(intent, requestCodeForPermissionsNotifications);
|
||||
return;
|
||||
}
|
||||
else if(s.equals(Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS))
|
||||
@ -1291,13 +1060,6 @@ public class ActivityPermissions extends Activity
|
||||
|
||||
return;
|
||||
}
|
||||
else if(s.equalsIgnoreCase(Manifest.permission.WRITE_SECURE_SETTINGS))
|
||||
{
|
||||
AlertDialog diaglog = Miscellaneous.messageBox(getResources().getString(R.string.info), getResources().getString(R.string.writeSecureSettingsNotice), ActivityPermissions.this);
|
||||
diaglog.show();
|
||||
Linkify.addLinks((TextView) diaglog.findViewById(android.R.id.message), Linkify.ALL);
|
||||
// return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1341,20 +1103,6 @@ public class ActivityPermissions extends Activity
|
||||
}
|
||||
}
|
||||
|
||||
void requestNotificationAccess()
|
||||
{
|
||||
Intent intent = new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS);
|
||||
startActivityForResult(intent, requestCodeForPermissionsNotifications);
|
||||
}
|
||||
|
||||
|
||||
void requestScheduleExactAlarms()
|
||||
{
|
||||
Intent intent = new Intent(Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM);
|
||||
startActivityForResult(intent, requestCodeForPermissionsScheduleExactAlarms);
|
||||
}
|
||||
|
||||
|
||||
protected void applyChanges()
|
||||
{
|
||||
AutomationService service = AutomationService.getInstance();
|
||||
@ -1733,47 +1481,4 @@ public class ActivityPermissions extends Activity
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
|
||||
if(Build.VERSION.SDK_INT >= 33 && BuildConfig.FLAVOR.equals(AutomationService.flavor_name_apk))
|
||||
{
|
||||
for (String p : getRequiredPermissions(false))
|
||||
{
|
||||
if (p.equals(Manifest.permission.BIND_NOTIFICATION_LISTENER_SERVICE) || p.equals(Manifest.permission.BIND_ACCESSIBILITY_SERVICE))
|
||||
{
|
||||
tvRestrictionPermissionsNotice.setText(getResources().getString(R.string.noticeRestrictedPermissions));
|
||||
|
||||
/*
|
||||
Opening the app's settings directly does not work because the
|
||||
mentioned 3 dots are only displayed when you went there the hard way.
|
||||
*/
|
||||
/*
|
||||
tvRestrictionPermissionsNotice.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View view)
|
||||
{
|
||||
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||
intent.setData(Uri.parse("package:" + getPackageName()));
|
||||
startActivity(intent);
|
||||
}
|
||||
})*/;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(String p : getRequiredPermissions(false))
|
||||
{
|
||||
if(!havePermission(p, this))
|
||||
return;
|
||||
}
|
||||
|
||||
// have all
|
||||
setHaveAllPermissions();
|
||||
}
|
||||
}
|
@ -16,20 +16,12 @@ public class ActivitySettings extends PreferenceActivity
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
addPreferencesFromResource(layout.activity_settings);
|
||||
|
||||
if(BuildConfig.FLAVOR.equals(AutomationService.flavor_name_apk))
|
||||
if(BuildConfig.FLAVOR.equals("apkFlavor"))
|
||||
{
|
||||
chkPrefUpdateCheck = (CheckBoxPreference) findPreference("automaticUpdateCheck");
|
||||
chkPrefUpdateCheck.setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,6 @@ public class ActivityVolumeTest extends Activity
|
||||
instance = this;
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
setContentView(R.layout.activity_volume_calibration);
|
||||
|
||||
tvCurrentVolume = (TextView)findViewById(R.id.tvCurrentVolume);
|
||||
@ -49,15 +48,20 @@ public class ActivityVolumeTest extends Activity
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
|
||||
public void onProgressChanged(SeekBar seekBar, int progress,
|
||||
boolean fromUser)
|
||||
{
|
||||
etReferenceValue.setText(String.valueOf(sbReferenceValue.getProgress()));
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
|
||||
public class AsyncTasks
|
||||
@ -22,7 +23,7 @@ public class AsyncTasks
|
||||
|
||||
try
|
||||
{
|
||||
String result = Miscellaneous.downloadURL("https://server47.de/automation/?action=getLatestVersionCode", null, null, ActivityManageActionTriggerUrl.methodGet, null).trim();
|
||||
String result = Miscellaneous.downloadURL("https://server47.de/automation/?action=getLatestVersionCode", null, null).trim();
|
||||
int latestVersion = Integer.parseInt(result);
|
||||
|
||||
// At this point the update check itself has already been successful.
|
||||
|
@ -28,29 +28,20 @@ import androidx.core.app.NotificationManagerCompat;
|
||||
|
||||
import com.jens.automation2.Trigger.Trigger_Enum;
|
||||
import com.jens.automation2.location.LocationProvider;
|
||||
import com.jens.automation2.receivers.CalendarReceiver;
|
||||
import com.jens.automation2.receivers.DateTimeListener;
|
||||
import com.jens.automation2.receivers.PackageReplacedReceiver;
|
||||
import com.jens.automation2.receivers.PhoneStatusListener;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
public class AutomationService extends Service implements OnInitListener
|
||||
{
|
||||
protected TextToSpeech ttsEngine = null;
|
||||
protected int ttsStatus = -1;
|
||||
protected final static int notificationId = 1000;
|
||||
protected final static int notificationIdRestrictions = 1005;
|
||||
protected final static int notificationIdLocationRestriction = 1006;
|
||||
|
||||
public static final String flavor_name_apk = "apkFlavor";
|
||||
public static final String flavor_name_fdroid = "fdroidFlavor";
|
||||
public static final String flavor_name_googleplay = "googlePlayFlavor";
|
||||
|
||||
final static String NOTIFICATION_CHANNEL_ID_SERVICE = "com.jens.automation2_service";
|
||||
final static String NOTIFICATION_CHANNEL_NAME_SERVICE = "Service notification";
|
||||
|
||||
@ -67,8 +58,6 @@ public class AutomationService extends Service implements OnInitListener
|
||||
protected Calendar lockSoundChangesEnd = null;
|
||||
protected boolean isRunning;
|
||||
|
||||
Map<String,String> variableMap = new HashMap();
|
||||
|
||||
protected static AutomationService centralInstance = null;
|
||||
|
||||
public void nullLockSoundChangesEnd()
|
||||
@ -99,11 +88,6 @@ public class AutomationService extends Service implements OnInitListener
|
||||
this.lockSoundChangesEnd = lockSoundChangesEnd;
|
||||
}
|
||||
|
||||
public int getTtsStatus()
|
||||
{
|
||||
return ttsStatus;
|
||||
}
|
||||
|
||||
protected final IBinder myBinder = new LocalBinder();
|
||||
|
||||
protected LocationProvider myLocationProvider;
|
||||
@ -127,19 +111,6 @@ public class AutomationService extends Service implements OnInitListener
|
||||
|
||||
// Store a reference to myself. Other classes often need a context or something, this can provide that.
|
||||
centralInstance = this;
|
||||
|
||||
/*
|
||||
This has been reported to throw a NullPointerException under
|
||||
rare circumstances. The root cause remains unknown.
|
||||
*/
|
||||
try
|
||||
{
|
||||
Miscellaneous.setDisplayLanguage(AutomationService.this);
|
||||
}
|
||||
catch(NullPointerException e)
|
||||
{
|
||||
Miscellaneous.logEvent("e", "setDisplayLanguage()", Log.getStackTraceString(e), 3);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean checkStartupRequirements(Context context, boolean startAtBoot)
|
||||
@ -222,9 +193,6 @@ public class AutomationService extends Service implements OnInitListener
|
||||
{
|
||||
Bundle b = intent.getExtras();
|
||||
startAtBoot = b.getBoolean("startAtBoot", false);
|
||||
|
||||
if(startAtBoot)
|
||||
Settings.deviceStartDone = false;
|
||||
}
|
||||
|
||||
if (checkStartupRequirements(this, startAtBoot))
|
||||
@ -235,10 +203,7 @@ public class AutomationService extends Service implements OnInitListener
|
||||
startUpRoutine();
|
||||
|
||||
Intent myIntent = new Intent(this, ActivityMainTabLayout.class);
|
||||
if(getApplicationContext().getApplicationInfo().targetSdkVersion >= 31)
|
||||
myPendingIntent = PendingIntent.getActivity(this, 0, myIntent, PendingIntent.FLAG_MUTABLE);
|
||||
else
|
||||
myPendingIntent = PendingIntent.getActivity(this, 0, myIntent, 0);
|
||||
myPendingIntent = PendingIntent.getActivity(this, 0, myIntent, 0);
|
||||
notificationBuilder = createServiceNotificationBuilder();
|
||||
|
||||
updateNotification();
|
||||
@ -247,10 +212,12 @@ public class AutomationService extends Service implements OnInitListener
|
||||
ActivityMainScreen.updateMainScreen();
|
||||
|
||||
this.isRunning = true;
|
||||
|
||||
Miscellaneous.logEvent("i", "Service", this.getResources().getString(R.string.serviceStarted) + " VERSION_CODE: " + BuildConfig.VERSION_CODE + ", VERSION_NAME: " + BuildConfig.VERSION_NAME + ", flavor: " + BuildConfig.FLAVOR, 1);
|
||||
if(Settings.showToasts)
|
||||
Toast.makeText(this, this.getResources().getString(R.string.serviceStarted), Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(this, this.getResources().getString(R.string.serviceStarted), Toast.LENGTH_LONG).show();
|
||||
// ********** Test area **********
|
||||
// Miscellaneous.logEvent("i", "setNetworkType", "bin hier.", 3);
|
||||
// Actions.setData(true);
|
||||
// ********** Test area **********
|
||||
|
||||
/*
|
||||
On normal phones the app is supposed to automatically restart in case of any problems.
|
||||
@ -280,6 +247,8 @@ public class AutomationService extends Service implements OnInitListener
|
||||
reloadSettings, reloadPointsOfInterest, reloadRules, updateNotification
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
public void serviceInterface(serviceCommands command)
|
||||
{
|
||||
Miscellaneous.logEvent("i", "Bind", "Ahhhh, customers... How can I help you?", 5);
|
||||
@ -320,10 +289,7 @@ public class AutomationService extends Service implements OnInitListener
|
||||
|
||||
ReceiverCoordinator.applySettingsAndRules();
|
||||
|
||||
DateTimeListener.setOrResetAlarms();
|
||||
|
||||
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.calendarEvent) && ActivityPermissions.isPermissionDeclaratedInManifest(AutomationService.getInstance(), Manifest.permission.READ_CALENDAR) && ActivityPermissions.havePermission(Manifest.permission.READ_CALENDAR, AutomationService.getInstance()))
|
||||
CalendarReceiver.armOrRearmTimer();
|
||||
DateTimeListener.reloadAlarms();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -333,8 +299,7 @@ public class AutomationService extends Service implements OnInitListener
|
||||
|
||||
stopRoutine();
|
||||
this.isRunning = false;
|
||||
if(Settings.showToasts)
|
||||
Toast.makeText(this, getResources().getString(R.string.serviceStopped), Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(this, getResources().getString(R.string.serviceStopped), Toast.LENGTH_LONG).show();
|
||||
Miscellaneous.logEvent("i", "Service", getResources().getString(R.string.serviceStopped), 1);
|
||||
}
|
||||
|
||||
@ -343,26 +308,8 @@ public class AutomationService extends Service implements OnInitListener
|
||||
if (Settings.useTextToSpeechOnNormal || Settings.useTextToSpeechOnSilent || Settings.useTextToSpeechOnVibrate || Rule.isAnyRuleUsing(Action.Action_Enum.speakText))
|
||||
{
|
||||
if (ttsEngine == null)
|
||||
{
|
||||
ttsEngine = new TextToSpeech(this, new TextToSpeech.OnInitListener()
|
||||
{
|
||||
@Override
|
||||
public void onInit(int status)
|
||||
{
|
||||
ttsStatus = status;
|
||||
|
||||
if (status == TextToSpeech.SUCCESS)
|
||||
{
|
||||
ttsEngine.setLanguage(Locale.getDefault());
|
||||
Miscellaneous.logEvent("i", "TTS engine", "TTS engine available.", 3);
|
||||
}
|
||||
else
|
||||
Miscellaneous.logEvent("i", "TTS engine", "TTS engine not available. Status: " + String.valueOf(status), 3);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
ttsEngine = new TextToSpeech(this, this);
|
||||
} else
|
||||
{
|
||||
if (ttsEngine != null)
|
||||
ttsEngine.shutdown();
|
||||
@ -371,8 +318,6 @@ public class AutomationService extends Service implements OnInitListener
|
||||
|
||||
private void startUpRoutine()
|
||||
{
|
||||
Settings.serviceStartDone = false;
|
||||
|
||||
checkForTtsEngine();
|
||||
checkForPermissions();
|
||||
checkForRestrictedFeatures();
|
||||
@ -391,9 +336,6 @@ public class AutomationService extends Service implements OnInitListener
|
||||
if(r.getsGreenLight(AutomationService.this))
|
||||
r.activate(AutomationService.this, false);
|
||||
}
|
||||
|
||||
Settings.serviceStartDone = true;
|
||||
Settings.deviceStartDone = true;
|
||||
}
|
||||
|
||||
protected void startLocationProvider()
|
||||
@ -507,10 +449,6 @@ public class AutomationService extends Service implements OnInitListener
|
||||
private void stopRoutine()
|
||||
{
|
||||
Miscellaneous.logEvent("i", "Service", "Stopping service...", 3);
|
||||
|
||||
// Clear variables for trigger/action with same name
|
||||
variableMap.clear();
|
||||
|
||||
try
|
||||
{
|
||||
myLocationProvider.stopLocationService();
|
||||
@ -527,7 +465,6 @@ public class AutomationService extends Service implements OnInitListener
|
||||
PackageReplacedReceiver.setHasServiceBeenRunning(false, this);
|
||||
|
||||
centralInstance = null;
|
||||
Settings.serviceStartDone = false;
|
||||
}
|
||||
|
||||
protected static Builder createDefaultNotificationBuilderOld()
|
||||
@ -536,12 +473,7 @@ public class AutomationService extends Service implements OnInitListener
|
||||
builder.setContentTitle("Automation");
|
||||
|
||||
if(Settings.showIconWhenServiceIsRunning)
|
||||
{
|
||||
if(BuildConfig.FLAVOR.equalsIgnoreCase(AutomationService.flavor_name_googleplay))
|
||||
builder.setSmallIcon(R.drawable.crane);
|
||||
else
|
||||
builder.setSmallIcon(R.drawable.ic_launcher);
|
||||
}
|
||||
builder.setSmallIcon(R.drawable.ic_launcher);
|
||||
|
||||
builder.setCategory(Notification.CATEGORY_SERVICE);
|
||||
builder.setWhen(System.currentTimeMillis());
|
||||
@ -549,7 +481,7 @@ public class AutomationService extends Service implements OnInitListener
|
||||
|
||||
Notification defaultNotification = builder.build();
|
||||
|
||||
defaultNotification.icon = R.drawable.crane;
|
||||
defaultNotification.icon = R.drawable.ic_launcher;
|
||||
defaultNotification.when = System.currentTimeMillis();
|
||||
|
||||
// defaultNotification.defaults |= Notification.DEFAULT_VIBRATE;
|
||||
@ -596,12 +528,7 @@ public class AutomationService extends Service implements OnInitListener
|
||||
builder.setOnlyAlertOnce(true);
|
||||
|
||||
if(Settings.showIconWhenServiceIsRunning)
|
||||
{
|
||||
if (BuildConfig.FLAVOR.equals(AutomationService.flavor_name_googleplay))
|
||||
builder.setSmallIcon(R.drawable.crane);
|
||||
else
|
||||
builder.setSmallIcon(R.drawable.ic_launcher);
|
||||
}
|
||||
builder.setSmallIcon(R.drawable.ic_launcher);
|
||||
|
||||
// builder.setContentText(textToDisplay);
|
||||
// builder.setSmallIcon(icon);
|
||||
@ -631,11 +558,11 @@ public class AutomationService extends Service implements OnInitListener
|
||||
if(activePoi == null)
|
||||
{
|
||||
PointOfInterest closestPoi = PointOfInterest.getClosestPOI(instance.getLocationProvider().getCurrentLocation());
|
||||
bodyText = AutomationService.getInstance().getResources().getString(R.string.activePoi) + " " + AutomationService.getInstance().getResources().getString(R.string.none) + "\n" + AutomationService.getInstance().getResources().getString(R.string.closestPoi) + ": " + closestPoi.getName() + lastRuleString;
|
||||
bodyText = AutomationService.getInstance().getResources().getString(R.string.activePoi) + ": " + AutomationService.getInstance().getResources().getString(R.string.none) + "\n" + AutomationService.getInstance().getResources().getString(R.string.closestPoi) + ": " + closestPoi.getName() + lastRuleString;
|
||||
}
|
||||
else
|
||||
{
|
||||
bodyText = AutomationService.getInstance().getResources().getString(R.string.activePoi) + " " + activePoi.getName() + lastRuleString;
|
||||
bodyText = AutomationService.getInstance().getResources().getString(R.string.activePoi) + ": " + activePoi.getName() + lastRuleString;
|
||||
}
|
||||
}
|
||||
catch(NullPointerException e)
|
||||
@ -694,6 +621,8 @@ public class AutomationService extends Service implements OnInitListener
|
||||
@Override
|
||||
public void onInit(int status)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -725,26 +654,25 @@ public class AutomationService extends Service implements OnInitListener
|
||||
{
|
||||
try
|
||||
{
|
||||
for(int i = 0; i < 60; i++)
|
||||
for(int i = 0; i < 5; i++)
|
||||
{
|
||||
if(ttsEngine == null || ttsStatus != TextToSpeech.SUCCESS)
|
||||
if(ttsEngine != null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
Miscellaneous.logEvent("i", "TTS", "Waiting for a moment to give the TTS service time to load...", 4);
|
||||
Thread.sleep(500); // give the tts engine time to load
|
||||
Thread.sleep(1000); // give the tts engine time to load
|
||||
}
|
||||
catch(Exception e)
|
||||
{}
|
||||
}
|
||||
else
|
||||
{
|
||||
Miscellaneous.logEvent("i", "TextToSpeech", "Speaking \"" + text + "\" in language " + ttsEngine.getLanguage().toLanguageTag(), 3);
|
||||
this.ttsEngine.speak(text, TextToSpeech.QUEUE_ADD, null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
Miscellaneous.logEvent("i", "TextToSpeech", "TTS engine not available after waiting 30 seconds, yet. Aborting.", 3);
|
||||
Miscellaneous.logEvent("i", "TextToSpeech", "Speaking " + text + " in language " + ttsEngine.getLanguage().toLanguageTag(), 3);
|
||||
this.ttsEngine.speak(text, TextToSpeech.QUEUE_ADD, null);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
@ -754,19 +682,14 @@ public class AutomationService extends Service implements OnInitListener
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, String> getVariableMap()
|
||||
{
|
||||
return variableMap;
|
||||
}
|
||||
|
||||
public static boolean isMainActivityRunning(Context context)
|
||||
{
|
||||
|
||||
public static boolean isMainActivityRunning(Context context)
|
||||
{
|
||||
if(ActivityMainScreen.getActivityMainScreenInstance() == null)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isMyServiceRunning(Context context)
|
||||
{
|
||||
|
@ -15,7 +15,6 @@ import android.content.Intent;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.database.Cursor;
|
||||
import android.media.AudioAttributes;
|
||||
import android.media.RingtoneManager;
|
||||
@ -32,27 +31,20 @@ import android.provider.Settings.Secure;
|
||||
import android.telephony.PhoneNumberUtils;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.util.Base64;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.jens.automation2.location.LocationProvider;
|
||||
import com.jens.automation2.receivers.CalendarReceiver;
|
||||
import com.jens.automation2.receivers.NotificationListener;
|
||||
import com.jens.automation2.receivers.PhoneStatusListener;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.client.methods.HttpRequestBase;
|
||||
import org.apache.http.conn.ssl.SSLSocketFactory;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
import org.apache.http.params.BasicHttpParams;
|
||||
import org.apache.http.params.HttpParams;
|
||||
import org.apache.http.params.HttpProtocolParams;
|
||||
@ -75,9 +67,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.StringReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.Thread.UncaughtExceptionHandler;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
@ -85,8 +75,6 @@ import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.DigestInputStream;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.KeyStore;
|
||||
@ -94,6 +82,7 @@ import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.sql.Time;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
@ -101,8 +90,8 @@ import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
import java.util.Set;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
@ -121,16 +110,12 @@ import androidx.annotation.RequiresApi;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.documentfile.provider.DocumentFile;
|
||||
|
||||
import eu.chainfire.libsuperuser.Shell;
|
||||
|
||||
public class Miscellaneous extends Service
|
||||
{
|
||||
protected static String writeableFolderStringCache = null;
|
||||
public static Context startupContext;
|
||||
|
||||
public static final String lineSeparator = System.getProperty("line.separator");
|
||||
|
||||
public static String downloadURL(String url, String username, String password, String method, Map<String, String> httpParams)
|
||||
public static String downloadURL(String url, String username, String password)
|
||||
{
|
||||
HttpClient httpclient = new DefaultHttpClient();
|
||||
StringBuilder responseBody = new StringBuilder();
|
||||
@ -158,27 +143,7 @@ public class Miscellaneous extends Service
|
||||
connection.setDoOutput(true);
|
||||
connection.setRequestProperty ("Authorization", "Basic " + encodedCredentials);
|
||||
}
|
||||
else if(method.equals(ActivityManageActionTriggerUrl.methodPost))
|
||||
connection.setRequestMethod("POST");
|
||||
|
||||
if(httpParams.size() > 0)
|
||||
{
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setDoInput(true);
|
||||
connection.setDoOutput(true);
|
||||
|
||||
List<NameValuePair> paramPairs = new ArrayList<NameValuePair>();
|
||||
|
||||
for(String key : httpParams.keySet())
|
||||
paramPairs.add(new BasicNameValuePair(key, httpParams.get(key)));
|
||||
|
||||
OutputStream os = connection.getOutputStream();
|
||||
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
|
||||
writer.write(getQuery(paramPairs));
|
||||
writer.flush();
|
||||
writer.close();
|
||||
}
|
||||
|
||||
|
||||
InputStream content = (InputStream)connection.getInputStream();
|
||||
BufferedReader in = new BufferedReader (new InputStreamReader (content));
|
||||
String line;
|
||||
@ -203,67 +168,34 @@ public class Miscellaneous extends Service
|
||||
return responseBody.toString();
|
||||
}
|
||||
}
|
||||
|
||||
private static String getQuery(List<NameValuePair> params) throws UnsupportedEncodingException
|
||||
{
|
||||
StringBuilder result = new StringBuilder();
|
||||
boolean first = true;
|
||||
|
||||
for (NameValuePair pair : params)
|
||||
{
|
||||
if (first)
|
||||
first = false;
|
||||
else
|
||||
result.append("&");
|
||||
|
||||
result.append(URLEncoder.encode(pair.getName(), "UTF-8"));
|
||||
result.append("=");
|
||||
result.append(URLEncoder.encode(pair.getValue(), "UTF-8"));
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public static String downloadUrlWithoutCertificateChecking(String url, String username, String password, String method, Map<String, String> httpParams)
|
||||
public static String downloadURLwithoutCertificateChecking(String url, String username, String password)
|
||||
{
|
||||
try
|
||||
// HttpClient httpclient = new DefaultHttpClient();
|
||||
// StringBuilder responseBody = new StringBuilder();
|
||||
boolean errorFound = false;
|
||||
|
||||
try
|
||||
{
|
||||
HttpParams params = new BasicHttpParams();
|
||||
params.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false);
|
||||
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
|
||||
HttpClient httpclient = new DefaultHttpClient(params);
|
||||
httpclient = Actions.getInsecureSslClient(httpclient);
|
||||
|
||||
HttpRequestBase httpRequest;
|
||||
if(
|
||||
method.equals(ActivityManageActionTriggerUrl.methodPost)
|
||||
||
|
||||
(username != null && password != null)
|
||||
||
|
||||
httpParams.size() > 0
|
||||
)
|
||||
httpRequest = new HttpPost(url);
|
||||
else
|
||||
httpRequest = new HttpGet(url);
|
||||
|
||||
HttpPost httppost = new HttpPost(url);
|
||||
|
||||
// Add http simple authentication if specified
|
||||
if(username != null && password != null)
|
||||
{
|
||||
String encodedCredentials = Base64.encodeToString(new String(username + ":" + password).getBytes(), Base64.DEFAULT);
|
||||
httpRequest.addHeader("Authorization", "Basic " + encodedCredentials);
|
||||
// List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
|
||||
httppost.addHeader("Authorization", "Basic " + encodedCredentials);
|
||||
// nameValuePairs.add(new BasicNameValuePair("Authorization", "Basic " + encodedCredentials));
|
||||
// httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));
|
||||
}
|
||||
|
||||
if(httpParams.size() > 0)
|
||||
{
|
||||
List<NameValuePair> paramPairs = new ArrayList<NameValuePair>();
|
||||
|
||||
for(String key : httpParams.keySet())
|
||||
paramPairs.add(new BasicNameValuePair(key, httpParams.get(key)));
|
||||
|
||||
((HttpPost)httpRequest).setEntity(new UrlEncodedFormEntity(paramPairs, "UTF-8"));
|
||||
}
|
||||
|
||||
HttpResponse response = httpclient.execute(httpRequest);
|
||||
HttpResponse response = httpclient.execute(httppost);
|
||||
HttpEntity entity = response.getEntity();
|
||||
if (entity != null)
|
||||
{
|
||||
@ -274,7 +206,8 @@ public class Miscellaneous extends Service
|
||||
catch(Exception e)
|
||||
{
|
||||
Miscellaneous.logEvent("e", "HTTP error", Log.getStackTraceString(e), 3);
|
||||
return "httpError";
|
||||
errorFound = true;
|
||||
return "httpError";
|
||||
}
|
||||
// finally
|
||||
// {
|
||||
@ -299,9 +232,25 @@ public class Miscellaneous extends Service
|
||||
@Override
|
||||
public IBinder onBind(Intent arg0)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
// public static void logEvent(String type, String header, String description)
|
||||
// {
|
||||
// if(type.equals("e"))
|
||||
// Log.e(header, description);
|
||||
//
|
||||
// if(type.equals("w"))
|
||||
// Log.w(header, description);
|
||||
//
|
||||
// if(type.equals("i"))
|
||||
// Log.i(header, description);
|
||||
//
|
||||
// if(Settings.writeLogFile)
|
||||
// writeToLogFile(type, header, description);
|
||||
// }
|
||||
|
||||
public static void logEvent(String type, String header, String description, int logLevel)
|
||||
{
|
||||
try
|
||||
@ -326,7 +275,7 @@ public class Miscellaneous extends Service
|
||||
{
|
||||
writeToLogFile(type, header, description);
|
||||
|
||||
if (!logCleanerRunning && Math.random() < 0.1) // tidy up with 10% probability
|
||||
if(!logCleanerRunning && Math.random() < 0.1) // tidy up with 10% probability
|
||||
{
|
||||
rotateLogFile(getLogFile());
|
||||
}
|
||||
@ -338,6 +287,7 @@ public class Miscellaneous extends Service
|
||||
{
|
||||
logCleanerRunning = true;
|
||||
|
||||
|
||||
long maxSizeInBytes = (long)Settings.logFileMaxSize * 1024 * 1024;
|
||||
|
||||
if(logFile.exists() && logFile.length() > (maxSizeInBytes))
|
||||
@ -526,16 +476,11 @@ public class Miscellaneous extends Service
|
||||
switch(direction)
|
||||
{
|
||||
case Trigger.directionEquals:
|
||||
if(Miscellaneous.isRegularExpression(needle))
|
||||
return haystack.matches(needle);
|
||||
else
|
||||
return haystack.equalsIgnoreCase(needle);
|
||||
return haystack.equalsIgnoreCase(needle);
|
||||
case Trigger.directionNotEquals:
|
||||
return !haystack.equalsIgnoreCase(needle);
|
||||
case Trigger.directionContains:
|
||||
return haystack.toLowerCase().contains(needle.toLowerCase());
|
||||
case Trigger.directionNotContains:
|
||||
return !haystack.toLowerCase().contains(needle.toLowerCase());
|
||||
case Trigger.directionStartsWith:
|
||||
return haystack.toLowerCase().startsWith(needle.toLowerCase());
|
||||
case Trigger.directionEndsWith:
|
||||
@ -545,7 +490,7 @@ public class Miscellaneous extends Service
|
||||
}
|
||||
}
|
||||
|
||||
public static int compareTimes(TimeObject time1, TimeObject time2)
|
||||
public static int compareTimes(Time time1, Time time2)
|
||||
{
|
||||
// Miscellaneous.logEvent("i", "TimeCompare", "To compare: " + time1.toString() + " / " + time2.toString());
|
||||
|
||||
@ -585,45 +530,7 @@ public class Miscellaneous extends Service
|
||||
|
||||
Miscellaneous.logEvent("i", "TimeCompare", "Default return code. Shouldn't be here.", 5);
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static int compareTimes(Calendar calOne, Calendar calTwo)
|
||||
{
|
||||
if(calOne.get(Calendar.HOUR_OF_DAY) == calTwo.get(Calendar.HOUR_OF_DAY) && calOne.get(Calendar.MINUTE) == calTwo.get((Calendar.MINUTE)))
|
||||
{
|
||||
// Miscellaneous.logEvent("i", "TimeCompare", "Times are equal.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(calOne.get(Calendar.HOUR_OF_DAY) > calTwo.get(Calendar.HOUR_OF_DAY))
|
||||
{
|
||||
// Miscellaneous.logEvent("i", "TimeCompare", "Time1 is bigger/later by hours.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(calOne.get(Calendar.HOUR_OF_DAY) < calTwo.get(Calendar.HOUR_OF_DAY))
|
||||
{
|
||||
// Miscellaneous.logEvent("i", "TimeCompare", "Time2 is bigger/later by hours.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(calOne.get(Calendar.HOUR_OF_DAY) == calTwo.get(Calendar.HOUR_OF_DAY))
|
||||
{
|
||||
if(calOne.get(Calendar.MINUTE) < calTwo.get(Calendar.MINUTE))
|
||||
{
|
||||
// Miscellaneous.logEvent("i", "TimeCompare", "Hours are equal. Time2 is bigger/later by minutes.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(calOne.get(Calendar.MINUTE) > calTwo.get(Calendar.MINUTE))
|
||||
{
|
||||
// Miscellaneous.logEvent("i", "TimeCompare", "Hours are equal. Time1 is bigger/later by minutes.");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
Miscellaneous.logEvent("i", "TimeCompare", "Default return code. Shouldn't be here.", 5);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
public static String convertStreamToString(InputStream is)
|
||||
@ -647,10 +554,7 @@ public class Miscellaneous extends Service
|
||||
returnContext = ActivityPermissions.getInstance().getApplicationContext();
|
||||
if(returnContext != null)
|
||||
return returnContext;
|
||||
|
||||
if(startupContext != null)
|
||||
return startupContext;
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -702,89 +606,32 @@ public class Miscellaneous extends Service
|
||||
}
|
||||
|
||||
if(source.contains("[serialnr]"))
|
||||
{
|
||||
if (Build.VERSION.SDK_INT > 8)
|
||||
if(Build.VERSION.SDK_INT > 8)
|
||||
source = source.replace("[serialnr]", Secure.getString(context.getContentResolver(), Build.SERIAL));
|
||||
else
|
||||
source = source.replace("[serialnr]", "serialUnknown");
|
||||
}
|
||||
|
||||
if(
|
||||
source.contains("[d]") ||
|
||||
source.contains("[m]") ||
|
||||
source.contains("[Y]") ||
|
||||
source.contains("[h]") ||
|
||||
source.contains("[H]") ||
|
||||
source.contains("[i]") ||
|
||||
source.contains("[s]") ||
|
||||
source.contains("[d]") |
|
||||
source.contains("[m]") |
|
||||
source.contains("[Y]") |
|
||||
source.contains("[h]") |
|
||||
source.contains("[H]") |
|
||||
source.contains("[i]") |
|
||||
source.contains("[s]") |
|
||||
source.contains("[ms]")
|
||||
)
|
||||
{
|
||||
Calendar cal = Calendar.getInstance();
|
||||
|
||||
if(source.contains("[d]"))
|
||||
{
|
||||
String result = String.valueOf(cal.get(Calendar.DAY_OF_MONTH));
|
||||
if(result.length() < 2)
|
||||
result = "0" + result;
|
||||
|
||||
source = source.replace("[d]", result);
|
||||
}
|
||||
|
||||
if(source.contains("[m]"))
|
||||
{
|
||||
String result = String.valueOf(cal.get(Calendar.MONTH) +1);
|
||||
if(result.length() < 2)
|
||||
result = "0" + result;
|
||||
|
||||
source = source.replace("[m]", result);
|
||||
}
|
||||
|
||||
if(source.contains("[Y]"))
|
||||
{
|
||||
source = source.replace("[Y]", String.valueOf(cal.get(Calendar.YEAR)));
|
||||
}
|
||||
|
||||
if(source.contains("[h]"))
|
||||
{
|
||||
String result = String.valueOf(cal.get(Calendar.HOUR));
|
||||
if(result.length() < 2)
|
||||
result = "0" + result;
|
||||
|
||||
source = source.replace("[h]", result);
|
||||
}
|
||||
|
||||
if(source.contains("[H]"))
|
||||
{
|
||||
String result = String.valueOf(cal.get(Calendar.HOUR_OF_DAY));
|
||||
if(result.length() < 2)
|
||||
result = "0" + result;
|
||||
|
||||
source = source.replace("[H]", result);
|
||||
}
|
||||
|
||||
if(source.contains("[i]"))
|
||||
{
|
||||
String result = String.valueOf(cal.get(Calendar.MINUTE));
|
||||
if(result.length() < 2)
|
||||
result = "0" + result;
|
||||
|
||||
source = source.replace("[i]", result);
|
||||
}
|
||||
|
||||
if(source.contains("[s]"))
|
||||
{
|
||||
String result = String.valueOf(cal.get(Calendar.SECOND));
|
||||
if(result.length() < 2)
|
||||
result = "0" + result;
|
||||
|
||||
source = source.replace("[s]", result);
|
||||
}
|
||||
|
||||
if(source.contains("[ms]"))
|
||||
{
|
||||
source = source.replace("[ms]", String.valueOf(cal.get(Calendar.MILLISECOND)));
|
||||
}
|
||||
source = source.replace("[d]", String.valueOf(cal.get(Calendar.DAY_OF_MONTH)));
|
||||
source = source.replace("[m]", String.valueOf(cal.get(Calendar.MONTH)));
|
||||
source = source.replace("[Y]", String.valueOf(cal.get(Calendar.YEAR)));
|
||||
source = source.replace("[h]", String.valueOf(cal.get(Calendar.HOUR)));
|
||||
source = source.replace("[H]", String.valueOf(cal.get(Calendar.HOUR_OF_DAY)));
|
||||
source = source.replace("[i]", String.valueOf(cal.get(Calendar.MINUTE)));
|
||||
source = source.replace("[s]", String.valueOf(cal.get(Calendar.SECOND)));
|
||||
source = source.replace("[ms]", String.valueOf(cal.get(Calendar.MILLISECOND)));
|
||||
}
|
||||
|
||||
if(source.contains("[notificationTitle]"))
|
||||
@ -794,7 +641,7 @@ public class Miscellaneous extends Service
|
||||
String notificationTitle = NotificationListener.getLastNotification().getTitle();
|
||||
|
||||
if (notificationTitle != null && notificationTitle.length() > 0)
|
||||
source = source.replace("[notificationTitle]", escapeStringForUrl(notificationTitle));
|
||||
source = source.replace("[notificationTitle]", notificationTitle);
|
||||
else
|
||||
{
|
||||
source = source.replace("[notificationTitle]", "notificationTitle unknown");
|
||||
@ -815,7 +662,7 @@ public class Miscellaneous extends Service
|
||||
String notificationText = NotificationListener.getLastNotification().getText();
|
||||
|
||||
if (notificationText != null && notificationText.length() > 0)
|
||||
source = source.replace("[notificationText]", escapeStringForUrl(notificationText));
|
||||
source = source.replace("[notificationText]", notificationText);
|
||||
else
|
||||
{
|
||||
source = source.replace("[notificationText]", "notificationText unknown");
|
||||
@ -828,98 +675,6 @@ public class Miscellaneous extends Service
|
||||
Miscellaneous.logEvent("w", "Variable replacement", "lastNotification was empty.", 3);
|
||||
}
|
||||
}
|
||||
|
||||
if(source.contains("[last_trigger_url_result]"))
|
||||
{
|
||||
try
|
||||
{
|
||||
source = source.replace("[last_trigger_url_result]", AutomationService.getInstance().getVariableMap().get("last_trigger_url_result"));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Miscellaneous.logEvent("w", "Variable replacement", "Error replacing variable last_trigger_url_result.", 3);
|
||||
}
|
||||
}
|
||||
|
||||
if(source.contains("[last_run_executable_exit_code]"))
|
||||
{
|
||||
try
|
||||
{
|
||||
source = source.replace("[last_run_executable_exit_code]", AutomationService.getInstance().getVariableMap().get("last_run_executable_exit_code"));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Miscellaneous.logEvent("w", "Variable replacement", "Error replacing variable last_run_executable_exit_code.", 3);
|
||||
}
|
||||
}
|
||||
|
||||
if(source.contains("[last_run_executable_output]"))
|
||||
{
|
||||
try
|
||||
{
|
||||
source = source.replace("[last_run_executable_output]", AutomationService.getInstance().getVariableMap().get("last_run_executable_output"));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Miscellaneous.logEvent("w", "Variable replacement", "Error replacing variable last_run_executable_output.", 3);
|
||||
}
|
||||
}
|
||||
|
||||
if(source.contains("[last_calendar_title]"))
|
||||
{
|
||||
try
|
||||
{
|
||||
source = source.replace("[last_calendar_title]", CalendarReceiver.getLastTriggeringEvent().title);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Miscellaneous.logEvent("w", "Variable replacement", "Error replacing variable last_calendar_title.", 3);
|
||||
}
|
||||
}
|
||||
|
||||
if(source.contains("[last_calendar_description]"))
|
||||
{
|
||||
try
|
||||
{
|
||||
source = source.replace("[last_calendar_description]", CalendarReceiver.getLastTriggeringEvent().description);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Miscellaneous.logEvent("w", "Variable replacement", "Error replacing variable last_calendar_description.", 3);
|
||||
}
|
||||
}
|
||||
|
||||
if(source.contains("[last_calendar_location]"))
|
||||
{
|
||||
try
|
||||
{
|
||||
source = source.replace("[last_calendar_location]", CalendarReceiver.getLastTriggeringEvent().location);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Miscellaneous.logEvent("w", "Variable replacement", "Error replacing variable last_calendar_location.", 3);
|
||||
}
|
||||
}
|
||||
|
||||
while(source.contains("[variable-"))
|
||||
{
|
||||
int pos1 = source.indexOf("[variable-");
|
||||
int pos2 = source.indexOf("]", pos1);
|
||||
|
||||
int posA = pos1 + "[variable-".length();
|
||||
int posB = source.indexOf("]", posA);
|
||||
|
||||
String variableName = source.substring(posA, posB);
|
||||
|
||||
String replacement;
|
||||
|
||||
if(AutomationService.getInstance().variableMap.containsKey(variableName))
|
||||
replacement = AutomationService.getInstance().variableMap.get(variableName);
|
||||
else
|
||||
replacement = "unknownVariable";
|
||||
|
||||
source = source.substring(0, pos1) + escapeStringForUrl(replacement) + source.substring(pos2 +1);
|
||||
}
|
||||
|
||||
// Miscellaneous.logEvent("i", "URL after replace", source);
|
||||
|
||||
@ -947,7 +702,7 @@ public class Miscellaneous extends Service
|
||||
alertDialog.setTitle(title);
|
||||
alertDialog.setMessage(message);
|
||||
|
||||
alertDialog.setPositiveButton(context.getResources().getString(R.string.ok), new DialogInterface.OnClickListener()
|
||||
alertDialog.setPositiveButton("Ok", new DialogInterface.OnClickListener()
|
||||
{
|
||||
public void onClick(DialogInterface dialog, int whichButton)
|
||||
{
|
||||
@ -955,6 +710,14 @@ public class Miscellaneous extends Service
|
||||
}
|
||||
});
|
||||
|
||||
// alertDialog.setNegativeButton(context.getResources().getString(R.string.cancel), new DialogInterface.OnClickListener()
|
||||
// {
|
||||
// public void onClick(DialogInterface dialog, int whichButton)
|
||||
// {
|
||||
// // Canceled.
|
||||
// }
|
||||
// });
|
||||
|
||||
return alertDialog.create();
|
||||
}
|
||||
|
||||
@ -981,43 +744,39 @@ public class Miscellaneous extends Service
|
||||
*
|
||||
* @return <code>true</code> if the device is rooted, <code>false</code> otherwise.
|
||||
*/
|
||||
public static boolean isPhoneRooted()
|
||||
{
|
||||
try
|
||||
{
|
||||
return Shell.SU.available();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
// get from build info
|
||||
String buildTags = Build.TAGS;
|
||||
if (buildTags != null && buildTags.contains("test-keys"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public static boolean isPhoneRooted()
|
||||
{
|
||||
// if(true)
|
||||
// return true;
|
||||
|
||||
// check if /system/app/Superuser.apk is present
|
||||
try
|
||||
{
|
||||
File file = new File("/system/app/Superuser.apk");
|
||||
if (file.exists())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception e1)
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
// get from build info
|
||||
String buildTags = Build.TAGS;
|
||||
if (buildTags != null && buildTags.contains("test-keys"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// try executing commands
|
||||
return canExecuteCommand("/system/xbin/which su")
|
||||
||
|
||||
canExecuteCommand("/system/bin/which su")
|
||||
||
|
||||
canExecuteCommand("which su");
|
||||
}
|
||||
}
|
||||
// check if /system/app/Superuser.apk is present
|
||||
try
|
||||
{
|
||||
File file = new File("/system/app/Superuser.apk");
|
||||
if (file.exists())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception e1)
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
|
||||
// try executing commands
|
||||
return canExecuteCommand("/system/xbin/which su")
|
||||
||
|
||||
canExecuteCommand("/system/bin/which su")
|
||||
||
|
||||
canExecuteCommand("which su");
|
||||
}
|
||||
|
||||
// executes a command on the system
|
||||
private static boolean canExecuteCommand(String command)
|
||||
@ -1035,74 +794,64 @@ public class Miscellaneous extends Service
|
||||
|
||||
return executedSuccesfully;
|
||||
}
|
||||
public static boolean isNumericDecimal(String strNum)
|
||||
{
|
||||
if (strNum == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
double d = Double.parseDouble(strNum);
|
||||
}
|
||||
catch (NumberFormatException nfe)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isNumeric(String str)
|
||||
{
|
||||
return str.matches("-?\\d+(\\.\\d+)?"); //match a number with optional '-' and decimal.
|
||||
}
|
||||
public static boolean isNumeric(String str)
|
||||
{
|
||||
return str.matches("-?\\d+(\\.\\d+)?"); //match a number with optional '-' and decimal.
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables the SSL certificate checking for new instances of {@link HttpsURLConnection} This has been created to
|
||||
* aid testing on a local box, not for use on production.
|
||||
*/
|
||||
private static void disableSSLCertificateChecking()
|
||||
{
|
||||
try
|
||||
{
|
||||
SSLSocketFactory ssf = null;
|
||||
|
||||
try
|
||||
{
|
||||
SSLContext ctx = SSLContext.getInstance("TLS");
|
||||
|
||||
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
|
||||
trustStore.load(null, null);
|
||||
ssf = new MySSLSocketFactoryInsecure(trustStore);
|
||||
ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
|
||||
ctx.init(null, null, null);
|
||||
private static void disableSSLCertificateChecking()
|
||||
{
|
||||
try
|
||||
{
|
||||
SSLSocketFactory ssf = null;
|
||||
|
||||
try
|
||||
{
|
||||
SSLContext ctx = SSLContext.getInstance("TLS");
|
||||
|
||||
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
|
||||
trustStore.load(null, null);
|
||||
ssf = new MySSLSocketFactoryInsecure(trustStore);
|
||||
ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
|
||||
ctx.init(null, null, null);
|
||||
|
||||
// return new DefaultHttpClient(ccm, client.getParams());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
// return null;
|
||||
}
|
||||
|
||||
// Install the all-trusting trust manager
|
||||
SSLContext sc = SSLContext.getInstance("TLS");
|
||||
sc.init(null, getInsecureTrustManager(), new java.security.SecureRandom());
|
||||
}
|
||||
|
||||
// Install the all-trusting trust manager
|
||||
SSLContext sc = SSLContext.getInstance("TLS");
|
||||
sc.init(null, getInsecureTrustManager(), new java.security.SecureRandom());
|
||||
// HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
|
||||
// HttpsURLConnection.setDefaultSSLSocketFactory(ssf);
|
||||
|
||||
// Install the all-trusting host verifier
|
||||
HttpsURLConnection.setDefaultHostnameVerifier(getInsecureHostnameVerifier());
|
||||
HttpsURLConnection.setDefaultHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
|
||||
}
|
||||
catch (KeyManagementException e)
|
||||
{
|
||||
Miscellaneous.logEvent("e", "SSL", Log.getStackTraceString(e), 4);
|
||||
}
|
||||
catch (NoSuchAlgorithmException e)
|
||||
{
|
||||
Miscellaneous.logEvent("e", "SSL", Log.getStackTraceString(e), 4);
|
||||
}
|
||||
|
||||
// Install the all-trusting host verifier
|
||||
HttpsURLConnection.setDefaultHostnameVerifier(getInsecureHostnameVerifier());
|
||||
HttpsURLConnection.setDefaultHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
|
||||
}
|
||||
catch (KeyManagementException e)
|
||||
{
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (NoSuchAlgorithmException e)
|
||||
{
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static TrustManager[] getInsecureTrustManager()
|
||||
@ -1320,12 +1069,7 @@ public class Miscellaneous extends Service
|
||||
builder.setOnlyAlertOnce(true);
|
||||
|
||||
if(Settings.showIconWhenServiceIsRunning && notificationChannelId.equals(AutomationService.NOTIFICATION_CHANNEL_ID_SERVICE))
|
||||
{
|
||||
if(BuildConfig.FLAVOR.equals(AutomationService.flavor_name_googleplay))
|
||||
builder.setSmallIcon(R.drawable.crane);
|
||||
else
|
||||
builder.setSmallIcon(R.drawable.ic_launcher);
|
||||
}
|
||||
builder.setSmallIcon(R.drawable.ic_launcher);
|
||||
else if(!notificationChannelId.equals(AutomationService.NOTIFICATION_CHANNEL_ID_SERVICE))
|
||||
builder.setSmallIcon(R.drawable.info);
|
||||
|
||||
@ -1635,7 +1379,7 @@ public class Miscellaneous extends Service
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean restrictedFeaturesConfiguredFdroid()
|
||||
public static boolean restrictedFeaturesConfigured()
|
||||
{
|
||||
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.activityDetection))
|
||||
{
|
||||
@ -1652,17 +1396,6 @@ public class Miscellaneous extends Service
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean restrictedFeaturesConfiguredGoogle()
|
||||
{
|
||||
if(Rule.isAnyRuleUsing(Action.Action_Enum.startPhoneCall) || Rule.isAnyRuleUsing(Action.Action_Enum.stopPhoneCall))
|
||||
{
|
||||
if(BuildConfig.FLAVOR.equals(AutomationService.flavor_name_googleplay))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Element getXmlTree(String inputString) throws SAXException, IOException, ParserConfigurationException
|
||||
{
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
@ -1893,7 +1626,7 @@ public class Miscellaneous extends Service
|
||||
{
|
||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
|
||||
{
|
||||
if (BuildConfig.FLAVOR.equalsIgnoreCase(AutomationService.flavor_name_googleplay))
|
||||
if (BuildConfig.FLAVOR.equalsIgnoreCase("googlePlayFlavor"))
|
||||
{
|
||||
if(checkExistingRules)
|
||||
{
|
||||
@ -2026,12 +1759,13 @@ public class Miscellaneous extends Service
|
||||
|
||||
public static boolean comparePhoneNumbers(String number1, String number2)
|
||||
{
|
||||
if(Build.VERSION.SDK_INT > Build.VERSION_CODES.S)
|
||||
/* To be activated when Android S SDK comes out
|
||||
if(Build.VERSION.SDK_INT > Build.VERSION_CODES.Q)
|
||||
{
|
||||
TelephonyManager tm = (TelephonyManager)Miscellaneous.getAnyContext().getSystemService(Context.TELEPHONY_SERVICE);
|
||||
return PhoneNumberUtils.areSamePhoneNumber(number1, number2, tm.getNetworkCountryIso());
|
||||
}
|
||||
else
|
||||
else*/
|
||||
return PhoneNumberUtils.compare(number1, number2);
|
||||
}
|
||||
|
||||
@ -2165,64 +1899,4 @@ public class Miscellaneous extends Service
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int getTargetSDK(Context context)
|
||||
{
|
||||
return context.getApplicationContext().getApplicationInfo().targetSdkVersion;
|
||||
}
|
||||
|
||||
public static void setDisplayLanguage(Context context)
|
||||
{
|
||||
if(!Settings.displayLanguage.equals(Settings.default_displayLanguage))
|
||||
{
|
||||
Locale myLocale;
|
||||
|
||||
if(Settings.displayLanguage.contains("_"))
|
||||
{
|
||||
String[] parts = Settings.displayLanguage.split("_");
|
||||
myLocale = new Locale(parts[0], parts[1]);
|
||||
}
|
||||
else
|
||||
myLocale = new Locale(Settings.displayLanguage);
|
||||
|
||||
Resources res = context.getResources();
|
||||
DisplayMetrics dm = res.getDisplayMetrics();
|
||||
Configuration conf = res.getConfiguration();
|
||||
conf.locale = myLocale;
|
||||
res.updateConfiguration(conf, dm);
|
||||
//Intent refresh = new Intent(this, AndroidLocalize.class);
|
||||
//finish();
|
||||
//startActivity(refresh);
|
||||
}
|
||||
}
|
||||
|
||||
public static String escapeStringForUrl(String input)
|
||||
{
|
||||
String output;
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
|
||||
{
|
||||
try
|
||||
{
|
||||
output = URLEncoder.encode(input, String.valueOf(StandardCharsets.UTF_8));
|
||||
}
|
||||
catch (UnsupportedEncodingException e)
|
||||
{
|
||||
Miscellaneous.logEvent("e", "URLEncoder", "Error encoding string for URL. Leaving as it is. Error details: " + Log.getStackTraceString(e), 3);
|
||||
output = input;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
output = Uri.encode(input);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
public static String getCallingMethodName()
|
||||
{
|
||||
StackTraceElement callingFrame = Thread.currentThread().getStackTrace()[4];
|
||||
return callingFrame.getMethodName();
|
||||
}
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
package com.jens.automation2;
|
||||
|
||||
import android.accessibilityservice.AccessibilityService;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
import android.view.Display;
|
||||
import android.view.accessibility.AccessibilityEvent;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.RequiresApi;
|
||||
|
||||
public class MyAccessibilityService extends AccessibilityService
|
||||
{
|
||||
static MyAccessibilityService instance;
|
||||
|
||||
public static MyAccessibilityService getInstance()
|
||||
{
|
||||
if(instance == null)
|
||||
{
|
||||
instance = new MyAccessibilityService();
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccessibilityEvent(AccessibilityEvent accessibilityEvent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInterrupt()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate()
|
||||
{
|
||||
super.onCreate();
|
||||
instance = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onServiceConnected()
|
||||
{
|
||||
super.onServiceConnected();
|
||||
Miscellaneous.logEvent("i", "Accessibility service", "Service started.", 4);
|
||||
}
|
||||
}
|
@ -79,7 +79,7 @@ public class News
|
||||
if (!(new File(filePath)).exists() || Settings.lastNewsPolltime == Settings.default_lastNewsPolltime || now.getTimeInMillis() >= Settings.lastNewsPolltime + (long)(Settings.newsDisplayForXDays * 24 * 60 * 60 * 1000))
|
||||
{
|
||||
String newsUrl = "https://server47.de/automation/appNews.php";
|
||||
newsContent = Miscellaneous.downloadURL(newsUrl, null, null, ActivityManageActionTriggerUrl.methodGet, null);
|
||||
newsContent = Miscellaneous.downloadURL(newsUrl, null, null);
|
||||
|
||||
// Cache content to local storage
|
||||
if(Miscellaneous.writeStringToFile(filePath, newsContent))
|
||||
|
@ -64,7 +64,7 @@ public class PointOfInterest implements Comparable<PointOfInterest>
|
||||
public void setName(String desiredName)
|
||||
{
|
||||
this.oldName = this.name;
|
||||
this.name = desiredName.trim();
|
||||
this.name = desiredName;
|
||||
}
|
||||
|
||||
public Location getLocation()
|
||||
@ -421,18 +421,14 @@ public class PointOfInterest implements Comparable<PointOfInterest>
|
||||
public boolean create(Context context)
|
||||
{
|
||||
for(PointOfInterest poi : PointOfInterest.pointOfInterestCollection)
|
||||
{
|
||||
if (poi.getName().equals(this.getName()))
|
||||
if(poi.getName().equals(this.getName()))
|
||||
{
|
||||
Toast.makeText(context, context.getResources().getString(R.string.anotherPoiByThatName), Toast.LENGTH_LONG).show();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if(plausibilityCheck())
|
||||
{
|
||||
Miscellaneous.logEvent("i", "Creating POI", this.toStringLong(), 3);
|
||||
|
||||
PointOfInterest.pointOfInterestCollection.add(this);
|
||||
PointOfInterest.writePoisToFile();
|
||||
|
||||
@ -494,10 +490,8 @@ public class PointOfInterest implements Comparable<PointOfInterest>
|
||||
Check for change of rule name END
|
||||
*/
|
||||
|
||||
if(plausibilityCheck())
|
||||
if (plausibilityCheck())
|
||||
{
|
||||
Miscellaneous.logEvent("i", "Changing POI", "Old name: " + this.oldName + ", new data: " + this.toStringLong(), 3);
|
||||
|
||||
if(PointOfInterest.writePoisToFile())
|
||||
{
|
||||
AutomationService service = AutomationService.getInstance();
|
||||
@ -694,16 +688,22 @@ public class PointOfInterest implements Comparable<PointOfInterest>
|
||||
@Override
|
||||
public void onProviderDisabled(String provider)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProviderEnabled(String provider)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStatusChanged(String provider, int status, Bundle extras)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,12 +3,13 @@ package com.jens.automation2;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.media.AudioManager;
|
||||
import android.media.Ringtone;
|
||||
import android.media.RingtoneManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.provider.MediaStore;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
@ -42,13 +43,13 @@ public class Profile implements Comparable<Profile>
|
||||
protected int volumeAlarms;
|
||||
|
||||
protected boolean changeIncomingCallsRingtone;
|
||||
protected String incomingCallsRingtone;
|
||||
protected File incomingCallsRingtone;
|
||||
|
||||
protected boolean changeVibrateWhenRinging;
|
||||
protected boolean vibrateWhenRinging;
|
||||
|
||||
protected boolean changeNotificationRingtone;
|
||||
protected String notificationRingtone;
|
||||
protected File notificationRingtone;
|
||||
|
||||
protected boolean changeAudibleSelection;
|
||||
protected boolean audibleSelection;
|
||||
@ -63,7 +64,7 @@ public class Profile implements Comparable<Profile>
|
||||
public void setName(String name)
|
||||
{
|
||||
this.oldName = this.name;
|
||||
this.name = name.trim();
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
@ -172,11 +173,11 @@ public class Profile implements Comparable<Profile>
|
||||
return changeIncomingCallsRingtone;
|
||||
}
|
||||
|
||||
public void setIncomingCallsRingtone(String incomingCallsRingtone)
|
||||
public void setIncomingCallsRingtone(File incomingCallsRingtone)
|
||||
{
|
||||
this.incomingCallsRingtone = incomingCallsRingtone;
|
||||
}
|
||||
public String getIncomingCallsRingtone()
|
||||
public File getIncomingCallsRingtone()
|
||||
{
|
||||
return incomingCallsRingtone;
|
||||
}
|
||||
@ -208,11 +209,11 @@ public class Profile implements Comparable<Profile>
|
||||
return changeNotificationRingtone;
|
||||
}
|
||||
|
||||
public void setNotificationRingtone(String notificationsRingtone)
|
||||
public void setNotificationRingtone(File notificationsRingtone)
|
||||
{
|
||||
this.notificationRingtone = notificationsRingtone;
|
||||
}
|
||||
public String getNotificationRingtone()
|
||||
public File getNotificationRingtone()
|
||||
{
|
||||
return notificationRingtone;
|
||||
}
|
||||
@ -293,69 +294,53 @@ public class Profile implements Comparable<Profile>
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean applyRingTone(String ringtoneFile, int ringtoneType, Context context)
|
||||
private boolean applyRingTone(File ringtoneFile, int ringtoneType, Context context)
|
||||
{
|
||||
Miscellaneous.logEvent("i", "Profile", "Request to set ringtone to " + ringtoneFile, 3);
|
||||
Miscellaneous.logEvent("i", "Profile", "Request to set ringtone to " + ringtoneFile.getAbsolutePath(), 3);
|
||||
|
||||
// if(!ringtoneFile.exists() || !ringtoneFile.canRead())
|
||||
// {
|
||||
// String message = "Ringtone file does not exist or cannot read it: " + ringtoneFile.getAbsolutePath();
|
||||
// Miscellaneous.logEvent("i", "Profile", message, 3);
|
||||
// Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// Set by URI
|
||||
if(ringtoneFile.contains("//"))
|
||||
if(!ringtoneFile.exists() || !ringtoneFile.canRead())
|
||||
{
|
||||
Uri target = Uri.parse(ringtoneFile);
|
||||
RingtoneManager.setActualDefaultRingtoneUri(context, ringtoneType, target);
|
||||
Miscellaneous.logEvent("i", "Profile", "Ringtone set to: " + ringtoneFile, 1);
|
||||
return true;
|
||||
} // Set by filepath
|
||||
else
|
||||
{
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(MediaStore.MediaColumns.DATA, ringtoneFile);
|
||||
values.put(MediaStore.MediaColumns.TITLE, ringtoneFile);
|
||||
//values.put(MediaStore.MediaColumns.TITLE, ringtoneFile.getName());
|
||||
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3");
|
||||
values.put(MediaStore.MediaColumns.SIZE, ringtoneFile.length());
|
||||
values.put(MediaStore.Audio.Media.IS_RINGTONE, ringtoneType == RingtoneManager.TYPE_RINGTONE);
|
||||
values.put(MediaStore.Audio.Media.IS_NOTIFICATION, ringtoneType == RingtoneManager.TYPE_NOTIFICATION);
|
||||
values.put(MediaStore.Audio.Media.IS_ALARM, false);
|
||||
values.put(MediaStore.Audio.Media.IS_MUSIC, false);
|
||||
|
||||
try
|
||||
{
|
||||
Uri newRingTone = null;
|
||||
|
||||
Uri existingRingTone = MediaStore.Audio.Media.getContentUriForPath(ringtoneFile);
|
||||
|
||||
try
|
||||
{
|
||||
if (existingRingTone != null)
|
||||
context.getContentResolver().delete(existingRingTone, MediaStore.MediaColumns.DATA + "=\"" + ringtoneFile + "\"", null);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Miscellaneous.logEvent("w","Delete file from ringtones", "Deleting ringtone from library failed: " + Log.getStackTraceString(e), 2);
|
||||
}
|
||||
|
||||
newRingTone = context.getContentResolver().insert(existingRingTone, values);
|
||||
|
||||
RingtoneManager.setActualDefaultRingtoneUri(context, ringtoneType, newRingTone);
|
||||
|
||||
Miscellaneous.logEvent("i", "Profile", "Ringtone set to: " + newRingTone.toString(), 1);
|
||||
return true;
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
String message = "Error setting ringtone: " + Log.getStackTraceString(t);
|
||||
Miscellaneous.logEvent("e", "Profile", message, 1);
|
||||
}
|
||||
String message = "Ringtone file does not exist or cannot read it: " + ringtoneFile.getAbsolutePath();
|
||||
Miscellaneous.logEvent("i", "Profile", message, 3);
|
||||
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(MediaStore.MediaColumns.DATA, ringtoneFile.getAbsolutePath());
|
||||
values.put(MediaStore.MediaColumns.TITLE, ringtoneFile.getName());
|
||||
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3");
|
||||
values.put(MediaStore.MediaColumns.SIZE, ringtoneFile.length());
|
||||
values.put(MediaStore.Audio.Media.IS_RINGTONE, ringtoneType == RingtoneManager.TYPE_RINGTONE);
|
||||
values.put(MediaStore.Audio.Media.IS_NOTIFICATION, ringtoneType == RingtoneManager.TYPE_NOTIFICATION);
|
||||
values.put(MediaStore.Audio.Media.IS_ALARM, false);
|
||||
values.put(MediaStore.Audio.Media.IS_MUSIC, false);
|
||||
|
||||
try
|
||||
{
|
||||
Uri newRingTone = null;
|
||||
|
||||
//TODO: This part needs to be made compatible with Android 11 and above.
|
||||
if(Build.VERSION.SDK_INT > 30)
|
||||
{
|
||||
Uri existingRingTone = MediaStore.Audio.Media.getContentUriForPath(ringtoneFile.getAbsolutePath());
|
||||
|
||||
if (existingRingTone != null)
|
||||
context.getContentResolver().delete(existingRingTone, MediaStore.MediaColumns.DATA + "=\"" + ringtoneFile.getAbsolutePath() + "\"", null);
|
||||
|
||||
newRingTone = context.getContentResolver().insert(existingRingTone, values);
|
||||
}
|
||||
|
||||
RingtoneManager.setActualDefaultRingtoneUri(context, ringtoneType, newRingTone);
|
||||
Miscellaneous.logEvent("i", "Profile", "Ringtone set to: " + newRingTone.toString(), 1);
|
||||
return true;
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
String message = "Error setting ringtone: " + Log.getStackTraceString(t);
|
||||
Miscellaneous.logEvent("e", "Profile", message, 1);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -524,7 +509,7 @@ public class Profile implements Comparable<Profile>
|
||||
Actions.setSound(context, soundMode);
|
||||
|
||||
if(changeDndMode)
|
||||
Actions.setDoNotDisturb(context, dndMode);
|
||||
Actions.setDND(context, dndMode);
|
||||
|
||||
if(changeVolumeMusicVideoGameMedia)
|
||||
am.setStreamVolume(AudioManager.STREAM_MUSIC, volumeMusic, AudioManager.FLAG_PLAY_SOUND);
|
||||
@ -585,17 +570,17 @@ public class Profile implements Comparable<Profile>
|
||||
}
|
||||
finally
|
||||
{
|
||||
Miscellaneous.logEvent("i", "Profile", "Checking for applicable rules after profile " + this.getName() + " has been activated.", 2);
|
||||
Miscellaneous.logEvent("i", "POI", "Checking for applicable rule after profile " + this.getName() + " has been activated.", 2);
|
||||
List<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.profileActive);
|
||||
for(int i=0; i<ruleCandidates.size(); i++)
|
||||
{
|
||||
if(ruleCandidates.get(i).haveEnoughPermissions() && ruleCandidates.get(i).getsGreenLight(AutomationService.getInstance()))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "Profile", "Rule " + ruleCandidates.get(i).getName() + " applies after " + this.getName() + " has been activated.", 2);
|
||||
Miscellaneous.logEvent("i", "POI", "Rule " + ruleCandidates.get(i).getName() + " applies after " + this.getName() + " has been activated.", 2);
|
||||
ruleCandidates.get(i).activate(AutomationService.getInstance(), false);
|
||||
}
|
||||
}
|
||||
Miscellaneous.logEvent("i", "Profile", "Done checking for applicable rules after profile " + this.getName() + " has been activated.", 2);
|
||||
Miscellaneous.logEvent("i", "POI", "Done checking for applicable rule after profile " + this.getName() + " has been activated.", 2);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -1,13 +1,10 @@
|
||||
package com.jens.automation2;
|
||||
|
||||
import android.Manifest;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
|
||||
import com.jens.automation2.location.CellLocationChangedReceiver;
|
||||
import com.jens.automation2.location.WifiBroadcastReceiver;
|
||||
import com.jens.automation2.receivers.BroadcastListener;
|
||||
import com.jens.automation2.receivers.CalendarReceiver;
|
||||
import com.jens.automation2.receivers.DateTimeListener;
|
||||
import com.jens.automation2.receivers.AutomationListenerInterface;
|
||||
import com.jens.automation2.receivers.BatteryReceiver;
|
||||
@ -20,8 +17,6 @@ import com.jens.automation2.receivers.NoiseListener;
|
||||
import com.jens.automation2.receivers.PhoneStatusListener;
|
||||
import com.jens.automation2.receivers.ProcessListener;
|
||||
import com.jens.automation2.receivers.ScreenStateReceiver;
|
||||
import com.jens.automation2.receivers.SubSystemStateReceiver;
|
||||
import com.jens.automation2.receivers.TetheringReceiver;
|
||||
import com.jens.automation2.receivers.TimeZoneListener;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
@ -63,8 +58,7 @@ public class ReceiverCoordinator
|
||||
ProcessListener.class,
|
||||
MediaPlayerListener.class,
|
||||
ScreenStateReceiver.class,
|
||||
TimeZoneListener.class,
|
||||
TetheringReceiver.class
|
||||
TimeZoneListener.class
|
||||
};
|
||||
}
|
||||
catch (ClassNotFoundException e)
|
||||
@ -73,7 +67,6 @@ public class ReceiverCoordinator
|
||||
DateTimeListener.class,
|
||||
BatteryReceiver.class,
|
||||
BluetoothReceiver.class,
|
||||
BroadcastListener.class,
|
||||
ConnectivityReceiver.class,
|
||||
DeviceOrientationListener.class,
|
||||
HeadphoneJackListener.class,
|
||||
@ -82,8 +75,7 @@ public class ReceiverCoordinator
|
||||
PhoneStatusListener.class,
|
||||
ProcessListener.class,
|
||||
ScreenStateReceiver.class,
|
||||
TimeZoneListener.class,
|
||||
TetheringReceiver.class
|
||||
TimeZoneListener.class
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -147,8 +139,7 @@ public class ReceiverCoordinator
|
||||
}
|
||||
|
||||
// startPhoneStateListener
|
||||
if(!BuildConfig.FLAVOR.equals(AutomationService.flavor_name_googleplay))
|
||||
PhoneStatusListener.startPhoneStatusListener(AutomationService.getInstance()); // also used to mute anouncements during calls
|
||||
PhoneStatusListener.startPhoneStatusListener(AutomationService.getInstance()); // also used to mute anouncements during calls
|
||||
|
||||
// startConnectivityReceiver
|
||||
ConnectivityReceiver.startConnectivityReceiver(AutomationService.getInstance());
|
||||
@ -172,10 +163,6 @@ public class ReceiverCoordinator
|
||||
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.noiseLevel))
|
||||
NoiseListener.startNoiseListener(AutomationService.getInstance());
|
||||
|
||||
// startBroadcastListener
|
||||
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.broadcastReceived))
|
||||
BroadcastListener.getInstance().startListener(AutomationService.getInstance());
|
||||
|
||||
// startProcessListener
|
||||
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.process_started_stopped))
|
||||
ProcessListener.startProcessListener(AutomationService.getInstance());
|
||||
@ -183,12 +170,6 @@ public class ReceiverCoordinator
|
||||
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.deviceOrientation))
|
||||
DeviceOrientationListener.getInstance().startListener(AutomationService.getInstance());
|
||||
|
||||
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.tethering))
|
||||
TetheringReceiver.getInstance().startListener(AutomationService.getInstance());
|
||||
|
||||
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.subSystemState))
|
||||
SubSystemStateReceiver.getInstance().startListener(AutomationService.getInstance());
|
||||
|
||||
try
|
||||
{
|
||||
Class testClass = Class.forName(ActivityManageRule.activityDetectionClassPath);
|
||||
@ -212,9 +193,6 @@ public class ReceiverCoordinator
|
||||
|
||||
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.screenState))
|
||||
ScreenStateReceiver.startScreenStateReceiver(AutomationService.getInstance());
|
||||
|
||||
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.calendarEvent) && ActivityPermissions.isPermissionDeclaratedInManifest(AutomationService.getInstance(), Manifest.permission.READ_CALENDAR) && ActivityPermissions.havePermission(Manifest.permission.READ_CALENDAR, AutomationService.getInstance()))
|
||||
CalendarReceiver.startCalendarReceiver(AutomationService.getInstance());
|
||||
}
|
||||
|
||||
public static void stopAllReceivers()
|
||||
@ -228,19 +206,16 @@ public class ReceiverCoordinator
|
||||
TimeZoneListener.stopTimeZoneListener();
|
||||
DateTimeListener.stopAlarmListener(AutomationService.getInstance());
|
||||
NoiseListener.stopNoiseListener();
|
||||
BroadcastListener.getInstance().stopListener(AutomationService.getInstance());
|
||||
ProcessListener.stopProcessListener(AutomationService.getInstance());
|
||||
MediaPlayerListener.getInstance().stopListener(AutomationService.getInstance());
|
||||
DeviceOrientationListener.getInstance().stopListener(AutomationService.getInstance());
|
||||
TetheringReceiver.getInstance().stopListener(AutomationService.getInstance());
|
||||
SubSystemStateReceiver.getInstance().stopListener(AutomationService.getInstance());
|
||||
|
||||
try
|
||||
{
|
||||
Class testClass = Class.forName(ActivityManageRule.activityDetectionClassPath);
|
||||
Miscellaneous.runMethodReflective("ActivityDetectionReceiver", "stopActivityDetectionReceiver", null);
|
||||
}
|
||||
catch(Exception e)
|
||||
catch(ClassNotFoundException e)
|
||||
{
|
||||
// Nothing to do, just not stopping this one.
|
||||
}
|
||||
@ -248,7 +223,6 @@ public class ReceiverCoordinator
|
||||
BluetoothReceiver.stopBluetoothReceiver();
|
||||
HeadphoneJackListener.getInstance().stopListener(AutomationService.getInstance());
|
||||
DeviceOrientationListener.getInstance().stopListener(AutomationService.getInstance());
|
||||
CalendarReceiver.getInstance().stopListener(AutomationService.getInstance());
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
@ -292,17 +266,6 @@ public class ReceiverCoordinator
|
||||
NoiseListener.stopNoiseListener();
|
||||
}
|
||||
|
||||
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.broadcastReceived))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "LocationProvider", "Starting BroadcastReceiver because used in a new/changed rule.", 4);
|
||||
BroadcastListener.getInstance().startListener(AutomationService.getInstance());
|
||||
}
|
||||
else
|
||||
{
|
||||
Miscellaneous.logEvent("i", "LocationProvider", "Shutting down BroadcastReceiver because not used in any rule.", 4);
|
||||
BroadcastListener.getInstance().stopListener(AutomationService.getInstance());
|
||||
}
|
||||
|
||||
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.process_started_stopped))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "LocationProvider", "Starting ProcessListener because used in a new/changed rule.", 4);
|
||||
@ -337,7 +300,7 @@ public class ReceiverCoordinator
|
||||
MediaPlayerListener.getInstance().stopListener(AutomationService.getInstance());
|
||||
}
|
||||
|
||||
if(!BuildConfig.FLAVOR.equalsIgnoreCase(AutomationService.flavor_name_fdroid))
|
||||
if(!BuildConfig.FLAVOR.equalsIgnoreCase("fdroidFlavor"))
|
||||
{
|
||||
if (Rule.isAnyRuleUsing(Trigger.Trigger_Enum.activityDetection))
|
||||
{
|
||||
@ -398,11 +361,11 @@ public class ReceiverCoordinator
|
||||
}
|
||||
}
|
||||
|
||||
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.headsetPlugged))
|
||||
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.headsetPlugged))
|
||||
{
|
||||
if(!HeadphoneJackListener.isHeadphoneJackListenerActive())
|
||||
{
|
||||
Miscellaneous.logEvent("i", "HeadphoneJackListener", "Starting HeadphoneJackListener because used in a new/changed rule.", 4);
|
||||
Miscellaneous.logEvent("i", "LocationProvider", "Starting HeadphoneJackListener because used in a new/changed rule.", 4);
|
||||
if(HeadphoneJackListener.getInstance().haveAllPermission())
|
||||
HeadphoneJackListener.getInstance().startListener(AutomationService.getInstance());
|
||||
}
|
||||
@ -411,7 +374,7 @@ public class ReceiverCoordinator
|
||||
{
|
||||
if(HeadphoneJackListener.isHeadphoneJackListenerActive())
|
||||
{
|
||||
Miscellaneous.logEvent("i", "HeadphoneJackListener", "Shutting down HeadphoneJackListener because not used in any rule.", 4);
|
||||
Miscellaneous.logEvent("i", "LocationProvider", "Shutting down HeadphoneJackListener because not used in any rule.", 4);
|
||||
HeadphoneJackListener.getInstance().stopListener(AutomationService.getInstance());
|
||||
}
|
||||
}
|
||||
@ -434,55 +397,6 @@ public class ReceiverCoordinator
|
||||
}
|
||||
}
|
||||
|
||||
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.tethering))
|
||||
{
|
||||
if(!TetheringReceiver.getInstance().isListenerRunning())
|
||||
{
|
||||
Miscellaneous.logEvent("i", "TetheringReceiver", "Starting TetheringReceiver because used in a new/changed rule.", 4);
|
||||
// if(DevicePositionListener.getInstance().haveAllPermission())
|
||||
TetheringReceiver.getInstance().startListener(AutomationService.getInstance());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(TetheringReceiver.getInstance().isListenerRunning())
|
||||
{
|
||||
Miscellaneous.logEvent("i", "TetheringReceiver", "Shutting down TetheringReceiver because not used in any rule.", 4);
|
||||
TetheringReceiver.getInstance().stopListener(AutomationService.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.subSystemState))
|
||||
{
|
||||
if(!SubSystemStateReceiver.getInstance().isListenerRunning())
|
||||
{
|
||||
Miscellaneous.logEvent("i", "SubSystemStateReceiver", "Starting SubSystemStateReceiver because used in a new/changed rule.", 4);
|
||||
// if(DevicePositionListener.getInstance().haveAllPermission())
|
||||
TetheringReceiver.getInstance().startListener(AutomationService.getInstance());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(SubSystemStateReceiver.getInstance().isListenerRunning())
|
||||
{
|
||||
Miscellaneous.logEvent("i", "SubSystemStateReceiver", "Shutting down SubSystemStateReceiver because not used in any rule.", 4);
|
||||
SubSystemStateReceiver.getInstance().stopListener(AutomationService.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.calendarEvent) && ActivityPermissions.isPermissionDeclaratedInManifest(AutomationService.getInstance(), Manifest.permission.READ_CALENDAR) && ActivityPermissions.havePermission(Manifest.permission.READ_CALENDAR, AutomationService.getInstance()))
|
||||
{
|
||||
if(!CalendarReceiver.getInstance().isListenerRunning())
|
||||
CalendarReceiver.getInstance().startListener(AutomationService.getInstance());
|
||||
else
|
||||
CalendarReceiver.armOrRearmTimer();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(CalendarReceiver.getInstance().isListenerRunning())
|
||||
CalendarReceiver.getInstance().stopListener(AutomationService.getInstance());
|
||||
}
|
||||
|
||||
AutomationService.updateNotification();
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import java.util.Set;
|
||||
public class Settings implements SharedPreferences
|
||||
{
|
||||
public static final int rulesThatHaveBeenRanHistorySize = 10;
|
||||
public static final int lockSoundChangesInterval = 15;
|
||||
public final static int lockSoundChangesInterval = 15;
|
||||
public static final int newsPollEveryXDays = 3;
|
||||
public static final int newsDisplayForXDays = 3;
|
||||
public static final int updateCheckFrequencyDays = 7;
|
||||
@ -65,10 +65,8 @@ public class Settings implements SharedPreferences
|
||||
public static int tabsPlacement;
|
||||
public static boolean executeRulesAndProfilesWithSingleClick;
|
||||
public static boolean displayNewsOnMainScreen;
|
||||
public static boolean showToasts;
|
||||
public static boolean automaticUpdateCheck;
|
||||
public static long musicCheckFrequency;
|
||||
public static String displayLanguage;
|
||||
|
||||
public static boolean lockSoundChanges;
|
||||
public static boolean noticeAndroid9MicrophoneShown;
|
||||
@ -79,13 +77,7 @@ public class Settings implements SharedPreferences
|
||||
public static ArrayList<String> whatHasBeenDone;
|
||||
|
||||
/*
|
||||
Not saved permanently.
|
||||
*/
|
||||
public static boolean deviceStartDone = true; // by default assume device has not just been started
|
||||
public static boolean serviceStartDone = false;
|
||||
|
||||
/*
|
||||
Generic settings valid for all installations and not changeable
|
||||
Generic settings valid for all installations and not changable
|
||||
*/
|
||||
public static final String dateFormat = "E dd.MM.yyyy HH:mm:ss:ssss";
|
||||
|
||||
@ -132,14 +124,11 @@ public class Settings implements SharedPreferences
|
||||
public static final int default_tabsPlacement = 0;
|
||||
public static final boolean default_executeRulesAndProfilesWithSingleClick = false;
|
||||
public static final boolean default_displayNewsOnMainScreen = false;
|
||||
|
||||
public static final boolean default_showToasts = true;
|
||||
public static final boolean default_automaticUpdateCheck = false;
|
||||
public static final boolean default_lockSoundChanges = false;
|
||||
public static final long default_lastNewsPolltime = -1;
|
||||
public static final long default_lastUpdateCheck = -1;
|
||||
public static final long default_musicCheckFrequency = 2500;
|
||||
public static final String default_displayLanguage = "systemDefaultLanguage";
|
||||
|
||||
@Override
|
||||
public boolean contains(String arg0)
|
||||
@ -149,45 +138,56 @@ public class Settings implements SharedPreferences
|
||||
@Override
|
||||
public Editor edit()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Map<String, ?> getAll()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public boolean getBoolean(String arg0, boolean arg1)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public float getFloat(String arg0, float arg1)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public int getInt(String arg0, int arg1)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public long getLong(String arg0, long arg1)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public String getString(String arg0, String arg1)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public void registerOnSharedPreferenceChangeListener(OnSharedPreferenceChangeListener arg0)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
@Override
|
||||
public void unregisterOnSharedPreferenceChangeListener(OnSharedPreferenceChangeListener arg0)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public static void readFromPersistentStorage(Context context)
|
||||
@ -264,7 +264,6 @@ public class Settings implements SharedPreferences
|
||||
tabsPlacement = Integer.parseInt(prefs.getString("tabsPlacement", String.valueOf(default_tabsPlacement)));
|
||||
|
||||
musicCheckFrequency = Long.parseLong(prefs.getString("musicCheckFrequency", String.valueOf(default_musicCheckFrequency)));
|
||||
displayLanguage = prefs.getString("displayLanguage", default_displayLanguage);
|
||||
|
||||
if(Settings.musicCheckFrequency == 0)
|
||||
Settings.musicCheckFrequency = Settings.default_musicCheckFrequency;
|
||||
@ -272,7 +271,6 @@ public class Settings implements SharedPreferences
|
||||
executeRulesAndProfilesWithSingleClick = prefs.getBoolean("executeRulesAndProfilesWithSingleClick", default_executeRulesAndProfilesWithSingleClick);
|
||||
automaticUpdateCheck = prefs.getBoolean("automaticUpdateCheck", default_automaticUpdateCheck);
|
||||
displayNewsOnMainScreen = prefs.getBoolean("displayNewsOnMainScreen", default_displayNewsOnMainScreen);
|
||||
showToasts = prefs.getBoolean("showToasts", default_showToasts);
|
||||
|
||||
lockSoundChanges = prefs.getBoolean("lockSoundChanges", default_lockSoundChanges);
|
||||
noticeAndroid9MicrophoneShown = prefs.getBoolean("noticeAndroid9MicrophoneShown", false);
|
||||
@ -468,15 +466,9 @@ public class Settings implements SharedPreferences
|
||||
if(!prefs.contains("displayNewsOnMainScreen") || force)
|
||||
editor.putBoolean("displayNewsOnMainScreen", default_displayNewsOnMainScreen);
|
||||
|
||||
if(!prefs.contains("showToasts") || force)
|
||||
editor.putBoolean("showToasts", default_showToasts);
|
||||
|
||||
if(!prefs.contains("musicCheckFrequency") || force)
|
||||
editor.putLong("musicCheckFrequency", default_musicCheckFrequency);
|
||||
|
||||
if(!prefs.contains("displayLanguage") || force)
|
||||
editor.putString("displayLanguage", default_displayLanguage);
|
||||
|
||||
if(!prefs.contains("lockSoundChanges") || force)
|
||||
editor.putBoolean("lockSoundChanges", default_lockSoundChanges);
|
||||
|
||||
@ -557,14 +549,11 @@ public class Settings implements SharedPreferences
|
||||
editor.putBoolean("executeRulesAndProfilesWithSingleClick", executeRulesAndProfilesWithSingleClick);
|
||||
editor.putBoolean("automaticUpdateCheck", automaticUpdateCheck);
|
||||
editor.putBoolean("displayNewsOnMainScreen", displayNewsOnMainScreen);
|
||||
editor.putBoolean("showToasts", showToasts);
|
||||
|
||||
if(Settings.musicCheckFrequency == 0)
|
||||
Settings.musicCheckFrequency = Settings.default_musicCheckFrequency;
|
||||
editor.putString("musicCheckFrequency", String.valueOf(musicCheckFrequency));
|
||||
|
||||
editor.putString("displayLanguage", displayLanguage);
|
||||
|
||||
editor.putBoolean("lockSoundChanges", lockSoundChanges);
|
||||
editor.putBoolean("noticeAndroid9MicrophoneShown", noticeAndroid9MicrophoneShown);
|
||||
editor.putBoolean("noticeAndroid10WifiShown", noticeAndroid10WifiShown);
|
||||
@ -608,6 +597,8 @@ public class Settings implements SharedPreferences
|
||||
@Override
|
||||
public Set<String> getStringSet(String arg0, Set<String> arg1)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -2,13 +2,12 @@ package com.jens.automation2;
|
||||
|
||||
import java.sql.Time;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
public class TimeFrame
|
||||
{
|
||||
// Defines a timeframe
|
||||
protected TimeObject triggerTimeStart;
|
||||
protected TimeObject triggerTimeStop;
|
||||
protected Time triggerTimeStart;
|
||||
protected Time triggerTimeStop;
|
||||
protected long repetition;
|
||||
|
||||
protected final static String separator = "/";
|
||||
@ -21,35 +20,34 @@ public class TimeFrame
|
||||
public void setDayList(ArrayList<Integer> dayList)
|
||||
{
|
||||
this.dayList = dayList;
|
||||
Collections.sort(dayList);
|
||||
}
|
||||
public void setDayListFromString(String dayListString)
|
||||
{
|
||||
// Log.i("Parsing", "Full string: " + dayListString);
|
||||
char[] dayListCharArray = dayListString.toCharArray();
|
||||
|
||||
dayList = new ArrayList<Integer>();
|
||||
for(char item : dayListCharArray)
|
||||
{
|
||||
// Log.i("Parsing", String.valueOf(item));
|
||||
dayList.add(Integer.parseInt(String.valueOf(item)));
|
||||
}
|
||||
|
||||
Collections.sort(dayList);
|
||||
}
|
||||
|
||||
public TimeObject getTriggerTimeStart()
|
||||
public Time getTriggerTimeStart()
|
||||
{
|
||||
return triggerTimeStart;
|
||||
}
|
||||
public void setTriggerTimeStart(TimeObject triggerTimeStart)
|
||||
public void setTriggerTimeStart(Time triggerTimeStart)
|
||||
{
|
||||
this.triggerTimeStart = triggerTimeStart;
|
||||
}
|
||||
|
||||
public TimeObject getTriggerTimeStop()
|
||||
public Time getTriggerTimeStop()
|
||||
{
|
||||
return triggerTimeStop;
|
||||
}
|
||||
public void setTriggerTimeStop(TimeObject triggerTimeStop)
|
||||
public void setTriggerTimeStop(Time triggerTimeStop)
|
||||
{
|
||||
this.triggerTimeStop = triggerTimeStop;
|
||||
}
|
||||
@ -64,7 +62,7 @@ public class TimeFrame
|
||||
this.repetition = repetition;
|
||||
}
|
||||
|
||||
public TimeFrame (TimeObject timeStart, TimeObject timeEnd, ArrayList<Integer> dayList2, long repetition)
|
||||
public TimeFrame (Time timeStart, Time timeEnd, ArrayList<Integer> dayList2, long repetition)
|
||||
{
|
||||
this.setTriggerTimeStart(timeStart);
|
||||
this.setTriggerTimeStop(timeEnd);
|
||||
@ -75,8 +73,8 @@ public class TimeFrame
|
||||
public TimeFrame (String fileContent)
|
||||
{
|
||||
String[] dateArray = fileContent.split(separator); // example: timestart/timestop/days[int]/repetition
|
||||
this.setTriggerTimeStart(TimeObject.valueOf(dateArray[0]));
|
||||
this.setTriggerTimeStop(TimeObject.valueOf(dateArray[1]));
|
||||
this.setTriggerTimeStart(Time.valueOf(dateArray[0]));
|
||||
this.setTriggerTimeStop(Time.valueOf(dateArray[1]));
|
||||
this.setDayListFromString(dateArray[2]);
|
||||
if(dateArray.length > 3) // may not exist in old config files
|
||||
this.setRepetition(Long.parseLong(dateArray[3]));
|
||||
|
@ -1,78 +0,0 @@
|
||||
package com.jens.automation2;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.sql.Time;
|
||||
|
||||
public class TimeObject
|
||||
{
|
||||
int hours, minutes, seconds;
|
||||
|
||||
public TimeObject()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public int getHours()
|
||||
{
|
||||
return hours;
|
||||
}
|
||||
|
||||
public void setHours(int hours)
|
||||
{
|
||||
this.hours = hours;
|
||||
}
|
||||
|
||||
public int getMinutes()
|
||||
{
|
||||
return minutes;
|
||||
}
|
||||
|
||||
public void setMinutes(int minutes)
|
||||
{
|
||||
this.minutes = minutes;
|
||||
}
|
||||
|
||||
public int getSeconds()
|
||||
{
|
||||
return seconds;
|
||||
}
|
||||
|
||||
public void setSeconds(int seconds)
|
||||
{
|
||||
this.seconds = seconds;
|
||||
}
|
||||
|
||||
public TimeObject(int hours, int minutes, int seconds)
|
||||
{
|
||||
this.hours = hours;
|
||||
this.minutes = minutes;
|
||||
this.seconds = seconds;
|
||||
}
|
||||
|
||||
public static TimeObject valueOf(String input)
|
||||
{
|
||||
TimeObject ro = null;
|
||||
|
||||
if(input.contains(":"))
|
||||
{
|
||||
String[] parts = input.split(":");
|
||||
if(parts.length == 2)
|
||||
ro = new TimeObject(Integer.parseInt(parts[0]), Integer.parseInt(parts[1]), 0);
|
||||
else if(parts.length == 3)
|
||||
ro = new TimeObject(Integer.parseInt(parts[0]), Integer.parseInt(parts[1]), Integer.parseInt(parts[2]));
|
||||
else
|
||||
Miscellaneous.logEvent("w", "TimeObject", "Invalid length for time. Input: " + input, 4);
|
||||
}
|
||||
|
||||
return ro;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
Time time = Time.valueOf(this.getHours() + ":" + this.getMinutes() + ":" + this.getSeconds());
|
||||
return time.toString();
|
||||
}
|
||||
}
|
@ -160,9 +160,9 @@ public class XmlFileInterface
|
||||
serializer.text(String.valueOf(Profile.getProfileCollection().get(i).getChangeIncomingCallsRingtone()));
|
||||
serializer.endTag(null, "changeIncomingCallsRingtone");//
|
||||
serializer.startTag(null, "incomingCallsRingtone");
|
||||
String incomingFile = Profile.getProfileCollection().get(i).getIncomingCallsRingtone();
|
||||
File incomingFile = Profile.getProfileCollection().get(i).getIncomingCallsRingtone();
|
||||
if(incomingFile != null)
|
||||
serializer.text(String.valueOf(Profile.getProfileCollection().get(i).getIncomingCallsRingtone()));
|
||||
serializer.text(String.valueOf(Profile.getProfileCollection().get(i).getIncomingCallsRingtone().getPath()));
|
||||
else
|
||||
serializer.text("null");
|
||||
serializer.endTag(null, "incomingCallsRingtone");
|
||||
@ -178,9 +178,9 @@ public class XmlFileInterface
|
||||
serializer.text(String.valueOf(Profile.getProfileCollection().get(i).getChangeNotificationRingtone()));
|
||||
serializer.endTag(null, "changeNotificationRingtone");//
|
||||
serializer.startTag(null, "notificationRingtone");
|
||||
String notificationFile = Profile.getProfileCollection().get(i).getNotificationRingtone();
|
||||
File notificationFile = Profile.getProfileCollection().get(i).getNotificationRingtone();
|
||||
if(notificationFile != null)
|
||||
serializer.text(String.valueOf(Profile.getProfileCollection().get(i).getNotificationRingtone()));
|
||||
serializer.text(String.valueOf(Profile.getProfileCollection().get(i).getNotificationRingtone().getPath()));
|
||||
else
|
||||
serializer.text("null");
|
||||
serializer.endTag(null, "notificationRingtone");
|
||||
@ -217,7 +217,7 @@ public class XmlFileInterface
|
||||
}
|
||||
serializer.endTag(null, "ProfileCollection");
|
||||
|
||||
|
||||
|
||||
serializer.startTag(null, "RuleCollection");
|
||||
for(int i=0; i<Rule.getRuleCollection().size(); i++)
|
||||
{
|
||||
@ -631,7 +631,7 @@ public class XmlFileInterface
|
||||
{
|
||||
String path = readTag(parser, "incomingCallsRingtone");
|
||||
if(!path.equals("null"))
|
||||
newProfile.setIncomingCallsRingtone(path);
|
||||
newProfile.setIncomingCallsRingtone(new File(path));
|
||||
else
|
||||
newProfile.setIncomingCallsRingtone(null);
|
||||
}
|
||||
@ -643,7 +643,7 @@ public class XmlFileInterface
|
||||
{
|
||||
String path = readTag(parser, "notificationRingtone");
|
||||
if(!path.equals("null"))
|
||||
newProfile.setNotificationRingtone(path);
|
||||
newProfile.setNotificationRingtone(new File(path));
|
||||
else
|
||||
newProfile.setNotificationRingtone(null);
|
||||
}
|
||||
@ -1286,24 +1286,20 @@ public class XmlFileInterface
|
||||
else
|
||||
newTag = tag.replace("/", Action.intentPairSeparator);
|
||||
|
||||
String[] newTagPieces = new String[0];
|
||||
if(newTag.contains(Action.actionParameter2Split))
|
||||
newTagPieces = newTag.split(Action.actionParameter2Split);
|
||||
else
|
||||
newTag.split(";");
|
||||
String[] newTagPieces = newTag.split(";");
|
||||
|
||||
if(newTagPieces.length < 2 || (!newTagPieces[0].contains(Actions.dummyPackageString) && newTagPieces[1].contains(Action.intentPairSeparator)))
|
||||
{
|
||||
newTag = Actions.dummyPackageString + Action.actionParameter2Split + newTag;
|
||||
newTagPieces = newTag.split(Action.actionParameter2Split);
|
||||
newTag = Actions.dummyPackageString + ";" + newTag;
|
||||
newTagPieces = newTag.split(";");
|
||||
}
|
||||
|
||||
if(newTagPieces.length < 3)
|
||||
newTag += Action.actionParameter2Split + ActivityManageActionStartActivity.startByActivityString;
|
||||
newTag += ";" + ActivityManageActionStartActivity.startByActivityString;
|
||||
else if(newTagPieces.length >= 3)
|
||||
{
|
||||
if(newTagPieces[2].contains(Action.intentPairSeparator))
|
||||
newTag = newTagPieces[0] + Action.actionParameter2Split + newTagPieces[1] + Action.actionParameter2Split + ActivityManageActionStartActivity.startByActivityString + Action.actionParameter2Split + newTagPieces[2];
|
||||
newTag = newTagPieces[0] + ";" + newTagPieces[1] + ";" + ActivityManageActionStartActivity.startByActivityString + ";" + newTagPieces[2];
|
||||
}
|
||||
|
||||
newAction.setParameter2(newTag);
|
||||
|
@ -272,23 +272,29 @@ public class CellLocationChangedReceiver extends PhoneStateListener
|
||||
locationListenerArmed = false;
|
||||
Miscellaneous.logEvent("i", "LocationListener", "Disarmed location listener, accuracy reached", 4);
|
||||
}
|
||||
|
||||
// Miscellaneous.logEvent("i", "LocationListener", "Giving update to POI class");
|
||||
// PointOfInterest.positionUpdate(up2DateLocation, parentLocationProvider.parentService);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProviderDisabled(String provider)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProviderEnabled(String provider)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStatusChanged(String provider, int status, Bundle extras)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -7,11 +7,11 @@ import android.location.LocationManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.util.Log;
|
||||
|
||||
import com.jens.automation2.ActivityMainScreen;
|
||||
import com.jens.automation2.AutomationService;
|
||||
import com.jens.automation2.BuildConfig;
|
||||
import com.jens.automation2.Miscellaneous;
|
||||
import com.jens.automation2.PointOfInterest;
|
||||
import com.jens.automation2.R;
|
||||
@ -233,7 +233,6 @@ public class LocationProvider
|
||||
public void startLocationService()
|
||||
{
|
||||
// startPhoneStateListener
|
||||
if(!BuildConfig.FLAVOR.equals(AutomationService.flavor_name_googleplay))
|
||||
PhoneStatusListener.startPhoneStatusListener(parentService); // also used to mute anouncements during calls
|
||||
|
||||
// startConnectivityReceiver
|
||||
@ -402,12 +401,12 @@ public class LocationProvider
|
||||
Miscellaneous.logEvent("i", "LocationProvider", this.getParentService().getResources().getString(R.string.applyingSettingsAndRules), 3);
|
||||
|
||||
// *********** SETTING CHANGES ***********
|
||||
if(Settings.useWifiForPositioning && !WifiBroadcastReceiver.isWifiListenerActive() || Rule.isAnyRuleUsing(Trigger_Enum.wifiConnection))
|
||||
if(Settings.useWifiForPositioning && !WifiBroadcastReceiver.isWifiListenerActive())
|
||||
{
|
||||
Miscellaneous.logEvent("i", "LocationProvider", "Starting WifiReceiver because settings now allow to.", 4);
|
||||
WifiBroadcastReceiver.startWifiReceiver(this);
|
||||
}
|
||||
else if(!Settings.useWifiForPositioning && WifiBroadcastReceiver.isWifiListenerActive() && !Rule.isAnyRuleUsing(Trigger_Enum.wifiConnection))
|
||||
else if(!Settings.useWifiForPositioning && WifiBroadcastReceiver.isWifiListenerActive())
|
||||
{
|
||||
Miscellaneous.logEvent("i", "LocationProvider", "Shutting down WifiReceiver because settings forbid to.", 4);
|
||||
WifiBroadcastReceiver.stopWifiReceiver();
|
||||
@ -486,6 +485,7 @@ public class LocationProvider
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void resetSpeedTimer(Calendar timeOfForcedLocationCheck)
|
||||
{
|
||||
if(speedTimerActive)
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.jens.automation2.location;
|
||||
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@ -17,8 +18,6 @@ import com.jens.automation2.Rule;
|
||||
import com.jens.automation2.Settings;
|
||||
import com.jens.automation2.Trigger;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class WifiBroadcastReceiver extends BroadcastReceiver
|
||||
@ -26,19 +25,11 @@ public class WifiBroadcastReceiver extends BroadcastReceiver
|
||||
public static LocationProvider parentLocationProvider;
|
||||
public static Boolean wasConnected = false;
|
||||
protected static String lastWifiSsid = "";
|
||||
protected static String lastWifiSsidReal = "";
|
||||
public static boolean lastConnectedState = false;
|
||||
protected static boolean mayCellLocationChangedReceiverBeActivatedFromWifiPointOfView = true;
|
||||
protected static boolean mayCellLocationChangedReceiverBeActivatedFromWifiPointOfWifi = true;
|
||||
protected static WifiBroadcastReceiver wifiBrInstance;
|
||||
protected static IntentFilter wifiListenerIntentFilter;
|
||||
protected static boolean wifiListenerActive = false;
|
||||
|
||||
final static String unknownSsidName = "<unknown ssid>";
|
||||
|
||||
public static String getLastWifiSsidReal()
|
||||
{
|
||||
return lastWifiSsidReal;
|
||||
}
|
||||
protected static boolean wifiListenerActive=false;
|
||||
|
||||
public static String getLastWifiSsid()
|
||||
{
|
||||
@ -47,18 +38,11 @@ public class WifiBroadcastReceiver extends BroadcastReceiver
|
||||
|
||||
public static void setLastWifiSsid(String newWifiSsid)
|
||||
{
|
||||
// Remove double quotes that sometimes come
|
||||
if(newWifiSsid.startsWith("\"") && newWifiSsid.endsWith("\""))
|
||||
newWifiSsid = newWifiSsid.substring(1, newWifiSsid.length()-1);
|
||||
|
||||
// If it's a real name, not an empty string, it's stored as the last ssid
|
||||
if(newWifiSsid.length() > 0)
|
||||
{
|
||||
if(!newWifiSsid.equals(unknownSsidName))
|
||||
WifiBroadcastReceiver.lastWifiSsidReal = lastWifiSsid;
|
||||
|
||||
WifiBroadcastReceiver.lastWifiSsid = newWifiSsid;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isWifiListenerActive()
|
||||
@ -68,7 +52,7 @@ public class WifiBroadcastReceiver extends BroadcastReceiver
|
||||
|
||||
public static boolean mayCellLocationReceiverBeActivated()
|
||||
{
|
||||
return mayCellLocationChangedReceiverBeActivatedFromWifiPointOfView;
|
||||
return mayCellLocationChangedReceiverBeActivatedFromWifiPointOfWifi;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -76,20 +60,30 @@ public class WifiBroadcastReceiver extends BroadcastReceiver
|
||||
{
|
||||
try
|
||||
{
|
||||
if(!StringUtils.isEmpty(intent.getAction()))
|
||||
Miscellaneous.logEvent("i", "WifiReceiver", "Received signal with action \""+ intent.getAction() + "\".", 4);
|
||||
else
|
||||
Miscellaneous.logEvent("i", "WifiReceiver", "Received signal with empty action.", 4);
|
||||
|
||||
// int state = -1;
|
||||
NetworkInfo myWifi = null;
|
||||
|
||||
if(intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) // fired upon disconnection
|
||||
// if(intent.getAction().equals(WifiManager.RSSI_CHANGED_ACTION)) //gefeuert bei Verbindung
|
||||
// {
|
||||
// Miscellaneous.logEvent("i", "WifiReceiver", "RSSI_CHANGED_ACTION: " + String.valueOf(intent.getIntExtra(WifiManager.RSSI_CHANGED_ACTION, -1)));
|
||||
// }
|
||||
// else
|
||||
if(intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) //gefeuert bei Trennung
|
||||
{
|
||||
// state = intent.getIntExtra(WifiManager.NETWORK_STATE_CHANGED_ACTION, -1);
|
||||
// Miscellaneous.logEvent("i", "WifiReceiver", "NETWORK_STATE_CHANGED_ACTION: " + String.valueOf(state));
|
||||
myWifi = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
|
||||
}
|
||||
|
||||
|
||||
WifiManager myWifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
|
||||
|
||||
// ConnectivityManager connManager = (ConnectivityManager)context.getSystemService(context.CONNECTIVITY_SERVICE);
|
||||
// myWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
||||
// myWifi = state
|
||||
// WifiInfo wifiInfo = myWifiManager.getConnectionInfo();
|
||||
|
||||
// SupplicantState supState = wifiInfo.getSupplicantState();
|
||||
|
||||
if(intent.getAction().equals(WifiManager.RSSI_CHANGED_ACTION)) // fired upon connection
|
||||
{
|
||||
String ssid = myWifiManager.getConnectionInfo().getSSID();
|
||||
@ -101,14 +95,8 @@ public class WifiBroadcastReceiver extends BroadcastReceiver
|
||||
if(Settings.useWifiForPositioning && PointOfInterest.reachedPoiWithActivateWifiRule()) // Poi has wifi
|
||||
{
|
||||
Miscellaneous.logEvent("i", "WifiReceiver", context.getResources().getString(R.string.poiHasWifiStoppingCellLocationListener), 2);
|
||||
mayCellLocationChangedReceiverBeActivatedFromWifiPointOfView = false;
|
||||
mayCellLocationChangedReceiverBeActivatedFromWifiPointOfWifi = false;
|
||||
CellLocationChangedReceiver.stopCellLocationChangedReceiver();
|
||||
|
||||
/*
|
||||
TODO: Every time the screen is turned on, we receive a "wifi has been connected"-event.
|
||||
This is technically wrong and not really any change to when the screen was off. It has
|
||||
to be filtered.
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -122,7 +110,7 @@ public class WifiBroadcastReceiver extends BroadcastReceiver
|
||||
{
|
||||
wasConnected = true;
|
||||
Miscellaneous.logEvent("i", "WifiReceiver", "WifiReceiver just activated. Wifi already connected. Stopping CellLocationReceiver", 3);
|
||||
mayCellLocationChangedReceiverBeActivatedFromWifiPointOfView = false;
|
||||
mayCellLocationChangedReceiverBeActivatedFromWifiPointOfWifi = false;
|
||||
CellLocationChangedReceiver.stopCellLocationChangedReceiver();
|
||||
SensorActivity.stopAccelerometerTimer();
|
||||
String ssid = myWifiManager.getConnectionInfo().getSSID();
|
||||
@ -132,13 +120,13 @@ public class WifiBroadcastReceiver extends BroadcastReceiver
|
||||
}
|
||||
else if(!myWifi.isConnectedOrConnecting()) // really disconnected? because sometimes also fires on connect
|
||||
{
|
||||
if(wasConnected) // we could simply not be home yet
|
||||
if(wasConnected) // wir könnten einfach noch nicht daheim sein
|
||||
{
|
||||
try
|
||||
{
|
||||
wasConnected = false;
|
||||
Miscellaneous.logEvent("i", "WifiReceiver", "Disconnected from wifi \"" + getLastWifiSsid() + "\". Switching to CellLocationChangedReceiver.", 3);
|
||||
mayCellLocationChangedReceiverBeActivatedFromWifiPointOfView = true;
|
||||
Miscellaneous.logEvent("i", "WifiReceiver", String.format(context.getResources().getString(R.string.disconnectedFromWifi), getLastWifiSsid()) + " Switching to CellLocationChangedReceiver.", 3);
|
||||
mayCellLocationChangedReceiverBeActivatedFromWifiPointOfWifi = true;
|
||||
CellLocationChangedReceiver.startCellLocationChangedReceiver();
|
||||
lastConnectedState = false;
|
||||
findRules(AutomationService.getInstance());
|
||||
@ -226,16 +214,17 @@ public class WifiBroadcastReceiver extends BroadcastReceiver
|
||||
{
|
||||
try
|
||||
{
|
||||
if (wifiListenerActive)
|
||||
if(wifiListenerActive)
|
||||
{
|
||||
Miscellaneous.logEvent("i", "Wifi Listener", "Stopping wifiListener", 4);
|
||||
wifiListenerActive = false;
|
||||
parentLocationProvider.getParentService().unregisterReceiver(wifiBrInstance);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch(Exception ex)
|
||||
{
|
||||
Miscellaneous.logEvent("e", "Wifi Listener", "Error stopping wifiListener: " + Log.getStackTraceString(ex), 3);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -7,6 +7,7 @@ import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.BatteryManager;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.jens.automation2.ActivityPermissions;
|
||||
import com.jens.automation2.AutomationService;
|
||||
@ -18,35 +19,35 @@ import java.util.ArrayList;
|
||||
|
||||
public class BatteryReceiver extends BroadcastReceiver implements AutomationListenerInterface
|
||||
{
|
||||
private static int batteryLevel = -1; // initialize with a better value than this
|
||||
public static AutomationService automationServiceRef = null;
|
||||
static int batteryLevel = -1; // initialize with a better value than this
|
||||
static boolean usbHostConnected = false;
|
||||
static boolean batteryReceiverActive = false;
|
||||
static IntentFilter batteryIntentFilter = null;
|
||||
static Intent batteryStatus = null;
|
||||
private static boolean usbHostConnected = false;
|
||||
|
||||
private static int currentChargingState = 0; //0=unknown, 1=no, 2=yes
|
||||
private static int currentChargingType = 0; //AC, wireless, USB
|
||||
static BroadcastReceiver batteryInfoReceiverInstance = null;
|
||||
private static boolean batteryReceiverActive = false;
|
||||
private static IntentFilter batteryIntentFilter = null;
|
||||
private static Intent batteryStatus = null;
|
||||
private static BroadcastReceiver batteryInfoReceiverInstance = null;
|
||||
|
||||
public static void startBatteryReceiver(final AutomationService automationServiceRef)
|
||||
{
|
||||
if(!batteryReceiverActive)
|
||||
{
|
||||
BatteryReceiver.automationServiceRef = automationServiceRef;
|
||||
|
||||
|
||||
if(batteryInfoReceiverInstance == null)
|
||||
batteryInfoReceiverInstance = new BatteryReceiver();
|
||||
|
||||
|
||||
if(batteryIntentFilter == null)
|
||||
{
|
||||
batteryIntentFilter = new IntentFilter();
|
||||
batteryIntentFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
|
||||
batteryIntentFilter.addAction(Intent.ACTION_BATTERY_LOW);
|
||||
// batteryIntentFilter.addAction(Intent.ACTION_POWER_CONNECTED);
|
||||
// batteryIntentFilter.addAction(Intent.ACTION_POWER_DISCONNECTED);
|
||||
}
|
||||
|
||||
|
||||
batteryStatus = automationServiceRef.registerReceiver(batteryInfoReceiverInstance, batteryIntentFilter);
|
||||
|
||||
|
||||
batteryReceiverActive = true;
|
||||
}
|
||||
}
|
||||
@ -59,16 +60,16 @@ public class BatteryReceiver extends BroadcastReceiver implements AutomationList
|
||||
automationServiceRef.unregisterReceiver(batteryInfoReceiverInstance);
|
||||
batteryInfoReceiverInstance = null;
|
||||
}
|
||||
|
||||
|
||||
batteryReceiverActive = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static boolean isBatteryReceiverActive()
|
||||
{
|
||||
return batteryReceiverActive;
|
||||
}
|
||||
|
||||
|
||||
public static boolean isUsbHostConnected()
|
||||
{
|
||||
return usbHostConnected;
|
||||
@ -79,6 +80,8 @@ public class BatteryReceiver extends BroadcastReceiver implements AutomationList
|
||||
return batteryLevel;
|
||||
}
|
||||
|
||||
private static int currentChargingState = 0; //0=unknown, 1=no, 2=yes
|
||||
|
||||
public static int getCurrentChargingState()
|
||||
{
|
||||
return currentChargingState;
|
||||
@ -87,64 +90,63 @@ public class BatteryReceiver extends BroadcastReceiver implements AutomationList
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent)
|
||||
{
|
||||
Miscellaneous.logEvent("i", "BatteryReceiver", "Received event " + intent.getAction(), 5);
|
||||
|
||||
// Log.i("Battery", "Some battery event");
|
||||
|
||||
if (intent == null)
|
||||
return;
|
||||
if (context == null)
|
||||
return;
|
||||
return;
|
||||
|
||||
if(intent.getAction().equals(Intent.ACTION_BATTERY_LOW))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "Battery", "Low battery event", 5);
|
||||
Log.i("Battery", "Low battery event");
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
batteryLevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
|
||||
// int scale = -1;
|
||||
// int voltage = -1;
|
||||
// int temp = -1;
|
||||
// scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
|
||||
// temp = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, -1);
|
||||
// voltage = intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE, -1);
|
||||
Log.i("Battery", "Level: " + String.valueOf(batteryLevel));
|
||||
this.actionBatteryLevel(context);
|
||||
|
||||
int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
|
||||
int statusPlugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
|
||||
Miscellaneous.logEvent("i", "BatteryReceiver", "Status: " + String.valueOf(statusPlugged), 5);
|
||||
|
||||
switch(statusPlugged)
|
||||
{
|
||||
case BatteryManager.BATTERY_PLUGGED_AC:
|
||||
// Toast.makeText(context, "Regular charging", Toast.LENGTH_LONG).show();
|
||||
Miscellaneous.logEvent("i", "BatteryReceiver", "Regular charging.", 5);
|
||||
this.actionCharging(context, statusPlugged);
|
||||
break;
|
||||
case BatteryManager.BATTERY_PLUGGED_WIRELESS:
|
||||
// Toast.makeText(context, "Regular charging", Toast.LENGTH_LONG).show();
|
||||
Miscellaneous.logEvent("i", "BatteryReceiver", "Wireless charging.", 5);
|
||||
this.actionCharging(context, statusPlugged);
|
||||
break;
|
||||
case BatteryManager.BATTERY_PLUGGED_USB:
|
||||
this.actionUsbConnected(context);
|
||||
break;
|
||||
}
|
||||
|
||||
switch(status)
|
||||
{
|
||||
case BatteryManager.BATTERY_STATUS_CHARGING:
|
||||
case BatteryManager.BATTERY_STATUS_FULL:
|
||||
// Miscellaneous.logEvent("i", "BatteryReceiver", "Device has been fully charged.", 5);
|
||||
this.actionCharging(context, statusPlugged);
|
||||
break;
|
||||
case BatteryManager.BATTERY_STATUS_DISCHARGING:
|
||||
case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
|
||||
this.actionDischarging(context);
|
||||
break;
|
||||
}
|
||||
// Miscellaneous.logEvent("i", "BatteryReceiver", "Received battery event.");
|
||||
// if(intent.getAction().equals(Intent.ACTION_BATTERY_CHANGED))
|
||||
// {
|
||||
batteryLevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
|
||||
// int scale = -1;
|
||||
// int voltage = -1;
|
||||
// int temp = -1;
|
||||
// scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
|
||||
// temp = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, -1);
|
||||
// voltage = intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE, -1);
|
||||
Log.i("Battery", "Level: " + String.valueOf(batteryLevel));
|
||||
this.actionBatteryLevel(context);
|
||||
|
||||
int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
|
||||
int statusPlugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
|
||||
// Miscellaneous.logEvent("i", "BatteryReceiver", "Status: " + String.valueOf(statusPlugged));
|
||||
|
||||
switch(statusPlugged)
|
||||
{
|
||||
case BatteryManager.BATTERY_PLUGGED_AC:
|
||||
// Toast.makeText(context, "Regular charging", Toast.LENGTH_LONG).show();
|
||||
// Miscellaneous.logEvent("i", "BatteryReceiver", "Regular charging.");
|
||||
this.actionCharging(context);
|
||||
break;
|
||||
case BatteryManager.BATTERY_PLUGGED_USB:
|
||||
this.actionUsbConnected(context);
|
||||
break;
|
||||
}
|
||||
|
||||
switch(status)
|
||||
{
|
||||
// case BatteryManager.BATTERY_STATUS_CHARGING:
|
||||
// break;
|
||||
case BatteryManager.BATTERY_STATUS_FULL:
|
||||
// Toast.makeText(context, "Regular charging full", Toast.LENGTH_LONG).show();
|
||||
// Miscellaneous.logEvent("i", "BatteryReceiver", "Device has been fully charged.");
|
||||
this.actionCharging(context);
|
||||
break;
|
||||
case BatteryManager.BATTERY_STATUS_DISCHARGING:
|
||||
this.actionDischarging(context);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
@ -152,39 +154,34 @@ public class BatteryReceiver extends BroadcastReceiver implements AutomationList
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static int isDeviceCharging(Context context)
|
||||
{
|
||||
switch(currentChargingState)
|
||||
{
|
||||
case 0:
|
||||
Miscellaneous.logEvent("w", "ChargingInfo", "Information isn't available, yet.", 4);
|
||||
Miscellaneous.logEvent("w", "ChargingInfo", "Status of device charging was requested. Information isn't available, yet.", 4);
|
||||
break;
|
||||
case 1:
|
||||
Miscellaneous.logEvent("i", "ChargingInfo", "Device is discharging.", 3);
|
||||
Miscellaneous.logEvent("i", "ChargingInfo", "Status of device charging was requested. Device is discharging.", 3);
|
||||
break;
|
||||
case BatteryManager.BATTERY_STATUS_CHARGING:
|
||||
Miscellaneous.logEvent("i", "ChargingInfo", "Device is charging.", 3);
|
||||
Miscellaneous.logEvent("i", "ChargingInfo", "Status of device charging was requested. Device is charging.", 3);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return currentChargingState;
|
||||
}
|
||||
|
||||
public static int getCurrentChargingType()
|
||||
{
|
||||
return currentChargingType;
|
||||
}
|
||||
|
||||
private void actionCharging(Context context, int statusPlugged)
|
||||
|
||||
private void actionCharging(Context context)
|
||||
{
|
||||
if(currentChargingState != BatteryManager.BATTERY_STATUS_CHARGING) // Avoid flooding the log. This event will occur on a regular basis even though charging state wasn't changed.
|
||||
{
|
||||
Miscellaneous.logEvent("i", "BatteryReceiver", "Battery is charging or full.", 3);
|
||||
currentChargingState = BatteryManager.BATTERY_STATUS_CHARGING;
|
||||
currentChargingType = statusPlugged;
|
||||
|
||||
//activate rule(s)
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger_Enum.charging);
|
||||
// ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByCharging(true);
|
||||
for(int i=0; i<ruleCandidates.size(); i++)
|
||||
{
|
||||
if(ruleCandidates.get(i).getsGreenLight(context))
|
||||
@ -192,7 +189,7 @@ public class BatteryReceiver extends BroadcastReceiver implements AutomationList
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void actionBatteryLevel(Context context)
|
||||
{
|
||||
Miscellaneous.logEvent("i", "BatteryReceiver", "Battery level has changed.", 3);
|
||||
@ -204,7 +201,7 @@ public class BatteryReceiver extends BroadcastReceiver implements AutomationList
|
||||
ruleCandidates.get(i).activate(automationServiceRef, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void actionDischarging(Context context)
|
||||
{
|
||||
if(currentChargingState != BatteryManager.BATTERY_STATUS_UNKNOWN) // Avoid flooding the log. This event will occur on a regular basis even though charging state wasn't changed.
|
||||
@ -219,43 +216,44 @@ public class BatteryReceiver extends BroadcastReceiver implements AutomationList
|
||||
if(ruleCandidates.get(i).getsGreenLight(context))
|
||||
ruleCandidates.get(i).activate(automationServiceRef, false);
|
||||
}
|
||||
|
||||
|
||||
this.actionUsbDisconnected(context);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void actionUsbConnected(Context context)
|
||||
{
|
||||
// Event usbConnected
|
||||
|
||||
|
||||
// Miscellaneous.logEvent("i", "BatteryReceiver", "BATTERY_PLUGGED_USB");
|
||||
|
||||
|
||||
if(!usbHostConnected)
|
||||
{
|
||||
usbHostConnected = true;
|
||||
Miscellaneous.logEvent("i", "BatteryReceiver", "Connected to computer.", 3);
|
||||
// Toast.makeText(context, "Connected to computer.", Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(context, "Connected to computer.", Toast.LENGTH_LONG).show();
|
||||
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger_Enum.usb_host_connection);
|
||||
// ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByUsbHost(true);
|
||||
for(Rule oneRule : ruleCandidates)
|
||||
{
|
||||
if(oneRule.getsGreenLight(context))
|
||||
oneRule.activate(automationServiceRef, false);
|
||||
}
|
||||
|
||||
this.actionCharging(context, BatteryManager.BATTERY_PLUGGED_USB);
|
||||
|
||||
this.actionCharging(context);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void actionUsbDisconnected(Context context)
|
||||
{
|
||||
// Event usbDisConnected
|
||||
|
||||
|
||||
if(usbHostConnected)
|
||||
{
|
||||
usbHostConnected = false;
|
||||
Miscellaneous.logEvent("i", "BatteryReceiver", "Disconnected from computer.", 3);
|
||||
// Toast.makeText(context, "Disconnected from computer.", Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(context, "Disconnected from computer.", Toast.LENGTH_LONG).show();
|
||||
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger_Enum.usb_host_connection);
|
||||
// ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByUsbHost(false);
|
||||
@ -266,13 +264,11 @@ public class BatteryReceiver extends BroadcastReceiver implements AutomationList
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startListener(AutomationService automationService)
|
||||
{
|
||||
BatteryReceiver.startBatteryReceiver(automationService);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopListener(AutomationService automationService)
|
||||
{
|
||||
@ -296,4 +292,4 @@ public class BatteryReceiver extends BroadcastReceiver implements AutomationList
|
||||
// actually monitores several
|
||||
return new Trigger_Enum[] { Trigger_Enum.batteryLevel, Trigger_Enum.charging, Trigger_Enum.usb_host_connection };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -94,21 +94,20 @@ public class BluetoothReceiver extends BroadcastReceiver implements AutomationLi
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent)
|
||||
{
|
||||
// Miscellaneous.logEvent("i", "BluetoothReceiver", "Bluetooth event.", 4);
|
||||
|
||||
String action = intent.getAction();
|
||||
|
||||
Miscellaneous.logEvent("i", "BluetoothReceiver", "Bluetooth event: " + action, 5);
|
||||
|
||||
BluetoothDevice bluetoothDevice = null;
|
||||
|
||||
if(action.equals(BluetoothDevice.ACTION_ACL_CONNECTED) || action.equals("android.bluetooth.device.action.ACL_CONNECTED"))
|
||||
{
|
||||
if(action.equals(BluetoothDevice.ACTION_ACL_CONNECTED) | action.equals("android.bluetooth.device.action.ACL_CONNECTED"))
|
||||
{
|
||||
bluetoothDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
||||
lastAffectedDevice = bluetoothDevice;
|
||||
lastAction = action;
|
||||
connectedDevices.add(bluetoothDevice);
|
||||
Miscellaneous.logEvent("i", "BluetoothReceiver", String.format(context.getResources().getString(R.string.bluetoothConnectionTo), bluetoothDevice.getName()), 3);
|
||||
}
|
||||
else if(action.equals(BluetoothDevice.ACTION_ACL_DISCONNECTED) || action.equals(BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED) || action.equals("android.bluetooth.device.ACTION_ACL_DISCONNECTED") || action.equals("android.bluetooth.device.ACTION_ACL_DISCONNECT_REQUESTED"))
|
||||
else if(action.equals(BluetoothDevice.ACTION_ACL_DISCONNECTED) | action.equals(BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED) | action.equals("android.bluetooth.device.ACTION_ACL_DISCONNECTED") | action.equals("android.bluetooth.device.ACTION_ACL_DISCONNECT_REQUESTED"))
|
||||
{
|
||||
bluetoothDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
||||
lastAffectedDevice = bluetoothDevice;
|
||||
@ -116,7 +115,7 @@ public class BluetoothReceiver extends BroadcastReceiver implements AutomationLi
|
||||
connectedDevices.remove(bluetoothDevice);
|
||||
Miscellaneous.logEvent("i", "BluetoothReceiver", String.format(context.getResources().getString(R.string.bluetoothDisconnectFrom), bluetoothDevice.getName()), 3);
|
||||
}
|
||||
else if(action.equals(BluetoothDevice.ACTION_FOUND) || action.equals("android.bluetooth.device.ACTION_FOUND"))
|
||||
else if(action.equals(BluetoothDevice.ACTION_FOUND) | action.equals("android.bluetooth.device.ACTION_FOUND"))
|
||||
{
|
||||
bluetoothDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
||||
lastAffectedDevice = bluetoothDevice;
|
||||
@ -301,16 +300,4 @@ public class BluetoothReceiver extends BroadcastReceiver implements AutomationLi
|
||||
{
|
||||
return new Trigger_Enum[] { Trigger_Enum.bluetoothConnection };
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for Bluetooth.
|
||||
*
|
||||
* @return true if Bluetooth is available.
|
||||
*/
|
||||
public static boolean isBluetoothEnabled()
|
||||
{
|
||||
final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
|
||||
return bluetoothAdapter != null && bluetoothAdapter.isEnabled() && bluetoothAdapter.getState() == BluetoothAdapter.STATE_ON;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,172 +0,0 @@
|
||||
package com.jens.automation2.receivers;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.jens.automation2.ActivityPermissions;
|
||||
import com.jens.automation2.AutomationService;
|
||||
import com.jens.automation2.Miscellaneous;
|
||||
import com.jens.automation2.Rule;
|
||||
import com.jens.automation2.Trigger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
public class BroadcastListener extends android.content.BroadcastReceiver implements AutomationListenerInterface
|
||||
{
|
||||
ArrayList<EventOccurrence> broadcastsCollection = new ArrayList<>();
|
||||
public static AutomationService automationServiceRef = null;
|
||||
private static boolean broadcastReceiverActive = false;
|
||||
private static BroadcastListener broadcastReceiverInstance = null;
|
||||
private static IntentFilter broadcastIntentFilter = null;
|
||||
private static Intent broadcastStatus = null;
|
||||
|
||||
public static BroadcastListener getInstance()
|
||||
{
|
||||
if(broadcastReceiverInstance == null)
|
||||
broadcastReceiverInstance = new BroadcastListener();
|
||||
|
||||
return broadcastReceiverInstance;
|
||||
}
|
||||
|
||||
public static class EventOccurrence
|
||||
{
|
||||
Calendar time;
|
||||
String event;
|
||||
|
||||
public EventOccurrence(Calendar time, String event)
|
||||
{
|
||||
this.time = time;
|
||||
this.event = event;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent)
|
||||
{
|
||||
broadcastsCollection.add(new EventOccurrence(Calendar.getInstance(), intent.getAction()));
|
||||
|
||||
Miscellaneous.logEvent("i", "Broadcast received", "Broadcast " + intent.getAction() + " received.", 4);
|
||||
if(intent.getExtras() != null && intent.getExtras().size() > 0)
|
||||
{
|
||||
for (String key : intent.getExtras().keySet())
|
||||
{
|
||||
Miscellaneous.logEvent("i", "Broadcast extra", "Broadcast " + intent.getAction() + " has extra " + key + " and type " + intent.getExtras().get(key).getClass().getName(), 4);
|
||||
}
|
||||
}
|
||||
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.broadcastReceived);
|
||||
for(int i=0; i<ruleCandidates.size(); i++)
|
||||
{
|
||||
if(ruleCandidates.get(i).getsGreenLight(context))
|
||||
ruleCandidates.get(i).activate(automationServiceRef, false);
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<EventOccurrence> getBroadcastsCollection()
|
||||
{
|
||||
return broadcastsCollection;
|
||||
}
|
||||
|
||||
public boolean hasBroadcastOccurred(String event)
|
||||
{
|
||||
for(EventOccurrence eo : broadcastsCollection)
|
||||
{
|
||||
if(eo.event.equalsIgnoreCase(event))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasBroadcastOccurredSince(String event, Calendar timeLimit)
|
||||
{
|
||||
for(EventOccurrence eo : broadcastsCollection)
|
||||
{
|
||||
if(eo.event.equalsIgnoreCase(event) && (timeLimit == null || eo.time.getTimeInMillis() > timeLimit.getTimeInMillis()))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startListener(AutomationService automationService)
|
||||
{
|
||||
if(!broadcastReceiverActive)
|
||||
{
|
||||
BroadcastListener.automationServiceRef = automationService;
|
||||
|
||||
if(broadcastReceiverInstance == null)
|
||||
broadcastReceiverInstance = new BroadcastListener();
|
||||
|
||||
if(broadcastIntentFilter == null)
|
||||
{
|
||||
broadcastIntentFilter = new IntentFilter();
|
||||
|
||||
List<String> actionList = new ArrayList<>();
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.broadcastReceived);
|
||||
for(int i=0; i<ruleCandidates.size(); i++)
|
||||
{
|
||||
for(Trigger t : ruleCandidates.get(i).getTriggerSet())
|
||||
{
|
||||
if(t.getTriggerType().equals(Trigger.Trigger_Enum.broadcastReceived))
|
||||
{
|
||||
ActivityPermissions.addToArrayListUnique(t.getTriggerParameter2(), actionList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(String s : actionList)
|
||||
broadcastIntentFilter.addAction(s);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
broadcastStatus = automationServiceRef.registerReceiver(broadcastReceiverInstance, broadcastIntentFilter);
|
||||
broadcastReceiverActive = true;
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
/*
|
||||
We might be confronted with permission issues here.
|
||||
*/
|
||||
Miscellaneous.logEvent("e", "BroadcastListener", Log.getStackTraceString(e), 1);
|
||||
broadcastReceiverActive = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopListener(AutomationService automationService)
|
||||
{
|
||||
if(broadcastReceiverActive)
|
||||
{
|
||||
if(broadcastReceiverInstance != null)
|
||||
{
|
||||
automationServiceRef.unregisterReceiver(broadcastReceiverInstance);
|
||||
broadcastReceiverInstance = null;
|
||||
}
|
||||
|
||||
broadcastReceiverActive = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isListenerRunning()
|
||||
{
|
||||
return broadcastReceiverActive;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Trigger.Trigger_Enum[] getMonitoredTrigger()
|
||||
{
|
||||
return new Trigger.Trigger_Enum[] { Trigger.Trigger_Enum.broadcastReceived };
|
||||
}
|
||||
}
|
@ -1,659 +0,0 @@
|
||||
package com.jens.automation2.receivers;
|
||||
|
||||
import android.app.AlarmManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.provider.CalendarContract;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.jens.automation2.AutomationService;
|
||||
import com.jens.automation2.Miscellaneous;
|
||||
import com.jens.automation2.Rule;
|
||||
import com.jens.automation2.Trigger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
public class CalendarReceiver extends BroadcastReceiver implements AutomationListenerInterface
|
||||
{
|
||||
static CalendarReceiver calendarReceiverInstance = null;
|
||||
static boolean calendarReceiverActive = false;
|
||||
static IntentFilter calendarIntentFilter = null;
|
||||
private static Intent calendarIntent = null;
|
||||
|
||||
public static final int AVAILABILITY_OUT_OF_OFFICE = 4;
|
||||
public static final int AVAILABILITY_WORKING_ELSEWHERE = 5;
|
||||
public static final String calendarAlarmAction = "ALARM_FOR_CALENDAR";
|
||||
|
||||
static List<AndroidCalendar> calendarsCache = null;
|
||||
static List<CalendarEvent> calendarEventsCache = null;
|
||||
static List<CalendarEvent> calendarEventsReoccurringCache = null;
|
||||
|
||||
// To determine for which events which rules have been executed
|
||||
static List<RuleEventPair> calendarEventsUsed = new ArrayList<>();
|
||||
|
||||
static Timer timer = null;
|
||||
static TimerTask timerTask = null;
|
||||
static Calendar nextWakeup = null;
|
||||
static AlarmManager alarmManager = null;
|
||||
static boolean wakeupNeedsToBeScheduledOrRescheduled = false;
|
||||
|
||||
public static CalendarEvent getLastTriggeringEvent()
|
||||
{
|
||||
if(calendarEventsUsed.size() > 0)
|
||||
{
|
||||
return calendarEventsUsed.get(calendarEventsUsed.size() -1).event;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class RuleEventPair
|
||||
{
|
||||
Rule rule;
|
||||
CalendarEvent event;
|
||||
|
||||
public RuleEventPair(Rule rule, CalendarEvent event)
|
||||
{
|
||||
this.rule = rule;
|
||||
this.event = event;
|
||||
}
|
||||
}
|
||||
|
||||
public static void addUsedPair(RuleEventPair pair)
|
||||
{
|
||||
// Add pair only if it's not in the list already.
|
||||
for(RuleEventPair usedPair : calendarEventsUsed)
|
||||
{
|
||||
if(usedPair.rule.equals(pair.rule) && usedPair.event.equals(pair.event))
|
||||
return;
|
||||
}
|
||||
|
||||
calendarEventsUsed.add(pair);
|
||||
}
|
||||
|
||||
public static CalendarReceiver getInstance()
|
||||
{
|
||||
if(calendarReceiverInstance == null)
|
||||
calendarReceiverInstance = new CalendarReceiver();
|
||||
|
||||
return calendarReceiverInstance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent)
|
||||
{
|
||||
Miscellaneous.logEvent("i", "CalendarReceiver", "Received " + intent.getAction(), 4);
|
||||
|
||||
if(intent.getAction().equalsIgnoreCase(Intent.ACTION_PROVIDER_CHANGED))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "CalendarReceiver", "Clearing calendar caches.", 4);
|
||||
|
||||
clearCaches();
|
||||
|
||||
routineAtAlarm();
|
||||
}
|
||||
else if(intent.getAction().equalsIgnoreCase(calendarAlarmAction))
|
||||
{
|
||||
routineAtAlarm();
|
||||
}
|
||||
}
|
||||
|
||||
static void checkForRules(Context context)
|
||||
{
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.calendarEvent);
|
||||
for (int i = 0; i < ruleCandidates.size(); i++)
|
||||
{
|
||||
if (ruleCandidates.get(i).getsGreenLight(context))
|
||||
ruleCandidates.get(i).activate(AutomationService.getInstance(), false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startListener(AutomationService automationServiceRef)
|
||||
{
|
||||
startCalendarReceiver(automationServiceRef);
|
||||
}
|
||||
|
||||
static void clearCaches()
|
||||
{
|
||||
calendarsCache = null;
|
||||
calendarEventsCache = null;
|
||||
calendarEventsReoccurringCache = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopListener(AutomationService automationService)
|
||||
{
|
||||
if(calendarReceiverActive)
|
||||
{
|
||||
if(calendarReceiverInstance != null)
|
||||
{
|
||||
AutomationService.getInstance().unregisterReceiver(calendarReceiverInstance);
|
||||
calendarReceiverInstance = null;
|
||||
}
|
||||
|
||||
clearCaches();
|
||||
calendarEventsUsed.clear();
|
||||
|
||||
calendarReceiverActive = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isListenerRunning()
|
||||
{
|
||||
return calendarReceiverActive;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Trigger.Trigger_Enum[] getMonitoredTrigger()
|
||||
{
|
||||
return new Trigger.Trigger_Enum[]{Trigger.Trigger_Enum.calendarEvent};
|
||||
}
|
||||
|
||||
public static class AndroidCalendar
|
||||
{
|
||||
public int calendarId;
|
||||
public String displayName;
|
||||
public String accountString;
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return displayName + " (" + accountString + ")";
|
||||
}
|
||||
}
|
||||
|
||||
public static class CalendarEvent
|
||||
{
|
||||
public AndroidCalendar calendar;
|
||||
public int calendarId;
|
||||
public String eventId;
|
||||
public String title;
|
||||
public String description;
|
||||
public String location;
|
||||
public String availability;
|
||||
public Calendar start, end;
|
||||
public boolean allDay, reoccurring;
|
||||
|
||||
public boolean isCurrentlyActive()
|
||||
{
|
||||
Calendar now = Calendar.getInstance();
|
||||
return now.getTimeInMillis() >= start.getTimeInMillis() && now.getTimeInMillis() < end.getTimeInMillis();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "Title: " + title + ", location: " + location + ", description: " + description + ", start: " + Miscellaneous.formatDate(start.getTime()) + ", end: " + Miscellaneous.formatDate(end.getTime()) + ", is currently active: " + String.valueOf(isCurrentlyActive()) + ", all day: " + String.valueOf(allDay) + ", availability: " + availability;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object obj)
|
||||
{
|
||||
try
|
||||
{
|
||||
CalendarEvent compareEvent = (CalendarEvent) obj;
|
||||
return calendarId == compareEvent.calendarId
|
||||
&&
|
||||
eventId.equals(compareEvent.eventId)
|
||||
&&
|
||||
title.equals(compareEvent.title)
|
||||
&&
|
||||
description.equals(compareEvent.description)
|
||||
&&
|
||||
location.equals(compareEvent.location)
|
||||
&&
|
||||
availability.equals(compareEvent.availability)
|
||||
&&
|
||||
start.getTimeInMillis() == compareEvent.start.getTimeInMillis()
|
||||
&&
|
||||
end.getTimeInMillis() == compareEvent.end.getTimeInMillis()
|
||||
&&
|
||||
allDay == compareEvent.allDay;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Miscellaneous.logEvent("e", "CalendarReceiver compare()", Log.getStackTraceString(e), 5);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static List<AndroidCalendar> readCalendars(Context context)
|
||||
{
|
||||
if(calendarsCache == null)
|
||||
{
|
||||
calendarsCache = new ArrayList<>();
|
||||
|
||||
Cursor cursor;
|
||||
|
||||
cursor = context.getContentResolver().query(
|
||||
Uri.parse("content://com.android.calendar/calendars"),
|
||||
|
||||
new String[]{ CalendarContract.Calendars._ID, CalendarContract.Calendars.CALENDAR_DISPLAY_NAME, CalendarContract.Calendars.OWNER_ACCOUNT, },
|
||||
null, null, null);
|
||||
|
||||
cursor.moveToFirst();
|
||||
// fetching calendars name
|
||||
String CNames[] = new String[cursor.getCount()];
|
||||
|
||||
for (int i = 0; i < CNames.length; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
AndroidCalendar calendar = new AndroidCalendar();
|
||||
calendar.calendarId = Integer.parseInt(cursor.getString(0));
|
||||
calendar.displayName = cursor.getString(1);
|
||||
calendar.accountString = cursor.getString(2);
|
||||
|
||||
calendarsCache.add(calendar);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
cursor.moveToNext();
|
||||
}
|
||||
|
||||
if (cursor != null)
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
return calendarsCache;
|
||||
}
|
||||
|
||||
public static List<CalendarEvent> readCalendarEvents(Context context, boolean includeReoccurring, boolean includePastEvents)
|
||||
{
|
||||
if(calendarEventsCache == null)
|
||||
{
|
||||
calendarEventsCache = new ArrayList<>();
|
||||
|
||||
Cursor cursor;
|
||||
|
||||
cursor = context.getContentResolver().query(
|
||||
Uri.parse("content://com.android.calendar/events"),
|
||||
new String[] {
|
||||
CalendarContract.Events.CALENDAR_ID,
|
||||
CalendarContract.Events._ID,
|
||||
CalendarContract.Events.TITLE,
|
||||
CalendarContract.Events.DESCRIPTION,
|
||||
CalendarContract.Events.ALL_DAY,
|
||||
CalendarContract.Events.DTSTART,
|
||||
CalendarContract.Events.DTEND,
|
||||
CalendarContract.Events.EVENT_LOCATION,
|
||||
CalendarContract.Events.AVAILABILITY
|
||||
},
|
||||
null, null, null);
|
||||
|
||||
cursor.moveToFirst();
|
||||
// fetching calendars name
|
||||
String CNames[] = new String[cursor.getCount()];
|
||||
|
||||
Calendar now = Calendar.getInstance();
|
||||
|
||||
for (int i = 0; i < CNames.length; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
CalendarEvent event = new CalendarEvent();
|
||||
event.calendarId = Integer.parseInt(cursor.getString(0));
|
||||
|
||||
for(AndroidCalendar cal : readCalendars(context))
|
||||
{
|
||||
if(cal.calendarId == event.calendarId)
|
||||
{
|
||||
event.calendar = cal;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
event.eventId = cursor.getString(1);
|
||||
event.title = cursor.getString(2);
|
||||
event.description = cursor.getString(3);
|
||||
event.allDay = cursor.getString(4).equals("1");
|
||||
event.start = Miscellaneous.calendarFromLong(Long.parseLong(cursor.getString(5)));
|
||||
event.end = Miscellaneous.calendarFromLong(Long.parseLong(cursor.getString(6)));
|
||||
event.location = cursor.getString(7);
|
||||
event.availability = cursor.getString(8);
|
||||
event.reoccurring = false;
|
||||
|
||||
if(includePastEvents || event.end.getTimeInMillis() > now.getTimeInMillis())
|
||||
calendarEventsCache.add(event);
|
||||
}
|
||||
catch (Exception e)
|
||||
{}
|
||||
cursor.moveToNext();
|
||||
}
|
||||
|
||||
if(cursor != null)
|
||||
cursor.close();
|
||||
|
||||
}
|
||||
|
||||
if(includeReoccurring && calendarEventsReoccurringCache == null)
|
||||
{
|
||||
calendarEventsReoccurringCache = new ArrayList<>();
|
||||
|
||||
Cursor cursor;
|
||||
|
||||
Calendar queryStart, queryEnd;
|
||||
if(includePastEvents)
|
||||
queryStart = Miscellaneous.calendarFromLong(0);
|
||||
else
|
||||
queryStart = Calendar.getInstance();
|
||||
|
||||
queryEnd = Calendar.getInstance();
|
||||
queryEnd.add(Calendar.YEAR, 1);
|
||||
|
||||
cursor = context.getContentResolver().query(
|
||||
Uri.parse("content://com.android.calendar/instances/when/" + queryStart.getTimeInMillis() + "/" + queryEnd.getTimeInMillis()),
|
||||
new String[] {
|
||||
CalendarContract.Instances.CALENDAR_ID,
|
||||
CalendarContract.Instances._ID,
|
||||
CalendarContract.Instances.TITLE,
|
||||
CalendarContract.Instances.DESCRIPTION,
|
||||
CalendarContract.Instances.ALL_DAY,
|
||||
CalendarContract.Instances.BEGIN,
|
||||
CalendarContract.Instances.END,
|
||||
CalendarContract.Instances.EVENT_LOCATION,
|
||||
CalendarContract.Instances.AVAILABILITY
|
||||
},
|
||||
null, null, null);
|
||||
|
||||
cursor.moveToFirst();
|
||||
String CNames[] = new String[cursor.getCount()];
|
||||
|
||||
Calendar now = Calendar.getInstance();
|
||||
|
||||
for (int i = 0; i < CNames.length; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
CalendarEvent event = new CalendarEvent();
|
||||
event.calendarId = Integer.parseInt(cursor.getString(0));
|
||||
|
||||
for(AndroidCalendar cal : readCalendars(context))
|
||||
{
|
||||
if(cal.calendarId == event.calendarId)
|
||||
{
|
||||
event.calendar = cal;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
event.eventId = cursor.getString(1);
|
||||
event.title = cursor.getString(2);
|
||||
event.description = cursor.getString(3);
|
||||
event.allDay = cursor.getString(4).equals("1");
|
||||
event.start = Miscellaneous.calendarFromLong(Long.parseLong(cursor.getString(5)));
|
||||
event.end = Miscellaneous.calendarFromLong(Long.parseLong(cursor.getString(6)));
|
||||
event.location = cursor.getString(7);
|
||||
event.availability = cursor.getString(8);
|
||||
event.reoccurring = true;
|
||||
|
||||
if(includePastEvents || event.end.getTimeInMillis() > now.getTimeInMillis())
|
||||
{
|
||||
// For the moment keeping separate records to some extent
|
||||
calendarEventsReoccurringCache.add(event);
|
||||
calendarEventsCache.add(event);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{}
|
||||
cursor.moveToNext();
|
||||
}
|
||||
|
||||
if(cursor != null)
|
||||
cursor.close();
|
||||
|
||||
}
|
||||
|
||||
return calendarEventsCache;
|
||||
}
|
||||
|
||||
protected static void routineAtAlarm()
|
||||
{
|
||||
checkForRules(Miscellaneous.getAnyContext());
|
||||
|
||||
// Set next timer
|
||||
calculateNextWakeup();
|
||||
armOrRearmTimer();
|
||||
}
|
||||
|
||||
public static void armOrRearmTimer()
|
||||
{
|
||||
PendingIntent pi = null;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
||||
{
|
||||
if (alarmManager == null)
|
||||
{
|
||||
alarmManager = (AlarmManager) Miscellaneous.getAnyContext().getSystemService(Context.ALARM_SERVICE);
|
||||
}
|
||||
|
||||
if(pi == null)
|
||||
{
|
||||
Intent intent = new Intent(Miscellaneous.getAnyContext(), CalendarReceiver.class);
|
||||
intent.setAction(calendarAlarmAction);
|
||||
pi = PendingIntent.getBroadcast(AutomationService.getInstance(), 0, intent, 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
timerTask = new TimerTask()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
routineAtAlarm();
|
||||
}
|
||||
};
|
||||
|
||||
if(timer != null)
|
||||
{
|
||||
timer.cancel();
|
||||
timer.purge();
|
||||
}
|
||||
timer = new Timer();
|
||||
}
|
||||
|
||||
if(nextWakeup == null)
|
||||
{
|
||||
readCalendarEvents(Miscellaneous.getAnyContext(), true,false);
|
||||
calculateNextWakeup();
|
||||
}
|
||||
|
||||
// If it's now filled, go on
|
||||
if(nextWakeup != null && wakeupNeedsToBeScheduledOrRescheduled)
|
||||
{
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
||||
{
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S || (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && alarmManager.canScheduleExactAlarms()))
|
||||
{
|
||||
try
|
||||
{
|
||||
alarmManager.cancel(pi);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
}
|
||||
Miscellaneous.logEvent("i", "armOrRearmTimer()", "Scheduling wakeup for calendar at " + Miscellaneous.formatDate(nextWakeup.getTime()), 4);
|
||||
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, nextWakeup.getTimeInMillis(), pi);
|
||||
wakeupNeedsToBeScheduledOrRescheduled = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
timer.schedule(timerTask, nextWakeup.getTimeInMillis());
|
||||
}
|
||||
}
|
||||
|
||||
private static void calculateNextWakeup()
|
||||
{
|
||||
Calendar now = Calendar.getInstance();
|
||||
List<CalendarEvent> events = readCalendarEvents(Miscellaneous.getAnyContext(), true, false);
|
||||
|
||||
if (events.size() == 0)
|
||||
{
|
||||
Miscellaneous.logEvent("i", "calculateNextWakeup()", "No future events, nothing to schedule.", 4);
|
||||
}
|
||||
else
|
||||
{
|
||||
List<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.calendarEvent);
|
||||
List<Long> wakeUpCandidatesList = new ArrayList<>();
|
||||
|
||||
for (CalendarEvent event : events)
|
||||
{
|
||||
for (Rule r : ruleCandidates)
|
||||
{
|
||||
for (Trigger t : r.getTriggerSet())
|
||||
{
|
||||
if (t.getTriggerType().equals(Trigger.Trigger_Enum.calendarEvent) && t.checkCalendarEvent(event, true))
|
||||
{
|
||||
/*
|
||||
Device needs to wakeup at start AND end of events, no matter what is specified in triggers.
|
||||
This is because we also need to know when a trigger doesn't apply anymore to make it
|
||||
count for hasStateNotAppliedSinceLastRuleExecution().
|
||||
Otherwise the same rule would not get executed again even after calendar events have come and gone.
|
||||
*/
|
||||
|
||||
if(event.start.getTimeInMillis() > now.getTimeInMillis())
|
||||
wakeUpCandidatesList.add(event.start.getTimeInMillis());
|
||||
|
||||
if(event.end.getTimeInMillis() > now.getTimeInMillis())
|
||||
wakeUpCandidatesList.add(event.end.getTimeInMillis());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(wakeUpCandidatesList);
|
||||
|
||||
if(wakeUpCandidatesList.size() == 0)
|
||||
Miscellaneous.logEvent("i", "calculateNextWakeupForCalendar()", "Not scheduling any calendar related wakeup as there are no future events that might match a configured trigger.", 4);
|
||||
else
|
||||
{
|
||||
if (nextWakeup == null || nextWakeup.getTimeInMillis() != wakeUpCandidatesList.get(0))
|
||||
{
|
||||
Calendar newAlarm = Miscellaneous.calendarFromLong(wakeUpCandidatesList.get(0));
|
||||
if (nextWakeup == null)
|
||||
Miscellaneous.logEvent("i", "calculateNextWakeupForCalendar()", "Chose " + Miscellaneous.formatDate(newAlarm.getTime()) + " as next wakeup for calendar triggers. Old was null.", 4);
|
||||
else
|
||||
Miscellaneous.logEvent("i", "calculateNextWakeupForCalendar()", "Chose " + Miscellaneous.formatDate(newAlarm.getTime()) + " as next wakeup for calendar triggers. Old was " + Miscellaneous.formatDate(nextWakeup.getTime()), 4);
|
||||
nextWakeup = newAlarm;
|
||||
if (!wakeupNeedsToBeScheduledOrRescheduled)
|
||||
wakeupNeedsToBeScheduledOrRescheduled = true;
|
||||
}
|
||||
else
|
||||
Miscellaneous.logEvent("i", "calculateNextWakeupForCalendar()", "Alarm " + Miscellaneous.formatDate(nextWakeup.getTime()) + " has been selected as next wakeup, but not rescheduling since this was not a change.", 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void startCalendarReceiver(final AutomationService automationServiceRef)
|
||||
{
|
||||
if (!calendarReceiverActive)
|
||||
{
|
||||
if (calendarReceiverInstance == null)
|
||||
calendarReceiverInstance = new CalendarReceiver();
|
||||
|
||||
if (calendarIntentFilter == null)
|
||||
{
|
||||
calendarIntentFilter = new IntentFilter();
|
||||
calendarIntentFilter.addAction(Intent.ACTION_PROVIDER_CHANGED);
|
||||
calendarIntentFilter.addDataScheme("content");
|
||||
calendarIntentFilter.addDataAuthority("com.android.calendar", null);
|
||||
}
|
||||
|
||||
calendarIntent = automationServiceRef.registerReceiver(calendarReceiverInstance, calendarIntentFilter);
|
||||
|
||||
calendarReceiverActive = true;
|
||||
|
||||
armOrRearmTimer();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean mayRuleStillBeActivatedForPendingCalendarEvents(Rule rule)
|
||||
{
|
||||
for(RuleEventPair pair : calendarEventsUsed)
|
||||
Miscellaneous.logEvent("i", "mayRuleStillBeActivatedForPendingCalendarEvents()", "Existing pair of " + pair.rule.getName() + " and " + pair.event, 5);
|
||||
|
||||
for(CalendarEvent event : readCalendarEvents(Miscellaneous.getAnyContext(), true,false))
|
||||
{
|
||||
for(Trigger t : rule.getTriggerSet())
|
||||
{
|
||||
if(t.getTriggerType().equals(Trigger.Trigger_Enum.calendarEvent) && t.checkCalendarEvent(event, false))
|
||||
{
|
||||
if (!hasEventBeenUsedInRule(rule, event))
|
||||
{
|
||||
/*
|
||||
If there are multiple parallel calendar events and a rule has multiple
|
||||
triggers of type calendar event, we don't want the rule to fire only once.
|
||||
*/
|
||||
if(rule.getAmountOfTriggersForType(Trigger.Trigger_Enum.calendarEvent) == 1)
|
||||
{
|
||||
Miscellaneous.logEvent("i", "mayRuleStillBeActivatedForPendingCalendarEvents()", "Rule " + rule.getName() + " has not been used in conjunction with event " + event, 4);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean hasEventBeenUsedInRule(Rule rule, CalendarEvent event)
|
||||
{
|
||||
for (RuleEventPair executedPair : calendarEventsUsed)
|
||||
{
|
||||
if (executedPair.rule.equals(rule) && executedPair.event.equals(event))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static List<CalendarReceiver.CalendarEvent> getApplyingCalendarEvents(Rule rule)
|
||||
{
|
||||
List<CalendarReceiver.CalendarEvent> returnList = new ArrayList<>();
|
||||
|
||||
try
|
||||
{
|
||||
List<CalendarReceiver.CalendarEvent> calendarEvents = CalendarReceiver.readCalendarEvents(AutomationService.getInstance(), true,false);
|
||||
|
||||
for(Trigger t : rule.getTriggerSet())
|
||||
{
|
||||
if(t.getTriggerType().equals(Trigger.Trigger_Enum.calendarEvent))
|
||||
{
|
||||
for (CalendarReceiver.CalendarEvent event : calendarEvents)
|
||||
{
|
||||
if (t.checkCalendarEvent(event, false))
|
||||
returnList.add(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Miscellaneous.logEvent("e", "getApplyingCalendarEvents()", Log.getStackTraceString(e), 1);
|
||||
}
|
||||
|
||||
return returnList;
|
||||
}
|
||||
}
|
@ -8,21 +8,19 @@ import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
|
||||
import com.jens.automation2.AutomationService;
|
||||
import com.jens.automation2.Miscellaneous;
|
||||
import com.jens.automation2.Rule;
|
||||
import com.jens.automation2.TimeFrame;
|
||||
import com.jens.automation2.TimeObject;
|
||||
import com.jens.automation2.Trigger;
|
||||
import com.jens.automation2.Trigger.Trigger_Enum;
|
||||
|
||||
import java.sql.Time;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
|
||||
public class DateTimeListener extends BroadcastReceiver implements AutomationListenerInterface
|
||||
@ -35,7 +33,7 @@ public class DateTimeListener extends BroadcastReceiver implements AutomationLis
|
||||
static PendingIntent alarmPendingIntent = null;
|
||||
|
||||
public static void startAlarmListener(final AutomationService automationServiceRef)
|
||||
{
|
||||
{
|
||||
DateTimeListener.startAlarmListenerInternal(automationServiceRef);
|
||||
}
|
||||
public static void stopAlarmListener(Context context)
|
||||
@ -47,37 +45,37 @@ public class DateTimeListener extends BroadcastReceiver implements AutomationLis
|
||||
{
|
||||
return alarmListenerActive;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent)
|
||||
{
|
||||
Miscellaneous.logEvent("i", "AlarmListener", "Alarm received", 2);
|
||||
|
||||
ArrayList<Rule> allRulesWithTimeFrame = Rule.findRuleCandidates(Trigger_Enum.timeFrame);
|
||||
for(int i=0; i < allRulesWithTimeFrame.size(); i++)
|
||||
ArrayList<Rule> allRulesWithNowInTimeFrame = Rule.findRuleCandidates(Trigger_Enum.timeFrame);
|
||||
for(int i=0; i < allRulesWithNowInTimeFrame.size(); i++)
|
||||
{
|
||||
if(allRulesWithTimeFrame.get(i).getsGreenLight(context))
|
||||
allRulesWithTimeFrame.get(i).activate(automationServiceRef, false);
|
||||
if(allRulesWithNowInTimeFrame.get(i).getsGreenLight(context))
|
||||
allRulesWithNowInTimeFrame.get(i).activate(automationServiceRef, false);
|
||||
}
|
||||
|
||||
setOrResetAlarms();
|
||||
|
||||
setAlarms();
|
||||
}
|
||||
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
|
||||
public static void setOrResetAlarms()
|
||||
public static void setAlarms()
|
||||
{
|
||||
alarmCandidates.clear();
|
||||
|
||||
Calendar calNow = Calendar.getInstance();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("E dd.MM.yyyy HH:mm");
|
||||
|
||||
|
||||
clearAlarms();
|
||||
|
||||
|
||||
int i=0;
|
||||
|
||||
|
||||
ArrayList<Rule> allRulesWithTimeFrames = new ArrayList<Rule>();
|
||||
allRulesWithTimeFrames = Rule.findRuleCandidates(Trigger_Enum.timeFrame);
|
||||
|
||||
// allRulesWithTimeFrames = Rule.findRuleCandidatesByTimeFrame();
|
||||
/*
|
||||
* Take care of regular executions, no repetitions in between.
|
||||
*/
|
||||
@ -98,7 +96,7 @@ public class DateTimeListener extends BroadcastReceiver implements AutomationLis
|
||||
TimeFrame tf = new TimeFrame(oneTrigger.getTriggerParameter2());
|
||||
|
||||
Calendar calSet;
|
||||
TimeObject setTime;
|
||||
Time setTime;
|
||||
|
||||
if(oneTrigger.getTriggerParameter())
|
||||
setTime = tf.getTriggerTimeStart();
|
||||
@ -191,17 +189,18 @@ public class DateTimeListener extends BroadcastReceiver implements AutomationLis
|
||||
* 4. Take div result +1 and add this on top of starting time
|
||||
* 5. Is this next possible execution still inside timeframe? Also consider timeframes spanning over midnight
|
||||
*/
|
||||
|
||||
Calendar calSet;
|
||||
Time setTime;
|
||||
TimeFrame tf = new TimeFrame(oneTrigger.getTriggerParameter2());
|
||||
|
||||
if(tf.getRepetition() > 0)
|
||||
{
|
||||
// if(oneTrigger.applies(calNow, Miscellaneous.getAnyContext()))
|
||||
// {
|
||||
Calendar calSchedule = getNextRepeatedExecution(oneTrigger);
|
||||
if(oneTrigger.applies(calNow, Miscellaneous.getAnyContext()))
|
||||
{
|
||||
Calendar calSchedule = getNextRepeatedExecutionAfter(oneTrigger, calNow);
|
||||
|
||||
alarmCandidates.add(new ScheduleElement(calSchedule, "Rule " + oneRule.getName() + ", trigger " + oneTrigger.toString()));
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -212,15 +211,15 @@ public class DateTimeListener extends BroadcastReceiver implements AutomationLis
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
scheduleNextAlarm();
|
||||
}
|
||||
|
||||
|
||||
private static void scheduleNextAlarm()
|
||||
{
|
||||
Long currentTime = System.currentTimeMillis();
|
||||
ScheduleElement scheduleCandidate = null;
|
||||
|
||||
|
||||
if(alarmCandidates.size() == 0)
|
||||
{
|
||||
Miscellaneous.logEvent("i", "AlarmManager", "No alarms to be scheduled.", 3);
|
||||
@ -234,48 +233,38 @@ public class DateTimeListener extends BroadcastReceiver implements AutomationLis
|
||||
else if(alarmCandidates.size() > 1)
|
||||
{
|
||||
scheduleCandidate = alarmCandidates.get(0);
|
||||
|
||||
|
||||
for(ScheduleElement alarmCandidate : alarmCandidates)
|
||||
{
|
||||
if(Math.abs(currentTime - alarmCandidate.time.getTimeInMillis()) < Math.abs(currentTime - scheduleCandidate.time.getTimeInMillis()))
|
||||
scheduleCandidate = alarmCandidate;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Intent alarmIntent = new Intent(automationServiceRef, DateTimeListener.class);
|
||||
|
||||
if(Miscellaneous.getAnyContext().getApplicationContext().getApplicationInfo().targetSdkVersion >= 31)
|
||||
alarmPendingIntent = PendingIntent.getBroadcast(automationServiceRef, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
|
||||
else
|
||||
alarmPendingIntent = PendingIntent.getBroadcast(automationServiceRef, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
||||
centralAlarmManagerInstance.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, scheduleCandidate.time.getTimeInMillis(), alarmPendingIntent);
|
||||
else
|
||||
centralAlarmManagerInstance.set(AlarmManager.RTC_WAKEUP, scheduleCandidate.time.getTimeInMillis(), alarmPendingIntent);
|
||||
alarmPendingIntent = PendingIntent.getBroadcast(automationServiceRef, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
centralAlarmManagerInstance.set(AlarmManager.RTC_WAKEUP, scheduleCandidate.time.getTimeInMillis(), alarmPendingIntent);
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("E dd.MM.yyyy HH:mm:ss");
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTimeInMillis(scheduleCandidate.time.getTimeInMillis());
|
||||
Miscellaneous.logEvent("i", "AlarmManager", "Chose " + sdf.format(calendar.getTime()) + " as next scheduled alarm.", 4);
|
||||
Miscellaneous.logEvent("i", "AlarmManager", "Chose " + sdf.format(calendar.getTime()) + " as next scheduled alarm.", 4);
|
||||
}
|
||||
|
||||
|
||||
public static void clearAlarms()
|
||||
{
|
||||
Miscellaneous.logEvent("i", "AlarmManager", "Clearing possibly standing alarms.", 4);
|
||||
|
||||
for(int requestCode : requestCodeList)
|
||||
{
|
||||
Intent alarmIntent = new Intent(automationServiceRef, DateTimeListener.class);
|
||||
if(alarmPendingIntent == null)
|
||||
alarmPendingIntent = PendingIntent.getBroadcast(automationServiceRef, requestCode, alarmIntent, 0);
|
||||
|
||||
// Miscellaneous.logEvent("i", "AlarmManager", "Clearing alarm with request code: " + String.valueOf(requestCode));
|
||||
centralAlarmManagerInstance.cancel(alarmPendingIntent);
|
||||
}
|
||||
|
||||
requestCodeList.clear();
|
||||
}
|
||||
|
||||
|
||||
private static void startAlarmListenerInternal(AutomationService givenAutomationServiceRef)
|
||||
{
|
||||
if(!alarmListenerActive)
|
||||
@ -283,11 +272,12 @@ public class DateTimeListener extends BroadcastReceiver implements AutomationLis
|
||||
Miscellaneous.logEvent("i", "AlarmListener", "Starting alarm listener.", 4);
|
||||
DateTimeListener.automationServiceRef = givenAutomationServiceRef;
|
||||
centralAlarmManagerInstance = (AlarmManager)automationServiceRef.getSystemService(automationServiceRef.ALARM_SERVICE);
|
||||
|
||||
// alarmIntent = new Intent(automationServiceRef, AlarmListener.class);
|
||||
// alarmPendingIntent = PendingIntent.getBroadcast(automationServiceRef, 0, alarmIntent, 0);
|
||||
alarmListenerActive = true;
|
||||
Miscellaneous.logEvent("i", "AlarmListener", "Alarm listener started.", 4);
|
||||
DateTimeListener.setOrResetAlarms();
|
||||
|
||||
DateTimeListener.setAlarms();
|
||||
|
||||
// // get a Calendar object with current time
|
||||
// Calendar cal = Calendar.getInstance();
|
||||
// // add 5 minutes to the calendar object
|
||||
@ -297,7 +287,7 @@ public class DateTimeListener extends BroadcastReceiver implements AutomationLis
|
||||
else
|
||||
Miscellaneous.logEvent("i", "AlarmListener", "Request to start AlarmListener. But it's already active.", 5);
|
||||
}
|
||||
|
||||
|
||||
private static void stopAlarmListenerInternal()
|
||||
{
|
||||
if(alarmListenerActive)
|
||||
@ -310,7 +300,10 @@ public class DateTimeListener extends BroadcastReceiver implements AutomationLis
|
||||
else
|
||||
Miscellaneous.logEvent("i", "AlarmListener", "Request to stop AlarmListener. But it's not running.", 5);
|
||||
}
|
||||
|
||||
public static void reloadAlarms()
|
||||
{
|
||||
DateTimeListener.setAlarms();
|
||||
}
|
||||
@Override
|
||||
public void startListener(AutomationService automationService)
|
||||
{
|
||||
@ -368,217 +361,46 @@ public class DateTimeListener extends BroadcastReceiver implements AutomationLis
|
||||
}
|
||||
}
|
||||
|
||||
static int getNextDayIntForExecution(Trigger trigger)
|
||||
{
|
||||
TimeFrame tf = new TimeFrame(trigger.getTriggerParameter2());
|
||||
Calendar now = Calendar.getInstance();
|
||||
|
||||
if(tf.getDayList().contains(now.get(Calendar.DAY_OF_WEEK)))
|
||||
return now.get(Calendar.DAY_OF_WEEK);
|
||||
else
|
||||
{
|
||||
int dayNumberOfNextExecution = now.get(Calendar.DAY_OF_WEEK);
|
||||
|
||||
while(!tf.getDayList().contains(dayNumberOfNextExecution))
|
||||
{
|
||||
dayNumberOfNextExecution++;
|
||||
if(dayNumberOfNextExecution > 6)
|
||||
dayNumberOfNextExecution = 1;
|
||||
}
|
||||
|
||||
return dayNumberOfNextExecution;
|
||||
}
|
||||
}
|
||||
|
||||
static int getDayDelta(Calendar now, int dayNumberOfNextExecution)
|
||||
{
|
||||
int result = dayNumberOfNextExecution - now.get(Calendar.DAY_OF_WEEK);
|
||||
|
||||
if(result >= 0)
|
||||
return result;
|
||||
else
|
||||
return 6 + result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@RequiresApi(api = Build.VERSION_CODES.N)
|
||||
public static Calendar getNextRepeatedExecution(Trigger trigger)
|
||||
public static Calendar getNextRepeatedExecutionAfter(Trigger trigger, Calendar now)
|
||||
{
|
||||
Calendar now = Calendar.getInstance();
|
||||
Miscellaneous.logEvent("i", "DateTimeListener", "Checking for next repetition execution after " + Miscellaneous.formatDate(now.getTime()), 5);
|
||||
Calendar calculationStart, calSchedule = null;
|
||||
Calendar calSet;
|
||||
Time setTime;
|
||||
TimeFrame tf = new TimeFrame(trigger.getTriggerParameter2());
|
||||
|
||||
if(tf.getRepetition() > 0)
|
||||
{
|
||||
if(trigger.getTriggerParameter())
|
||||
setTime = tf.getTriggerTimeStart();
|
||||
else
|
||||
setTime = tf.getTriggerTimeStop();
|
||||
|
||||
calSet = (Calendar) now.clone();
|
||||
calSet.set(Calendar.HOUR_OF_DAY, setTime.getHours());
|
||||
calSet.set(Calendar.MINUTE, setTime.getMinutes());
|
||||
calSet.set(Calendar.SECOND, 0);
|
||||
calSet.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
// If the starting time is a day ahead remove 1 day.
|
||||
if(calSet.getTimeInMillis() > now.getTimeInMillis())
|
||||
calSet.add(Calendar.DAY_OF_MONTH, -1);
|
||||
|
||||
long differenceInSeconds = Math.abs(now.getTimeInMillis() - calSet.getTimeInMillis()) / 1000;
|
||||
long nextExecutionMultiplier = Math.floorDiv(differenceInSeconds, tf.getRepetition()) + 1;
|
||||
long nextScheduleTimestamp = (calSet.getTimeInMillis() / 1000) + (nextExecutionMultiplier * tf.getRepetition());
|
||||
Calendar calSchedule = Calendar.getInstance();
|
||||
calSchedule.setTimeInMillis(nextScheduleTimestamp * 1000);
|
||||
|
||||
/*
|
||||
Are we inside of the timeframe or outside?
|
||||
|
||||
Inside -> is this demanded?
|
||||
Yes:
|
||||
If last execution known, calculate from it
|
||||
If not known, calculate from start of timeframe
|
||||
No:
|
||||
Use end-time and add repetition
|
||||
|
||||
Outside? -> is this demanded?
|
||||
Yes:
|
||||
If last execution known, calculate from it
|
||||
If not known, calculate from end of timeframe
|
||||
No:
|
||||
Use start-time and add repetition
|
||||
* Das war mal aktiviert. Allerdings: Die ganze Funktion liefert zurück, wenn die Regel NOCH nicht
|
||||
* zutrifft, aber wir z.B. gleich den zeitlichen Bereich betreten.
|
||||
*/
|
||||
|
||||
if(areWeInTimeFrame(trigger, new Date()))
|
||||
{
|
||||
if(trigger.getTriggerParameter())
|
||||
{
|
||||
if(trigger.getParentRule().getLastExecution() != null)
|
||||
{
|
||||
calculationStart = (Calendar) trigger.getParentRule().getLastExecution().clone();
|
||||
}
|
||||
else
|
||||
{
|
||||
calculationStart = (Calendar) now.clone();
|
||||
calculationStart.set(Calendar.HOUR_OF_DAY, tf.getTriggerTimeStart().getHours());
|
||||
calculationStart.set(Calendar.MINUTE, tf.getTriggerTimeStart().getMinutes());
|
||||
calculationStart.set(Calendar.SECOND, tf.getTriggerTimeStart().getSeconds());
|
||||
calculationStart.set(Calendar.MILLISECOND, 0);
|
||||
}
|
||||
long differenceInSeconds = Math.abs(now.getTimeInMillis() - calculationStart.getTimeInMillis()) / 1000;
|
||||
long nextExecutionMultiplier = Math.floorDiv(differenceInSeconds, tf.getRepetition()) + 1;
|
||||
calSchedule = (Calendar) calculationStart.clone();
|
||||
calSchedule.add(Calendar.SECOND, (int) (nextExecutionMultiplier * tf.getRepetition()));
|
||||
}
|
||||
else
|
||||
{
|
||||
calculationStart = (Calendar) now.clone();
|
||||
calculationStart.set(Calendar.HOUR_OF_DAY, tf.getTriggerTimeStop().getHours());
|
||||
calculationStart.set(Calendar.MINUTE, tf.getTriggerTimeStop().getMinutes());
|
||||
calculationStart.set(Calendar.SECOND, tf.getTriggerTimeStop().getSeconds());
|
||||
calculationStart.set(Calendar.MILLISECOND, 0);
|
||||
calSchedule = (Calendar) calculationStart.clone();
|
||||
calSchedule.add(Calendar.SECOND, (int) tf.getRepetition());
|
||||
}
|
||||
}
|
||||
else // not in timeframe
|
||||
{
|
||||
if (!trigger.getTriggerParameter())
|
||||
{
|
||||
if (trigger.getParentRule().getLastExecution() != null)
|
||||
{
|
||||
calculationStart = (Calendar) trigger.getParentRule().getLastExecution().clone();
|
||||
long differenceInSeconds = Math.abs(now.getTimeInMillis() - calculationStart.getTimeInMillis()) / 1000;
|
||||
long nextExecutionMultiplier = Math.floorDiv(differenceInSeconds, tf.getRepetition()) + 1;
|
||||
calSchedule = (Calendar) calculationStart.clone();
|
||||
calSchedule.add(Calendar.SECOND, (int) (nextExecutionMultiplier * tf.getRepetition()));
|
||||
Miscellaneous.logEvent("i", "getNextRepeatedExecutionAfter()", "Chose " + Miscellaneous.formatDate(calSchedule.getTime()) + " as next repeated execution time.", 5);
|
||||
return calSchedule;
|
||||
}
|
||||
else
|
||||
{
|
||||
calculationStart = (Calendar) now.clone();
|
||||
if(tf.getDayList().contains(now.get(Calendar.DAY_OF_WEEK)))
|
||||
{
|
||||
calculationStart.set(Calendar.HOUR_OF_DAY, tf.getTriggerTimeStop().getHours());
|
||||
calculationStart.set(Calendar.MINUTE, tf.getTriggerTimeStop().getMinutes());
|
||||
calculationStart.set(Calendar.SECOND, tf.getTriggerTimeStop().getSeconds());
|
||||
calculationStart.set(Calendar.MILLISECOND, 0);
|
||||
calculationStart.add(Calendar.SECOND, (int) tf.getRepetition());
|
||||
|
||||
int dayDelta = getDayDelta(now, getNextDayIntForExecution(trigger));
|
||||
calculationStart.add(Calendar.DAY_OF_WEEK, dayDelta);
|
||||
}
|
||||
calSchedule = (Calendar) calculationStart.clone();
|
||||
Miscellaneous.logEvent("i", "getNextRepeatedExecutionAfter()", "Chose " + Miscellaneous.formatDate(calSchedule.getTime()) + " as next repeated execution time.", 5);
|
||||
return calSchedule;
|
||||
}
|
||||
/*long differenceInSeconds = Math.abs(now.getTimeInMillis() - calculationStart.getTimeInMillis()) / 1000;
|
||||
long nextExecutionMultiplier = Math.floorDiv(differenceInSeconds, tf.getRepetition()) + 1;
|
||||
calSchedule = (Calendar) calculationStart.clone();
|
||||
calSchedule.add(Calendar.SECOND, (int) (nextExecutionMultiplier * tf.getRepetition()));*/
|
||||
}
|
||||
else
|
||||
{
|
||||
calculationStart = (Calendar) now.clone();
|
||||
calculationStart.set(Calendar.HOUR_OF_DAY, tf.getTriggerTimeStart().getHours());
|
||||
calculationStart.set(Calendar.MINUTE, tf.getTriggerTimeStart().getMinutes());
|
||||
calculationStart.set(Calendar.SECOND, tf.getTriggerTimeStart().getSeconds());
|
||||
calculationStart.set(Calendar.MILLISECOND, 0);
|
||||
calSchedule = (Calendar) calculationStart.clone();
|
||||
calSchedule.add(Calendar.SECOND, (int) (tf.getRepetition()));
|
||||
}
|
||||
|
||||
if (Miscellaneous.compareTimes(calSchedule, now) > 0)
|
||||
calSchedule.add(Calendar.DAY_OF_MONTH, 1);
|
||||
}
|
||||
|
||||
int dayDelta = getDayDelta(now, getNextDayIntForExecution(trigger));
|
||||
calSchedule.add(Calendar.DAY_OF_WEEK, dayDelta);
|
||||
|
||||
Miscellaneous.logEvent("i", "getNextRepeatedExecutionAfter()", "Chose " + Miscellaneous.formatDate(calSchedule.getTime()) + " as next repeated execution time.", 5);
|
||||
return calSchedule;
|
||||
}
|
||||
else
|
||||
Miscellaneous.logEvent("i", "getNextRepeatedExecutionAfter()", "Trigger " + trigger.toString() + " is not configured to repeat.", 5);
|
||||
Miscellaneous.logEvent("i", "DateTimeListener", "Trigger " + trigger.toString() + " is not executed repeatedly.", 5);
|
||||
|
||||
return calSchedule;
|
||||
}
|
||||
|
||||
public static boolean areWeInTimeFrame(Trigger trigger, Object triggeringObject)
|
||||
{
|
||||
/*
|
||||
* Use format known from Automation
|
||||
* 07:30:00/17:30:00/23456/300 <-- last parameter is optional: repetition in seconds
|
||||
* Also required: inside or outside that interval
|
||||
*/
|
||||
|
||||
Date triggeringTime;
|
||||
// if(triggeringObject instanceof Date)
|
||||
// triggeringTime = (Date)triggeringObject;
|
||||
// else
|
||||
triggeringTime = new Date();
|
||||
|
||||
String timeString = String.valueOf(triggeringTime.getHours()) + ":" + String.valueOf(triggeringTime.getMinutes()) + ":" + String.valueOf(triggeringTime.getSeconds());
|
||||
TimeObject nowTime = TimeObject.valueOf(timeString);
|
||||
Calendar calNow = Calendar.getInstance();
|
||||
|
||||
try
|
||||
{
|
||||
TimeFrame tf = new TimeFrame(trigger.getTriggerParameter2());
|
||||
|
||||
if(tf.getDayList().contains(calNow.get(Calendar.DAY_OF_WEEK)))
|
||||
{
|
||||
if(
|
||||
// Regular case, start time is lower than end time
|
||||
(
|
||||
Miscellaneous.compareTimes(tf.getTriggerTimeStart(), nowTime) >= 0
|
||||
&&
|
||||
Miscellaneous.compareTimes(nowTime, tf.getTriggerTimeStop()) > 0
|
||||
)
|
||||
||
|
||||
// Other case, start time higher than end time, timeframe goes over midnight
|
||||
(
|
||||
Miscellaneous.compareTimes(tf.getTriggerTimeStart(), tf.getTriggerTimeStop()) < 0
|
||||
&&
|
||||
(Miscellaneous.compareTimes(tf.getTriggerTimeStart(), nowTime) >= 0
|
||||
||
|
||||
Miscellaneous.compareTimes(nowTime, tf.getTriggerTimeStop()) > 0)
|
||||
)
|
||||
||
|
||||
// further case: start and end times are identical, meaning a 24h window
|
||||
(
|
||||
Miscellaneous.compareTimes(tf.getTriggerTimeStart(), tf.getTriggerTimeStop()) == 0
|
||||
)
|
||||
)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Miscellaneous.logEvent("e", "Trigger", "There was an error while checking if the time based trigger applies: " + Log.getStackTraceString(e), 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
}
|
@ -34,18 +34,17 @@ public class DeviceOrientationListener implements SensorEventListener, Automatio
|
||||
static int sensorValueCounter = 0;
|
||||
|
||||
// Gravity rotational data
|
||||
float gravity[];
|
||||
private float gravity[];
|
||||
// Magnetic rotational data
|
||||
float magnetic[]; //for magnetic rotational data
|
||||
float accels[] = new float[3];
|
||||
float mags[] = new float[3];
|
||||
float[] values = new float[3];
|
||||
boolean hasMagneticSensor=false;
|
||||
private float magnetic[]; //for magnetic rotational data
|
||||
private float accels[] = new float[3];
|
||||
private float mags[] = new float[3];
|
||||
private float[] values = new float[3];
|
||||
|
||||
// azimuth, pitch and roll
|
||||
float azimuth;
|
||||
float pitch;
|
||||
float roll;
|
||||
private float azimuth;
|
||||
private float pitch;
|
||||
private float roll;
|
||||
|
||||
boolean applies = false;
|
||||
boolean flipped = false;
|
||||
@ -92,7 +91,7 @@ public class DeviceOrientationListener implements SensorEventListener, Automatio
|
||||
isRunning = true;
|
||||
|
||||
sManager.registerListener(this, sManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);
|
||||
hasMagneticSensor = sManager.registerListener(this, sManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD), SensorManager.SENSOR_DELAY_NORMAL);
|
||||
sManager.registerListener(this, sManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD), SensorManager.SENSOR_DELAY_NORMAL);
|
||||
}
|
||||
}
|
||||
|
||||
@ -130,9 +129,6 @@ public class DeviceOrientationListener implements SensorEventListener, Automatio
|
||||
break;
|
||||
}
|
||||
|
||||
if (!hasMagneticSensor)
|
||||
mags=new float[]{1f,1f,1f};
|
||||
|
||||
if (mags != null && accels != null)
|
||||
{
|
||||
gravity = new float[9];
|
||||
|
@ -20,7 +20,7 @@ public class HeadphoneJackListener extends BroadcastReceiver implements Automati
|
||||
private static boolean headsetConnected = false;
|
||||
private static int headphoneType = -1;
|
||||
|
||||
protected static boolean headphoneJackListenerActive = false;
|
||||
protected static boolean headphoneJackListenerActive=false;
|
||||
protected static IntentFilter headphoneJackListenerIntentFilter = null;
|
||||
protected static HeadphoneJackListener instance;
|
||||
|
||||
@ -76,6 +76,7 @@ public class HeadphoneJackListener extends BroadcastReceiver implements Automati
|
||||
}
|
||||
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger_Enum.headsetPlugged);
|
||||
// ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByHeadphoneJack(isHeadsetConnected());
|
||||
for(int i=0; i<ruleCandidates.size(); i++)
|
||||
{
|
||||
if(ruleCandidates.get(i).getsGreenLight(context))
|
||||
@ -103,12 +104,13 @@ public class HeadphoneJackListener extends BroadcastReceiver implements Automati
|
||||
{
|
||||
Miscellaneous.logEvent("i", "HeadsetJackListener", "Starting HeadsetJackListener", 4);
|
||||
headphoneJackListenerActive = true;
|
||||
// getInstance().startHeadphoneJackListener(AutomationService.getInstance(), headphoneJackListenerIntentFilter);
|
||||
automationService.registerReceiver(this, headphoneJackListenerIntentFilter);
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Miscellaneous.logEvent("e", "HeadsetJackListener", "Error starting HeadsetJackListener: " + Log.getStackTraceString(ex), 3);
|
||||
Miscellaneous.logEvent("e", "ActivityDetectionReceiver", "Error starting HeadsetJackListener: " + Log.getStackTraceString(ex), 3);
|
||||
}
|
||||
}
|
||||
|
||||
@ -120,6 +122,7 @@ public class HeadphoneJackListener extends BroadcastReceiver implements Automati
|
||||
if(headphoneJackListenerActive)
|
||||
{
|
||||
Miscellaneous.logEvent("i", "HeadsetJackListener", "Stopping HeadsetJackListener", 4);
|
||||
// getInstance().stopHeadphoneJackListener(AutomationService.getInstance());
|
||||
automationService.unregisterReceiver(this);
|
||||
headphoneJackListenerActive = false;
|
||||
}
|
||||
@ -147,4 +150,5 @@ public class HeadphoneJackListener extends BroadcastReceiver implements Automati
|
||||
{
|
||||
return new Trigger_Enum[] { Trigger_Enum.headsetPlugged };
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,14 +2,15 @@ package com.jens.automation2.receivers;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Notification;
|
||||
import android.app.PendingIntent;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.service.notification.NotificationListenerService;
|
||||
import android.service.notification.StatusBarNotification;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
|
||||
import com.jens.automation2.AutomationService;
|
||||
@ -19,7 +20,6 @@ import com.jens.automation2.Trigger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
// See here for reference: http://gmariotti.blogspot.com/2013/11/notificationlistenerservice-and-kitkat.html
|
||||
|
||||
@ -27,6 +27,8 @@ import java.util.List;
|
||||
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
|
||||
public class NotificationListener extends NotificationListenerService// implements AutomationListenerInterface
|
||||
{
|
||||
static Calendar lastResponseToNotification = null;
|
||||
static boolean listenerRunning = false;
|
||||
static NotificationListener instance;
|
||||
static SimpleNotification lastNotification = null;
|
||||
|
||||
@ -42,30 +44,13 @@ public class NotificationListener extends NotificationListenerService// implemen
|
||||
// a bitmap to be used instead of the small icon when showing the notification payload
|
||||
public static final String EXTRA_LARGE_ICON = "android.largeIcon";
|
||||
|
||||
public static void setLastNotification(SimpleNotification notification)
|
||||
{
|
||||
lastNotification = notification;
|
||||
}
|
||||
protected static IntentFilter notificationReceiverIntentFilter = null;
|
||||
|
||||
public static SimpleNotification getLastNotification()
|
||||
{
|
||||
return lastNotification;
|
||||
}
|
||||
|
||||
// To determine for which notifications which rules have been executed
|
||||
static List<RuleNotificationPair> notificationUsed = new ArrayList<>();
|
||||
|
||||
public static class RuleNotificationPair
|
||||
{
|
||||
Rule rule;
|
||||
SimpleNotification notification;
|
||||
|
||||
public RuleNotificationPair(Rule rule, SimpleNotification sn)
|
||||
{
|
||||
this.rule = rule;
|
||||
this.notification = sn;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate()
|
||||
{
|
||||
@ -100,16 +85,10 @@ public class NotificationListener extends NotificationListenerService// implemen
|
||||
|
||||
synchronized boolean checkNotification(boolean created, StatusBarNotification sbn)
|
||||
{
|
||||
//TODO: Merge with functino in Trigger class
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT)
|
||||
{
|
||||
lastNotification = convertNotificationToSimpleNotification(created, sbn);
|
||||
|
||||
if(created)
|
||||
Miscellaneous.logEvent("i", "New notification", lastNotification.toString(), 5);
|
||||
else
|
||||
Miscellaneous.logEvent("i", "Notification removed", lastNotification.toString(), 5);
|
||||
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.notification);
|
||||
for (int i = 0; i < ruleCandidates.size(); i++)
|
||||
{
|
||||
@ -165,6 +144,51 @@ public class NotificationListener extends NotificationListenerService// implemen
|
||||
return returnNotification;
|
||||
}
|
||||
|
||||
/*@Override
|
||||
public void startListener(AutomationService automationService)
|
||||
{
|
||||
if(instance == null)
|
||||
instance = new NotificationListener();
|
||||
|
||||
if(notificationReceiverIntentFilter == null)
|
||||
{
|
||||
notificationReceiverIntentFilter = new IntentFilter();
|
||||
notificationReceiverIntentFilter.addAction("android.service.notification.NotificationListenerService");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if(!listenerRunning)
|
||||
{
|
||||
Miscellaneous.logEvent("i", "NotificationListener", "Starting NotificationListener", 4);
|
||||
listenerRunning = true;
|
||||
AutomationService.getInstance().registerReceiver(instance, notificationReceiverIntentFilter);
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Miscellaneous.logEvent("e", "BluetoothReceiver", "Error starting BluetoothReceiver: " + Log.getStackTraceString(ex), 3);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopListener(AutomationService automationService)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isListenerRunning()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Trigger.Trigger_Enum[] getMonitoredTrigger()
|
||||
{
|
||||
return new Trigger.Trigger_Enum[0];
|
||||
}*/
|
||||
|
||||
public static class SimpleNotification
|
||||
{
|
||||
boolean created;
|
||||
@ -232,19 +256,6 @@ public class NotificationListener extends NotificationListenerService// implemen
|
||||
", text='" + text + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object obj)
|
||||
{
|
||||
return
|
||||
this.publishTime.getTimeInMillis() == ((SimpleNotification)obj).publishTime.getTimeInMillis()
|
||||
&&
|
||||
this.app.equals(((SimpleNotification)obj).app)
|
||||
&&
|
||||
this.title.equals(((SimpleNotification)obj).title)
|
||||
&&
|
||||
this.text.equals(((SimpleNotification)obj).text);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -265,36 +276,6 @@ public class NotificationListener extends NotificationListenerService// implemen
|
||||
cancelNotification(sbn.getPackageName(), sbn.getTag(), sbn.getId());
|
||||
else
|
||||
cancelNotification(sbn.getKey());
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
|
||||
public void clickNotificationButton(StatusBarNotification sbn, String buttonText)
|
||||
{
|
||||
boolean buttonFound = false;
|
||||
|
||||
if(sbn.getNotification().actions != null)
|
||||
{
|
||||
for (Notification.Action a : sbn.getNotification().actions)
|
||||
{
|
||||
if((Miscellaneous.isRegularExpression(buttonText) && a.title.toString().matches(buttonText)) || a.title.toString().equalsIgnoreCase(buttonText))
|
||||
{
|
||||
if (!buttonFound)
|
||||
buttonFound = true;
|
||||
|
||||
try
|
||||
{
|
||||
Miscellaneous.logEvent("w", "clickNotificationButton()", "Pressing button with text \"" + a.title.toString() + "\".", 2);
|
||||
a.actionIntent.send();
|
||||
}
|
||||
catch (PendingIntent.CanceledException e)
|
||||
{
|
||||
Miscellaneous.logEvent("w", "clickNotificationButton()", Log.getStackTraceString(e), 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!buttonFound)
|
||||
Miscellaneous.logEvent("w", "clickNotificationButton()", "Button with text \n" + buttonText + "\n could not found.", 2);
|
||||
}
|
||||
}
|
@ -6,15 +6,10 @@ import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.os.Build;
|
||||
import android.telephony.PhoneStateListener;
|
||||
import android.telephony.TelephonyCallback;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
|
||||
import com.jens.automation2.ActivityPermissions;
|
||||
import com.jens.automation2.AutomationService;
|
||||
import com.jens.automation2.Miscellaneous;
|
||||
@ -27,7 +22,8 @@ import java.util.ArrayList;
|
||||
|
||||
public class PhoneStatusListener implements AutomationListenerInterface
|
||||
{
|
||||
static int problematicAndroidLevel = 29;
|
||||
// protected static int currentStateIncoming = -1;
|
||||
// protected static int currentStateOutgoing = -1;
|
||||
protected static String lastPhoneNumber="";
|
||||
protected static int lastPhoneDirection = -1; //0=incoming, 1=outgoing
|
||||
protected static int currentState = -1;
|
||||
@ -76,76 +72,7 @@ public class PhoneStatusListener implements AutomationListenerInterface
|
||||
return currentState;
|
||||
}
|
||||
|
||||
public static interface IncomingCallsReceiver
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected static void workWithIncomingCallData(int state, String incomingNumber)
|
||||
{
|
||||
if(lastPhoneDirection == 2 && currentState != TelephonyManager.CALL_STATE_IDLE)
|
||||
{
|
||||
// This status update is actually for an outgoing call
|
||||
setCurrentState(state);
|
||||
|
||||
if(incomingNumber != null && incomingNumber.length() > 0) // check for null in case call comes in with suppressed number.
|
||||
setLastPhoneNumber(incomingNumber);
|
||||
|
||||
switch(state)
|
||||
{
|
||||
case TelephonyManager.CALL_STATE_IDLE:
|
||||
Miscellaneous.logEvent("i", "Call state", "New call state: CALL_STATE_IDLE", 4);
|
||||
break;
|
||||
case TelephonyManager.CALL_STATE_OFFHOOK:
|
||||
Miscellaneous.logEvent("i", "Call state", "New call state: CALL_STATE_OFFHOOK", 4);
|
||||
break;
|
||||
case TelephonyManager.CALL_STATE_RINGING:
|
||||
Miscellaneous.logEvent("i", "Call state", String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.outgoingCallTo), incomingNumber), 4);
|
||||
break;
|
||||
}
|
||||
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger_Enum.phoneCall);
|
||||
for(int i=0; i<ruleCandidates.size(); i++)
|
||||
{
|
||||
AutomationService asInstance = AutomationService.getInstance();
|
||||
if(asInstance != null)
|
||||
if(ruleCandidates.get(i).getsGreenLight(asInstance))
|
||||
ruleCandidates.get(i).activate(asInstance, false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
setCurrentState(state);
|
||||
setLastPhoneDirection(1);
|
||||
|
||||
if (incomingNumber != null && incomingNumber.length() > 0) // check for null in case call comes in with suppressed number.
|
||||
setLastPhoneNumber(incomingNumber);
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case TelephonyManager.CALL_STATE_IDLE:
|
||||
Miscellaneous.logEvent("i", "Call state", "New call state: CALL_STATE_IDLE", 4);
|
||||
break;
|
||||
case TelephonyManager.CALL_STATE_OFFHOOK:
|
||||
Miscellaneous.logEvent("i", "Call state", "New call state: CALL_STATE_OFFHOOK", 4);
|
||||
break;
|
||||
case TelephonyManager.CALL_STATE_RINGING:
|
||||
Miscellaneous.logEvent("i", "Call state", String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.incomingCallFrom), incomingNumber), 4);
|
||||
break;
|
||||
}
|
||||
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger_Enum.phoneCall);
|
||||
for (int i = 0; i < ruleCandidates.size(); i++)
|
||||
{
|
||||
AutomationService asInstance = AutomationService.getInstance();
|
||||
if (asInstance != null)
|
||||
if (ruleCandidates.get(i).getsGreenLight(asInstance))
|
||||
ruleCandidates.get(i).activate(asInstance, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class IncomingCallsReceiverOld extends PhoneStateListener implements IncomingCallsReceiver
|
||||
public static class IncomingCallsReceiver extends PhoneStateListener
|
||||
{
|
||||
@Override
|
||||
public void onCallStateChanged(int state, String incomingNumber)
|
||||
@ -161,42 +88,67 @@ public class PhoneStatusListener implements AutomationListenerInterface
|
||||
If the last call was outgoing the state has not changed to idle this is kind of a fake alert.
|
||||
*/
|
||||
|
||||
workWithIncomingCallData(state, incomingNumber);
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.S)
|
||||
public static class IncomingCallsReceiverNew extends BroadcastReceiver implements IncomingCallsReceiver
|
||||
{
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent)
|
||||
{
|
||||
/*
|
||||
this code detects both incoming and outgoing,
|
||||
if the state changes idle => ringing you know it's an incoming call,
|
||||
if the state changes idle => offhook, you know it's an outgoing call
|
||||
*/
|
||||
|
||||
if (!intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL))
|
||||
if(lastPhoneDirection == 2 && currentState != TelephonyManager.CALL_STATE_IDLE)
|
||||
{
|
||||
String stateStr = intent.getExtras().getString(TelephonyManager.EXTRA_STATE);
|
||||
int state = 99;
|
||||
// This status update is actually for an outgoing call
|
||||
setCurrentState(state);
|
||||
|
||||
switch(stateStr)
|
||||
if(incomingNumber != null && incomingNumber.length() > 0) // check for null in case call comes in with suppressed number.
|
||||
setLastPhoneNumber(incomingNumber);
|
||||
|
||||
switch(state)
|
||||
{
|
||||
case "RINGING":
|
||||
state = TelephonyManager.CALL_STATE_RINGING;
|
||||
case TelephonyManager.CALL_STATE_IDLE:
|
||||
Miscellaneous.logEvent("i", "Call state", "New call state: CALL_STATE_IDLE", 4);
|
||||
break;
|
||||
case "IDLE":
|
||||
state = TelephonyManager.CALL_STATE_IDLE;
|
||||
case TelephonyManager.CALL_STATE_OFFHOOK:
|
||||
Miscellaneous.logEvent("i", "Call state", "New call state: CALL_STATE_OFFHOOK", 4);
|
||||
break;
|
||||
case "OFFHOOK":
|
||||
state = TelephonyManager.CALL_STATE_OFFHOOK;
|
||||
case TelephonyManager.CALL_STATE_RINGING:
|
||||
Miscellaneous.logEvent("i", "Call state", String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.outgoingCallTo), incomingNumber), 4);
|
||||
break;
|
||||
}
|
||||
|
||||
String number = intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
|
||||
Log.i("test", "test");
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger_Enum.phoneCall);
|
||||
for(int i=0; i<ruleCandidates.size(); i++)
|
||||
{
|
||||
AutomationService asInstance = AutomationService.getInstance();
|
||||
if(asInstance != null)
|
||||
if(ruleCandidates.get(i).getsGreenLight(asInstance))
|
||||
ruleCandidates.get(i).activate(asInstance, false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// state != TelephonyManager.CALL_STATE_IDLE &&
|
||||
|
||||
setCurrentState(state);
|
||||
setLastPhoneDirection(1);
|
||||
|
||||
if (incomingNumber != null && incomingNumber.length() > 0) // check for null in case call comes in with suppressed number.
|
||||
setLastPhoneNumber(incomingNumber);
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case TelephonyManager.CALL_STATE_IDLE:
|
||||
Miscellaneous.logEvent("i", "Call state", "New call state: CALL_STATE_IDLE", 4);
|
||||
break;
|
||||
case TelephonyManager.CALL_STATE_OFFHOOK:
|
||||
Miscellaneous.logEvent("i", "Call state", "New call state: CALL_STATE_OFFHOOK", 4);
|
||||
break;
|
||||
case TelephonyManager.CALL_STATE_RINGING:
|
||||
Miscellaneous.logEvent("i", "Call state", String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.incomingCallFrom), incomingNumber), 4);
|
||||
break;
|
||||
}
|
||||
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger_Enum.phoneCall);
|
||||
for (int i = 0; i < ruleCandidates.size(); i++)
|
||||
{
|
||||
AutomationService asInstance = AutomationService.getInstance();
|
||||
if (asInstance != null)
|
||||
if (ruleCandidates.get(i).getsGreenLight(asInstance))
|
||||
ruleCandidates.get(i).activate(asInstance, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -223,12 +175,12 @@ public class PhoneStatusListener implements AutomationListenerInterface
|
||||
Miscellaneous.logEvent("i", "Call state", String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.outgoingCallTo), getLastPhoneNumber()), 4);
|
||||
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger_Enum.phoneCall);
|
||||
for(int i = 0; i < ruleCandidates.size(); i++)
|
||||
for(int i=0; i<ruleCandidates.size(); i++)
|
||||
{
|
||||
AutomationService asInstance = AutomationService.getInstance();
|
||||
if(asInstance != null)
|
||||
if(ruleCandidates.get(i).getsGreenLight(asInstance))
|
||||
ruleCandidates.get(i).activate(asInstance, false);
|
||||
ruleCandidates.get(i).activate(asInstance, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -253,12 +205,7 @@ public class PhoneStatusListener implements AutomationListenerInterface
|
||||
}
|
||||
|
||||
if(incomingCallsReceiverInstance == null)
|
||||
{
|
||||
// if(Build.VERSION.SDK_INT >= 31)
|
||||
// incomingCallsReceiverInstance = new IncomingCallsReceiverNew();
|
||||
// else
|
||||
incomingCallsReceiverInstance = new IncomingCallsReceiverOld();
|
||||
}
|
||||
incomingCallsReceiverInstance = new IncomingCallsReceiver();
|
||||
|
||||
if(outgoingCallsReceiverInstance == null)
|
||||
outgoingCallsReceiverInstance = new OutgoingCallsReceiver();
|
||||
@ -268,17 +215,8 @@ public class PhoneStatusListener implements AutomationListenerInterface
|
||||
if(!incomingCallsReceiverActive)
|
||||
{
|
||||
Miscellaneous.logEvent("i", "PhoneStatusListener", "Starting PhoneStatusListener->incomingCallsReceiver", 4);
|
||||
// if(Build.VERSION.SDK_INT >= problematicAndroidLevel)
|
||||
// {
|
||||
// IntentFilter callsFilter = new IntentFilter();
|
||||
// callsFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
|
||||
// automationService.registerReceiver((IncomingCallsReceiverNew)incomingCallsReceiverInstance, callsFilter);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
TelephonyManager tm = (TelephonyManager) automationService.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
tm.listen((IncomingCallsReceiverOld)incomingCallsReceiverInstance, PhoneStateListener.LISTEN_CALL_STATE);
|
||||
// }
|
||||
TelephonyManager tm = (TelephonyManager)automationService.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
tm.listen(incomingCallsReceiverInstance, PhoneStateListener.LISTEN_CALL_STATE);
|
||||
incomingCallsReceiverActive = true;
|
||||
}
|
||||
|
||||
@ -302,15 +240,8 @@ public class PhoneStatusListener implements AutomationListenerInterface
|
||||
if(incomingCallsReceiverActive)
|
||||
{
|
||||
Miscellaneous.logEvent("i", "PhoneStatusListener", "Stopping phoneStatusListener", 4);
|
||||
// if(Build.VERSION.SDK_INT >= 31)
|
||||
// {
|
||||
// automationService.unregisterReceiver((IncomingCallsReceiverNew)incomingCallsReceiverInstance);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
TelephonyManager tm = (TelephonyManager) automationService.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
tm.listen((IncomingCallsReceiverOld)incomingCallsReceiverInstance, PhoneStateListener.LISTEN_NONE);
|
||||
// }
|
||||
TelephonyManager tm = (TelephonyManager)automationService.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
tm.listen(incomingCallsReceiverInstance, PhoneStateListener.LISTEN_NONE);
|
||||
incomingCallsReceiverActive = false;
|
||||
}
|
||||
|
||||
@ -358,4 +289,4 @@ public class PhoneStatusListener implements AutomationListenerInterface
|
||||
{
|
||||
return new Trigger_Enum[] { Trigger_Enum.phoneCall };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,14 @@
|
||||
package com.jens.automation2.receivers;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.KeyguardManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Build;
|
||||
import android.provider.Settings;
|
||||
import android.os.BatteryManager;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
|
||||
import com.jens.automation2.Actions;
|
||||
import com.jens.automation2.ActivityPermissions;
|
||||
import com.jens.automation2.AutomationService;
|
||||
import com.jens.automation2.Miscellaneous;
|
||||
@ -20,13 +16,10 @@ import com.jens.automation2.Rule;
|
||||
import com.jens.automation2.Trigger.Trigger_Enum;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
public class ScreenStateReceiver extends BroadcastReceiver implements AutomationListenerInterface
|
||||
{
|
||||
static int screenPowerState = -1; // initialize with a better value than this
|
||||
static int screenLockState = -1; // initialize with a better value than this
|
||||
static int screenState = -1; // initialize with a better value than this
|
||||
public static AutomationService automationServiceRef = null;
|
||||
|
||||
private static boolean screenStateReceiverActive = false;
|
||||
@ -34,18 +27,9 @@ public class ScreenStateReceiver extends BroadcastReceiver implements Automation
|
||||
private static Intent screenStatusIntent = null;
|
||||
private static BroadcastReceiver screenStateReceiverInstance = null;
|
||||
|
||||
public final static String broadcastScreenLockedWithoutSecurity = "automation.system.screen_locked_without_security";
|
||||
public final static String broadcastScreenLockedWithSecurity = "automation.system.screen_locked_with_security";
|
||||
|
||||
public final static int SCREEN_STATE_OFF = 0;
|
||||
public final static int SCREEN_STATE_ON = 1;
|
||||
public final static int SCREEN_STATE_UNLOCKED = 2;
|
||||
public final static int SCREEN_STATE_LOCKED_WITHOUT_SECURITY = 3;
|
||||
public final static int SCREEN_STATE_LOCKED_WITH_SECURITY = 4;
|
||||
|
||||
public static BroadcastReceiver getScreenStateReceiverInstance()
|
||||
{
|
||||
if (screenStateReceiverInstance == null)
|
||||
if(screenStateReceiverInstance == null)
|
||||
screenStateReceiverInstance = new ScreenStateReceiver();
|
||||
|
||||
return screenStateReceiverInstance;
|
||||
@ -53,60 +37,58 @@ public class ScreenStateReceiver extends BroadcastReceiver implements Automation
|
||||
|
||||
public static void startScreenStateReceiver(final AutomationService automationServiceRef)
|
||||
{
|
||||
if (!screenStateReceiverActive)
|
||||
if(!screenStateReceiverActive)
|
||||
{
|
||||
ScreenStateReceiver.automationServiceRef = automationServiceRef;
|
||||
|
||||
if (screenStateReceiverInstance == null)
|
||||
|
||||
if(screenStateReceiverInstance == null)
|
||||
screenStateReceiverInstance = new ScreenStateReceiver();
|
||||
|
||||
if (screenStateIntentFilter == null)
|
||||
|
||||
if(screenStateIntentFilter == null)
|
||||
{
|
||||
screenStateIntentFilter = new IntentFilter();
|
||||
screenStateIntentFilter.addAction(Intent.ACTION_SCREEN_OFF);
|
||||
screenStateIntentFilter.addAction(Intent.ACTION_SCREEN_ON);
|
||||
screenStateIntentFilter.addAction(Intent.ACTION_USER_PRESENT); // also fired when device is unlocked
|
||||
screenStateIntentFilter.addAction(broadcastScreenLockedWithoutSecurity);
|
||||
screenStateIntentFilter.addAction(broadcastScreenLockedWithSecurity);
|
||||
screenStateIntentFilter.addAction(Intent.ACTION_USER_PRESENT);
|
||||
// Intent.ACTION_USER_UNLOCKED
|
||||
}
|
||||
|
||||
|
||||
screenStatusIntent = automationServiceRef.registerReceiver(screenStateReceiverInstance, screenStateIntentFilter);
|
||||
|
||||
|
||||
screenStateReceiverActive = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static void stopScreenStateReceiver()
|
||||
{
|
||||
if (screenStateReceiverActive)
|
||||
if(screenStateReceiverActive)
|
||||
{
|
||||
if (screenStateReceiverInstance != null)
|
||||
if(screenStateReceiverInstance != null)
|
||||
{
|
||||
automationServiceRef.unregisterReceiver(screenStateReceiverInstance);
|
||||
screenStateReceiverInstance = null;
|
||||
}
|
||||
|
||||
|
||||
screenStateReceiverActive = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static boolean isScreenStateReceiverActive()
|
||||
{
|
||||
return screenStateReceiverActive;
|
||||
}
|
||||
|
||||
public static int getScreenPowerState()
|
||||
public static int getScreenState()
|
||||
{
|
||||
return screenPowerState;
|
||||
return screenState;
|
||||
}
|
||||
|
||||
public static int getScreenLockState()
|
||||
private static int currentChargingState = 0; //0=unknown, 1=no, 2=yes
|
||||
|
||||
public static int getCurrentChargingState()
|
||||
{
|
||||
return screenLockState;
|
||||
return currentChargingState;
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP_MR1)
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent)
|
||||
{
|
||||
@ -119,65 +101,32 @@ public class ScreenStateReceiver extends BroadcastReceiver implements Automation
|
||||
|
||||
try
|
||||
{
|
||||
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF))
|
||||
if(intent.getAction().equals(Intent.ACTION_SCREEN_OFF))
|
||||
{
|
||||
ScreenStateReceiver.screenPowerState = SCREEN_STATE_OFF;
|
||||
|
||||
KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
|
||||
|
||||
// PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||
// Miscellaneous.logEvent("i", "ScreenStateReceiver", "Method 2: " + String.valueOf(pm.isInteractive() && pm.isScreenOn() && keyguardManager.isKeyguardLocked() && keyguardManager.isDeviceLocked()), 4);
|
||||
// if (pm.isInteractive() && pm.isScreenOn() && keyguardManager.isKeyguardLocked() && keyguardManager.isDeviceLocked())
|
||||
// Miscellaneous.logEvent("i", "ScreenStateReceiver", "pm.isInteractive(): " + String.valueOf(pm.isInteractive()), 4);
|
||||
// Miscellaneous.logEvent("i", "ScreenStateReceiver", "pm.isScreenOn(): " + String.valueOf(pm.isScreenOn()), 4);
|
||||
Miscellaneous.logEvent("i", "ScreenStateReceiver", "keyguardManager.isKeyguardLocked(): " + String.valueOf(keyguardManager.isKeyguardLocked()), 4);
|
||||
Miscellaneous.logEvent("i", "ScreenStateReceiver", "keyguardManager.isDeviceLocked(): " + String.valueOf(keyguardManager.isDeviceLocked()), 4);
|
||||
|
||||
if(keyguardManager.isKeyguardLocked() && !keyguardManager.isDeviceLocked())
|
||||
{
|
||||
Actions.sendBroadcast(Miscellaneous.getAnyContext(), broadcastScreenLockedWithoutSecurity);
|
||||
}
|
||||
else if(keyguardManager.isDeviceLocked())
|
||||
{
|
||||
Actions.sendBroadcast(Miscellaneous.getAnyContext(), broadcastScreenLockedWithSecurity);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Lock may be activated delayed, not at power button press
|
||||
ScreenLockMonitor mon = new ScreenLockMonitor();
|
||||
mon.startMonitor();
|
||||
}
|
||||
ScreenStateReceiver.screenState = 0;
|
||||
}
|
||||
else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON))
|
||||
else if(intent.getAction().equals(Intent.ACTION_SCREEN_ON))
|
||||
{
|
||||
ScreenStateReceiver.screenPowerState = SCREEN_STATE_ON;
|
||||
ScreenStateReceiver.screenState = 1;
|
||||
}
|
||||
else if (intent.getAction().equals(Intent.ACTION_USER_PRESENT))
|
||||
else if(intent.getAction().equals(Intent.ACTION_USER_PRESENT))
|
||||
{
|
||||
ScreenStateReceiver.screenLockState = SCREEN_STATE_UNLOCKED;
|
||||
}
|
||||
else if (intent.getAction().equals(broadcastScreenLockedWithoutSecurity))
|
||||
{
|
||||
ScreenStateReceiver.screenLockState = SCREEN_STATE_LOCKED_WITHOUT_SECURITY;
|
||||
}
|
||||
else if (intent.getAction().equals(broadcastScreenLockedWithSecurity))
|
||||
{
|
||||
ScreenStateReceiver.screenLockState = SCREEN_STATE_LOCKED_WITH_SECURITY;
|
||||
ScreenStateReceiver.screenState = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
Miscellaneous.logEvent("e", "ScreenStateReceiver", "Unknown state received: " + intent.getAction(), 3);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
catch(Exception e)
|
||||
{
|
||||
Miscellaneous.logEvent("e", "ScreenStateReceiver", "Error receiving screen state: " + e.getMessage(), 3);
|
||||
}
|
||||
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger_Enum.screenState);
|
||||
for (int i = 0; i < ruleCandidates.size(); i++)
|
||||
for(int i=0; i<ruleCandidates.size(); i++)
|
||||
{
|
||||
if (ruleCandidates.get(i).getsGreenLight(context))
|
||||
if(ruleCandidates.get(i).getsGreenLight(context))
|
||||
ruleCandidates.get(i).activate(automationServiceRef, false);
|
||||
}
|
||||
}
|
||||
@ -187,7 +136,6 @@ public class ScreenStateReceiver extends BroadcastReceiver implements Automation
|
||||
{
|
||||
ScreenStateReceiver.startScreenStateReceiver(automationService);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopListener(AutomationService automationService)
|
||||
{
|
||||
@ -197,7 +145,7 @@ public class ScreenStateReceiver extends BroadcastReceiver implements Automation
|
||||
public static boolean haveAllPermission()
|
||||
{
|
||||
return ActivityPermissions.havePermission(Manifest.permission.READ_PHONE_STATE, Miscellaneous.getAnyContext()) &&
|
||||
ActivityPermissions.havePermission(Manifest.permission.BATTERY_STATS, Miscellaneous.getAnyContext());
|
||||
ActivityPermissions.havePermission(Manifest.permission.BATTERY_STATS, Miscellaneous.getAnyContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -209,66 +157,6 @@ public class ScreenStateReceiver extends BroadcastReceiver implements Automation
|
||||
@Override
|
||||
public Trigger_Enum[] getMonitoredTrigger()
|
||||
{
|
||||
return new Trigger_Enum[]{Trigger_Enum.screenState};
|
||||
}
|
||||
|
||||
class ScreenLockMonitor
|
||||
{
|
||||
long runs = 0;
|
||||
final long maxRuns = 20;
|
||||
final long interval = 1000;
|
||||
|
||||
Timer timer = new Timer();
|
||||
|
||||
TimerTask task = new TimerTask()
|
||||
{
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP_MR1)
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
KeyguardManager keyguardManager = (KeyguardManager) Miscellaneous.getAnyContext().getSystemService(Context.KEYGUARD_SERVICE);
|
||||
|
||||
Miscellaneous.logEvent("i", "ScreenStateReceiver", "keyguardManager.isKeyguardLocked(): " + String.valueOf(keyguardManager.isKeyguardLocked()), 4);
|
||||
Miscellaneous.logEvent("i", "ScreenStateReceiver", "keyguardManager.isDeviceLocked(): " + String.valueOf(keyguardManager.isDeviceLocked()), 4);
|
||||
|
||||
if(keyguardManager.isKeyguardLocked() && !keyguardManager.isDeviceLocked())
|
||||
{
|
||||
Actions.sendBroadcast(Miscellaneous.getAnyContext(), broadcastScreenLockedWithoutSecurity);
|
||||
timer.purge();
|
||||
timer.cancel();
|
||||
}
|
||||
else if(keyguardManager.isDeviceLocked())
|
||||
{
|
||||
Actions.sendBroadcast(Miscellaneous.getAnyContext(), broadcastScreenLockedWithSecurity);
|
||||
timer.purge();
|
||||
timer.cancel();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (runs++ > maxRuns)
|
||||
{
|
||||
Miscellaneous.logEvent("w", "ScreenStateReceiver->ScreenLockMonitor", "Lock never came.", 4);
|
||||
timer.purge();
|
||||
timer.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public void startMonitor()
|
||||
{
|
||||
ContentResolver mResolver = Miscellaneous.getAnyContext().getContentResolver();
|
||||
long lockscreen_timeout = 0;
|
||||
|
||||
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1)
|
||||
lockscreen_timeout = Settings.System.getInt(mResolver, "lock_screen_lock_after_timeout", 0);
|
||||
else
|
||||
lockscreen_timeout = Settings.Secure.getInt(mResolver, "lock_screen_lock_after_timeout", 0);
|
||||
|
||||
if(lockscreen_timeout > 0)
|
||||
timer.schedule(task, lockscreen_timeout);
|
||||
else
|
||||
timer.scheduleAtFixedRate(task, 0, interval);
|
||||
}
|
||||
return new Trigger_Enum[] { Trigger_Enum.screenState };
|
||||
}
|
||||
}
|
@ -11,13 +11,12 @@ import com.jens.automation2.Settings;
|
||||
|
||||
public class StartupIntentReceiver extends BroadcastReceiver
|
||||
{
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent)
|
||||
{
|
||||
Settings.readFromPersistentStorage(context);
|
||||
|
||||
Miscellaneous.startupContext = context;
|
||||
|
||||
// Miscellaneous.logEvent("i", "Boot event", "Received event: " + intent.getAction(), 5);
|
||||
|
||||
if(Settings.startServiceAtSystemBoot)
|
||||
|
@ -1,151 +0,0 @@
|
||||
package com.jens.automation2.receivers;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.net.wifi.WifiManager;
|
||||
|
||||
import com.jens.automation2.AutomationService;
|
||||
import com.jens.automation2.Miscellaneous;
|
||||
import com.jens.automation2.Rule;
|
||||
import com.jens.automation2.Trigger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class SubSystemStateReceiver extends BroadcastReceiver implements AutomationListenerInterface
|
||||
{
|
||||
public static AutomationService automationServiceRef = null;
|
||||
private static IntentFilter subSystemStateIntentFilter = null;
|
||||
private static BroadcastReceiver subSystemStateReceiverInstance = null;
|
||||
private static Intent subSystemStatusIntent = null;
|
||||
private static boolean subSystemStateReceiverActive = false;
|
||||
static SubSystemStateReceiver instance;
|
||||
|
||||
final static String stateBluetooth = "android.bluetooth.adapter.action.STATE_CHANGED";
|
||||
final static String stateWifi = "android.net.wifi.STATE_CHANGE";
|
||||
final static String connectivityBroadcast = "android.net.conn.CONNECTIVITY_CHANGE";
|
||||
|
||||
static Map<String, Boolean> stateMap = null;
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent)
|
||||
{
|
||||
if (intent == null)
|
||||
return;
|
||||
if (context == null)
|
||||
return;
|
||||
|
||||
Miscellaneous.logEvent("e", "ScreenStateReceiver", "Received: " + intent.getAction(), 3);
|
||||
|
||||
if(stateMap == null)
|
||||
stateMap = new HashMap<>();
|
||||
|
||||
try
|
||||
{
|
||||
/*if (intent.getAction().equals(stateWifi) || intent.getAction().equals(connectivityBroadcast))
|
||||
{
|
||||
if(intent.hasExtra(WifiManager.EXTRA_WIFI_STATE))
|
||||
{
|
||||
int wifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_UNKNOWN);
|
||||
|
||||
if (wifiState == WifiManager.WIFI_STATE_ENABLED)
|
||||
stateMap.put("wifi", true);
|
||||
else if (wifiState == WifiManager.WIFI_STATE_DISABLED)
|
||||
stateMap.put("wifi", false);
|
||||
}
|
||||
}
|
||||
else if (intent.getAction().equals(stateBluetooth))
|
||||
{
|
||||
if(intent.hasExtra(BluetoothAdapter.EXTRA_STATE))
|
||||
{
|
||||
int bluetoothState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
|
||||
|
||||
if (bluetoothState == BluetoothAdapter.STATE_ON)
|
||||
stateMap.put("bluetooth", true);
|
||||
else if (bluetoothState == BluetoothAdapter.STATE_OFF)
|
||||
stateMap.put("bluetooth", false);
|
||||
}
|
||||
}*/
|
||||
if (intent.getAction().equals(stateWifi) || intent.getAction().equals(connectivityBroadcast) || intent.getAction().equals(stateBluetooth))
|
||||
{
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.subSystemState);
|
||||
for (int i = 0; i < ruleCandidates.size(); i++)
|
||||
{
|
||||
if (ruleCandidates.get(i).getsGreenLight(context))
|
||||
ruleCandidates.get(i).activate(automationServiceRef, false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Miscellaneous.logEvent("e", "SubSystemStateReceiver", "Unknown state received: " + intent.getAction(), 3);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Miscellaneous.logEvent("e", "SubSystemStateReceiver", "Error receiving screen state: " + e.getMessage(), 3);
|
||||
}
|
||||
}
|
||||
|
||||
public static SubSystemStateReceiver getInstance()
|
||||
{
|
||||
if(instance == null)
|
||||
instance = new SubSystemStateReceiver();
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startListener(AutomationService automationService)
|
||||
{
|
||||
if (!subSystemStateReceiverActive)
|
||||
{
|
||||
automationServiceRef = automationService;
|
||||
|
||||
if (subSystemStateReceiverInstance == null)
|
||||
subSystemStateReceiverInstance = new SubSystemStateReceiver();
|
||||
|
||||
if (subSystemStateIntentFilter == null)
|
||||
{
|
||||
subSystemStateIntentFilter = new IntentFilter();
|
||||
subSystemStateIntentFilter.addAction(stateWifi);
|
||||
subSystemStateIntentFilter.addAction(connectivityBroadcast);
|
||||
subSystemStateIntentFilter.addAction(stateBluetooth);
|
||||
}
|
||||
|
||||
subSystemStatusIntent = automationServiceRef.registerReceiver(subSystemStateReceiverInstance, subSystemStateIntentFilter);
|
||||
|
||||
subSystemStateReceiverActive = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopListener(AutomationService automationService)
|
||||
{
|
||||
if (subSystemStateReceiverActive)
|
||||
{
|
||||
if (subSystemStateReceiverInstance != null)
|
||||
{
|
||||
automationServiceRef.unregisterReceiver(subSystemStateReceiverInstance);
|
||||
subSystemStateReceiverInstance = null;
|
||||
}
|
||||
|
||||
subSystemStateReceiverActive = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isListenerRunning()
|
||||
{
|
||||
return subSystemStateReceiverActive;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Trigger.Trigger_Enum[] getMonitoredTrigger()
|
||||
{
|
||||
return new Trigger.Trigger_Enum[]{Trigger.Trigger_Enum.subSystemState};
|
||||
}
|
||||
}
|
@ -1,205 +0,0 @@
|
||||
package com.jens.automation2.receivers;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
|
||||
import com.jens.automation2.ActivityManageTriggerTethering;
|
||||
import com.jens.automation2.AutomationService;
|
||||
import com.jens.automation2.Miscellaneous;
|
||||
import com.jens.automation2.Rule;
|
||||
import com.jens.automation2.Trigger;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
|
||||
public class TetheringReceiver extends android.content.BroadcastReceiver implements AutomationListenerInterface
|
||||
{
|
||||
public static AutomationService automationServiceRef = null;
|
||||
private static boolean receiverActive = false;
|
||||
private static TetheringReceiver receiverInstance = null;
|
||||
private static IntentFilter intentFilter = null;
|
||||
|
||||
private static List<String> lastTetheringTypes = null;
|
||||
private static boolean tetheringActive = false;
|
||||
|
||||
public static List<String> getLastTetheringTypes()
|
||||
{
|
||||
return lastTetheringTypes;
|
||||
}
|
||||
|
||||
public static TetheringReceiver getInstance()
|
||||
{
|
||||
if(receiverInstance == null)
|
||||
receiverInstance = new TetheringReceiver();
|
||||
|
||||
return receiverInstance;
|
||||
}
|
||||
|
||||
public static boolean isTetheringActive()
|
||||
{
|
||||
return tetheringActive;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent)
|
||||
{
|
||||
Miscellaneous.logEvent("i", "TetheringReceiver", "Received " + intent.getAction(), 5);
|
||||
|
||||
/*
|
||||
DETECT BY DATA DELIVERED IN INTENT
|
||||
*/
|
||||
|
||||
// if(intent.getAction().equals("android.net.conn.TETHER_STATE_CHANGED"))
|
||||
// {
|
||||
String searchArray = null;
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 26)
|
||||
searchArray = "tetherArray";
|
||||
else
|
||||
searchArray = "activeArray";
|
||||
|
||||
for (String key : intent.getExtras().keySet())
|
||||
{
|
||||
// Miscellaneous.logEvent("i", "Broadcast extra", "Broadcast " + intent.getAction() + " has extra " + key + " and type " + intent.getExtras().get(key).getClass().getName(), 4);
|
||||
Object ob = intent.getExtras().get(key);
|
||||
|
||||
if (key.equals(searchArray) && ob instanceof ArrayList)
|
||||
{
|
||||
if (((ArrayList<String>) ob).size() > 0)
|
||||
{
|
||||
tetheringActive = true;
|
||||
if (lastTetheringTypes == null)
|
||||
lastTetheringTypes = new ArrayList<>();
|
||||
else
|
||||
lastTetheringTypes.clear();
|
||||
|
||||
for (String adapterName : (ArrayList<String>) ob)
|
||||
{
|
||||
if (adapterName.contains("wlan"))
|
||||
lastTetheringTypes.add(ActivityManageTriggerTethering.tetheringTypeWifi);
|
||||
else if (adapterName.contains("bluetooth"))
|
||||
lastTetheringTypes.add(ActivityManageTriggerTethering.tetheringTypeBluetooth);
|
||||
else if (adapterName.contains("rndis"))
|
||||
lastTetheringTypes.add(ActivityManageTriggerTethering.tetheringTypeUsb);
|
||||
else if (adapterName.contains("ndis"))
|
||||
lastTetheringTypes.add(ActivityManageTriggerTethering.tetheringTypeCable);
|
||||
}
|
||||
}
|
||||
else
|
||||
tetheringActive = false;
|
||||
}
|
||||
|
||||
// Miscellaneous.logEvent("i", "Broadcast extra", "Broadcast " + intent.getAction() + " has extra " + key + " and type " + intent.getExtras().get(key).getClass().getName(), 4);
|
||||
}
|
||||
// }
|
||||
// else if(intent.getAction().equals("android.net.conn.CONNECTIVITY_CHANGE"))
|
||||
/*
|
||||
DETECT BY CHECKING ALL NETWORK INTERFACES
|
||||
*/
|
||||
// {
|
||||
/*try
|
||||
{
|
||||
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); )
|
||||
{
|
||||
NetworkInterface intf = en.nextElement();
|
||||
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); )
|
||||
{
|
||||
InetAddress inetAddress = enumIpAddr.nextElement();
|
||||
if (!intf.isLoopback())
|
||||
{
|
||||
if (intf.getName().contains("rndis"))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "TetheringReceiver", "Tethering on interface " + intf.getName() + " seems to be active.", 4);
|
||||
lastTetheringTypes.add(ActivityManageTriggerTethering.tetheringTypeUsb);
|
||||
tetheringActive = true;
|
||||
}
|
||||
else if (intf.getName().contains("ndis"))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "TetheringReceiver", "Tethering on interface " + intf.getName() + " seems to be active.", 4);
|
||||
lastTetheringTypes.add(ActivityManageTriggerTethering.tetheringTypeCable);
|
||||
tetheringActive = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Miscellaneous.logEvent("e", "TetheringReceiver", Log.getStackTraceString(e), 1);
|
||||
}*/
|
||||
// }
|
||||
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.tethering);
|
||||
for(int i=0; i<ruleCandidates.size(); i++)
|
||||
{
|
||||
if(ruleCandidates.get(i).getsGreenLight(context))
|
||||
ruleCandidates.get(i).activate(automationServiceRef, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startListener(AutomationService automationService)
|
||||
{
|
||||
if(!receiverActive)
|
||||
{
|
||||
TetheringReceiver.automationServiceRef = automationService;
|
||||
|
||||
if(receiverInstance == null)
|
||||
receiverInstance = new TetheringReceiver();
|
||||
|
||||
if(intentFilter == null)
|
||||
{
|
||||
intentFilter = new IntentFilter();
|
||||
intentFilter.addAction("android.net.conn.TETHER_STATE_CHANGED");
|
||||
// intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
automationServiceRef.registerReceiver(receiverInstance, intentFilter);
|
||||
receiverActive = true;
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
/*
|
||||
We might be confronted with permission issues here.
|
||||
*/
|
||||
Miscellaneous.logEvent("e", "TetheringReceiver", Log.getStackTraceString(e), 1);
|
||||
receiverActive = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopListener(AutomationService automationService)
|
||||
{
|
||||
if(receiverActive)
|
||||
{
|
||||
if(receiverInstance != null)
|
||||
{
|
||||
automationServiceRef.unregisterReceiver(receiverInstance);
|
||||
receiverInstance = null;
|
||||
}
|
||||
|
||||
receiverActive = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isListenerRunning()
|
||||
{
|
||||
return receiverActive;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Trigger.Trigger_Enum[] getMonitoredTrigger()
|
||||
{
|
||||
return new Trigger.Trigger_Enum[] { Trigger.Trigger_Enum.tethering};
|
||||
}
|
||||
}
|
@ -14,13 +14,14 @@ import com.jens.automation2.Trigger.Trigger_Enum;
|
||||
public class TimeZoneListener extends BroadcastReceiver implements AutomationListenerInterface
|
||||
{
|
||||
private static TimeZoneListener timeZoneListenerInstance = null;
|
||||
protected static boolean timezoneListenerActive = false;
|
||||
protected static boolean timeZoneListenerActive = false;
|
||||
protected static AutomationService automationServiceRef = null;
|
||||
protected static IntentFilter timezoneListenerIntentFilter = null;
|
||||
protected static IntentFilter timeZoneListenerIntentFilter = null;
|
||||
|
||||
|
||||
public static boolean isTimezoneListenerActive()
|
||||
public static boolean isTimeZoneListenerActive()
|
||||
{
|
||||
return timezoneListenerActive;
|
||||
return timeZoneListenerActive;
|
||||
}
|
||||
|
||||
public static void startTimeZoneListener(AutomationService automationService)
|
||||
@ -32,19 +33,19 @@ public class TimeZoneListener extends BroadcastReceiver implements AutomationLis
|
||||
|
||||
try
|
||||
{
|
||||
if(!timezoneListenerActive && Rule.isAnyRuleUsing(Trigger_Enum.timeFrame))
|
||||
if(!timeZoneListenerActive && Rule.isAnyRuleUsing(Trigger_Enum.timeFrame))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "TimeZoneListener", "Starting TimeZoneListener", 4);
|
||||
timezoneListenerActive = true;
|
||||
timeZoneListenerActive = true;
|
||||
|
||||
if(timezoneListenerIntentFilter == null)
|
||||
if(timeZoneListenerIntentFilter == null)
|
||||
{
|
||||
timezoneListenerIntentFilter = new IntentFilter();
|
||||
timezoneListenerIntentFilter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
|
||||
timezoneListenerIntentFilter.addAction(Intent.ACTION_TIME_CHANGED);
|
||||
timeZoneListenerIntentFilter = new IntentFilter();
|
||||
timeZoneListenerIntentFilter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
|
||||
timeZoneListenerIntentFilter.addAction(Intent.ACTION_TIME_CHANGED);
|
||||
}
|
||||
|
||||
automationService.registerReceiver(timeZoneListenerInstance, timezoneListenerIntentFilter);
|
||||
automationService.registerReceiver(timeZoneListenerInstance, timeZoneListenerIntentFilter);
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
@ -56,11 +57,11 @@ public class TimeZoneListener extends BroadcastReceiver implements AutomationLis
|
||||
{
|
||||
try
|
||||
{
|
||||
if(timezoneListenerActive)
|
||||
if(timeZoneListenerActive)
|
||||
{
|
||||
Miscellaneous.logEvent("i", "TimeZoneListener", "Stopping TimeZoneListener", 4);
|
||||
automationServiceRef.unregisterReceiver(timeZoneListenerInstance);
|
||||
timezoneListenerActive = false;
|
||||
timeZoneListenerActive = false;
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
@ -76,12 +77,12 @@ public class TimeZoneListener extends BroadcastReceiver implements AutomationLis
|
||||
if(action.equals(Intent.ACTION_TIMEZONE_CHANGED))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "TimeZoneListener", "Device timezone changed. Reloading alarms.", 3);
|
||||
DateTimeListener.setOrResetAlarms();
|
||||
DateTimeListener.reloadAlarms();
|
||||
}
|
||||
else if(action.equals(Intent.ACTION_TIME_CHANGED))
|
||||
{
|
||||
Miscellaneous.logEvent("i", "TimeZoneListener", "Device time changed. Reloading alarms.", 3);
|
||||
DateTimeListener.setOrResetAlarms();
|
||||
Miscellaneous.logEvent("i", "TimeZoneListener", "Device time changed. Reloading alarms.", 4);
|
||||
DateTimeListener.reloadAlarms();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
@ -103,7 +104,7 @@ public class TimeZoneListener extends BroadcastReceiver implements AutomationLis
|
||||
@Override
|
||||
public boolean isListenerRunning()
|
||||
{
|
||||
return TimeZoneListener.isTimezoneListenerActive();
|
||||
return TimeZoneListener.isTimeZoneListenerActive();
|
||||
}
|
||||
@Override
|
||||
public Trigger_Enum[] getMonitoredTrigger()
|
||||
|
Before Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.3 KiB |
Before Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 679 B |
Before Width: | Height: | Size: 2.0 KiB |
Before Width: | Height: | Size: 2.3 KiB |
Before Width: | Height: | Size: 13 KiB |