Call blocking on Android 9
This commit is contained in:
parent
96be593bfd
commit
ff22a5c549
|
@ -25,7 +25,7 @@ Currently implemented (more or less):
|
|||
|
||||
* Showing a notification with some caller info (positive/negative rating, category, number of negative reviews and such) when the phone's ringing. *Works offline.*
|
||||
* Loading and displaying a list of reviews for a number (accessed by pressing the notification). *Requires internet.*
|
||||
* Automatic blocking of unwanted calls (may not work on some devices; may work as a system app on Android 9; doesn't work on Android 10+). *Works offline.*
|
||||
* Automatic blocking of unwanted calls (may not work on some devices; doesn't work on Android 10+). *Works offline.*
|
||||
* Automatic update of the database (for offline use). *Requires internet.*
|
||||
|
||||
|
||||
|
|
|
@ -7,8 +7,9 @@
|
|||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||
<uses-permission android:name="android.permission.READ_CALL_LOG" />
|
||||
<uses-permission android:name="android.permission.CALL_PHONE" />
|
||||
<uses-permission android:name="android.permission.ANSWER_PHONE_CALLS" />
|
||||
|
||||
<!-- required for call blocking on Android 9, also requires to be installed as a system app -->
|
||||
<!-- may be needed for call blocking on Android 9, also requires to be installed as a system app -->
|
||||
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE"
|
||||
tools:ignore="ProtectedPermissions" />
|
||||
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
package dummydomain.yetanothercallblocker;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import android.os.Build;
|
||||
import android.telecom.TelecomManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import com.android.internal.telephony.ITelephony;
|
||||
|
@ -108,14 +112,29 @@ public class CallReceiver extends BroadcastReceiver {
|
|||
return numberInfo;
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
private boolean rejectCall(@NonNull Context context) {
|
||||
TelephonyManager tm = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
TelecomManager telecomManager = (TelecomManager)
|
||||
context.getSystemService(Context.TELECOM_SERVICE);
|
||||
try {
|
||||
telecomManager.endCall();
|
||||
LOG.info("Rejected call using TelecomManager");
|
||||
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
LOG.warn("Error while rejecting call on API 26+", e);
|
||||
}
|
||||
}
|
||||
|
||||
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
try {
|
||||
Method m = tm.getClass().getDeclaredMethod("getITelephony");
|
||||
m.setAccessible(true);
|
||||
ITelephony telephony = (ITelephony)m.invoke(tm);
|
||||
|
||||
telephony.endCall();
|
||||
LOG.info("Rejected call using ITelephony");
|
||||
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -21,6 +21,9 @@ public class PermissionHelper {
|
|||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
requiredPermissions.add(Manifest.permission.READ_CALL_LOG);
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
requiredPermissions.add(Manifest.permission.ANSWER_PHONE_CALLS);
|
||||
}
|
||||
|
||||
List<String> missingPermissions = new ArrayList<>();
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ Features:
|
|||
|
||||
* Showing a notification with some caller info (positive/negative rating, category, number of negative reviews and such) when the phone's ringing. ''Works offline.''
|
||||
* Loading and displaying a list of reviews for a number. ''Requires internet.''
|
||||
* Automatic blocking of unwanted calls (may not work on some devices; may work as a system app on Android 9; doesn't work on Android 10+). ''Works offline.''
|
||||
* Automatic blocking of unwanted calls (may not work on some devices; doesn't work on Android 10+). ''Works offline.''
|
||||
* Automatic update of the database (for offline use). ''Requires internet.''
|
||||
|
||||
How to use:
|
||||
|
|
Loading…
Reference in New Issue