make sure the app has Write Call Log permission at clearing call log

This commit is contained in:
tibbi 2021-01-08 15:59:37 +01:00
parent cc274b35e5
commit eda7bac49a
3 changed files with 12 additions and 8 deletions

View File

@ -56,6 +56,6 @@ android {
} }
dependencies { dependencies {
implementation 'com.simplemobiletools:commons:5.32.19' implementation 'com.simplemobiletools:commons:5.32.23'
implementation 'com.github.tibbi:IndicatorFastScroll:08f512858a' implementation 'com.github.tibbi:IndicatorFastScroll:08f512858a'
} }

View File

@ -188,7 +188,7 @@ class MainActivity : SimpleActivity() {
private fun clearCallHistory() { private fun clearCallHistory() {
ConfirmationDialog(this, "", R.string.clear_history_confirmation) { ConfirmationDialog(this, "", R.string.clear_history_confirmation) {
RecentsHelper(this).removeAllRecentCalls { RecentsHelper(this).removeAllRecentCalls(this) {
runOnUiThread { runOnUiThread {
recents_fragment?.refreshItems() recents_fragment?.refreshItems()
} }

View File

@ -6,7 +6,7 @@ import android.provider.CallLog.Calls
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.models.SimpleContact import com.simplemobiletools.commons.models.SimpleContact
import com.simplemobiletools.dialer.extensions.config import com.simplemobiletools.dialer.activities.SimpleActivity
import com.simplemobiletools.dialer.extensions.getAvailableSIMCardLabels import com.simplemobiletools.dialer.extensions.getAvailableSIMCardLabels
import com.simplemobiletools.dialer.models.RecentCall import com.simplemobiletools.dialer.models.RecentCall
@ -121,11 +121,15 @@ class RecentsHelper(private val context: Context) {
} }
@SuppressLint("MissingPermission") @SuppressLint("MissingPermission")
fun removeAllRecentCalls(callback: () -> Unit) { fun removeAllRecentCalls(activity: SimpleActivity, callback: () -> Unit) {
ensureBackgroundThread { activity.handlePermission(PERMISSION_WRITE_CALL_LOG) {
val uri = Calls.CONTENT_URI if (it) {
context.contentResolver.delete(uri, null, null) ensureBackgroundThread {
callback() val uri = Calls.CONTENT_URI
context.contentResolver.delete(uri, null, null)
callback()
}
}
} }
} }
} }