Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move string to xml #37

Merged
merged 6 commits into from
Jan 5, 2024
Merged
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
25 changes: 25 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Set the default behavior, in case people don't have core.autocrlf set.
* text eol=lf

# Explicitly declare text files you want to always be normalized and converted
# to native line endings on checkout.
# *.c text
# *.h text

# Declare files that will always have CRLF line endings on checkout.
*.cmd text eol=crlf
*.bat text eol=crlf

# Denote all files that are truly binary and should not be modified.
tools/** binary
*.jar binary
*.exe binary
*.apk binary
*.png binary
*.jpg binary
*.ttf binary
*.so binary

# Help GitHub detect languages
native/jni/external/** linguist-vendored
native/jni/systemproperties/** linguist-language=C++
25 changes: 18 additions & 7 deletions app/src/main/assets/boot_patch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# File name Type Description
#
# boot_patch.sh script A script to patch boot image for APatch.
# (this file) The script will use files in its same
# (this file) The script will use files in its same
# directory to complete the patching process.
# bootimg binary The target boot image
# kpimg binary KernelPatch core Image
Expand Down Expand Up @@ -38,30 +38,43 @@ getdir() {
# Switch to the location of the script file
cd "$(getdir "${BASH_SOURCE:-$0}")"

# Load utility functions
. ./util_functions.sh

echo "APatch Boot Image Patcher"

# Check if 64-bit
if [ $(uname -m) = "aarch64" ]; then
echo "System is arm64"
else
echo "Not is arm64"
exit
echo "System is not arm64"
exit 1
fi


SUPERKEY=$1
BOOTIMAGE=$2

if [ -z "$BOOTIMAGE" ]; then
find_boot_image
fi

[ -z "$SUPERKEY" ] && { echo "SuperKey empty!"; exit 1; }
[ -e "$BOOTIMAGE" ] || { echo "$BOOTIMAGE does not exist!"; exit 1; }

echo "- Target image: $BOOTIMAGE"

# Check for dependencies
command -v ./magiskboot >/dev/null 2>&1 || { echo "magiskboot not found!"; exit 1; }
command -v ./kptools >/dev/null 2>&1 || { echo "kptools not found!"; exit 1; }

echo "- Unpacking boot image"
./magiskboot unpack "$BOOTIMAGE" >/dev/null 2>&1

if [ $? -ne 0 ]; then
echo "Unpack error: $?"
exit $?
fi

mv kernel kernel.ori

echo "- Patching kernel"
Expand All @@ -75,7 +88,5 @@ fi
echo "- Repacking boot image"
./magiskboot repack "$BOOTIMAGE" >/dev/null 2>&1 || exit $?

ls -l "new-boot.img" | echo

# Reset any error code
true
true
60 changes: 60 additions & 0 deletions app/src/main/assets/util_functions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/system/bin/sh
#######################################################################################
# Helper Functions (credits to topjohnwu)
#######################################################################################

toupper() {
echo "$@" | tr '[:lower:]' '[:upper:]'
}

grep_prop() {
local REGEX="s/^$1=//p"
shift
local FILES=$@
[ -z "$FILES" ] && FILES='/system/build.prop'
cat $FILES 2>/dev/null | dos2unix | sed -n "$REGEX" | head -n 1
}

find_block() {
local BLOCK DEV DEVICE DEVNAME PARTNAME UEVENT
for BLOCK in "$@"; do
DEVICE=$(find /dev/block \( -type b -o -type c -o -type l \) -iname $BLOCK | head -n 1) 2>/dev/null
if [ ! -z $DEVICE ]; then
readlink -f $DEVICE
return 0
fi
done
# Fallback by parsing sysfs uevents
for UEVENT in /sys/dev/block/*/uevent; do
DEVNAME=$(grep_prop DEVNAME $UEVENT)
PARTNAME=$(grep_prop PARTNAME $UEVENT)
for BLOCK in "$@"; do
if [ "$(toupper $BLOCK)" = "$(toupper $PARTNAME)" ]; then
echo /dev/block/$DEVNAME
return 0
fi
done
done
# Look just in /dev in case we're dealing with MTD/NAND without /dev/block devices/links
for DEV in "$@"; do
DEVICE=$(find /dev \( -type b -o -type c -o -type l \) -maxdepth 1 -iname $DEV | head -n 1) 2>/dev/null
if [ ! -z $DEVICE ]; then
readlink -f $DEVICE
return 0
fi
done
return 1
}

find_boot_image() {
SLOT=$(getprop ro.boot.slot_suffix)
if [ ! -z $SLOT ]; then
BOOTIMAGE=$(find_block "ramdisk$SLOT" "recovery_ramdisk$SLOT" "init_boot$SLOT" "boot$SLOT")
else
BOOTIMAGE=$(find_block ramdisk recovery_ramdisk kern-a android_boot kernel bootimg init_boot boot lnx boot_a)
fi
if [ -z $BOOTIMAGE ]; then
# Lets see what fstabs tells me
BOOTIMAGE=$(grep -v '#' /etc/*fstab* | grep -E '/boot(img)?[^a-zA-Z]' | grep -oE '/dev/[a-zA-Z0-9_./-]*' | head -n 1)
fi
}
4 changes: 4 additions & 0 deletions app/src/main/java/me/bmax/apatch/APatchApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ class APApplication : Application() {
}
}

fun getSuperKey(): String {
return superKey
}

fun updateSuperKey(password: String) {
superKey = password
}
Expand Down
39 changes: 19 additions & 20 deletions app/src/main/java/me/bmax/apatch/ui/screen/APM.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import me.bmax.apatch.APApplication
import me.bmax.apatch.util.DownloadListener
import me.bmax.apatch.util.download
import me.bmax.apatch.R
import me.bmax.apatch.ui.component.ConfirmDialog
Expand Down Expand Up @@ -93,7 +92,7 @@ fun APModuleScreen(navigator: DestinationsNavigator) {
{ /* Empty */ }
} else {
{
val moduleInstall = stringResource(id = R.string.module_install)
val moduleInstall = stringResource(id = R.string.apm_install)
val selectZipLauncher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.StartActivityForResult()
) {
Expand Down Expand Up @@ -136,7 +135,7 @@ fun APModuleScreen(navigator: DestinationsNavigator) {
contentAlignment = Alignment.Center
) {
Text(
stringResource(R.string.module_magisk_conflict),
stringResource(R.string.apm_magisk_conflict),
textAlign = TextAlign.Center,
)
}
Expand All @@ -160,20 +159,20 @@ fun APModuleScreen(navigator: DestinationsNavigator) {
private fun ModuleList(
viewModel: APModuleViewModel, modifier: Modifier = Modifier, onInstallModule: (Uri) -> Unit
) {
val failedEnable = stringResource(R.string.module_failed_to_enable)
val failedDisable = stringResource(R.string.module_failed_to_disable)
val failedUninstall = stringResource(R.string.module_uninstall_failed)
val successUninstall = stringResource(R.string.module_uninstall_success)
val failedEnable = stringResource(R.string.apm_failed_to_enable)
val failedDisable = stringResource(R.string.apm_failed_to_disable)
val failedUninstall = stringResource(R.string.apm_uninstall_failed)
val successUninstall = stringResource(R.string.apm_uninstall_success)
val reboot = stringResource(id = R.string.reboot)
val rebootToApply = stringResource(id = R.string.reboot_to_apply)
val rebootToApply = stringResource(id = R.string.apm_reboot_to_apply)
val moduleStr = stringResource(id = R.string.apm)
val uninstall = stringResource(id = R.string.uninstall)
val uninstall = stringResource(id = R.string.apm_uninstall)
val cancel = stringResource(id = android.R.string.cancel)
val moduleUninstallConfirm = stringResource(id = R.string.module_uninstall_confirm)
val updateText = stringResource(R.string.module_update)
val changelogText = stringResource(R.string.module_changelog)
val downloadingText = stringResource(R.string.module_downloading)
val startDownloadingText = stringResource(R.string.module_start_downloading)
val moduleUninstallConfirm = stringResource(id = R.string.apm_uninstall_confirm)
val updateText = stringResource(R.string.apm_update)
val changelogText = stringResource(R.string.apm_changelog)
val downloadingText = stringResource(R.string.apm_downloading)
val startDownloadingText = stringResource(R.string.apm_start_downloading)

val dialogHost = LocalDialogHost.current
val snackBarHost = LocalSnackbarHost.current
Expand Down Expand Up @@ -293,7 +292,7 @@ private fun ModuleList(
contentAlignment = Alignment.Center
) {
Text(
stringResource(R.string.module_overlay_fs_not_available),
stringResource(R.string.apm_overlay_fs_not_available),
textAlign = TextAlign.Center
)
}
Expand All @@ -307,7 +306,7 @@ private fun ModuleList(
contentAlignment = Alignment.Center
) {
Text(
stringResource(R.string.module_empty),
stringResource(R.string.apm_empty),
textAlign = TextAlign.Center
)
}
Expand Down Expand Up @@ -402,8 +401,8 @@ private fun ModuleItem(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
) {
val moduleVersion = stringResource(id = R.string.module_version)
val moduleAuthor = stringResource(id = R.string.module_author)
val moduleVersion = stringResource(id = R.string.apm_version)
val moduleAuthor = stringResource(id = R.string.apm_author)

Column(modifier = Modifier.fillMaxWidth(0.8f)) {
Text(
Expand Down Expand Up @@ -481,7 +480,7 @@ private fun ModuleItem(
Text(
fontFamily = MaterialTheme.typography.labelMedium.fontFamily,
fontSize = MaterialTheme.typography.labelMedium.fontSize,
text = stringResource(R.string.module_update),
text = stringResource(R.string.apm_update),
)
}
}
Expand All @@ -493,7 +492,7 @@ private fun ModuleItem(
Text(
fontFamily = MaterialTheme.typography.labelMedium.fontFamily,
fontSize = MaterialTheme.typography.labelMedium.fontSize,
text = stringResource(R.string.uninstall),
text = stringResource(R.string.apm_uninstall),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ enum class BottomBarDestination(
) {
Home(HomeScreenDestination, R.string.home, Icons.Filled.Home, Icons.Outlined.Home),
KModule(KPModuleScreenDestination, R.string.kpm, Icons.Filled.Build, Icons.Outlined.Build),
SuperUser(SuperUserScreenDestination, R.string.superuser, Icons.Filled.Security, Icons.Outlined.Security),
SuperUser(SuperUserScreenDestination, R.string.su_title, Icons.Filled.Security, Icons.Outlined.Security),
AModule(APModuleScreenDestination, R.string.apm, Icons.Filled.Apps, Icons.Outlined.Apps)
}
29 changes: 16 additions & 13 deletions app/src/main/java/me/bmax/apatch/ui/screen/Home.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fun HomeScreen(navigator: DestinationsNavigator) {
) {
WarningCard()
KStatusCard(state)
AStatusCard(state)
AStatusCard(state, navigator)
InfoCard()
LearnMoreCard()
Spacer(Modifier)
Expand All @@ -97,10 +97,10 @@ fun AuthSuperKey(showDialog: MutableState<Boolean>) {
var enable by remember { mutableStateOf(false) }
AlertDialog(
onDismissRequest = { showDialog.value = false },
title = { Text("Enter SuperKey") },
title = { Text(stringResource(id = R.string.home_auth_key_title)) },
text = {
Column {
Text("Please enter the superkey set when patching")
Text(stringResource(id = R.string.home_auth_key_desc))
Spacer(modifier = Modifier.height(4.dp))
Box(
contentAlignment = Alignment.CenterEnd,
Expand All @@ -110,7 +110,7 @@ fun AuthSuperKey(showDialog: MutableState<Boolean>) {
onValueChange = {
key = it
enable = !key.isEmpty() },
label = { Text("SuperKey") },
label = { Text(stringResource(id = R.string.super_key)) },
visualTransformation = if (keyVisible) VisualTransformation.None else PasswordVisualTransformation(),
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password)
)
Expand All @@ -134,7 +134,7 @@ fun AuthSuperKey(showDialog: MutableState<Boolean>) {
showDialog.value = false
}
) {
Text("Cancel")
Text(stringResource(id = android.R.string.cancel))
}
},
confirmButton = {
Expand All @@ -145,7 +145,7 @@ fun AuthSuperKey(showDialog: MutableState<Boolean>) {
apApp.updateSuperKey(key)
}
) {
Text("Confirm")
Text(stringResource(id = android.R.string.ok))
}
},
)
Expand All @@ -169,10 +169,10 @@ fun StartPatch(showDialog: MutableState<Boolean>, navigator: DestinationsNavigat

AlertDialog(
onDismissRequest = { showDialog.value = false },
title = { Text(stringResource(id = R.string.set_key_title)) },
title = { Text(stringResource(id = R.string.home_patch_set_key_title)) },
text = {
Column {
Text(stringResource(id = R.string.set_key_desc))
Text(stringResource(id = R.string.home_patch_set_key_desc))
Spacer(modifier = Modifier.height(4.dp))
TextField(
value = key,
Expand All @@ -196,7 +196,7 @@ fun StartPatch(showDialog: MutableState<Boolean>, navigator: DestinationsNavigat
selectBootimgLauncher.launch(intent)
}
) {
Text(stringResource(id = R.string.next_step))
Text(stringResource(id = R.string.home_patch_next_step))
}
},
)
Expand Down Expand Up @@ -397,7 +397,7 @@ private fun KStatusCard(state: APApplication.State) {
}

@Composable
private fun AStatusCard(state: APApplication.State) {
private fun AStatusCard(state: APApplication.State, navigator: DestinationsNavigator) {
ElevatedCard(
colors = CardDefaults.elevatedCardColors(containerColor = run {
MaterialTheme.colorScheme.secondaryContainer
Expand Down Expand Up @@ -470,6 +470,9 @@ private fun AStatusCard(state: APApplication.State) {
state.equals(APApplication.State.KERNELPATCH_READY)
|| state.equals(APApplication.State.ANDROIDPATCH_NEED_UPDATE) -> {
APApplication.install()
if (state.equals(APApplication.State.ANDROIDPATCH_NEED_UPDATE)) {
navigator.navigate(PatchScreenDestination(null, apApp.getSuperKey()))
}
}
state.equals(APApplication.State.ANDROIDPATCH_INSTALLED) -> {
APApplication.uninstall()
Expand All @@ -482,17 +485,17 @@ private fun AStatusCard(state: APApplication.State) {
content = {
when {
state.equals(APApplication.State.KERNELPATCH_READY) -> {
Text(text = "Install", color = Color.Black)
Text(text = stringResource(id = R.string.home_ap_cando_install), color = Color.Black)
}
state.equals(APApplication.State.ANDROIDPATCH_UNINSTALLING)
|| state.equals(APApplication.State.ANDROIDPATCH_UNINSTALLING) -> {
Icon(Icons.Outlined.Cached, contentDescription = "busy")
}
state.equals(APApplication.State.ANDROIDPATCH_NEED_UPDATE) -> {
Text(text = "Update", color = Color.Black)
Text(text = stringResource(id = R.string.home_ap_cando_update), color = Color.Black)
}
state.equals(APApplication.State.ANDROIDPATCH_INSTALLED) -> {
Text(text = "Uninstall", color = Color.Black)
Text(text = stringResource(id = R.string.home_ap_cando_uninstall), color = Color.Black)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/me/bmax/apatch/ui/screen/Install.kt
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ fun InstallScreen(navigator: DestinationsNavigator, uri: Uri) {
@Composable
private fun TopBar(onBack: () -> Unit = {}, onSave: () -> Unit = {}) {
TopAppBar(
title = { Text(stringResource(R.string.install)) },
title = { Text(stringResource(R.string.apm_install)) },
navigationIcon = {
IconButton(
onClick = onBack
Expand Down
Loading
Loading