Skip to content

Commit

Permalink
refactor: UI, SERVER_API
Browse files Browse the repository at this point in the history
SERVER_API: io.github.iamr0s:Dhizuku-SERVER_API
SERVER_API source: https://github.com/iamr0s/Dhizuku-API
  • Loading branch information
iamr0s committed Aug 19, 2024
1 parent 8dbe3f9 commit 9c3ae04
Show file tree
Hide file tree
Showing 107 changed files with 1,796 additions and 3,210 deletions.
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

1 change: 0 additions & 1 deletion api
Submodule api deleted from b17a8c
17 changes: 4 additions & 13 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import org.jetbrains.kotlin.konan.properties.loadProperties
import java.util.Properties

@Suppress("DSL_SCOPE_VIOLATION")
plugins {
alias(libs.plugins.agp.app)
alias(libs.plugins.kotlin)
id("kotlin-kapt")
alias(libs.plugins.ksp)
alias(libs.plugins.compose.compiler)
}

val keystoreDir = "$rootDir/keystore"
Expand All @@ -22,11 +22,11 @@ for (name in arrayOf("r0s.properties", "debug.properties")) {
android {
namespace = "com.rosan.dhizuku"

compileSdk = 34
compileSdk = 35

defaultConfig {
minSdk = 21
targetSdk = 34
targetSdk = 35
val versionProps = loadProperties("$rootDir/version.properties")
versionCode = versionProps.getProperty("versionCode").toInt()
versionName = versionProps.getProperty("versionName")
Expand Down Expand Up @@ -92,27 +92,20 @@ android {
buildFeatures {
buildConfig = true
compose = true
aidl = true
}

dependenciesInfo {
includeInApk = false
includeInBundle = false
}

composeOptions {
kotlinCompilerExtensionVersion = libs.versions.compose.compiler.get()
}

ksp {
arg("room.schemaLocation", "$projectDir/schemas")
}
}

dependencies {
compileOnly(project(":hidden-api"))
implementation(project(":dhizuku-aidl"))
implementation(project(":dhizuku-shared"))

implementation(libs.androidx.core)
implementation(libs.androidx.lifecycle)
Expand All @@ -133,8 +126,6 @@ dependencies {
implementation(libs.koin.android)
implementation(libs.koin.compose)

implementation(libs.lottie.compose)

implementation(libs.accompanist)
implementation(libs.accompanist.navigationAnimation)
implementation(libs.accompanist.flowlayout)
Expand All @@ -148,5 +139,5 @@ dependencies {
implementation(libs.rikka.shizuku.api)
implementation(libs.rikka.shizuku.provider)

implementation(libs.iamr0s.androidAppProcess)
implementation(libs.iamr0s.dhizuku.api)
}
32 changes: 18 additions & 14 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,35 @@
</activity>

<provider
android:name=".server.DhizukuProvider"
android:name=".server.MyDhizukuProvider"
android:authorities="com.rosan.dhizuku.server.provider"
android:directBootAware="true"
android:enabled="true"
android:exported="true"
tools:ignore="ExportedContentProvider,UnusedAttribute" />
tools:ignore="ExportedContentProvider,UnusedAttribute">
<intent-filter>
<action android:name="com.rosan.dhizuku.server.provider" />
</intent-filter>
</provider>

<service
android:name=".server.RunningService"
android:directBootAware="true"
android:exported="false"
android:foregroundServiceType="remoteMessaging"
tools:ignore="UnusedAttribute">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</service>

<receiver
android:name=".server.DhizukuDAReceiver"
android:exported="false"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data
android:name="android.app.device_admin"
android:resource="@xml/device_admin" />
android:resource="@xml/dhizuku_device_admin" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
<action android:name="android.app.action.DEVICE_ADMIN_DISABLE_REQUESTED" />
Expand Down Expand Up @@ -92,17 +107,6 @@
android:multiprocess="false"
android:permission="android.permission.INTERACT_ACROSS_USERS_FULL" />

<service
android:name=".server.DhizukuService"
android:directBootAware="true"
android:exported="false"
android:foregroundServiceType="remoteMessaging"
tools:ignore="UnusedAttribute">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</service>

</application>

</manifest>

This file was deleted.

This file was deleted.

6 changes: 0 additions & 6 deletions app/src/main/aidl/com/rosan/dhizuku/aidl/ITest.aidl

This file was deleted.

70 changes: 15 additions & 55 deletions app/src/main/java/com/rosan/dhizuku/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,79 +3,39 @@ package com.rosan.dhizuku
import android.app.Application
import android.app.admin.DevicePolicyManager
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.common.util.clearDelegatedScopes
import com.rosan.dhizuku.data.common.util.getPackageInfoForUid
import com.rosan.dhizuku.data.common.util.signature
import com.rosan.dhizuku.data.settings.repo.AppRepo
import com.rosan.dhizuku.di.init.appModules
import com.rosan.dhizuku.server.DhizukuService
import com.rosan.dhizuku.shared.DhizukuVariables
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import com.rosan.dhizuku.server.DhizukuState
import com.rosan.dhizuku.server.RunningService
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
import org.koin.core.context.startKoin
import org.koin.dsl.module
import rikka.sui.Sui

class App : Application(), KoinComponent {
private val scope = CoroutineScope(Dispatchers.IO)

private val repo by inject<AppRepo>()

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

var isDeviceAdminer by mutableStateOf(false)
private set

var isDeviceOwner by mutableStateOf(false)
private set

var isProfileOwner by mutableStateOf(false)
private set

var isOwner by mutableStateOf(false)
private set

override fun onCreate() {
super.onCreate()
syncOwnerStatus()
DhizukuState.sync(getSystemService(Context.DEVICE_POLICY_SERVICE) as DevicePolicyManager)
startKoin {
androidLogger()
androidContext(this@App)
modules(appModules)
modules(module { single { this@App } })
}
Sui.init(packageName)
syncAppRepo()
DhizukuService.start(this)
}

fun syncOwnerStatus() {
isDeviceAdminer = devicePolicyManager.isAdminActive(DhizukuVariables.COMPONENT_NAME)
isDeviceOwner = devicePolicyManager.isDeviceOwnerApp(packageName)
isProfileOwner = devicePolicyManager.isProfileOwnerApp(packageName)
isOwner = isDeviceOwner || isProfileOwner
RunningService.start(this)
}

fun syncAppRepo() = scope.launch {
repo.all().forEach {
val packageInfo = packageManager.getPackageInfoForUid(it.uid)
if (it.allowApi &&
packageInfo != null &&
it.signature == packageInfo.signature
) return@forEach
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) clearDelegatedScopes(it.uid)
repo.delete(it)
}
}
// fun syncAppRepo() = scope.launch {
// repo.all().forEach {
// val packageInfo = packageManager.getPackageInfoForUid(it.uid)
// if (it.allowApi &&
// packageInfo != null &&
// it.signature == packageInfo.signature
// ) return@forEach
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) clearDelegatedScopes(it.uid)
// repo.delete(it)
// }
// }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.rosan.dhizuku.data.common.model.exception

class DhizukuNotWorkException : RuntimeException {
constructor() : super()

constructor(message: String?) : super(message)

constructor(cause: Throwable?) : super(cause)

constructor(message: String?, cause: Throwable?) : super(message, cause)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import android.os.Looper
import android.widget.Toast
import androidx.annotation.RequiresApi
import androidx.annotation.StringRes
import com.rosan.dhizuku.shared.DhizukuVariables
import com.rosan.dhizuku.server.DhizukuDAReceiver

fun Context.openUrlInBrowser(url: String) {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
Expand All @@ -34,7 +34,7 @@ fun Context.clearDelegatedScopes(uid: Int) {
val devicePolicyManager = getSystemService(Context.DEVICE_POLICY_SERVICE) as DevicePolicyManager
packageNames.forEach {
devicePolicyManager.setDelegatedScopes(
DhizukuVariables.COMPONENT_NAME,
DhizukuDAReceiver.name,
it,
emptyList()
)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.rosan.dhizuku.data.common.util

import android.content.pm.PackageManager
import com.rosan.dhizuku.api.Dhizuku
import com.rosan.dhizuku.api.DhizukuRequestPermissionListener
import com.rosan.dhizuku.data.common.model.exception.DhizukuNotWorkException
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.first

private suspend fun blockingRequestDhizukuPermission() = callbackFlow {
Dhizuku.requestPermission(object : DhizukuRequestPermissionListener() {
override fun onRequestPermission(grantResult: Int) {
if (grantResult == PackageManager.PERMISSION_GRANTED) trySend(Unit)
else close(DhizukuNotWorkException("dhizuku permission denied"))
}
})
awaitClose()
}.catch {
throw if (it !is DhizukuNotWorkException) DhizukuNotWorkException(cause = it)
else it
}.first()

suspend fun <T> requireDhizukuPermissionGranted(action: suspend () -> T): T {
if (!Dhizuku.init()) throw DhizukuNotWorkException("dhizuku isn't activated")
if (!Dhizuku.isPermissionGranted())
blockingRequestDhizukuPermission()
return action()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.rosan.dhizuku.data.common.util

fun Int.has(flag: Int) = this and flag != 0
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import android.content.pm.PackageManager
import android.os.Build

fun PackageManager.getPackageNameForUid(uid: Int): String? =
getNameForUid(uid) ?: getPackagesForUid(uid)?.first()
getPackagesForUid(uid)?.first()

fun PackageManager.getPackageInfoForUid(
uid: Int,
Expand Down
Loading

0 comments on commit 9c3ae04

Please sign in to comment.