diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f7fc9c2..fa56670 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -55,5 +55,11 @@ android:name=".ui.activity.ConfigureActivity" android:exported="true" android:screenOrientation="behind" /> + + \ No newline at end of file diff --git a/app/src/main/java/com/fankes/coloros/notify/hook/HookConst.kt b/app/src/main/java/com/fankes/coloros/notify/hook/HookConst.kt index d57eba2..f3120bc 100644 --- a/app/src/main/java/com/fankes/coloros/notify/hook/HookConst.kt +++ b/app/src/main/java/com/fankes/coloros/notify/hook/HookConst.kt @@ -33,7 +33,9 @@ object HookConst { const val REMOVE_DEV_NOTIFY = "_remove_dev_notify" const val REMOVE_CHANGECP_NOTIFY = "_remove_charge_complete_notify" const val REMOVE_DNDALERT_NOTIFY = "_remove_dndalert_notify" + const val ENABLE_NOTIFY_ICON_FIX_AUTO = "_enable_notify_icon_fix_auto" const val NOTIFY_ICON_DATAS = "_notify_icon_datas" + const val NOTIFY_ICON_FIX_AUTO_TIME = "_notify_icon_fix_auto_time" const val SOURCE_SYNC_WAY = "_rule_source_sync_way" const val SOURCE_SYNC_WAY_CUSTOM_URL = "_rule_source_sync_way_custom_url" diff --git a/app/src/main/java/com/fankes/coloros/notify/hook/entity/SystemUIHooker.kt b/app/src/main/java/com/fankes/coloros/notify/hook/entity/SystemUIHooker.kt index 5314e61..f5e0be2 100644 --- a/app/src/main/java/com/fankes/coloros/notify/hook/entity/SystemUIHooker.kt +++ b/app/src/main/java/com/fankes/coloros/notify/hook/entity/SystemUIHooker.kt @@ -45,7 +45,9 @@ import com.fankes.coloros.notify.hook.HookConst.ANDROID_PACKAGE_NAME import com.fankes.coloros.notify.hook.HookConst.ENABLE_ANDROID12_STYLE import com.fankes.coloros.notify.hook.HookConst.ENABLE_MODULE_LOG import com.fankes.coloros.notify.hook.HookConst.ENABLE_NOTIFY_ICON_FIX +import com.fankes.coloros.notify.hook.HookConst.ENABLE_NOTIFY_ICON_FIX_AUTO import com.fankes.coloros.notify.hook.HookConst.ENABLE_NOTIFY_ICON_FIX_NOTIFY +import com.fankes.coloros.notify.hook.HookConst.NOTIFY_ICON_FIX_AUTO_TIME import com.fankes.coloros.notify.hook.HookConst.REMOVE_CHANGECP_NOTIFY import com.fankes.coloros.notify.hook.HookConst.REMOVE_DEV_NOTIFY import com.fankes.coloros.notify.hook.HookConst.REMOVE_DNDALERT_NOTIFY @@ -698,8 +700,12 @@ class SystemUIHooker : YukiBaseHooker() { param(ContextClass, IntentClass) } afterHook { - // TODO 待实现 - loggerD(msg = "当前时间:${System.currentTimeMillis()}") + if (isEnableHookColorNotifyIcon() && prefs.getBoolean(ENABLE_NOTIFY_ICON_FIX_AUTO, default = true)) + IconAdaptationTool.prepareAutoUpdateIconRule( + context = firstArgs()!!, + // TODO 设置 UI 界面设置定时更新规则 + timeSet = prefs.getString(NOTIFY_ICON_FIX_AUTO_TIME, default = "07:00") + ) } } } diff --git a/app/src/main/java/com/fankes/coloros/notify/ui/activity/auto/NotifyIconRuleUpdateActivity.kt b/app/src/main/java/com/fankes/coloros/notify/ui/activity/auto/NotifyIconRuleUpdateActivity.kt new file mode 100644 index 0000000..38aea45 --- /dev/null +++ b/app/src/main/java/com/fankes/coloros/notify/ui/activity/auto/NotifyIconRuleUpdateActivity.kt @@ -0,0 +1,69 @@ +/* + * ColorOSNotifyIcon - Optimize notification icons for ColorOS and adapt to native notification icon specifications. + * Copyright (C) 2019-2022 Fankes Studio(qzmmcn@163.com) + * https://github.com/fankes/ColorOSNotifyIcon + * + * This software is non-free but opensource software: you can redistribute it + * and/or modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + *

+ * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * and eula along with this software. If not, see + * + * + * This file is Created by fankes on 2022/3/26. + */ +@file:Suppress("DEPRECATION") + +package com.fankes.coloros.notify.ui.activity.auto + +import android.app.Activity +import android.os.Bundle +import android.view.View +import android.view.WindowManager +import com.fankes.coloros.notify.application.CNNApplication.Companion.appContext +import com.fankes.coloros.notify.ui.activity.base.BaseActivity +import com.fankes.coloros.notify.utils.factory.delayedRun +import com.fankes.coloros.notify.utils.tool.IconRuleManagerTool +import com.fankes.coloros.notify.utils.tool.SystemUITool + +class NotifyIconRuleUpdateActivity : Activity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + /** 设置透明窗口 */ + window?.decorView?.systemUiVisibility = + View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE + window?.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) + window?.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) + /** 检测运行状态 */ + if (BaseActivity.isMainThreadRunning) { + finish() + return + } + /** 注册 */ + SystemUITool.register(context = this) + /** 拉取云端数据 */ + IconRuleManagerTool.sync(appContext) { + /** 刷新系统界面 */ + SystemUITool.refreshSystemUI() + /** 结束当前窗口 */ + runOnUiThread { delayedRun(ms = 1000) { finish() } } + } + /** 切换到后台 */ + moveTaskToBack(true) + } + + override fun onDestroy() { + super.onDestroy() + /** 解除注册 */ + SystemUITool.unregister(context = this) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/fankes/coloros/notify/ui/activity/base/BaseActivity.kt b/app/src/main/java/com/fankes/coloros/notify/ui/activity/base/BaseActivity.kt index b520442..c993844 100644 --- a/app/src/main/java/com/fankes/coloros/notify/ui/activity/base/BaseActivity.kt +++ b/app/src/main/java/com/fankes/coloros/notify/ui/activity/base/BaseActivity.kt @@ -37,11 +37,18 @@ import java.lang.reflect.ParameterizedType abstract class BaseActivity : AppCompatActivity() { + companion object { + + /** 应用是否正在运行 */ + var isMainThreadRunning = false + } + /** 获取绑定布局对象 */ lateinit var binding: VB override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + isMainThreadRunning = true javaClass.genericSuperclass.also { type -> if (type is ParameterizedType) { binding = (type.actualTypeArguments[0] as Class).method { diff --git a/app/src/main/java/com/fankes/coloros/notify/utils/factory/FunctionFactory.kt b/app/src/main/java/com/fankes/coloros/notify/utils/factory/FunctionFactory.kt index 0ddf6dd..e6dfb89 100644 --- a/app/src/main/java/com/fankes/coloros/notify/utils/factory/FunctionFactory.kt +++ b/app/src/main/java/com/fankes/coloros/notify/utils/factory/FunctionFactory.kt @@ -57,6 +57,8 @@ import com.highcapable.yukihookapi.hook.factory.method import com.highcapable.yukihookapi.hook.type.java.StringType import com.topjohnwu.superuser.Shell import java.io.ByteArrayOutputStream +import java.text.SimpleDateFormat +import java.util.* /** @@ -380,6 +382,14 @@ fun Context.copyToClipboard(content: String) = runInSafe { } } +/** + * 时间戳 -> 时间 + * @param format 格式化方法 - 默认:yyyy-MM-dd HH:mm:ss + * @return [String] 目标字符串时间 + */ +fun Long.stampToDate(format: String = "yyyy-MM-dd HH:mm:ss") = + safeOfNothing { SimpleDateFormat(format, Locale.CHINA).format(Date(this)) ?: "" } + /** * 延迟执行 * @param ms 毫秒 - 默认:150 diff --git a/app/src/main/java/com/fankes/coloros/notify/utils/tool/IconAdaptationTool.kt b/app/src/main/java/com/fankes/coloros/notify/utils/tool/IconAdaptationTool.kt index 12053fc..889b6a4 100644 --- a/app/src/main/java/com/fankes/coloros/notify/utils/tool/IconAdaptationTool.kt +++ b/app/src/main/java/com/fankes/coloros/notify/utils/tool/IconAdaptationTool.kt @@ -35,10 +35,7 @@ import android.os.Build import androidx.core.graphics.drawable.toBitmap import com.fankes.coloros.notify.const.Const import com.fankes.coloros.notify.hook.HookEntry -import com.fankes.coloros.notify.utils.factory.bitmap -import com.fankes.coloros.notify.utils.factory.findAppIcon -import com.fankes.coloros.notify.utils.factory.findAppName -import com.fankes.coloros.notify.utils.factory.runInSafe +import com.fankes.coloros.notify.utils.factory.* /** * 通知图标适配推送通知类 @@ -50,6 +47,9 @@ object IconAdaptationTool { /** 推送通知的渠道名称 */ private const val NOTIFY_CHANNEL = "notifyRuleSupportId" + /** 已过期的日期 */ + private val outDateLimits = HashSet() + /** * 使用的小图标 * @return [Bitmap] @@ -159,4 +159,30 @@ object IconAdaptationTool { fun removeNewAppSupportNotify(context: Context, packageName: String) = runInSafe { context.getSystemService(NotificationManager::class.java)?.cancel(packageName.hashCode()) } + + /** + * 自动更新通知图标优化在线规则 + * + * 一天执行一次 + * @param context 实例 + * @param timeSet 设定的时间 + */ + fun prepareAutoUpdateIconRule(context: Context, timeSet: String) = runInSafe { + System.currentTimeMillis().also { + if (it.stampToDate(format = "HH:mm") == timeSet && (outDateLimits.isEmpty() || outDateLimits.none { each -> + each == it.stampToDate(format = "yyyy-MM-dd") + })) { + outDateLimits.add(it.stampToDate(format = "yyyy-MM-dd")) + context.startActivity( + Intent().apply { + component = ComponentName( + Const.MODULE_PACKAGE_NAME, + "${Const.MODULE_PACKAGE_NAME}.ui.activity.auto.NotifyIconRuleUpdateActivity" + ) + flags = Intent.FLAG_ACTIVITY_NEW_TASK + } + ) + } + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/fankes/coloros/notify/utils/tool/SystemUITool.kt b/app/src/main/java/com/fankes/coloros/notify/utils/tool/SystemUITool.kt index e62ac71..dce789e 100644 --- a/app/src/main/java/com/fankes/coloros/notify/utils/tool/SystemUITool.kt +++ b/app/src/main/java/com/fankes/coloros/notify/utils/tool/SystemUITool.kt @@ -26,6 +26,7 @@ import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.content.IntentFilter +import com.fankes.coloros.notify.application.CNNApplication.Companion.appContext import com.fankes.coloros.notify.const.Const import com.fankes.coloros.notify.utils.factory.* import com.google.android.material.snackbar.Snackbar @@ -100,9 +101,16 @@ object SystemUITool { * @param isRefreshCacheOnly 仅刷新缓存不刷新图标和通知改变 - 默认:否 * @param it 成功后回调 */ - fun refreshSystemUI(context: Context, isRefreshCacheOnly: Boolean = false, it: () -> Unit = {}) = + fun refreshSystemUI(context: Context? = null, isRefreshCacheOnly: Boolean = false, it: () -> Unit = {}) = runInSafe { + fun sendMessage() { + (context ?: appContext).sendBroadcast(Intent().apply { + action = Const.ACTION_REMIND_CHECKING_RECEIVER + putExtra("isRefreshCacheOnly", isRefreshCacheOnly) + putExtra(Const.MODULE_VERSION_VERIFY_TAG, Const.MODULE_VERSION_VERIFY) + }) + } if (isXposedModuleActive) - context.showDialog { + context?.showDialog { title = "请稍后" progressContent = "正在等待系统界面刷新" /** 是否等待成功 */ @@ -124,14 +132,11 @@ object SystemUITool { else -> it() } } - context.sendBroadcast(Intent().apply { - action = Const.ACTION_REMIND_CHECKING_RECEIVER - putExtra("isRefreshCacheOnly", isRefreshCacheOnly) - putExtra(Const.MODULE_VERSION_VERIFY_TAG, Const.MODULE_VERSION_VERIFY) - }) + sendMessage() noCancelable() - } - else context.snake(msg = "模块没有激活,更改不会生效") + } ?: sendMessage() + else context?.snake(msg = "模块没有激活,更改不会生效") + } /** * 显示需要重启系统界面的 [Snackbar]