|
|
|
@ -9,6 +9,8 @@ import androidx.work.OneTimeWorkRequestBuilder
|
|
|
|
|
import androidx.work.WorkManager
|
|
|
|
|
import androidx.work.workDataOf
|
|
|
|
|
import com.google.gson.Gson
|
|
|
|
|
import com.idormy.sms.forwarder.core.Core
|
|
|
|
|
import com.idormy.sms.forwarder.database.entity.Rule
|
|
|
|
|
import com.idormy.sms.forwarder.entity.MsgInfo
|
|
|
|
|
import com.idormy.sms.forwarder.utils.PACKAGE_NAME
|
|
|
|
|
import com.idormy.sms.forwarder.utils.SettingUtils
|
|
|
|
@ -20,14 +22,11 @@ import java.util.*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Suppress("PrivatePropertyName", "DEPRECATION")
|
|
|
|
|
class NotifyService : NotificationListenerService()/*, LifecycleOwner*/ {
|
|
|
|
|
class NotifyService : NotificationListenerService() {
|
|
|
|
|
|
|
|
|
|
/*private val mRegistry = LifecycleRegistry(this)*/
|
|
|
|
|
private val TAG: String = "NotifyService"
|
|
|
|
|
|
|
|
|
|
override fun onListenerConnected() {
|
|
|
|
|
//super.onListenerConnected()
|
|
|
|
|
// Check if Notification Listener Permission is allowed
|
|
|
|
|
Log.d(TAG, "onListenerConnected")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -81,37 +80,32 @@ class NotifyService : NotificationListenerService()/*, LifecycleOwner*/ {
|
|
|
|
|
if (TextUtils.isEmpty(title) && TextUtils.isEmpty(text)) return
|
|
|
|
|
|
|
|
|
|
val msgInfo = MsgInfo("app", from, text, Date(), title, -1)
|
|
|
|
|
val request = OneTimeWorkRequestBuilder<SendWorker>()
|
|
|
|
|
.setInputData(
|
|
|
|
|
workDataOf(
|
|
|
|
|
Worker.sendMsgInfo to Gson().toJson(msgInfo),
|
|
|
|
|
//Worker.sendSbnId to sbn.id
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
.build()
|
|
|
|
|
WorkManager.getInstance(applicationContext).enqueue(request)
|
|
|
|
|
|
|
|
|
|
//TODO:收不到返回信息,自动消除待解决
|
|
|
|
|
/*WorkManager.getInstance(context).getWorkInfoByIdLiveData(request.id)
|
|
|
|
|
.observe(this) { info: WorkInfo? ->
|
|
|
|
|
Log.e(TAG, info.toString())
|
|
|
|
|
if (info != null && info.state == WorkInfo.State.SUCCEEDED) {
|
|
|
|
|
//TODO:自动消除通知(临时方案,重复查询换取准确性)
|
|
|
|
|
if (SettingUtils.enableCancelAppNotify) {
|
|
|
|
|
val ruleList: List<Rule> = Core.rule.getRuleList(msgInfo.type, 1, "SIM0")
|
|
|
|
|
for (rule in ruleList) {
|
|
|
|
|
if (rule.checkMsg(msgInfo)) {
|
|
|
|
|
Log.d(TAG, "自动消除通知")
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
|
|
cancelNotification(sbn.key)
|
|
|
|
|
} else {
|
|
|
|
|
cancelNotification(sbn.packageName, sbn.tag, sbn.id)
|
|
|
|
|
}
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
//自动消除全部通知(临时方案)
|
|
|
|
|
if (SettingUtils.enableCancelAppNotify) {
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
|
|
cancelNotification(sbn.key)
|
|
|
|
|
} else {
|
|
|
|
|
cancelNotification(sbn.packageName, sbn.tag, sbn.id)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val request = OneTimeWorkRequestBuilder<SendWorker>()
|
|
|
|
|
.setInputData(
|
|
|
|
|
workDataOf(
|
|
|
|
|
Worker.sendMsgInfo to Gson().toJson(msgInfo),
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
.build()
|
|
|
|
|
WorkManager.getInstance(applicationContext).enqueue(request)
|
|
|
|
|
|
|
|
|
|
} catch (e: Exception) {
|
|
|
|
|
Log.e(TAG, "Parsing Notification failed: " + e.message.toString())
|
|
|
|
|
}
|
|
|
|
@ -119,11 +113,7 @@ class NotifyService : NotificationListenerService()/*, LifecycleOwner*/ {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onNotificationRemoved(sbn: StatusBarNotification?) {
|
|
|
|
|
//super.onNotificationRemoved(sbn)
|
|
|
|
|
Log.d(TAG, "Removed Package Name : ${sbn?.packageName}")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*override fun getLifecycle(): Lifecycle {
|
|
|
|
|
return mRegistry
|
|
|
|
|
}*/
|
|
|
|
|
}
|