parent
00aebd8b86
commit
d5f7d1051d
|
|
@ -176,6 +176,8 @@ tasks.withType<JavaCompile>().configureEach {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
// 手动启动延后到隐私授权之后的初始化器。
|
||||
implementation("androidx.startup:startup-runtime:1.2.0")
|
||||
api(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar","*.aar"))))
|
||||
// 基础依赖
|
||||
implementation(libs.androidx.core.ktx)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
<!-- 不允许依赖库重新引入读取安装列表/运行任务的权限。 -->
|
||||
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" tools:node="remove" />
|
||||
<uses-permission android:name="android.permission.GET_TASKS" tools:node="remove" />
|
||||
<uses-permission android:name="android.permission.REAL_GET_TASKS" tools:node="remove" />
|
||||
<!-- 在Android14及以上版本读取SelectedPhotoAccess需要添加READ_MEDIA_VISUAL_USER_SELECTED权限 -->
|
||||
<uses-permission android:name="android.permission.READ_MEDIA_VISUAL_USER_SELECTED" />
|
||||
<!-- 写入外部存储权限,用于截长图保存,主要兼容Android 13及以下版本(Android13以上高版本不需要,但低版本必须) -->
|
||||
|
|
@ -37,7 +41,7 @@
|
|||
<package android:name="com.eg.android.AlipayGphone" /> <!-- 支付宝 -->
|
||||
<package android:name="hk.alipay.wallet" /> <!-- AlipayHK -->
|
||||
<package android:name="com.tencent.mm" />
|
||||
<intent>
|
||||
<intent tools:node="remove">
|
||||
<action android:name="com.getui.sdk.action" />
|
||||
</intent>
|
||||
</queries>
|
||||
|
|
@ -62,6 +66,20 @@
|
|||
tools:replace="android:allowBackup,android:supportsRtl"
|
||||
tools:targetApi="33">
|
||||
|
||||
<!-- SDK 自动初始化发生在 Application.onCreate 之前,改为同意后手动初始化。 -->
|
||||
<provider android:name="com.google.mlkit.common.internal.MlKitInitProvider"
|
||||
tools:node="remove" />
|
||||
<provider android:name="com.getui.gtc.base.GtcProvider" tools:node="remove" />
|
||||
<provider android:name=".provider.ConsentGtcProvider"
|
||||
android:authorities="${applicationId}.getui.gtc.provider"
|
||||
android:exported="false" />
|
||||
<provider android:name="androidx.startup.InitializationProvider"
|
||||
android:authorities="${applicationId}.androidx-startup"
|
||||
tools:node="merge">
|
||||
<meta-data android:name="okhttp3.internal.platform.PlatformInitializer"
|
||||
tools:node="remove" />
|
||||
</provider>
|
||||
|
||||
<activity
|
||||
android:name="com.img.rabbit.MainActivity"
|
||||
android:theme="@style/SplashTheme"
|
||||
|
|
@ -103,6 +121,16 @@
|
|||
|
||||
|
||||
<!--如果是小程序模式,还需要添加这行配置-->
|
||||
<activity
|
||||
android:name=".wxapi.AuthorizedWXEntryActivity"
|
||||
android:exported="false"
|
||||
android:excludeFromRecents="true"
|
||||
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
|
||||
<activity
|
||||
android:name=".wxapi.AuthorizedWXPayEntryActivity"
|
||||
android:exported="false"
|
||||
android:launchMode="singleTop"
|
||||
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
|
||||
<activity
|
||||
android:name="io.dcloud.feature.payment.weixin.WXPayProcessMeadiatorActivity"
|
||||
android:excludeFromRecents="true"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package com.img.rabbit
|
||||
|
||||
import android.app.ActivityManager
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
|
|
@ -8,53 +7,45 @@ import android.util.Log
|
|||
import com.bumptech.glide.Glide
|
||||
import com.img.rabbit.utils.NetworkMonitor
|
||||
import com.g.gysdk.GYManager
|
||||
import com.getui.gtc.base.util.CommonUtil.isMainProcess
|
||||
import androidx.startup.AppInitializer
|
||||
import com.google.mlkit.common.sdkinternal.MlKitContext
|
||||
import com.github.gzuliyujiang.oaid.DeviceID
|
||||
import com.github.gzuliyujiang.oaid.IGetter
|
||||
import com.img.rabbit.config.Constants
|
||||
import com.img.rabbit.provider.storage.PreferenceUtil
|
||||
import com.img.rabbit.provider.storage.PrivacyConsentStore
|
||||
import com.img.rabbit.provider.ConsentGtcProvider
|
||||
import com.img.rabbit.provider.utils.HeadParamUtils
|
||||
import com.img.rabbit.uni.UniMPImmersiveWindow
|
||||
import com.img.rabbit.utils.ChannelUtils
|
||||
import com.tencent.mmkv.MMKV
|
||||
import com.umeng.analytics.MobclickAgent
|
||||
import com.umeng.commonsdk.UMConfigure
|
||||
import com.umeng.socialize.PlatformConfig
|
||||
import io.dcloud.common.util.RuningAcitvityUtil
|
||||
import okhttp3.internal.platform.PlatformInitializer
|
||||
import io.dcloud.feature.sdk.DCSDKInitConfig
|
||||
import io.dcloud.feature.sdk.DCUniMPSDK
|
||||
import io.dcloud.feature.sdk.MenuActionSheetItem
|
||||
import java.lang.Exception
|
||||
import java.io.File
|
||||
|
||||
|
||||
class BaseApplication : Application() {
|
||||
private val TAG = "BaseApplication"
|
||||
private var batiaoInitialized = false
|
||||
private var thirdPartyInitialized = false
|
||||
private var uniAppInitialized = false
|
||||
private var uniAppOaid: String? = null
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
// UniMP Activity 运行在独立进程,窗口适配必须在主进程判断之前注册。
|
||||
UniMPImmersiveWindow.register(this)
|
||||
// 只有是主进程时,才执行重量级初始化
|
||||
if (getProcessName(this) == packageName) {
|
||||
Log.i(TAG, "进行必要的SDK初始化...")
|
||||
// 初始化MMKV
|
||||
initMMKV()
|
||||
// 非小程序进程(使用unimp 关键字 可以根据宿主的具体情况进行调整)
|
||||
if (PreferenceUtil.getAgreement() && !RuningAcitvityUtil.getAppName(baseContext).contains("unimp")) {
|
||||
Log.i(TAG, "已同意隐私政策,BaseApplication开始初始化SDK服务...")
|
||||
initThirdParty()
|
||||
initUM()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
override fun attachBaseContext(base: Context?) {
|
||||
//MultiDex.install(base)
|
||||
super.attachBaseContext(base)
|
||||
PrivacyConsentStore.initialize(this)
|
||||
HeadParamUtils.applicationContext = this
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -63,8 +54,19 @@ class BaseApplication : Application() {
|
|||
*/
|
||||
@Synchronized
|
||||
fun initThirdParty(){
|
||||
//需要在隐私框架下才能处理的逻辑
|
||||
if(PreferenceUtil.getAgreement()){
|
||||
if (!PrivacyConsentStore.isAccepted() || thirdPartyInitialized) return
|
||||
// 独立进程也必须先检查授权;只注册其所需的窗口适配。
|
||||
UniMPImmersiveWindow.register(this)
|
||||
if (currentProcessName() == packageName) {
|
||||
initMMKV()
|
||||
AppInitializer.getInstance(this).initializeComponent(PlatformInitializer::class.java)
|
||||
MlKitContext.initializeIfNeeded(this)
|
||||
// 采集开关必须在任何 SDK(包括构建插件注入代码)启动前设置。
|
||||
UMConfigure.enableAplCollection(false)
|
||||
check(GYManager.getInstance().setSecurity(this, false)) {
|
||||
"无法关闭个验扩展采集"
|
||||
}
|
||||
ConsentGtcProvider.initializeAfterConsent(this)
|
||||
if (!batiaoInitialized) {
|
||||
initializeBatiaoAfterConsent()
|
||||
batiaoInitialized = true
|
||||
|
|
@ -76,9 +78,11 @@ class BaseApplication : Application() {
|
|||
Glide.get(this)
|
||||
// 初始化个推SDK
|
||||
initGeTuiOneKeyLogin()
|
||||
initUM()
|
||||
// 初始化OAID和uni-app SDK
|
||||
initOAIDAndUniAPPSdk()
|
||||
}
|
||||
thirdPartyInitialized = true
|
||||
}
|
||||
|
||||
// Batiao 构建插件只向此方法注入初始化,调用前必须检查隐私协议。
|
||||
|
|
@ -129,7 +133,7 @@ class BaseApplication : Application() {
|
|||
|
||||
//初始化uni-app SDK
|
||||
private fun initUniAPPSdk() {
|
||||
if (PreferenceUtil.getAgreement() && isMainProcess(this)) {
|
||||
if (PreferenceUtil.getAgreement() && currentProcessName() == packageName) {
|
||||
val oaid = PreferenceUtil.getOAID()
|
||||
if (uniAppInitialized && uniAppOaid == oaid) return
|
||||
uniAppInitialized = true
|
||||
|
|
@ -158,19 +162,15 @@ class BaseApplication : Application() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun getProcessName(context: Context): String? {
|
||||
private fun currentProcessName(): String? {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
return getProcessName()
|
||||
}
|
||||
|
||||
val am = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
|
||||
val runningApps = am.runningAppProcesses ?: return null
|
||||
for (proInfo in runningApps) {
|
||||
if (proInfo.pid == android.os.Process.myPid()) {
|
||||
return proInfo.processName
|
||||
}
|
||||
}
|
||||
return null
|
||||
// 旧系统只读取当前进程名,不枚举其他应用的进程。
|
||||
return runCatching {
|
||||
File("/proc/self/cmdline").readText().substringBefore('\u0000')
|
||||
}.getOrNull()
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -13,16 +13,22 @@ import androidx.compose.foundation.background
|
|||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.BoxWithConstraints
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.safeDrawingPadding
|
||||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.foundation.layout.wrapContentHeight
|
||||
import androidx.compose.foundation.layout.wrapContentSize
|
||||
import androidx.compose.foundation.layout.wrapContentWidth
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.text.ClickableText
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
|
|
@ -38,6 +44,7 @@ import androidx.compose.runtime.setValue
|
|||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.scale
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
|
|
@ -47,6 +54,7 @@ import androidx.compose.ui.text.TextStyle
|
|||
import androidx.compose.ui.text.buildAnnotatedString
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextDecoration
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
|
|
@ -57,7 +65,6 @@ import androidx.lifecycle.viewmodel.compose.viewModel
|
|||
import com.google.accompanist.permissions.ExperimentalPermissionsApi
|
||||
import com.img.rabbit.bean.response.UniVersionEntity
|
||||
import com.img.rabbit.components.GlobalToast
|
||||
import com.img.rabbit.config.Constants
|
||||
import com.img.rabbit.config.Constants.agreementUrl
|
||||
import com.img.rabbit.config.Constants.privacyUrl
|
||||
import com.img.rabbit.pages.LoadingCallback
|
||||
|
|
@ -70,7 +77,6 @@ import com.img.rabbit.pages.dialog.UpdateDialog
|
|||
import com.img.rabbit.provider.storage.PreferenceUtil
|
||||
import com.img.rabbit.utils.AppEventBus
|
||||
import com.img.rabbit.utils.AppUpdate
|
||||
import com.img.rabbit.utils.ChannelUtils
|
||||
import com.img.rabbit.utils.FileUtils
|
||||
import com.img.rabbit.utils.GlobalEvent
|
||||
import com.img.rabbit.utils.GlobalEventBus
|
||||
|
|
@ -83,12 +89,9 @@ import com.img.rabbit.viewmodel.GeneralViewModel
|
|||
import com.img.rabbit.viewmodel.LoginViewModel
|
||||
import com.img.rabbit.viewmodel.ReportViewModel
|
||||
import com.img.rabbit.viewmodel.SplashViewModel
|
||||
import com.umeng.analytics.MobclickAgent
|
||||
import com.umeng.commonsdk.UMConfigure
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
class MainActivity : ComponentActivity(), LoadingCallback {
|
||||
private lateinit var generalViewModel: GeneralViewModel
|
||||
|
|
@ -103,8 +106,26 @@ class MainActivity : ComponentActivity(), LoadingCallback {
|
|||
enableEdgeToEdge()
|
||||
|
||||
setContent {
|
||||
// 授权前仅渲染原生协议页,不创建会访问 MMKV/网络/微信的业务 ViewModel。
|
||||
var consentAccepted by remember { mutableStateOf(PreferenceUtil.getAgreement()) }
|
||||
if (!consentAccepted) {
|
||||
splashScreen.setKeepOnScreenCondition { false }
|
||||
AppTheme {
|
||||
SplashScreenContent {
|
||||
PrivacyPolicyScreen { accepted ->
|
||||
if (accepted) {
|
||||
PreferenceUtil.saveAgreement(true)
|
||||
(application as BaseApplication).initThirdParty()
|
||||
consentAccepted = true
|
||||
} else {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return@setContent
|
||||
}
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
var showSplash by remember { mutableStateOf(false) }
|
||||
|
||||
val context = LocalContext.current
|
||||
val loginViewModel: LoginViewModel = viewModel()
|
||||
|
|
@ -267,41 +288,11 @@ class MainActivity : ComponentActivity(), LoadingCallback {
|
|||
|
||||
AppTheme {
|
||||
SplashScreenContent{
|
||||
//未同意提示政策弹窗
|
||||
if (!generalViewModel.agreementStatus.value){
|
||||
//同意继续
|
||||
PrivacyPolicyScreen(
|
||||
viewModel = loginViewModel,
|
||||
) { isAllowPrivacyPolicy ->
|
||||
if (isAllowPrivacyPolicy) {
|
||||
generalViewModel.setIsAgreement(true)
|
||||
loginViewModel.setIsPolicyAgreement(true)
|
||||
(applicationContext as BaseApplication).initThirdParty()
|
||||
initUM()
|
||||
showSplash = true
|
||||
} else {
|
||||
// 不同意隐私协议政策,直接退出应用
|
||||
(context as MainActivity).finish()
|
||||
// 强制退出应用进程
|
||||
exitProcess(0)
|
||||
}
|
||||
}
|
||||
}else{
|
||||
showSplash = true
|
||||
}
|
||||
|
||||
if(showSplash){
|
||||
//val token = PreferenceUtil.getAccessToken()
|
||||
// 未登录,显示登录页
|
||||
//if (token.isNullOrEmpty() && loginViewModel.userConfigResult.value == null) {
|
||||
if(isLogout){// 退出登录后,显示登录页
|
||||
// 显示登录页
|
||||
if(isLogout){
|
||||
LoginScreen(generalViewModel = generalViewModel, loginViewModel = loginViewModel, isVisibilityBreak = false)
|
||||
} else {
|
||||
//已登录,显示主页面
|
||||
MainScreen(generalViewModel = generalViewModel, loginViewModel = loginViewModel)
|
||||
}
|
||||
}
|
||||
|
||||
if(showLoginDialog){
|
||||
TipsDialog(
|
||||
|
|
@ -436,15 +427,6 @@ class MainActivity : ComponentActivity(), LoadingCallback {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化友盟(同意协议的时候,进行一次初始化)
|
||||
*/
|
||||
private fun initUM() {
|
||||
UMConfigure.preInit(applicationContext, Constants.UmengAppkey, ChannelUtils.getChannel(applicationContext))
|
||||
UMConfigure.init(this, Constants.UmengAppkey, ChannelUtils.getChannel(applicationContext), UMConfigure.DEVICE_TYPE_PHONE, "")
|
||||
MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.AUTO)
|
||||
}
|
||||
|
||||
override fun showLoading() {
|
||||
lifecycleScope.launch {
|
||||
generalViewModel.setLoading(true)
|
||||
|
|
@ -517,35 +499,39 @@ fun SplashScreenContent(
|
|||
|
||||
|
||||
@Composable
|
||||
private fun PrivacyPolicyScreen(viewModel: LoginViewModel, onAgreementChange: (Boolean) -> Unit) {
|
||||
private fun PrivacyPolicyScreen(onAgreementChange: (Boolean) -> Unit) {
|
||||
val context = LocalContext.current
|
||||
Box(
|
||||
modifier = Modifier.fillMaxSize()
|
||||
){
|
||||
Box(
|
||||
BoxWithConstraints(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.background(Color(0xCC000000))
|
||||
){
|
||||
.safeDrawingPadding()
|
||||
.padding(horizontal = 24.dp, vertical = 24.dp),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(horizontal = 38.dp, vertical = 213.dp)
|
||||
.align(Alignment.Center)
|
||||
.background(Color.White, shape = RoundedCornerShape(26.dp))
|
||||
.widthIn(max = 400.dp)
|
||||
.fillMaxWidth()
|
||||
.heightIn(max = maxHeight)
|
||||
.clip(RoundedCornerShape(26.dp))
|
||||
.background(Color.White)
|
||||
){
|
||||
Image(
|
||||
painter = painterResource(id = R.mipmap.ic_privacy_policy_top_mask),
|
||||
contentDescription = null,
|
||||
modifier = Modifier
|
||||
.fillMaxSize(),
|
||||
alignment = Alignment.TopCenter
|
||||
.fillMaxWidth()
|
||||
.height(64.dp),
|
||||
contentScale = ContentScale.FillBounds
|
||||
)
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.padding(top = 36.dp)
|
||||
.align(Alignment.TopCenter)
|
||||
.fillMaxWidth()
|
||||
// 内容与按钮使用同一条纵向布局,空间不足时整体滚动。
|
||||
.verticalScroll(rememberScrollState())
|
||||
.padding(start = 24.dp, end = 24.dp, top = 32.dp, bottom = 12.dp)
|
||||
) {
|
||||
Text(
|
||||
text = "用户协议与隐私政策",
|
||||
|
|
@ -554,6 +540,8 @@ private fun PrivacyPolicyScreen(viewModel: LoginViewModel, onAgreementChange: (B
|
|||
.align(Alignment.CenterHorizontally),
|
||||
fontWeight = FontWeight.Normal,
|
||||
fontSize = 18.sp,
|
||||
lineHeight = 26.sp,
|
||||
textAlign = TextAlign.Center,
|
||||
color = Color(0xFF1A1A1A)
|
||||
)
|
||||
Box(
|
||||
|
|
@ -570,7 +558,7 @@ private fun PrivacyPolicyScreen(viewModel: LoginViewModel, onAgreementChange: (B
|
|||
val startIndexPrivacy2 = agreement.lastIndexOf("《隐私政策》")
|
||||
|
||||
val serviceLength = "《服务协议》".length
|
||||
val privacyLength = "《服务协议》".length
|
||||
val privacyLength = "《隐私政策》".length
|
||||
|
||||
// 高亮显示 "《服务协议》"
|
||||
addStyle(
|
||||
|
|
@ -627,11 +615,11 @@ private fun PrivacyPolicyScreen(viewModel: LoginViewModel, onAgreementChange: (B
|
|||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.wrapContentHeight()
|
||||
.align(Alignment.CenterHorizontally)
|
||||
.padding(horizontal = 12.dp),
|
||||
.align(Alignment.CenterHorizontally),
|
||||
style = TextStyle(
|
||||
fontWeight = FontWeight.Normal,
|
||||
fontSize = 12.sp,
|
||||
lineHeight = 20.sp,
|
||||
color = Color(0xFF1A1A1A)
|
||||
),
|
||||
onClick = { offset ->
|
||||
|
|
@ -649,20 +637,12 @@ private fun PrivacyPolicyScreen(viewModel: LoginViewModel, onAgreementChange: (B
|
|||
}
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.wrapContentHeight()
|
||||
.align(Alignment.BottomCenter)
|
||||
) {
|
||||
Box(Modifier.height(24.dp))
|
||||
//同意按钮,用户协议与隐私政策
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.wrapContentHeight()
|
||||
.padding(start = 33.dp, end = 33.dp)
|
||||
.background(
|
||||
Color(0xFF252525),
|
||||
shape = RoundedCornerShape(359.dp),
|
||||
|
|
@ -691,7 +671,6 @@ private fun PrivacyPolicyScreen(viewModel: LoginViewModel, onAgreementChange: (B
|
|||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.wrapContentHeight()
|
||||
.padding(start = 33.dp, end = 33.dp)
|
||||
.background(
|
||||
Color(0x00000000),
|
||||
shape = RoundedCornerShape(359.dp),
|
||||
|
|
@ -701,7 +680,6 @@ private fun PrivacyPolicyScreen(viewModel: LoginViewModel, onAgreementChange: (B
|
|||
interactionSource = remember { MutableInteractionSource() }
|
||||
) {
|
||||
onAgreementChange(false)
|
||||
viewModel.setIsPolicyAgreement(false)
|
||||
}
|
||||
) {
|
||||
Text(
|
||||
|
|
@ -719,11 +697,19 @@ private fun PrivacyPolicyScreen(viewModel: LoginViewModel, onAgreementChange: (B
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Preview(name = "隐私弹窗-小屏", widthDp = 360, heightDp = 640, showBackground = true)
|
||||
@Preview(name = "隐私弹窗-大字体", widthDp = 320, heightDp = 480, fontScale = 1.5f, showBackground = true)
|
||||
@Composable
|
||||
private fun PrivacyPolicyPreview() {
|
||||
MaterialTheme {
|
||||
PrivacyPolicyScreen(onAgreementChange = {})
|
||||
}
|
||||
}
|
||||
|
||||
@Preview(showBackground = true)
|
||||
@Composable
|
||||
fun MainScreenPreview() {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,58 @@
|
|||
package com.img.rabbit.provider
|
||||
|
||||
import android.content.ContentProvider
|
||||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import android.content.pm.ProviderInfo
|
||||
import android.database.Cursor
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import com.getui.gtc.base.GtcProvider
|
||||
import com.img.rabbit.provider.storage.PrivacyConsentStore
|
||||
|
||||
/** 保留个推的进程通信地址,但在授权前不创建 SDK Provider。 */
|
||||
class ConsentGtcProvider : ContentProvider() {
|
||||
private var delegate: ContentProvider? = null
|
||||
private lateinit var providerInfo: ProviderInfo
|
||||
|
||||
override fun attachInfo(context: Context, info: ProviderInfo) {
|
||||
providerInfo = info
|
||||
super.attachInfo(context, info)
|
||||
}
|
||||
|
||||
override fun onCreate(): Boolean = true
|
||||
|
||||
@Synchronized
|
||||
private fun initialize(): ContentProvider? {
|
||||
if (!PrivacyConsentStore.isAccepted()) return null
|
||||
return delegate ?: GtcProvider().also {
|
||||
it.attachInfo(requireNotNull(context), providerInfo)
|
||||
delegate = it
|
||||
}
|
||||
}
|
||||
|
||||
override fun call(method: String, arg: String?, extras: Bundle?): Bundle? {
|
||||
val provider = initialize() ?: return null
|
||||
return if (method == INITIALIZE) Bundle() else provider.call(method, arg, extras)
|
||||
}
|
||||
|
||||
override fun query(uri: Uri, projection: Array<out String>?, selection: String?,
|
||||
selectionArgs: Array<out String>?, sortOrder: String?): Cursor? = null
|
||||
override fun getType(uri: Uri): String? = null
|
||||
override fun insert(uri: Uri, values: ContentValues?): Uri? = null
|
||||
override fun delete(uri: Uri, selection: String?, selectionArgs: Array<out String>?): Int = 0
|
||||
override fun update(uri: Uri, values: ContentValues?, selection: String?,
|
||||
selectionArgs: Array<out String>?): Int = 0
|
||||
|
||||
companion object {
|
||||
private const val INITIALIZE = "rabbit.initializeAfterConsent"
|
||||
|
||||
fun initializeAfterConsent(context: Context) {
|
||||
if (!PrivacyConsentStore.isAccepted()) return
|
||||
context.contentResolver.call(
|
||||
Uri.parse("content://${context.packageName}.getui.gtc.provider"),
|
||||
INITIALIZE, null, null
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -22,7 +22,6 @@ object PreferenceUtil {
|
|||
private const val KEY_USER_CONFIG = "user_config"
|
||||
private const val KEY_WX_CODE = "wx_code"
|
||||
private const val KEY_USER_INFO = "user_info"
|
||||
private const val KEY_AGREEMENT = "agreement"
|
||||
private const val KEY_WGT_VERSION = "uni_wgt_version"
|
||||
|
||||
|
||||
|
|
@ -33,7 +32,7 @@ object PreferenceUtil {
|
|||
|
||||
|
||||
// Gson实例
|
||||
private val gson: Gson = GsonBuilder().create()
|
||||
private val gson: Gson by lazy { GsonBuilder().create() }
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -69,11 +68,11 @@ object PreferenceUtil {
|
|||
|
||||
|
||||
fun saveAgreement(agreement: Boolean) {
|
||||
mmkv.putBoolean(KEY_AGREEMENT, agreement)
|
||||
PrivacyConsentStore.setAccepted(agreement)
|
||||
}
|
||||
|
||||
fun getAgreement(): Boolean {
|
||||
return mmkv.decodeBool(KEY_AGREEMENT, false)
|
||||
return PrivacyConsentStore.isAccepted()
|
||||
}
|
||||
|
||||
fun saveUserConfig(config: UserConfigEntity?) {
|
||||
|
|
@ -209,5 +208,6 @@ object PreferenceUtil {
|
|||
*/
|
||||
fun clearAll() {
|
||||
mmkv.clearAll()
|
||||
PrivacyConsentStore.setAccepted(false)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
package com.img.rabbit.provider.storage
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
|
||||
/** 协议判断不能依赖尚未获准初始化的 MMKV 或其他 SDK。 */
|
||||
object PrivacyConsentStore {
|
||||
private lateinit var preferences: SharedPreferences
|
||||
|
||||
fun initialize(context: Context) {
|
||||
preferences = context.getSharedPreferences("privacy_consent", Context.MODE_PRIVATE)
|
||||
}
|
||||
|
||||
fun isAccepted(): Boolean = preferences.getBoolean("accepted", false)
|
||||
|
||||
fun setAccepted(accepted: Boolean) {
|
||||
// 在启动小程序等独立进程前落盘,保证它们读取到明确的授权状态。
|
||||
check(preferences.edit().putBoolean("accepted", accepted).commit()) {
|
||||
"无法保存隐私协议状态"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,15 +3,9 @@ package com.img.rabbit.provider.utils
|
|||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import com.img.rabbit.R
|
||||
import okhttp3.internal.platform.ContextAwarePlatform
|
||||
import okhttp3.internal.platform.Platform
|
||||
|
||||
object HeadParamUtils {
|
||||
var applicationContext: Context?
|
||||
get() = (Platform.get() as? ContextAwarePlatform)?.applicationContext
|
||||
set(value) {
|
||||
(Platform.get() as? ContextAwarePlatform)?.applicationContext = value
|
||||
}
|
||||
var applicationContext: Context? = null
|
||||
|
||||
fun getAppVersionName(): String? {
|
||||
return try {
|
||||
|
|
|
|||
|
|
@ -62,6 +62,10 @@ class BindViewModel : BaseViewModel() {
|
|||
|
||||
|
||||
fun oneKeyLoginForGeTuiSdk(activity: Activity, onShowOneKeyScreen:(Boolean)->Unit) {
|
||||
if (!PreferenceUtil.getAgreement()) {
|
||||
onShowOneKeyScreen(false)
|
||||
return
|
||||
}
|
||||
// 初始化 SDK
|
||||
GYManager.getInstance().init(GyConfig.with(activity.applicationContext).callBack(object : GyCallBack {
|
||||
override fun onSuccess(response: GYResponse?) {
|
||||
|
|
|
|||
|
|
@ -97,6 +97,7 @@ class GeneralViewModel: BaseViewModel(){
|
|||
}
|
||||
|
||||
private fun initWXApi(context: Context) {
|
||||
if (!PreferenceUtil.getAgreement()) return
|
||||
api = WXAPIFactory.createWXAPI(context, Constants.WxAppId, true)
|
||||
api.registerApp(Constants.WxAppId)
|
||||
|
||||
|
|
@ -118,6 +119,10 @@ class GeneralViewModel: BaseViewModel(){
|
|||
override fun onCleared() {
|
||||
super.onCleared()
|
||||
connectivityManager.unregisterNetworkCallback(networkCallback)
|
||||
if (::receiver.isInitialized && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
HeadParamUtils.applicationContext?.unregisterReceiver(receiver)
|
||||
}
|
||||
if (::api.isInitialized) api.detach()
|
||||
}
|
||||
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
|
|
|
|||
|
|
@ -12,7 +12,11 @@ import com.tencent.mm.opensdk.modelmsg.SendAuth
|
|||
import com.umeng.socialize.weixin.view.WXCallbackActivity
|
||||
|
||||
|
||||
class WXEntryActivity : WXCallbackActivity() {
|
||||
class WXEntryActivity : WechatConsentActivity() {
|
||||
override val callbackClassName = "com.img.rabbit.wxapi.AuthorizedWXEntryActivity"
|
||||
}
|
||||
|
||||
class AuthorizedWXEntryActivity : WXCallbackActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
try {
|
||||
// The SDK dispatches handleIntent/onResp synchronously.
|
||||
|
|
|
|||
|
|
@ -10,7 +10,11 @@ import com.tencent.mm.opensdk.modelbase.BaseReq
|
|||
import com.tencent.mm.opensdk.modelbase.BaseResp
|
||||
import io.dcloud.feature.payment.weixin.AbsWXPayCallbackActivity
|
||||
|
||||
class WXPayEntryActivity : AbsWXPayCallbackActivity() {
|
||||
class WXPayEntryActivity : WechatConsentActivity() {
|
||||
override val callbackClassName = "com.img.rabbit.wxapi.AuthorizedWXPayEntryActivity"
|
||||
}
|
||||
|
||||
class AuthorizedWXPayEntryActivity : AbsWXPayCallbackActivity() {
|
||||
//val scope = CoroutineScope(Dispatchers.Main)
|
||||
private lateinit var generalViewModel: GeneralViewModel
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
package com.img.rabbit.wxapi
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import com.img.rabbit.provider.storage.PrivacyConsentStore
|
||||
|
||||
/** 外部回调先经过原生 Activity,避免 SDK 父类在未授权时执行 onCreate。 */
|
||||
abstract class WechatConsentActivity : Activity() {
|
||||
protected abstract val callbackClassName: String
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
dispatch(intent)
|
||||
}
|
||||
|
||||
override fun onNewIntent(intent: Intent) {
|
||||
super.onNewIntent(intent)
|
||||
dispatch(intent)
|
||||
}
|
||||
|
||||
private fun dispatch(callback: Intent) {
|
||||
if (PrivacyConsentStore.isAccepted()) {
|
||||
startActivity(Intent(callback).setClassName(this, callbackClassName))
|
||||
}
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@
|
|||
See https://developer.android.com/about/versions/12/backup-restore
|
||||
-->
|
||||
<full-backup-content>
|
||||
<exclude domain="sharedpref" path="privacy_consent.xml" />
|
||||
<!--
|
||||
<include domain="sharedpref" path="."/>
|
||||
<exclude domain="sharedpref" path="device.xml"/>
|
||||
|
|
|
|||
|
|
@ -5,11 +5,15 @@
|
|||
-->
|
||||
<data-extraction-rules>
|
||||
<cloud-backup>
|
||||
<exclude domain="sharedpref" path="privacy_consent.xml" />
|
||||
<!-- TODO: Use <include> and <exclude> to control what is backed up.
|
||||
<include .../>
|
||||
<exclude .../>
|
||||
-->
|
||||
</cloud-backup>
|
||||
<device-transfer>
|
||||
<exclude domain="sharedpref" path="privacy_consent.xml" />
|
||||
</device-transfer>
|
||||
<!--
|
||||
<device-transfer>
|
||||
<include .../>
|
||||
|
|
|
|||
Loading…
Reference in New Issue