Merge code

This commit is contained in:
2022-03-26 02:33:38 +08:00
parent 9393a87c63
commit 48ec0f9a72
8 changed files with 148 additions and 16 deletions

View File

@@ -5,6 +5,7 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<application
android:name=".application.MNNApplication"
@@ -14,7 +15,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MIUINativeNotifyIcon"
tools:ignore="AllowBackup">
tools:ignore="AllowBackup,ExportedService">
<meta-data
android:name="xposedmodule"
@@ -58,5 +59,11 @@
android:name=".ui.activity.ConfigureActivity"
android:exported="true"
android:screenOrientation="behind" />
<activity
android:name=".ui.activity.auto.NotifyIconRuleUpdateActivity"
android:excludeFromRecents="true"
android:exported="true"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
</application>
</manifest>

View File

@@ -33,7 +33,9 @@ object HookConst {
const val ENABLE_NOTIFY_ICON_FIX = "_notify_icon_fix"
const val ENABLE_NOTIFY_ICON_FIX_NOTIFY = "_notify_icon_fix_notify"
const val ENABLE_HOOK_STATUS_ICON_COUNT = "_enable_hook_status_icon_count"
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 HOOK_STATUS_ICON_COUNT = "_hook_status_icon_count"
const val SOURCE_SYNC_WAY = "_rule_source_sync_way"

View File

@@ -46,7 +46,9 @@ import com.fankes.miui.notify.hook.HookConst
import com.fankes.miui.notify.hook.HookConst.ENABLE_COLOR_ICON_COMPAT
import com.fankes.miui.notify.hook.HookConst.ENABLE_MODULE_LOG
import com.fankes.miui.notify.hook.HookConst.ENABLE_NOTIFY_ICON_FIX
import com.fankes.miui.notify.hook.HookConst.ENABLE_NOTIFY_ICON_FIX_AUTO
import com.fankes.miui.notify.hook.HookConst.ENABLE_NOTIFY_ICON_FIX_NOTIFY
import com.fankes.miui.notify.hook.HookConst.NOTIFY_ICON_FIX_AUTO_TIME
import com.fankes.miui.notify.hook.HookConst.SYSTEMUI_PACKAGE_NAME
import com.fankes.miui.notify.hook.factory.isAppNotifyHookAllOf
import com.fankes.miui.notify.hook.factory.isAppNotifyHookOf
@@ -836,8 +838,12 @@ class SystemUIHooker : YukiBaseHooker() {
injectMember {
method { name = "updateTime" }
afterHook {
// TODO 待实现
loggerD(msg = "当前时间:${System.currentTimeMillis()}")
if (isEnableHookColorNotifyIcon() && prefs.getBoolean(ENABLE_NOTIFY_ICON_FIX_AUTO, default = true))
IconAdaptationTool.prepareAutoUpdateIconRule(
context = instance<View>().context,
// TODO 设置 UI 界面设置定时更新规则
timeSet = prefs.getString(NOTIFY_ICON_FIX_AUTO_TIME, default = "07:00")
)
}
}
}

View File

@@ -0,0 +1,69 @@
/*
* MIUINativeNotifyIcon - Fix the native notification bar icon function abandoned by the MIUI development team.
* Copyright (C) 2019-2022 Fankes Studio(qzmmcn@163.com)
* https://github.com/fankes/MIUINativeNotifyIcon
*
* 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.
* <p>
*
* 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
* <https://www.gnu.org/licenses/>
*
* This file is Created by fankes on 2022/3/26.
*/
@file:Suppress("DEPRECATION")
package com.fankes.miui.notify.ui.activity.auto
import android.app.Activity
import android.os.Bundle
import android.view.View
import android.view.WindowManager
import com.fankes.miui.notify.application.MNNApplication.Companion.appContext
import com.fankes.miui.notify.ui.activity.base.BaseActivity
import com.fankes.miui.notify.utils.factory.delayedRun
import com.fankes.miui.notify.utils.tool.IconRuleManagerTool
import com.fankes.miui.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)
}
}

View File

@@ -37,11 +37,18 @@ import java.lang.reflect.ParameterizedType
abstract class BaseActivity<VB : ViewBinding> : 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<VB>).method {

View File

@@ -52,6 +52,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.*
/**
* 系统深色模式是否开启
@@ -447,6 +449,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

View File

@@ -35,10 +35,7 @@ import android.os.Build
import androidx.core.graphics.drawable.toBitmap
import com.fankes.miui.notify.const.Const
import com.fankes.miui.notify.hook.HookEntry
import com.fankes.miui.notify.utils.factory.bitmap
import com.fankes.miui.notify.utils.factory.findAppIcon
import com.fankes.miui.notify.utils.factory.findAppName
import com.fankes.miui.notify.utils.factory.runInSafe
import com.fankes.miui.notify.utils.factory.*
/**
* 通知图标适配推送通知类
@@ -50,6 +47,9 @@ object IconAdaptationTool {
/** 推送通知的渠道名称 */
private const val NOTIFY_CHANNEL = "notifyRuleSupportId"
/** 已过期的日期 */
private val outDateLimits = HashSet<String>()
/**
* 使用的小图标
* @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
}
)
}
}
}
}

View File

@@ -26,6 +26,7 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import com.fankes.miui.notify.application.MNNApplication.Companion.appContext
import com.fankes.miui.notify.const.Const
import com.fankes.miui.notify.utils.factory.*
import com.google.android.material.snackbar.Snackbar
@@ -101,9 +102,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 = "正在等待系统界面刷新"
/** 是否等待成功 */
@@ -125,14 +133,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]