forked from jens/Automation
stop phone call action
This commit is contained in:
@ -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);
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
@ -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:
|
||||
|
@ -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()
|
||||
|
Reference in New Issue
Block a user