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 3 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("dev.rikka.shizuku:api:13.1.2")
implementation("dev.rikka.shizuku:provider:13.1.2")
compileOnly("dev.rikka.hidden:stub:4.2.0")
Aunali321 marked this conversation as resolved.
Show resolved Hide resolved
}
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="app.revanced.manager.shizuku"
Aunali321 marked this conversation as resolved.
Show resolved Hide resolved
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>
5 changes: 5 additions & 0 deletions app/src/main/java/app/revanced/manager/ManagerApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch
import org.koin.android.ext.android.inject
import app.revanced.manager.service.ShizukuApi
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
import org.koin.androidx.workmanager.koin.workManagerFactory
import org.koin.core.context.startKoin
lateinit var rvmApp: ManagerApplication
Aunali321 marked this conversation as resolved.
Show resolved Hide resolved

class ManagerApplication : Application() {
private val scope = MainScope()
Expand All @@ -20,6 +22,9 @@ class ManagerApplication : Application() {
override fun onCreate() {
super.onCreate()

rvmApp = this
ShizukuApi.init()

startKoin {
androidContext(this@ManagerApplication)
androidLogger()
Expand Down
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
41 changes: 41 additions & 0 deletions app/src/main/java/app/revanced/manager/service/ShizkuService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package app.revanced.manager.service

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.rvmApp
import rikka.shizuku.Shizuku
import java.io.File

object ShizukuApi {

var isBinderAvailable = false
var isPermissionGranted by mutableStateOf(false)

fun init() {
Shizuku.addBinderReceivedListenerSticky {
isBinderAvailable = true
isPermissionGranted = Shizuku.checkSelfPermission() == PackageManager.PERMISSION_GRANTED
}
Shizuku.addBinderDeadListener {
isBinderAvailable = false
isPermissionGranted = false
}
}
Aunali321 marked this conversation as resolved.
Show resolved Hide resolved

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

fun isShizukuPermissionGranted() = isBinderAvailable && isPermissionGranted

fun isShizukuInstalled() = Shizuku.pingBinder()
}
94 changes: 94 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,94 @@
package app.revanced.manager.ui.component

import android.content.pm.PackageManager
import android.util.Log
import androidx.compose.animation.AnimatedVisibility
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.runtime.LaunchedEffect
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.service.ShizukuApi
import rikka.shizuku.Shizuku

private val listener: (Int, Int) -> Unit = { _, grantResult ->
ShizukuApi.isPermissionGranted = grantResult == PackageManager.PERMISSION_GRANTED
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun ShizukuCard() {
LaunchedEffect(Unit) {
Shizuku.addRequestPermissionResultListener(listener)
}
DisposableEffect(Unit) {
onDispose {
Shizuku.removeRequestPermissionResultListener(listener)
}
}

AnimatedVisibility(visible = !ShizukuApi.isPermissionGranted) {
Card(
colors = CardDefaults.cardColors(
MaterialTheme.colorScheme.errorContainer
),
onClick = {
if (ShizukuApi.isBinderAvailable && !ShizukuApi.isPermissionGranted) {
Log.e("ShizukuCard", "Requesting permission")
Aunali321 marked this conversation as resolved.
Show resolved Hide resolved
Shizuku.requestPermission(114514)
}
},
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 @@ -141,7 +141,6 @@ fun DashboardScreen(
)
}
}

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

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
Expand All @@ -9,13 +10,21 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import app.revanced.manager.R
import app.revanced.manager.service.ShizukuApi
import app.revanced.manager.ui.component.ShizukuCard

@Composable
fun InstalledAppsScreen() {
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Text(
text = stringResource(R.string.no_patched_apps_found),
style = MaterialTheme.typography.titleLarge
)
Column(
modifier = Modifier.fillMaxSize(),
) {
if (ShizukuApi.isShizukuInstalled()) ShizukuCard()

Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Text(
text = stringResource(R.string.no_patched_apps_found),
style = MaterialTheme.typography.titleLarge
)
}
}
}
Loading