-
-
Notifications
You must be signed in to change notification settings - Fork 582
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2031 from marunjar/incoming_calls_in_history
implement call screening service
- Loading branch information
Showing
6 changed files
with
79 additions
and
12 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
40 changes: 40 additions & 0 deletions
40
app/src/main/java/fr/neamar/kiss/broadcast/IncomingCallScreeningService.java
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,40 @@ | ||
package fr.neamar.kiss.broadcast; | ||
|
||
import android.content.SharedPreferences; | ||
import android.os.Build; | ||
import android.preference.PreferenceManager; | ||
import android.telecom.Call; | ||
import android.telecom.CallScreeningService; | ||
import android.text.TextUtils; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.RequiresApi; | ||
|
||
import fr.neamar.kiss.DataHandler; | ||
import fr.neamar.kiss.KissApplication; | ||
import fr.neamar.kiss.dataprovider.ContactsProvider; | ||
import fr.neamar.kiss.pojo.ContactsPojo; | ||
|
||
@RequiresApi(api = Build.VERSION_CODES.N) | ||
public class IncomingCallScreeningService extends CallScreeningService { | ||
|
||
@Override | ||
public void onScreenCall(@NonNull Call.Details callDetails) { | ||
respondToCall(callDetails, new CallResponse.Builder().build()); | ||
|
||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); | ||
if (prefs.getBoolean("enable-phone-history", false) && callDetails.getHandle() != null) { | ||
String phoneNumber = callDetails.getHandle().getSchemeSpecificPart(); | ||
if (!TextUtils.isEmpty(phoneNumber)) { | ||
DataHandler dataHandler = KissApplication.getApplication(this).getDataHandler(); | ||
ContactsProvider contactsProvider = dataHandler.getContactsProvider(); | ||
if (contactsProvider != null) { | ||
ContactsPojo contactPojo = contactsProvider.findByPhone(phoneNumber); | ||
if (contactPojo != null) { | ||
dataHandler.addToHistory(contactPojo.getHistoryId()); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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