Skip to content
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
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ jobs:
- name: Build debug
run: ./build.py -v all

- name: Run app unit tests
run: ./app/gradlew -p app testDebugUnitTest

- name: Stop gradle daemon
run: ./app/gradlew --stop

Expand Down
2 changes: 2 additions & 0 deletions app/apk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ android {

dependencies {
implementation(project(":core"))
implementation(project(":shared"))
implementation(project(":wear"))
coreLibraryDesugaring(libs.jdk.libs)

// Compose
Expand Down
4 changes: 4 additions & 0 deletions app/apk/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<!-- Wear Compose requires API 25. It is only used where useWearUi() is true, which
includes that check, so it never runs on older releases. -->
<uses-sdk tools:overrideLibrary="androidx.wear.compose.foundation,androidx.wear.compose.material3,androidx.wear.compose.material.core,androidx.wear.compose.navigation3,androidx.wear.input" />

<application android:localeConfig="@xml/locale_config">
<activity
android:name=".ui.MainActivity"
Expand Down
8 changes: 0 additions & 8 deletions app/apk/src/main/java/com/topjohnwu/magisk/ui/MagiskTheme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.setValue
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalContext
Expand All @@ -32,7 +29,6 @@ import com.google.android.material.color.utilities.DynamicColor
import com.google.android.material.color.utilities.Hct
import com.google.android.material.color.utilities.MaterialDynamicColors
import com.google.android.material.color.utilities.SchemeTonalSpot
import com.topjohnwu.magisk.core.Config
import com.topjohnwu.magisk.core.model.ColorMode

@SuppressLint("RestrictedApi")
Expand Down Expand Up @@ -99,10 +95,6 @@ fun dynamicColorScheme(

val MagiskAccentColor = Color(0xFF00AF9C)

object ThemeState {
var colorMode by mutableIntStateOf(Config.colorMode)
}

// Same values as androidx.activity's internal DefaultLightScrim / DefaultDarkScrim
private val LightScrim = android.graphics.Color.argb(0xe6, 0xFF, 0xFF, 0xFF)
private val DarkScrim = android.graphics.Color.argb(0x80, 0x1b, 0x1b, 0x1b)
Expand Down
98 changes: 17 additions & 81 deletions app/apk/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@ import android.Manifest
import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.content.pm.ApplicationInfo
import android.content.res.Resources
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.os.CancellationSignal
import android.provider.OpenableColumns
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.animation.AnimatedContentTransitionScope.SlideDirection
Expand Down Expand Up @@ -38,7 +34,6 @@ import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.arch.VMFactory
import com.topjohnwu.magisk.core.Config
import com.topjohnwu.magisk.core.Const
import com.topjohnwu.magisk.core.Info
import com.topjohnwu.magisk.core.base.ActivityExtension
import com.topjohnwu.magisk.core.base.SplashController
import com.topjohnwu.magisk.core.base.SplashScreenHost
Expand All @@ -50,6 +45,8 @@ import com.topjohnwu.magisk.ui.deny.DenyListViewModel
import com.topjohnwu.magisk.ui.flash.FlashScreen
import com.topjohnwu.magisk.ui.flash.FlashUtils
import com.topjohnwu.magisk.ui.flash.FlashViewModel
import com.topjohnwu.magisk.ui.flash.queryDisplayName
import com.topjohnwu.magisk.ui.flash.sanitizeDisplayName
import com.topjohnwu.magisk.ui.module.ActionScreen
import com.topjohnwu.magisk.ui.module.ActionViewModel
import com.topjohnwu.magisk.ui.navigation.LocalNavigator
Expand All @@ -60,17 +57,11 @@ import com.topjohnwu.magisk.ui.superuser.SuperuserDetailScreen
import com.topjohnwu.magisk.ui.superuser.SuperuserGrantScreen
import com.topjohnwu.magisk.ui.superuser.SuperuserGrantViewModel
import com.topjohnwu.magisk.ui.superuser.SuperuserViewModel
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import com.topjohnwu.magisk.wear.WearUi
import com.topjohnwu.magisk.wear.useWearUi
import kotlinx.coroutines.flow.MutableStateFlow
import java.io.File
import kotlinx.coroutines.withTimeoutOrNull
import com.topjohnwu.magisk.core.R as CoreR

private const val MAX_DISPLAY_NAME_LENGTH = 100
private const val DISPLAY_NAME_QUERY_TIMEOUT_MS = 3000L

class MainActivity : ComponentActivity(), SplashScreenHost {

override val extension = ActivityExtension(this)
Expand All @@ -80,13 +71,15 @@ class MainActivity : ComponentActivity(), SplashScreenHost {
// A tab requested by a new intent while the activity is running (it's singleTask)
private val tabRequest = MutableStateFlow<Int?>(null)
internal val showUnsupported = MutableStateFlow<List<Pair<Int, Int>>>(emptyList())
// Set in onCreate where the Wear OS UI replaces this one
private var wearUi: WearUi? = null

override fun attachBaseContext(base: Context) {
super.attachBaseContext(base.wrap())
}

override fun onCreate(savedInstanceState: Bundle?) {
applySystemBarStyle()
if (useWearUi()) wearUi = WearUi(this, extension) else applySystemBarStyle()
extension.onCreate(savedInstanceState)
splashController.preOnCreate()
super.onCreate(savedInstanceState)
Expand All @@ -110,6 +103,11 @@ class MainActivity : ComponentActivity(), SplashScreenHost {

@SuppressLint("InlinedApi")
override fun onCreateUi(savedInstanceState: Bundle?) {
wearUi?.let {
it.onCreateUi(savedInstanceState)
return
}

showUnsupportedMessage()

// Only ask on startup, not every time the activity is recreated
Expand Down Expand Up @@ -284,55 +282,6 @@ class MainActivity : ComponentActivity(), SplashScreenHost {
}
}

/**
* Names from external apps are untrusted: drop control and formatting characters
* (e.g. bidi overrides that can reorder the text) and cap the length.
*/
private fun String.sanitizeDisplayName(): String {
val sb = StringBuilder()
var count = 0
var i = 0
// Work on code points, so supplementary characters (e.g. invisible tag characters)
// are recognized and never split
while (i < length && count < MAX_DISPLAY_NAME_LENGTH) {
val cp = codePointAt(i)
i += Character.charCount(cp)
val type = Character.getType(cp)
if (Character.isISOControl(cp) || type == Character.FORMAT.toInt() ||
type == Character.SURROGATE.toInt()) continue
sb.appendCodePoint(cp)
count++
}
return sb.toString().trim()
}

/**
* Query the display name from the provider of an external URI. The provider is controlled
* by another app, so never block on it indefinitely: give up after a timeout and cancel it.
*/
private suspend fun queryDisplayName(context: Context, uri: Uri): String? {
val signal = CancellationSignal()
// Not a child of the caller, so giving up doesn't have to wait for the provider
val query = CoroutineScope(Dispatchers.IO).async {
runCatching {
context.contentResolver.query(
uri, arrayOf(OpenableColumns.DISPLAY_NAME), null, null, null, signal
)?.use { cursor ->
val idx = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)
if (cursor.moveToFirst() && idx >= 0) cursor.getString(idx) else null
}
}.getOrNull()
}
return try {
withTimeoutOrNull(DISPLAY_NAME_QUERY_TIMEOUT_MS) { query.await() }
} finally {
if (!query.isCompleted) {
signal.cancel()
query.cancel()
}
}
}

private fun setHideOverlayWindows(hide: Boolean) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
window.setHideOverlayWindows(hide)
Expand All @@ -342,6 +291,10 @@ class MainActivity : ComponentActivity(), SplashScreenHost {
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
setIntent(intent)
wearUi?.let {
it.onNewIntent()
return
}
getRequestedTab(intent)?.let { tabRequest.value = it }
intentState.value += 1
}
Expand All @@ -363,24 +316,7 @@ class MainActivity : ComponentActivity(), SplashScreenHost {
}

private fun showUnsupportedMessage() {
val messages = mutableListOf<Pair<Int, Int>>()

if (Info.env.isUnsupported) {
messages.add(CoreR.string.unsupport_magisk_title to CoreR.string.unsupport_magisk_msg)
}
if (!Info.isEmulator && Info.env.isActive && System.getenv("PATH")
?.split(':')
?.filterNot { File("$it/magisk").exists() }
?.any { File("$it/su").exists() } == true) {
messages.add(CoreR.string.unsupport_general_title to CoreR.string.unsupport_other_su_msg)
}
if (applicationInfo.flags and ApplicationInfo.FLAG_SYSTEM != 0) {
messages.add(CoreR.string.unsupport_general_title to CoreR.string.unsupport_system_app_msg)
}
if (applicationInfo.flags and ApplicationInfo.FLAG_EXTERNAL_STORAGE != 0) {
messages.add(CoreR.string.unsupport_general_title to CoreR.string.unsupport_external_storage_msg)
}

val messages = unsupportedMessages()
if (messages.isNotEmpty()) {
showUnsupported.value = messages
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.topjohnwu.magisk.ui.component

import androidx.annotation.StringRes
import androidx.compose.foundation.layout.Box
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.Sort
Expand All @@ -22,13 +21,6 @@ import androidx.compose.ui.unit.DpOffset
import androidx.compose.ui.unit.dp
import com.topjohnwu.magisk.core.R as CoreR

enum class AppSortBy(@StringRes val labelRes: Int) {
NAME(CoreR.string.sort_by_name),
PACKAGE_NAME(CoreR.string.sort_by_package_name),
INSTALL_TIME(CoreR.string.sort_by_install_time),
UPDATE_TIME(CoreR.string.sort_by_update_time);
}

@Composable
fun AppSortFilterActions(
sortBy: AppSortBy,
Expand Down
31 changes: 31 additions & 0 deletions app/core/src/main/res/values-pl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<string name="install_inactive_slot">Zainstaluj w nieaktywnym slocie (po OTA)</string>
<string name="install_inactive_slot_msg">Po ponownym uruchomieniu twoje urządzenie zostanie ZMUSZONE do rozruchu z aktualnie nieaktywnego slotu!\nUżywaj tej opcji tylko po ukończeniu aktualizacji OTA.\nKontynuować?</string>
<string name="setup_title">Dodatkowa konfiguracja</string>
<string name="select_from_storage">Wybierz z pamięci</string>
<string name="reboot_delay_toast">Ponowne uruchomienie za 5 sekund…</string>
<string name="flash_screen_title">Instalacja</string>

Expand Down Expand Up @@ -209,4 +210,34 @@
<string name="install_unknown_denied">Zezwól na \"Instaluj z nieznanych źródeł\", aby włączyć tę funkcję</string>
<string name="app_not_found">Nie znaleziono aplikacji do wykonania tej czynności</string>
<string name="reboot_apply_change">Uruchom ponownie, aby zastosować zmiany</string>

<!--Wear OS-->
<string name="wear_pick_empty">Brak pasujących plików w folderze Download</string>
<string name="wear_home_running">Działa</string>
<string name="wear_home_installed_code">Zainstalowany · %1$d</string>
<string name="wear_home_uninstall">Odinstaluj</string>
<string name="wear_root_full">Pełny root</string>
<string name="wear_root_restricted">Ograniczony root</string>
<string name="wear_root_none">Bez roota</string>
<string name="wear_su_logs">Logi su</string>
<string name="wear_grant_granted">Przyznano · %1$s</string>
<string name="wear_log_today">Dziś</string>
<string name="wear_log_yesterday">Wczoraj</string>
<string name="wear_log_clear_msg">Usunąć wszystkie wpisy z logu %1$s?</string>
<string name="wear_module_active">Aktywny</string>
<string name="wear_module_disabled">Wyłączony</string>
<string name="wear_module_removed">Usunięty po restarcie</string>
<string name="wear_module_enabled">Włączony</string>
<string name="wear_module_reboot">Uruchom ponownie</string>
<string name="wear_module_run_action">Uruchom akcję</string>
<string name="wear_module_remove">Usuń moduł</string>
<string name="wear_action_running">Trwa…</string>
<string name="wear_install_direct_msg">Załatać obraz boot tego urządzenia i od razu go wgrać?</string>
<string name="wear_flash_keep_charging">Nie zdejmuj z ładowarki</string>
<string name="wear_flash_wait">Poczekaj, aż się skończy</string>
<string name="wear_restore_msg">Wgrywa z powrotem stockowy obraz boot zapisany przy instalacji Magiska. Po ponownym uruchomieniu Magiska już nie będzie.</string>
<string name="wear_restore_sha1">SHA1 kopii</string>
<string name="wear_restore_no_backup">Brak kopii obrazu boot</string>
<string name="wear_restore_hold">Przytrzymaj, aby przywrócić</string>
<string name="wear_settings_updates">Aktualizacje</string>
</resources>
6 changes: 6 additions & 0 deletions app/core/src/main/res/values/resources.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
<string name="shared_uid" translatable="false">SharedUID</string>
<string name="empty" translatable="false"/>

<!-- Wear OS -->
<string name="wear_home_status_item" translatable="false">%1$s: %2$s</string>
<string name="wear_log_su" translatable="false">su</string>
<string name="wear_log_su_result" translatable="false">%1$s · %2$s</string>
<string name="wear_module_subtitle" translatable="false">%1$s · %2$s</string>

<string name="paypal" translatable="false">PayPal</string>
<string name="patreon" translatable="false">Patreon</string>
<string name="twitter" translatable="false">Twitter</string>
Expand Down
30 changes: 30 additions & 0 deletions app/core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,34 @@
<string name="reboot_apply_change">Reboot to apply changes</string>
<string name="running_exit_title">Execution in progress</string>
<string name="running_exit_msg">Are you sure you want to exit? The running operation may not complete.</string>

<!--Wear OS-->
<string name="wear_pick_empty">No matching files in the Download folder</string>
<string name="wear_home_running">Running</string>
<string name="wear_home_installed_code">Installed · %1$d</string>
<string name="wear_home_uninstall">Uninstall</string>
<string name="wear_root_full">Full root</string>
<string name="wear_root_restricted">Restricted root</string>
<string name="wear_root_none">No root</string>
<string name="wear_su_logs">Superuser logs</string>
<string name="wear_grant_granted">Granted · %1$s</string>
<string name="wear_log_today">Today</string>
<string name="wear_log_yesterday">Yesterday</string>
<string name="wear_log_clear_msg">Delete all entries of the %1$s log?</string>
<string name="wear_module_active">Active</string>
<string name="wear_module_disabled">Disabled</string>
<string name="wear_module_removed">Removed after reboot</string>
<string name="wear_module_enabled">Enabled</string>
<string name="wear_module_reboot">Reboot</string>
<string name="wear_module_run_action">Run action</string>
<string name="wear_module_remove">Remove module</string>
<string name="wear_action_running">Running…</string>
<string name="wear_install_direct_msg">Patch the boot image of this device and flash it now?</string>
<string name="wear_flash_keep_charging">Keep the watch on the charger</string>
<string name="wear_flash_wait">Wait until it finishes</string>
<string name="wear_restore_msg">Flashes back the stock boot image saved when Magisk was installed. Magisk is gone after a reboot.</string>
<string name="wear_restore_sha1">Backup SHA1</string>
<string name="wear_restore_no_backup">No boot image backup</string>
<string name="wear_restore_hold">Hold to restore</string>
<string name="wear_settings_updates">Updates</string>
</resources>
12 changes: 12 additions & 0 deletions app/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ compose-m3 = "1.4.0"
navigation3 = "1.1.7"
navigationevent = "1.1.2"
wire = "7.0.3"
wear-compose = "1.7.2"

[libraries]
commons-compress = { module = "org.apache.commons:commons-compress", version = "1.28.0" }
Expand Down Expand Up @@ -42,6 +43,7 @@ test-runner = { module = "androidx.test:runner", version = "1.7.0" }
test-rules = { module = "androidx.test:rules", version = "1.7.0" }
test-junit = { module = "androidx.test.ext:junit", version = "1.3.0" }
test-uiautomator = { module = "androidx.test.uiautomator:uiautomator", version = "2.4.0" }
junit = { module = "junit:junit", version = "4.13.2" }

# topjohnwu
libsu-core = { module = "com.github.topjohnwu.libsu:core", version.ref = "libsu" }
Expand All @@ -51,6 +53,7 @@ libsu-nio = { module = "com.github.topjohnwu.libsu:nio", version.ref = "libsu" }
# Compose
activity-compose = { module = "androidx.activity:activity-compose", version = "1.13.0" }
accompanist-drawablepainter = { module = "com.google.accompanist:accompanist-drawablepainter", version = "0.37.3" }
compose-runtime = { module = "androidx.compose.runtime:runtime", version.ref = "compose-ui" }
compose-ui = { module = "androidx.compose.ui:ui", version.ref = "compose-ui" }
compose-animation = { module = "androidx.compose.animation:animation", version.ref = "compose-ui" }
compose-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "compose-ui" }
Expand All @@ -60,13 +63,22 @@ compose-material3 = { module = "androidx.compose.material3:material3", version.r
compose-material3-adaptive-navigation-suite = { module = "androidx.compose.material3:material3-adaptive-navigation-suite", version.ref = "compose-m3" }
window-core = { module = "androidx.window:window-core", version = "1.5.0" }
compose-material-icons-extended = { module = "androidx.compose.material:material-icons-extended", version = "1.7.8" }
lifecycle-livedata-core = { module = "androidx.lifecycle:lifecycle-livedata-core", version.ref = "lifecycle" }
lifecycle-viewmodel = { module = "androidx.lifecycle:lifecycle-viewmodel", version.ref = "lifecycle" }
lifecycle-viewmodel-savedstate = { module = "androidx.lifecycle:lifecycle-viewmodel-savedstate", version.ref = "lifecycle" }
lifecycle-runtime-compose = { module = "androidx.lifecycle:lifecycle-runtime-compose", version.ref = "lifecycle" }
lifecycle-viewmodel-compose = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "lifecycle" }
lifecycle-viewmodel-navigation3 = { module = "androidx.lifecycle:lifecycle-viewmodel-navigation3", version.ref = "lifecycle" }
navigation3-runtime = { module = "androidx.navigation3:navigation3-runtime", version.ref = "navigation3" }
navigation3-ui = { module = "androidx.navigation3:navigation3-ui", version.ref = "navigation3" }
navigationevent-compose = { module = "androidx.navigationevent:navigationevent-compose", version.ref = "navigationevent" }

# Wear OS
wear-compose-foundation = { module = "androidx.wear.compose:compose-foundation", version.ref = "wear-compose" }
wear-compose-material3 = { module = "androidx.wear.compose:compose-material3", version.ref = "wear-compose" }
wear-compose-navigation3 = { module = "androidx.wear.compose:compose-navigation3", version.ref = "wear-compose" }
wear-input = { module = "androidx.wear:wear-input", version = "1.1.0" }

# For build-logic
android-gradle-plugin = { module = "com.android.tools.build:gradle", version.ref = "android" }
android-build-sdk-common = { module = "com.android.tools:sdk-common", version.ref = "android-tools" }
Expand Down
2 changes: 1 addition & 1 deletion app/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ pluginManagement {
}

rootProject.name = "Magisk"
include(":apk", ":core", ":test")
include(":apk", ":core", ":shared", ":test", ":wear")
Loading
Loading