Commit 29ee864e authored by Your Name's avatar Your Name

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	app/src/main/java/com/zxdemo/notity/NotificationUtils.kt
parents 470a639f c89d55f4
......@@ -11,6 +11,13 @@ public class Global {
public static String FUNCTION_SCREENSHOT = "function_screenshot";
public static String NOTIFICATION_WHERE_UNLOCK = "notification_where_unlock";
public static String NOTIFICATION_WHERE_FCM = "notification_where_fcm";
public static String NOTIFICATION_WHERE_INSTALL = "notification_where_install";
public static String NOTIFICATION_WHERE_TIMBER = "notification_where_timber";
public static String NOTIFICATION_WHERE_BATTERY = "notification_where_battery";
//配置
public static String NotificationStayStatus = "NotificationStayStatus";//int
public static String NotificationStayCount = "NotificationStayCount";//int
......@@ -25,4 +32,6 @@ public class Global {
public static String lockNotificationStatus = "lockNotificationStatus";
public static String batteryNotificationStatus = "batteryNotificationStatus";
public static String NotificationInterval = "notificationInterval";
}
package com.zxdemo.http
import android.util.Log
import com.swiftcleaner.chovey.BuildConfig
import com.zxdemo.ZxApplication
......@@ -21,7 +22,6 @@ object ZxHttp {
var referrer = ""
var referrerSp = SpUtils.getInstance().getString("referrer", "")
if (referrerSp.isNotEmpty()) {
// referrer = Base64.getEncoder().encodeToString(referrer.toByteArray())
referrer = android.util.Base64.encodeToString(referrer.toByteArray(), android.util.Base64.DEFAULT)
}
......@@ -85,6 +85,7 @@ object ZxHttp {
requestBack.invoke(1)
e.printStackTrace()
}
override fun onResponse(call: Call, response: Response) {
// 请求成功时的处理逻辑
try {
......@@ -115,12 +116,11 @@ object ZxHttp {
}
fun getHttpReportInterface(action: String, value: String, ext: JSONObject?) {
var bp = DeviceUtils.getConfigParms()
// val url = "https://rp.swiftdevinc.xyz/jsonsp?pkg=${com.zxdemo.ZxApplication.packname}"
val bp = DeviceUtils.getConfigParms()
val url = "$REPORT_DOMAIN/jsonsp?pkg=${ZxApplication.packname}"
var json = JSONObject()
val json = JSONObject()
json.put("bp", bp)
var jData = JSONObject()
val jData = JSONObject()
jData.put("action", action)
if (value.isNotEmpty()) {
jData.put("value", value)
......@@ -130,7 +130,7 @@ object ZxHttp {
Log.d("TAG", "getHttpReportInterface: $json")
var result = AESUtils.encrypt(json.toString())
val result = AESUtils.encrypt(json.toString())
HttpUtils.postJson(url, result, object : Callback {
override fun onFailure(call: Call, e: IOException) {
......
......@@ -13,10 +13,9 @@ import android.os.HandlerThread
import android.util.Log
import android.widget.RemoteViews
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.ContextCompat
import com.swiftcleaner.chovey.BuildConfig
import com.swiftcleaner.chovey.R
import com.swiftcleaner.chovey.model.bean.Global
import com.swiftcleaner.chovey.model.bean.Global.FUNCTION_APP_MANAGER
import com.swiftcleaner.chovey.model.bean.Global.FUNCTION_APP_PROCESS
import com.swiftcleaner.chovey.model.bean.Global.FUNCTION_BATTERY
......@@ -25,17 +24,15 @@ import com.swiftcleaner.chovey.model.bean.Global.FUNCTION_LARGE_FILE
import com.swiftcleaner.chovey.model.bean.Global.FUNCTION_SCREENSHOT
import com.swiftcleaner.chovey.model.bean.Global.FUNCTION_SIMILAR_PHOTOS
import com.swiftcleaner.chovey.model.bean.Global.FUNCTION_WHATS_APP
import com.swiftcleaner.chovey.model.bean.Global.NotificationInterval
import com.swiftcleaner.chovey.model.bean.Global.NotificationStayCount
import com.swiftcleaner.chovey.model.bean.Global.NotificationStayDelay
import com.swiftcleaner.chovey.model.bean.Global.NotificationStayStatus
import com.swiftcleaner.chovey.view.MainActivity
import com.swiftcleaner.chovey.view.activity.StartActivity
import com.zxdemo.ZxApplication.Companion.isAppInForeground
import com.zxdemo.ZxApplication.Companion.isDeviceLocked
import com.zxdemo.ZxApplication.Companion.isScreenOn
import com.zxdemo.ZxApplication
import com.zxdemo.admob.ReportAdUtils
import com.zxdemo.http.ZxHttp
import com.zxdemo.utils.SpUtils
import java.util.Random
......@@ -125,18 +122,16 @@ object NotificationUtils {
}
val actionId = nextNotificationId
val intervalTime = System.currentTimeMillis() - lastNotificationTime
val spInterval = SpUtils.getInstance().getInt("NotificationInterval", 1)
val oneMinute = 1 * 60 * 1000L
val intervalTime = System.currentTimeMillis() - lastNotificationTime
val spInterval = SpUtils.getInstance().getInt(NotificationInterval, 1)
Log.e("sendNotification", "where=$where actionId=$actionId intervalTime=$intervalTime spInterval=$spInterval")
if (lastNotificationTime != 0L && intervalTime < spInterval * oneMinute) {
return
}
val bigRemoteViews = RemoteViews(context.packageName, R.layout.notification_common)
val smallRemoteViews = RemoteViews(context.packageName, R.layout.notification_common_small)
var intentAction = ""
when (actionId) {
FUNCTION_CLEAN -> {
bigRemoteViews.setImageViewResource(R.id.iv_icon, R.mipmap.h_cleanjunk)
......@@ -146,73 +141,93 @@ object NotificationUtils {
val descsmall = "Swift Cleaner - Phone Helper"
bigRemoteViews.setTextViewText(R.id.tv_desc, desc)
smallRemoteViews.setTextViewText(R.id.tv_desc, desc)
smallRemoteViews.setTextViewText(R.id.tv_desc, descsmall)
intentAction = Global.FUNCTION_CLEAN
}
FUNCTION_APP_MANAGER -> {
bigRemoteViews.setImageViewResource(R.id.iv_icon, R.mipmap.h_appmanager)
smallRemoteViews.setImageViewResource(R.id.iv_icon, R.mipmap.h_appmanager)
val desc = "Smart App Management."
smallRemoteViews.setImageViewResource(R.id.iv_icon, R.mipmap.logox)
val descsmall = "Swift Cleaner - Phone Helper"
val desc = "Clean out junk files to free up space on your phone!"
bigRemoteViews.setTextViewText(R.id.tv_desc, desc)
smallRemoteViews.setTextViewText(R.id.tv_desc, desc)
smallRemoteViews.setTextViewText(R.id.tv_desc, descsmall)
intentAction = Global.FUNCTION_APP_MANAGER
}
FUNCTION_BATTERY -> {
bigRemoteViews.setImageViewResource(R.id.iv_icon, R.mipmap.h_batteryinfo)
smallRemoteViews.setImageViewResource(R.id.iv_icon, R.mipmap.h_batteryinfo)
val desc = "Watch your battery info!"
smallRemoteViews.setImageViewResource(R.id.iv_icon, R.mipmap.logox)
val descsmall = "Swift Cleaner - Phone Helper"
val desc = "Clean out junk files to free up space on your phone!"
bigRemoteViews.setTextViewText(R.id.tv_desc, desc)
smallRemoteViews.setTextViewText(R.id.tv_desc, desc)
smallRemoteViews.setTextViewText(R.id.tv_desc, descsmall)
intentAction = Global.FUNCTION_BATTERY
}
FUNCTION_LARGE_FILE -> {
bigRemoteViews.setImageViewResource(R.id.iv_icon, R.mipmap.h_large)
smallRemoteViews.setImageViewResource(R.id.iv_icon, R.mipmap.h_large)
val desc = "Clean out large files to free up space on your phone!"
smallRemoteViews.setImageViewResource(R.id.iv_icon, R.mipmap.logox)
val descsmall = "Swift Cleaner - Phone Helper"
val desc = "Clean out junk files to free up space on your phone!"
bigRemoteViews.setTextViewText(R.id.tv_desc, desc)
smallRemoteViews.setTextViewText(R.id.tv_desc, desc)
smallRemoteViews.setTextViewText(R.id.tv_desc, descsmall)
intentAction = Global.FUNCTION_LARGE_FILE
}
FUNCTION_WHATS_APP-> {
FUNCTION_WHATS_APP -> {
bigRemoteViews.setImageViewResource(R.id.iv_icon, R.mipmap.h_whatsapp)
smallRemoteViews.setImageViewResource(R.id.iv_icon, R.mipmap.h_whatsapp)
val desc = "Clean out whatsapp files to free up space on your phone!"
smallRemoteViews.setImageViewResource(R.id.iv_icon, R.mipmap.logox)
val descsmall = "Swift Cleaner - Phone Helper"
val desc = "Clean out junk files to free up space on your phone!"
bigRemoteViews.setTextViewText(R.id.tv_desc, desc)
smallRemoteViews.setTextViewText(R.id.tv_desc, desc)
smallRemoteViews.setTextViewText(R.id.tv_desc, descsmall)
intentAction = Global.FUNCTION_WHATS_APP
}
FUNCTION_APP_PROCESS -> {
bigRemoteViews.setImageViewResource(R.id.iv_icon, R.mipmap.jg__appprocss)
smallRemoteViews.setImageViewResource(R.id.iv_icon, R.mipmap.jg__appprocss)
val desc = "Smart App Process."
smallRemoteViews.setImageViewResource(R.id.iv_icon, R.mipmap.logox)
val descsmall = "Swift Cleaner - Phone Helper"
val desc = "Clean out junk files to free up space on your phone!"
bigRemoteViews.setTextViewText(R.id.tv_desc, desc)
smallRemoteViews.setTextViewText(R.id.tv_desc, desc)
smallRemoteViews.setTextViewText(R.id.tv_desc, descsmall)
intentAction = Global.FUNCTION_APP_PROCESS
}
FUNCTION_SIMILAR_PHOTOS -> {
bigRemoteViews.setImageViewResource(R.id.iv_icon, R.mipmap.h_simiar)
smallRemoteViews.setImageViewResource(R.id.iv_icon, R.mipmap.h_simiar)
val desc = "Clean out similar files to free up space on your phone!"
smallRemoteViews.setImageViewResource(R.id.iv_icon, R.mipmap.logox)
val descsmall = "Swift Cleaner - Phone Helper"
val desc = "Clean out junk files to free up space on your phone!"
bigRemoteViews.setTextViewText(R.id.tv_desc, desc)
smallRemoteViews.setTextViewText(R.id.tv_desc, desc)
smallRemoteViews.setTextViewText(R.id.tv_desc, descsmall)
intentAction = Global.FUNCTION_SIMILAR_PHOTOS
}
FUNCTION_SCREENSHOT -> {
bigRemoteViews.setImageViewResource(R.id.iv_icon, R.mipmap.h_screenshot)
smallRemoteViews.setImageViewResource(R.id.iv_icon, R.mipmap.h_screenshot)
val desc = "Clean out screen files to free up space on your phone!"
smallRemoteViews.setImageViewResource(R.id.iv_icon, R.mipmap.logox)
val descsmall = "Swift Cleaner - Phone Helper"
val desc = "Clean out junk files to free up space on your phone!"
bigRemoteViews.setTextViewText(R.id.tv_desc, desc)
smallRemoteViews.setTextViewText(R.id.tv_desc, desc)
smallRemoteViews.setTextViewText(R.id.tv_desc, descsmall)
intentAction = Global.FUNCTION_SCREENSHOT
}
else -> {
......@@ -222,14 +237,14 @@ object NotificationUtils {
val flag = PendingIntent.FLAG_IMMUTABLE
val btnRequestCode = Random().nextInt(1000)
val intent = Intent(context, StartActivity::class.java)
intent.putExtra("actionId", intentAction)
intent.putExtra("actionId", actionId)
val btnPendingIntent = PendingIntent.getActivity(context, btnRequestCode, intent, flag)
bigRemoteViews.setOnClickPendingIntent(R.id.fl_btn, btnPendingIntent)
smallRemoteViews.setOnClickPendingIntent(R.id.tv_btn, btnPendingIntent)
val open = SpUtils.getInstance().getInt(NotificationStayStatus, 0)
if (open == 1) {
// notificationHover(context, intent, bigRemoteViews, smallRemoteViews)
notificationHover(context, intent, bigRemoteViews, smallRemoteViews)
} else {
sendNotification(
context,
......@@ -268,14 +283,16 @@ object NotificationUtils {
private var currentNotificationIdIndex = -1
private val nextNotificationId: String
get() {
// 将当前通知 ID 索引加 1
currentNotificationIdIndex++
// 如果当前通知 ID 索引超出列表范围,则将其重置为 0
if (currentNotificationIdIndex >= NOTIFICATION_IDS.size) {
currentNotificationIdIndex = 0
}
// 返回下一个通知 ID
return NOTIFICATION_IDS[currentNotificationIdIndex]
// // 将当前通知 ID 索引加 1
// currentNotificationIdIndex++
// // 如果当前通知 ID 索引超出列表范围,则将其重置为 0
// if (currentNotificationIdIndex >= NOTIFICATION_IDS.size) {
// currentNotificationIdIndex = 0
// }
// // 返回下一个通知 ID
// return NOTIFICATION_IDS[currentNotificationIdIndex]
return NOTIFICATION_IDS.random()
}
}
......@@ -6,6 +6,7 @@ import android.content.Intent
import android.content.IntentFilter
import android.os.Build
import android.util.Log
import com.swiftcleaner.chovey.model.bean.Global.NOTIFICATION_WHERE_INSTALL
import com.zxdemo.notity.NotificationUtils
import com.zxdemo.utils.SpUtils
import java.time.LocalDateTime
......@@ -33,28 +34,6 @@ class AppInstallReceiver : BroadcastReceiver() {
}
override fun onReceive(context: Context, intent: Intent) {
//获取当前时间和上一次推送的时间
var current = LocalDateTime.now()
val intervalTime = 1L //间隔时间(分钟)
val lastTime =
SpUtils.getInstance().getString("NOTICE_APP_TIME", "")
var parsedDateTime: LocalDateTime = current
if (lastTime != "") {
parsedDateTime =
LocalDateTime.parse(lastTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"))
}
// 计算两个时间点之间的差异
val minutesBetween = ChronoUnit.MINUTES.between(parsedDateTime, current)
if (minutesBetween >= intervalTime || minutesBetween.toInt() == 0) {
intent.action?.let {
Log.d("TAG", "onReceive:安装卸载推送 ${intent.action}")
NotificationUtils.sendNotification(context, "AppInstallReceiver")
SpUtils.getInstance().putString(
"NOTICE_APP_TIME",
current.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"))
)
}
}
NotificationUtils.sendNotification(context, NOTIFICATION_WHERE_INSTALL)
}
}
......@@ -5,6 +5,8 @@ import android.content.Context
import android.content.Intent
import android.os.BatteryManager
import android.util.Log
import com.swiftcleaner.chovey.model.bean.Global.NOTIFICATION_WHERE_BATTERY
import com.swiftcleaner.chovey.model.bean.Global.NOTIFICATION_WHERE_INSTALL
import com.swiftcleaner.chovey.model.bean.Global.batteryNotificationStatus
import com.zxdemo.notity.NotificationUtils
import com.zxdemo.utils.SpUtils
......@@ -34,9 +36,8 @@ class BatteryStatusReceiver() : BroadcastReceiver() {
&&
state == BatteryManager.BATTERY_STATUS_CHARGING
) {
Log.d("TAG", "onReceive: 电池推送")
if (context != null) {
NotificationUtils.sendNotification(context, "BatteryStatusReceiver")
NotificationUtils.sendNotification(context, NOTIFICATION_WHERE_BATTERY)
}
}
}
......
......@@ -2,10 +2,8 @@ package com.zxdemo.receiver
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.util.Log
class FcmReceiver : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
Log.d("TAG", "onReceive:$intent ")
}
}
\ No newline at end of file
......@@ -6,6 +6,7 @@ import android.content.Intent
import android.content.IntentFilter
import android.os.Build
import android.util.Log
import com.swiftcleaner.chovey.model.bean.Global.NOTIFICATION_WHERE_UNLOCK
import com.swiftcleaner.chovey.model.bean.Global.lockNotificationStatus
import com.zxdemo.ZxApplication
import com.zxdemo.notity.NotificationUtils
......@@ -54,7 +55,7 @@ class UnlockReceiver : BroadcastReceiver() {
//获取当前时间和上一次推送的时间
if (lockNotificationStatus == 1 && mIsScreenOn && !isLock) {
NotificationUtils.sendNotification(ZxApplication.context, "UnlockReceiver")
NotificationUtils.sendNotification(ZxApplication.context, NOTIFICATION_WHERE_UNLOCK)
}
}
......
package com.zxdemo.service
import android.util.Log
import android.annotation.SuppressLint
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import com.swiftcleaner.chovey.model.bean.Global.NOTIFICATION_WHERE_FCM
import com.zxdemo.ZxApplication
import com.zxdemo.http.ZxHttp
import com.zxdemo.notity.NotificationUtils
@SuppressLint("MissingFirebaseInstanceTokenRefresh")
class FcmService : FirebaseMessagingService() {
override fun onMessageReceived(message: RemoteMessage) {
Log.d("TAG", "onMessageReceived: ${message.data}")
ZxHttp.getHttpReportInterface("FCM_Received", "", null)
NotificationUtils.sendNotification(ZxApplication.context, "FcmService")
NotificationUtils.sendNotification(ZxApplication.context, NOTIFICATION_WHERE_FCM)
}
}
\ No newline at end of file
package com.zxdemo.utils
import android.util.Log
import com.swiftcleaner.chovey.model.bean.Global.NOTIFICATION_WHERE_TIMBER
import com.zxdemo.ZxApplication.Companion.isAppInForeground
import com.zxdemo.ZxApplication.Companion.isDeviceLocked
import com.zxdemo.ZxApplication.Companion.isScreenOn
......@@ -31,11 +32,8 @@ object GlobalTimer {
taskTimer = Timer() // 创建新的 Timer 实例
val task = object : TimerTask() {
override fun run() {
Log.d("glc", "Scheduled task is running")
Log.d("glc", "${!isDeviceLocked} ${!isAppInForeground} $isScreenOn")
// 确保设备处于交互状态,未锁定,且应用未暂停
NotificationUtils.sendNotification(ZxApplication.context, "GlobalTimer")
NotificationUtils.sendNotification(ZxApplication.context, NOTIFICATION_WHERE_TIMBER)
}
}
taskTimer!!.schedule(task, delay, period) // 调度任务
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment