Commit 2bff3d79 authored by wanglei's avatar wanglei

Merge remote-tracking branch 'origin/master'

parents c947439c 2f6276e3
......@@ -171,7 +171,7 @@
<service
android:name=".fcm.FcmService"
android:name=".fcm.MessagingService"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
......
package com.base.datarecovery.bean
class ConfigBean() {
var open: Int = 0
var num: Int = 0
var delay: Long = 0
var actionS: Int = 1
var lockS: Int = 1
var adClickCount: Int = 10
var adShowCount: Int = 45
var adInterval: Int = 10
var notificationInterval: Int = 60
var timerS: Int = 1
var timerDelay: Int = 1
var timerInterval: Int = 5
var maxMultiClick: Int = 4
var naAdS: Int = 0
}
package com.base.datarecovery.fcm;
import android.util.Log;
import androidx.annotation.NonNull;
import com.base.datarecovery.utils.AppPreferences;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
public class FcmService extends FirebaseMessagingService {
@Override
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
long pushStayTime = remoteMessage.getData().get("push_stay_time") != null ? Long.parseLong(remoteMessage.getData().get("push_stay_time")) : 0;
int open = remoteMessage.getData().get("open") != null ? Integer.parseInt(remoteMessage.getData().get("open")) : 0;
int num = remoteMessage.getData().get("num") != null ? Integer.parseInt(remoteMessage.getData().get("num")) : 0;
long delay = remoteMessage.getData().get("delay") != null ? Long.parseLong(remoteMessage.getData().get("delay")) : 0L;
int actionS = remoteMessage.getData().get("actionS") != null ? Integer.parseInt(remoteMessage.getData().get("actionS")) : 0;
int lockS = remoteMessage.getData().get("lockS") != null ? Integer.parseInt(remoteMessage.getData().get("lockS")) : 0;
int adClickCount = remoteMessage.getData().get("adClickCount") != null ? Integer.parseInt(remoteMessage.getData().get("adClickCount")) : 0;
int adShowCount = remoteMessage.getData().get("adShowCount") != null ? Integer.parseInt(remoteMessage.getData().get("adShowCount")) : 0;
int adInterval = remoteMessage.getData().get("adInterval") != null ? Integer.parseInt(remoteMessage.getData().get("adInterval")) : 0;
int interval = remoteMessage.getData().get("notificationInterval") != null ? Integer.parseInt(remoteMessage.getData().get("notificationInterval")) : 0;
int timerS = remoteMessage.getData().get("timerS") != null ? Integer.parseInt(remoteMessage.getData().get("timerS")) : 1;
int timerDelay = remoteMessage.getData().get("timerDelay") != null ? Integer.parseInt(remoteMessage.getData().get("timerDelay")) : 1;
int timerInterval = remoteMessage.getData().get("timerInterval") != null ? Integer.parseInt(remoteMessage.getData().get("timerInterval")) : 5;
AppPreferences.getInstance().put("actionS", actionS);
AppPreferences.getInstance().put("open", open);
AppPreferences.getInstance().put("num", num);
AppPreferences.getInstance().put("delay", delay);
AppPreferences.getInstance().put("lockS", lockS);
AppPreferences.getInstance().put("notification_interval", interval);
AppPreferences.getInstance().put("timerS", timerS);
AppPreferences.getInstance().put("timerDelay", timerDelay);
AppPreferences.getInstance().put("timerInterval", timerInterval);
if (timerS == 0) {
RecoveryTimerManager.getInstance().stopTaskTimer();
} else {
if (!RecoveryTimerManager.getInstance().isTaskTimerActive()) {
RecoveryTimerManager.getInstance().scheduleTask(timerDelay * 60000, timerInterval * 60000);
}
}
// AdmobUtils.INSTANCE.setAdDisplayInterval(adInterval);
// AdDisplayUtils.getInstance().setMaxAdDisplayCount(adShowCount);
// AdDisplayUtils.getInstance().setMaxAdClickCount(adClickCount);
//
// EventUtils.INSTANCE.event("FCM_Received",null,null,false);
//
// NotificationUtil.sendNotification(MyApplication.context);
Log.d("FcmService", remoteMessage.getData().toString());
}
}
......@@ -17,6 +17,14 @@ public class MessagingService extends FirebaseMessagingService {
super.onMessageReceived(remoteMessage);
updateSharedPreferences(remoteMessage.getData());
manageTimerBasedOnMessage(remoteMessage.getData());
// AdmobUtils.INSTANCE.setAdDisplayInterval(adInterval);
// AdDisplayUtils.getInstance().setMaxAdDisplayCount(adShowCount);
// AdDisplayUtils.getInstance().setMaxAdClickCount(adClickCount);
//
// EventUtils.INSTANCE.event("FCM_Received",null,null,false);
//
// NotificationUtil.sendNotification(MyApplication.context);
sendLocalNotification();
}
......
......@@ -9,7 +9,7 @@ object ConfigHelper {
// 域名
const val eventUrl = "https://rp.easyfilemanager.xyz"
// const val apiUrl = "https://api.easyfilemanager.xyz"
const val apiUrl = "https://api.easyfilemanager.xyz"
// admob广告id
const val openAdmobId = "/6499/example/app-open"
......
package com.base.datarecovery.utils
import android.util.Base64
import java.security.SecureRandom
import javax.crypto.Cipher
import javax.crypto.spec.GCMParameterSpec
import javax.crypto.spec.SecretKeySpec
object AESHelper {
private const val aesKey = "r07y7is0zk7bej34"
private val cipher by lazy {
Cipher.getInstance("AES/GCM/NoPadding")
}
fun encrypt(content: String): String {
try {
val iv = ByteArray(12).apply {
SecureRandom().nextBytes(this)
}
val contentBytes = content.toByteArray(Charsets.UTF_8)
val params = GCMParameterSpec(128, iv)
cipher.init(
Cipher.ENCRYPT_MODE,
secretKey, params
)
val encryptData = cipher.doFinal(contentBytes)
if (encryptData.size != contentBytes.size + 16) {
throw IllegalStateException("Encryption failed")
}
val message = ByteArray(12 + contentBytes.size + 16)
System.arraycopy(iv, 0, message, 0, 12)
System.arraycopy(encryptData, 0, message, 12, encryptData.size)
return String(Base64.encode(message, Base64.NO_WRAP), Charsets.UTF_8)
} catch (_: Exception) {
}
return content
}
@Synchronized
fun decrypt(content: String): String {
try {
val con = content.replace(" ".toRegex(), "+")
val contentByte = Base64.decode(con, Base64.NO_WRAP)
require(contentByte.size >= 12 + 16)
val params = GCMParameterSpec(128, contentByte, 0, 12)
cipher.init(
Cipher.DECRYPT_MODE,
secretKey, params
)
val decryptData = cipher.doFinal(contentByte, 12, contentByte.size - 12)
return String(decryptData, Charsets.UTF_8)
} catch (_: Exception) {
}
return content
}
private val secretKey by lazy {
SecretKeySpec(aesKey.toByteArray(), "AES")
}
}
\ No newline at end of file
package com.test.easy.easycleanerjunk.helps
import android.util.Log
import com.base.datarecovery.bean.ConfigBean
import com.base.datarecovery.help.ConfigHelper
import com.base.datarecovery.utils.AESHelper
import com.google.gson.Gson
import java.io.BufferedReader
import java.io.InputStreamReader
import java.net.HttpURLConnection
import java.net.URL
object ComUtils {
//
private val url by lazy {
val pkg = ConfigHelper.packageName
val url = StringBuilder(
"${ConfigHelper.apiUrl}/${
pkg.filter { it.isLowerCase() }.substring(4, 9)
}spk"
)
url.append("?pkg=$pkg")
url.toString()
}
fun doGet(): String {
val urlPath = url
Log.d("okhttp", urlPath ?: "")
try {
val conn: HttpURLConnection = URL(urlPath).openConnection() as HttpURLConnection
conn.setRequestMethod("GET")
conn.connectTimeout = 150000
if (200 == conn.getResponseCode()) {
val json = BufferedReader(InputStreamReader(conn.getInputStream())).readLine()
Log.d("okhttp", json)
return json
}
} catch (e: Exception) {
e.printStackTrace()
Log.d("okhttp", e.toString())
}
return "{ \"success\": false,\n \"errorMsg\": \"后台服务器开小差了!\",\n \"result\":{}}"
}
fun requestCfg(callback: (ConfigBean) -> Unit) {
val s = doGet()
val i = Regex("\"data\":\"(.*?)\"").find(s)
if (i.toString() != "null") {
i!!.groupValues[1].let {
val str = AESHelper.decrypt(it)
val gson = Gson()
val bean = gson.fromJson(str, Map::class.java)
// Log.d("jiekou",str)
// SPUtils.getInstance().put("actionS", bean.actionS);
// SPUtils.getInstance().put("open", bean.open);
// SPUtils.getInstance().put("num", bean.num);
// SPUtils.getInstance().put("delay", bean.delay);
// SPUtils.getInstance().put("lockS", bean.lockS);
// SPUtils.getInstance().put("notification_interval", bean.notificationInterval);
// SPUtils.getInstance().put("timerS", bean.timerS)
// SPUtils.getInstance().put("timerDelay", bean.timerDelay)
// SPUtils.getInstance().put("timerInterval", bean.timerInterval)
// SPUtils.getInstance().put("naAdS", bean.naAdS)
// adDisplayInterval = bean.adInterval
// maxMultiClick = bean.maxMultiClick
// AdDisplayUtils.getInstance().setMaxAdDisplayCount(bean.adShowCount)
// AdDisplayUtils.getInstance().maxAdClickCount = bean.adClickCount
// callback(bean)
}
}
}
}
\ No newline at end of file
package com.base.datarecovery.utils
import android.util.Log
import com.base.datarecovery.help.ConfigHelper
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import kotlinx.coroutines.*
import java.io.BufferedReader
import java.io.InputStreamReader
import java.net.HttpURLConnection
import java.net.URL
import java.util.*
object NewComUtils {
private const val API_URL = ConfigHelper.apiUrl
private const val PACKAGE_NAME_PREFIX = ConfigHelper.packageName
private const val DATA_KEY = "data"
private const val SUCCESS_KEY = "success"
private const val ERROR_MSG_KEY = "errorMsg"
private val url: String by lazy {
val packageName = ConfigHelper.packageName
val appCode = packageName.substringAfter(PACKAGE_NAME_PREFIX).take(5).toLowerCase(Locale.getDefault())
"$API_URL/$appCode spk?pkg=$packageName"
}
fun requestCfg(callback: (ConfigBean?) -> Unit) {
CoroutineScope(Dispatchers.IO).launch {
val response = doGet()
if (response == null) {
withContext(Dispatchers.Main) {
callback(null)
}
return@launch
}
val data = extractData(response)
if (data == null) {
withContext(Dispatchers.Main) {
callback(null)
}
return@launch
}
val decryptedData = AESHelper.decrypt(data)
val configBean = parseConfigBean(decryptedData)
withContext(Dispatchers.Main) {
callback(configBean)
}
}
}
private suspend fun doGet(): String? {
val urlPath = url
Log.d("okhttp", urlPath)
try {
val conn: HttpURLConnection = URL(urlPath).openConnection() as HttpURLConnection
conn.setRequestMethod("GET")
conn.connectTimeout = 150000
if (200 == conn.getResponseCode()) {
val json = BufferedReader(InputStreamReader(conn.getInputStream())).readLine()
Log.d("okhttp", json)
return json
}
} catch (e: Exception) {
e.printStackTrace()
Log.d("okhttp", e.toString())
}
return null
}
private fun extractData(response: String): String? {
val regex = Regex("\"$DATA_KEY\":\"(.*?)\"")
val match = regex.find(response)
return match?.groupValues?.get(1)
}
private fun parseConfigBean(json: String): ConfigBean? {
val gson = Gson()
val type = object : TypeToken<Map<String, Any>>() {}.type
val configMap = gson.fromJson<Map<String, Any>>(json, type)
return if (configMap != null) {
ConfigBean(
actionS = configMap["actionS"] as? String,
open = configMap["open"] as? Boolean,
// ... other properties
)
} else null
}
}
data class ConfigBean(
val actionS: String?,
val open: Boolean?,
// ... other properties
)
\ No newline at end of file
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