diff --git a/app/build.gradle b/app/build.gradle index 5af0f17c69..9661f9eca1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -403,7 +403,6 @@ dependencies { implementation(project(':module_message')) { exclude group: 'androidx.swiperefreshlayout' } -// implementation(project(':feature:vpn')) implementation(project(':feature:pkg')) implementation(project(':feature:oaid')) implementation(project(':feature:floating-window')) diff --git a/app/src/main/java/com/gh/common/constant/Config.java b/app/src/main/java/com/gh/common/constant/Config.java index d7fc5d4727..d0ef3a1a1d 100644 --- a/app/src/main/java/com/gh/common/constant/Config.java +++ b/app/src/main/java/com/gh/common/constant/Config.java @@ -15,6 +15,7 @@ import com.gh.gamecenter.BuildConfig; import com.gh.gamecenter.common.constant.CommonConsts; import com.gh.gamecenter.common.constant.Constants; import com.gh.gamecenter.common.eventbus.EBReuse; +import com.gh.gamecenter.common.exposure.meta.MetaUtil; import com.gh.gamecenter.common.retrofit.BiResponse; import com.gh.gamecenter.common.retrofit.Response; import com.gh.gamecenter.common.utils.DarkModeUtils; @@ -79,19 +80,6 @@ public class Config { return !SPUtils.getBoolean(Constants.SP_TEENAGER_MODE); } - /** - * VPN 开关选项是否开启 - */ - public static boolean isVpnOptionEnabled() { - if (mNewApiSettingsEntity == null - || mNewApiSettingsEntity.getInstall() == null - || mNewApiSettingsEntity.getInstall().getVpnRequired() == null) { - return false; - } - - return mNewApiSettingsEntity.getInstall().getVpnRequired().getShouldShowVpnOption(); - } - public static void setSettings(SettingsEntity settingsEntity) { getPreferences().edit().putString(SETTINGS_KEY, GsonUtils.toJson(settingsEntity)).apply(); mSettingsEntity = settingsEntity; @@ -311,7 +299,9 @@ public class Config { String filterString = UrlFilterUtils.getFilterQuery( "manufacturer", Build.MANUFACTURER, "model", Build.MODEL, - "android_sdk_version", String.valueOf(Build.VERSION.SDK_INT)); + "android_sdk_version", String.valueOf(Build.VERSION.SDK_INT), + "rom", MetaUtil.INSTANCE.getRom().name() + " " + MetaUtil.INSTANCE.getRom().getVersionName() + ); RetrofitManager.getInstance() .getNewApi().getNewSettings(PackageUtils.getGhVersionName(), channel, filterString) diff --git a/app/src/main/java/com/gh/common/util/DirectUtils.kt b/app/src/main/java/com/gh/common/util/DirectUtils.kt index 255b843752..0bb4df4166 100644 --- a/app/src/main/java/com/gh/common/util/DirectUtils.kt +++ b/app/src/main/java/com/gh/common/util/DirectUtils.kt @@ -253,7 +253,7 @@ object DirectUtils { path ) - HOST_WEB, HOST_WEB_INURL, HOST_WEB_AL -> { + HOST_WEB, HOST_WEB_INURL, HOST_WEB_AL, HOST_QA_CONTENT -> { when { linkEntity.link!!.contains("v.douyin") && PackageHelper.localPackageNameSet.contains("com.ss.android.ugc.aweme") -> { directDouyin(context, "1402577827140941") @@ -353,7 +353,7 @@ object DirectUtils { "feedback" -> directToFeedback(context, linkEntity.name, false, "", false, false, entrance) - "qa", "qa_content", "Q&A" -> directToQa(context, linkEntity.text ?: "", linkEntity.link ?: "") + "qa", "Q&A" -> directToQa(context, linkEntity.text ?: "", linkEntity.link ?: "") "qa_list" -> directToHelpAndFeedback(context) diff --git a/app/src/main/java/com/gh/common/util/NewFlatLogUtils.kt b/app/src/main/java/com/gh/common/util/NewFlatLogUtils.kt index cdc02949fc..e335e32aa7 100644 --- a/app/src/main/java/com/gh/common/util/NewFlatLogUtils.kt +++ b/app/src/main/java/com/gh/common/util/NewFlatLogUtils.kt @@ -2007,29 +2007,6 @@ object NewFlatLogUtils { log(json, "event", false) } - // vpn 弹窗显示 - fun logVpnHintDialogShow(gameId: String, gameName: String) { - val json = json { - KEY_EVENT to "vpn_pre_access_dialog_show" - KEY_GAME_ID to gameId - KEY_GAME_NAME to gameName - parseAndPutMeta().invoke(this) - } - log(json, "event", false) - } - - // vpn 弹窗点击 - fun logVpnHintDialogClick(gameId: String, gameName: String, button: String) { - val json = json { - KEY_EVENT to "vpn_pre_access_dialog_click" - KEY_GAME_ID to gameId - KEY_GAME_NAME to gameName - "button" to button - parseAndPutMeta().invoke(this) - } - log(json, "event", false) - } - // 谷歌框架弹窗显示 fun logGAppsDialogShowed(gameId: String, gameName: String) { val json = json { diff --git a/app/src/main/java/com/gh/common/util/PackageInstaller.kt b/app/src/main/java/com/gh/common/util/PackageInstaller.kt index 594c96bd67..6ef91f3054 100644 --- a/app/src/main/java/com/gh/common/util/PackageInstaller.kt +++ b/app/src/main/java/com/gh/common/util/PackageInstaller.kt @@ -6,7 +6,6 @@ import android.content.Context import android.content.Intent import android.net.Uri import android.os.Build -import android.view.View import androidx.appcompat.app.AppCompatActivity import androidx.core.content.FileProvider import com.gh.common.dialog.InstallPermissionDialogFragment @@ -20,13 +19,13 @@ import com.gh.gamecenter.core.utils.CurrentActivityHolder import com.gh.gamecenter.core.utils.MD5Utils import com.gh.gamecenter.core.utils.ToastUtils import com.gh.gamecenter.install.InstallService -import com.gh.gamecenter.vpn.VpnHelper import com.gh.vspace.VHelper import com.halo.assistant.HaloApp import com.lightgame.download.DownloadEntity import com.lightgame.utils.Utils import java.io.File +// TODO 将弹窗改成以责任链模式来处理 object PackageInstaller { /** @@ -124,13 +123,13 @@ object PackageInstaller { } if (PackageUtils.isCanLaunchSetup(context, pkgPath)) { - val currentActivity = CurrentActivityHolder.getCurrentActivity() - - if (VpnHelper.shouldUseVpn() && currentActivity is AppCompatActivity) { - turnOnVpnThenInstall(currentActivity, pkgPath, downloadEntity) - } else { - install(context, pkgPath) - } + installWithPureModeHandled( + context, + pkgPath, + downloadEntity?.gameId ?: "unknown", + downloadEntity?.name ?: "unknown", + downloadEntity?.categoryChinese ?: "unknown" + ) } else { if (isPluggin) { DialogHelper.showPluginDialog( @@ -160,6 +159,21 @@ object PackageInstaller { } } + /** + * 处理纯净模式后的安装 + */ + private fun installWithPureModeHandled( + context: Context, + pkgPath: String, + gameId: String, + gameName: String, + gameType: String, + ) { + PureModeHelper.handlePureModeIfNeeded(context, gameId, gameName, gameType) { + install(context, pkgPath) + } + } + /** * 最终执行安装的方法 */ @@ -291,82 +305,4 @@ object PackageInstaller { return MD5Utils.getContentMD5(gameName + "_" + System.currentTimeMillis()) } - /** - * 启动 VPN 然后安装应用 (若没有授权会先提醒授权 VPN ,若拒绝授权会回落到直接执行安装) - */ - private fun turnOnVpnThenInstall(currentActivity: AppCompatActivity, - pkgPath: String, - downloadEntity: DownloadEntity?) { - if (VpnHelper.isVpnPermissionGranted(currentActivity) == true) { - VpnHelper.startVpn(currentActivity) { shouldShowVpnError -> - if (shouldShowVpnError) { - ToastUtils.toast("安装防护功能启动失败") - } - install(currentActivity, pkgPath) - } - } else { - val isTheFirstTimeToShowVpnHintDialog = VpnHelper.isTheFistTimeToShowVpnHintDialog() - - downloadEntity?.let { - NewFlatLogUtils.logVpnHintDialogShow(it.gameId, it.name) - } - - // 将 VPN 提示弹窗标记为已读(已读后的下一次显示"不再提醒"按钮) - VpnHelper.setVpnHintDialogShowed() - if (!VpnHelper.shouldShowVpnHintDialog()) { - VpnHelper.startVpn(currentActivity) { shouldShowVpnError -> - if (shouldShowVpnError) { - ToastUtils.toast("安装防护功能启动失败") - } - install(currentActivity, pkgPath) - } - } else { - DialogHelper.showGuideDialog( - context = currentActivity, - title = "开启安装防护", - content = "建议您开启安装防护功能,该功能有助于帮助您更快的完成安装,避免因提示和置换导致的重复下载等问题,安装防护功能需要获取您的VPN权限", - confirmText = "立即授权开启防护", - cancelText = "不再提醒", - confirmClickCallback = { - VpnHelper.ignoreVpnHintDialog() - VpnHelper.startVpn(currentActivity) { shouldShowVpnError -> - if (shouldShowVpnError) { - ToastUtils.toast("安装防护功能启动失败") - } - install(currentActivity, pkgPath) - } - - downloadEntity?.let { - NewFlatLogUtils.logVpnHintDialogClick(it.gameId, it.name, "立即授权") - } - }, - cancelClickCallback = { - VpnHelper.ignoreVpnFunction() - install(currentActivity, pkgPath) - downloadEntity?.let { - NewFlatLogUtils.logVpnHintDialogClick(it.gameId, it.name, "不再提醒") - } - }, - extraConfig = DialogHelper.Config( - showCloseIcon = true, - showAlternativeCancelStyle = !isTheFirstTimeToShowVpnHintDialog - ), - uiModificationCallback = { binding -> - binding.cancelTv.visibility = View.GONE - binding.closeContainer.setOnClickListener { - binding.markDismissByTouchInside() - - install(currentActivity, pkgPath) - binding.dismiss() - - downloadEntity?.let { - NewFlatLogUtils.logVpnHintDialogClick(it.gameId, it.name, "关闭按钮") - } - } - } - ) - } - } - } - } \ No newline at end of file diff --git a/app/src/main/java/com/gh/common/util/PostCommentUtils.java b/app/src/main/java/com/gh/common/util/PostCommentUtils.java index fa58820f99..8e0b9e94ca 100644 --- a/app/src/main/java/com/gh/common/util/PostCommentUtils.java +++ b/app/src/main/java/com/gh/common/util/PostCommentUtils.java @@ -5,12 +5,12 @@ import android.os.Build; import android.text.TextUtils; import com.gh.gamecenter.R; +import com.gh.gamecenter.common.exposure.meta.MetaUtil; import com.gh.gamecenter.common.retrofit.JSONObjectResponse; import com.gh.gamecenter.common.retrofit.Response; import com.gh.gamecenter.feature.entity.CommentEntity; import com.gh.gamecenter.retrofit.RetrofitManager; import com.lightgame.utils.Utils; -import com.walkud.rom.checker.RomIdentifier; import org.json.JSONObject; @@ -37,7 +37,7 @@ public class PostCommentUtils { device.put("model", Build.MODEL); device.put("manufacturer", Build.MANUFACTURER); device.put("android_version", android.os.Build.VERSION.RELEASE); - device.put("rom", RomIdentifier.getRom().name() + " " + RomIdentifier.getRom().getVersionName()); + device.put("rom", MetaUtil.INSTANCE.getRom().name() + " " + MetaUtil.INSTANCE.getRom().getVersionName()); content.put("device", device); } catch (Exception e) { e.printStackTrace(); diff --git a/app/src/main/java/com/gh/common/util/PureModeHelper.kt b/app/src/main/java/com/gh/common/util/PureModeHelper.kt new file mode 100644 index 0000000000..d5f7534dfb --- /dev/null +++ b/app/src/main/java/com/gh/common/util/PureModeHelper.kt @@ -0,0 +1,342 @@ +package com.gh.common.util + +import android.app.Activity +import android.content.Context +import android.content.Intent +import android.provider.Settings +import android.view.View +import androidx.appcompat.app.AppCompatActivity +import androidx.lifecycle.DefaultLifecycleObserver +import androidx.lifecycle.LifecycleOwner +import com.gh.common.constant.Config +import com.gh.gamecenter.common.utils.DialogHelper +import com.gh.gamecenter.entity.NewApiSettingsEntity +import com.lightgame.utils.Utils + +import com.gh.gamecenter.R +import com.gh.gamecenter.common.utils.SensorsBridge +import com.gh.gamecenter.common.utils.enlargeTouchArea +import com.gh.gamecenter.common.utils.setDrawableEnd +import com.gh.gamecenter.core.utils.SPUtils + +/** + * 处理厂商纯净/安全模式的辅助类 + */ +object PureModeHelper { + + private const val TAG = "PureModeHelper" + + private const val HW = "HUAWEI" + + private const val HW_PURE_MODE_STATE = "pure_mode_state" + private const val HW_PURE_ENHANCED_MODE_STATE = "pure_enhanced_mode_state" + + private const val HW_PURE_MODE = "harmony_os_pure_mode" + private const val HW_PURE_ENHANCED_MODE = "harmony_os_pure_enhanced_mode" + + private const val SP_USER_IGNORE_GUIDE = "user_ignore_guide" + + private const val SWITCH_EXIST = 1 + private const val SWITCH_ON = 0 + private const val SWITCH_OFF = -1 + + private var isThisDeviceUsingEnhancedMode = false // 当前设备是否是增强纯净模式 + + fun handlePureModeIfNeeded( + context: Context, + gameId: String, + gameName: String, + gameType: String, + callback: () -> Unit + ) { + // 用户忽略提醒,不再走下面的逻辑 + if (SPUtils.getBoolean(SP_USER_IGNORE_GUIDE, false)) { + callback() + return + } + + // 仅适用于华为手机 + val manufacturer = android.os.Build.MANUFACTURER + if (manufacturer != HW) { + callback.invoke() + return + } + + val solidContext = DialogHelper.checkDialogContext(context) + + if (solidContext == null) { + callback.invoke() + return + } + + if (readState(solidContext, HW_PURE_ENHANCED_MODE_STATE) == SWITCH_ON) { + Utils.log(TAG, "增强纯净模式开启!") + isThisDeviceUsingEnhancedMode = true + + val pureModeGuide = + Config.getNewApiSettingsEntity()?.install?.guides?.firstOrNull { it.type == HW_PURE_ENHANCED_MODE } + + if (pureModeGuide != null) { + showHWHintDialog(solidContext, pureModeGuide, gameId, gameName, gameType, true, callback) + } else { + callback.invoke() + } + } else if (readState(solidContext, HW_PURE_ENHANCED_MODE_STATE) != SWITCH_EXIST + && readState(solidContext, HW_PURE_MODE_STATE) == SWITCH_ON + ) { + Utils.log(TAG, "纯净模式开启!") + isThisDeviceUsingEnhancedMode = false + + val pureModeGuide = + Config.getNewApiSettingsEntity()?.install?.guides?.firstOrNull { it.type == HW_PURE_MODE } + + if (pureModeGuide != null) { + showHWHintDialog(solidContext, pureModeGuide, gameId, gameName, gameType, false, callback) + } else { + callback.invoke() + } + } else { + callback() + } + } + + private fun showHWHintDialog( + context: Context, + guide: NewApiSettingsEntity.Guide, + gameId: String, + gameName: String, + gameType: String, + isEnhancedMode: Boolean, + callback: () -> Unit + ) { + var isIgnored = false + + if (context is Activity) { + if (context.isFinishing) { + callback.invoke() + return + } + } + + trackDialogShow(isEnhancedMode, gameId, gameName, gameType) + + DialogHelper.showGuideDialog( + context = context, + title = guide.title, + content = guide.content, + confirmText = guide.buttonTextSettingJump, + cancelText = guide.buttonTextClose, + uiModificationCallback = { binding -> + binding.hintTv.buildSpannableString { + addText(guide.linkTextPrefix) + addText(guide.linkText) { + setColor(ColorResId(R.color.text_theme)) + onClick(false) { + binding.extraHintIv.performClick() + } + } + } + binding.extraHintIv.setImageResource(R.drawable.ic_home_head_arrow) + binding.extraHintIv.setOnClickListener { + directToLink( + context, + guide, + gameId, + gameName, + gameType, + isEnhancedMode, + isIgnored + ) + } + binding.extraHintIv.enlargeTouchArea() + binding.extraHintIv.visibility = View.VISIBLE + binding.hintTv.visibility = View.VISIBLE + binding.selectorContainer.visibility = if (guide.dialogFrequency == "once") View.VISIBLE else View.GONE + binding.selectorContainer.setOnClickListener { + binding.selectorContainer.isChecked = !binding.selectorContainer.isChecked + isIgnored = binding.selectorContainer.isChecked + } + + binding.confirmTv.setOnClickListener { + toHWPureModeSetting(context) + trackDialogClicked( + isEnhancedMode = isEnhancedMode, + gameId = gameId, + gameName = gameName, + gameType = gameType, + buttonName = guide.buttonTextSettingJump, + isIgnored = isIgnored + ) + } + + // 监听是否已授权,授权后自动调起安装并 dismiss dialog + if (context is AppCompatActivity) { + val lifecycle = context.lifecycle + lifecycle.addObserver(object : DefaultLifecycleObserver { + override fun onResume(owner: LifecycleOwner) { + val granted = (isThisDeviceUsingEnhancedMode && readState(context, HW_PURE_ENHANCED_MODE_STATE) != SWITCH_ON) + || (!isThisDeviceUsingEnhancedMode && readState(context, HW_PURE_MODE_STATE) != SWITCH_ON) + + if (granted) { + binding.dialog.dismiss() + callback.invoke() + lifecycle.removeObserver(this) + } + } + + override fun onDestroy(owner: LifecycleOwner) { + super.onDestroy(owner) + + lifecycle.removeObserver(this) + } + }) + } + }, + confirmClickCallback = { + // do nothing, 上面 setOnClickListener 处理了 + }, + cancelClickCallback = { + if (guide.dialogFrequency == "once" && isIgnored) { + SPUtils.setBoolean(SP_USER_IGNORE_GUIDE, true) + } + trackDialogClicked( + isEnhancedMode = isEnhancedMode, + gameId = gameId, + gameName = gameName, + gameType = gameType, + buttonName = guide.buttonTextClose, + isIgnored = isIgnored + ) + callback() + }, + touchOutsideCallback = { + if (guide.dialogFrequency == "once" && isIgnored) { + SPUtils.setBoolean(SP_USER_IGNORE_GUIDE, true) + } + trackDialogClicked( + isEnhancedMode = isEnhancedMode, + gameId = gameId, + gameName = gameName, + gameType = gameType, + buttonName = "关闭弹窗", + isIgnored = isIgnored + ) + callback() + }, + extraConfig = DialogHelper.Config(centerTitle = true) + ) + } + + private fun directToLink( + context: Context, + guide: NewApiSettingsEntity.Guide, + gameId: String, + gameName: String, + gameType: String, + isEnhancedMode: Boolean, + isIgnored: Boolean + ) { + DirectUtils.directToLinkPage(context, guide.link, "纯净模式弹窗", "") + trackDialogClicked( + isEnhancedMode, + gameId, + gameName, + gameType, + "跳转链接", + isIgnored, + guide.link.link ?: "", + guide.link.type ?: "", + guide.link.text ?: "" + ) + } + + private fun trackDialogShow( + isEnhancedMode: Boolean, + gameId: String, + gameName: String, + gameType: String + ) { + if (isEnhancedMode) { + SensorsBridge.trackAddedProtectionDialogShow( + gameId = gameId, + gameName = gameName, + gameType = gameType + ) + } else { + SensorsBridge.trackPureModeDialogShow( + gameId = gameId, + gameName = gameName, + gameType = gameType + ) + } + } + + private fun trackDialogClicked( + isEnhancedMode: Boolean, + gameId: String, + gameName: String, + gameType: String, + buttonName: String, + isIgnored: Boolean, + linkId: String? = null, + linkType: String? = null, + linkText: String? = null + ) { + if (isEnhancedMode) { + SensorsBridge.trackAddedProtectionDialogClick( + gameId = gameId, + gameName = gameName, + gameType = gameType, + buttonName = buttonName, + isIgnored = isIgnored, + linkId = linkId ?: "", + linkType = linkType ?: "", + linkText = linkText ?: "" + ) + } else { + SensorsBridge.trackPureModeDialogClick( + gameId = gameId, + gameName = gameName, + gameType = gameType, + buttonName = buttonName, + isIgnored = isIgnored, + linkId = linkId ?: "", + linkType = linkType ?: "", + linkText = linkText ?: "" + ) + } + } + + private fun toHWPureModeSetting(context: Context) { + try { + val intent = Intent() + intent.setPackage("com.huawei.security.privacycenter") + intent.setAction("com.huawei.securitycenter.PURE_MODE_ACTIVITY") + intent.putExtra("intent_from_settings", true) + context.startActivity(intent) + } catch (_: Exception) { + toSystemSettings(context) + } + } + + private fun toSystemSettings(context: Context) { + try { + val intent = Intent(Settings.ACTION_SETTINGS) + context.startActivity(intent) + } catch (e: Exception) { + e.printStackTrace() + } + } + + private fun readState(context: Context, key: String): Int { + try { + val result = Settings.Secure.getInt(context.getContentResolver(), key, SWITCH_OFF) + Utils.log(TAG, "readState $key state >>> $result") + return result + } catch (e: Exception) { + e.printStackTrace() + } + return SWITCH_OFF + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/gh/gamecenter/entity/NewApiSettingsEntity.kt b/app/src/main/java/com/gh/gamecenter/entity/NewApiSettingsEntity.kt index b238ccd47a..1c76a6564d 100644 --- a/app/src/main/java/com/gh/gamecenter/entity/NewApiSettingsEntity.kt +++ b/app/src/main/java/com/gh/gamecenter/entity/NewApiSettingsEntity.kt @@ -35,24 +35,43 @@ class NewApiSettingsEntity( val install: Boolean ) - // VPN 配置 class Install( - @SerializedName("vpn_required") - val vpnRequired: VpnSetting? = null, @SerializedName("guides") val guides: List? = null ) - class VpnSetting( - @SerializedName("current_device") - val shouldShowVpnOption: Boolean, - @SerializedName("packages") - val vpnMatchedPackagesName: HashSet - ) - + /** + * 当为鸿蒙纯净模式相关时 + * { + * "type': "harmony_os_pure_mode", // 华为鸿蒙系统纯净模式相关 harmony_os_pure_mode/harmony_os_pure_enhanced_mode + * "link": { + * "type": "qa_content", + * "link": "61026d03802abe4d7260fdc3", + * "text": "点击查看教程" // 链接文案,有设置时替换该字段,无设置时读取对应通用链接原本的文案 + * }, + * "title": "", + * "content": "", + * "link_text_prefix": "关闭场景模式:", // 链接引导文案 + * "button_text_close": "", // 关闭按钮 + * "button_text_setting_jump": "", // 前往设置按钮 + * "dialog_frequency": "once" // once/every_time + * } + */ class Guide( val type: String, - val link: LinkEntity + val link: LinkEntity, + val title: String = "", + val content: String = "", + @SerializedName("link_text_prefix") + val linkTextPrefix: String = "", + @SerializedName("link_text") + val linkText: String = "", + @SerializedName("button_text_close") + val buttonTextClose: String = "", + @SerializedName("button_text_setting_jump") + val buttonTextSettingJump: String = "", + @SerializedName("dialog_frequency") + val dialogFrequency: String = "", ) class PackageObserveActions( diff --git a/app/src/main/java/com/gh/gamecenter/gamedetail/desc/DescViewModel.kt b/app/src/main/java/com/gh/gamecenter/gamedetail/desc/DescViewModel.kt index fbb6101940..924e59b6c9 100644 --- a/app/src/main/java/com/gh/gamecenter/gamedetail/desc/DescViewModel.kt +++ b/app/src/main/java/com/gh/gamecenter/gamedetail/desc/DescViewModel.kt @@ -24,7 +24,6 @@ import com.gh.gamecenter.retrofit.RetrofitManager import com.google.gson.JsonArray import com.google.gson.reflect.TypeToken import com.halo.assistant.HaloApp -import com.walkud.rom.checker.RomIdentifier import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.schedulers.Schedulers import okhttp3.ResponseBody @@ -213,7 +212,7 @@ class DescViewModel( params["source"] = HaloApp.getInstance().application.getString(R.string.app_name) params["jnfj"] = MetaUtil.getBase64EncodedIMEI() params["manufacturer"] = Build.MANUFACTURER - params["rom"] = RomIdentifier.getRom().name + " " + RomIdentifier.getRom().versionName + params["rom"] = MetaUtil.getRom().name + " " + MetaUtil.getRom().versionName params["suggestion_type"] = "游戏求更新" params["game_id"] = game?.id ?: "" diff --git a/app/src/main/java/com/gh/gamecenter/gamedetail/rating/edit/RatingEditActivity.kt b/app/src/main/java/com/gh/gamecenter/gamedetail/rating/edit/RatingEditActivity.kt index c8d1d3cc1f..9c475ed870 100644 --- a/app/src/main/java/com/gh/gamecenter/gamedetail/rating/edit/RatingEditActivity.kt +++ b/app/src/main/java/com/gh/gamecenter/gamedetail/rating/edit/RatingEditActivity.kt @@ -17,7 +17,6 @@ import com.gh.common.DefaultJsApi import com.gh.common.util.* import com.gh.common.util.NewFlatLogUtils import com.gh.common.util.NewLogUtils -import com.gh.gamecenter.BuildConfig import com.gh.gamecenter.R import com.gh.gamecenter.ShellActivity import com.gh.gamecenter.WebActivity @@ -31,6 +30,7 @@ import com.gh.gamecenter.common.entity.ErrorEntity import com.gh.gamecenter.common.entity.NotificationUgc import com.gh.gamecenter.common.entity.SimpleGameEntity import com.gh.gamecenter.common.entity.SuggestType +import com.gh.gamecenter.common.exposure.meta.MetaUtil import com.gh.gamecenter.common.mvvm.Status import com.gh.gamecenter.common.utils.* import com.gh.gamecenter.common.view.dsbridge.DWebView @@ -44,7 +44,6 @@ import com.gh.gamecenter.feature.entity.GameEntity import com.gh.gamecenter.login.user.UserManager import com.halo.assistant.HaloApp import com.lightgame.utils.Utils -import com.walkud.rom.checker.RomIdentifier import okhttp3.MediaType import okhttp3.RequestBody import org.json.JSONObject @@ -539,7 +538,7 @@ class RatingEditActivity : ToolBarActivity(), KeyboardHeightObserver { jsonObject.put("game_version", gameVersion) jsonObject.put("source", if (mFromAmway) "anliwall" else "game_detail") jsonObject.put("plugin_version", PackageUtils.getMetaData(this, mInstallPackageName, "gh_version")) - jsonObject.put("rom", RomIdentifier.getRom().name + " " + RomIdentifier.getRom().versionName) + jsonObject.put("rom", MetaUtil.getRom().name + " " + MetaUtil.getRom().versionName) jsonObject.put("again", again) val body = RequestBody.create(MediaType.parse("application/json"), jsonObject.toString()) diff --git a/app/src/main/java/com/gh/gamecenter/vpn/VpnHelper.kt b/app/src/main/java/com/gh/gamecenter/vpn/VpnHelper.kt deleted file mode 100644 index 8996364eb2..0000000000 --- a/app/src/main/java/com/gh/gamecenter/vpn/VpnHelper.kt +++ /dev/null @@ -1,124 +0,0 @@ -package com.gh.gamecenter.vpn - -import android.content.Context -import android.os.Build -import android.os.ParcelFileDescriptor -import androidx.appcompat.app.AppCompatActivity -import com.alibaba.android.arouter.launcher.ARouter -import com.gh.common.constant.Config -import com.gh.download.PackageObserver -import com.gh.gamecenter.common.constant.RouteConsts -import com.gh.gamecenter.core.provider.IVpnProvider -import com.gh.gamecenter.core.utils.SPUtils -import com.gh.gamecenter.eventbus.EBPackage -import com.lightgame.utils.Utils -import java.util.* - -object VpnHelper { - - private const val TAG = "VPN" - private const val KEY_IS_FIRST_TIME_TO_SHOW_VPN_HINT_DIALOG = "is_first_time_to_show_vpn_hint_dialog" - private const val KEY_IGNORED_VPN_HINT_DIALOG = "ignored_vpn_hint_dialog" // 忽略 VPN 提示弹窗 - private const val KEY_IGNORED_VPN_FUNCTION = "ignored_vpn_function" // 忽略 VPN 功能 - private const val STOP_VPN_COUNT_DOWN_INTERVAL = 30 * 1000L // 30 秒后自动停止 VPN 功能 - - private var mCountDownTimer: Timer? = null - private var mPfd: ParcelFileDescriptor? = null - - private val mVpnProvider by lazy { - ARouter.getInstance().build(RouteConsts.provider.vpn).navigation() as? IVpnProvider - } - - private var mPackageChangedListener: PackageObserver.PackageChangeListener? = null - - /** - * 仅后台配置打开且手机系统大于 5.0 时才启用 VPN 功能 - */ - fun shouldUseVpn() = Config.isVpnOptionEnabled() - && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP - && !SPUtils.getBoolean(KEY_IGNORED_VPN_FUNCTION, false) - && mVpnProvider != null - - fun isTheFistTimeToShowVpnHintDialog() = SPUtils.getBoolean(KEY_IS_FIRST_TIME_TO_SHOW_VPN_HINT_DIALOG, true) - - /** - * 标记 VPN 提示弹窗已显示 - */ - fun setVpnHintDialogShowed() = SPUtils.setBoolean(KEY_IS_FIRST_TIME_TO_SHOW_VPN_HINT_DIALOG, false) - - /** - * 是否需要显示 VPN 提示弹窗 - */ - fun shouldShowVpnHintDialog() = !SPUtils.getBoolean(KEY_IGNORED_VPN_HINT_DIALOG, false) - - /** - * 忽略 VPN 提示弹窗,不再询问 - */ - fun ignoreVpnHintDialog() = SPUtils.setBoolean(KEY_IGNORED_VPN_HINT_DIALOG, true) - - /** - * 忽略 VPN 功能,不在启用 - */ - fun ignoreVpnFunction() = SPUtils.setBoolean(KEY_IGNORED_VPN_FUNCTION, true) - - fun isVpnPermissionGranted(activity: AppCompatActivity) = mVpnProvider?.isVpnPermissionGranted(activity) - - fun startVpn(activity: AppCompatActivity, onVpnStartedCallback: ((Boolean) -> Unit)) { - val applicationContext = activity.applicationContext - val packagesSet = Config.getNewApiSettingsEntity()?.install?.vpnRequired?.vpnMatchedPackagesName - - if (packagesSet.isNullOrEmpty()) { - Utils.log(TAG, "vpn matched packages is empty, vpn is disabled") - return - } - - startVpn(activity, packagesSet, onVpnStartedCallback) - - mPackageChangedListener = PackageObserver.PackageChangeListener { - if (it.type == EBPackage.TYPE_INSTALLED) { - stopVpnIfNeeded(applicationContext) - } - } - - - if (mCountDownTimer == null) { - mCountDownTimer = Timer() - } - - val task: TimerTask = object : TimerTask() { - override fun run() { - stopVpnIfNeeded(applicationContext) - } - } - - mCountDownTimer?.schedule(task, STOP_VPN_COUNT_DOWN_INTERVAL) - - PackageObserver.registerPackageChangeChangeListener(mPackageChangedListener!!) - } - - private fun startVpn( - activity: AppCompatActivity, - noInternetConnectionPackageNameSet: HashSet, - onVpnStartedCallback: ((Boolean) -> Unit) - ) { - mVpnProvider?.startVpn(activity, noInternetConnectionPackageNameSet, onVpnStartedCallback) { pfd -> - mPfd = pfd - } - } - - fun stopVpnIfNeeded(context: Context) { - if (mPfd != null) { - mVpnProvider?.stopVpn(context, mPfd) - mPfd = null - } - - mCountDownTimer?.cancel() - mCountDownTimer = null - - mPackageChangedListener?.let { - PackageObserver.unregisterPackageChangeChangeListener(it) - } - mPackageChangedListener = null - } - -} \ No newline at end of file diff --git a/app/src/main/java/com/gh/gamecenter/wrapper/MainWrapperFragment.kt b/app/src/main/java/com/gh/gamecenter/wrapper/MainWrapperFragment.kt index c1ad2591f4..f957bb2dcc 100644 --- a/app/src/main/java/com/gh/gamecenter/wrapper/MainWrapperFragment.kt +++ b/app/src/main/java/com/gh/gamecenter/wrapper/MainWrapperFragment.kt @@ -12,6 +12,7 @@ import androidx.core.text.color import androidx.core.view.doOnNextLayout import androidx.viewpager2.adapter.FragmentStateAdapter import com.gh.common.util.PackageHelper +import com.gh.common.util.PureModeHelper import com.gh.gamecenter.R import com.gh.gamecenter.ShellActivity import com.gh.gamecenter.common.base.fragment.ToolbarFragment diff --git a/app/src/main/java/com/gh/vspace/VFeedbackDialogFragment.kt b/app/src/main/java/com/gh/vspace/VFeedbackDialogFragment.kt index dad7a1f1ff..8e91528123 100644 --- a/app/src/main/java/com/gh/vspace/VFeedbackDialogFragment.kt +++ b/app/src/main/java/com/gh/vspace/VFeedbackDialogFragment.kt @@ -27,7 +27,6 @@ import com.gh.gamecenter.retrofit.RetrofitManager import com.halo.assistant.HaloApp import com.lightgame.utils.Utils import com.lightgame.utils.toast.ToastHelper -import com.walkud.rom.checker.RomIdentifier import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.schedulers.Schedulers import kotlinx.parcelize.Parcelize @@ -227,7 +226,7 @@ class VFeedbackDialogFragment : BaseDialogFragment() { "source" to HaloApp.getInstance().application.getString(R.string.app_name) "jnfj" to MetaUtil.getBase64EncodedIMEI() "manufacturer" to Build.MANUFACTURER - "rom" to RomIdentifier.getRom().name + " " + RomIdentifier.getRom().versionName + "rom" to MetaUtil.getRom().name + " " + MetaUtil.getRom().versionName "suggestion_type" to "游戏问题" "game_id" to game.id diff --git a/feature/new_feedback/src/main/java/com/gh/gamecenter/feedback/view/qa/QaFeedbackViewModel.kt b/feature/new_feedback/src/main/java/com/gh/gamecenter/feedback/view/qa/QaFeedbackViewModel.kt index 912f1be1c4..ad69062bab 100644 --- a/feature/new_feedback/src/main/java/com/gh/gamecenter/feedback/view/qa/QaFeedbackViewModel.kt +++ b/feature/new_feedback/src/main/java/com/gh/gamecenter/feedback/view/qa/QaFeedbackViewModel.kt @@ -9,6 +9,7 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider import com.alibaba.android.arouter.launcher.ARouter import com.gh.gamecenter.common.constant.RouteConsts +import com.gh.gamecenter.common.exposure.meta.MetaUtil import com.gh.gamecenter.common.exposure.meta.MetaUtil.getBase64EncodedIMEI import com.gh.gamecenter.common.retrofit.BiResponse import com.gh.gamecenter.common.utils.singleToMain @@ -18,7 +19,6 @@ import com.gh.gamecenter.core.provider.IPackageUtilsProvider import com.gh.gamecenter.feedback.HaloApp import com.gh.gamecenter.feedback.R import com.gh.gamecenter.feedback.retrofit.RetrofitManager -import com.walkud.rom.checker.RomIdentifier import okhttp3.ResponseBody class QaFeedbackViewModel(application: Application, private val contentId: String) : AndroidViewModel(application) { @@ -40,7 +40,7 @@ class QaFeedbackViewModel(application: Application, private val contentId: Strin map["source"] = HaloApp.getInstance().getString(R.string.app_name) map["jnfj"] = getBase64EncodedIMEI() map["manufacturer"] = Build.MANUFACTURER - map["rom"] = RomIdentifier.getRom().name + " " + RomIdentifier.getRom().versionName + map["rom"] = MetaUtil.getRom().name + " " + MetaUtil.getRom().versionName val requestBody = map.toRequestBody() RetrofitManager.getInstance().api diff --git a/feature/new_feedback/src/main/java/com/gh/gamecenter/feedback/view/suggest/SuggestViewModel.kt b/feature/new_feedback/src/main/java/com/gh/gamecenter/feedback/view/suggest/SuggestViewModel.kt index fa9683a5e2..8de4fa450d 100644 --- a/feature/new_feedback/src/main/java/com/gh/gamecenter/feedback/view/suggest/SuggestViewModel.kt +++ b/feature/new_feedback/src/main/java/com/gh/gamecenter/feedback/view/suggest/SuggestViewModel.kt @@ -15,6 +15,7 @@ import com.gh.gamecenter.common.constant.Constants import com.gh.gamecenter.common.constant.RouteConsts import com.gh.gamecenter.common.entity.ErrorEntity import com.gh.gamecenter.common.entity.SuggestType +import com.gh.gamecenter.common.exposure.meta.MetaUtil import com.gh.gamecenter.common.exposure.meta.MetaUtil.getBase64EncodedIMEI import com.gh.gamecenter.common.json.json import com.gh.gamecenter.common.retrofit.BiResponse @@ -34,7 +35,6 @@ import com.gh.gamecenter.feedback.entity.ContactType import com.gh.gamecenter.feedback.entity.SuggestionProblem import com.gh.gamecenter.feedback.retrofit.RetrofitManager import com.lightgame.utils.Utils -import com.walkud.rom.checker.RomIdentifier import okhttp3.ResponseBody import org.json.JSONArray import org.json.JSONObject @@ -210,7 +210,7 @@ class SuggestViewModel( "source" to getApplication().getString(R.string.app_name) "jnfj" to getBase64EncodedIMEI() "manufacturer" to Build.MANUFACTURER - "rom" to RomIdentifier.getRom().name + " " + RomIdentifier.getRom().versionName + "rom" to MetaUtil.getRom().name + " " + MetaUtil.getRom().versionName "suggestion_type" to suggestType "from" to contact "contact_func" to contactType.value @@ -320,7 +320,7 @@ class SuggestViewModel( "source" to getApplication().getString(R.string.app_name) "jnfj" to getBase64EncodedIMEI() "manufacturer" to Build.MANUFACTURER - "rom" to RomIdentifier.getRom().name + " " + RomIdentifier.getRom().versionName + "rom" to MetaUtil.getRom().name + " " + MetaUtil.getRom().versionName "suggestion_type" to mSuggestType "app_name" to appName "owner_type" to copyrightIdentity diff --git a/feature/vpn/.gitignore b/feature/vpn/.gitignore deleted file mode 100644 index 42afabfd2a..0000000000 --- a/feature/vpn/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build \ No newline at end of file diff --git a/feature/vpn/build.gradle b/feature/vpn/build.gradle deleted file mode 100644 index 2ee804ba47..0000000000 --- a/feature/vpn/build.gradle +++ /dev/null @@ -1,69 +0,0 @@ -if (isRelease.toBoolean()) { - apply plugin: 'com.android.library' -} else { - apply plugin: 'com.android.application' -} -apply plugin: 'org.jetbrains.kotlin.android' -apply plugin: 'kotlin-kapt' -apply plugin: 'kotlin-parcelize' - -android { - compileSdkVersion rootProject.ext.compileSdkVersion - - defaultConfig { - if (!isRelease.toBoolean()) { - applicationId "com.gh.vpn" - multiDexEnabled true - } - minSdk rootProject.ext.minSdkVersion - targetSdkVersion rootProject.ext.targetSdkVersion - versionCode rootProject.ext.versionCode - versionName rootProject.ext.versionName - - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - } - - sourceSets { - main { - if (isRelease.toBoolean()) { - manifest.srcFile 'src/main/AndroidManifest.xml' - java { - exclude 'manifest/**' - } - } else { - java { - srcDirs = ['src/main/java', "src/vpn/java"] - } - manifest.srcFile 'src/main/manifest/AndroidManifest.xml' - res.srcDirs = ['src/main/res','src/vpn/res'] - } - } - } - - kapt { - arguments { - arg("AROUTER_MODULE_NAME", project.name) - } - } - - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - - kotlinOptions { - jvmTarget = '1.8' - } -} - -dependencies { - implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs') - kapt "com.alibaba:arouter-compiler:$arouterVersion" - if (!isRelease.toBoolean()) { - implementation "androidx.multidex:multidex:${multiDex}" - } - - implementation(project(path: ":module_common")) { - exclude group: 'androidx.swiperefreshlayout' - } -} \ No newline at end of file diff --git a/feature/vpn/proguard-rules.pro b/feature/vpn/proguard-rules.pro deleted file mode 100644 index 817f2247a0..0000000000 --- a/feature/vpn/proguard-rules.pro +++ /dev/null @@ -1,25 +0,0 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile - --renamesourcefileattribute SourceFile -# Keep Attribute --keepattributes *Annotation*,Signature,InnerClasses,EnclosingMethod,SourceFile,LineNumberTable \ No newline at end of file diff --git a/feature/vpn/src/main/AndroidManifest.xml b/feature/vpn/src/main/AndroidManifest.xml deleted file mode 100644 index 03a59a3d9c..0000000000 --- a/feature/vpn/src/main/AndroidManifest.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/feature/vpn/src/main/java/com/gh/gamecenter/vpn/HaloApp.kt b/feature/vpn/src/main/java/com/gh/gamecenter/vpn/HaloApp.kt deleted file mode 100644 index 8329fd58fa..0000000000 --- a/feature/vpn/src/main/java/com/gh/gamecenter/vpn/HaloApp.kt +++ /dev/null @@ -1,44 +0,0 @@ -package com.gh.gamecenter.vpn - -import android.app.Application -import android.content.res.Configuration -import com.gh.gamecenter.core.iinterface.IApplication -import com.google.auto.service.AutoService - -@AutoService(IApplication::class) -class HaloApp : IApplication { - - override fun attachBaseContext() { - // Do nothing - } - - override fun onCreate(application: Application) { - mApp = application - } - - - override fun onLowMemory() { - // Do nothing - } - - override fun onTerminate() { - // Do nothing - } - - override fun onTrimMemory(level: Int) { - // Do nothing - } - - override fun onConfigurationChanged(newConfig: Configuration) { - // Do nothing - } - - companion object { - private lateinit var mApp: Application - - @JvmStatic - fun getInstance(): Application { - return mApp - } - } -} diff --git a/feature/vpn/src/main/java/com/gh/gamecenter/vpn/HaloVpnService.kt b/feature/vpn/src/main/java/com/gh/gamecenter/vpn/HaloVpnService.kt deleted file mode 100644 index 51024a5592..0000000000 --- a/feature/vpn/src/main/java/com/gh/gamecenter/vpn/HaloVpnService.kt +++ /dev/null @@ -1,97 +0,0 @@ -package com.gh.gamecenter.vpn - -import android.app.NotificationChannel -import android.app.NotificationManager -import android.content.Context -import android.content.Intent -import android.content.pm.PackageManager -import android.net.VpnService -import android.os.Build -import android.os.ParcelFileDescriptor -import androidx.annotation.RequiresApi -import androidx.core.app.NotificationCompat -import com.lightgame.R -import com.lightgame.download.ForegroundNotificationManager -import com.lightgame.utils.Utils -import java.io.IOException -import java.util.* - -class HaloVpnService : VpnService() { - - private var mForegroundNotificationManager: ForegroundNotificationManager? = null - - override fun onCreate() { - super.onCreate() - - mForegroundNotificationManager = ForegroundNotificationManager(this, this.application) - startForegroundIfNeeded() - } - - override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { - val serviceAction = intent?.getStringExtra(KEY_ACTION_TYPE) - - if (serviceAction == ACTION_STOP) { - mForegroundNotificationManager?.cancel(FOREGROUND_ID) - stopSelf() - } - - // 不需要 intent 为空的重建 - return START_NOT_STICKY - } - - private fun startForegroundIfNeeded() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - val channel = NotificationChannel("VPN", "Halo VPN", NotificationManager.IMPORTANCE_LOW) - val manager = applicationContext.getSystemService(NOTIFICATION_SERVICE) as NotificationManager - manager.createNotificationChannel(channel) - val notification = NotificationCompat.Builder(this, "VPN") - .setSmallIcon(R.drawable.ic_download_notification) - .build() - if (mForegroundNotificationManager != null) { - mForegroundNotificationManager?.notify(FOREGROUND_ID, notification) - } - } - } - - companion object { - - const val KEY_ACTION_TYPE = "action_type" - const val ACTION_STOP = "stop" - const val FOREGROUND_ID = 1011 - - @RequiresApi(Build.VERSION_CODES.LOLLIPOP) - fun prepare(context: Context): Intent? { - return VpnService.prepare(context) - } - - @RequiresApi(Build.VERSION_CODES.LOLLIPOP) - fun startVPN(noInternetConnectionPackageNameSet: HashSet): ParcelFileDescriptor? { - val builder = HaloVpnService().Builder() - builder.addAddress("10.1.10.1", 32) - builder.addAddress("fd00:1:fd00:1:fd00:1:fd00:1", 128) - builder.setMtu(10000) - builder.addRoute("0.0.0.0", 0) - builder.addRoute("2000::", 3) - - for (packageName in noInternetConnectionPackageNameSet) { - try { - builder.addAllowedApplication(packageName) - } catch (e: PackageManager.NameNotFoundException) { - e.printStackTrace() - } - } - - return builder.establish() - } - - fun stopVPN(pfd: ParcelFileDescriptor) { - try { - pfd.close() - } catch(e: IOException) { - Utils.log("VPN", "encounter error while trying to stop VPN, ${e.localizedMessage}") - } - } - - } - -} \ No newline at end of file diff --git a/feature/vpn/src/main/java/com/gh/gamecenter/vpn/VpnProviderImpl.kt b/feature/vpn/src/main/java/com/gh/gamecenter/vpn/VpnProviderImpl.kt deleted file mode 100644 index 9c1c4c7abf..0000000000 --- a/feature/vpn/src/main/java/com/gh/gamecenter/vpn/VpnProviderImpl.kt +++ /dev/null @@ -1,88 +0,0 @@ -package com.gh.gamecenter.vpn - -import android.app.Activity -import android.content.Context -import android.content.Intent -import android.os.Build -import android.os.ParcelFileDescriptor -import androidx.annotation.RequiresApi -import androidx.appcompat.app.AppCompatActivity -import com.alibaba.android.arouter.facade.annotation.Route -import com.gh.gamecenter.common.activityresult.ActResultRequest -import com.gh.gamecenter.common.constant.RouteConsts -import com.gh.gamecenter.core.provider.IVpnProvider -import java.util.HashSet - -@Route(path = RouteConsts.provider.vpn, name = "VPN 暴露服务") -class VpnProviderImpl : IVpnProvider { - - @RequiresApi(Build.VERSION_CODES.LOLLIPOP) - override fun isVpnPermissionGranted(activity: AppCompatActivity): Boolean { - return (HaloVpnService.prepare(activity) == null) - } - - /** - * @param packageNameSet 要应用 VPN 的包名列表 - * @param vpnStartedCallback 启动 VPN 的回调,值为 true 代表遇到错误 - */ - @RequiresApi(Build.VERSION_CODES.LOLLIPOP) - override fun startVpn( - activity: AppCompatActivity, - packageNameSet: HashSet, - vpnStartedCallback: ((containsError: Boolean) -> Unit), - pfdCreatedCallback: ((pfd: ParcelFileDescriptor?) -> Unit) - ) { - val intent = HaloVpnService.prepare(activity) - if (intent != null) { - try { - ActResultRequest(activity).startForResult(intent) { resultCode, _ -> - if (resultCode == Activity.RESULT_OK) { - pfdCreatedCallback.invoke(startVpn(activity, packageNameSet)) - vpnStartedCallback.invoke(false) - } else if (resultCode == Activity.RESULT_CANCELED) { - vpnStartedCallback.invoke(false) - } - } - } catch (e: Exception) { - e.printStackTrace() - pfdCreatedCallback.invoke(null) - vpnStartedCallback.invoke(true) - } - } else { - pfdCreatedCallback.invoke(startVpn(activity, packageNameSet)) - vpnStartedCallback.invoke(false) - } - } - - @RequiresApi(Build.VERSION_CODES.LOLLIPOP) - private fun startVpn( - activity: AppCompatActivity, - packageNameSet: HashSet, - ): ParcelFileDescriptor? { - val pfd: ParcelFileDescriptor? = HaloVpnService.startVPN(packageNameSet) - val serviceIntent = Intent(activity, HaloVpnService::class.java) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - activity.startForegroundService(serviceIntent) - } else { - activity.startService(serviceIntent) - } - - return pfd - } - - override fun stopVpn(context: Context, pfd: ParcelFileDescriptor?) { - val intent = Intent(context, HaloVpnService::class.java) - intent.putExtra(HaloVpnService.KEY_ACTION_TYPE, HaloVpnService.ACTION_STOP) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - context.startForegroundService(intent) - } else { - context.startService(intent) - } - HaloVpnService.stopVPN(pfd!!) - } - - override fun init(context: Context?) { - // do nothing - } - -} \ No newline at end of file diff --git a/feature/vpn/src/main/manifest/AndroidManifest.xml b/feature/vpn/src/main/manifest/AndroidManifest.xml deleted file mode 100644 index 4f14054c58..0000000000 --- a/feature/vpn/src/main/manifest/AndroidManifest.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/feature/vpn/src/main/res/values-zh-rTW/strings.xml b/feature/vpn/src/main/res/values-zh-rTW/strings.xml deleted file mode 100644 index a389d6dd4d..0000000000 --- a/feature/vpn/src/main/res/values-zh-rTW/strings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - VPN - diff --git a/feature/vpn/src/main/res/values/strings.xml b/feature/vpn/src/main/res/values/strings.xml deleted file mode 100644 index c7679bc0c5..0000000000 --- a/feature/vpn/src/main/res/values/strings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - VPN - diff --git a/feature/vpn/src/vpn/java/com/gh/gamecenter/vpn/VpnModuleApp.kt b/feature/vpn/src/vpn/java/com/gh/gamecenter/vpn/VpnModuleApp.kt deleted file mode 100644 index be28f5aabe..0000000000 --- a/feature/vpn/src/vpn/java/com/gh/gamecenter/vpn/VpnModuleApp.kt +++ /dev/null @@ -1,36 +0,0 @@ -package com.gh.gamecenter.vpn - -import androidx.multidex.MultiDexApplication -import com.alibaba.android.arouter.launcher.ARouter -import com.gh.gamecenter.core.iinterface.IApplication -import java.util.* - -class VpnModuleApp : MultiDexApplication() { - - private val mApplicationList = ServiceLoader.load(IApplication::class.java, this.javaClass.classLoader) - - override fun onCreate() { - super.onCreate() - initArouter() - mApp = this - for (application in mApplicationList) { - application.onCreate(this) - } - } - - private fun initArouter() { - if (BuildConfig.DEBUG) { // 这两行必须写在init之前,否则这些配置在init过程中将无效 - ARouter.openLog() // 打印日志 - ARouter.openDebug() // 开启调试模式(如果在InstantRun模式下运行,必须开启调试模式!线上版本需要关闭,否则有安全风险) - } - ARouter.init(this) // 尽可能早,推荐在Application中初始化 - } - - companion object { - private lateinit var mApp: VpnModuleApp - - fun getInstance(): VpnModuleApp { - return mApp - } - } -} \ No newline at end of file diff --git a/feature/vpn/src/vpn/java/com/gh/gamecenter/vpn/provider/AppProviderImpl.kt b/feature/vpn/src/vpn/java/com/gh/gamecenter/vpn/provider/AppProviderImpl.kt deleted file mode 100644 index 5e17ce3509..0000000000 --- a/feature/vpn/src/vpn/java/com/gh/gamecenter/vpn/provider/AppProviderImpl.kt +++ /dev/null @@ -1,107 +0,0 @@ -package com.gh.gamecenter.vpn.provider - -import android.app.Activity -import android.app.Application -import android.content.Context -import com.alibaba.android.arouter.facade.annotation.Route -import com.gh.gamecenter.common.constant.RouteConsts -import com.gh.gamecenter.core.provider.IAppProvider -import com.gh.gamecenter.core.provider.IFlavorProvider -import com.gh.gamecenter.vpn.BuildConfig -import com.gh.gamecenter.vpn.HaloApp -import com.gh.gamecenter.vpn.R - -@Route(path = RouteConsts.provider.app, name = "Application暴露服务") -class AppProviderImpl : IAppProvider { - override fun init(context: Context?) { - // Do nothing - } - - override fun get(key: String, isRemove: Boolean): Any? { - return "" - } - - override fun put(key: String, any: Any) { - // do nothing - } - - override fun getAppName(): String { - return HaloApp.getInstance().getString(R.string.app_name) - } - - override fun getAppVersion(): String { - return BuildConfig.VERSION_NAME - } - - override fun getGid(): String { - return "" - } - - override fun refreshGid() { - // Do nothing - } - - override fun getOaid(): String { - return "" - } - - override fun getChannel(): String { - return "" - } - - override fun setChannel(channel: String) { - // Do nothing - } - - override fun getUserAgent(): String { - return "" - } - - override fun getServerUserMark(): String { - return "" - } - - override fun getDeviceRamSize(): Long { - return 0L - } - - override fun getTemporaryLocalDeviceId(): String { - return "" - } - - override fun getFlavorProvider(): IFlavorProvider { - return object : IFlavorProvider { - override fun getChannelStr(application: Application): String { - return "" - } - - override fun init(application: Application, activity: Activity, activateRatio: Int) { - // do nothing - } - - override fun logEvent(content: String) { - // do nothing - } - - override fun logCoreEvent() { - // do nothing - } - } - } - - override fun getFlavor(): String { - return "internal" - } - - override fun isUserAcceptPrivacyPolicy(context: Context): Boolean { - return true - } - - override fun getIsBrandNewInstall(): Boolean { - return false - } - - override fun setSkippingThirdParty(isSkippingThirdParty: Boolean) { - // do nothing - } -} \ No newline at end of file diff --git a/feature/vpn/src/vpn/java/com/gh/gamecenter/vpn/view/VpnActivity.kt b/feature/vpn/src/vpn/java/com/gh/gamecenter/vpn/view/VpnActivity.kt deleted file mode 100644 index dfff3cde38..0000000000 --- a/feature/vpn/src/vpn/java/com/gh/gamecenter/vpn/view/VpnActivity.kt +++ /dev/null @@ -1,38 +0,0 @@ -package com.gh.gamecenter.vpn.view - -import android.os.Bundle -import android.os.ParcelFileDescriptor -import android.view.View -import androidx.appcompat.app.AppCompatActivity -import com.alibaba.android.arouter.launcher.ARouter -import com.gh.gamecenter.common.constant.RouteConsts -import com.gh.gamecenter.core.provider.IVpnProvider -import com.gh.gamecenter.vpn.R -import com.lightgame.utils.Utils - -class VpnActivity : AppCompatActivity() { - - private var mPfd: ParcelFileDescriptor? = null - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - - val vpnImpl = ARouter.getInstance().build(RouteConsts.provider.vpn).navigation() as? IVpnProvider - - setContentView(R.layout.activity_vpn) - - findViewById(R.id.btn).setOnClickListener { - if (mPfd == null) { - vpnImpl?.startVpn(this, hashSetOf("com.gh.gamecenter"), { - Utils.log("vpn started result is $it") - }, { - mPfd = it - }) - } else { - vpnImpl?.stopVpn(this, mPfd) - mPfd = null - } - } - } - -} \ No newline at end of file diff --git a/feature/vpn/src/vpn/res/layout/activity_vpn.xml b/feature/vpn/src/vpn/res/layout/activity_vpn.xml deleted file mode 100644 index 95b55a35a0..0000000000 --- a/feature/vpn/src/vpn/res/layout/activity_vpn.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - -