Refactor: Move keystore to external dir

This commit is contained in:
wingio 2023-03-25 14:26:31 -04:00
parent eba0fbf29c
commit 1df152f41b
8 changed files with 107 additions and 4 deletions

View file

@ -101,6 +101,7 @@ dependencies {
implementation("com.google.accompanist:accompanist-systemuicontroller:$accompanistVersion")
implementation("com.google.accompanist:accompanist-pager:$accompanistVersion")
implementation("com.google.accompanist:accompanist-permissions:$accompanistVersion")
val voyagerVersion = "1.0.0-rc03"

View file

@ -1,6 +1,5 @@
package dev.beefers.vendetta.manager.installer.util
import dev.beefers.vendetta.manager.network.utils.Signer
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.lsposed.lspatch.share.PatchConfig

View file

@ -1,7 +1,8 @@
package dev.beefers.vendetta.manager.network.utils
package dev.beefers.vendetta.manager.installer.util
import android.content.Context
import com.android.apksig.ApkSigner
import dev.beefers.vendetta.manager.utils.Constants
import org.bouncycastle.asn1.x500.X500Name
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo
import org.bouncycastle.cert.X509v3CertificateBuilder
@ -28,8 +29,14 @@ object Signer : KoinComponent {
get() {
lateinit var ks: File
cacheDir.resolve("ks.keystore").also {
if (it.exists()) {
it.copyTo(Constants.VENDETTA_DIR.resolve("ks.keystore"), true)
it.delete()
}
}
Constants.VENDETTA_DIR.resolve("ks.keystore").also {
if (!it.exists()) {
cacheDir.mkdir()
Constants.VENDETTA_DIR.mkdir()
newKeystore(it)
}
ks = it

View file

@ -25,6 +25,7 @@ import com.google.accompanist.pager.PagerState
import com.google.accompanist.pager.rememberPagerState
import dev.beefers.vendetta.manager.ui.screen.home.HomeScreen
import dev.beefers.vendetta.manager.ui.viewmodel.main.MainViewModel
import dev.beefers.vendetta.manager.ui.widgets.dialog.StoragePermissionsDialog
import dev.beefers.vendetta.manager.ui.widgets.updater.UpdateDialog
import dev.beefers.vendetta.manager.utils.MainTab
import kotlinx.coroutines.launch
@ -38,6 +39,8 @@ class MainScreen : Screen {
val viewModel: MainViewModel = getScreenModel()
val pagerState = rememberPagerState()
StoragePermissionsDialog()
CompositionLocalProvider(
LocalPagerState provides pagerState
) {

View file

@ -23,7 +23,7 @@ import dev.beefers.vendetta.manager.domain.manager.PreferenceManager
import dev.beefers.vendetta.manager.installer.util.ManifestPatcher
import dev.beefers.vendetta.manager.installer.util.Patcher
import dev.beefers.vendetta.manager.installer.util.installApks
import dev.beefers.vendetta.manager.network.utils.Signer
import dev.beefers.vendetta.manager.installer.util.Signer
import dev.beefers.vendetta.manager.utils.DiscordVersion
import dev.beefers.vendetta.manager.utils.copyText
import dev.beefers.vendetta.manager.utils.showToast

View file

@ -0,0 +1,86 @@
package dev.beefers.vendetta.manager.ui.widgets.dialog
import android.Manifest
import android.annotation.SuppressLint
import android.content.Intent
import android.os.Build
import android.os.Environment
import android.provider.Settings
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.window.DialogProperties
import androidx.core.net.toUri
import com.google.accompanist.permissions.*
import dev.beefers.vendetta.manager.BuildConfig
import dev.beefers.vendetta.manager.R
@Composable
fun StoragePermissionsDialog() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
ManageStorageDialog()
} else {
ExternalStorageDialog()
}
}
@Composable
@SuppressLint("NewApi")
private fun ManageStorageDialog() {
var manageStorageGranted by remember { mutableStateOf(Environment.isExternalStorageManager()) }
if (!manageStorageGranted) {
AlertDialog(
onDismissRequest = {},
confirmButton = {
val launcher =
rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) {
if (Environment.isExternalStorageManager()) {
manageStorageGranted = true
}
}
Button(
onClick = {
Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)
.setData("package:${BuildConfig.APPLICATION_ID}".toUri())
.let { launcher.launch(it) }
}
) {
Text(stringResource(R.string.action_open_settings))
}
},
title = { Text(stringResource(R.string.title_permission_grant)) },
text = { Text(stringResource(R.string.msg_permission_grant)) },
properties = DialogProperties(
dismissOnBackPress = false,
dismissOnClickOutside = false
)
)
}
}
@OptIn(ExperimentalPermissionsApi::class)
@Composable
private fun ExternalStorageDialog() {
val writeStorageState = rememberPermissionState(Manifest.permission.WRITE_EXTERNAL_STORAGE)
if (!writeStorageState.status.isGranted) {
AlertDialog(
onDismissRequest = {},
confirmButton = {
Button(onClick = writeStorageState::launchPermissionRequest) {
Text(stringResource(R.string.action_confirm))
}
},
title = { Text(stringResource(R.string.title_permission_grant)) },
text = { Text(stringResource(R.string.msg_permission_grant)) },
properties = DialogProperties(
dismissOnBackPress = false,
dismissOnClickOutside = false
)
)
}
}

View file

@ -1,5 +1,7 @@
package dev.beefers.vendetta.manager.utils
import android.os.Environment
object Constants {
val TEAM_MEMBERS = listOf(
@ -7,6 +9,8 @@ object Constants {
TeamMember("Kasi", "Developer - Xposed Module", "redstonekasi")
)
val VENDETTA_DIR = Environment.getExternalStorageDirectory().resolve("Vendetta")
}
data class TeamMember(

View file

@ -9,6 +9,7 @@
<string name="msg_five_left">5 more taps</string>
<string name="msg_two_left">2 more taps</string>
<string name="msg_unlocked">You are now a developer</string>
<string name="msg_permission_grant">In order for Vendetta Manager to function, file permissions are required. Since shared data is stored in ~/Vendetta, permissions are required in order to access it.</string>
<string name="group_download">Download APKs</string>
<string name="group_patch">Patching</string>
@ -52,6 +53,7 @@
<string name="action_retry">Retry</string>
<string name="action_reload">Reload</string>
<string name="action_open_about">Open about</string>
<string name="action_open_settings">Open settings</string>
<string name="installer_cached">Cached</string>
@ -60,6 +62,7 @@
<string name="title_settings">Settings</string>
<string name="title_update">Update available!</string>
<string name="title_about">About</string>
<string name="title_permission_grant">Grant Permissions</string>
<string name="theme_system">System</string>
<string name="theme_light">Light</string>