stop phone call action

This commit is contained in:
jens 2022-10-03 13:22:25 +02:00
parent 135f4594be
commit 62034e1b10
16 changed files with 112 additions and 19 deletions

View File

@ -67,6 +67,7 @@
<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-feature
android:name="android.hardware.telephony"

View File

@ -65,6 +65,7 @@
<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-feature
android:name="android.hardware.telephony"

View File

@ -52,7 +52,8 @@ public class Action
sendBroadcast,
runExecutable,
wakelock,
makePhoneCall,
startPhoneCall,
stopPhoneCall,
sendTextMessage;
public String getFullName(Context context)
@ -129,8 +130,10 @@ public class Action
return context.getResources().getString(R.string.runExecutable);
case wakelock:
return context.getResources().getString(R.string.keepDeviceAwake);
case makePhoneCall:
return context.getResources().getString(R.string.makePhoneCall);
case startPhoneCall:
return context.getResources().getString(R.string.startPhoneCall);
case stopPhoneCall:
return context.getResources().getString(R.string.endPhoneCall);
default:
return "Unknown";
}
@ -280,8 +283,11 @@ public class Action
case wakelock:
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.keepDeviceAwake) + " (" + String.valueOf(getParameter1()) + ")");
break;
case makePhoneCall:
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.makePhoneCall));
case startPhoneCall:
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.startPhoneCall));
break;
case stopPhoneCall:
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.endPhoneCall));
break;
default:
returnString.append(action.toString());
@ -594,8 +600,11 @@ public class Action
else
Actions.wakeLockStop();
break;
case makePhoneCall:
Actions.makePhoneCall(context, this.getParameter2());
case startPhoneCall:
Actions.startPhoneCall(context, this.getParameter2());
break;
case stopPhoneCall:
Actions.endPhoneCall(context);
break;
default:
Miscellaneous.logEvent("w", "Action", context.getResources().getString(R.string.unknownActionSpecified), 3);

View File

@ -24,6 +24,7 @@ import android.os.VibrationEffect;
import android.os.Vibrator;
import android.provider.MediaStore;
import android.service.notification.StatusBarNotification;
import android.telecom.TelecomManager;
import android.telephony.SmsManager;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
@ -2186,7 +2187,7 @@ public class Actions
wakeLockStopRequested = true;
}
public static void makePhoneCall(Context context, String phoneNumber)
public static void startPhoneCall(Context context, String phoneNumber)
{
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNumber));
// intent.setClassName("com.android.phone","com.android.phone.OutgoingCallBroadcaster");
@ -2194,4 +2195,34 @@ public class Actions
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();
}
}
}

View File

@ -418,7 +418,7 @@ public class ActivityManageRule extends Activity
activityEditRunExecutableIntent.putExtra(intentNameActionParameter2, a.getParameter2());
startActivityForResult(activityEditRunExecutableIntent, requestCodeActionRunExecutableEdit);
break;
case makePhoneCall:
case startPhoneCall:
Intent activityEditMakePhoneCallIntent = new Intent(ActivityManageRule.this, ActivityManageActionMakePhoneCall.class);
activityEditMakePhoneCallIntent.putExtra(intentNameActionParameter1, a.getParameter1());
activityEditMakePhoneCallIntent.putExtra(intentNameActionParameter2, a.getParameter2());
@ -2005,14 +2005,18 @@ public class ActivityManageRule extends Activity
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.makePhoneCall.toString()))
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));
}
@ -2182,12 +2186,18 @@ public class ActivityManageRule extends Activity
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionRunExecutable.class);
startActivityForResult(intent, requestCodeActionRunExecutableAdd);
}
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.makePhoneCall.toString()))
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.startPhoneCall.toString()))
{
newAction.setAction(Action_Enum.makePhoneCall);
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.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);

View File

@ -679,10 +679,13 @@ public class ActivityPermissions extends Activity
else
addToArrayListUnique(Manifest.permission.BIND_DEVICE_ADMIN, requiredPermissions);
break;
case makePhoneCall:
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;
default:
break;
}
@ -875,7 +878,11 @@ public class ActivityPermissions extends Activity
usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName));
break;
case Manifest.permission.CALL_PHONE:
for(String ruleName : getRulesUsing(Action.Action_Enum.makePhoneCall))
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:

View File

@ -842,6 +842,12 @@ public class Trigger
if(this.getTriggerParameter())
{
if(this.getBatteryLevel() == 100)
{
Miscellaneous.logEvent("i", Miscellaneous.getAnyContext().getResources().getString(R.string.ruleCheckOf), "Rule " + this.getParentRule().getName() + " doesn't apply. Can never exceed 100%.", 3);
return false;
}
if(BatteryReceiver.getBatteryLevel() < this.getBatteryLevel())
{
Miscellaneous.logEvent("i", Miscellaneous.getAnyContext().getResources().getString(R.string.ruleCheckOf), String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.ruleDoesntApplyBatteryLowerThan) + " " + String.valueOf(this.getBatteryLevel()), this.getParentRule().getName()), 3);
@ -850,6 +856,12 @@ public class Trigger
}
else
{
if(this.getBatteryLevel() == 0)
{
Miscellaneous.logEvent("i", Miscellaneous.getAnyContext().getResources().getString(R.string.ruleCheckOf), "Rule " + this.getParentRule().getName() + " doesn't apply. Can never drop below 0%.", 3);
return false;
}
if(BatteryReceiver.getBatteryLevel() < 100 && BatteryReceiver.getBatteryLevel() >= this.getBatteryLevel()
||
BatteryReceiver.getBatteryLevel() > this.getBatteryLevel()

View File

@ -17,7 +17,7 @@
android:textSize="25dp"
android:textStyle="bold"
android:layout_marginBottom="@dimen/default_margin"
android:text="@string/makePhoneCall"/>
android:text="@string/startPhoneCall"/>
<TextView
android:id="@+id/tvMakePhoneCallExplanation1"

View File

@ -755,4 +755,7 @@
<string name="cable">Kabel</string>
<string name="tetheringBluetoothNotPossible">Bluetooth tethering kann gegenwärtig nicht detektiert werden. Nur die anderen Verbindungsarten werden diesen Auslöser aktivieren.</string>
<string name="type">Art</string>
<string name="startPhoneCall">Telefonnummer anrufen</string>
<string name="android.permission.CALL_PHONE">Telefonnummer anrufen</string>
<string name="makePhoneCallExplanation1">Hier können Sie eine Telefonnummer eingeben, die ohne weitere Aufforderung angerufen wird. Sie können dies verwenden, um Einstellungen vorzunehmen, z. B. Anpassungen an der Anrufweiterleitung usw. vorzunehmen. Bitte suchen Sie selbst nach den dafür benötigten Codes.</string>
</resources>

View File

@ -754,4 +754,7 @@
<string name="cable">Cable</string>
<string name="tetheringBluetoothNotPossible">Actualmente no se puede detectar Bluetooth tethering. Solo los otros tipos de connection van a activar este condición.</string>
<string name="type">Tipo</string>
<string name="startPhoneCall">Llamar al número de teléfono</string>
<string name="android.permission.CALL_PHONE">Llamar al número de teléfono</string>
<string name="makePhoneCallExplanation1">Aquí puede ingresar un número de teléfono al que se llamará sin más indicaciones. Puede usar esto para realizar configuraciones como realizar ajustes en el enrutamiento de llamadas, etc. Por favor, busque los códigos necesarios para esto por su cuenta.</string>
</resources>

View File

@ -754,4 +754,7 @@
<string name="type">Type</string>
<string name="cable">Cable</string>
<string name="tetheringBluetoothNotPossible">Le partage de connexion Bluetooth ne peut actuellement pas être détecté. Seuls les autres moyens de connexion activeront ce déclencheur.</string>
<string name="startPhoneCall">Numéro de téléphone d\'appel</string>
<string name="android.permission.CALL_PHONE">Numéro de téléphone d\'appel</string>
<string name="makePhoneCallExplanation1">Ici, vous pouvez entrer un numéro de téléphone qui sera appelé sans autres invites. Vous pouvez l\'utiliser pour effectuer des paramètres tels que des ajustements au routage des appels, etc. Veuillez rechercher vous-même les codes requis pour cela.</string>
</resources>

View File

@ -755,4 +755,7 @@
<string name="cable">Cavo</string>
<string name="tetheringBluetoothNotPossible">Il tethering Bluetooth al momento non può essere rilevato. Solo gli altri mezzi di connessione attiveranno questo trigger.</string>
<string name="type">Digitare</string>
<string name="startPhoneCall">Chiama il numero di telefono</string>
<string name="android.permission.CALL_PHONE">Chiama il numero di telefono</string>
<string name="makePhoneCallExplanation1">Qui è possibile inserire un numero di telefono che verrà chiamato senza ulteriori richieste. È possibile utilizzarlo per effettuare impostazioni come apportare modifiche al routing delle chiamate, ecc. Si prega di cercare i codici richiesti per questo da soli.</string>
</resources>

View File

@ -753,5 +753,8 @@
<string name="cable">Kabel</string>
<string name="tetheringBluetoothNotPossible">Bluetooth-tethering kan momenteel niet worden gedetecteerd. Alleen de andere verbindingsmiddelen activeren deze trigger.</string>
<string name="type">Type</string>
<string name="startPhoneCall">Telefoonnummer bellen</string>
<string name="android.permission.CALL_PHONE">Telefoonnummer bellen</string>
<string name="makePhoneCallExplanation1">Hier kunt u een telefoonnummer invoeren dat zonder verdere prompts wordt gebeld. U kunt dit gebruiken om instellingen aan te brengen, zoals het aanpassen van de gespreksroutering, enz.. Zoek zelf naar de codes die hiervoor nodig zijn.</string>
</resources>

View File

@ -812,4 +812,7 @@
<string name="cable">Кабель</string>
<string name="tetheringBluetoothNotPossible">В настоящее время модем Bluetooth не может быть обнаружен. Только другие средства связи активируют этот триггер.</string>
<string name="type">тип</string>
<string name="startPhoneCall">Номер телефона</string>
<string name="android.permission.CALL_PHONE">Номер телефона</string>
<string name="makePhoneCallExplanation1">Здесь вы можете ввести номер телефона, который будет звонить без дальнейших запросов. Вы можете использовать это для внесения настроек, таких как внесение изменений в маршрутизацию вызовов и т. Д. Пожалуйста, найдите коды, необходимые для этого, самостоятельно.</string>
</resources>

View File

@ -852,7 +852,9 @@
<string name="type">Type</string>
<string name="cable">Cable</string>
<string name="tetheringBluetoothNotPossible">Bluetooth tethering can currently not be detected. Only the other means of connection will activate this trigger.</string>
<string name="makePhoneCall">Make phone call</string>
<string name="android.permission.CALL_PHONE">Make phone call</string>
<string name="startPhoneCall">Call phone number</string>
<string name="android.permission.CALL_PHONE">Call phone number</string>
<string name="makePhoneCallExplanation1">Here you can enter a phone number that will be called without further prompts. You may use this to make settings like making adjustments to call routing, etc.. Please search for the codes required for this on your own.</string>
<string name="endPhoneCall">End phone call</string>
<string name="android.permission.ANSWER_PHONE_CALLS">End phone call</string>
</resources>

View File

@ -1 +1,3 @@
* New: Confirmation dialog before deleting locations, rules and profile
* New: Confirmation dialog before deleting locations, rules and profile
* New action: Make phone call without further prompt
* Fixed: Battery receiver could trigger above 100% or below 0%