Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
A
appzxhy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wanglei
appzxhy
Commits
57e27536
Commit
57e27536
authored
Jun 11, 2025
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[商业化]修改请求配置解析的问题,ump,请求配置回调
parent
a3f1b488
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
211 additions
and
161 deletions
+211
-161
MyApplication.kt
app/src/main/java/com/base/appzxhy/MyApplication.kt
+37
-67
AdConfigBean.kt
...rc/main/java/com/base/appzxhy/bean/config/AdConfigBean.kt
+1
-0
AdsMgr.kt
app/src/main/java/com/base/appzxhy/business/ads/AdsMgr.kt
+1
-1
NewComUtils.kt
...main/java/com/base/appzxhy/business/helper/NewComUtils.kt
+127
-57
SplashActivity.kt
...rc/main/java/com/base/appzxhy/ui/splash/SplashActivity.kt
+42
-19
SplashViewModel.kt
...c/main/java/com/base/appzxhy/ui/splash/SplashViewModel.kt
+2
-2
UmpUtils.kt
app/src/main/java/com/base/appzxhy/utils/UmpUtils.kt
+1
-15
No files found.
app/src/main/java/com/base/appzxhy/MyApplication.kt
View file @
57e27536
...
...
@@ -7,7 +7,6 @@ import android.content.Intent
import
android.os.Bundle
import
android.text.TextUtils
import
android.util.Log
import
com.base.appzxhy.business.helper.EventUtils
import
com.base.appzxhy.business.helper.InstallHelps
import
com.base.appzxhy.business.helper.NewComUtils
import
com.base.appzxhy.business.service.StayJobService.Companion.startStayJobService
...
...
@@ -18,18 +17,13 @@ import com.base.appzxhy.utils.SolarEngineUtils.initSolarEngine
import
com.base.appzxhy.utils.SolarEngineUtils.solarkey
import
com.facebook.FacebookSdk
import
com.google.android.gms.ads.identifier.AdvertisingIdClient
import
com.google.gson.Gson
import
com.hjq.language.MultiLanguages
import
com.hjq.language.OnLanguageListener
import
com.reyun.solar.engine.SolarEngineManager
import
org.json.JSONObject
import
java.util.Locale
import
java.util.UUID
import
com.base.appzxhy.SpConstObject.appLanguageSp
import
com.base.appzxhy.SpConstObject.appLanguageCountrySp
import
com.base.appzxhy.bean.config.AdConfigBean
import
com.base.appzxhy.bean.config.ConfigBean
import
com.base.appzxhy.bean.config.PopupConfigBean
import
com.base.appzxhy.business.ads.AdsMgr
import
com.base.appzxhy.business.helper.NewComUtils.spConfig
import
com.base.appzxhy.business.push.fcm.FCMManager
...
...
@@ -44,7 +38,6 @@ import com.facebook.appevents.AppEventsLogger
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.MainScope
import
kotlinx.coroutines.launch
import
kotlinx.coroutines.withContext
class
MyApplication
:
Application
()
{
...
...
@@ -74,10 +67,11 @@ class MyApplication : Application() {
appContext
=
this
// initUUid()
// initGid()
// initApp()
// initLanguage()
initUUid
()
initGid
()
initApp
()
initLifeListener
()
initLanguage
()
}
...
...
@@ -125,17 +119,35 @@ class MyApplication : Application() {
fun
initApp
()
{
kotlin
.
runCatching
{
startStayJobService
()
}
//初始化广告相关业务
AdsMgr
.
init
(
appContext
)
initPush
()
initAppConfig
()
initFacebook
()
initSolar
()
}
private
fun
initSolar
()
{
SolarEngineManager
.
getInstance
().
preInit
(
this
,
solarkey
)
appContext
.
initSolarEngine
(
true
)
}
private
fun
initFacebook
()
{
//初始化facebook sdk
FacebookSdk
.
sdkInitialize
(
applicationContext
)
AppEventsLogger
.
activateApp
(
this
)
}
private
fun
initPush
()
{
kotlin
.
runCatching
{
startStayJobService
()
}
// val token = AppPreferences.getInstance().getString("token", "")
val
topic
=
GlobalConfig
.
PACKAGE_NAME
+
"_push"
...
...
@@ -143,12 +155,7 @@ class MyApplication : Application() {
FCMManager
.
initFirebase
(
this
)
FCMManager
.
subscribeToTopic
(
topic
)
initAppConfig
()
SolarEngineManager
.
getInstance
().
preInit
(
this
,
solarkey
)
initLifeListener
()
changeTimer
()
ScreenStatusReceiver
.
registerScreenStatusReceiver
(
this
)
// PackageStatusReceiver.registerPackageStatusReceiver(this)
registerBatteryReceiver
(
this
)
...
...
@@ -162,16 +169,20 @@ class MyApplication : Application() {
//开启通知队列
MyNotificationManager
.
startNotificationQueue
()
appContext
.
initSolarEngine
(
true
)
}
private
fun
initAppConfig
()
{
initConfig
()
//初始化sp的配置
NewComUtils
.
parseConfigBean
(
spConfig
)
NewComUtils
.
requestCfgCallBackMap
.
put
(
"changeTimer"
)
{
LogEx
.
logDebug
(
TAG
,
"requestCfgCallBackMap changeTimer"
)
changeTimer
()
}
InstallHelps
.
init
{
initRemoteConfi
g
()
NewComUtils
.
requestCf
g
()
}
}
...
...
@@ -240,46 +251,5 @@ class MyApplication : Application() {
})
}
private
fun
initRemoteConfig
()
{
NewComUtils
.
requestCfg
{
config
->
LogEx
.
logDebug
(
"requestCfg"
,
"config=$config"
)
if
(
config
!=
null
)
{
initConfig
(
config
)
}
else
{
EventUtils
.
event
(
"configNull"
)
}
}
}
private
fun
initConfig
(
config
:
String
=
spConfig
)
=
MainScope
().
launch
(
Dispatchers
.
IO
)
{
if
(
config
.
isEmpty
())
return
@launch
// kotlin.runCatching {
val
configBean
=
Gson
().
fromJson
(
config
,
ConfigBean
::
class
.
java
)
val
jsonObject
=
JSONObject
()
jsonObject
.
put
(
"ut"
,
configBean
.
ut
)
EventUtils
.
event
(
"user_type"
,
ext
=
jsonObject
)
//配置
ConfigBean
.
configBean
=
configBean
//广告
AdConfigBean
.
adsConfigBean
=
configBean
.
adConfigBean
LogEx
.
logDebug
(
"initConfig"
,
"adsConfigBean=${configBean.adConfigBean.functionInShowAd}"
)
//通知配置
PopupConfigBean
.
popupConfigBean
=
configBean
.
popupConfigBean
LogEx
.
logDebug
(
"initConfig"
,
"popupConfigBean=${configBean.popupConfigBean.popupCount}"
)
//启动定时器
changeTimer
()
// }
}
}
\ No newline at end of file
app/src/main/java/com/base/appzxhy/bean/config/AdConfigBean.kt
View file @
57e27536
...
...
@@ -18,6 +18,7 @@ class AdConfigBean(
var
functionBackShowAd
:
Boolean
=
true
,
//功能退出显示广告
var
functionInShowAd
:
Boolean
=
true
,
//功能进入显示广告
var
rvEmptyShowNative
:
Boolean
=
true
,
//列表空的显示原生不
var
requestUmp
:
Boolean
=
false
,
//是否需要请求ump
)
{
...
...
app/src/main/java/com/base/appzxhy/business/ads/AdsMgr.kt
View file @
57e27536
...
...
@@ -94,7 +94,7 @@ object AdsMgr {
return
}
initAdmob
(
context
)
//
initMax(context)
initMax
(
context
)
}
...
...
app/src/main/java/com/base/appzxhy/business/helper/NewComUtils.kt
View file @
57e27536
...
...
@@ -4,20 +4,25 @@ import android.util.Base64
import
android.util.Log
import
com.base.appzxhy.BuildConfig
import
com.base.appzxhy.GlobalConfig
import
com.base.appzxhy.bean.config.AdConfigBean
import
com.base.appzxhy.bean.config.ConfigBean
import
com.base.appzxhy.bean.config.PopupConfigBean
import
com.base.appzxhy.utils.AppPreferences
import
com.base.appzxhy.utils.LogEx
import
kotlinx.coroutines.CoroutineScope
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.launch
import
java.io.BufferedReader
import
java.io.InputStreamReader
import
java.net.HttpURLConnection
import
java.net.URL
import
com.google.gson.Gson
import
okhttp3.Call
import
okhttp3.Callback
import
okhttp3.OkHttpClient
import
okhttp3.Request
import
okhttp3.Response
import
org.json.JSONObject
import
java.io.IOException
import
java.util.Locale
import
java.util.concurrent.TimeUnit
import
java.util.concurrent.atomic.AtomicBoolean
object
NewComUtils
{
private
val
TAG
=
"NewComUtils"
private
const
val
API_URL
=
GlobalConfig
.
URL_API
private
const
val
PACKAGE_NAME_PREFIX
=
GlobalConfig
.
PACKAGE_NAME
...
...
@@ -43,7 +48,8 @@ object NewComUtils {
AppPreferences
.
getInstance
().
put
(
"lastRequestTime"
,
value
,
true
)
}
private
val
url
:
String
by
lazy
{
fun
getUrl
():
String
{
val
packageName
=
GlobalConfig
.
PACKAGE_NAME
val
appCode
=
packageName
.
substringAfter
(
PACKAGE_NAME_PREFIX
).
take
(
5
).
toLowerCase
(
Locale
.
getDefault
())
...
...
@@ -63,79 +69,143 @@ object NewComUtils {
s
=
"$s&mode=4"
}
s
// mode =3 google mode=2 facebook mode=1 自然,mode=4 测试
// mode =3 google mode=2 facebook mode=1 自然,mode=4 测试
// &mode=3
return
s
}
var
requestCfgCallBack
:
(()
->
Unit
)?
=
null
//请求中的回调
var
requestCfgIng
=
AtomicBoolean
(
false
)
fun
requestCfg
(
callback
:
(
json
:
String
?)
->
Unit
)
{
fun
canRequestCfg
():
Boolean
{
val
passHour
=
(
System
.
currentTimeMillis
()
-
lastRequestTime
)
/
3600000
CoroutineScope
(
Dispatchers
.
IO
).
launch
{
requestCfgIng
.
set
(
true
)
val
passHour
=
(
System
.
currentTimeMillis
()
-
lastRequestTime
)
/
3600000
if
(
BuildConfig
.
DEBUG
)
{
lastRequestTime
=
0L
}
if
(
BuildConfig
.
DEBUG
)
{
lastRequestTime
=
0L
}
if
(
lastRequestTime
!=
0L
&&
passHour
<
ConfigBean
.
configBean
.
getConfigInterval
)
{
Log
.
e
(
TAG
,
"请求间隔 passHour=$passHour"
)
return
false
}
if
(
lastRequestTime
!=
0L
&&
passHour
<
ConfigBean
.
configBean
.
getConfigInterval
)
{
callback
.
invoke
(
null
)
Log
.
e
(
TAG
,
"请求间隔 passHour=$passHour"
)
return
@launch
}
return
true
}
fun
requestCfg
()
{
val
response
=
doGet
(
)
if
(
response
==
null
)
{
callback
(
null
)
return
@launch
}
requestCfgIng
.
set
(
true
)
if
(!
canRequestCfg
())
{
return
}
val
data
=
extractData
(
response
)
if
(
data
==
null
)
{
callback
(
null
)
return
@launch
val
urlPath
=
getUrl
()
LogEx
.
logDebug
(
TAG
,
"url=$urlPath"
)
val
request
=
Request
.
Builder
()
.
url
(
urlPath
)
.
get
()
.
build
()
client
.
newCall
(
request
).
enqueue
(
object
:
Callback
{
override
fun
onFailure
(
call
:
Call
,
e
:
IOException
)
{
e
.
printStackTrace
()
Log
.
d
(
TAG
,
"onFailure $e"
)
handleCfgCallBack
()
}
lastRequestTime
=
System
.
currentTimeMillis
()
val
decryptedData
=
AESHelper
.
decrypt
(
data
)
LogEx
.
logDebug
(
TAG
,
"decryptedData=$decryptedData"
)
spConfig
=
decryptedData
callback
(
decryptedData
)
requestCfgIng
.
set
(
false
)
override
fun
onResponse
(
call
:
Call
,
response
:
Response
)
{
requestCfgCallBack
?.
invoke
()
requestCfgCallBack
=
null
if
(
response
.
isSuccessful
)
{
val
json
=
response
.
body
?.
string
()
?:
""
LogEx
.
logDebug
(
TAG
,
"json=$json"
)
}
}
val
data
=
extractData
(
json
)
if
(
data
!=
null
)
{
lastRequestTime
=
System
.
currentTimeMillis
()
val
decryptedData
=
AESHelper
.
decrypt
(
data
)
LogEx
.
logDebug
(
TAG
,
"decryptedData=$decryptedData"
)
parseConfigBean
(
decryptedData
)
}
private
fun
doGet
():
String
?
{
val
urlPath
=
url
LogEx
.
logDebug
(
TAG
,
"url=$url"
)
try
{
val
conn
:
HttpURLConnection
=
URL
(
urlPath
).
openConnection
()
as
HttpURLConnection
conn
.
setRequestMethod
(
"GET"
)
conn
.
connectTimeout
=
150000
if
(
200
==
conn
.
getResponseCode
())
{
val
json
=
BufferedReader
(
InputStreamReader
(
conn
.
inputStream
)).
readLine
()
LogEx
.
logDebug
(
TAG
,
"json=$json"
)
return
json
}
handleCfgCallBack
()
}
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
Log
.
d
(
"okhttp"
,
e
.
toString
())
}
return
null
})
}
private
val
client
=
OkHttpClient
.
Builder
()
.
connectTimeout
(
10
,
TimeUnit
.
SECONDS
)
.
callTimeout
(
10
,
TimeUnit
.
SECONDS
)
.
readTimeout
(
10
,
TimeUnit
.
SECONDS
)
.
writeTimeout
(
10
,
TimeUnit
.
SECONDS
)
.
build
()
private
fun
extractData
(
response
:
String
):
String
?
{
val
regex
=
Regex
(
"\"$DATA_KEY\":\"(.*?)\""
)
val
match
=
regex
.
find
(
response
)
return
match
?.
groupValues
?.
get
(
1
)
}
fun
parseConfigBean
(
config
:
String
)
{
if
(
config
.
isNotEmpty
())
{
try
{
val
configBean
=
Gson
().
fromJson
(
config
,
ConfigBean
::
class
.
java
)
val
jsonObject
=
JSONObject
()
jsonObject
.
put
(
"ut"
,
configBean
.
ut
)
EventUtils
.
event
(
"user_type"
,
ext
=
jsonObject
)
//配置
ConfigBean
.
configBean
=
configBean
//广告
AdConfigBean
.
adsConfigBean
=
configBean
.
adConfigBean
LogEx
.
logDebug
(
"initConfig"
,
"adsConfigBean=${configBean.adConfigBean.functionInShowAd}"
)
//通知配置
PopupConfigBean
.
popupConfigBean
=
configBean
.
popupConfigBean
LogEx
.
logDebug
(
"initConfig"
,
"popupConfigBean=${configBean.popupConfigBean.popupCount}"
)
if
(
spConfig
!=
config
)
{
spConfig
=
config
}
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
EventUtils
.
event
(
"parseConfigBean_error"
,
value
=
config
)
}
}
}
var
requestCfgCallBackMap
=
hashMapOf
<
String
,
()
->
Unit
>()
private
fun
handleCfgCallBack
()
{
requestCfgIng
.
set
(
false
)
LogEx
.
logDebug
(
TAG
,
"handleCfgCallBack"
)
val
key1
=
"adCallBack"
requestCfgCallBackMap
.
get
(
key1
)
?.
let
{
it
.
invoke
()
requestCfgCallBackMap
.
remove
(
key1
)
}
val
key2
=
"changeTimer"
requestCfgCallBackMap
.
get
(
key2
)
?.
let
{
it
.
invoke
()
requestCfgCallBackMap
.
remove
(
key2
)
}
}
}
app/src/main/java/com/base/appzxhy/ui/splash/SplashActivity.kt
View file @
57e27536
...
...
@@ -26,20 +26,22 @@ import com.base.appzxhy.SpConstObject.isGuided
import
com.base.appzxhy.base.BaseActivity
import
com.base.appzxhy.base.jumpAction
import
com.base.appzxhy.bean.FeatureBean.Companion.BATTERY_INFO
import
com.base.appzxhy.bean.config.AdConfigBean
import
com.base.appzxhy.business.ads.AdsMgr
import
com.base.appzxhy.business.ads.AdsShowCallBack
import
com.base.appzxhy.business.helper.EventUtils
import
com.base.appzxhy.business.helper.NewComUtils
import
com.base.appzxhy.business.helper.NewComUtils.requestCfgCallBack
import
com.base.appzxhy.business.helper.NewComUtils.spConfig
import
com.base.appzxhy.business.service.StayJobService.Companion.startStayJobService
import
com.base.appzxhy.databinding.ActivitySplashBinding
import
com.base.appzxhy.ui.dialog.StoragePermissionDialog
import
com.base.appzxhy.ui.guide.GuideCleanActivity
import
com.base.appzxhy.ui.main.MainActivity
import
com.base.appzxhy.utils.LogEx
import
com.base.appzxhy.utils.PermissionUtils.checkStorePermission
import
com.base.appzxhy.utils.PermissionUtils.requestStoragePermission
import
com.base.appzxhy.utils.UmpUtils
import
com.base.appzxhy.utils.umpCalled
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.launch
import
java.util.concurrent.atomic.AtomicBoolean
...
...
@@ -83,6 +85,13 @@ class SplashActivity : BaseActivity<ActivitySplashBinding>(ActivitySplashBinding
showLoadingAd
()
setPrivacyPolicy
()
requestNotificationPermission
()
viewModel
.
jumpNext
=
{
// Log.e(TAG, "Countdown jumpNext")
// jumpNext()
}
// viewModel.onTick = { s, t ->
// Log.e(TAG, "onTick $s $t")
// }
}
private
fun
setPrivacyPolicy
()
{
...
...
@@ -139,17 +148,27 @@ class SplashActivity : BaseActivity<ActivitySplashBinding>(ActivitySplashBinding
}
private
fun
initUMP
()
{
val
ump
=
UmpUtils
(
this
)
private
fun
initUMP
(
callBack
:
()
->
Unit
)
{
if
(
ump
.
consentInformation
.
canRequestAds
())
{
AdsMgr
.
init
(
this
)
}
else
{
ump
.
callback
=
{
AdsMgr
.
init
(
this
)
if
(
AdConfigBean
.
adsConfigBean
.
requestUmp
&&
!
umpCalled
)
{
umpCalled
=
true
val
ump
=
UmpUtils
(
this
)
if
(
ump
.
consentInformation
.
canRequestAds
())
{
callBack
.
invoke
()
}
else
{
ump
.
callback
=
{
callBack
.
invoke
()
}
LogEx
.
logDebug
(
TAG
,
"requestUMP"
)
ump
.
requestUMP
()
}
ump
.
requestUMP
()
}
else
{
callBack
.
invoke
()
}
}
private
fun
showLoadingAd
()
{
...
...
@@ -160,16 +179,19 @@ class SplashActivity : BaseActivity<ActivitySplashBinding>(ActivitySplashBinding
if
(
ifAgreePrivacy
)
{
val
acAction
=
{
AdsMgr
.
showOpen
(
this
,
showCallBack
=
object
:
AdsShowCallBack
()
{
override
fun
show
()
{
viewModel
.
stopCountdown
()
}
initUMP
{
LogEx
.
logDebug
(
TAG
,
"initUMP callBack"
)
AdsMgr
.
showOpen
(
this
,
showCallBack
=
object
:
AdsShowCallBack
()
{
override
fun
show
()
{
viewModel
.
stopCountdown
()
}
override
fun
next
()
{
binding
.
root
.
postDelayed
({
jumpNext
()
},
200
)
}
override
fun
next
()
{
binding
.
root
.
postDelayed
({
jumpNext
()
},
200
)
}
})
})
}
}
if
(
spConfig
.
isNotEmpty
())
{
...
...
@@ -177,7 +199,9 @@ class SplashActivity : BaseActivity<ActivitySplashBinding>(ActivitySplashBinding
acAction
.
invoke
()
}
else
{
if
(
NewComUtils
.
requestCfgIng
.
get
())
{
requestCfgCallBack
=
{
Log
.
e
(
TAG
,
"requestCfg"
)
NewComUtils
.
requestCfgCallBackMap
.
put
(
"adCallBack"
)
{
Log
.
e
(
TAG
,
"requestCfgCallBack"
)
lifecycleScope
.
launch
(
Dispatchers
.
Main
)
{
Log
.
e
(
TAG
,
"2"
)
acAction
.
invoke
()
...
...
@@ -251,7 +275,6 @@ class SplashActivity : BaseActivity<ActivitySplashBinding>(ActivitySplashBinding
}
}
override
fun
onNewIntent
(
intent
:
Intent
?)
{
super
.
onNewIntent
(
intent
)
handleIntentExtras
()
...
...
app/src/main/java/com/base/appzxhy/ui/splash/SplashViewModel.kt
View file @
57e27536
...
...
@@ -30,8 +30,7 @@ class SplashViewModel : ViewModel() {
countdownJob
=
viewModelScope
.
launch
(
Dispatchers
.
IO
)
{
while
(
isActive
)
{
val
currentTime
=
System
.
currentTimeMillis
()
val
elapsed
=
currentTime
-
startTime
val
elapsed
=
System
.
currentTimeMillis
()
-
startTime
val
remaining
=
totalTimeMs
-
elapsed
if
(
remaining
<=
0
)
{
...
...
@@ -49,6 +48,7 @@ class SplashViewModel : ViewModel() {
}
launch
(
Dispatchers
.
Main
)
{
jumpNext
?.
invoke
()
jumpNext
=
null
}
}
}
...
...
app/src/main/java/com/base/appzxhy/utils/UmpUtils.kt
View file @
57e27536
...
...
@@ -41,7 +41,7 @@ class UmpUtils(
debugSettings
.
setDebugGeography
(
ConsentDebugSettings
.
DebugGeography
.
DEBUG_GEOGRAPHY_EEA
)
//通过TEST-DEVICE-HASHED-ID log过滤ConsentDebugSettings 打印测试id,使用测试id来测试
// debugSettings.addTestDeviceHashedId("TEST-DEVICE-HASHED-ID")
debugSettings
.
addTestDeviceHashedId
(
"
73FE7C2634104D50A11BE9B902AA0FA6
"
)
debugSettings
.
addTestDeviceHashedId
(
"
E136C135912795B2B1121AFD737A0F0E
"
)
return
debugSettings
.
build
()
}
...
...
@@ -114,19 +114,5 @@ class UmpUtils(
callback
=
null
}
})
// UserMessagingPlatform.loadAndShowConsentFormIfRequired(activity) { loadAndShowError: FormError? ->
// LogEx.logDebug(
// TAG,
// "loadAndShowConsentFormIfRequired message=${loadAndShowError?.message} errorCode=${loadAndShowError?.errorCode}"
// )
// if (loadAndShowError != null) {
// callback?.invoke(false)
// callback = null
// } else {
// callback?.invoke(consentInformation.canRequestAds())
// callback = null
// }
// }
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment