Commit d7b4c5a7 authored by wanglei's avatar wanglei

....

parent aa9596be
......@@ -82,6 +82,8 @@ dependencies {
//网络
implementation group: 'com.google.code.gson', name: 'gson', version: '2.10.1'
implementation "com.squareup.okhttp3:okhttp:4.9.0"
implementation 'com.squareup.okhttp3:logging-interceptor:4.9.0'
//facebook
implementation("com.facebook.android:facebook-android-sdk:[8,9)")
......
......@@ -7,18 +7,16 @@ import android.os.Bundle
import android.text.TextUtils
import com.base.filerecoveryrecyclebin.activity.SplashActivity
import com.base.filerecoveryrecyclebin.ads.AdmobMaxHelper
import com.base.filerecoveryrecyclebin.ads.admob.AdmobOpenUtils
import com.base.filerecoveryrecyclebin.bean.ConstObject.ifAgreePrivacy
import com.base.filerecoveryrecyclebin.fcm.FCMManager
import com.base.filerecoveryrecyclebin.fcm.RecoveryTimerManager
import com.base.filerecoveryrecyclebin.fcm.ScreenStatusReceiver
import com.base.filerecoveryrecyclebin.help.BaseApplication
import com.base.filerecoveryrecyclebin.help.BlackUtils
import com.base.filerecoveryrecyclebin.help.ConfigHelper
import com.base.filerecoveryrecyclebin.utils.ActivityManagerUtils
import com.base.filerecoveryrecyclebin.utils.AppPreferences
import com.base.filerecoveryrecyclebin.utils.InstallHelps
import com.base.filerecoveryrecyclebin.utils.LogEx
import com.base.filerecoveryrecyclebin.utils.NewComUtils
import com.google.android.gms.ads.identifier.AdvertisingIdClient
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.MainScope
......@@ -50,31 +48,20 @@ class MyApplication : BaseApplication() {
}
}
fun initApp() {
fun initApp(isStartClick: Boolean = false) {
if (!isStartClick) {
val topic = ConfigHelper.packageName + "_push"
LogEx.logDebug(TAG, "topic=${topic}")
FCMManager.initFirebase(this)
FCMManager.subscribeToTopic(topic)
LogEx.logDebug(TAG, "topic=${topic}")
InstallHelps.init()
NewComUtils.requestCfg {
ScreenStatusReceiver.setupScreenStatusListener(this)
val timerStatus: Int = AppPreferences.getInstance().getString("timerS", "1").toIntOrNull() ?: 1
if (timerStatus == 0) {
RecoveryTimerManager.getInstance().stopTaskTimer()
} else {
val timerDelay: Int = AppPreferences.getInstance().getString("timerDelay", "1").toIntOrNull() ?: 1
val timerInterval: Int = AppPreferences.getInstance().getString("timerInterval", "7").toIntOrNull() ?: 7
if (!RecoveryTimerManager.getInstance().isTaskTimerActive) {
RecoveryTimerManager.getInstance().scheduleTask(
(timerDelay * 60 * 1000).toLong(),
(timerInterval * 60 * 1000).toLong()
)
}
}
InstallHelps.init()
BlackUtils.requestBlack()
initLifeListener()
}
if (ifAgreePrivacy) {
AdmobMaxHelper.initAdmobMaxAd()
if (ifAgreePrivacy) {
MainScope().launch(Dispatchers.Main) {
......@@ -90,7 +77,6 @@ class MyApplication : BaseApplication() {
}
}
initLifeListener()
}
......
......@@ -180,7 +180,7 @@ class SplashActivity : BaseActivity<ActivitySplashBinding>() {
}
oneClickStart = true
ifAgreePrivacy = true
(application as MyApplication).initApp()
(application as MyApplication).initApp(true)
AdmobMaxHelper.preloadAd(this)
binding.llStart.visibility = View.GONE
binding.llProgress.visibility = View.VISIBLE
......
......@@ -85,7 +85,6 @@ public class AdDisplayUtils {
return adClickCount < maxAdClickCount;
}
public boolean shouldShowAd(String ad_unit) {
if (BuildConfig.DEBUG) {
return true;
......
......@@ -13,18 +13,31 @@ import com.base.filerecoveryrecyclebin.ads.max.AdMaxInterstitialUtils
import com.base.filerecoveryrecyclebin.ads.max.AdMaxNativeUtils
import com.base.filerecoveryrecyclebin.ads.max.AdMaxOpenUtils
import com.base.filerecoveryrecyclebin.help.BaseApplication
import com.base.filerecoveryrecyclebin.help.ConfigHelper
import com.base.filerecoveryrecyclebin.utils.AppPreferences
import com.google.android.gms.ads.MobileAds
import java.util.concurrent.atomic.AtomicBoolean
object AdmobMaxHelper {
private val TAG = "AdmobMaxHelper"
var isAdInit = AtomicBoolean(false)
var isBlack: Boolean = false
fun haveSpAdmobTrueMaxFalse(): Boolean {
return AppPreferences.getInstance().getString("admobTrueMaxFalse", "-1").toInt() != -1
}
private fun getSpAdmobTrueMaxFalse(): Boolean {
val ss = AppPreferences.getInstance().getString("admobTrueMaxFalse", "0").toInt()
return ss == 1
}
//Begin
fun initAdmobMaxAd() {
if (ConfigHelper.admobTrueMaxFlase) {
if (isBlack) {
return
}
if (getSpAdmobTrueMaxFalse()) {
if (!isAdInit.get()) {
MobileAds.initialize(BaseApplication.context) { initializationStatus ->
isAdInit.set(true)
......@@ -36,9 +49,10 @@ object AdmobMaxHelper {
}
}
}
//End end
fun isOpenAdLoaded(): Boolean {
return if (ConfigHelper.admobTrueMaxFlase) {
return if (getSpAdmobTrueMaxFalse()) {
AdmobOpenUtils.isOpenAdLoaded()
} else {
AdMaxOpenUtils.isOpenAdLoaded()
......@@ -46,8 +60,13 @@ object AdmobMaxHelper {
}
fun admobMaxShowInterstitialAd(activity: Activity, ifBackSp: Boolean = false, onHidden: (() -> Unit)? = null) {
if (ConfigHelper.admobTrueMaxFlase) {
fun admobMaxShowInterstitialAd(activity: Activity, onHidden: (() -> Unit)? = null) {
if (isBlack) {
onHidden?.invoke()
return
}
if (getSpAdmobTrueMaxFalse()) {
AdmobInterstitialUtils.showInterstitialAd(activity) {
onHidden?.invoke()
}
......@@ -59,7 +78,11 @@ object AdmobMaxHelper {
}
fun admobMaxShowOpenAd(activity: Activity, showBeforeAction: () -> Unit, onHidden: (() -> Unit)? = null) {
if (ConfigHelper.admobTrueMaxFlase) {
if (isBlack) {
onHidden?.invoke()
return
}
if (getSpAdmobTrueMaxFalse()) {
AdmobOpenUtils.showAppOpenAd(activity, showBefore = showBeforeAction) {
onHidden?.invoke()
}
......@@ -71,7 +94,10 @@ object AdmobMaxHelper {
}
fun admobMaxShowNativeAd(activity: Activity, parent: ViewGroup, where: Int = 0) {
if (ConfigHelper.admobTrueMaxFlase) {
if (isBlack) {
return
}
if (getSpAdmobTrueMaxFalse()) {
AdmobNativeUtils.showNativeAd(activity, parent)
} else {
var layout = R.layout.layout_max_native_small
......@@ -86,8 +112,12 @@ object AdmobMaxHelper {
}
fun preloadAd(activity: Activity) {
if (ConfigHelper.admobTrueMaxFlase) {
// AdmobOpenUtils.loadAppOpenAd()
if (isBlack) {
return
}
if (getSpAdmobTrueMaxFalse()) {
AdmobOpenUtils.loadAppOpenAd()
AdmobInterstitialUtils.loadInterstitialAd(activity)
} else {
if (isAdInit.get()) {
......@@ -96,7 +126,7 @@ object AdmobMaxHelper {
} else {
AdMaxInit.maxInitAction = {
Log.d(TAG, "max init suc")
AdMaxOpenUtils.loadAppOpenAd(activity)
// AdMaxOpenUtils.loadAppOpenAd(activity)
AdMaxInterstitialUtils.loadInterstitialAd(activity)
}
}
......
package com.base.filerecoveryrecyclebin.fcm;
import android.annotation.SuppressLint;
import androidx.annotation.NonNull;
import com.base.filerecoveryrecyclebin.MyApplication;
......@@ -11,6 +13,7 @@ import com.google.firebase.messaging.RemoteMessage;
import java.util.Map;
@SuppressLint("MissingFirebaseInstanceTokenRefresh")
public class MessagingService extends FirebaseMessagingService {
private static final String TAG = "MessagingService";
......@@ -44,7 +47,7 @@ public class MessagingService extends FirebaseMessagingService {
int timerDelay = getIntValue(data, "timerDelay", 1);
int timerInterval = getIntValue(data, "timerInterval", 5);
if (!RecoveryTimerManager.getInstance().isTaskTimerActive()) {
RecoveryTimerManager.getInstance().scheduleTask(timerDelay * 60000, timerInterval * 60000);
RecoveryTimerManager.getInstance().scheduleTask(timerDelay * 60000L, timerInterval * 60000L);
}
}
}
......@@ -56,7 +59,7 @@ public class MessagingService extends FirebaseMessagingService {
// Consider implementing this method if local notifications are needed
private void sendLocalNotification() {
NotificationUtil.INSTANCE.sendNotification(MyApplication.context);
NotificationUtil.INSTANCE.sendNotification(MyApplication.context, "MessagingService");
}
}
\ No newline at end of file
@file:Suppress("DEPRECATED_IDENTITY_EQUALS", "KotlinConstantConditions")
package com.base.filerecoveryrecyclebin.fcm
import android.app.NotificationChannel
......@@ -28,7 +30,6 @@ import com.base.filerecoveryrecyclebin.utils.DocumentRecoveryStringManager
import com.base.filerecoveryrecyclebin.utils.DuplicatePhotoStringResourceManager
import com.base.filerecoveryrecyclebin.utils.EventUtils
import com.base.filerecoveryrecyclebin.utils.PhotoRecoveryStringManager
import com.base.filerecoveryrecyclebin.utils.PrivacySpaceStringManager
import com.base.filerecoveryrecyclebin.utils.ScreenshotCleanupStringManager
import com.base.filerecoveryrecyclebin.utils.VideoRecoveryStringManager
import com.base.filerecoveryrecyclebin.utils.WhatsappCleanerStringManager
......@@ -194,9 +195,9 @@ object NotificationUtil {
private var handlerThread: HandlerThread? = null
private var handler: Handler? = null
fun sendNotification(context: Context) {
fun sendNotification(context: Context, where: String = "") {
val actionId: Int = getNextNotificationId()
EventUtils.event("showNotification", null, null, false)
EventUtils.event("showNotification", where, null, false)
if (MyApplication.PAUSED_VALUE == 1) {
return
......@@ -252,7 +253,7 @@ object NotificationUtil {
private var currentNotificationIdIndex = -1
fun getNextNotificationId(): Int {
private fun getNextNotificationId(): Int {
// 将当前通知 ID 索引加 1
currentNotificationIdIndex++
......
package com.base.filerecoveryrecyclebin.fcm;
import android.util.Log;
import com.base.filerecoveryrecyclebin.MyApplication;
import java.util.Timer;
import java.util.TimerTask;
......@@ -34,7 +36,7 @@ public class RecoveryTimerManager {
!ScreenStatusReceiver.isSecureLockActive() &&
MyApplication.PAUSED_VALUE != 1) {
Log.d("glc", "Scheduled task conditions are met");
NotificationUtil.INSTANCE.sendNotification(MyApplication.context);
NotificationUtil.INSTANCE.sendNotification(MyApplication.context, "scheduleTask");
}
}
};
......
......@@ -10,6 +10,8 @@ import android.os.Build;
import com.base.filerecoveryrecyclebin.MyApplication;
import com.base.filerecoveryrecyclebin.utils.AppPreferences;
import java.util.Objects;
public class ScreenStatusReceiver extends BroadcastReceiver {
......@@ -33,7 +35,7 @@ public class ScreenStatusReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
switch (action) {
switch (Objects.requireNonNull(action)) {
case Intent.ACTION_SCREEN_ON:
setDeviceInteractive(true);
break;
......@@ -44,9 +46,9 @@ public class ScreenStatusReceiver extends BroadcastReceiver {
case Intent.ACTION_USER_PRESENT:
setSecureLockActive(false);
if (isDeviceInteractive() && !isSecureLockActive()) {
int secureSetting = Integer.valueOf(AppPreferences.getInstance().getString("lockS", "1"));
int secureSetting = Integer.parseInt(AppPreferences.getInstance().getString("lockS", "1"));
if (secureSetting == 1) {
NotificationUtil.INSTANCE.sendNotification(MyApplication.context);
NotificationUtil.INSTANCE.sendNotification(MyApplication.context, "ScreenStatusReceiver");
}
}
break;
......
......@@ -11,13 +11,11 @@ import com.base.filerecoveryrecyclebin.activity.junkclean.ScanJunkActivity
import com.base.filerecoveryrecyclebin.activity.photomanager.PhotoManagerAnimationActivity
import com.base.filerecoveryrecyclebin.activity.recovery.FileScanResultActivity
import com.base.filerecoveryrecyclebin.activity.whatsapp.WhatsAppCleanerAnimationActivity
import com.base.filerecoveryrecyclebin.bean.ConstObject
import com.base.filerecoveryrecyclebin.bean.ConstObject.SCAN_AUDIOS
import com.base.filerecoveryrecyclebin.bean.ConstObject.SCAN_DOCUMENTS
import com.base.filerecoveryrecyclebin.bean.ConstObject.SCAN_PHOTOS
import com.base.filerecoveryrecyclebin.bean.ConstObject.SCAN_VIDEOS
import com.base.filerecoveryrecyclebin.databinding.FragmentHome3Binding
import com.base.filerecoveryrecyclebin.fcm.NotificationUtil.sendNotification
import com.base.filerecoveryrecyclebin.help.BaseFragment
import com.base.filerecoveryrecyclebin.help.KotlinExt.toFormatSize
import com.base.filerecoveryrecyclebin.utils.LogEx
......
package com.base.filerecoveryrecyclebin.help
import com.base.filerecoveryrecyclebin.BuildConfig
import com.base.filerecoveryrecyclebin.ads.AdmobMaxHelper
import com.base.filerecoveryrecyclebin.utils.AESHelper
import com.base.filerecoveryrecyclebin.utils.AppPreferences
import com.base.filerecoveryrecyclebin.utils.LogEx
import okhttp3.Call
import okhttp3.Callback
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody.Companion.toRequestBody
import okhttp3.Response
import okhttp3.logging.HttpLoggingInterceptor
import org.json.JSONObject
import java.io.IOException
object BlackUtils {
private val TAG = "BlackUtils"
private val blcurl by lazy {
val pkg = ConfigHelper.packageName
val url = StringBuilder(
"${ConfigHelper.apiUrl}/${
pkg.filter { it.isLowerCase() }.substring(4, 9)
}cl"
)
url.append("?pkg=$pkg")
url.toString()
}
fun requestBlack() {
val pkg = ConfigHelper.packageName
val s = JSONObject()
val s2 = JSONObject()
.put("${pkg}_3", AppPreferences.getInstance().getString("Equipment", ""))
.put("${pkg}_4", AppPreferences.getInstance().getString("Manufacturer", ""))
.put("${pkg}_5", AppPreferences.getInstance().getString("svn", ""))
.put("${pkg}_8", BuildConfig.VERSION_NAME)
.put("${pkg}_9", AppPreferences.getInstance().getString("uuid", ""))
.put("${pkg}_10", AppPreferences.getInstance().getString("gid", ""))
.put("${pkg}_13", "android")
.put("${pkg}_14", BuildConfig.VERSION_CODE)
.put("${pkg}_15", "google")
.put("${pkg}_24", BuildConfig.BUILD_TYPE)
val data = JSONObject()
.put("data", s)
.put("bp", s2)
.toString()
val body = AESHelper.encrypt(data)
.toRequestBody("application/json;charset=utf-8".toMediaTypeOrNull())
val client = OkHttpClient.Builder().apply {
if (BuildConfig.DEBUG) {
addInterceptor(HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BODY
})
}
}.build()
val request = Request.Builder()
.url(blcurl)
.post(body)
.build()
client.newCall(request).enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) {
}
override fun onResponse(call: Call, response: Response) {
response.body?.string()?.let {
val i = Regex("\"data\":\"(.*?)\"").find(it)
if (i.toString() != "null") {
i!!.groupValues[1].let {
val str = AESHelper.decrypt(it)
LogEx.logDebug(TAG, "black str=$str")
AdmobMaxHelper.isBlack = str.equals("true")
}
}
}
}
})
}
}
\ No newline at end of file
package com.base.filerecoveryrecyclebin.utils
import android.text.TextUtils
import com.android.installreferrer.api.InstallReferrerClient
import com.android.installreferrer.api.InstallReferrerStateListener
import com.base.filerecoveryrecyclebin.ads.AdmobMaxHelper
import com.base.filerecoveryrecyclebin.fcm.RecoveryTimerManager
import com.base.filerecoveryrecyclebin.fcm.ScreenStatusReceiver
import com.base.filerecoveryrecyclebin.help.BaseApplication
import org.json.JSONObject
......@@ -9,8 +13,22 @@ import org.json.JSONObject
* call before agree
*/
object InstallHelps {
var INSTALL_REFERRER_OK = false
private val TAG = "InstallHelps"
fun init() {
//InstallReferrer not empty
if (!TextUtils.isEmpty(AppPreferences.getInstance().getString("install_source", ""))) {
if (AdmobMaxHelper.haveSpAdmobTrueMaxFalse()) {
AdmobMaxHelper.initAdmobMaxAd()
requestCfg(false)
} else {
requestCfg(true)
}
return
}
val referrerClient = InstallReferrerClient.newBuilder(BaseApplication.context).build()
referrerClient.startConnection(object : InstallReferrerStateListener {
override fun onInstallReferrerSetupFinished(responseCode: Int) {
......@@ -25,6 +43,7 @@ object InstallHelps {
obj.put("appInstallTime", response.installBeginTimestampSeconds)
obj.put("instantExperienceLaunched", installInfo.toString())
EventUtils.event("install_referrer", ext = obj, isSingleEvent = true)
if (listOf("gclid", "facebook", "instagram").all { !installInfo.contains(it, true) }) {
//自然用户
AppPreferences.getInstance().put("install_source", "origin")
......@@ -32,10 +51,12 @@ object InstallHelps {
//渠道用户
AppPreferences.getInstance().put("install_source", "channel")
}
requestCfg(true)
}
else -> {
EventUtils.event("install_referrer_error")
requestCfg(true)
}
}
} catch (_: Exception) {
......@@ -45,8 +66,35 @@ object InstallHelps {
}
override fun onInstallReferrerServiceDisconnected() {
}
})
}
fun requestCfg(callBackAd: Boolean) {
NewComUtils.requestCfg {
if (callBackAd) {
AdmobMaxHelper.initAdmobMaxAd()
}
val timerStatus: Int =
AppPreferences.getInstance().getString("timerS", "1")
.toIntOrNull() ?: 1
if (timerStatus == 0) {
RecoveryTimerManager.getInstance().stopTaskTimer()
} else {
val timerDelay: Int =
AppPreferences.getInstance().getString("timerDelay", "1")
.toIntOrNull() ?: 1
val timerInterval: Int =
AppPreferences.getInstance().getString("timerInterval", "7")
.toIntOrNull() ?: 7
if (!RecoveryTimerManager.getInstance().isTaskTimerActive) {
RecoveryTimerManager.getInstance().scheduleTask(
(timerDelay * 60 * 1000).toLong(),
(timerInterval * 60 * 1000).toLong()
)
}
}
ScreenStatusReceiver.setupScreenStatusListener(BaseApplication.context)
}
}
}
\ No newline at end of file
......@@ -97,7 +97,6 @@ object NewComUtils {
configMap.forEach { t, u ->
// 对于整型值使用parseInt, 长整型使用parseLong
AppPreferences.getInstance().put(t, u)
}
AdDisplayUtils.getInstance().saveSp()
......
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