Skip to content

Commit

Permalink
fix #4
Browse files Browse the repository at this point in the history
  • Loading branch information
qhy040404 committed Sep 7, 2024
1 parent ceb0f2d commit d8be5f8
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 125 deletions.
2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,5 @@ dependencies {
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")
implementation("org.lsposed.hiddenapibypass:hiddenapibypass:4.3")
}
121 changes: 32 additions & 89 deletions app/src/main/java/com/qhy040404/fxxkmiuiad/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@ 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 All @@ -34,13 +31,20 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
}
}

private val packageList = Constants.FUCKLIST.filter {
packageManager.getPackageInfo(it, 0) != null
}
private lateinit var packageList: List<String>

override fun init() {
Shizuku.addRequestPermissionResultListener(callback)
initView()

packageList = Constants.FUCKLIST.filter {
try {
packageManager.getPackageInfo(it, 0)
true
} catch (e: PackageManager.NameNotFoundException) {
false
}
}
}

override fun onResume() {
Expand Down Expand Up @@ -188,95 +192,34 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
binding.enableBtn.setOnClickListener {
packageList.forEach {
PackageUtils.setApplicationEnabledSetting(it, PackageManager.COMPONENT_ENABLED_STATE_ENABLED)
PackageUtils.setPackagesSuspendedAsUser(it, false)
}
if (packageList.any { packageManager.isPackageSuspended(it) }) {
thread {
Thread.sleep(200L)
runOnUiThread {
MaterialAlertDialogBuilder(this)
.setTitle("修改状态失败")
.setMessage(
"""
部分包处于 suspend 状态
如需解除请使用 shell 解除
点击按钮以复制指令。
""".trimIndent()
)
.setPositiveButton("关闭", null)
.setNeutralButton("复制 adb 指令") { _, _ ->
buildString {
packageList.forEach {
append("adb shell pm unsuspend $it")
appendLine()
}
}.copyToClipboard(this)
}
.setNegativeButton("复制 shell 指令") { _, _ ->
buildString {
packageList.forEach {
append("pm unsuspend $it")
appendLine()
}
}.copyToClipboard(this)
}
.create()
.show()
}
}
} else {
thread {
Thread.sleep(200L)
runOnUiThread {
Toast.makeText(this, "已启用", Toast.LENGTH_SHORT).show()
refreshView()
}

thread {
Thread.sleep(200L)
runOnUiThread {
Toast.makeText(this, "已启用", Toast.LENGTH_SHORT).show()
refreshView()
}
}
}
binding.disableBtn.setOnClickListener {
runCatching {
packageList.forEach {
PackageUtils.setApplicationEnabledSetting(it, PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER)
}
}.onSuccess {
thread {
Thread.sleep(200L)
runOnUiThread {
Toast.makeText(this, "已禁用", Toast.LENGTH_SHORT).show()
refreshView()
}
packageList.forEach { pkgName ->
runCatching {
PackageUtils.setApplicationEnabledSetting(
pkgName,
PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER
)
}.onFailure {
PackageUtils.setPackagesSuspendedAsUser(pkgName, true)
}
}.onFailure {
thread {
Thread.sleep(200L)
runOnUiThread {
MaterialAlertDialogBuilder(this)
.setTitle("修改状态失败")
.setMessage("""
当前版本系统不允许修改相关包状态为 disabled
请通过 shell 来使对应包 suspend
点击按钮以复制指令。
""".trimIndent())
.setPositiveButton("关闭", null)
.setNeutralButton("复制 adb 指令") {_ ,_ ->
buildString {
packageList.forEach {
append("adb shell pm suspend $it")
appendLine()
}
}.copyToClipboard(this)
}
.setNegativeButton("复制 shell 指令") {_,_->
buildString {
packageList.forEach {
append("pm suspend $it")
appendLine()
}
}.copyToClipboard(this)
}
.create()
.show()
}
}

thread {
Thread.sleep(200L)
runOnUiThread {
Toast.makeText(this, "已禁用", Toast.LENGTH_SHORT).show()
refreshView()
}
}
}
Expand Down
23 changes: 0 additions & 23 deletions app/src/main/java/com/qhy040404/fxxkmiuiad/utils/ClipboardUtils.kt

This file was deleted.

29 changes: 25 additions & 4 deletions app/src/main/java/com/qhy040404/fxxkmiuiad/utils/PackageUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,22 @@ import android.content.pm.IPackageManager
import android.content.pm.PackageManager
import com.qhy040404.fxxkmiuiad.BuildConfig
import com.qhy040404.fxxkmiuiad.compat.PackageManagerCompat.Companion.asCompat
import org.lsposed.hiddenapibypass.HiddenApiBypass
import rikka.shizuku.ShizukuBinderWrapper
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 -> {
if (isPackageSuspended(pkg)) {
"禁用 (suspend)"
} else {
"启用"
try {
if (isPackageSuspended(pkg)) {
"禁用 (suspend)"
} else {
"启用"
}
} catch (e: PackageManager.NameNotFoundException) {
"未安装"
}
}

Expand Down Expand Up @@ -47,4 +52,20 @@ object PackageUtils {
ShizukuBinderWrapper(SystemServiceHelper.getSystemService("package"))
).setApplicationEnabledSetting(packageName, state, 0, 0, BuildConfig.APPLICATION_ID)
}

fun setPackagesSuspendedAsUser(packageName: String, suspended: Boolean) {
HiddenApiBypass.addHiddenApiExemptions("")

IPackageManager.Stub.asInterface(
ShizukuBinderWrapper(SystemServiceHelper.getSystemService("package"))
).setPackagesSuspendedAsUser(
arrayOf(packageName),
suspended,
null,
null,
null,
"com.android.shell",
0
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.qhy040404.fxxkmiuiad.utils

enum class ShizukuStatus {
Ok,
Outdated,
NotRunning,
NotAuthorized,
NotInstalled
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,3 @@ object ShizukuUtils {
}
}

enum class ShizukuStatus {
Ok,
Outdated,
NotRunning,
NotAuthorized,
NotInstalled
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@
import android.os.Binder;
import android.os.IBinder;
import android.os.IInterface;
import android.os.PersistableBundle;
import android.os.RemoteException;

public interface IPackageManager extends IInterface {
void setApplicationEnabledSetting(String packageName, int newState, int flags, int userId, String callingPackage);

// String[] setPackagesSuspendedAsUser(String[] packageNames, boolean suspended,
// PersistableBundle appExtras, PersistableBundle launcherExtras,
// SuspendDialogInfo dialogInfo, String suspendingPackage,int flags);

String[] setPackagesSuspendedAsUser(String[] strArr, boolean z, PersistableBundle persistableBundle, PersistableBundle persistableBundle2, SuspendDialogInfo suspendDialogInfo, String str, int i) throws RemoteException;


abstract class Stub extends Binder implements IPackageManager {
public static IPackageManager asInterface(IBinder obj) {
throw new UnsupportedOperationException();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package android.content.pm;

public final class SuspendDialogInfo {
}

0 comments on commit d8be5f8

Please sign in to comment.