|
@@ -0,0 +1,521 @@
|
|
|
+package com.xplora.commonservice.modules
|
|
|
+
|
|
|
+import android.annotation.SuppressLint
|
|
|
+import android.app.*
|
|
|
+import android.app.NotificationManager
|
|
|
+import android.content.ComponentName
|
|
|
+import android.content.Context
|
|
|
+import android.content.Intent
|
|
|
+import android.os.Bundle
|
|
|
+import android.os.Handler
|
|
|
+import android.os.Looper
|
|
|
+import android.os.PowerManager
|
|
|
+import android.provider.Settings
|
|
|
+import android.widget.RemoteViews
|
|
|
+import android.widget.Toast
|
|
|
+import androidx.core.app.NotificationCompat
|
|
|
+import androidx.core.app.NotificationManagerCompat
|
|
|
+import androidx.core.graphics.drawable.IconCompat
|
|
|
+import com.xplora.commonservice.BaseApplication
|
|
|
+import com.xplora.commonservice.BaseApplication.Companion.globalContext
|
|
|
+import com.xplora.commonservice.R
|
|
|
+import com.xplora.commonservice.model.ChatMsgType
|
|
|
+import com.xplora.commonservice.model.LocalActions.NOTIFICATION_CHAT
|
|
|
+import com.xplora.commonservice.model.LocalActions.NOTIFICATION_MISSED_CALL
|
|
|
+import com.xplora.commonservice.model.LocalActions.NOTIFICATION_RINGTONE
|
|
|
+import com.xplora.commonservice.model.LocalActions.NOTIFICATION_WATCHFACE
|
|
|
+import com.xplora.commonservice.model.NotificationDetails
|
|
|
+import com.xplora.commonservice.model.database.ChatDbDbEntity
|
|
|
+import com.xplora.commonservice.modules.database.DatabaseManager
|
|
|
+import com.xplora.commonservice.modules.goplay.GoplayContentManager
|
|
|
+import com.xplora.commonservice.ui.activity.EmptyActivity
|
|
|
+import com.xplora.commonservice.ui.activity.OtaCheckActivity
|
|
|
+import java.text.SimpleDateFormat
|
|
|
+import java.util.*
|
|
|
+
|
|
|
+object NotificationManager {
|
|
|
+ var batteryNotifyLevel = -1
|
|
|
+ @SuppressLint("StaticFieldLeak")
|
|
|
+ private val notificationManager: NotificationManagerCompat =
|
|
|
+ NotificationManagerCompat.from(globalContext)
|
|
|
+ private val chatChannel = NotificationChannel(
|
|
|
+ "chat",
|
|
|
+ "xplora chat notification",
|
|
|
+ NotificationManager.IMPORTANCE_DEFAULT
|
|
|
+ )
|
|
|
+
|
|
|
+ private val systemChannel = NotificationChannel(
|
|
|
+ "system",
|
|
|
+ "system notification",
|
|
|
+ NotificationManager.IMPORTANCE_HIGH
|
|
|
+ )
|
|
|
+
|
|
|
+ private val otaChannel = NotificationChannel(
|
|
|
+ "ota",
|
|
|
+ "xplora ota notification",
|
|
|
+ NotificationManager.IMPORTANCE_DEFAULT
|
|
|
+ )
|
|
|
+
|
|
|
+ init {
|
|
|
+ chatChannel.vibrationPattern = longArrayOf(0, 500)
|
|
|
+ chatChannel.enableVibration(true)
|
|
|
+ notificationManager.createNotificationChannel(chatChannel)
|
|
|
+ systemChannel.vibrationPattern = longArrayOf(0, 500)
|
|
|
+ systemChannel.enableVibration(true)
|
|
|
+ notificationManager.createNotificationChannel(systemChannel)
|
|
|
+ otaChannel.vibrationPattern = longArrayOf(0, 500)
|
|
|
+ otaChannel.enableVibration(true)
|
|
|
+ notificationManager.createNotificationChannel(otaChannel)
|
|
|
+ }
|
|
|
+
|
|
|
+ private enum class NotificationTypes {
|
|
|
+ CHAT, BATTERY_LOW, CHARGING, MISSED_CALL, OTA, NEW_RINGTONE, NEW_WATCHFACE
|
|
|
+ }
|
|
|
+
|
|
|
+ private val ids = mapOf(
|
|
|
+ NotificationTypes.CHAT.name to 0x1a,
|
|
|
+ NotificationTypes.BATTERY_LOW.name to 0x1b,
|
|
|
+ NotificationTypes.CHARGING.name to 0x1c,
|
|
|
+ NotificationTypes.MISSED_CALL.name to 0x1d,
|
|
|
+ NotificationTypes.NEW_RINGTONE.name to 0x1e,
|
|
|
+ NotificationTypes.NEW_WATCHFACE.name to 0x1f,
|
|
|
+ NotificationTypes.OTA.name to 0xFF
|
|
|
+ )
|
|
|
+
|
|
|
+ fun showBatteryLowNotify() {
|
|
|
+ val icon = IconCompat.createWithResource(globalContext, R.drawable.ic_notify_battery_low)
|
|
|
+ val details = NotificationDetails(
|
|
|
+ ids[NotificationTypes.BATTERY_LOW.name]!!,
|
|
|
+ "system",
|
|
|
+ globalContext.getString(R.string.package_name_system),
|
|
|
+ globalContext.getColor(R.color.notify_battery_low),
|
|
|
+ globalContext.getString(R.string.battery_low),
|
|
|
+ globalContext.getString(R.string.battery_low),
|
|
|
+ icon
|
|
|
+ )
|
|
|
+ notifyNotification(details)
|
|
|
+ }
|
|
|
+
|
|
|
+ fun cancelBatteryLowNotify() {
|
|
|
+ val icon = IconCompat.createWithResource(globalContext, R.drawable.ic_notify_battery_low)
|
|
|
+ val details = NotificationDetails(
|
|
|
+ ids[NotificationTypes.BATTERY_LOW.name]!!,
|
|
|
+ "system",
|
|
|
+ globalContext.getString(R.string.package_name_system),
|
|
|
+ globalContext.getColor(R.color.notify_battery_low),
|
|
|
+ globalContext.getString(R.string.battery_low),
|
|
|
+ globalContext.getString(R.string.battery_low),
|
|
|
+ icon
|
|
|
+ )
|
|
|
+ cancelNotification(details)
|
|
|
+ }
|
|
|
+
|
|
|
+ fun showChargingNotify() {
|
|
|
+ val icon = IconCompat.createWithResource(globalContext, R.drawable.ic_notify_charging)
|
|
|
+ val details = NotificationDetails(
|
|
|
+ ids[NotificationTypes.CHARGING.name]!!,
|
|
|
+ "system",
|
|
|
+ globalContext.getString(R.string.package_name_system),
|
|
|
+ globalContext.getColor(R.color.notify_charging),
|
|
|
+ globalContext.getString(R.string.charging),
|
|
|
+ globalContext.getString(R.string.charging),
|
|
|
+ icon
|
|
|
+ )
|
|
|
+ notifyNotification(details)
|
|
|
+ cancelBatteryLowNotify()
|
|
|
+ }
|
|
|
+
|
|
|
+ fun cancelChargingNotify() {
|
|
|
+ val icon = IconCompat.createWithResource(globalContext, R.drawable.ic_notify_charging)
|
|
|
+ val details = NotificationDetails(
|
|
|
+ ids[NotificationTypes.CHARGING.name]!!,
|
|
|
+ "system",
|
|
|
+ globalContext.getString(R.string.package_name_system),
|
|
|
+ globalContext.getColor(R.color.notify_charging),
|
|
|
+ globalContext.getString(R.string.charging),
|
|
|
+ globalContext.getString(R.string.charging),
|
|
|
+ icon
|
|
|
+ )
|
|
|
+ cancelNotification(details)
|
|
|
+ }
|
|
|
+
|
|
|
+ fun showChatNotification(chatDbEntity: ChatDbDbEntity) {
|
|
|
+ if (isChat()) return
|
|
|
+ var name = ""
|
|
|
+ for (entity in DatabaseManager.queryContact()) {
|
|
|
+ if (chatDbEntity.senderUserId == entity.userId) {
|
|
|
+ name = entity.name!!
|
|
|
+ }
|
|
|
+ }
|
|
|
+ val content =
|
|
|
+ if (chatDbEntity.type == ChatMsgType.TEXT.toString()) {
|
|
|
+ chatDbEntity.text!!
|
|
|
+ } else {
|
|
|
+ globalContext.getString(R.string.new_msg)
|
|
|
+ }
|
|
|
+ val icon = IconCompat.createWithResource(globalContext, R.drawable.ic_notify_chat)
|
|
|
+
|
|
|
+ val intent = Intent(NOTIFICATION_CHAT)
|
|
|
+ // intent.action = LocalActions.NOTIFICATION_CHAT
|
|
|
+ intent.component = ComponentName(
|
|
|
+ "com.xplora.commonservice",
|
|
|
+ "com.xplora.commonservice.modules.callbacks.NotificationReceiver"
|
|
|
+ )
|
|
|
+ val sender: PendingIntent = PendingIntent.getBroadcast(
|
|
|
+ globalContext,
|
|
|
+ 0,
|
|
|
+ intent,
|
|
|
+ PendingIntent.FLAG_UPDATE_CURRENT
|
|
|
+ )
|
|
|
+ val contacts = DatabaseManager.queryContact()
|
|
|
+ var unreadCount = 0
|
|
|
+ for (contact in contacts) {
|
|
|
+ unreadCount += contact.unRead.toInt()
|
|
|
+ }
|
|
|
+ if (unreadCount >= 2) {
|
|
|
+ name.plus("($unreadCount)")
|
|
|
+ }
|
|
|
+ val detail = NotificationDetails(
|
|
|
+ ids[NotificationTypes.CHAT.name]!!,
|
|
|
+ "chat",
|
|
|
+ globalContext.getString(R.string.package_chat),
|
|
|
+ globalContext.getColor(R.color.notify_chat),
|
|
|
+ name,
|
|
|
+ content,
|
|
|
+ icon,
|
|
|
+ sender
|
|
|
+ )
|
|
|
+ notifyNotification(detail)
|
|
|
+ postToast(globalContext.getString(R.string.new_msg))
|
|
|
+ notifyWatchHome(globalContext.getString(R.string.new_msg))
|
|
|
+ }
|
|
|
+
|
|
|
+ fun cancelChatNotification() {
|
|
|
+ val icon = IconCompat.createWithResource(globalContext, R.drawable.ic_notify_chat)
|
|
|
+ val detail = NotificationDetails(
|
|
|
+ ids[NotificationTypes.CHAT.name]!!,
|
|
|
+ "chat",
|
|
|
+ globalContext.getString(R.string.package_chat),
|
|
|
+ globalContext.getColor(R.color.notify_chat),
|
|
|
+ icon = icon
|
|
|
+ )
|
|
|
+ cancelNotification(detail)
|
|
|
+ }
|
|
|
+
|
|
|
+ fun showOtaNotification() {
|
|
|
+ if (isOtaActivity()) return
|
|
|
+ val title = globalContext.getString(R.string.ota_title)
|
|
|
+ val content = globalContext.getString(R.string.new_available)
|
|
|
+ val icon = IconCompat.createWithResource(globalContext, R.drawable.ic_notify_ota)
|
|
|
+
|
|
|
+ val intent = Intent()
|
|
|
+ intent.component = ComponentName(
|
|
|
+ globalContext.packageName,
|
|
|
+ OtaCheckActivity::class.java.name
|
|
|
+ )
|
|
|
+ val sender: PendingIntent = PendingIntent.getActivity(
|
|
|
+ globalContext,
|
|
|
+ 0,
|
|
|
+ intent,
|
|
|
+ PendingIntent.FLAG_UPDATE_CURRENT
|
|
|
+ )
|
|
|
+ val detail = NotificationDetails(
|
|
|
+ ids[NotificationTypes.OTA.name]!!,
|
|
|
+ "ota",
|
|
|
+ globalContext.getString(R.string.package_name_ota),
|
|
|
+ globalContext.getColor(R.color.notify_ota),
|
|
|
+ title,
|
|
|
+ content,
|
|
|
+ icon,
|
|
|
+ sender
|
|
|
+ )
|
|
|
+ notifyNotification(detail)
|
|
|
+ postToast(globalContext.getString(R.string.new_available))
|
|
|
+ notifyWatchHome(globalContext.getString(R.string.new_available))
|
|
|
+ }
|
|
|
+
|
|
|
+ fun cancelOtaNotification() {
|
|
|
+ val icon = IconCompat.createWithResource(globalContext, R.drawable.ic_notify_ota)
|
|
|
+ val detail = NotificationDetails(
|
|
|
+ ids[NotificationTypes.OTA.name]!!,
|
|
|
+ "ota",
|
|
|
+ globalContext.getString(R.string.package_name_ota),
|
|
|
+ globalContext.getColor(R.color.notify_ota),
|
|
|
+ icon = icon
|
|
|
+ )
|
|
|
+ cancelNotification(detail)
|
|
|
+ }
|
|
|
+
|
|
|
+ fun showMissedCallNotification(number: String) {
|
|
|
+ val contacts = DatabaseManager.queryContact()
|
|
|
+ var name = "UNKNOWN"
|
|
|
+ for (contact in contacts) {
|
|
|
+ if (contact.phoneNumber == number || (contact.phoneNumber!!.length >= 5 && (contact.phoneNumber!!.takeLast(
|
|
|
+ 5
|
|
|
+ ) == number.takeLast(5)))
|
|
|
+ ) {
|
|
|
+ name = contact.name!!
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ val title = name
|
|
|
+ val content = globalContext.getString(R.string.missed_call)
|
|
|
+ val icon = IconCompat.createWithResource(globalContext, R.drawable.ic_notify_missed_call)
|
|
|
+
|
|
|
+ val intent = Intent(NOTIFICATION_MISSED_CALL)
|
|
|
+ intent.putExtra("number", number)
|
|
|
+ // intent.action = LocalActions.NOTIFICATION_CHAT
|
|
|
+ intent.component = ComponentName(
|
|
|
+ "com.xplora.commonservice",
|
|
|
+ "com.xplora.commonservice.modules.callbacks.NotificationReceiver"
|
|
|
+ )
|
|
|
+ val sender: PendingIntent = PendingIntent.getBroadcast(
|
|
|
+ globalContext,
|
|
|
+ 0,
|
|
|
+ intent,
|
|
|
+ PendingIntent.FLAG_UPDATE_CURRENT
|
|
|
+ )
|
|
|
+ val detail = NotificationDetails(
|
|
|
+ ids[NotificationTypes.MISSED_CALL.name]!!,
|
|
|
+ "system",
|
|
|
+ globalContext.getString(R.string.missed_call),
|
|
|
+ globalContext.getColor(R.color.notify_missed_call),
|
|
|
+ title,
|
|
|
+ content,
|
|
|
+ icon,
|
|
|
+ sender
|
|
|
+ )
|
|
|
+ notifyNotification(detail)
|
|
|
+ }
|
|
|
+
|
|
|
+ fun cancelMissedCallNotification() {
|
|
|
+ val icon = IconCompat.createWithResource(globalContext, R.drawable.ic_notify_missed_call)
|
|
|
+ val detail = NotificationDetails(
|
|
|
+ ids[NotificationTypes.MISSED_CALL.name]!!,
|
|
|
+ "system",
|
|
|
+ globalContext.getString(R.string.missed_call_title),
|
|
|
+ globalContext.getColor(R.color.notify_missed_call),
|
|
|
+ icon = icon
|
|
|
+ )
|
|
|
+ cancelNotification(detail)
|
|
|
+ }
|
|
|
+
|
|
|
+ fun showGoplayContentNotification(name: String, type: String) {
|
|
|
+ // if (isInRingtone()) return
|
|
|
+ val id: Int
|
|
|
+ val packageName: String
|
|
|
+ val color: Int
|
|
|
+ val title: String
|
|
|
+ val icon: IconCompat
|
|
|
+ val i: Intent
|
|
|
+ val notifyString: String
|
|
|
+ when (type) {
|
|
|
+ GoplayContentManager.CONTENT_TYPE_RINGTONE -> {
|
|
|
+ id = ids[NotificationTypes.NEW_RINGTONE.name]!!
|
|
|
+ packageName = globalContext.getString(R.string.new_ringtone)
|
|
|
+ color = globalContext.getColor(R.color.notify_ringtone)
|
|
|
+ title = globalContext.getString(R.string.new_ringtone)
|
|
|
+ icon = IconCompat.createWithResource(globalContext, R.drawable.ic_ringtone)
|
|
|
+ i = Intent(NOTIFICATION_RINGTONE)
|
|
|
+ notifyString = globalContext.getString(R.string.new_ringtone)
|
|
|
+ if (!isInRingtone()) postToast(globalContext.getString(R.string.new_ringtone))
|
|
|
+ }
|
|
|
+ GoplayContentManager.CONTENT_TYPE_WATCHFACE -> {
|
|
|
+ id = ids[NotificationTypes.NEW_WATCHFACE.name]!!
|
|
|
+ packageName = globalContext.getString(R.string.new_watchface)
|
|
|
+ color = globalContext.getColor(R.color.notify_watchface)
|
|
|
+ title = globalContext.getString(R.string.new_watchface)
|
|
|
+ icon = IconCompat.createWithResource(globalContext, R.drawable.ic_watchface)
|
|
|
+ i = Intent(NOTIFICATION_WATCHFACE)
|
|
|
+ notifyString = globalContext.getString(R.string.new_watchface)
|
|
|
+ if (!isInWatchface()) postToast(globalContext.getString(R.string.new_watchface))
|
|
|
+ }
|
|
|
+ else -> {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ i.component = ComponentName(
|
|
|
+ "com.xplora.commonservice",
|
|
|
+ "com.xplora.commonservice.modules.callbacks.NotificationReceiver"
|
|
|
+ )
|
|
|
+ val sender: PendingIntent = PendingIntent.getBroadcast(
|
|
|
+ globalContext,
|
|
|
+ 0,
|
|
|
+ i,
|
|
|
+ PendingIntent.FLAG_UPDATE_CURRENT
|
|
|
+ )
|
|
|
+ val detail =
|
|
|
+ NotificationDetails(id, "system", packageName, color, title, name, icon, sender)
|
|
|
+ notifyNotification(detail)
|
|
|
+ notifyWatchHome(notifyString)
|
|
|
+ if (type == GoplayContentManager.CONTENT_TYPE_RINGTONE && (isLauncher() || isInRingtone())) {
|
|
|
+ val ii = Intent(globalContext, EmptyActivity::class.java)
|
|
|
+ ii.putExtra("type", EmptyActivity.TYPE_NEW_RINGTONE)
|
|
|
+ globalContext.startActivity(ii)
|
|
|
+ }
|
|
|
+ if (type == GoplayContentManager.CONTENT_TYPE_WATCHFACE && (isLauncher() || isInWatchface())) {
|
|
|
+ val ii = Intent(globalContext, EmptyActivity::class.java)
|
|
|
+ ii.putExtra("type", EmptyActivity.TYPE_NEW_WATCHFACE)
|
|
|
+ globalContext.startActivity(ii)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ fun cancelRingtoneNotification() {
|
|
|
+ val icon = IconCompat.createWithResource(globalContext, R.drawable.ic_ringtone)
|
|
|
+ val detail = NotificationDetails(
|
|
|
+ ids[NotificationTypes.NEW_RINGTONE.name]!!,
|
|
|
+ "system",
|
|
|
+ globalContext.getString(R.string.new_ringtone),
|
|
|
+ globalContext.getColor(R.color.notify_ringtone),
|
|
|
+ icon = icon
|
|
|
+ )
|
|
|
+ cancelNotification(detail)
|
|
|
+ }
|
|
|
+
|
|
|
+ fun cancelWatchfaceNotification() {
|
|
|
+ val icon = IconCompat.createWithResource(globalContext, R.drawable.ic_watchface)
|
|
|
+ val detail = NotificationDetails(
|
|
|
+ ids[NotificationTypes.NEW_WATCHFACE.name]!!,
|
|
|
+ "system",
|
|
|
+ globalContext.getString(R.string.new_watchface),
|
|
|
+ globalContext.getColor(R.color.notify_watchface),
|
|
|
+ icon = icon
|
|
|
+ )
|
|
|
+ cancelNotification(detail)
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun notifyNotification(detail: NotificationDetails) {
|
|
|
+ val notificationCompatBuilder =
|
|
|
+ NotificationCompat.Builder(globalContext, detail.channelId)
|
|
|
+ .setContentTitle(detail.notificationTitle)
|
|
|
+ .setContentText(detail.notificationText)
|
|
|
+ .setAutoCancel(true)
|
|
|
+
|
|
|
+ val icon: IconCompat = detail.icon
|
|
|
+ notificationCompatBuilder.setSmallIcon(icon)
|
|
|
+
|
|
|
+ val bundle = Bundle()
|
|
|
+ bundle.putString("android.substName", detail.packageName)
|
|
|
+ notificationCompatBuilder.addExtras(bundle)
|
|
|
+ if (Settings.Global.getInt(
|
|
|
+ globalContext.contentResolver,
|
|
|
+ Settings.System.VIBRATE_WHEN_RINGING,
|
|
|
+ 0
|
|
|
+ ) == 0
|
|
|
+ ) {
|
|
|
+ notificationCompatBuilder.setVibrate(null)
|
|
|
+ notificationCompatBuilder.setVibrate(longArrayOf(0))
|
|
|
+ }
|
|
|
+ val forbiddenStatus =
|
|
|
+ Settings.Global.getInt(
|
|
|
+ globalContext.contentResolver,
|
|
|
+ "disable_status",
|
|
|
+ 0
|
|
|
+ )
|
|
|
+ if (forbiddenStatus > 0) {
|
|
|
+ notificationCompatBuilder.setSilent(true)
|
|
|
+ notificationCompatBuilder.setVibrate(longArrayOf(0, 500))
|
|
|
+ }
|
|
|
+
|
|
|
+ val contentView = RemoteViews(globalContext.packageName, R.layout.layout_notification)
|
|
|
+ detail.contentIntent?.let { contentView.setOnClickPendingIntent(R.id.notification, it) }
|
|
|
+ contentView.setImageViewIcon(R.id.icon, detail.icon.toIcon(globalContext))
|
|
|
+ contentView.setTextViewText(R.id.name, detail.packageName)
|
|
|
+ contentView.setTextColor(R.id.name, detail.color!!)
|
|
|
+ val strTimeFormat = Settings.System.getString(
|
|
|
+ globalContext.contentResolver,
|
|
|
+ Settings.System.TIME_12_24
|
|
|
+ )
|
|
|
+ val format = if (strTimeFormat == "24") {
|
|
|
+ SimpleDateFormat("HH:mm")
|
|
|
+ } else {
|
|
|
+ SimpleDateFormat("hh:mm a")
|
|
|
+ }
|
|
|
+ contentView.setTextViewText(
|
|
|
+ R.id.time,
|
|
|
+ format.format(Date())
|
|
|
+ )
|
|
|
+ contentView.setTextViewText(R.id.title, detail.notificationTitle)
|
|
|
+ contentView.setTextViewText(R.id.text, detail.notificationText)
|
|
|
+ notificationCompatBuilder.setContent(contentView)
|
|
|
+ notificationCompatBuilder.setGroupSummary(false)
|
|
|
+ notificationCompatBuilder.setGroup("group")
|
|
|
+
|
|
|
+ val notification = notificationCompatBuilder.build()
|
|
|
+ notification.flags = Notification.FLAG_AUTO_CANCEL
|
|
|
+ notificationManager.notify(detail.id, notification)
|
|
|
+ val mPm =
|
|
|
+ globalContext.getSystemService(Context.POWER_SERVICE) as PowerManager
|
|
|
+ val wl = mPm.newWakeLock(
|
|
|
+ PowerManager.ACQUIRE_CAUSES_WAKEUP or PowerManager.FULL_WAKE_LOCK,
|
|
|
+ "CommonService:Notification"
|
|
|
+ )
|
|
|
+ wl.acquire(1)
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun cancelNotification(detail: NotificationDetails) {
|
|
|
+ notificationManager.cancel(detail.id)
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun notifyWatchHome(content: String) {
|
|
|
+ Settings.Global.putString(globalContext.contentResolver, "new_message", content)
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun postToast(text: String) {
|
|
|
+ if (isLauncher()) return
|
|
|
+ val mPm =
|
|
|
+ globalContext.getSystemService(Context.POWER_SERVICE) as PowerManager
|
|
|
+ val wl = mPm.newWakeLock(
|
|
|
+ PowerManager.ACQUIRE_CAUSES_WAKEUP or PowerManager.FULL_WAKE_LOCK,
|
|
|
+ "NotificationManager:postNotification"
|
|
|
+ )
|
|
|
+ wl.acquire(1000)
|
|
|
+ val handler = Handler(Looper.getMainLooper())
|
|
|
+ handler.post {
|
|
|
+ Toast.makeText(
|
|
|
+ globalContext,
|
|
|
+ text,
|
|
|
+ Toast.LENGTH_SHORT
|
|
|
+ ).show()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun isOtaActivity(): Boolean {
|
|
|
+ val am: ActivityManager =
|
|
|
+ globalContext.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
|
|
|
+ val activityName: String? = am.getRunningTasks(1)[0].topActivity?.className
|
|
|
+ return (activityName == "com.xplora.commonservice.ui.activity.ForceUpdateActivity" ||
|
|
|
+ activityName == "com.xplora.commonservice.ui.activity.OtaCheckActivity" ||
|
|
|
+ activityName == "com.xplora.commonservice.ui.activity.OtaInstallOverNightActivity")
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun isChat(): Boolean {
|
|
|
+ val am: ActivityManager =
|
|
|
+ globalContext.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
|
|
|
+ val packageName: String? = am.getRunningTasks(1)[0].topActivity?.packageName
|
|
|
+ return packageName == "com.xplora.xpchat"
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun isLauncher(): Boolean {
|
|
|
+ val am: ActivityManager =
|
|
|
+ globalContext.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
|
|
|
+ val activityName: String? = am.getRunningTasks(1)[0].topActivity?.className
|
|
|
+ return activityName == "com.xplora.xplauncher.activity.MainActivity" &&
|
|
|
+ Settings.Global.getInt(globalContext.contentResolver, "launcher_home", 0) == 1
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun isInRingtone(): Boolean {
|
|
|
+ val am: ActivityManager =
|
|
|
+ globalContext.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
|
|
|
+ val activityName: String? = am.getRunningTasks(1)[0].topActivity?.className
|
|
|
+ return activityName == "com.xplora.xpsettings.Activity.RingToneActivity"
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun isInWatchface(): Boolean {
|
|
|
+ val am: ActivityManager =
|
|
|
+ globalContext.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
|
|
|
+ val activityName: String? = am.getRunningTasks(1)[0].topActivity?.className
|
|
|
+ return activityName == "com.xplora.xplauncher.activity.FaceSelectActivity"
|
|
|
+ }
|
|
|
+}
|