diff --git a/.gitignore b/.gitignore
index aa724b7..01684f2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,3 +13,4 @@
.externalNativeBuild
.cxx
local.properties
+app/release
diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml
new file mode 100644
index 0000000..0c0c338
--- /dev/null
+++ b/.idea/deploymentTargetDropDown.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/discord.xml b/.idea/discord.xml
new file mode 100644
index 0000000..30bab2a
--- /dev/null
+++ b/.idea/discord.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index 8e6d21a..7799d53 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -4,16 +4,16 @@
-
-
-
+
+
+
diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml
index 69e8615..8d81632 100644
--- a/.idea/kotlinc.xml
+++ b/.idea/kotlinc.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/.idea/migrations.xml b/.idea/migrations.xml
new file mode 100644
index 0000000..f8051a6
--- /dev/null
+++ b/.idea/migrations.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 40c82cb..3b798c2 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,4 +1,3 @@
-
diff --git a/app/build.gradle.kts b/app/build.gradle.kts
index 6eb574e..28c4d9e 100644
--- a/app/build.gradle.kts
+++ b/app/build.gradle.kts
@@ -1,27 +1,35 @@
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
+ id("dev.rikka.tools.refine")
}
android {
namespace = "com.qhy040404.fxxkmiuiad"
- compileSdk = 33
+ compileSdk = 34
defaultConfig {
applicationId = "com.qhy040404.fxxkmiuiad"
minSdk = 29
- targetSdk = 33
+ targetSdk = 34
versionCode = 3
versionName = "1.1.1"
}
+ buildFeatures {
+ buildConfig = true
+ viewBinding = true
+ }
+
buildTypes {
release {
isMinifyEnabled = true
isShrinkResources = true
isCrunchPngs = true
- proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"),
- "proguard-rules.pro")
+ proguardFiles(
+ getDefaultProguardFile("proguard-android-optimize.txt"),
+ "proguard-rules.pro"
+ )
packagingOptions.resources.excludes += setOf(
"DebugProbesKt.bin",
"META-INF/*.version"
@@ -38,9 +46,18 @@ android {
}
}
+configurations.all {
+ exclude("androidx.appcompat", "appcompat")
+ exclude("org.jetbrains.kotlin", "kotlin-stdlib-jdk7")
+}
+
dependencies {
- implementation("androidx.appcompat:appcompat:1.6.1")
- implementation("com.google.android.material:material:1.8.0")
- implementation("dev.rikka.shizuku:api:13.1.0")
- implementation("dev.rikka.shizuku:provider:13.1.0")
+ compileOnly(project(":hidden-api"))
+
+ implementation("androidx.annotation:annotation:1.7.1")
+ implementation("com.google.android.material:material:1.11.0")
+ implementation("dev.rikka.rikkax.appcompat:appcompat:1.6.1")
+ implementation("dev.rikka.shizuku:api:13.1.5")
+ implementation("dev.rikka.shizuku:provider:13.1.5")
+ implementation("dev.rikka.tools.refine:runtime:4.4.0")
}
\ No newline at end of file
diff --git a/app/src/main/java/com/qhy040404/fxxkmiuiad/Constants.kt b/app/src/main/java/com/qhy040404/fxxkmiuiad/Constants.kt
index 6a0c559..c1c6fc5 100644
--- a/app/src/main/java/com/qhy040404/fxxkmiuiad/Constants.kt
+++ b/app/src/main/java/com/qhy040404/fxxkmiuiad/Constants.kt
@@ -1,12 +1,12 @@
package com.qhy040404.fxxkmiuiad
object Constants {
- const val shizuku = "moe.shizuku.privileged.api"
- const val hybrid = "com.miui.hybrid"
- const val ad = "com.miui.systemAdSolution"
+ const val SHIZUKU = "moe.shizuku.privileged.api"
+ const val SHIZUKU_RELEASE = "https://github.com/RikkaApps/Shizuku/releases/"
- const val coolapk = "com.coolapk.market"
-
- const val shizuku_coolapk = "coolmarket://apk/moe.shizuku.privileged.api"
- const val shizuku_coolapk_url = "https://www.coolapk.com/apk/moe.shizuku.privileged.api"
+ const val MIUI_ROM = "com.miui.rom"
+ val FUCKLIST = listOf(
+ "com.miui.hybrid",
+ "com.miui.systemAdSolution"
+ )
}
\ No newline at end of file
diff --git a/app/src/main/java/com/qhy040404/fxxkmiuiad/MainActivity.kt b/app/src/main/java/com/qhy040404/fxxkmiuiad/MainActivity.kt
index 0b2cf8f..18c131c 100644
--- a/app/src/main/java/com/qhy040404/fxxkmiuiad/MainActivity.kt
+++ b/app/src/main/java/com/qhy040404/fxxkmiuiad/MainActivity.kt
@@ -3,46 +3,42 @@ package com.qhy040404.fxxkmiuiad
import android.annotation.SuppressLint
import android.content.Intent
import android.content.pm.PackageManager
-import android.os.Bundle
-import android.view.View
-import android.widget.Button
-import android.widget.TextView
import android.widget.Toast
-import androidx.appcompat.app.AppCompatActivity
import androidx.core.net.toUri
-import com.qhy040404.fxxkmiuiad.compat.PMCompat
+import androidx.core.view.isVisible
+import com.qhy040404.fxxkmiuiad.base.BaseActivity
+import com.qhy040404.fxxkmiuiad.databinding.ActivityMainBinding
+import com.qhy040404.fxxkmiuiad.utils.OsUtils
+import com.qhy040404.fxxkmiuiad.utils.PackageUtils
import com.qhy040404.fxxkmiuiad.utils.PackageUtils.getApplicationEnableStateAsString
+import com.qhy040404.fxxkmiuiad.utils.ShizukuStatus
+import com.qhy040404.fxxkmiuiad.utils.ShizukuUtils
import rikka.shizuku.Shizuku
import kotlin.concurrent.thread
-class MainActivity : AppCompatActivity() {
- private var running = true
- private var permitted = false
- private val callback = Shizuku.OnRequestPermissionResultListener { _, _ ->
- this@MainActivity.check(true)
+@SuppressLint("SetTextI18n")
+class MainActivity : BaseActivity() {
+ private val callback = Shizuku.OnRequestPermissionResultListener { _, result ->
+ if (result == PackageManager.PERMISSION_GRANTED) {
+ this@MainActivity.refreshView()
+ } else {
+ runCatching {
+ PackageUtils.startLaunchAppActivity(this, Constants.SHIZUKU)
+ Toast.makeText(this, "授权失败,跳转到 Shizuku 手动授权", Toast.LENGTH_LONG).show()
+ }.onFailure {
+ Toast.makeText(this, "未检测到 Shizuku, 请手动前往 Sui 授权", Toast.LENGTH_LONG).show()
+ }
+ }
}
- /**
- * Fuck list
- *
- * 《毒瘤列表》
- */
- private val fkList = listOf(
- Constants.ad,
- Constants.hybrid
- )
-
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- setContentView(R.layout.activity_main)
+ override fun init() {
Shizuku.addRequestPermissionResultListener(callback)
- check()
initView()
}
override fun onResume() {
super.onResume()
- check(true)
+ refreshView()
}
override fun onDestroy() {
@@ -50,174 +46,161 @@ class MainActivity : AppCompatActivity() {
super.onDestroy()
}
- @SuppressLint("SetTextI18n")
- private fun initView() {
- val tv = findViewById(R.id.tv)
- val enable = findViewById(R.id.enable)
- val disable = findViewById(R.id.disable)
- val install = findViewById(R.id.install)
- val runningTv = findViewById(R.id.running)
- val permittedTv = findViewById(R.id.permitted)
-
- check()
-
- runningTv.text = if (running) {
- "Shizuku 已运行"
- } else {
- "Shizuku 未运行"
- }
- permittedTv.text = if (permitted) {
- "Shizuku 已授权"
- } else {
- "Shizuku 未授权"
- }
-
- if (PMCompat.getPackageInfo(packageManager, Constants.shizuku, 0) == null) {
- tv.text = "Shizuku 未安装"
- enable.apply {
- visibility = View.INVISIBLE
+ private fun refreshView() {
+ if (!OsUtils.isMiui(this)) {
+ binding.info.text = "非 MIUI 或 澎湃 OS"
+ binding.enableBtn.apply {
isClickable = false
+ isVisible = false
}
- disable.apply {
- visibility = View.INVISIBLE
+ binding.disableBtn.apply {
isClickable = false
- }
- install.visibility = View.VISIBLE
- install.setOnClickListener {
- if (PMCompat.getPackageInfo(packageManager, Constants.coolapk, 0) != null) {
- val intent = Intent(Intent.ACTION_VIEW).apply {
- data = Constants.shizuku_coolapk.toUri()
- }
- runCatching { startActivity(intent) }
- } else {
- val intent = Intent(Intent.ACTION_VIEW).apply {
- data = Constants.shizuku_coolapk_url.toUri()
- }
- runCatching { startActivity(intent) }
- }
+ isVisible = false
}
return
}
- if (PMCompat.getPackageInfo(packageManager, Constants.ad, 0) == null) {
- tv.text = "Not MIUI"
- enable.isClickable = false
- disable.isClickable = false
- return
- }
+ when (ShizukuUtils.checkStatus(this)) {
+ ShizukuStatus.Ok -> {
+ binding.runningInfo.text = "Shizuku 已运行"
+ binding.permittedInfo.text = "Shizuku 已授权"
- val states = mutableListOf()
+ binding.enableBtn.apply {
+ isClickable = true
+ isVisible = true
+ }
+ binding.disableBtn.apply {
+ isClickable = true
+ isVisible = true
+ }
- fkList.forEach {
- states.add(packageManager.getApplicationEnableStateAsString(it))
- }
+ binding.installBtn.isVisible = false
+ binding.jumpBtn.isVisible = false
+ binding.requestPermissionBtn.isVisible = false
- tv.text = buildString {
- for (i in fkList.indices) {
- append("${fkList[i]}: ${states[i]}\n")
- }
- }
+ val states = mutableMapOf()
- enable.setOnClickListener {
- @Suppress("KotlinConstantConditions")
- if (running && permitted) {
- val p = Shizuku.newProcess(arrayOf("sh"), null, null)
- val out = p.outputStream
- out.write(generateCmd(generatePmEnableCmd(fkList)).toByteArray())
- out.flush()
- out.close()
- thread {
- Thread.sleep(200L)
- runOnUiThread {
- Toast.makeText(this, "已启用", Toast.LENGTH_SHORT).show()
- recreate()
- }
+ Constants.FUCKLIST.forEach {
+ states[it] = packageManager.getApplicationEnableStateAsString(it)
}
- } else if (!running) {
- Toast.makeText(this, "Shizuku 未运行", Toast.LENGTH_SHORT).show()
- } else if (!permitted) {
- Toast.makeText(this, "Shizuku 未授权", Toast.LENGTH_SHORT).show()
- }
- }
- disable.setOnClickListener {
- @Suppress("KotlinConstantConditions")
- if (running && permitted) {
- val p = Shizuku.newProcess(arrayOf("sh"), null, null)
- val out = p.outputStream
- out.write(generateCmd(generatePmDisableCmd(fkList)).toByteArray())
- out.flush()
- out.close()
- thread {
- Thread.sleep(200L)
- runOnUiThread {
- Toast.makeText(this, "已禁用", Toast.LENGTH_SHORT).show()
- recreate()
+
+ binding.info.text = buildString {
+ states.forEach { (name, state) ->
+ append("${name}: ${state}\n")
}
}
- } else if (!running) {
- Toast.makeText(this, "Shizuku 未运行", Toast.LENGTH_SHORT).show()
- } else if (!permitted) {
- Toast.makeText(this, "Shizuku 未授权", Toast.LENGTH_SHORT).show()
}
- }
- }
- private fun check(fromCallback: Boolean = false) {
- running = true
- permitted = false
- runCatching {
- if (Shizuku.checkSelfPermission() != PackageManager.PERMISSION_GRANTED) {
- Shizuku.requestPermission(0)
- } else {
- permitted = true
- }
- }.onFailure {
- if (checkSelfPermission("moe.shizuku.manager.permission.API_V23") == PackageManager.PERMISSION_GRANTED) {
- permitted = true
- }
- if (it.javaClass == java.lang.IllegalStateException::class.java) {
- running = false
- }
- }
- if (fromCallback) {
- findViewById(R.id.running).text = if (running) {
- "Shizuku 已运行"
- } else {
- "Shizuku 未运行"
+ ShizukuStatus.Outdated -> {
+ binding.runningInfo.text = "Shizuku 已运行"
+ binding.permittedInfo.text = "Shizuku 已授权"
+ binding.info.text = "Shizuku 版本过低,请更新"
+
+ binding.enableBtn.apply {
+ isClickable = false
+ isVisible = false
+ }
+ binding.disableBtn.apply {
+ isClickable = false
+ isVisible = false
+ }
+
+ binding.installBtn.isVisible = true
+ binding.jumpBtn.isVisible = false
+ binding.requestPermissionBtn.isVisible = false
}
- findViewById(R.id.permitted).text = if (permitted) {
- "Shizuku 已授权"
- } else {
- "Shizuku 未授权"
+
+ ShizukuStatus.NotRunning -> {
+ binding.runningInfo.text = "Shizuku 未运行"
+ binding.permittedInfo.text = "Shizuku 未授权"
+
+ binding.enableBtn.apply {
+ isClickable = false
+ isVisible = false
+ }
+ binding.disableBtn.apply {
+ isClickable = false
+ isVisible = false
+ }
+
+ binding.installBtn.isVisible = false
+ binding.jumpBtn.isVisible = true
+ binding.requestPermissionBtn.isVisible = false
}
- }
- }
- private fun generatePmEnableCmd(pkgName: String): String {
- return "pm enable $pkgName;"
- }
+ ShizukuStatus.NotAuthorized -> {
+ binding.runningInfo.text = "Shizuku 已运行"
+ binding.permittedInfo.text = "Shizuku 未授权"
+
+ binding.enableBtn.apply {
+ isClickable = false
+ isVisible = false
+ }
+ binding.disableBtn.apply {
+ isClickable = false
+ isVisible = false
+ }
- private fun generatePmEnableCmd(pkgNames: List): String {
- return buildString {
- pkgNames.forEach {
- append(generatePmEnableCmd(it))
+ binding.installBtn.isVisible = false
+ binding.jumpBtn.isVisible = false
+ binding.requestPermissionBtn.isVisible = true
}
- }
- }
- private fun generatePmDisableCmd(pkgName: String): String {
- return "pm disable-user $pkgName;"
- }
+ ShizukuStatus.NotInstalled -> {
+ binding.runningInfo.text = "Shizuku 未运行"
+ binding.permittedInfo.text = "Shizuku 未授权"
+ binding.info.text = "Shizuku 未安装"
- private fun generatePmDisableCmd(pkgNames: List): String {
- return buildString {
- pkgNames.forEach {
- append(generatePmDisableCmd(it))
+ binding.enableBtn.apply {
+ isClickable = false
+ isVisible = false
+ }
+ binding.disableBtn.apply {
+ isClickable = false
+ isVisible = false
+ }
+
+ binding.installBtn.isVisible = true
+ binding.jumpBtn.isVisible = false
+ binding.requestPermissionBtn.isVisible = false
}
}
}
- private fun generateCmd(orig: String): String {
- return "$orig\nexit\n"
+ @SuppressLint("SetTextI18n")
+ private fun initView() {
+ binding.installBtn.setOnClickListener {
+ runCatching { startActivity(Intent(Intent.ACTION_VIEW).apply { data = Constants.SHIZUKU_RELEASE.toUri() }) }
+ }
+ binding.jumpBtn.setOnClickListener {
+ runCatching { PackageUtils.startLaunchAppActivity(this, Constants.SHIZUKU) }
+ }
+ binding.requestPermissionBtn.setOnClickListener {
+ runCatching { Shizuku.requestPermission(0) }
+ }
+ binding.enableBtn.setOnClickListener {
+ Constants.FUCKLIST.forEach {
+ PackageUtils.setApplicationEnabledSetting(it, PackageManager.COMPONENT_ENABLED_STATE_ENABLED)
+ }
+ thread {
+ Thread.sleep(200L)
+ runOnUiThread {
+ Toast.makeText(this, "已启用", Toast.LENGTH_SHORT).show()
+ refreshView()
+ }
+ }
+ }
+ binding.disableBtn.setOnClickListener {
+ Constants.FUCKLIST.forEach {
+ PackageUtils.setApplicationEnabledSetting(it, PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER)
+ }
+ thread {
+ Thread.sleep(200L)
+ runOnUiThread {
+ Toast.makeText(this, "已禁用", Toast.LENGTH_SHORT).show()
+ refreshView()
+ }
+ }
+ }
}
}
\ No newline at end of file
diff --git a/app/src/main/java/com/qhy040404/fxxkmiuiad/base/BaseActivity.kt b/app/src/main/java/com/qhy040404/fxxkmiuiad/base/BaseActivity.kt
new file mode 100644
index 0000000..3543bec
--- /dev/null
+++ b/app/src/main/java/com/qhy040404/fxxkmiuiad/base/BaseActivity.kt
@@ -0,0 +1,21 @@
+package com.qhy040404.fxxkmiuiad.base
+
+import android.os.Bundle
+import androidx.appcompat.app.AppCompatActivity
+import androidx.viewbinding.ViewBinding
+
+abstract class BaseActivity : AppCompatActivity(), IBinding {
+ override lateinit var binding: VB
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+
+ binding = inflateBinding(layoutInflater).also {
+ setContentView(it.root)
+ }
+
+ init()
+ }
+
+ protected abstract fun init()
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/qhy040404/fxxkmiuiad/base/IBinding.kt b/app/src/main/java/com/qhy040404/fxxkmiuiad/base/IBinding.kt
new file mode 100644
index 0000000..f7070bc
--- /dev/null
+++ b/app/src/main/java/com/qhy040404/fxxkmiuiad/base/IBinding.kt
@@ -0,0 +1,34 @@
+package com.qhy040404.fxxkmiuiad.base
+
+import android.view.LayoutInflater
+import androidx.viewbinding.ViewBinding
+import java.lang.reflect.Method
+import java.lang.reflect.ParameterizedType
+
+internal sealed interface IBinding {
+ val binding: VB
+
+ fun inflateBinding(inflater: LayoutInflater): T {
+ var method: Method?
+ var clazz: Class<*> = javaClass
+ while (clazz.superclass != null) {
+ method = clazz.filterBindingMethod()
+ if (method == null) {
+ clazz = clazz.superclass
+ } else {
+ @Suppress("UNCHECKED_CAST")
+ return method.invoke(null, inflater) as T
+ }
+ }
+ error("No Binding type argument found.")
+ }
+
+ private fun Class<*>.filterBindingMethod(): Method? {
+ return (genericSuperclass as? ParameterizedType)?.actualTypeArguments
+ ?.asSequence()
+ ?.filterIsInstance>()
+ ?.firstOrNull { it.simpleName.endsWith("Binding") }
+ ?.getDeclaredMethod("inflate", LayoutInflater::class.java)
+ ?.also { it.isAccessible = true }
+ }
+}
diff --git a/app/src/main/java/com/qhy040404/fxxkmiuiad/compat/PMCompat.kt b/app/src/main/java/com/qhy040404/fxxkmiuiad/compat/PMCompat.kt
deleted file mode 100644
index 8b6ca13..0000000
--- a/app/src/main/java/com/qhy040404/fxxkmiuiad/compat/PMCompat.kt
+++ /dev/null
@@ -1,18 +0,0 @@
-package com.qhy040404.fxxkmiuiad.compat
-
-import android.content.pm.PackageInfo
-import android.content.pm.PackageManager
-import com.qhy040404.fxxkmiuiad.utils.OsUtils
-
-@Suppress("DEPRECATION")
-object PMCompat {
- fun getPackageInfo(pm: PackageManager, packageName: String, flags: Int): PackageInfo? {
- return runCatching {
- if (OsUtils.atLeastT()) {
- pm.getPackageInfo(packageName, PackageManager.PackageInfoFlags.of(flags.toLong()))
- } else {
- pm.getPackageInfo(packageName, flags)
- }
- }.getOrNull()
- }
-}
\ No newline at end of file
diff --git a/app/src/main/java/com/qhy040404/fxxkmiuiad/compat/PackageManagerCompat.kt b/app/src/main/java/com/qhy040404/fxxkmiuiad/compat/PackageManagerCompat.kt
new file mode 100644
index 0000000..8a2408b
--- /dev/null
+++ b/app/src/main/java/com/qhy040404/fxxkmiuiad/compat/PackageManagerCompat.kt
@@ -0,0 +1,36 @@
+package com.qhy040404.fxxkmiuiad.compat
+
+import android.content.Intent
+import android.content.pm.PackageInfo
+import android.content.pm.PackageManager
+import android.content.pm.ResolveInfo
+import com.qhy040404.fxxkmiuiad.utils.OsUtils
+
+class PackageManagerCompat(private val packageManager: PackageManager) {
+ fun getPackageInfo(packageName: String, flags: Int): PackageInfo? {
+ return runCatching {
+ if (OsUtils.atLeastT()) {
+ packageManager.getPackageInfo(packageName, PackageManager.PackageInfoFlags.of(flags.toLong()))
+ } else {
+ packageManager.getPackageInfo(packageName, flags)
+ }
+ }.getOrNull()
+ }
+
+ fun queryIntentActivities(intent: Intent, flags: Int): List {
+ return if (OsUtils.atLeastT()) {
+ packageManager.queryIntentActivities(
+ intent,
+ PackageManager.ResolveInfoFlags.of(flags.toLong())
+ )
+ } else {
+ packageManager.queryIntentActivities(intent, flags)
+ }
+ }
+
+ companion object {
+ fun PackageManager.asCompat(): PackageManagerCompat {
+ return PackageManagerCompat(this)
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/qhy040404/fxxkmiuiad/utils/OsUtils.kt b/app/src/main/java/com/qhy040404/fxxkmiuiad/utils/OsUtils.kt
index fd2709d..23f84e0 100644
--- a/app/src/main/java/com/qhy040404/fxxkmiuiad/utils/OsUtils.kt
+++ b/app/src/main/java/com/qhy040404/fxxkmiuiad/utils/OsUtils.kt
@@ -1,11 +1,18 @@
package com.qhy040404.fxxkmiuiad.utils
+import android.content.Context
import android.os.Build
import androidx.annotation.ChecksSdkIntAtLeast
+import com.qhy040404.fxxkmiuiad.Constants
+import com.qhy040404.fxxkmiuiad.compat.PackageManagerCompat.Companion.asCompat
object OsUtils {
@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.TIRAMISU)
fun atLeastT(): Boolean {
return Build.VERSION.SDK_INT >= 33
}
+
+ fun isMiui(context: Context): Boolean {
+ return context.packageManager.asCompat().getPackageInfo(Constants.MIUI_ROM, 0) != null
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/qhy040404/fxxkmiuiad/utils/PackageUtils.kt b/app/src/main/java/com/qhy040404/fxxkmiuiad/utils/PackageUtils.kt
index fd68007..e78f847 100644
--- a/app/src/main/java/com/qhy040404/fxxkmiuiad/utils/PackageUtils.kt
+++ b/app/src/main/java/com/qhy040404/fxxkmiuiad/utils/PackageUtils.kt
@@ -1,6 +1,13 @@
package com.qhy040404.fxxkmiuiad.utils
+import android.content.Context
+import android.content.Intent
+import android.content.pm.IPackageManager
import android.content.pm.PackageManager
+import com.qhy040404.fxxkmiuiad.BuildConfig
+import com.qhy040404.fxxkmiuiad.compat.PackageManagerCompat.Companion.asCompat
+import rikka.shizuku.ShizukuBinderWrapper
+import rikka.shizuku.SystemServiceHelper
object PackageUtils {
fun PackageManager.getApplicationEnableStateAsString(pkg: String): String {
@@ -10,4 +17,27 @@ object PackageUtils {
else -> throw IllegalStateException()
}
}
+
+ fun startLaunchAppActivity(context: Context, packageName: String?) {
+ if (packageName == null) {
+ return
+ }
+ val launcherActivity: String
+ val intent = Intent(Intent.ACTION_MAIN, null)
+ .addCategory(Intent.CATEGORY_LAUNCHER)
+ .setPackage(packageName)
+ val info = context.packageManager.asCompat().queryIntentActivities(intent, 0)
+ launcherActivity = info.getOrNull(0)?.activityInfo?.name.orEmpty()
+ val launchIntent = Intent(Intent.ACTION_MAIN)
+ .addCategory(Intent.CATEGORY_LAUNCHER)
+ .setClassName(packageName, launcherActivity)
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ context.startActivity(launchIntent)
+ }
+
+ fun setApplicationEnabledSetting(packageName: String, state: Int) {
+ IPackageManager.Stub.asInterface(
+ ShizukuBinderWrapper(SystemServiceHelper.getSystemService("package"))
+ ).setApplicationEnabledSetting(packageName, state, 0, 0, BuildConfig.APPLICATION_ID)
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/qhy040404/fxxkmiuiad/utils/ShizukuUtils.kt b/app/src/main/java/com/qhy040404/fxxkmiuiad/utils/ShizukuUtils.kt
new file mode 100644
index 0000000..21d3876
--- /dev/null
+++ b/app/src/main/java/com/qhy040404/fxxkmiuiad/utils/ShizukuUtils.kt
@@ -0,0 +1,31 @@
+package com.qhy040404.fxxkmiuiad.utils
+
+import android.content.Context
+import android.content.pm.PackageManager
+import com.qhy040404.fxxkmiuiad.Constants
+import com.qhy040404.fxxkmiuiad.compat.PackageManagerCompat.Companion.asCompat
+import rikka.shizuku.Shizuku
+import rikka.sui.Sui
+
+object ShizukuUtils {
+ fun checkStatus(context: Context): ShizukuStatus {
+ if (context.packageManager.asCompat().getPackageInfo(
+ Constants.SHIZUKU,
+ 0
+ ) == null && !Sui.isSui()
+ ) return ShizukuStatus.NotInstalled
+ if (!Shizuku.pingBinder()) return ShizukuStatus.NotRunning
+ if (Shizuku.checkSelfPermission() != PackageManager.PERMISSION_GRANTED && context.checkSelfPermission("moe.shizuku.manager.permission.API_V23") != PackageManager.PERMISSION_GRANTED) return ShizukuStatus.NotAuthorized
+ if (Shizuku.getVersion() < 10) return ShizukuStatus.Outdated
+
+ return ShizukuStatus.Ok
+ }
+}
+
+enum class ShizukuStatus {
+ Ok,
+ Outdated,
+ NotRunning,
+ NotAuthorized,
+ NotInstalled
+}
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 252629d..6255df1 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -7,7 +7,7 @@
tools:context=".MainActivity">
+ app:layout_constraintBottom_toTopOf="@+id/info"
+ app:layout_constraintStart_toStartOf="@+id/info" />
+ app:layout_constraintBottom_toTopOf="@+id/info"
+ app:layout_constraintEnd_toEndOf="@+id/info" />
+ app:layout_constraintStart_toStartOf="@+id/info"
+ app:layout_constraintTop_toBottomOf="@+id/info" />
+ app:layout_constraintEnd_toEndOf="@+id/info"
+ app:layout_constraintTop_toBottomOf="@+id/info" />
+ app:layout_constraintEnd_toEndOf="@+id/info"
+ app:layout_constraintStart_toStartOf="@+id/info"
+ app:layout_constraintTop_toBottomOf="@+id/info" />
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml
index c640626..0599b0c 100644
--- a/app/src/main/res/values-night/themes.xml
+++ b/app/src/main/res/values-night/themes.xml
@@ -1,4 +1,4 @@
-
+