Skip to content

Commit

Permalink
Added a feature to save logs to local storage (#1741)
Browse files Browse the repository at this point in the history
- Added export logs to local storage
[1664](#1664)

---------

Co-authored-by: weishu <[email protected]>
  • Loading branch information
ALEX5402 and tiann authored May 23, 2024
1 parent 4e3f03a commit d686016
Show file tree
Hide file tree
Showing 46 changed files with 200 additions and 25 deletions.
2 changes: 1 addition & 1 deletion manager/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,4 @@ dependencies {

implementation(libs.markdown)
implementation(libs.androidx.webkit)
}
}
160 changes: 136 additions & 24 deletions manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Settings.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package me.weishu.kernelsu.ui.screen

import android.content.ContentResolver
import android.content.Context
import android.content.Intent
import android.database.Cursor
import android.net.Uri
import android.provider.OpenableColumns
import android.util.Log
import android.widget.Toast
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
Expand All @@ -20,25 +26,34 @@ import androidx.compose.material.icons.filled.DeleteForever
import androidx.compose.material.icons.filled.DeveloperMode
import androidx.compose.material.icons.filled.Fence
import androidx.compose.material.icons.filled.RemoveModerator
import androidx.compose.material.icons.filled.Save
import androidx.compose.material.icons.filled.Share
import androidx.compose.material.icons.filled.Update
import androidx.compose.material3.BottomSheetScaffold
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.ListItem
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.LineHeightStyle
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.core.content.FileProvider
import com.maxkeppeker.sheets.core.models.base.Header
import com.maxkeppeker.sheets.core.models.base.IconSource
Expand All @@ -65,12 +80,16 @@ import me.weishu.kernelsu.ui.component.rememberLoadingDialog
import me.weishu.kernelsu.ui.screen.destinations.AppProfileTemplateScreenDestination
import me.weishu.kernelsu.ui.screen.destinations.FlashScreenDestination
import me.weishu.kernelsu.ui.util.getBugreportFile
import me.weishu.kernelsu.ui.util.getFileNameFromUri
import me.weishu.kernelsu.ui.util.shrinkModules
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter

/**
* @author weishu
* @date 2023/1/1.
*/
@OptIn(ExperimentalMaterial3Api::class)
@Destination
@Composable
fun SettingScreen(navigator: DestinationsNavigator) {
Expand Down Expand Up @@ -151,6 +170,7 @@ fun SettingScreen(navigator: DestinationsNavigator) {
enableWebDebugging = it
}

var showBottomsheet by remember { mutableStateOf(false) }

ListItem(
leadingContent = {
Expand All @@ -161,34 +181,127 @@ fun SettingScreen(navigator: DestinationsNavigator) {
},
headlineContent = { Text(stringResource(id = R.string.send_log)) },
modifier = Modifier.clickable {
scope.launch {
val bugreport = loadingDialog.withLoading {
withContext(Dispatchers.IO) {
getBugreportFile(context)
showBottomsheet = true
}
)
if (showBottomsheet){
ModalBottomSheet(
onDismissRequest = { showBottomsheet = false },
content = {
Row(modifier = Modifier.padding(10.dp)
.align(Alignment.CenterHorizontally)

) {
Box{
Column(
modifier = Modifier.padding(16.dp)
.clickable {
scope.launch {
val bugreport = loadingDialog.withLoading {
withContext(Dispatchers.IO) {
getBugreportFile(context)
}
}

val uri: Uri =
FileProvider.getUriForFile(
context,
"${BuildConfig.APPLICATION_ID}.fileprovider",
bugreport
)
val filename = getFileNameFromUri(context , uri)
val savefile = Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
addCategory(Intent.CATEGORY_OPENABLE)
type = "application/zip"
putExtra(Intent.EXTRA_STREAM, uri)
putExtra(Intent.EXTRA_TITLE, filename)
flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
}
context.startActivity(
Intent.createChooser(
savefile,
context.getString(R.string.save_log)
)
)
}
}
) {
Icon(
Icons.Filled.Save,
contentDescription = null,
modifier = Modifier.align(Alignment.CenterHorizontally)
)
Text(
text = stringResource(id = R.string.save_log),
modifier = Modifier.padding(top = 16.dp),
textAlign = TextAlign.Center.also {
LineHeightStyle(
alignment = LineHeightStyle.Alignment.Center,
trim = LineHeightStyle.Trim.None
)
}

)
}

}
}
Box{
Column(
modifier = Modifier.padding(16.dp)
.clickable {
scope.launch {
val bugreport = loadingDialog.withLoading {
withContext(Dispatchers.IO) {
getBugreportFile(context)
}
}

val uri: Uri =
FileProvider.getUriForFile(
context,
"${BuildConfig.APPLICATION_ID}.fileprovider",
bugreport
)
val uri: Uri =
FileProvider.getUriForFile(
context,
"${BuildConfig.APPLICATION_ID}.fileprovider",
bugreport
)

val shareIntent = Intent(Intent.ACTION_SEND)
shareIntent.putExtra(Intent.EXTRA_STREAM, uri)
shareIntent.setDataAndType(uri, "application/zip")
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
val shareIntent = Intent(Intent.ACTION_SEND)
shareIntent.putExtra(Intent.EXTRA_STREAM, uri)
shareIntent.setDataAndType(uri, "application/zip")
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)

context.startActivity(
Intent.createChooser(
shareIntent,
context.getString(R.string.send_log)
)
)
context.startActivity(
Intent.createChooser(
shareIntent,
context.getString(R.string.send_log)
)
)
}
}
) {
Icon(
Icons.Filled.Share,
contentDescription = null,
modifier = Modifier.align(Alignment.CenterHorizontally)
)
Text(
text = stringResource(id = R.string.send_log),
modifier = Modifier.padding(top = 16.dp),
textAlign = TextAlign.Center.also {
LineHeightStyle(
alignment = LineHeightStyle.Alignment.Center,
trim = LineHeightStyle.Trim.None
)
}

)
}

}
}
}
}
)
)


}

val shrink = stringResource(id = R.string.shrink_sparse_image)
val shrinkMessage = stringResource(id = R.string.shrink_sparse_image_message)
Expand Down Expand Up @@ -237,7 +350,6 @@ fun SettingScreen(navigator: DestinationsNavigator) {
}
}
}

@Composable
fun UninstallItem(
navigator: DestinationsNavigator,
Expand Down
16 changes: 16 additions & 0 deletions manager/app/src/main/java/me/weishu/kernelsu/ui/util/KsuCli.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package me.weishu.kernelsu.ui.util

import android.content.ContentResolver
import android.content.Context
import android.database.Cursor
import android.net.Uri
import android.os.Build
import android.os.Environment
import android.os.Parcelable
import android.os.SystemClock
import android.provider.OpenableColumns
import android.util.Log
import com.topjohnwu.superuser.CallbackList
import com.topjohnwu.superuser.Shell
Expand Down Expand Up @@ -48,6 +52,18 @@ inline fun <T> withNewRootShell(
return createRootShell(globalMnt).use(block)
}

fun getFileNameFromUri(context: Context, uri: Uri): String? {
var fileName: String? = null
val contentResolver: ContentResolver = context.contentResolver
val cursor: Cursor? = contentResolver.query(uri, null, null, null, null)
cursor?.use {
if (it.moveToFirst()) {
fileName = it.getString(it.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME))
}
}
return fileName
}

fun createRootShell(globalMnt: Boolean = false): Shell {
Shell.enableVerboseLogging = BuildConfig.DEBUG
val builder = Shell.Builder.create()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package me.weishu.kernelsu.ui.util

import android.content.ContentResolver
import android.content.Context
import android.net.Uri
import android.os.Build
import android.os.ParcelFileDescriptor
import android.system.Os
import com.topjohnwu.superuser.ShellUtils
import me.weishu.kernelsu.Natives
import me.weishu.kernelsu.ui.screen.getManagerVersion
import java.io.File
import java.io.FileOutputStream
import java.io.FileWriter
import java.io.PrintWriter
import java.time.LocalDateTime
Expand Down Expand Up @@ -108,3 +112,4 @@ fun getBugreportFile(context: Context): File {

return targetFile
}

1 change: 1 addition & 0 deletions manager/app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,5 @@
<string name="selected_lkm">صورة lkm المحددة: %s</string>
<string name="settings_restore_stock_image_message">استعادة صورة المصنع المخزنة (في حالة وجود نسخة احتياطية)، والتي تُستخدم عادة قبل OTA؛ إذا كنت بحاجة إلى إلغاء تثبيت KernelSU، فيرجى استخدام \"إلغاء التثبيت الدائم\".</string>
<string name="settings_uninstall_temporary_message">قم بإلغاء تثبيت KernelSU مؤقتًا، واستعد إلى حالته الأصلية بعد إعادة التشغيل التالية.</string>
<string name="save_log">حفظ السجلات</string>
</resources>
1 change: 1 addition & 0 deletions manager/app/src/main/res/values-az/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,5 @@
<string name="force_stop_app">Məcburi dayandır</string>
<string name="restart_app">Yenidən başlat</string>
<string name="failed_to_update_sepolicy">%s görə SELinux qaydalarını güncəlləmək mümkün olmadı</string>
<string name="save_log">Girişləri Saxla</string>
</resources>
1 change: 1 addition & 0 deletions manager/app/src/main/res/values-bn-rBD/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@
<string name="module_uninstall_failed">%s আনইনস্টল করা যায়নি</string>
<string name="module_version">ভার্সন</string>
<string name="module_author">অথার</string>
<string name="save_log">লগ সংরক্ষণ করুন</string>
</resources>
1 change: 1 addition & 0 deletions manager/app/src/main/res/values-bn/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@
<string name="profile_namespace_individual">আলাদাভাবে</string>
<string name="profile_umount_modules">আনমাউন্ট মোডিউল</string>
<string name="require_kernel_version">ম্যানেজার সঠিকভাবে কাজ করার জন্য বর্তমান KernelSU সংস্করণ %d খুবই কম। অনুগ্রহ করে %d বা উচ্চতর সংস্করণে আপগ্রেড করুন!</string>
<string name="save_log">লগ সংরক্ষণ করুন</string>
</resources>
1 change: 1 addition & 0 deletions manager/app/src/main/res/values-bs/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,5 @@
<string name="profile_template">Šablon</string>
<string name="profile_custom">Prilagođeno</string>
<string name="profile_name">Naziv profila</string>
<string name="save_log">Sačuvaj Dnevnike</string>
</resources>
1 change: 1 addition & 0 deletions manager/app/src/main/res/values-da/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,5 @@
<string name="profile_selinux_rules">Regler</string>
<string name="restart_app">Genstart</string>
<string name="require_kernel_version">Den nuværende KernelSU version %d er for lav til manageren for at fungere ordentligt. Opgrader til version %d eller højere!</string>
<string name="save_log">Gem Logfiler</string>
</resources>
1 change: 1 addition & 0 deletions manager/app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,5 @@
<string name="open">Öffnen</string>
<string name="settings_check_update">Updates suchen</string>
<string name="settings_check_update_summary">Automatisch nach Updates suchen beim Öffnen der App</string>
<string name="save_log">Protokolle Speichern</string>
</resources>
1 change: 1 addition & 0 deletions manager/app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,5 @@
<string name="app_profile_template_delete">Eliminar</string>
<string name="app_profile_template_import_empty">El portapapeles esta vacio!</string>
<string name="app_profile_template_view">Ver plantilla</string>
<string name="save_log">Guardar Registros</string>
</resources>
1 change: 1 addition & 0 deletions manager/app/src/main/res/values-et/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,5 @@
<string name="settings_check_update_summary">Rakenduse avamisel kontrolli automaatselt uuendusi</string>
<string name="open">Ava</string>
<string name="enable_web_debugging">Luba WebView silumine</string>
<string name="save_log">Salvesta Logid</string>
</resources>
1 change: 1 addition & 0 deletions manager/app/src/main/res/values-fa/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,5 @@
<string name="profile_namespace_global">گلوبال</string>
<string name="profile_namespace_individual">تکی</string>
<string name="profile_umount_modules">جداکردن ماژول ها</string>
<string name="save_log">ذخیره گزارش‌ها</string>
</resources>
1 change: 1 addition & 0 deletions manager/app/src/main/res/values-fil/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,5 @@
<string name="profile_name">Pangalan ng profile</string>
<string name="profile_namespace_inherited">Minana</string>
<string name="settings_umount_modules_default_summary">Ang pangkalahatang default na halaga para sa \"Umount modules\" sa Mga Profile ng App. Kung pinagana, aalisin nito ang lahat ng mga pagbabago sa modyul sa system para sa mga aplikasyon na walang hanay ng Profile.</string>
<string name="save_log">I-save ang mga Log</string>
</resources>
1 change: 1 addition & 0 deletions manager/app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,5 @@
<string name="selected_lkm">lkm sélectionné : %s</string>
<string name="settings_uninstall_permanent_message">Désinstallation complète et permanente de KernelSU (root et tous les modules).</string>
<string name="settings_uninstall_temporary_message">Désinstaller KernelSU temporairement et rétablir l\'état original au redémarrage suivant.</string>
<string name="save_log">Enregistrer les Journaux</string>
</resources>
1 change: 1 addition & 0 deletions manager/app/src/main/res/values-hi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,5 @@
<string name="about_source_code">%1$s पर स्रोत कोड देखें<br/>हमारे %2$s चैनल से जुड़ें</string>
<string name="home_manager_version">मैनेजर वर्जन</string>
<string name="new_version_available">नया वर्जन: %s उपलब्ध है,अपग्रेड के लिए क्लिक करें</string>
<string name="save_log">लॉग सहेजें</string>
</resources>
1 change: 1 addition & 0 deletions manager/app/src/main/res/values-hr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,5 @@
<string name="launch_app">Pokrenite</string>
<string name="force_stop_app">Prisilno Zaustavite</string>
<string name="restart_app">Resetujte</string>
<string name="save_log">Spremi Zapise</string>
</resources>
Loading

0 comments on commit d686016

Please sign in to comment.