Skip to content

Commit 12e7475

Browse files
committed
Add call confirmation request
Now VISOR can FINALLY have interactive commands. The first dynamic one was the contacts one. Now all can be interactive. He will request a user confirmation before calling any number. 2 new commands were added for this: a confirmation one, and a rejection one. There is no need to explicitly reject a command though - it will be rejected in 60 seconds if there's no confirmation. Updated the makePhoneCall() function to say why it could not place a call (no permission to call any number or just emergency numbers?). Removed the forced permissions and authorizations (again).
1 parent f45f814 commit 12e7475

File tree

8 files changed

+355
-109
lines changed

8 files changed

+355
-109
lines changed

app/src/main/java/com/dadi590/assist_c_a/GlobalUtils/AndroidSystem/UtilsAndroid.java

+3
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,7 @@ private UtilsAndroid() {
4747
public static final int MODE_RECOVERY = -987678;
4848
public static final int MODE_BOOTLOADER = -987679;
4949
public static final int MODE_FAST = -987680;
50+
51+
public static final int NO_CALL_EMERGENCY = -987681;
52+
public static final int NO_CALL_ANY = -987682;
5053
}

app/src/main/java/com/dadi590/assist_c_a/GlobalUtils/AndroidSystem/UtilsAndroidTelephony.java

+23-20
Original file line numberDiff line numberDiff line change
@@ -183,47 +183,50 @@ public static void setCallSpeakerphoneEnabled(final boolean enabled) {
183183

184184
/**
185185
* <p>Places a phone call.</p>
186-
* <p>If the app is a privileged system app, it is possible to call emergency numbers - do not attempt without being
187-
* such an app, or a security exception will be thrown and not handled.</p>
186+
* <br>
187+
* <p><u>---CONSTANTS---</u></p>
188+
* <p>- {@link UtilsAndroid#NO_ERR} --> for the returning value: if the operation completed successfully</p>
189+
* <p>- {@link UtilsAndroid#NO_CALL_ANY} --> for the returning value: no permission to call numbers</p>
190+
* <p>- {@link UtilsAndroid#NO_CALL_EMERGENCY} --> for the returning value: no permission to call emergency numbers</p>
191+
* <p><u>---CONSTANTS---</u></p>
188192
*
189-
* @param phone_number the phone number to call, with country prefix (for example, +351123456789 or +351112 for
190-
* Portugal)
193+
* @param phone_number the phone number to call
191194
*
192-
* @return true if the call was placed, false if it was just dialed because there are not enough permissions to
193-
* place the call (either because there's no permission to place calls, or there's no permission to place emergency
194-
* calls)
195+
* @return one of the constants
195196
*/
196-
public static boolean makePhoneCall(@NonNull final String phone_number) {
197+
public static int makePhoneCall(@NonNull final String phone_number) {
197198
final Context context = UtilsGeneral.getContext();
198199

199200
final Intent intent = new Intent("", Uri.fromParts("tel", phone_number, null));
200201

201-
// I think below Android 11, ACTION_DIAL can be used to dial emergency numbers (haven't tested it yet though).
202-
final String action_dial_emergency = Build.VERSION.SDK_INT >= Build.VERSION_CODES.R ?
203-
Intent.ACTION_DIAL_EMERGENCY : Intent.ACTION_DIAL;
202+
// On 2023-02-01, Android Developers says ACTION_DIAL can be used for emergency numbers (so at least until
203+
// Android 12 it's like this).
204+
final String action_dial_emergency = Intent.ACTION_DIAL;
205+
final boolean is_potentially_emergency_number = UtilsTelephony.isPotentialEmergencyNumber(phone_number);
204206

205207
final String action;
206-
final boolean call_placed;
208+
final int return_code;
207209
if (UtilsPermsAuths.checkSelfPermission(Manifest.permission.CALL_PRIVILEGED)) {
210+
// As written on the AOSP code for ACTION_CALL_PRIVILEGED:
211+
// "Perform a call to any number (emergency or not) specified by the data."
208212
action = Intent.ACTION_CALL_PRIVILEGED;
209-
call_placed = true;
213+
return_code = UtilsAndroid.NO_ERR;
210214
} else if (UtilsPermsAuths.checkSelfPermission(Manifest.permission.CALL_PHONE)) {
211-
if (UtilsTelephony.isEmergencyNumber(phone_number)) {
215+
if (is_potentially_emergency_number) {
212216
action = action_dial_emergency;
213-
call_placed = false;
217+
return_code = UtilsAndroid.NO_CALL_EMERGENCY;
214218
} else {
215219
action = Intent.ACTION_CALL;
216-
call_placed = true;
220+
return_code = UtilsAndroid.NO_ERR;
217221
}
218222
} else {
219-
action = UtilsTelephony.isEmergencyNumber(phone_number) ? action_dial_emergency : Intent.ACTION_DIAL;
220-
call_placed = false;
223+
action = is_potentially_emergency_number ? action_dial_emergency : Intent.ACTION_DIAL;
224+
return_code = UtilsAndroid.NO_CALL_ANY;
221225
}
222-
223226
intent.setAction(action);
224227
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
225228
context.startActivity(intent);
226229

227-
return call_placed;
230+
return return_code;
228231
}
229232
}

app/src/main/java/com/dadi590/assist_c_a/GlobalUtils/UtilsPermsAuths.java

+17-12
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
package com.dadi590.assist_c_a.GlobalUtils;
2323

2424
import android.app.Activity;
25+
import android.app.AppOpsManager;
2526
import android.app.NotificationManager;
2627
import android.content.ComponentName;
2728
import android.content.Context;
@@ -116,7 +117,7 @@ public static int checkRequestPerms(@Nullable final Activity activity, final boo
116117

117118
final String [][][] list_to_use = PERMS_CONSTS.list_of_perms_lists;
118119
final int list_to_use_len = list_to_use.length;
119-
final boolean force_permissions = (request && activity == null);
120+
final boolean force_permissions = false;// todo (request && activity == null); - same reason on the auths function
120121
int num_not_granted_perms = 0;
121122

122123
int array_length = 0;
@@ -209,7 +210,11 @@ public static int checkRequestAuths(int what_to_do) {
209210
final String package_name = context.getPackageName();
210211
int missing_authorizations = 0;
211212

212-
// todo Remove the comments when you make a way to request VISOR to stop requesting specific permissions
213+
// todo Remove this when you make a way to request VISOR to stop requesting specific permissions
214+
// Also I can't test stuff with this thing forcing all auths and perms to be granted...
215+
if (ALSO_FORCE == what_to_do) {
216+
what_to_do = CHECK_ONLY;
217+
}
213218

214219
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
215220
// Check if the DND management policy access has been granted for the app and if not, open the settings
@@ -218,10 +223,10 @@ public static int checkRequestAuths(int what_to_do) {
218223
getSystemService(Context.NOTIFICATION_SERVICE);
219224
if (!mNotificationManager.isNotificationPolicyAccessGranted()) {
220225
if (ALSO_FORCE == what_to_do) {
221-
/*final String command = "cmd notification allow_dnd " + package_name;
226+
final String command = "cmd notification allow_dnd " + package_name;
222227
UtilsShell.executeShellCmd(command, false, true);
223228

224-
missing_authorizations += mNotificationManager.isNotificationPolicyAccessGranted() ? 0 : 1;*/
229+
missing_authorizations += mNotificationManager.isNotificationPolicyAccessGranted() ? 0 : 1;
225230
} else {
226231
++missing_authorizations;
227232

@@ -236,11 +241,11 @@ public static int checkRequestAuths(int what_to_do) {
236241
// Check if the app can draw system overlays and open the settings screen if not
237242
if (!Settings.canDrawOverlays(context)) {
238243
if (ALSO_FORCE == what_to_do) {
239-
/*final String command = "appops set " + package_name + " " + AppOpsManager.OP_SYSTEM_ALERT_WINDOW +
244+
final String command = "appops set " + package_name + " " + AppOpsManager.OP_SYSTEM_ALERT_WINDOW +
240245
" allow";
241246
UtilsShell.executeShellCmd(command, false, true);
242247

243-
missing_authorizations += Settings.canDrawOverlays(context) ? 0 : 1;*/
248+
missing_authorizations += Settings.canDrawOverlays(context) ? 0 : 1;
244249
} else {
245250
++missing_authorizations;
246251

@@ -257,10 +262,10 @@ public static int checkRequestAuths(int what_to_do) {
257262
final PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
258263
if (!powerManager.isIgnoringBatteryOptimizations(package_name)) {
259264
if (ALSO_FORCE == what_to_do) {
260-
/*final String command = "dumpsys deviceidle whitelist +" + package_name;
265+
final String command = "dumpsys deviceidle whitelist +" + package_name;
261266
UtilsShell.executeShellCmd(command, false, true);
262267

263-
missing_authorizations += powerManager.isIgnoringBatteryOptimizations(package_name) ? 0 : 1;*/
268+
missing_authorizations += powerManager.isIgnoringBatteryOptimizations(package_name) ? 0 : 1;
264269
} else {
265270
++missing_authorizations;
266271

@@ -277,11 +282,11 @@ public static int checkRequestAuths(int what_to_do) {
277282
// Check if the app has the WRITE_SETTINGS permission and request it if not
278283
if (!Settings.System.canWrite(context)) {
279284
if (ALSO_FORCE == what_to_do) {
280-
/*final String command = "appops set " + package_name + " " + AppOpsManager.OP_WRITE_SETTINGS +
285+
final String command = "appops set " + package_name + " " + AppOpsManager.OP_WRITE_SETTINGS +
281286
" allow";
282287
UtilsShell.executeShellCmd(command, false, true);
283288

284-
missing_authorizations += Settings.System.canWrite(context) ? 0 : 1;*/
289+
missing_authorizations += Settings.System.canWrite(context) ? 0 : 1;
285290
} else {
286291
++missing_authorizations;
287292

@@ -298,9 +303,9 @@ public static int checkRequestAuths(int what_to_do) {
298303

299304
if (!UtilsApp.isDeviceAdmin()) {
300305
if (ALSO_FORCE == what_to_do) {
301-
/*forceDeviceAdmin();
306+
forceDeviceAdmin();
302307

303-
missing_authorizations += UtilsApp.isDeviceAdmin() ? 0 : 1;*/
308+
missing_authorizations += UtilsApp.isDeviceAdmin() ? 0 : 1;
304309
} else {
305310
++missing_authorizations;
306311

0 commit comments

Comments
 (0)