mirror of
https://github.com/awfixers-stuff/OwnDroid.git
synced 2026-03-23 11:05:59 +00:00
remove shizuku-api dependency
This commit is contained in:
7
Guide.md
7
Guide.md
@@ -146,7 +146,7 @@ adb shell dpm remove-active-admin com.binbin.androidowner/com.binbin.androidowne
|
||||
|
||||
请自己学习如何启动[Shizuku](https://github.com/RikkaApps/Shizuku)
|
||||
|
||||
检查权限时如果返回“请更新Shizuku”,说明你的Shizuku版本小于v11,建议更新Shizuku。如果你的安卓版本不支持新的Shizuku,你仍然可以尝试使用下面这些功能
|
||||
如果Shizuku正在运行但是Android owner无法申请权限,请关闭Shizuku和Android owner的电池优化(这种情况在非原生系统中比较常见)
|
||||
|
||||
功能:
|
||||
|
||||
@@ -154,12 +154,13 @@ adb shell dpm remove-active-admin com.binbin.androidowner/com.binbin.androidowne
|
||||
- 激活Profile owner
|
||||
- 激活Device admin
|
||||
- 激活[由组织拥有的工作资料](#由组织拥有的工作资料)
|
||||
- 列出所有Device owner和Profile owner
|
||||
|
||||
Shizuku的本质是ADB。在安卓10或以下,你还是要连接电脑激活Shizuku
|
||||
|
||||
不能在非主用户中使用,即使检查权限返回“已授权”
|
||||
不能在非主用户中使用
|
||||
|
||||
因为作者懒得研究Shizuku-API,所以直接套壳了rish。因为是套壳的rish,所以不支持Sui
|
||||
因为作者懒得研究Shizuku-API,所以Android owner没有添加任何Shizuku相关依赖。以上功能均是通过rish实现。因为是套壳的rish,所以不支持Sui
|
||||
|
||||
### 设备唯一标识码
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@ android {
|
||||
applicationId = "com.binbin.androidowner"
|
||||
minSdk = 21
|
||||
targetSdk = 34
|
||||
versionCode = 17
|
||||
versionName = "4.0"
|
||||
versionCode = 18
|
||||
versionName = "4.1"
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
vectorDrawables {
|
||||
@@ -55,23 +55,20 @@ android {
|
||||
|
||||
dependencies {
|
||||
implementation("org.apache.commons:commons-io:1.3.2")
|
||||
val shizukuVersion = "13.1.5"
|
||||
implementation("dev.rikka.shizuku:api:$shizukuVersion")
|
||||
implementation("dev.rikka.shizuku:provider:$shizukuVersion")
|
||||
implementation("androidx.core:core-ktx:1.12.0")
|
||||
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2")
|
||||
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.7.0")
|
||||
implementation("androidx.activity:activity-compose:1.8.2")
|
||||
implementation(platform("androidx.compose:compose-bom:2023.08.00"))
|
||||
implementation(platform("androidx.compose:compose-bom:2024.02.01"))
|
||||
implementation("androidx.compose.ui:ui")
|
||||
implementation("androidx.compose.ui:ui-graphics")
|
||||
debugImplementation("androidx.compose.ui:ui-tooling-preview")
|
||||
implementation("androidx.compose.material3:material3:1.1.2")
|
||||
implementation("androidx.navigation:navigation-compose:2.7.6")
|
||||
implementation("androidx.compose.material3:material3:1.2.0")
|
||||
implementation("androidx.navigation:navigation-compose:2.7.7")
|
||||
testImplementation("junit:junit:4.13.2")
|
||||
androidTestImplementation("androidx.test.ext:junit:1.1.5")
|
||||
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
|
||||
androidTestImplementation(platform("androidx.compose:compose-bom:2023.08.00"))
|
||||
androidTestImplementation(platform("androidx.compose:compose-bom:2024.02.01"))
|
||||
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
|
||||
debugImplementation("androidx.compose.ui:ui-tooling")
|
||||
debugImplementation("androidx.compose.ui:ui-test-manifest:1.6.0")
|
||||
debugImplementation("androidx.compose.ui:ui-test-manifest:1.6.2")
|
||||
}
|
||||
@@ -73,12 +73,5 @@
|
||||
<action android:name="com.binbin.androidowner.PKG_INSTALL_RESULT"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<provider
|
||||
android:name="rikka.shizuku.ShizukuProvider"
|
||||
android:authorities="${applicationId}.shizuku"
|
||||
android:enabled="true"
|
||||
android:exported="true"
|
||||
android:multiprocess="false"
|
||||
android:permission="android.permission.INTERACT_ACROSS_USERS_FULL" />
|
||||
</application>
|
||||
</manifest>
|
||||
|
||||
@@ -40,7 +40,6 @@ import androidx.navigation.compose.composable
|
||||
import androidx.navigation.compose.currentBackStackEntryAsState
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import com.binbin.androidowner.ui.theme.AndroidOwnerTheme
|
||||
import rikka.shizuku.Shizuku
|
||||
import java.io.FileNotFoundException
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
@@ -57,22 +56,9 @@ var caCert = byteArrayOf()
|
||||
|
||||
@ExperimentalMaterial3Api
|
||||
class MainActivity : ComponentActivity() {
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
if(VERSION.SDK_INT>=24){
|
||||
Shizuku.removeBinderReceivedListener(ShizukuUtil.binderReceivedListener)
|
||||
Shizuku.removeBinderDeadListener(ShizukuUtil.binderDeadListener)
|
||||
Shizuku.removeRequestPermissionResultListener(ShizukuUtil.requestPermissionListener)
|
||||
}
|
||||
}
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||
super.onCreate(savedInstanceState)
|
||||
if(VERSION.SDK_INT>=24){
|
||||
Shizuku.addBinderReceivedListenerSticky(ShizukuUtil.binderReceivedListener)
|
||||
Shizuku.addBinderDeadListener(ShizukuUtil.binderDeadListener)
|
||||
Shizuku.addRequestPermissionResultListener(ShizukuUtil.requestPermissionListener)
|
||||
}
|
||||
getUserIcon = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
||||
userIconUri = it.data?.data
|
||||
if(userIconUri==null){ Toast.makeText(applicationContext, "空URI", Toast.LENGTH_SHORT).show() }
|
||||
|
||||
@@ -4,7 +4,6 @@ import android.app.admin.DevicePolicyManager
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Context.MODE_PRIVATE
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Binder
|
||||
import android.os.Build.VERSION
|
||||
import android.widget.Toast
|
||||
@@ -40,7 +39,6 @@ import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.apache.commons.io.IOUtils
|
||||
import rikka.shizuku.Shizuku
|
||||
import java.io.*
|
||||
|
||||
@Composable
|
||||
@@ -57,7 +55,7 @@ fun ShizukuActivate(){
|
||||
val coScope = rememberCoroutineScope()
|
||||
val scrollState = rememberScrollState()
|
||||
val outputTextScrollState = rememberScrollState()
|
||||
Column(modifier = Modifier.verticalScroll(scrollState)){
|
||||
Column(modifier = Modifier.fillMaxSize().verticalScroll(scrollState), horizontalAlignment = Alignment.CenterHorizontally){
|
||||
var outputText by remember{mutableStateOf("")}
|
||||
if(Binder.getCallingUid()/100000!=0){
|
||||
Row(modifier = sections(colorScheme.errorContainer), verticalAlignment = Alignment.CenterVertically){
|
||||
@@ -66,19 +64,25 @@ fun ShizukuActivate(){
|
||||
}
|
||||
}
|
||||
|
||||
var launchPermissionCheck by remember{mutableStateOf(false)}
|
||||
LaunchedEffect(launchPermissionCheck){
|
||||
if(launchPermissionCheck){
|
||||
outputText = checkPermission(myContext)
|
||||
scrollState.animateScrollTo(scrollState.maxValue, scrollAnim())
|
||||
launchPermissionCheck=false
|
||||
}
|
||||
}
|
||||
Button(
|
||||
onClick = {launchPermissionCheck=true},
|
||||
enabled = VERSION.SDK_INT>=24, modifier = Modifier.fillMaxWidth().padding(horizontal = 8.dp)
|
||||
onClick = {
|
||||
coScope.launch {
|
||||
scrollState.animateScrollTo(scrollState.maxValue, scrollAnim())
|
||||
outputTextScrollState.animateScrollTo(0, scrollAnim())
|
||||
val getUid = executeCommand(myContext, "sh rish.sh","id -u",null,filesDir)
|
||||
outputText = if(getUid.contains("2000")){
|
||||
myContext.getString(R.string.shizuku_activated_shell)
|
||||
}else if(getUid.contains("0")){
|
||||
myContext.getString(R.string.shizuku_activated_root)
|
||||
}else if(getUid.contains("Error: 1")){
|
||||
myContext.getString(R.string.shizuku_not_started)
|
||||
}else{
|
||||
getUid
|
||||
}
|
||||
}
|
||||
}
|
||||
) {
|
||||
Text(text = stringResource(R.string.check_permission))
|
||||
Text(text = stringResource(R.string.check_shizuku))
|
||||
}
|
||||
|
||||
if(!isDeviceOwner(myDpm)&&!isProfileOwner(myDpm)){
|
||||
@@ -160,7 +164,6 @@ fun ShizukuActivate(){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Button(
|
||||
onClick = {
|
||||
coScope.launch{
|
||||
@@ -168,27 +171,12 @@ fun ShizukuActivate(){
|
||||
scrollState.animateScrollTo(scrollState.maxValue, scrollAnim())
|
||||
outputTextScrollState.animateScrollTo(0, scrollAnim())
|
||||
}
|
||||
},
|
||||
modifier = Modifier.fillMaxWidth().padding(horizontal = 8.dp)
|
||||
}
|
||||
) {
|
||||
Text(text = stringResource(R.string.list_owners))
|
||||
}
|
||||
|
||||
Button(
|
||||
onClick = {
|
||||
coScope.launch {
|
||||
outputText= myContext.getString(R.string.should_contain_2000_or_0)
|
||||
scrollState.animateScrollTo(scrollState.maxValue, scrollAnim())
|
||||
outputTextScrollState.animateScrollTo(0, scrollAnim())
|
||||
outputText+=executeCommand(myContext, "sh rish.sh","id",null,filesDir)
|
||||
}
|
||||
},
|
||||
modifier = Modifier.align(Alignment.CenterHorizontally)
|
||||
) {
|
||||
Text(text = stringResource(R.string.test_rish))
|
||||
}
|
||||
|
||||
SelectionContainer(modifier = Modifier.horizontalScroll(outputTextScrollState)){
|
||||
SelectionContainer(modifier = Modifier.align(Alignment.Start).horizontalScroll(outputTextScrollState)){
|
||||
Text(text = outputText, style = bodyTextStyle, softWrap = false, modifier = Modifier.padding(4.dp))
|
||||
}
|
||||
|
||||
@@ -218,20 +206,6 @@ fun extractRish(myContext:Context){
|
||||
if(VERSION.SDK_INT>=34){ Runtime.getRuntime().exec("chmod 400 rish_shizuku.dex",null,myContext.filesDir) }
|
||||
}
|
||||
|
||||
private fun checkPermission(myContext: Context):String {
|
||||
return if(Shizuku.isPreV11()) {
|
||||
myContext.getString(R.string.please_update_shizuku)
|
||||
}else{
|
||||
try{
|
||||
if(Shizuku.checkSelfPermission()==PackageManager.PERMISSION_GRANTED) {
|
||||
val permission = when(Shizuku.getUid()){ 0->"Root"; 2000->"Shell"; else->myContext.getString(R.string.unknown) }
|
||||
myContext.getString(R.string.shizuku_permission_granted, Shizuku.getVersion().toString(), permission)
|
||||
}else if(Shizuku.shouldShowRequestPermissionRationale()){ myContext.getString(R.string.denied) }
|
||||
else{ Shizuku.requestPermission(0); myContext.getString(R.string.request_permission) }
|
||||
}catch(e: Throwable){ myContext.getString(R.string.shizuku_not_started) }
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun executeCommand(myContext: Context, command: String, subCommand:String, env: Array<String>?, dir:File?): String {
|
||||
var result = ""
|
||||
val tunnel:ByteArrayInputStream
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.binbin.androidowner;
|
||||
|
||||
import android.content.pm.PackageManager;
|
||||
import android.util.Log;
|
||||
import rikka.shizuku.Shizuku;
|
||||
|
||||
public class ShizukuUtil {
|
||||
private static void onRequestPermissionsResult(int requestCode, int grantResult) {
|
||||
boolean granted = PackageManager.PERMISSION_GRANTED == grantResult;
|
||||
Log.d("ShizukuUtil","RequestCode: "+requestCode);
|
||||
Log.d("ShizukuUtil","GrantState: "+granted);
|
||||
}
|
||||
static final Shizuku.OnRequestPermissionResultListener requestPermissionListener = ShizukuUtil::onRequestPermissionsResult;
|
||||
static final Shizuku.OnBinderReceivedListener binderReceivedListener = () -> Log.d("ShizukuUtil","Binder received");
|
||||
static final Shizuku.OnBinderDeadListener binderDeadListener = () -> Log.e("ShizukuUtil","Binder dead");
|
||||
}
|
||||
@@ -80,14 +80,9 @@
|
||||
<!--Shizuku-->
|
||||
<string name="shizuku">Shizuku</string>
|
||||
<string name="not_primary_user_not_support_shizuku">暂不支持在非主用户中使用Shizuku</string>
|
||||
<string name="check_permission">检查权限</string>
|
||||
<string name="check_shizuku">检查Shizuku</string>
|
||||
<string name="input_userid_of_work_profile">请输入工作资料的UserID</string>
|
||||
<string name="list_owners">列出Owners</string>
|
||||
<string name="should_contain_2000_or_0">下面应该出现一行包含“2000”或“0”的文本\n</string>
|
||||
<string name="test_rish">测试rish</string>
|
||||
<string name="please_update_shizuku">请更新Shizuku</string>
|
||||
<string name="shizuku_permission_granted">Shizuku v%1$s\n已授权(%2$s)</string>
|
||||
<string name="request_permission">请求授权</string>
|
||||
<string name="shizuku_not_started">服务未启动</string>
|
||||
<string name="activate_org_profile_command_with_user_id" tools:ignore="TypographyDashes">
|
||||
dpm mark-profile-owner-on-organization-owned-device --user %1$s com.binbin.androidowner/com.binbin.androidowner.MyDeviceAdminReceiver
|
||||
@@ -95,6 +90,8 @@
|
||||
<string name="dpm_activate_do_command">dpm set-device-owner com.binbin.androidowner/com.binbin.androidowner.MyDeviceAdminReceiver</string>
|
||||
<string name="dpm_activate_po_command">dpm set-profile-owner com.binbin.androidowner/com.binbin.androidowner.MyDeviceAdminReceiver</string>
|
||||
<string name="dpm_activate_da_command">dpm set-active-admin com.binbin.androidowner/com.binbin.androidowner.MyDeviceAdminReceiver</string>
|
||||
<string name="shizuku_activated_shell">已授权(Shell)</string>
|
||||
<string name="shizuku_activated_root">已授权(Root)</string>
|
||||
|
||||
<!--System-->
|
||||
<string name="device_ctrl">系统</string>
|
||||
|
||||
Reference in New Issue
Block a user