Skip to content
This repository has been archived by the owner on Nov 20, 2023. It is now read-only.

feat: add Shizuku installation support #83

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,9 @@ dependencies {

// Markdown to HTML
implementation(libs.markdown)

// Shizuku
implementation(libs.shizuku.api)
implementation(libs.shizuku.provider)
compileOnly(libs.hidden.stub)
}
16 changes: 16 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,21 @@
android:value="androidx.startup"
tools:node="remove" />
</provider>
<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" />
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
</application>
</manifest>
2 changes: 2 additions & 0 deletions app/src/main/java/app/revanced/manager/di/ServiceModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package app.revanced.manager.di
import app.revanced.manager.network.service.GithubService
import app.revanced.manager.network.service.HttpService
import app.revanced.manager.network.service.ReVancedService
import app.revanced.manager.service.ShizukuService
import org.koin.core.module.dsl.singleOf
import org.koin.dsl.module

Expand All @@ -18,4 +19,5 @@ val serviceModule = module {
single { provideReVancedService(get()) }
singleOf(::HttpService)
singleOf(::GithubService)
singleOf(::ShizukuService)
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
package app.revanced.manager.domain.manager

import android.content.Context
import app.revanced.manager.R
import app.revanced.manager.domain.manager.base.BasePreferencesManager
import app.revanced.manager.ui.theme.Theme

class PreferencesManager(
context: Context
) : BasePreferencesManager(context, "settings") {

enum class InstallerManager(val displayName: Int) {
DEFAULT(R.string.default_installer),
SHIZUKU(R.string.shizuku_installer),
ROOT(R.string.root_installer),
MAGISK(R.string.magisk_installer),
}

val dynamicColor = booleanPreference("dynamic_color", true)
val theme = enumPreference("theme", Theme.SYSTEM)

Expand All @@ -18,6 +27,7 @@ class PreferencesManager(
val keystorePass = stringPreference("keystore_pass", KeystoreManager.DEFAULT)

val preferSplits = booleanPreference("prefer_splits", false)
val defaultInstaller = enumPreference("installer", InstallerManager.DEFAULT)

val showAutoUpdatesDialog = booleanPreference("show_auto_updates_dialog", true)
val managerAutoUpdates = booleanPreference("manager_auto_updates", false)
Expand Down
43 changes: 43 additions & 0 deletions app/src/main/java/app/revanced/manager/service/ShizukuService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package app.revanced.manager.service

import android.app.Application
import android.content.Intent
import android.content.pm.PackageManager
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.core.content.FileProvider
import app.revanced.manager.util.PM
import rikka.shizuku.Shizuku
import java.io.File

class ShizukuService(
private val app: Application,
private val pm: PM
) {
var isPermissionGranted by mutableStateOf(false)

init {
Shizuku.addBinderReceivedListenerSticky {
isPermissionGranted = Shizuku.checkSelfPermission() == PackageManager.PERMISSION_GRANTED
}
Shizuku.addBinderDeadListener {
isPermissionGranted = false
}
}

fun installPackage(file: File) {
val intent = Intent(Intent.ACTION_VIEW, FileProvider.getUriForFile(app, "app.revanced.manager.provider", file)
).apply {
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
app.startActivity(intent)
}

fun isShizukuInstalled() = pm.getPackageInfo(shizukuPackageName) != null

companion object {
const val shizukuPackageName = "moe.shizuku.privileged.api"
}
}
84 changes: 84 additions & 0 deletions app/src/main/java/app/revanced/manager/ui/component/ShizukuCard.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package app.revanced.manager.ui.component

import android.util.Log
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Warning
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import app.revanced.manager.R
import app.revanced.manager.util.tag
import rikka.shizuku.Shizuku

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun ShizukuCard(
onPermissionResult: (Int, Int) -> Unit,
) {
DisposableEffect(Unit) {
Shizuku.addRequestPermissionResultListener(onPermissionResult)

onDispose {
Shizuku.removeRequestPermissionResultListener(onPermissionResult)
}
}

Card(
colors = CardDefaults.cardColors(
MaterialTheme.colorScheme.errorContainer
),
onClick = {
Log.i(tag, "Requesting permission")
Shizuku.requestPermission(114514)
Aunali321 marked this conversation as resolved.
Show resolved Hide resolved
},
modifier = Modifier
.fillMaxWidth()
.padding(16.dp)
.clip(RoundedCornerShape(24.dp))
.background(MaterialTheme.colorScheme.tertiaryContainer),
) {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(16.dp)
) {
Icon(
imageVector = Icons.Default.Warning,
contentDescription = null,
tint = MaterialTheme.colorScheme.onErrorContainer,
modifier = Modifier.size(24.dp)
)
Column {
Text(
text = stringResource(R.string.shizuku_unavailable),
style = MaterialTheme.typography.titleMedium
)
Text(
text = stringResource(R.string.home_shizuku_warning),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onErrorContainer
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ fun DashboardScreen(
)
}
}

HorizontalPager(
pageCount = pages.size,
state = pagerState,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package app.revanced.manager.ui.screen

import android.content.pm.PackageManager
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.fillMaxSize
Expand All @@ -21,6 +23,7 @@ import app.revanced.manager.data.room.apps.installed.InstalledApp
import app.revanced.manager.ui.component.AppIcon
import app.revanced.manager.ui.component.AppLabel
import app.revanced.manager.ui.component.LoadingIndicator
import app.revanced.manager.ui.component.ShizukuCard
import app.revanced.manager.ui.viewmodel.InstalledAppsViewModel
import org.koin.androidx.compose.getViewModel

Expand All @@ -36,8 +39,18 @@ fun InstalledAppsScreen(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = installedApps?.let { if (it.isEmpty()) Arrangement.Center else Arrangement.Top } ?: Arrangement.Center
) {
item {
AnimatedVisibility(
visible = viewModel.shizukuService.isShizukuInstalled() && !viewModel.shizukuService.isPermissionGranted
) {
ShizukuCard(
onPermissionResult = { _, grantResult ->
viewModel.shizukuService.isPermissionGranted = grantResult == PackageManager.PERMISSION_GRANTED
}
)
}
}
installedApps?.let { installedApps ->

if (installedApps.isNotEmpty()) {
items(
installedApps,
Expand Down
Loading
Loading