From 7b5e4c0fbe4def62b3181610bc97c4789fac39d8 Mon Sep 17 00:00:00 2001 From: ryuunoakaihitomi <22442525+ryuunoakaihitomi@users.noreply.github.com> Date: Tue, 3 May 2022 00:08:57 +0800 Subject: [PATCH] =?UTF-8?q?R3.15.7=20#31=20=E6=B7=BB=E5=8A=A0=E5=AF=B9Sui?= =?UTF-8?q?=E7=9A=84=E6=94=AF=E6=8C=81=EF=BC=8C=E6=84=9F=E8=B0=A2@Kazurin-?= =?UTF-8?q?775=20=E9=99=84=E5=8A=A0=E7=BB=84=E4=BB=B6=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 18 +++++++++--------- .../powerpanel/ui/main/MainActivity.kt | 6 ++++-- .../powerpanel/ui/main/PowerViewModel.kt | 19 +++++++++++++------ build.gradle | 2 +- 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index b972c8e..36de6dd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -21,10 +21,10 @@ android { //targetSdkVersion compileSdkVersion targetSdkVersion 32 // 版本号:发布日期 - versionCode 20220419 + versionCode 20220503 // 版本名说明: R3.x.y.z (R3:Refactoring 第三次重构,z:Quick Fix序号) // 不要包含非ASCII可打印字符,会导致Github release文件名异常 - versionName 'R3.15.7' + versionName 'R3.15.8' resConfigs "en", "zh-rCN" buildConfigField 'String', 'BUILD_TIME', '\"' + new Date() + '\"' @@ -132,12 +132,12 @@ dependencies { implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version" // https://github.com/firebase/firebase-android-sdk - normalImplementation platform('com.google.firebase:firebase-bom:29.2.1') + normalImplementation platform('com.google.firebase:firebase-bom:29.3.1') normalImplementation 'com.google.firebase:firebase-analytics-ktx' normalImplementation 'com.google.firebase:firebase-crashlytics-ktx' // https://github.com/microsoft/appcenter-sdk-android - normalImplementation 'com.microsoft.appcenter:appcenter-analytics:4.4.2' + normalImplementation 'com.microsoft.appcenter:appcenter-analytics:4.4.3' /* ------- 其他第三方开源组件 ------- */ @@ -154,7 +154,7 @@ dependencies { implementation "dev.rikka.shizuku:provider:$shizuku_version" // https://github.com/ryuunoakaihitomi/PowerAct - implementation 'github.ryuunoakaihitomi.poweract:poweract:1.6.1' + implementation 'github.ryuunoakaihitomi.poweract:poweract:1.7.1' // https://github.com/ryuunoakaihitomi/ReToast runtimeOnly 'github.ryuunoakaihitomi.retoast:retoast:2.0.0' @@ -189,10 +189,10 @@ dependencies { implementation 'com.jakewharton.timber:timber:5.0.1' // https://github.com/PureWriter/about-page - implementation 'com.drakeet.about:about:2.5.0' + implementation 'com.drakeet.about:about:2.5.1' // https://github.com/zxing/zxing - implementation 'com.google.zxing:core:3.4.1' + implementation 'com.google.zxing:core:3.5.0' // https://github.com/CyanogenMod/cm_platform_sdk implementation 'org.cyanogenmod:platform.sdk:6.0' @@ -207,10 +207,10 @@ dependencies { implementation 'dev.rikka.rikkax.compatibility:compatibility:2.0.0' // https://github.com/KyuubiRan/EzXHelper - implementation 'com.github.kyuubiran:EzXHelper:0.8.6' + implementation 'com.github.kyuubiran:EzXHelper:0.8.8' // https://github.com/square/leakcanary - debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.8.1' + debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.9.1' // https://github.com/whataa/pandora // 最新版是v2.1.0,仅支持android-support diff --git a/app/src/main/java/github/ryuunoakaihitomi/powerpanel/ui/main/MainActivity.kt b/app/src/main/java/github/ryuunoakaihitomi/powerpanel/ui/main/MainActivity.kt index 91e7724..b92a11f 100644 --- a/app/src/main/java/github/ryuunoakaihitomi/powerpanel/ui/main/MainActivity.kt +++ b/app/src/main/java/github/ryuunoakaihitomi/powerpanel/ui/main/MainActivity.kt @@ -58,6 +58,7 @@ import io.noties.markwon.image.ImagesPlugin import org.apache.commons.io.IOUtils import rikka.compatibility.DeviceCompatibility import rikka.shizuku.Shizuku +import rikka.sui.Sui import timber.log.Timber import java.nio.charset.Charset import java.util.* @@ -97,9 +98,10 @@ class MainActivity : AppCompatActivity() { } powerViewModel.infoArray.observe(this) { val rootMode = powerViewModel.rootMode.value ?: false - /* 特权模式下主动请求Shizuku授权,在受限模式下PowerAct已经处理好这个步骤 */ + // 特权模式下(或者发现 Sui 时)主动请求 Shizuku 授权 + // 在受限模式下 PowerAct 已经处理好这个步骤 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && - rootMode && Shizuku.pingBinder() && + (rootMode || Sui.isSui()) && Shizuku.pingBinder() && Shizuku.checkSelfPermission() != PackageManager.PERMISSION_GRANTED ) { Timber.i("Request shizuku permission.") diff --git a/app/src/main/java/github/ryuunoakaihitomi/powerpanel/ui/main/PowerViewModel.kt b/app/src/main/java/github/ryuunoakaihitomi/powerpanel/ui/main/PowerViewModel.kt index 95c3daf..1082799 100644 --- a/app/src/main/java/github/ryuunoakaihitomi/powerpanel/ui/main/PowerViewModel.kt +++ b/app/src/main/java/github/ryuunoakaihitomi/powerpanel/ui/main/PowerViewModel.kt @@ -24,6 +24,7 @@ import github.ryuunoakaihitomi.powerpanel.util.RC import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import rikka.shizuku.Shizuku +import rikka.sui.Sui import timber.log.Timber // AndroidViewModel 因为魔法问题不可用了 @@ -60,14 +61,20 @@ class PowerViewModel : ViewModel() { // 用来显示对话框 fun prepare() { viewModelScope.launch(Dispatchers.IO) { - // 在这里提供root状态 - // 由于libsu 4.0.0的变更,Shell.rootAccess()在返回true的情况下不再准确;需要进一步判断 - val isRoot = if (Shell.rootAccess()) { - Shell.getShell().isRoot - } else false + val hasPrivilege = if (Sui.isSui()) { + // use Sui whenever available + Shizuku.checkSelfPermission() == PackageManager.PERMISSION_GRANTED + } else { + // if Sui is not present, fallback to plain old su + // 在这里提供root状态 + // 由于libsu 4.0.0的变更,Shell.rootAccess()在返回true的情况下不再准确;需要进一步判断 + if (Shell.rootAccess()) { + Shell.getShell().isRoot + } else false + } viewModelScope.launch { - _rootMode.value = isRoot + _rootMode.value = hasPrivilege forceMode.value = false changeInfo() } diff --git a/build.gradle b/build.gradle index 14f744f..2dd3958 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ buildscript { - ext.kotlin_version = '1.6.10' + ext.kotlin_version = '1.6.20' repositories { google() mavenCentral()