Rework
This commit is contained in:
parent
67b2a81647
commit
3d8257aeec
@ -136,6 +136,19 @@
|
||||
<receiver android:name=".receivers.ConnectivityReceiver" />
|
||||
<receiver android:name=".receivers.TimeZoneListener" />
|
||||
|
||||
<receiver
|
||||
android:name=".DeviceAdmin"
|
||||
android:description="@string/app_name"
|
||||
android:label="@string/app_name"
|
||||
android:permission= "android.permission.BIND_DEVICE_ADMIN" >
|
||||
<meta-data
|
||||
android:name="android.app.device_admin"
|
||||
android:resource="@xml/policies" />
|
||||
<intent-filter>
|
||||
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<activity android:name=".ActivityManageRule" />
|
||||
<activity android:name=".ActivityManageActionTriggerUrl" />
|
||||
<activity android:name=".ActivityDisplayLongMessage" />
|
||||
|
@ -1138,36 +1138,28 @@ public class Actions
|
||||
params.screenBrightness = 0;
|
||||
getWindow().setAttributes(params);*/
|
||||
|
||||
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||
// PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||
// WakeLock wakeLock = pm.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK,AutomationService.NOTIFICATION_CHANNEL_ID + ":turnOffScreen");
|
||||
WakeLock wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK , AutomationService.NOTIFICATION_CHANNEL_ID + ":turnOffScreen");
|
||||
wakeLock.acquire();
|
||||
// WakeLock wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK , AutomationService.NOTIFICATION_CHANNEL_ID + ":turnOffScreen");
|
||||
// wakeLock.acquire();
|
||||
|
||||
// WakeLock wakeLock = pm.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, "tag");
|
||||
// WakeLock wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK , "tag");
|
||||
// wakeLock.acquire();
|
||||
|
||||
try
|
||||
{
|
||||
Thread.sleep(100);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
Miscellaneous.logEvent("w", context.getResources().getString(R.string.wakeupDevice), "Error keeping device awake: " + Log.getStackTraceString(e), 4);
|
||||
}
|
||||
|
||||
wakeLock.release();
|
||||
// wakeLock.release();
|
||||
lockScreen();
|
||||
}
|
||||
|
||||
/*public static void lockScreen()
|
||||
public static void lockScreen()
|
||||
{
|
||||
Miscellaneous.logEvent("i", "Actions", "Locking screen.", 3);
|
||||
|
||||
// Works, but requires Manifest.permission.BIND_DEVICE_ADMIN
|
||||
// https://stackoverflow.com/questions/23898406/java-lang-securityexception-no-active-admin-owned-by-uid-10047-for-policy-4-on
|
||||
DevicePolicyManager deviceManger = (DevicePolicyManager)Miscellaneous.getAnyContext().getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||
deviceManger.lockNow();
|
||||
}*/
|
||||
DevicePolicyManager deviceManager = (DevicePolicyManager)Miscellaneous.getAnyContext().getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||
deviceManager.lockNow();
|
||||
}
|
||||
|
||||
// using root
|
||||
/*private void turnOffScreen()
|
||||
|
@ -326,6 +326,7 @@ public class ActivityManageRule extends Activity
|
||||
case triggerUrl:
|
||||
Intent activityEditTriggerUrlIntent = new Intent(ActivityManageRule.this, ActivityManageActionTriggerUrl.class);
|
||||
ActivityManageActionTriggerUrl.resultingAction = a;
|
||||
ActivityManageActionTriggerUrl.resultingAction.setParentRule(ruleToEdit);
|
||||
activityEditTriggerUrlIntent.putExtra("edit", true);
|
||||
startActivityForResult(activityEditTriggerUrlIntent, requestCodeActionTriggerUrlEdit);
|
||||
break;
|
||||
@ -1125,6 +1126,7 @@ public class ActivityManageRule extends Activity
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
//add TriggerUrl
|
||||
ActivityManageActionTriggerUrl.resultingAction.setParentRule(ruleToEdit);
|
||||
ruleToEdit.getActionSet().add(ActivityManageActionTriggerUrl.resultingAction);
|
||||
this.refreshActionList();
|
||||
}
|
||||
@ -1142,6 +1144,7 @@ public class ActivityManageRule extends Activity
|
||||
//add TimeFrame
|
||||
if(resultCode == RESULT_OK && ActivityManageTriggerTimeFrame.editedTimeFrameTrigger != null)
|
||||
{
|
||||
newTrigger.setParentRule(ruleToEdit);
|
||||
ruleToEdit.getTriggerSet().add(newTrigger);
|
||||
this.refreshTriggerList();
|
||||
}
|
||||
@ -1152,7 +1155,10 @@ public class ActivityManageRule extends Activity
|
||||
{
|
||||
//edit TimeFrame
|
||||
if(resultCode == RESULT_OK && ActivityManageTriggerTimeFrame.editedTimeFrameTrigger != null)
|
||||
{
|
||||
ActivityManageTriggerTimeFrame.editedTimeFrameTrigger.setParentRule(ruleToEdit);
|
||||
this.refreshTriggerList();
|
||||
}
|
||||
else
|
||||
Miscellaneous.logEvent("w", "TimeFrameEdit", "No timeframe returned. Assuming abort.", 5);
|
||||
}
|
||||
@ -1162,6 +1168,7 @@ public class ActivityManageRule extends Activity
|
||||
{
|
||||
newTrigger.setTriggerParameter(data.getBooleanExtra("wifiState", false));
|
||||
newTrigger.setTriggerParameter2(data.getStringExtra("wifiName"));
|
||||
newTrigger.setParentRule(ruleToEdit);
|
||||
ruleToEdit.getTriggerSet().add(newTrigger);
|
||||
this.refreshTriggerList();
|
||||
}
|
||||
@ -1174,6 +1181,7 @@ public class ActivityManageRule extends Activity
|
||||
editedTrigger.setTriggerType(Trigger_Enum.wifiConnection);
|
||||
editedTrigger.setTriggerParameter(data.getBooleanExtra("wifiState", false));
|
||||
editedTrigger.setTriggerParameter2(data.getStringExtra("wifiName"));
|
||||
editedTrigger.setParentRule(ruleToEdit);
|
||||
ruleToEdit.getTriggerSet().set(editIndex, editedTrigger);
|
||||
this.refreshTriggerList();
|
||||
}
|
||||
@ -1184,6 +1192,7 @@ public class ActivityManageRule extends Activity
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
newAction = ActivityManageActionStartActivity.resultingAction;
|
||||
newAction.setParentRule(ruleToEdit);
|
||||
ruleToEdit.getActionSet().add(newAction);
|
||||
this.refreshActionList();
|
||||
}
|
||||
@ -1194,6 +1203,7 @@ public class ActivityManageRule extends Activity
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
newAction = ActivityManageActionStartActivity.resultingAction;
|
||||
newAction.setParentRule(ruleToEdit);
|
||||
// ruleToEdit.getActionSet().add(newAction);
|
||||
this.refreshActionList();
|
||||
}
|
||||
@ -1204,6 +1214,7 @@ public class ActivityManageRule extends Activity
|
||||
if(resultCode == RESULT_OK && ActivityManageTriggerNfc.generatedId != null)
|
||||
{
|
||||
newTrigger.setNfcTagId(ActivityManageTriggerNfc.generatedId);
|
||||
newTrigger.setParentRule(ruleToEdit);
|
||||
ruleToEdit.getTriggerSet().add(newTrigger);
|
||||
this.refreshTriggerList();
|
||||
}
|
||||
@ -1225,6 +1236,7 @@ public class ActivityManageRule extends Activity
|
||||
data.getStringExtra("textDir") + Trigger.triggerParameter2Split +
|
||||
data.getStringExtra("text")
|
||||
);
|
||||
newTrigger.setParentRule(ruleToEdit);
|
||||
this.refreshTriggerList();
|
||||
}
|
||||
}
|
||||
@ -1233,6 +1245,7 @@ public class ActivityManageRule extends Activity
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
newTrigger = ActivityManageTriggerNotification.resultingTrigger;
|
||||
newTrigger.setParentRule(ruleToEdit);
|
||||
this.refreshTriggerList();
|
||||
}
|
||||
}
|
||||
@ -1240,6 +1253,7 @@ public class ActivityManageRule extends Activity
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
newTrigger.setParentRule(ruleToEdit);
|
||||
ruleToEdit.getTriggerSet().add(newTrigger);
|
||||
newTrigger.setTriggerParameter2(data.getStringExtra("triggerParameter2"));
|
||||
this.refreshTriggerList();
|
||||
@ -1250,6 +1264,7 @@ public class ActivityManageRule extends Activity
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
newTrigger = ActivityManageTriggerPhoneCall.resultingTrigger;
|
||||
newTrigger.setParentRule(ruleToEdit);
|
||||
this.refreshTriggerList();
|
||||
}
|
||||
}
|
||||
@ -1258,6 +1273,7 @@ public class ActivityManageRule extends Activity
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
//add SpeakText
|
||||
ActivityManageActionSpeakText.resultingAction.setParentRule(ruleToEdit);
|
||||
ruleToEdit.getActionSet().add(ActivityManageActionSpeakText.resultingAction);
|
||||
this.refreshActionList();
|
||||
}
|
||||
@ -1267,6 +1283,7 @@ public class ActivityManageRule extends Activity
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
//edit SpeakText
|
||||
ActivityManageActionSpeakText.resultingAction.setParentRule(ruleToEdit);
|
||||
newAction = ActivityManageActionSpeakText.resultingAction;
|
||||
this.refreshActionList();
|
||||
}
|
||||
@ -1276,6 +1293,7 @@ public class ActivityManageRule extends Activity
|
||||
//add bluetooth trigger
|
||||
if(resultCode == RESULT_OK && ActivityManageTriggerBluetooth.editedBluetoothTrigger != null)
|
||||
{
|
||||
newTrigger.setParentRule(ruleToEdit);
|
||||
ruleToEdit.getTriggerSet().add(newTrigger);
|
||||
this.refreshTriggerList();
|
||||
}
|
||||
@ -1287,6 +1305,7 @@ public class ActivityManageRule extends Activity
|
||||
//edit bluetooth trigger
|
||||
if(resultCode == RESULT_OK && ActivityManageTriggerBluetooth.editedBluetoothTrigger != null)
|
||||
{
|
||||
ActivityManageTriggerBluetooth.editedBluetoothTrigger.setParentRule(ruleToEdit);
|
||||
this.refreshTriggerList();
|
||||
}
|
||||
else
|
||||
@ -1298,6 +1317,7 @@ public class ActivityManageRule extends Activity
|
||||
{
|
||||
newAction.setParameter1(data.getBooleanExtra("autoBrightness", false));
|
||||
newAction.setParameter2(String.valueOf(data.getIntExtra("brightnessValue", 0)));
|
||||
newAction.setParentRule(ruleToEdit);
|
||||
ruleToEdit.getActionSet().add(newAction);
|
||||
this.refreshActionList();
|
||||
}
|
||||
@ -1312,6 +1332,8 @@ public class ActivityManageRule extends Activity
|
||||
if(data.hasExtra("brightnessValue"))
|
||||
ruleToEdit.getActionSet().get(editIndex).setParameter2(String.valueOf(data.getIntExtra("brightnessValue", 0)));
|
||||
|
||||
ruleToEdit.getActionSet().get(editIndex).setParentRule(ruleToEdit);
|
||||
|
||||
this.refreshActionList();
|
||||
}
|
||||
}
|
||||
@ -1319,6 +1341,7 @@ public class ActivityManageRule extends Activity
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
newAction.setParentRule(ruleToEdit);
|
||||
newAction.setParameter2(data.getStringExtra("vibratePattern"));
|
||||
ruleToEdit.getActionSet().add(newAction);
|
||||
this.refreshActionList();
|
||||
@ -1328,6 +1351,8 @@ public class ActivityManageRule extends Activity
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
ruleToEdit.getActionSet().get(editIndex).setParentRule(ruleToEdit);
|
||||
|
||||
if(data.hasExtra("vibratePattern"))
|
||||
ruleToEdit.getActionSet().get(editIndex).setParameter2(data.getStringExtra("vibratePattern"));
|
||||
|
||||
@ -1338,6 +1363,7 @@ public class ActivityManageRule extends Activity
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
newAction.setParentRule(ruleToEdit);
|
||||
newAction.setParameter1(data.getBooleanExtra(intentNameActionParameter1, false));
|
||||
newAction.setParameter2(data.getStringExtra(intentNameActionParameter2));
|
||||
ruleToEdit.getActionSet().add(newAction);
|
||||
@ -1348,6 +1374,8 @@ 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, false));
|
||||
|
||||
@ -1361,7 +1389,7 @@ public class ActivityManageRule extends Activity
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
//add SendTextMessage
|
||||
ActivityManageActionSendTextMessage.resultingAction.setParentRule(ruleToEdit);
|
||||
ruleToEdit.getActionSet().add(ActivityManageActionSendTextMessage.resultingAction);
|
||||
this.refreshActionList();
|
||||
}
|
||||
@ -1370,8 +1398,8 @@ public class ActivityManageRule extends Activity
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
//edit SendTextMessage
|
||||
newAction = ActivityManageActionSendTextMessage.resultingAction;
|
||||
newAction.setParentRule(ruleToEdit);
|
||||
//ruleToEdit.getActionSet().add(ActivityManageActionSendTextMessage.resultingAction);
|
||||
this.refreshActionList();
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
@ -46,6 +47,7 @@ public class ActivityPermissions extends Activity
|
||||
private static final int requestCodeForPermissionsNotificationPolicy = 12044;
|
||||
private static final int requestCodeForPermissionsBackgroundLocation = 12045;
|
||||
private static final int requestCodeForPermissionsNotifications = 12046;
|
||||
private static final int requestCodeForPermissionsDeviceAdmin = 12047;
|
||||
protected String[] specificPermissionsToRequest = null;
|
||||
|
||||
public static String intentExtraName = "permissionsToBeRequested";
|
||||
@ -282,6 +284,10 @@ public class ActivityPermissions extends Activity
|
||||
{
|
||||
return verifyNotificationPermission();
|
||||
}
|
||||
else if (s.equals(Manifest.permission.BIND_DEVICE_ADMIN))
|
||||
{
|
||||
return haveDeviceAdmin();
|
||||
}
|
||||
else
|
||||
{
|
||||
int res = context.checkCallingOrSelfPermission(s);
|
||||
@ -292,6 +298,33 @@ public class ActivityPermissions extends Activity
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean haveDeviceAdmin()
|
||||
{
|
||||
DevicePolicyManager deviceManger = (DevicePolicyManager)Miscellaneous.getAnyContext().getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||
// ComponentName compName = new ComponentName(ActivityPermissions.getInstance(), DeviceAdmin.class ) ;
|
||||
ComponentName compName = new ComponentName(Miscellaneous.getAnyContext(), DeviceAdmin.class) ;
|
||||
boolean active = deviceManger.isAdminActive(compName);
|
||||
return active;
|
||||
}
|
||||
|
||||
public static void requestDeviceAdmin()
|
||||
{
|
||||
if(!haveDeviceAdmin())
|
||||
{
|
||||
// deviceManger.removeActiveAdmin(compName);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
DevicePolicyManager deviceManger = (DevicePolicyManager)Miscellaneous.getAnyContext().getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||
ComponentName compName = new ComponentName(ActivityPermissions.getInstance(), DeviceAdmin.class) ;
|
||||
|
||||
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN );
|
||||
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN , compName );
|
||||
intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION , Miscellaneous.getAnyContext().getResources().getString(R.string.deviceAdminNote));
|
||||
ActivityPermissions.getInstance().startActivityForResult(intent, requestCodeForPermissionsDeviceAdmin);
|
||||
}
|
||||
}
|
||||
|
||||
public static String[] getRequiredPermissions(boolean onlyGeneral)
|
||||
{
|
||||
ArrayList<String> requiredPermissions = new ArrayList<String>();
|
||||
@ -627,6 +660,9 @@ public class ActivityPermissions extends Activity
|
||||
case playSound:
|
||||
addToArrayListUnique(Manifest.permission.READ_EXTERNAL_STORAGE, requiredPermissions);
|
||||
break;
|
||||
case turnScreenOnOrOff:
|
||||
addToArrayListUnique(Manifest.permission.BIND_DEVICE_ADMIN, requiredPermissions);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -833,6 +869,10 @@ public class ActivityPermissions extends Activity
|
||||
for(String ruleName : getRulesUsing(Action.Action_Enum.playSound))
|
||||
usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName));
|
||||
break;
|
||||
case Manifest.permission.BIND_DEVICE_ADMIN:
|
||||
for(String ruleName : getRulesUsing(Action.Action_Enum.turnScreenOnOrOff))
|
||||
usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName));
|
||||
break;
|
||||
}
|
||||
|
||||
return usingElements;
|
||||
@ -859,6 +899,13 @@ public class ActivityPermissions extends Activity
|
||||
requestPermissions(cachedPermissionsToRequest, true);
|
||||
}
|
||||
}
|
||||
if (requestCode == requestCodeForPermissionsDeviceAdmin)
|
||||
{
|
||||
NotificationManager mNotificationManager = (NotificationManager) ActivityPermissions.this.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
|
||||
if (mNotificationManager.isNotificationPolicyAccessGranted())
|
||||
requestPermissions(cachedPermissionsToRequest, true);
|
||||
}
|
||||
|
||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
|
||||
{
|
||||
@ -922,6 +969,13 @@ public class ActivityPermissions extends Activity
|
||||
startActivityForResult(intent, requestCodeForPermissionsWriteSettings);
|
||||
return;
|
||||
}
|
||||
if (s.equalsIgnoreCase(Manifest.permission.BIND_DEVICE_ADMIN))
|
||||
{
|
||||
requiredPermissions.remove(s);
|
||||
cachedPermissionsToRequest = requiredPermissions;
|
||||
requestDeviceAdmin();
|
||||
return;
|
||||
}
|
||||
else if (s.equalsIgnoreCase(Manifest.permission.ACCESS_NOTIFICATION_POLICY))
|
||||
{
|
||||
requiredPermissions.remove(s);
|
||||
|
@ -274,16 +274,7 @@ public class AutomationService extends Service implements OnInitListener
|
||||
|
||||
public void applySettingsAndRules()
|
||||
{
|
||||
if (Settings.useTextToSpeechOnNormal | Settings.useTextToSpeechOnSilent | Settings.useTextToSpeechOnVibrate)
|
||||
{
|
||||
if (ttsEngine == null)
|
||||
ttsEngine = new TextToSpeech(this, this);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ttsEngine != null)
|
||||
ttsEngine.shutdown();
|
||||
}
|
||||
checkForTtsEngine();
|
||||
|
||||
startLocationProvider();
|
||||
ReceiverCoordinator.startAllReceivers();
|
||||
@ -306,7 +297,7 @@ public class AutomationService extends Service implements OnInitListener
|
||||
|
||||
public void checkForTtsEngine()
|
||||
{
|
||||
if (Settings.useTextToSpeechOnNormal | Settings.useTextToSpeechOnSilent | Settings.useTextToSpeechOnVibrate | Rule.isAnyRuleUsing(Action.Action_Enum.speakText))
|
||||
if (Settings.useTextToSpeechOnNormal || Settings.useTextToSpeechOnSilent || Settings.useTextToSpeechOnVibrate || Rule.isAnyRuleUsing(Action.Action_Enum.speakText))
|
||||
{
|
||||
if (ttsEngine == null)
|
||||
ttsEngine = new TextToSpeech(this, this);
|
||||
@ -353,12 +344,8 @@ public class AutomationService extends Service implements OnInitListener
|
||||
if(r.isRuleActive())
|
||||
{
|
||||
if(!r.haveEnoughPermissions())
|
||||
// for (String permission : ActivityPermissions.getPermissionsForRule(r))
|
||||
{
|
||||
// if (!ActivityPermissions.havePermission(permission, AutomationService.this))
|
||||
{
|
||||
// r.setRuleActive(false);
|
||||
// r.change(AutomationService.this);
|
||||
if(!displayNotification)
|
||||
{
|
||||
displayNotification = true;
|
||||
@ -411,10 +398,7 @@ public class AutomationService extends Service implements OnInitListener
|
||||
|
||||
public void cancelNotification()
|
||||
{
|
||||
// stopForeground(false);
|
||||
NotificationManagerCompat.from(AutomationService.this).cancelAll();
|
||||
// NotificationManagerCompat.from(AutomationService.this).cancel(ActivityPermissions.notificationIdPermissions);
|
||||
// NotificationManagerCompat.from(AutomationService.this).cancel(AutomationService.notificationIdRestrictions);
|
||||
}
|
||||
|
||||
protected void checkForMissingBackgroundLocationPermission()
|
||||
@ -451,7 +435,6 @@ public class AutomationService extends Service implements OnInitListener
|
||||
private void stopRoutine()
|
||||
{
|
||||
Miscellaneous.logEvent("i", "Service", "Stopping service...", 3);
|
||||
// Log.i("STOP", "Stopping");
|
||||
try
|
||||
{
|
||||
myLocationProvider.stopLocationService();
|
||||
@ -480,7 +463,6 @@ public class AutomationService extends Service implements OnInitListener
|
||||
builder.setWhen(System.currentTimeMillis());
|
||||
builder.setContentIntent(myPendingIntent);
|
||||
|
||||
// Notification defaultNotification = new Notification();
|
||||
Notification defaultNotification = builder.build();
|
||||
|
||||
defaultNotification.icon = R.drawable.ic_launcher;
|
||||
@ -498,31 +480,6 @@ public class AutomationService extends Service implements OnInitListener
|
||||
// defaultNotification.ledOffMS = 1500;
|
||||
|
||||
return builder;
|
||||
|
||||
/*NotificationManager mNotificationManager = (NotificationManager) AutomationService.getInstance().getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
|
||||
NotificationCompat.Builder builder;
|
||||
builder = new NotificationCompat.Builder(AutomationService.getInstance());
|
||||
|
||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
|
||||
builder.setCategory(Notification.CATEGORY_EVENT);
|
||||
|
||||
builder.setWhen(System.currentTimeMillis());
|
||||
|
||||
builder.setContentTitle("Automation");
|
||||
builder.setSmallIcon(R.drawable.ic_launcher);
|
||||
// builder.setContentText(textToDisplay);
|
||||
// builder.setSmallIcon(icon);
|
||||
// builder.setContentIntent(pendingIntent);
|
||||
// builder.setStyle(new NotificationCompat.BigTextStyle().bigText(textToDisplay));
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
||||
{
|
||||
NotificationChannel channel = new NotificationChannel("notify_001", "Channel human readable title", NotificationManager.IMPORTANCE_DEFAULT);
|
||||
mNotificationManager.createNotificationChannel(channel);
|
||||
}
|
||||
|
||||
return builder;*/
|
||||
}
|
||||
|
||||
protected static NotificationCompat.Builder createDefaultNotificationBuilder()
|
||||
@ -572,79 +529,68 @@ public class AutomationService extends Service implements OnInitListener
|
||||
|
||||
if(instance != null)
|
||||
{
|
||||
// if(Settings.showIconWhenServiceIsRunning)
|
||||
// {
|
||||
Miscellaneous.logEvent("i", "Notification", "Request to update notification.", 4);
|
||||
Miscellaneous.logEvent("i", "Notification", "Request to update notification.", 4);
|
||||
|
||||
String bodyText="";
|
||||
String lastRuleString = "";
|
||||
|
||||
if(PointOfInterest.getPointOfInterestCollection() != null && PointOfInterest.getPointOfInterestCollection().size() > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
PointOfInterest activePoi = PointOfInterest.getActivePoi();
|
||||
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;
|
||||
}
|
||||
else
|
||||
{
|
||||
bodyText = AutomationService.getInstance().getResources().getString(R.string.activePoi) + ": " + activePoi.getName() + lastRuleString;
|
||||
}
|
||||
}
|
||||
catch(NullPointerException e)
|
||||
{
|
||||
if(
|
||||
Rule.isAnyRuleUsing(Trigger_Enum.pointOfInterest)
|
||||
&&
|
||||
ActivityPermissions.havePermission(Manifest.permission.ACCESS_COARSE_LOCATION, AutomationService.getInstance())
|
||||
&&
|
||||
ActivityPermissions.havePermission(Manifest.permission.ACCESS_FINE_LOCATION, AutomationService.getInstance())
|
||||
)
|
||||
bodyText = instance.getResources().getString(R.string.stillGettingPosition);
|
||||
else
|
||||
bodyText = instance.getResources().getString(R.string.locationEngineNotActive);
|
||||
}
|
||||
}
|
||||
String bodyText="";
|
||||
String lastRuleString = "";
|
||||
|
||||
if(PointOfInterest.getPointOfInterestCollection() != null && PointOfInterest.getPointOfInterestCollection().size() > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
lastRuleString = instance.getResources().getString(R.string.lastRule) + " " + Rule.getLastActivatedRule().getName() + " " + instance.getResources().getString(R.string.at) + " " + Rule.getLastActivatedRuleActivationTime().toLocaleString();
|
||||
PointOfInterest activePoi = PointOfInterest.getActivePoi();
|
||||
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;
|
||||
}
|
||||
else
|
||||
{
|
||||
bodyText = AutomationService.getInstance().getResources().getString(R.string.activePoi) + ": " + activePoi.getName() + lastRuleString;
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
catch(NullPointerException e)
|
||||
{
|
||||
lastRuleString = instance.getResources().getString(R.string.lastRule) + " n./a.";
|
||||
if(
|
||||
Rule.isAnyRuleUsing(Trigger_Enum.pointOfInterest)
|
||||
&&
|
||||
ActivityPermissions.havePermission(Manifest.permission.ACCESS_COARSE_LOCATION, AutomationService.getInstance())
|
||||
&&
|
||||
ActivityPermissions.havePermission(Manifest.permission.ACCESS_FINE_LOCATION, AutomationService.getInstance())
|
||||
)
|
||||
bodyText = instance.getResources().getString(R.string.stillGettingPosition);
|
||||
else
|
||||
bodyText = instance.getResources().getString(R.string.locationEngineNotActive);
|
||||
}
|
||||
}
|
||||
|
||||
String textToDisplay = bodyText + " " + lastRuleString;
|
||||
// if(Build.VERSION.SDK_INT < 11)
|
||||
// {
|
||||
// myNotification.setLatestEventInfo(instance, "Automation", textToDisplay, myPendingIntent);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
if(notificationBuilder == null)
|
||||
notificationBuilder = createDefaultNotificationBuilder();
|
||||
try
|
||||
{
|
||||
lastRuleString = instance.getResources().getString(R.string.lastRule) + " " + Rule.getLastActivatedRule().getName() + " " + instance.getResources().getString(R.string.at) + " " + Rule.getLastActivatedRuleActivationTime().toLocaleString();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
lastRuleString = instance.getResources().getString(R.string.lastRule) + " n./a.";
|
||||
}
|
||||
|
||||
notificationBuilder.setContentText(textToDisplay);
|
||||
notificationBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(textToDisplay));
|
||||
String textToDisplay = bodyText + " " + lastRuleString;
|
||||
|
||||
myNotification = notificationBuilder.build();
|
||||
myNotification.defaults = 0;
|
||||
// }
|
||||
if(notificationBuilder == null)
|
||||
notificationBuilder = createDefaultNotificationBuilder();
|
||||
|
||||
notificationBuilder.setContentText(textToDisplay);
|
||||
notificationBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(textToDisplay));
|
||||
|
||||
myNotification = notificationBuilder.build();
|
||||
myNotification.defaults = 0;
|
||||
|
||||
// NotificationManager notificationManager = (NotificationManager) instance.getSystemService(NOTIFICATION_SERVICE);
|
||||
// hide the notification after its selected
|
||||
// hide the notification after its selected
|
||||
// myNotification.flags |= Notification.FLAG_AUTO_CANCEL;
|
||||
myNotification.flags |= Notification.FLAG_NO_CLEAR;
|
||||
myNotification.flags |= Notification.FLAG_NO_CLEAR;
|
||||
// notificationManager.notify(notificationId, myNotification);
|
||||
|
||||
instance.startForeground(notificationId, myNotification);
|
||||
// }
|
||||
// else
|
||||
// instance.startForeground(notificationId, null); // do not show icon in task bar
|
||||
instance.startForeground(notificationId, myNotification);
|
||||
}
|
||||
}
|
||||
|
||||
@ -668,18 +614,18 @@ public class AutomationService extends Service implements OnInitListener
|
||||
**/
|
||||
public void speak(String text, boolean force)
|
||||
{
|
||||
if(text.length() > 0 && (force | Settings.useTextToSpeechOnNormal | Settings.useTextToSpeechOnSilent | Settings.useTextToSpeechOnVibrate))
|
||||
if(text.length() > 0 && (force || Settings.useTextToSpeechOnNormal || Settings.useTextToSpeechOnSilent || Settings.useTextToSpeechOnVibrate))
|
||||
{
|
||||
AudioManager myAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
|
||||
int mode = myAudioManager.getRingerMode();
|
||||
|
||||
if(
|
||||
(mode == AudioManager.RINGER_MODE_NORMAL && Settings.useTextToSpeechOnNormal)
|
||||
|
|
||||
||
|
||||
(mode == AudioManager.RINGER_MODE_VIBRATE && Settings.useTextToSpeechOnVibrate)
|
||||
|
|
||||
||
|
||||
(mode == AudioManager.RINGER_MODE_SILENT && Settings.useTextToSpeechOnSilent)
|
||||
|
|
||||
||
|
||||
force
|
||||
)
|
||||
{
|
||||
@ -709,12 +655,12 @@ public class AutomationService extends Service implements OnInitListener
|
||||
{}
|
||||
}
|
||||
}
|
||||
Miscellaneous.logEvent("i", "TextToSpeech", "Speaking " + text + " in language " + ttsEngine.getLanguage().toLanguageTag(), 3);
|
||||
this.ttsEngine.speak(text, TextToSpeech.QUEUE_ADD, null);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Miscellaneous.logEvent("e", "TextToSpeech", Log.getStackTraceString(e), 3);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -727,31 +673,6 @@ public class AutomationService extends Service implements OnInitListener
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
|
||||
// boolean isActivityFound = false;
|
||||
// ActivityManager activityManager = (ActivityManager)context.getSystemService (Context.ACTIVITY_SERVICE);
|
||||
// List<RunningTaskInfo> activitys = activityManager.getRunningTasks(Integer.MAX_VALUE);
|
||||
// isActivityFound = false;
|
||||
// for (int i = 0; i < activitys.size(); i++)
|
||||
// {
|
||||
// if (activitys.get(i).topActivity.toString().equalsIgnoreCase("ComponentInfo{com.jens.automation/com.jens.automation.ActivityMainScreen}"))
|
||||
// {
|
||||
// isActivityFound = true;
|
||||
// }
|
||||
// }
|
||||
// Miscellaneous.logEvent("i", "ActivityMainScreen", "Activity running status: " + String.valueOf(isActivityFound), 5);
|
||||
// return isActivityFound;
|
||||
|
||||
// ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
||||
// List<RunningTaskInfo> tasks = activityManager.getRunningTasks(Integer.MAX_VALUE);
|
||||
//
|
||||
// for (RunningTaskInfo task : tasks)
|
||||
// {
|
||||
// if (context.getPackageName().equalsIgnoreCase(task.baseActivity.getPackageName()))
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// return false;
|
||||
}
|
||||
|
||||
public static boolean isMyServiceRunning(Context context)
|
||||
@ -763,7 +684,6 @@ public class AutomationService extends Service implements OnInitListener
|
||||
{
|
||||
if(AutomationService.class.getName().equals(service.service.getClassName()))
|
||||
{
|
||||
// return AutomationService.getInstance() != null && AutomationService.getInstance().isRunning;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -772,7 +692,6 @@ public class AutomationService extends Service implements OnInitListener
|
||||
{
|
||||
if(Log.getStackTraceString(e).contains("activate")) // Means that a poi has been activated/deactivated. Service is running.
|
||||
return true;
|
||||
// return AutomationService.getInstance() != null && AutomationService.getInstance().isRunning;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
22
app/src/main/java/com/jens/automation2/DeviceAdmin.java
Normal file
22
app/src/main/java/com/jens/automation2/DeviceAdmin.java
Normal file
@ -0,0 +1,22 @@
|
||||
package com.jens.automation2;
|
||||
|
||||
import android.app.admin.DeviceAdminReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
public class DeviceAdmin extends DeviceAdminReceiver
|
||||
{
|
||||
@Override
|
||||
public void onEnabled (Context context , Intent intent)
|
||||
{
|
||||
super.onEnabled(context , intent) ;
|
||||
Miscellaneous.logEvent("i", "DeviceAdmin", "Got permission BIND_DEVICE_ADMIN.", 3);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisabled (Context context , Intent intent)
|
||||
{
|
||||
super.onDisabled(context , intent) ;
|
||||
Miscellaneous.logEvent("i", "DeviceAdmin", "Permission BIND_DEVICE_ADMIN taken.", 3);
|
||||
}
|
||||
}
|
@ -123,7 +123,7 @@ public class Trigger
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Miscellaneous.logEvent("e", "Trigger", "Error while checking if rule " + getParentRule().getName() + " applies. Error occured in trigger " + this.getParentRule().toString() + "." + Miscellaneous.lineSeparator + Log.getStackTraceString(e), 1);
|
||||
Miscellaneous.logEvent("e", "Trigger", "Error while checking if rule " + getParentRule().getName() + " applies." + Miscellaneous.lineSeparator + Log.getStackTraceString(e), 1);
|
||||
result = false;
|
||||
}
|
||||
|
||||
|
@ -891,8 +891,6 @@ public class XmlFileInterface
|
||||
|
||||
if(triggerEventString.equals("process_started_stopped") | triggerEventString.equals("process_running"))
|
||||
newTrigger.setTriggerType(Trigger_Enum.process_started_stopped);
|
||||
if(triggerEventString.equals("devicePosition"))
|
||||
newTrigger.setTriggerType(Trigger_Enum.deviceOrientation);
|
||||
else
|
||||
newTrigger.setTriggerType(Trigger_Enum.valueOf(triggerEventString));
|
||||
}
|
||||
|
@ -734,4 +734,6 @@
|
||||
<string name="deviceOrientationTimeAcceptIntervalTitle">Signal frequency</string>
|
||||
<string name="deviceOrientationTimeAcceptIntervalSummary">Accept new movement signals every x milliseconds</string>
|
||||
<string name="deviceOrientationSettings">Device orientation settings</string>
|
||||
<string name="android.permission.BIND_DEVICE_ADMIN">Device administrator</string>
|
||||
<string name="deviceAdminNote">Device administrator permissions required for at least 1 rule you created.</string>
|
||||
</resources>
|
@ -32,7 +32,7 @@ Mögliche Aktionen:
|
||||
* Klingelton und Toneinstellungen ändern
|
||||
* Eine andere Anwendung starten
|
||||
* Warten (zwischen anderen Aktionen)
|
||||
* Den Bildschirm des Geräts einschalten
|
||||
* Bildschirm ein-/ausschalten
|
||||
* Flugzeugmodus ein-/ausschalten
|
||||
* Datenverbindung ein-/ausschalten
|
||||
* Text sprechen (TTS)
|
||||
|
@ -32,7 +32,7 @@ Supported actions:
|
||||
* Change ringtone/sound setting
|
||||
* Start another application
|
||||
* Wait (in between other actions)
|
||||
* Wakeup device's screen
|
||||
* Turn screen on or off
|
||||
* Toggle airplane mode
|
||||
* Toggle mobile data connection
|
||||
* Speak text
|
||||
|
@ -21,7 +21,7 @@ Disparadores:
|
||||
* Notificaciónes de otras apps
|
||||
* Orientación del dispositivo (giroscopio)
|
||||
|
||||
Supported actions:
|
||||
Aciónes:
|
||||
* Pasar de wifi
|
||||
* Pasar de bluetooth
|
||||
* Pasar USB rúter
|
||||
@ -32,7 +32,7 @@ Supported actions:
|
||||
* Cambiar el tono de llamada / ajustes de sonido
|
||||
* Encender otra app
|
||||
* Esperar (inter otras aciónes)
|
||||
* Desperatar móvil
|
||||
* Encender o apagar pantalla
|
||||
* Pasar modo de vuelo
|
||||
* Pasar datos móviles
|
||||
* Leer texto
|
||||
|
Loading…
Reference in New Issue
Block a user