Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
Optimize compat (#229)
Browse files Browse the repository at this point in the history
- Add `PowerManagerDelegate`
- Remove unused code & res
  • Loading branch information
SanmerDev authored May 23, 2024
1 parent ed33d55 commit def43c8
Show file tree
Hide file tree
Showing 42 changed files with 198 additions and 270 deletions.
5 changes: 0 additions & 5 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,6 @@ dependencies {
implementation(libs.markwon.core)
implementation(libs.timber)

implementation(libs.libsu.core)
implementation(libs.rikka.shizuku.api)
implementation(libs.rikka.shizuku.provider)
implementation(libs.hiddenApiBypass)

implementation(libs.square.retrofit)
implementation(libs.square.retrofit.moshi)
implementation(libs.square.okhttp)
Expand Down
8 changes: 0 additions & 8 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,6 @@
android:name=".service.DownloadService"
android:foregroundServiceType="dataSync"
android:exported="false" />

<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>
6 changes: 0 additions & 6 deletions app/src/main/kotlin/com/sanmer/mrepo/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ package com.sanmer.mrepo

import android.app.Application
import com.sanmer.mrepo.app.utils.NotificationUtils
import com.sanmer.mrepo.compat.BuildCompat
import com.sanmer.mrepo.network.NetworkUtils
import com.sanmer.mrepo.utils.timber.DebugTree
import com.sanmer.mrepo.utils.timber.ReleaseTree
import dagger.hilt.android.HiltAndroidApp
import org.lsposed.hiddenapibypass.HiddenApiBypass
import timber.log.Timber

@HiltAndroidApp
Expand All @@ -23,10 +21,6 @@ class App : Application() {
override fun onCreate() {
super.onCreate()

if (BuildCompat.atLeastP) {
HiddenApiBypass.addHiddenApiExemptions("")
}

NotificationUtils.init(this)
NetworkUtils.setCacheDir(cacheDir)
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/kotlin/com/sanmer/mrepo/Compat.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.sanmer.mrepo.datastore.WorkingMode
import dev.sanmer.mrepo.compat.ServiceManagerCompat
import dev.sanmer.mrepo.compat.stub.IFileManager
import dev.sanmer.mrepo.compat.stub.IModuleManager
import dev.sanmer.mrepo.compat.stub.IPowerManager
import dev.sanmer.mrepo.compat.stub.IServiceManager
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
Expand All @@ -26,6 +27,7 @@ object Compat {

val moduleManager: IModuleManager get() = mService.moduleManager
val fileManager: IFileManager get() = mService.fileManager
val powerManager: IPowerManager get() = mService.powerManager

private fun state(alive: Boolean): Boolean {
isAlive = alive
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ import com.sanmer.mrepo.app.Event.Companion.isLoading
import com.sanmer.mrepo.app.Event.Companion.isSucceeded
import com.sanmer.mrepo.ui.component.NavigateUpTopBar
import com.sanmer.mrepo.ui.utils.isScrollingUp
import com.sanmer.mrepo.utils.Utils
import com.sanmer.mrepo.viewmodel.InstallViewModel
import kotlinx.coroutines.launch

Expand Down Expand Up @@ -142,7 +141,9 @@ fun InstallScreen(
targetScale = 0.8f
)
) {
FloatingButton()
FloatingButton(
reboot = viewModel::reboot
)
}
},
snackbarHost = { SnackbarHost(snackbarHostState) }
Expand Down Expand Up @@ -214,8 +215,10 @@ private fun TopBar(
)

@Composable
private fun FloatingButton() = FloatingActionButton(
onClick = { Utils.reboot() }
private fun FloatingButton(
reboot: () -> Unit,
) = FloatingActionButton(
onClick = reboot
) {
Icon(
painter = painterResource(id = R.drawable.reload),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import com.sanmer.mrepo.app.Event.Companion.isLoading
import com.sanmer.mrepo.app.Event.Companion.isSucceeded
import com.sanmer.mrepo.model.online.VersionItem
import com.sanmer.mrepo.network.compose.requestString
import com.sanmer.mrepo.ui.providable.LocalUserPreferences
import com.sanmer.mrepo.ui.utils.expandedShape
import kotlinx.coroutines.launch

Expand Down Expand Up @@ -87,30 +86,27 @@ fun VersionItemBottomSheet(
}
}
) {
val userPreferences = LocalUserPreferences.current
val enableInstall by remember {
derivedStateOf {
userPreferences.isRoot && isProviderAlive
when {
hasChangelog -> {
ButtonRow(
isUpdate = isUpdate,
enableInstall = isProviderAlive,
state = state,
onDownload = onDownload,
onClose = onClose
)
ChangelogItem(url = item.changelog)
}
}

if (hasChangelog) {
ButtonRow(
isUpdate = isUpdate,
enableInstall = enableInstall,
state = state,
onDownload = onDownload,
onClose = onClose
)
ChangelogItem(url = item.changelog)
} else {
ButtonColumn(
isUpdate = isUpdate,
enableInstall = enableInstall,
state = state,
downloader = onDownload,
onClose = onClose
)
else -> {
ButtonColumn(
isUpdate = isUpdate,
enableInstall = isProviderAlive,
state = state,
downloader = onDownload,
onClose = onClose
)
}
}

NavigationBarsSpacer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import com.sanmer.mrepo.model.local.LocalModule
import com.sanmer.mrepo.model.local.versionDisplay
import com.sanmer.mrepo.model.online.OnlineModule
import com.sanmer.mrepo.model.online.VersionItem
import com.sanmer.mrepo.ui.providable.LocalUserPreferences
import com.sanmer.mrepo.utils.extensions.toDateTime

@Composable
Expand Down Expand Up @@ -100,8 +99,6 @@ private fun CloudItem(
.fillMaxWidth(),
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
val userPreferences = LocalUserPreferences.current

Text(
text = stringResource(id = R.string.view_module_cloud),
style = MaterialTheme.typography.titleSmall,
Expand All @@ -120,7 +117,7 @@ private fun CloudItem(
)

ElevatedAssistChip(
enabled = userPreferences.isRoot && isProviderAlive,
enabled = isProviderAlive,
onClick = { onInstall(item) },
label = { Text(text = stringResource(id = R.string.module_install)) },
leadingIcon = {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,13 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Scaffold
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.TopAppBarScrollBehavior
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavController
Expand All @@ -42,14 +35,12 @@ fun SettingsScreen(
viewModel: SettingsViewModel = hiltViewModel()
) {
val userPreferences = LocalUserPreferences.current

val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior()

Scaffold(
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
topBar = {
TopBar(
isRoot = userPreferences.isRoot,
scrollBehavior = scrollBehavior
)
},
Expand Down Expand Up @@ -115,29 +106,10 @@ fun SettingsScreen(

@Composable
private fun TopBar(
isRoot: Boolean,
scrollBehavior: TopAppBarScrollBehavior
) = TopAppBar(
title = {
TopAppBarTitle(text = stringResource(id = R.string.page_settings))
},
actions = {
var expanded by remember { mutableStateOf(false) }

IconButton(
onClick = { expanded = true },
enabled = isRoot
) {
Icon(
painter = painterResource(id = R.drawable.reload),
contentDescription = null
)

SettingsMenu(
expanded = expanded,
onClose = { expanded = false }
)
}
},
scrollBehavior = scrollBehavior
)
10 changes: 0 additions & 10 deletions app/src/main/kotlin/com/sanmer/mrepo/utils/Utils.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
package com.sanmer.mrepo.utils

import com.topjohnwu.superuser.Shell

object Utils {
fun reboot(reason: String = "") {
if (reason == "recovery") {
// KEYCODE_POWER = 26, hide incorrect "Factory data reset" message
Shell.cmd("/system/bin/input keyevent 26").submit()
}
Shell.cmd("/system/bin/svc power reboot $reason || /system/bin/reboot $reason").submit()
}

fun getVersionDisplay(version: String, versionCode: Int): String {
val included = "\\(.*?${versionCode}.*?\\)".toRegex()
.containsMatchIn(version)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import com.sanmer.mrepo.repository.UserPreferencesRepository
import com.sanmer.mrepo.utils.extensions.tmpDir
import dagger.hilt.android.lifecycle.HiltViewModel
import dev.sanmer.mrepo.compat.content.State
import dev.sanmer.mrepo.compat.delegate.PowerManagerDelegate
import dev.sanmer.mrepo.compat.stub.IInstallCallback
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.first
Expand All @@ -44,6 +45,12 @@ class InstallViewModel @Inject constructor(
Timber.d("InstallViewModel init")
}

fun reboot() {
PowerManagerDelegate(Compat.powerManager).apply {
reboot()
}
}

suspend fun writeLogsTo(context: Context, uri: Uri) = withContext(Dispatchers.IO) {
runCatching {
val cr = context.contentResolver
Expand Down
6 changes: 0 additions & 6 deletions app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@
<string name="settings_root_not_available">غير متاح</string>
<string name="module_version_author">%1$sبواسطة%2$s</string>
<string name="license_fsf_libre">FSF الحر</string>
<string name="settings_menu_reboot">إعادة تشغيل</string>
<string name="settings_menu_reboot_userspace">اعادة تشغيل النظام</string>
<string name="settings_menu_reboot_recovery">اعادة التشغيل الى وضع الإسترداد</string>
<string name="settings_menu_reboot_bootloader">اعادة التشغيل الى محمل الإقلاع</string>
<string name="settings_menu_reboot_download">اعادة التشغيل الى وضع التنزيل</string>
<string name="settings_menu_reboot_edl">اعادة التشغيل الى وضع EDL</string>
<string name="module_remove">إزالة</string>
<string name="module_restore">استرجاع</string>
<string name="module_install">تثبيت</string>
Expand Down
6 changes: 0 additions & 6 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@
<string name="settings_root_not_available">Nicht verfügbar</string>
<string name="settings_root_none">Keiner</string>
<string name="settings_non_root_desc">Funktionalität eingeschränkt</string>
<string name="settings_menu_reboot">Neustart</string>
<string name="settings_menu_reboot_userspace">Neustart (schnell)</string>
<string name="settings_menu_reboot_recovery">Neustart ins Recovery</string>
<string name="settings_menu_reboot_bootloader">Neustart in den Bootloader</string>
<string name="settings_menu_reboot_download">Neustart in den Download-Modus</string>
<string name="settings_menu_reboot_edl">Neustart in den EDL-Modus</string>
<string name="settings_app_theme">App Design</string>
<string name="settings_app_theme_desc">Farben und Nacht-Modus ändern</string>
<string name="settings_download_path">Download Pfad</string>
Expand Down
Loading

0 comments on commit def43c8

Please sign in to comment.