Skip to content

Commit

Permalink
add prompt for some hyperos users
Browse files Browse the repository at this point in the history
  • Loading branch information
qhy040404 committed Apr 16, 2024
1 parent 674ef95 commit 9e31c8a
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 14 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />

<application
android:name=".FxxkMIUIAdApp"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/com/qhy040404/fxxkmiuiad/FxxkMIUIAdApp.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.qhy040404.fxxkmiuiad

import android.app.Application

class FxxkMIUIAdApp : Application() {
override fun onCreate() {
super.onCreate()
app = this
}

companion object {
lateinit var app: Application
}
}
100 changes: 87 additions & 13 deletions app/src/main/java/com/qhy040404/fxxkmiuiad/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ import android.annotation.SuppressLint
import android.content.Intent
import android.content.pm.PackageManager
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.core.net.toUri
import androidx.core.view.isVisible
import com.google.android.material.dialog.MaterialAlertDialogBuilder
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 com.qhy040404.fxxkmiuiad.utils.copyToClipboard
import rikka.shizuku.Shizuku
import kotlin.concurrent.thread

Expand Down Expand Up @@ -182,23 +185,94 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
Constants.FUCKLIST.forEach {
PackageUtils.setApplicationEnabledSetting(it, PackageManager.COMPONENT_ENABLED_STATE_ENABLED)
}
thread {
Thread.sleep(200L)
runOnUiThread {
Toast.makeText(this, "已启用", Toast.LENGTH_SHORT).show()
refreshView()
if (Constants.FUCKLIST.any { packageManager.isPackageSuspended(it) }) {
thread {
Thread.sleep(200L)
runOnUiThread {
MaterialAlertDialogBuilder(this)
.setTitle("修改状态失败")
.setMessage(
"""
部分包处于 suspend 状态
如需解除请使用 shell 解除
点击按钮以复制指令。
""".trimIndent()
)
.setPositiveButton("关闭", null)
.setNeutralButton("复制 adb 指令") { _, _ ->
buildString {
Constants.FUCKLIST.forEach {
append("adb shell pm unsuspend $it")
appendLine()
}
}.copyToClipboard(this)
}
.setNegativeButton("复制 shell 指令") { _, _ ->
buildString {
Constants.FUCKLIST.forEach {
append("pm unsuspend $it")
appendLine()
}
}.copyToClipboard(this)
}
.create()
.show()
}
}
} else {
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()
runCatching {
Constants.FUCKLIST.forEach {
PackageUtils.setApplicationEnabledSetting(it, PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER)
}
}.onSuccess {
thread {
Thread.sleep(200L)
runOnUiThread {
Toast.makeText(this, "已禁用", Toast.LENGTH_SHORT).show()
refreshView()
}
}
}.onFailure {
thread {
Thread.sleep(200L)
runOnUiThread {
MaterialAlertDialogBuilder(this)
.setTitle("修改状态失败")
.setMessage("""
当前版本系统不允许修改相关包状态为 disabled
请通过 shell 来使对应包 suspend
点击按钮以复制指令。
""".trimIndent())
.setPositiveButton("关闭", null)
.setNeutralButton("复制 adb 指令") {_ ,_ ->
buildString {
Constants.FUCKLIST.forEach {
append("adb shell pm suspend $it")
appendLine()
}
}.copyToClipboard(this)
}
.setNegativeButton("复制 shell 指令") {_,_->
buildString {
Constants.FUCKLIST.forEach {
append("pm suspend $it")
appendLine()
}
}.copyToClipboard(this)
}
.create()
.show()
}
}
}
}
Expand Down
23 changes: 23 additions & 0 deletions app/src/main/java/com/qhy040404/fxxkmiuiad/utils/ClipboardUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.qhy040404.fxxkmiuiad.utils

import android.app.Activity
import android.content.ClipData
import android.content.ClipboardManager
import android.widget.Toast
import androidx.core.content.getSystemService
import com.qhy040404.fxxkmiuiad.FxxkMIUIAdApp

val cm by lazy { FxxkMIUIAdApp.app.getSystemService<ClipboardManager>()!! }

fun Any.copyToClipboard(activity: Activity? = null) = this.toString().also {
cm.setPrimaryClip(
ClipData.newPlainText("", it)
)
activity?.runOnUiThread {
Toast.makeText(activity, it, Toast.LENGTH_LONG).show()
}
}

//fun Any.copyToClipboard() = cm.setPrimaryClip(
// ClipData.newPlainText("", this.toString())
//)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ import rikka.shizuku.SystemServiceHelper
object PackageUtils {
fun PackageManager.getApplicationEnableStateAsString(pkg: String): String {
return when (this.getApplicationEnabledSetting(pkg)) {
PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, PackageManager.COMPONENT_ENABLED_STATE_ENABLED -> "启用"
PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, PackageManager.COMPONENT_ENABLED_STATE_ENABLED -> {
if (isPackageSuspended(pkg)) {
"禁用 (suspend)"
} else {
"启用"
}
}

PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER, PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED -> "禁用"
else -> throw IllegalStateException()
}
Expand Down

0 comments on commit 9e31c8a

Please sign in to comment.