mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-06-05 21:49:23 +02:00
Merge pull request #446 from Naveen3Singh/callCounterFix
Properly clear missed calls on start
This commit is contained in:
@ -2,7 +2,6 @@ package com.simplemobiletools.dialer.activities
|
|||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.app.SearchManager
|
import android.app.SearchManager
|
||||||
import android.content.ContentValues
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.ShortcutInfo
|
import android.content.pm.ShortcutInfo
|
||||||
@ -12,7 +11,6 @@ import android.graphics.drawable.Icon
|
|||||||
import android.graphics.drawable.LayerDrawable
|
import android.graphics.drawable.LayerDrawable
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.provider.CallLog
|
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
@ -301,7 +299,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
wantedTab = main_tabs_holder.tabCount - 1
|
wantedTab = main_tabs_holder.tabCount - 1
|
||||||
|
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
resetMissedCalls()
|
clearMissedCalls()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -450,21 +448,14 @@ class MainActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// clear the missed calls count. Doesn't seem to always work, but having it can't hurt
|
@SuppressLint("MissingPermission")
|
||||||
// found at https://android.googlesource.com/platform/packages/apps/Dialer/+/nougat-release/src/com/android/dialer/calllog/MissedCallNotifier.java#181
|
private fun clearMissedCalls() {
|
||||||
private fun resetMissedCalls() {
|
|
||||||
val values = ContentValues().apply {
|
|
||||||
put(CallLog.Calls.NEW, 0)
|
|
||||||
put(CallLog.Calls.IS_READ, 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
val selection = "${CallLog.Calls.TYPE} = ?"
|
|
||||||
val selectionArgs = arrayOf(CallLog.Calls.MISSED_TYPE.toString())
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val uri = CallLog.Calls.CONTENT_URI
|
// notification cancellation triggers MissedCallNotifier.clearMissedCalls() which, in turn,
|
||||||
contentResolver.update(uri, values, selection, selectionArgs)
|
// should update the database and reset the cached missed call count in MissedCallNotifier.java
|
||||||
} catch (e: Exception) {
|
// https://android.googlesource.com/platform/packages/services/Telecomm/+/master/src/com/android/server/telecom/ui/MissedCallNotifierImpl.java#170
|
||||||
|
telecomManager.cancelMissedCallsNotification()
|
||||||
|
} catch (ignored: Exception) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user