Skip to content

Commit

Permalink
Dhizuku v2.8
Browse files Browse the repository at this point in the history
Add DelegatedScopes interface.
  • Loading branch information
iamr0s committed Jul 5, 2023
1 parent 3490a31 commit ba9339a
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 16 deletions.
2 changes: 1 addition & 1 deletion api
Submodule api updated 71 files
+22 −77 README.md
+72 −0 README_zh_rCN.md
+1 −1 build.gradle
+0 −0 demo-binder_wrapper/.gitignore
+44 −0 demo-binder_wrapper/build.gradle
+0 −0 demo-binder_wrapper/proguard-rules.pro
+1 −1 demo-binder_wrapper/src/androidTest/java/com/rosan/dhizuku/demo/ExampleInstrumentedTest.java
+5 −6 demo-binder_wrapper/src/main/AndroidManifest.xml
+1 −1 demo-binder_wrapper/src/main/java/com/rosan/dhizuku/demo/App.java
+36 −0 demo-binder_wrapper/src/main/java/com/rosan/dhizuku/demo/BaseActivity.java
+94 −0 demo-binder_wrapper/src/main/java/com/rosan/dhizuku/demo/MainActivity.java
+40 −0 demo-binder_wrapper/src/main/res/layout/main_activity.xml
+16 −0 demo-binder_wrapper/src/main/res/values-night/themes.xml
+9 −0 demo-binder_wrapper/src/main/res/values-zh-rCN/strings.xml
+0 −0 demo-binder_wrapper/src/main/res/values/colors.xml
+10 −0 demo-binder_wrapper/src/main/res/values/strings.xml
+16 −0 demo-binder_wrapper/src/main/res/values/themes.xml
+1 −1 demo-binder_wrapper/src/test/java/com/rosan/dhizuku/demo/ExampleUnitTest.java
+1 −0 demo-delegated_scopes/.gitignore
+43 −0 demo-delegated_scopes/build.gradle
+21 −0 demo-delegated_scopes/proguard-rules.pro
+26 −0 demo-delegated_scopes/src/androidTest/java/com/rosan/dhizuku/demo/ExampleInstrumentedTest.java
+22 −0 demo-delegated_scopes/src/main/AndroidManifest.xml
+13 −0 demo-delegated_scopes/src/main/java/com/rosan/dhizuku/demo/App.java
+36 −0 demo-delegated_scopes/src/main/java/com/rosan/dhizuku/demo/BaseActivity.java
+86 −0 demo-delegated_scopes/src/main/java/com/rosan/dhizuku/demo/MainActivity.java
+40 −0 demo-delegated_scopes/src/main/res/layout/main_activity.xml
+16 −0 demo-delegated_scopes/src/main/res/values-night/themes.xml
+10 −0 demo-delegated_scopes/src/main/res/values-zh-rCN/strings.xml
+10 −0 demo-delegated_scopes/src/main/res/values/colors.xml
+11 −0 demo-delegated_scopes/src/main/res/values/strings.xml
+16 −0 demo-delegated_scopes/src/main/res/values/themes.xml
+17 −0 demo-delegated_scopes/src/test/java/com/rosan/dhizuku/demo/ExampleUnitTest.java
+5 −5 demo-user_service/build.gradle
+26 −0 demo-user_service/src/androidTest/java/com/rosan/dhizuku/demo/ExampleInstrumentedTest.java
+7 −1 demo-user_service/src/main/aidl/com/rosan/dhizuku/demo/IUserService.aidl
+13 −0 demo-user_service/src/main/java/com/rosan/dhizuku/demo/App.java
+13 −7 demo-user_service/src/main/java/com/rosan/dhizuku/demo/MainActivity.java
+16 −2 demo-user_service/src/main/java/com/rosan/dhizuku/demo/UserService.java
+12 −0 demo-user_service/src/main/res/layout/main_activity.xml
+2 −0 demo-user_service/src/main/res/values-zh-rCN/strings.xml
+2 −0 demo-user_service/src/main/res/values/strings.xml
+17 −0 demo-user_service/src/test/java/com/rosan/dhizuku/demo/ExampleUnitTest.java
+0 −70 demo/build.gradle
+0 −24 demo/src/androidTest/java/com/rosan/dhizuku/demo/ExampleInstrumentedTest.kt
+0 −188 demo/src/main/java/com/rosan/dhizuku/demo/MainActivity.kt
+0 −37 demo/src/main/java/com/rosan/dhizuku/demo/PackageInstallerHelper.java
+0 −11 demo/src/main/java/com/rosan/dhizuku/demo/ui/theme/Color.kt
+0 −70 demo/src/main/java/com/rosan/dhizuku/demo/ui/theme/Theme.kt
+0 −34 demo/src/main/java/com/rosan/dhizuku/demo/ui/theme/Type.kt
+0 −30 demo/src/main/res/drawable-v24/ic_launcher_foreground.xml
+0 −170 demo/src/main/res/drawable/ic_launcher_background.xml
+0 −6 demo/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
+0 −6 demo/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
+ demo/src/main/res/mipmap-hdpi/ic_launcher.webp
+ demo/src/main/res/mipmap-hdpi/ic_launcher_round.webp
+ demo/src/main/res/mipmap-mdpi/ic_launcher.webp
+ demo/src/main/res/mipmap-mdpi/ic_launcher_round.webp
+ demo/src/main/res/mipmap-xhdpi/ic_launcher.webp
+ demo/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
+ demo/src/main/res/mipmap-xxhdpi/ic_launcher.webp
+ demo/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
+ demo/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
+ demo/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
+0 −3 demo/src/main/res/values/strings.xml
+0 −5 demo/src/main/res/values/themes.xml
+0 −17 demo/src/test/java/com/rosan/dhizuku/demo/ExampleUnitTest.kt
+5 −0 dhizuku-aidl/src/main/aidl/com/rosan/dhizuku/aidl/IDhizuku.aidl
+20 −0 dhizuku-api-impl/src/main/java/com/rosan/dhizuku/api/Dhizuku.java
+13 −0 hidden-api/src/main/java/android/app/admin/IDevicePolicyManager.java
+2 −0 settings.gradle
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ android {
applicationId = "com.rosan.dhizuku"
minSdk = 21
targetSdk = 33
versionCode = 10
versionName = "2.7"
versionCode = 11
versionName = "2.8"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
23 changes: 16 additions & 7 deletions app/src/main/java/com/rosan/dhizuku/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package com.rosan.dhizuku

import android.app.Application
import android.app.admin.DevicePolicyManager
import android.content.ComponentName
import android.content.Context
import android.os.Build
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import com.rosan.dhizuku.data.settings.repo.AppRepo
import com.rosan.dhizuku.di.init.appModules
import com.rosan.dhizuku.server.DhizukuDAReceiver
import com.rosan.dhizuku.server.DhizukuService
import com.rosan.dhizuku.shared.DhizukuVariables
import com.rosan.dhizuku.util.clearDelegatedScopes
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand All @@ -27,6 +28,10 @@ class App : Application(), KoinComponent {

private val appRepo by inject<AppRepo>()

private val devicePolicyManager by lazy {
getSystemService(Context.DEVICE_POLICY_SERVICE) as DevicePolicyManager
}

var isDeviceAdminer by mutableStateOf(false)
private set

Expand Down Expand Up @@ -54,10 +59,9 @@ class App : Application(), KoinComponent {
}

fun syncOwnerStatus() {
val manager = getSystemService(Context.DEVICE_POLICY_SERVICE) as DevicePolicyManager
isDeviceAdminer = manager.isAdminActive(ComponentName(this, DhizukuDAReceiver::class.java))
isDeviceOwner = manager.isDeviceOwnerApp(packageName)
isProfileOwner = manager.isProfileOwnerApp(packageName)
isDeviceAdminer = devicePolicyManager.isAdminActive(DhizukuVariables.COMPONENT_NAME)
isDeviceOwner = devicePolicyManager.isDeviceOwnerApp(packageName)
isProfileOwner = devicePolicyManager.isProfileOwnerApp(packageName)
isOwner = isDeviceOwner || isProfileOwner
}

Expand All @@ -67,7 +71,12 @@ class App : Application(), KoinComponent {
if (
packageManager.getPackagesForUid(it.uid).isNullOrEmpty() ||
!it.allowApi
) appRepo.delete(it)
) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
clearDelegatedScopes(it.uid)
}
appRepo.delete(it)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.rosan.dhizuku.server

val DHIZUKU_SERVRE_VERSION_CODE = 4
val DHIZUKU_SERVRE_VERSION_CODE = 5

val DHIZUKU_SERVER_VERSION_NAME = "1.4"
val DHIZUKU_SERVER_VERSION_NAME = "1.5"
27 changes: 27 additions & 0 deletions app/src/main/java/com/rosan/dhizuku/server/impl/IDhizukuImpl.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package com.rosan.dhizuku.server.impl

import android.app.admin.DevicePolicyManager
import android.content.Context
import android.content.SharedPreferences
import android.os.Binder
import android.os.Build
import android.os.Bundle
import android.os.IBinder
import android.os.Parcel
import androidx.annotation.RequiresApi
import com.rosan.dhizuku.R
import com.rosan.dhizuku.aidl.IDhizuku
import com.rosan.dhizuku.aidl.IDhizukuClient
import com.rosan.dhizuku.aidl.IDhizukuRemoteProcess
import com.rosan.dhizuku.aidl.IDhizukuUserServiceConnection
import com.rosan.dhizuku.data.reflect.repo.ReflectRepo
import com.rosan.dhizuku.data.settings.repo.AppRepo
import com.rosan.dhizuku.server.DHIZUKU_SERVER_VERSION_NAME
import com.rosan.dhizuku.server.DHIZUKU_SERVRE_VERSION_CODE
Expand All @@ -32,6 +36,12 @@ class IDhizukuImpl(private val client: IDhizukuClient? = null) : IDhizuku.Stub()

private val context by inject<Context>()

private val reflect by inject<ReflectRepo>()

private val devicePolicyManager by lazy {
context.getSystemService(Context.DEVICE_POLICY_SERVICE) as DevicePolicyManager
}

private val appRepo by inject<AppRepo>()

override fun getVersionCode(): Int = DHIZUKU_SERVRE_VERSION_CODE
Expand Down Expand Up @@ -98,6 +108,23 @@ class IDhizukuImpl(private val client: IDhizukuClient? = null) : IDhizuku.Stub()
DhizukuUserServiceConnections.unbind(uid, pid, args)
}

@RequiresApi(Build.VERSION_CODES.O)
override fun getDelegatedScopes(packageName: String): Array<String> {
requireCallingPermission("get_delegated_scopes")
return devicePolicyManager.getDelegatedScopes(DhizukuVariables.COMPONENT_NAME, packageName)
.toTypedArray()
}

@RequiresApi(Build.VERSION_CODES.O)
override fun setDelegatedScopes(packageName: String, scopes: Array<out String>) {
requireCallingPermission("set_delegated_scopes")
return devicePolicyManager.setDelegatedScopes(
DhizukuVariables.COMPONENT_NAME,
packageName,
scopes.toList()
)
}

override fun onTransact(code: Int, data: Parcel, reply: Parcel?, flags: Int): Boolean {
if (code == DhizukuVariables.TRANSACT_CODE_REMOTE_BINDER) {
val targetData = Parcel.obtain()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package com.rosan.dhizuku.ui.activity

import android.content.Intent
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.imePadding
import androidx.compose.material.AlertDialog
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import com.hjq.permissions.Permission
import com.hjq.permissions.XXPermissions
import com.rosan.dhizuku.server.DhizukuService
import com.rosan.dhizuku.ui.page.settings.SettingsPage
import com.rosan.dhizuku.ui.theme.InstallerTheme
import kotlinx.coroutines.CoroutineScope
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.rosan.dhizuku.ui.page.settings.config

import android.content.Context
import android.os.Build
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
Expand All @@ -9,6 +10,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.rosan.dhizuku.data.settings.model.room.entity.AppEntity
import com.rosan.dhizuku.data.settings.repo.AppRepo
import com.rosan.dhizuku.util.clearDelegatedScopes
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -97,6 +99,9 @@ class ConfigViewModel(
return@launch
}
entity.allowApi = allowApi
if (!allowApi && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.clearDelegatedScopes(entity.uid)
}
repo.update(entity)
}
}
Expand Down
19 changes: 18 additions & 1 deletion app/src/main/java/com/rosan/dhizuku/util/ContextUtil.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package com.rosan.dhizuku.util

import android.app.admin.DevicePolicyManager
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Handler
import android.os.Looper
import android.widget.Toast
import androidx.annotation.RequiresApi
import androidx.annotation.StringRes
import com.rosan.dhizuku.shared.DhizukuVariables

fun Context.openUrlInBrowser(url: String) {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
Expand All @@ -22,4 +26,17 @@ fun Context.toast(text: CharSequence, duration: Int = Toast.LENGTH_SHORT) {

fun Context.toast(@StringRes resId: Int, duration: Int = Toast.LENGTH_SHORT) {
toast(getString(resId), duration)
}
}

@RequiresApi(Build.VERSION_CODES.O)
fun Context.clearDelegatedScopes(uid: Int) {
val packageNames = packageManager.getPackagesForUid(uid) ?: emptyArray()
val devicePolicyManager = getSystemService(Context.DEVICE_POLICY_SERVICE) as DevicePolicyManager
packageNames.forEach {
devicePolicyManager.setDelegatedScopes(
DhizukuVariables.COMPONENT_NAME,
it,
emptyList()
)
}
}

0 comments on commit ba9339a

Please sign in to comment.