-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
129 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package ilchev.stefan.callblocker; | ||
|
||
import android.os.Build; | ||
import android.telecom.Call; | ||
import android.telecom.CallScreeningService; | ||
import android.util.Log; | ||
|
||
public class CallService extends CallScreeningService { | ||
|
||
private static final String TAG = "CallService"; | ||
|
||
private static void endCall(CallResponse.Builder builder) { | ||
builder.setDisallowCall(true) | ||
.setRejectCall(true) | ||
.setSkipNotification(true); | ||
} | ||
|
||
@Override | ||
public void onScreenCall(Call.Details callDetails) { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && | ||
callDetails.getCallDirection() != Call.Details.DIRECTION_INCOMING) { | ||
return; | ||
} | ||
var builder = new CallResponse.Builder(); | ||
try (AutoCloseable ignored = () -> respondToCall(callDetails, builder.build())) { | ||
var phoneNumber = callDetails.getHandle().getSchemeSpecificPart(); | ||
var sharedPreferences = getSharedPreferences(BuildConfig.APPLICATION_ID, MODE_PRIVATE); | ||
var callBlocker = new CallBlocker(sharedPreferences); | ||
if (callBlocker.isBlocked(phoneNumber)) { | ||
endCall(builder); | ||
CallReceiver.notifyBlockedCall(this, phoneNumber); | ||
} | ||
} catch (Throwable t) { | ||
Log.w(TAG, t); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters