From d402986dc3f25f0c4b3f8702914c627b7f5caed2 Mon Sep 17 00:00:00 2001 From: jens Date: Thu, 3 Feb 2022 13:41:05 +0100 Subject: [PATCH] ringtone --- .../java/com/jens/automation2/Rule.java | 11 + app/src/fdroidFlavor/AndroidManifest.xml | 7 + .../java/com/jens/automation2/Rule.java | 238 +++--------------- app/src/googlePlayFlavor/AndroidManifest.xml | 1 + .../java/com/jens/automation2/Rule.java | 236 +++-------------- .../ActivityManageActionSendTextMessage.java | 3 +- .../ActivityManageActionStartActivity.java | 41 ++- .../automation2/ActivityManageProfile.java | 6 + .../jens/automation2/ActivityPermissions.java | 32 ++- .../java/com/jens/automation2/Profile.java | 24 +- app/src/main/res/values-de/strings.xml | 2 + app/src/main/res/values-es/strings.xml | 2 + app/src/main/res/values-it/strings.xml | 28 ++- app/src/main/res/values-nl/strings.xml | 2 + app/src/main/res/values/strings.xml | 1 + .../metadata/android/en-US/changelogs/118.txt | 4 +- 16 files changed, 199 insertions(+), 439 deletions(-) diff --git a/app/src/apkFlavor/java/com/jens/automation2/Rule.java b/app/src/apkFlavor/java/com/jens/automation2/Rule.java index 18b2389..cdc5df7 100644 --- a/app/src/apkFlavor/java/com/jens/automation2/Rule.java +++ b/app/src/apkFlavor/java/com/jens/automation2/Rule.java @@ -748,4 +748,15 @@ public class Rule implements Comparable { return ActivityPermissions.havePermissionsForRule(this, Miscellaneous.getAnyContext()); } + + public static Rule getByName(String ruleName) + { + for(Rule r : Rule.getRuleCollection()) + { + if(r.getName().equals(ruleName)) + return r; + } + + return null; + } } \ No newline at end of file diff --git a/app/src/fdroidFlavor/AndroidManifest.xml b/app/src/fdroidFlavor/AndroidManifest.xml index 8ff496a..a3826ad 100644 --- a/app/src/fdroidFlavor/AndroidManifest.xml +++ b/app/src/fdroidFlavor/AndroidManifest.xml @@ -64,6 +64,7 @@ + + + + + + { this.lastExecution = lastExecution; } - + public boolean isRuleToggle() { return ruleToggle; @@ -529,7 +529,7 @@ public class Rule implements Comparable innerloop: for(Trigger oneTrigger : oneRule.getTriggerSet()) { - if(oneTrigger.getTriggerType() == triggerType) + if(oneTrigger.getTriggerType().equals(triggerType)) { ruleCandidates.add(oneRule); break innerloop; // we don't need to check the other triggers in the same rule @@ -539,6 +539,26 @@ public class Rule implements Comparable return ruleCandidates; } + + public static ArrayList findRuleCandidates(Action.Action_Enum actionType) + { + ArrayList ruleCandidates = new ArrayList(); + + for(Rule oneRule : ruleCollection) + { + innerloop: + for(Action oneAction : oneRule.getActionSet()) + { + if(oneAction.getAction().equals(actionType)) + { + ruleCandidates.add(oneRule); + break innerloop; // we don't need to check the other actions in the same rule + } + } + } + + return ruleCandidates; + } public static ArrayList findRuleCandidatesByPoi(PointOfInterest searchPoi, boolean triggerParameter) { @@ -581,186 +601,6 @@ public class Rule implements Comparable return ruleCandidates; } - /*public static ArrayList findRuleCandidatesByTimeFrame(TimeFrame searchTimeFrame, boolean triggerParameter) - { - ArrayList ruleCandidates = new ArrayList(); - - for(int i=0; i findRuleCandidatesByTime(Time searchTime) - { - Miscellaneous.logEvent("i", "RuleSearch", "Searching for rules with TimeFrame with time " + searchTime.toString() + ". RuleCollection-Size: " + String.valueOf(ruleCollection.size()), 3);; - ArrayList ruleCandidates = new ArrayList(); - - for(Rule oneRule : ruleCollection) - { - innerloop: - for(Trigger oneTrigger : oneRule.getTriggerSet()) - { - if(oneTrigger.getTriggerType() == Trigger.Trigger_Enum.timeFrame) - { - Miscellaneous.logEvent("i", "RuleSearch", "Searching interval: " + oneTrigger.getTimeFrame().getTriggerTimeStart().toString() + " to " + oneTrigger.getTimeFrame().getTriggerTimeStop().toString(), 5); - Miscellaneous.logEvent("i", "RuleSearch", "interval start: " + String.valueOf(oneTrigger.getTimeFrame().getTriggerTimeStart().getTime()), 5); - Miscellaneous.logEvent("i", "RuleSearch", "search time: " + String.valueOf(searchTime.getTime()), 5); - Miscellaneous.logEvent("i", "RuleSearch", "interval stop: " + String.valueOf(oneTrigger.getTimeFrame().getTriggerTimeStop().getTime()), 5); - - if(oneTrigger.getTimeFrame().getTriggerTimeStart().getTime() > oneTrigger.getTimeFrame().getTriggerTimeStop().getTime()) - { - Miscellaneous.logEvent("i", "Timeframe search", "Rule (" + oneRule.getName() + ") stretches over midnight.", 5); - if(oneTrigger.getTimeFrame().getTriggerTimeStart().getTime() <= searchTime.getTime() || searchTime.getTime() <= oneTrigger.getTimeFrame().getTriggerTimeStop().getTime()+20000) //add 20 seconds because of delay - { - ruleCandidates.add(oneRule); - break innerloop; //if the poi is found we don't need to search the other triggers in the same rule - } - } - else if(oneTrigger.getTimeFrame().getTriggerTimeStart().getTime() <= searchTime.getTime() && searchTime.getTime() <= oneTrigger.getTimeFrame().getTriggerTimeStop().getTime()+20000) //add 20 seconds because of delay - { - Miscellaneous.logEvent("i", "RuleSearch", "Rule found (" + oneRule.getName() + ") with TimeFrame with time " + searchTime.toString(), 3); - ruleCandidates.add(oneRule); - break innerloop; //if the poi is found we don't need to search the other triggers in the same rule - } - } - } - } - - Miscellaneous.logEvent("i", "RuleSearch", String.valueOf(ruleCandidates.size()) + " Rule(s) found with TimeFrame with time " + searchTime.toString(), 3); - - return ruleCandidates; - }*/ - - /*public static ArrayList findRuleCandidatesByCharging(boolean triggerParameter) - { - ArrayList ruleCandidates = new ArrayList(); - - for(Rule oneRule : ruleCollection) - { - innerloop: - for(Trigger oneTrigger : oneRule.getTriggerSet()) - { - if(oneTrigger.getTriggerType() == Trigger.Trigger_Enum.charging) - { - if(oneTrigger.getTriggerParameter() == triggerParameter) - { - ruleCandidates.add(oneRule); - break innerloop; //if the poi is found we don't need to search the other triggers in the same rule - } - } - } - } - - return ruleCandidates; - }*/ - - /*public static ArrayList findRuleCandidatesByUsbHost(boolean triggerParameter) - { - ArrayList ruleCandidates = new ArrayList(); - - for(Rule oneRule : ruleCollection) - { - innerloop: - for(Trigger oneTrigger : oneRule.getTriggerSet()) - { - if(oneTrigger.getTriggerType() == Trigger.Trigger_Enum.usb_host_connection) - { - if(oneTrigger.getTriggerParameter() == triggerParameter) - { - ruleCandidates.add(oneRule); - break innerloop; //if the poi is found we don't need to search the other triggers in the same rule - } - } - } - } - - return ruleCandidates; - }*/ - - /*public static ArrayList findRuleCandidatesByAirplaneMode(boolean triggerParameter) - { - ArrayList ruleCandidates = new ArrayList(); - - for(Rule oneRule : ruleCollection) - { - innerloop: - for(Trigger oneTrigger : oneRule.getTriggerSet()) - { - if(oneTrigger.getTriggerType() == Trigger.Trigger_Enum.airplaneMode) - { - if(oneTrigger.getTriggerParameter() == triggerParameter) - { - ruleCandidates.add(oneRule); - break innerloop; //we don't need to search the other triggers in the same rule - } - } - } - } - - return ruleCandidates; - }*/ - - /*public static ArrayList findRuleCandidatesByRoaming(boolean triggerParameter) - { - ArrayList ruleCandidates = new ArrayList(); - - for(Rule oneRule : ruleCollection) - { - innerloop: - for(Trigger oneTrigger : oneRule.getTriggerSet()) - { - if(oneTrigger.getTriggerType() == Trigger.Trigger_Enum.roaming) - { - if(oneTrigger.getTriggerParameter() == triggerParameter) - { - ruleCandidates.add(oneRule); - break innerloop; //we don't need to search the other triggers in the same rule - } - } - } - } - - return ruleCandidates; - }*/ - - /*public static ArrayList findRuleCandidatesByPhoneCall(String direction) - { - ArrayList ruleCandidates = new ArrayList(); - - for(Rule oneRule : ruleCollection) - { - innerloop: - for(Trigger oneTrigger : oneRule.getTriggerSet()) - { - if(oneTrigger.getTriggerType() == Trigger.Trigger_Enum.phoneCall) - { - String[] elements = oneTrigger.getTriggerParameter2().split(triggerParameter2Split); - if(elements[1].equals(Trigger.triggerPhoneCallDirectionAny) || elements[1].equals(direction)) - { - ruleCandidates.add(oneRule); - break innerloop; //we don't need to search the other triggers in the same rule - } - } - } - } - - return ruleCandidates; - }*/ - public static ArrayList findRuleCandidatesByPoi(PointOfInterest searchPoi) { ArrayList ruleCandidates = new ArrayList(); @@ -783,29 +623,6 @@ public class Rule implements Comparable return ruleCandidates; } - - /*public static ArrayList findRuleCandidatesByHeadphoneJack(boolean triggerParameter) - { - ArrayList ruleCandidates = new ArrayList(); - - for(Rule oneRule : ruleCollection) - { - innerloop: - for(Trigger oneTrigger : oneRule.getTriggerSet()) - { - if(oneTrigger.getTriggerType() == Trigger.Trigger_Enum.headsetPlugged) - { - if(oneTrigger.getTriggerParameter() == triggerParameter) - { - ruleCandidates.add(oneRule); - break innerloop; //we don't need to search the other triggers in the same rule - } - } - } - } - - return ruleCandidates; - }*/ public static ArrayList findRuleCandidatesByTriggerProfile(Profile profile) { @@ -904,4 +721,15 @@ public class Rule implements Comparable { return ActivityPermissions.havePermissionsForRule(this, Miscellaneous.getAnyContext()); } + + public static Rule getByName(String ruleName) + { + for(Rule r : Rule.getRuleCollection()) + { + if(r.getName().equals(ruleName)) + return r; + } + + return null; + } } diff --git a/app/src/googlePlayFlavor/AndroidManifest.xml b/app/src/googlePlayFlavor/AndroidManifest.xml index c0b847a..920f8b1 100644 --- a/app/src/googlePlayFlavor/AndroidManifest.xml +++ b/app/src/googlePlayFlavor/AndroidManifest.xml @@ -65,6 +65,7 @@ + innerloop: for(Trigger oneTrigger : oneRule.getTriggerSet()) { - if(oneTrigger.getTriggerType() == triggerType) + if(oneTrigger.getTriggerType().equals(triggerType)) { ruleCandidates.add(oneRule); break innerloop; // we don't need to check the other triggers in the same rule @@ -566,6 +566,26 @@ public class Rule implements Comparable return ruleCandidates; } + + public static ArrayList findRuleCandidates(Action.Action_Enum actionType) + { + ArrayList ruleCandidates = new ArrayList(); + + for(Rule oneRule : ruleCollection) + { + innerloop: + for(Action oneAction : oneRule.getActionSet()) + { + if(oneAction.getAction().equals(actionType)) + { + ruleCandidates.add(oneRule); + break innerloop; // we don't need to check the other actions in the same rule + } + } + } + + return ruleCandidates; + } public static ArrayList findRuleCandidatesByPoi(PointOfInterest searchPoi, boolean triggerParameter) { @@ -608,186 +628,6 @@ public class Rule implements Comparable return ruleCandidates; } - /*public static ArrayList findRuleCandidatesByTimeFrame(TimeFrame searchTimeFrame, boolean triggerParameter) - { - ArrayList ruleCandidates = new ArrayList(); - - for(int i=0; i findRuleCandidatesByTime(Time searchTime) - { - Miscellaneous.logEvent("i", "RuleSearch", "Searching for rules with TimeFrame with time " + searchTime.toString() + ". RuleCollection-Size: " + String.valueOf(ruleCollection.size()), 3);; - ArrayList ruleCandidates = new ArrayList(); - - for(Rule oneRule : ruleCollection) - { - innerloop: - for(Trigger oneTrigger : oneRule.getTriggerSet()) - { - if(oneTrigger.getTriggerType() == Trigger.Trigger_Enum.timeFrame) - { - Miscellaneous.logEvent("i", "RuleSearch", "Searching interval: " + oneTrigger.getTimeFrame().getTriggerTimeStart().toString() + " to " + oneTrigger.getTimeFrame().getTriggerTimeStop().toString(), 5); - Miscellaneous.logEvent("i", "RuleSearch", "interval start: " + String.valueOf(oneTrigger.getTimeFrame().getTriggerTimeStart().getTime()), 5); - Miscellaneous.logEvent("i", "RuleSearch", "search time: " + String.valueOf(searchTime.getTime()), 5); - Miscellaneous.logEvent("i", "RuleSearch", "interval stop: " + String.valueOf(oneTrigger.getTimeFrame().getTriggerTimeStop().getTime()), 5); - - if(oneTrigger.getTimeFrame().getTriggerTimeStart().getTime() > oneTrigger.getTimeFrame().getTriggerTimeStop().getTime()) - { - Miscellaneous.logEvent("i", "Timeframe search", "Rule (" + oneRule.getName() + ") stretches over midnight.", 5); - if(oneTrigger.getTimeFrame().getTriggerTimeStart().getTime() <= searchTime.getTime() || searchTime.getTime() <= oneTrigger.getTimeFrame().getTriggerTimeStop().getTime()+20000) //add 20 seconds because of delay - { - ruleCandidates.add(oneRule); - break innerloop; //if the poi is found we don't need to search the other triggers in the same rule - } - } - else if(oneTrigger.getTimeFrame().getTriggerTimeStart().getTime() <= searchTime.getTime() && searchTime.getTime() <= oneTrigger.getTimeFrame().getTriggerTimeStop().getTime()+20000) //add 20 seconds because of delay - { - Miscellaneous.logEvent("i", "RuleSearch", "Rule found (" + oneRule.getName() + ") with TimeFrame with time " + searchTime.toString(), 3); - ruleCandidates.add(oneRule); - break innerloop; //if the poi is found we don't need to search the other triggers in the same rule - } - } - } - } - - Miscellaneous.logEvent("i", "RuleSearch", String.valueOf(ruleCandidates.size()) + " Rule(s) found with TimeFrame with time " + searchTime.toString(), 3); - - return ruleCandidates; - }*/ - - /*public static ArrayList findRuleCandidatesByCharging(boolean triggerParameter) - { - ArrayList ruleCandidates = new ArrayList(); - - for(Rule oneRule : ruleCollection) - { - innerloop: - for(Trigger oneTrigger : oneRule.getTriggerSet()) - { - if(oneTrigger.getTriggerType() == Trigger.Trigger_Enum.charging) - { - if(oneTrigger.getTriggerParameter() == triggerParameter) - { - ruleCandidates.add(oneRule); - break innerloop; //if the poi is found we don't need to search the other triggers in the same rule - } - } - } - } - - return ruleCandidates; - }*/ - - /*public static ArrayList findRuleCandidatesByUsbHost(boolean triggerParameter) - { - ArrayList ruleCandidates = new ArrayList(); - - for(Rule oneRule : ruleCollection) - { - innerloop: - for(Trigger oneTrigger : oneRule.getTriggerSet()) - { - if(oneTrigger.getTriggerType() == Trigger.Trigger_Enum.usb_host_connection) - { - if(oneTrigger.getTriggerParameter() == triggerParameter) - { - ruleCandidates.add(oneRule); - break innerloop; //if the poi is found we don't need to search the other triggers in the same rule - } - } - } - } - - return ruleCandidates; - }*/ - - /*public static ArrayList findRuleCandidatesByAirplaneMode(boolean triggerParameter) - { - ArrayList ruleCandidates = new ArrayList(); - - for(Rule oneRule : ruleCollection) - { - innerloop: - for(Trigger oneTrigger : oneRule.getTriggerSet()) - { - if(oneTrigger.getTriggerType() == Trigger.Trigger_Enum.airplaneMode) - { - if(oneTrigger.getTriggerParameter() == triggerParameter) - { - ruleCandidates.add(oneRule); - break innerloop; //we don't need to search the other triggers in the same rule - } - } - } - } - - return ruleCandidates; - }*/ - - /*public static ArrayList findRuleCandidatesByRoaming(boolean triggerParameter) - { - ArrayList ruleCandidates = new ArrayList(); - - for(Rule oneRule : ruleCollection) - { - innerloop: - for(Trigger oneTrigger : oneRule.getTriggerSet()) - { - if(oneTrigger.getTriggerType() == Trigger.Trigger_Enum.roaming) - { - if(oneTrigger.getTriggerParameter() == triggerParameter) - { - ruleCandidates.add(oneRule); - break innerloop; //we don't need to search the other triggers in the same rule - } - } - } - } - - return ruleCandidates; - }*/ - - /*public static ArrayList findRuleCandidatesByPhoneCall(String direction) - { - ArrayList ruleCandidates = new ArrayList(); - - for(Rule oneRule : ruleCollection) - { - innerloop: - for(Trigger oneTrigger : oneRule.getTriggerSet()) - { - if(oneTrigger.getTriggerType() == Trigger.Trigger_Enum.phoneCall) - { - String[] elements = oneTrigger.getTriggerParameter2().split(triggerParameter2Split); - if(elements[1].equals(Trigger.triggerPhoneCallDirectionAny) || elements[1].equals(direction)) - { - ruleCandidates.add(oneRule); - break innerloop; //we don't need to search the other triggers in the same rule - } - } - } - } - - return ruleCandidates; - }*/ - public static ArrayList findRuleCandidatesByPoi(PointOfInterest searchPoi) { ArrayList ruleCandidates = new ArrayList(); @@ -810,29 +650,6 @@ public class Rule implements Comparable return ruleCandidates; } - - /*public static ArrayList findRuleCandidatesByHeadphoneJack(boolean triggerParameter) - { - ArrayList ruleCandidates = new ArrayList(); - - for(Rule oneRule : ruleCollection) - { - innerloop: - for(Trigger oneTrigger : oneRule.getTriggerSet()) - { - if(oneTrigger.getTriggerType() == Trigger.Trigger_Enum.headsetPlugged) - { - if(oneTrigger.getTriggerParameter() == triggerParameter) - { - ruleCandidates.add(oneRule); - break innerloop; //we don't need to search the other triggers in the same rule - } - } - } - } - - return ruleCandidates; - }*/ public static ArrayList findRuleCandidatesByTriggerProfile(Profile profile) { @@ -931,4 +748,15 @@ public class Rule implements Comparable { return ActivityPermissions.havePermissionsForRule(this, Miscellaneous.getAnyContext()); } + + public static Rule getByName(String ruleName) + { + for(Rule r : Rule.getRuleCollection()) + { + if(r.getName().equals(ruleName)) + return r; + } + + return null; + } } diff --git a/app/src/main/java/com/jens/automation2/ActivityManageActionSendTextMessage.java b/app/src/main/java/com/jens/automation2/ActivityManageActionSendTextMessage.java index ab54925..8310d6d 100644 --- a/app/src/main/java/com/jens/automation2/ActivityManageActionSendTextMessage.java +++ b/app/src/main/java/com/jens/automation2/ActivityManageActionSendTextMessage.java @@ -1,5 +1,6 @@ package com.jens.automation2; +import android.Manifest; import android.app.Activity; import android.content.Intent; import android.content.pm.PackageManager; @@ -123,7 +124,7 @@ public class ActivityManageActionSendTextMessage extends Activity { for(int i=0; i { @@ -331,6 +337,13 @@ public class ActivityManageActionStartActivity extends Activity return alertDialog; } + void getAppList() + { + GetActivityListTask getActivityListTask = new GetActivityListTask(); + getActivityListTask.execute(); + progressDialog = ProgressDialog.show(ActivityManageActionStartActivity.this, "", ActivityManageActionStartActivity.this.getResources().getString(R.string.gettingListOfInstalledApplications)); + } + @Override protected void onCreate(Bundle savedInstanceState) { @@ -364,9 +377,13 @@ public class ActivityManageActionStartActivity extends Activity @Override public void onClick(View v) { - GetActivityListTask getActivityListTask = new GetActivityListTask(); - getActivityListTask.execute(); - progressDialog = ProgressDialog.show(ActivityManageActionStartActivity.this, "", ActivityManageActionStartActivity.this.getResources().getString(R.string.gettingListOfInstalledApplications)); + int targetSdkVersion = getApplicationContext().getApplicationInfo().targetSdkVersion; + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && targetSdkVersion >= 30) + { + requestPermissions(new String[] {Manifest.permission.QUERY_ALL_PACKAGES}, requestCodeForRequestQueryAllPackagesPermission); + } + else + getAppList(); } }); @@ -661,4 +678,22 @@ public class ActivityManageActionStartActivity extends Activity getActionStartActivityDialog1Application().show(); } } + + @Override + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) + { + super.onRequestPermissionsResult(requestCode, permissions, grantResults); + + if(requestCode == requestCodeForRequestQueryAllPackagesPermission) + { + for(int i = 0; i < permissions.length; i++) + { + if(permissions[i].equals(Manifest.permission.QUERY_ALL_PACKAGES) && grantResults[i] == PackageManager.PERMISSION_GRANTED) + { + getAppList(); + break; + } + } + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/jens/automation2/ActivityManageProfile.java b/app/src/main/java/com/jens/automation2/ActivityManageProfile.java index f81ac10..273ab22 100644 --- a/app/src/main/java/com/jens/automation2/ActivityManageProfile.java +++ b/app/src/main/java/com/jens/automation2/ActivityManageProfile.java @@ -44,6 +44,8 @@ public class ActivityManageProfile extends Activity Button bChangeSoundIncomingCalls, bChangeSoundNotifications, bSaveProfile; TextView tvIncomingCallsRingtone, tvNotificationsRingtone; EditText etName; + + boolean guiUpdate = false; File incomingCallsRingtone = null, notificationsRingtone = null; @@ -368,6 +370,8 @@ public class ActivityManageProfile extends Activity public void editProfile(Profile profileToEdit) { + guiUpdate = true; + etName.setText(ActivityMainProfiles.profileToEdit.getName()); checkBoxChangeSoundMode.setChecked(ActivityMainProfiles.profileToEdit.getChangeSoundMode()); checkBoxChangeDnd.setChecked(ActivityMainProfiles.profileToEdit.getChangeDndMode()); @@ -393,6 +397,8 @@ public class ActivityManageProfile extends Activity setIncomingCallsRingtone(ActivityMainProfiles.profileToEdit.getIncomingCallsRingtone()); setNotificationsRingtone(ActivityMainProfiles.profileToEdit.getNotificationRingtone()); + + guiUpdate = false; } private boolean loadFormValuesToVariable() diff --git a/app/src/main/java/com/jens/automation2/ActivityPermissions.java b/app/src/main/java/com/jens/automation2/ActivityPermissions.java index 6c773d3..3f42fe0 100644 --- a/app/src/main/java/com/jens/automation2/ActivityPermissions.java +++ b/app/src/main/java/com/jens/automation2/ActivityPermissions.java @@ -353,6 +353,12 @@ public class ActivityPermissions extends Activity if(!havePermission(Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, workingContext)) addToArrayListUnique(Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, requiredPermissions); + for(Profile p : Profile.getProfileCollection()) + { + if(p.changeIncomingCallsRingtone || p.changeNotificationRingtone) + addToArrayListUnique(Manifest.permission.READ_EXTERNAL_STORAGE, requiredPermissions); + } + if (!onlyGeneral) { for (Rule rule : Rule.getRuleCollection()) @@ -864,8 +870,32 @@ public class ActivityPermissions extends Activity case Manifest.permission.READ_EXTERNAL_STORAGE: for(String ruleName : getRulesUsing(Action.Action_Enum.playSound)) usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName)); + for(String ruleName : getRulesUsing(Action.Action_Enum.changeSoundProfile)) - usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName)); + { + Rule tempRule = Rule.getByName(ruleName); + if(tempRule != null) + { + for (Action a : tempRule.getActionSet()) + { + if (a.getAction().equals(Action.Action_Enum.changeSoundProfile)) + { + Profile p = Profile.getByName(a.getParameter2()); + if (p.changeIncomingCallsRingtone || p.changeNotificationRingtone) + usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName)); + } + } + } + } + + for(Profile p : Profile.getProfileCollection()) + { + if(p.changeIncomingCallsRingtone || p.changeNotificationRingtone) + { + usingElements.add(String.format(getResources().getString(R.string.profileXrequiresThis), p.getName())); + } + } + break; case Manifest.permission.BIND_DEVICE_ADMIN: for(String ruleName : getRulesUsing(Action.Action_Enum.turnScreenOnOrOff)) diff --git a/app/src/main/java/com/jens/automation2/Profile.java b/app/src/main/java/com/jens/automation2/Profile.java index 58095d1..468cea7 100644 --- a/app/src/main/java/com/jens/automation2/Profile.java +++ b/app/src/main/java/com/jens/automation2/Profile.java @@ -308,29 +308,31 @@ public class Profile implements Comparable ContentValues values = new ContentValues(); values.put(MediaStore.MediaColumns.DATA, ringtoneFile.getAbsolutePath()); -// values.put(MediaStore.MediaColumns.TITLE, context.getResources().getString(R.string.app_name) + " ringtone"); -// values.put(MediaStore.MediaColumns.TITLE, ringtoneFile.getName().replace(".mp3", "").replace(".", "")); values.put(MediaStore.MediaColumns.TITLE, ringtoneFile.getName()); -// values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/*"); values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3"); values.put(MediaStore.MediaColumns.SIZE, ringtoneFile.length()); -// values.put(MediaStore.Audio.Media.ARTIST, R.string.app_name); 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); - Uri existingRingTone = MediaStore.Audio.Media.getContentUriForPath(ringtoneFile.getAbsolutePath()); - if(existingRingTone != null) - context.getContentResolver().delete(existingRingTone, MediaStore.MediaColumns.DATA + "=\"" + ringtoneFile.getAbsolutePath() + "\"", null); - Uri newRingTone = context.getContentResolver().insert(existingRingTone, values); - 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); -// Ringtone tone = RingtoneManager.getRingtone(context, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE)); -// tone.play(); return true; } catch (Throwable t) diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 31a1308..88d204d 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -697,4 +697,6 @@ Prüffrequenz Millisekunden zwischen Prüfungen Musik-läuft Erkennung + Das Abrufen des Standorts scheint unter Android 12 derzeit nicht zu funktionieren. Wenn es bei Ihnen nicht klappt, tut mir das leid. Ich werde versuchen die Ursache zu beheben, sobald mir die Ursache bekannt ist. Wenn der Donut bei Ihnen also nicht aufhört sich zu drehen, wissen Sie warum. + Profil \"%1$s\" benötigt dies. \ No newline at end of file diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 657c3ff..48616b2 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -696,4 +696,6 @@ Frecuencia de los controles Millisegundos entre controles Musica tocando deteción + Obtener la locación no parece estar funcionando en dispositivos Android 12 actualmente. Si no está funcionando para ti, lo siento. Intentaré arreglar esto tan pronto como conozca la causa. Así que si la rosquilla no deja de girar, ya sabes por qué. + El perfil \"%1$s\" requiere esto. \ No newline at end of file diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 34a4eca..3c5988d 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -456,10 +456,10 @@ Impostazioni predefinite ripristinate. Alcune impostazioni non saranno applicate prima che alcune impostazioni contestuali cambino o che il servizio venga riavviato. Questo creerà una email con la tua configurazione e i file di log allegati come file zip. Non sarà inviata automaticamente, dovrai premere \"invia\". Puoi anche cambiare il destinatario con te stesso, per esempio. - Agganciare i file di configurazione e di registro + Allegare i file di configurazione e di registro Mostra Aiuto Mostra icona - Mostra una icona quando il servizio è attivo (nasconderla funziona solo in versioni inferiori ad Android 7). Se hai una versione superiore, vai alle impostazioni di sistema, quindi all\'automazione, quindi alle notifiche e disabilita la \"Service notification\". + Mostra una icona quando il servizio è attivo (nasconderla funziona solo in versioni inferiori ad Android 7). Se hai una versione superiore, vai alle impostazioni di sistema, quindi Automation, e poi seleziona Notifiche, dove potrai disabilitare la \"Service notification\". Mostra sulla mappa Alcune opzioni sono disabilitate in quanto non ancora implementate. Saranno introdotte in una versione successiva. Modalità sonora @@ -533,7 +533,7 @@ Martedì Errore indeterminato. finchè - Variabili:\n È possibile utilizzare le seguenti variabili. All\'attivazione saranno sostituite con il valore corrispondente sul dispositivo. Includi le parentesi nel tuo testo.\n\n[uniqueid] - Il numero di serie del tuo dispositivo\n[serialnr] - Il serial number del tuo dispositivio (< Android 9)\n[latitude] - La latitudine del tuo dispositivo\n[longitude] - La longitudine del tuo dispositivo\n[phonenr] - Numero dell\'ultima chiamata (entrante o uscente)\n[d] - Il giorno del mese, sempre 2 cifre\n[m] - Mese in formato numerico, sempre 2 cifre\n[Y] - L\’anno, sempre 4 cifre\n[h] - Ore in formato 12 ore, sempre 2 cifre con due punti\n[H] - Ore in formato 24 ore, sempre 2 cifre con due punti\n[i] - Minuti, sempre 2 cifre\n[s] - Secondi, sempre 2 cifre\n[ms] - millisecondi, sempre 3 cifre [notificationTitle] - titolo dell\'ultima notifica [notificationText] - testo dell\'ultima notifica + Variabili:\n È possibile utilizzare le seguenti variabili. Quando attivate, saranno sostituite con il valore corrispondente sul tuo dispositivo. Includi le parentesi nel tuo testo.\n\n[uniqueid] - L\'ID unico del tuo dispositivo\n[serialnr] - Il numero di serie del tuo dispositivio (< Android 9)\n[latitude] - La latitudine del tuo dispositivo\n[longitude] - La longitudine del tuo dispositivo\n[phonenr] - Numero dell\'ultima chiamata (entrante o uscente)\n[d] - Il giorno del mese, sempre 2 cifre con zero iniziale \n[m] - Mese in formato numerico, sempre 2 cifre con zero iniziale \n[Y] - L\’anno, sempre con 4 cifre\n[h] - Ore in formato 12 ore, sempre 2 cifre con due punti\n[H] - Ore in formato 24 ore, sempre 2 cifre con due punti\n[i] - Minuti, sempre 2 cifre\n[s] - Secondi, sempre 2 cifre\n[ms] - millisecondi, sempre 3 cifre\n[notificationTitle] - titolo dell\'ultima notifica\n[notificationText] - testo dell\'ultima notifica URL da caricare: L\'url deve avere almeno 10 caratteri. Questo molto probabilmente non funzionerà dato che sei su una versione superiore ad Android 2.3. Tuttavia è possibile utilizzare la connessione wifi tethering per attivare la regola. @@ -661,22 +661,22 @@ Impossibile identificare un\'attività di avvio di questa app. Dovrai sceglierne uno manualmente. Crea notifica Inserisci un titolo. - Immettere un testo. - Info + Aggiungi un testo. + Informazioni Il profilo utilizzato in questa regola non sembra più esistere. Il primo in ordine alfabetico è stato selezionato. - I confronti sono fatti caso-INsensitive + I confronti non distinguono fra maiuscole e minuscole Chiudi notifica(e) - Se non specifichi alcun criterio, questa azione chiuderà TUTTE le notifiche. Quindi si consiglia di specificare almeno i criteri per almeno 1 di applicazione, titolo o testo. - Le impostazioni che fai qui possono far sì che tu non noti più certe cose dal tuo telefono. Possono anche mettere a tacere la sveglia. Quindi, qualunque cosa tu faccia, ti consigliamo di testarlo. + Se non specifichi alcun criterio, questa azione chiuderà TUTTE le notifiche. Quindi si consiglia di specificare almeno i criteri per almeno una applicazione, titolo o testo. + Le impostazioni che modifichi in questa sezione possono far sì che tu non possa più notare certe cose dal tuo telefono. Possono perfino silenziare la sveglia. Quindi, qualunque cosa tu faccia, ti consigliamo di provarlo. se - Tieni presente che questa azione potrebbe non funzionare con TUTTI i giocatori là fuori. E anche se lo fa, non tutti i pulsanti funzionano necessariamente. - Seleziona un\'azione! - fermarsi - Controllare la riproduzione multimediale + Tieni presente che questa azione potrebbe non funzionare con TUTTI i lettori là fuori. E anche se lo facesse, non tutti i pulsanti funzionerebbero necessariamente. + Si prega di selezionare un\'azione! + stop + Controllo riproduzione multimediale prossimo precedente pausa - giocare + riproduci attiva/disattiva riproduzione/pausa Seleziona comando Controllare la riproduzione multimediale @@ -697,4 +697,6 @@ Frequenza dei controlli [ms] Millisecondi tra i controlli Rilevamento della riproduzione musicale + Il profilo \"%1$s\" lo richiede. + Ottenere la posizione non sembra funzionare su dispositivi Android 12 al momento. Se non funziona per te, mi dispiace. Cercherò di risolvere questo problema non appena conoscerò la causa. Quindi, se la ciambella non smette di girare, sai perché. diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 6ac15df..a846868 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -695,4 +695,6 @@ Controleer frequentie [ms] Milliseconden tussen controles Detectie van het afspelen van muziek + Het verkrijgen van de locatie lijkt momenteel niet te werken op Android 12-apparaten. Als het niet voor je werkt, spijt het me. Ik zal proberen dit op te lossen zodra ik de oorzaak ken. Dus als de donut niet stopt met draaien, weet je waarom. + Profiel \"%1$s\" vereist dit. diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ab1983c..e83e669 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -567,6 +567,7 @@ Override do not disturb policy These are the permissions required: Rule \"%1$s\" requires this. + Profile \"%1$s\" requires this. This feature can detect if you\'re currently on the go and if it is on foot or in which type of vehicle (to a certain extent). The feature is not fully built into Automation, but is provided by Google Play Services. Technically it does not give a yes/no result, but return a percentage to which level it is sure it detected you\'re status. You can setup the percentage value from which Automation will accept a result. Two remarks: 1) More than 1 status could occur at the same time. For example you might be WALKING inside a driving bus. 2) This sensor is relatively expensive in terms of battery usage. If it is possible you might consider using alternatives, e.g. require your car\'s handsfree device to be connected to detect you\'re driving. Send text message Text to send diff --git a/fastlane/metadata/android/en-US/changelogs/118.txt b/fastlane/metadata/android/en-US/changelogs/118.txt index ff6c070..68341d1 100644 --- a/fastlane/metadata/android/en-US/changelogs/118.txt +++ b/fastlane/metadata/android/en-US/changelogs/118.txt @@ -4,4 +4,6 @@ * New action: Control media playback * Fixed: Translation bug in dutch variables text * Fixed: Variables were not replaced when sending text messages -* Fixed: Service wouldn't always start after device has been powered on \ No newline at end of file +* Fixed: Service wouldn't always start after device has been powered on +* Fixed: Set ringtones on Android 11 and above +* Fixed: Permission read storage required for changing ringtones \ No newline at end of file