新增:按需启用Cactus增强保活措施的开关

This commit is contained in:
pppscn 2022-06-11 19:12:32 +08:00
parent 84994483d4
commit 20225ffbfd
9 changed files with 107 additions and 66 deletions

View File

@ -86,9 +86,11 @@ PS.如果QQ群已满员请看群简介加入其他群
+ https://github.com/xiaoyuanhost/TranspondSms (项目原型)
+ https://github.com/xuexiangjys/XUI UI框架
+ https://github.com/xuexiangjys/XUpdateAPI (在线升级)
+ https://github.com/xuexiangjys/XUpdate (在线升级)
+ https://github.com/getActivity/XXPermissions (权限请求框架)
+ https://github.com/mainfunx/frpc_android (内网穿透)
+ https://github.com/gyf-dev/Cactus (保活措施)
+ https://github.com/yanzhenjie/AndServer (HttpServer)
+ [<img src="https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.svg?_ga=2.126618957.1361252949.1638261367-1417196221.1635638144&_gl=1*1pfl3dq*_ga*MTQxNzE5NjIyMS4xNjM1NjM4MTQ0*_ga_V0XZL7QHEB*MTYzODMzMjA4OC43LjAuMTYzODMzMjA5Ny4w" alt="GitHub license" style="zoom:50%;" />](https://jb.gg/OpenSourceSupport) (License Certificate for JetBrains All Products Pack)
--------

View File

@ -77,9 +77,11 @@ PS.If the QQ group is full, please see the group introduction to join other grou
+ https://github.com/xiaoyuanhost/TranspondSms (Foundation of `SmsForwarder`)
+ https://github.com/xuexiangjys/XUI UI Framework
+ https://github.com/xuexiangjys/XUpdateAPI (online update)
+ https://github.com/xuexiangjys/XUpdate (online update)
+ https://github.com/getActivity/XXPermissions (permission requiring)
+ https://github.com/mainfunx/frpc_android (内网穿透)
+ https://github.com/mainfunx/frpc_android (reverse proxy)
+ https://github.com/gyf-dev/Cactus (Keep Alive)
+ https://github.com/yanzhenjie/AndServer (HttpServer)
+ [<img src="https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.svg?_ga=2.126618957.1361252949.1638261367-1417196221.1635638144&_gl=1*1pfl3dq*_ga*MTQxNzE5NjIyMS4xNjM1NjM4MTQ0*_ga_V0XZL7QHEB*MTYzODMzMjA4OC43LjAuMTYzODMzMjA5Ny4w" alt="GitHub license" style="zoom:50%;" />](https://jb.gg/OpenSourceSupport) (License Certificate for JetBrains All Products Pack)
--------

View File

@ -82,6 +82,8 @@ class App : Application(), CactusCallback, Configuration.Provider by Core {
//Cactus运行状态
val mStatus = MutableLiveData<Boolean>().apply { value = true }
var mDisposable: Disposable? = null
}
override fun attachBaseContext(base: Context) {
@ -139,7 +141,7 @@ class App : Application(), CactusCallback, Configuration.Provider by Core {
}
//Cactus 集成双进程前台服务JobScheduleronePix(一像素)WorkManager无声音乐
if (!isDebug) {
if (SettingUtils.enableCactus) {
//注册广播监听器
registerReceiver(CactusReceiver(), IntentFilter().apply {
addAction(Cactus.CACTUS_WORK)
@ -209,8 +211,6 @@ class App : Application(), CactusCallback, Configuration.Provider by Core {
ANRWatchDogInit.init()
}
private var mDisposable: Disposable? = null
@SuppressLint("CheckResult")
override fun doWork(times: Int) {
Log.d(TAG, "doWork:$times")

View File

@ -99,10 +99,9 @@ class SettingsFragment : BaseFragment<FragmentSettingsBinding?>(), View.OnClickL
batterySetting(binding!!.layoutBatterySetting, binding!!.sbBatterySetting)
//不在最近任务列表中显示
switchExcludeFromRecents(binding!!.layoutExcludeFromRecents, binding!!.sbExcludeFromRecents)
//后台播放无声音乐
switchPlaySilenceMusic(binding!!.sbPlaySilenceMusic)
//1像素透明Activity保活(只有在android p以下可以使用)
switchOnePixelActivity(binding!!.sbOnePixelActivity)
//Cactus增强保活措施
switchEnableCactus(binding!!.sbEnableCactus, binding!!.scbPlaySilenceMusic, binding!!.scbOnePixelActivity)
//接口请求失败重试时间间隔
editRetryDelayTime(binding!!.etRetryTimes, binding!!.etDelayTime, binding!!.etTimeout)
@ -525,25 +524,30 @@ class SettingsFragment : BaseFragment<FragmentSettingsBinding?>(), View.OnClickL
}
}
//后台播放无声音乐
@SuppressLint("ObsoleteSdkInt,UseSwitchCompatOrMaterialCode")
fun switchPlaySilenceMusic(sbPlaySilenceMusic: SwitchButton) {
sbPlaySilenceMusic.isChecked = SettingUtils.enablePlaySilenceMusic
sbPlaySilenceMusic.setOnCheckedChangeListener { _: CompoundButton?, isChecked: Boolean ->
//转发应用通知
@SuppressLint("UseSwitchCompatOrMaterialCode")
fun switchEnableCactus(sbEnableCactus: SwitchButton, scbPlaySilenceMusic: SmoothCheckBox, scbOnePixelActivity: SmoothCheckBox) {
val layoutCactusOptional: LinearLayout = binding!!.layoutCactusOptional
val isEnable: Boolean = SettingUtils.enableCactus
sbEnableCactus.isChecked = isEnable
layoutCactusOptional.visibility = if (isEnable) View.VISIBLE else View.GONE
sbEnableCactus.setOnCheckedChangeListener { _: CompoundButton?, isChecked: Boolean ->
layoutCactusOptional.visibility = if (isChecked) View.VISIBLE else View.GONE
SettingUtils.enableCactus = isChecked
}
scbPlaySilenceMusic.isChecked = SettingUtils.enablePlaySilenceMusic
scbPlaySilenceMusic.setOnCheckedChangeListener { _: SmoothCheckBox, isChecked: Boolean ->
SettingUtils.enablePlaySilenceMusic = isChecked
XToastUtils.warning(getString(R.string.need_to_restart))
}
}
//1像素透明Activity保活
@SuppressLint("ObsoleteSdkInt,UseSwitchCompatOrMaterialCode")
fun switchOnePixelActivity(sbOnePixelActivity: SwitchButton) {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.P) {
binding!!.layoutOnePixelActivity.visibility = View.VISIBLE
}
sbOnePixelActivity.isChecked = SettingUtils.enableOnePixelActivity
sbOnePixelActivity.setOnCheckedChangeListener { _: CompoundButton?, isChecked: Boolean ->
//if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.P) {
binding!!.layoutOnePixelActivity.visibility = View.VISIBLE
//}
scbOnePixelActivity.isChecked = SettingUtils.enableOnePixelActivity
scbOnePixelActivity.setOnCheckedChangeListener { _: SmoothCheckBox, isChecked: Boolean ->
SettingUtils.enableOnePixelActivity = isChecked
XToastUtils.warning(getString(R.string.need_to_restart))
}

View File

@ -65,6 +65,7 @@ const val SP_SMS_TEMPLATE = "sms_template"
const val SP_ENABLE_HELP_TIP = "enable_help_tip"
const val SP_PURE_CLIENT_MODE = "enable_pure_client_mode"
const val SP_ENABLE_CACTUS = "enable_cactus"
const val CACTUS_TIMER = "cactus_timer"
const val CACTUS_LAST_TIMER = "cactus_last_timer"
const val CACTUS_DATE = "cactus_date"

View File

@ -173,6 +173,14 @@ class SettingUtils private constructor() {
MMKVUtils.put(SP_ENABLE_EXCLUDE_FROM_RECENTS, enableExcludeFromRecents)
}
//是否转发应用通知
@JvmStatic
var enableCactus: Boolean
get() = MMKVUtils.getBoolean(SP_ENABLE_APP_NOTIFY, false)
set(enableAppNotify) {
MMKVUtils.put(SP_ENABLE_APP_NOTIFY, enableAppNotify)
}
//是否播放静音音乐
@JvmStatic
var enablePlaySilenceMusic: Boolean
@ -181,7 +189,7 @@ class SettingUtils private constructor() {
MMKVUtils.put(SP_ENABLE_PLAY_SILENCE_MUSIC, enablePlaySilenceMusic)
}
//是否不在最近任务列表中显示
//是否启用1像素
@JvmStatic
var enableOnePixelActivity: Boolean
get() = MMKVUtils.getBoolean(SP_ENABLE_ONE_PIXEL_ACTIVITY, false)

View File

@ -635,56 +635,74 @@
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/play_silence_music"
android:text="@string/enable_cactus"
android:textStyle="bold"
tools:ignore="RelativeOverlap" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/play_silence_music_tips"
android:text="@string/enabe_cactus_tips"
android:textSize="9sp"
tools:ignore="SmallSp" />
<LinearLayout
android:id="@+id/layout_cactus_optional"
android:layout_width="match_parent"
android:layout_height="25dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/optional_components"
android:textSize="10sp"
android:textStyle="bold"
tools:ignore="SmallSp" />
<com.xuexiang.xui.widget.button.SmoothCheckBox
android:id="@+id/scb_play_silence_music"
android:layout_width="15dp"
android:layout_height="15dp"
app:scb_color_checked="@color/colorPrimary" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="2dp"
android:text="@string/play_silence_music"
android:textSize="11sp" />
<LinearLayout
android:id="@+id/layout_one_pixel_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone">
<com.xuexiang.xui.widget.button.SmoothCheckBox
android:id="@+id/scb_one_pixel_activity"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_marginStart="5dp"
app:scb_color_checked="@color/colorPrimary" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="2dp"
android:text="@string/one_pixel_activity"
android:textSize="11sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<com.xuexiang.xui.widget.button.switchbutton.SwitchButton
android:id="@+id/sb_play_silence_music"
style="@style/SwitchButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="@+id/layout_one_pixel_activity"
style="@style/settingBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/one_pixel_activity"
android:textStyle="bold"
tools:ignore="RelativeOverlap" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/one_pixel_activity_tips"
android:textSize="9sp"
tools:ignore="SmallSp" />
</LinearLayout>
<com.xuexiang.xui.widget.button.switchbutton.SwitchButton
android:id="@+id/sb_one_pixel_activity"
android:id="@+id/sb_enable_cactus"
style="@style/SwitchButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

View File

@ -856,4 +856,7 @@
<string name="pure_client_mode_tips">When starting the APP, it will directly enter the active control client</string>
<string name="exit_pure_client_mode">Exit pure client mode</string>
<string name="enabling_pure_client_mode">Do you want to quit the app immediately and start it manually to take effect in pure client mode?</string>
<string name="optional_components">Optional:</string>
<string name="enable_cactus">Enable Cactus Keep Alive</string>
<string name="enabe_cactus_tips">Dual process foreground service/JobScheduler/WorkManager/1px/silent music</string>
</resources>

View File

@ -602,7 +602,7 @@
<string name="play_silence_music">后台播放无声音乐</string>
<string name="play_silence_music_tips">【按需启用】播放无声音乐让后台一直运行,可能比较耗电</string>
<string name="one_pixel">1像素</string>
<string name="one_pixel_activity">1像素透明Activity保活</string>
<string name="one_pixel_activity">1像素透明Activity</string>
<string name="one_pixel_activity_tips">【按需启用】使进程的优先级在屏幕锁屏时间由4提升为最高优先级1</string>
<string name="optional">可选</string>
<string name="TelegramChatIdTips">请按照wiki中的步骤获取</string>
@ -857,4 +857,7 @@
<string name="pure_client_mode_tips">启动APP时直接进入主动控制·客户端</string>
<string name="exit_pure_client_mode">退出纯客户端模式</string>
<string name="enabling_pure_client_mode">是否立即退出App并手动启动以生效纯客户端模式</string>
<string name="optional_components">可选组件:</string>
<string name="enable_cactus">启用 Cactus 增强保活措施(会增加耗电)</string>
<string name="enabe_cactus_tips">双进程前台服务/JobScheduler/WorkManager/1像素/无声音乐</string>
</resources>