mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-02 06:46:22 +01:00
Dump system logcat
This commit is contained in:
parent
d3c62611fa
commit
4295a011d3
4 changed files with 54 additions and 0 deletions
|
@ -0,0 +1,32 @@
|
|||
package com.nkming.nc_photos.plugin
|
||||
|
||||
import io.flutter.plugin.common.MethodCall
|
||||
import io.flutter.plugin.common.MethodChannel
|
||||
|
||||
class LogcatChannelHandler : MethodChannel.MethodCallHandler {
|
||||
companion object {
|
||||
const val METHOD_CHANNEL = "${K.LIB_ID}/logcat_method"
|
||||
}
|
||||
|
||||
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
|
||||
when (call.method) {
|
||||
"dump" -> {
|
||||
try {
|
||||
dump(result)
|
||||
} catch (e: Throwable) {
|
||||
result.error("systemException", e.toString(), null)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun dump(result: MethodChannel.Result) {
|
||||
val logs = StringBuilder()
|
||||
val process = Runtime.getRuntime().exec("logcat -d")
|
||||
process.inputStream.bufferedReader().use {
|
||||
while (it.readLine()?.also(logs::appendLine) != null) {
|
||||
}
|
||||
}
|
||||
result.success(logs.toString())
|
||||
}
|
||||
}
|
|
@ -98,6 +98,13 @@ class NcPhotosPlugin : FlutterPlugin, ActivityAware,
|
|||
PermissionChannelHandler.METHOD_CHANNEL
|
||||
)
|
||||
permissionMethodChannel.setMethodCallHandler(permissionChannelHandler)
|
||||
|
||||
val logcatChannelHandler = LogcatChannelHandler()
|
||||
logcatMethodChannel = MethodChannel(
|
||||
flutterPluginBinding.binaryMessenger,
|
||||
LogcatChannelHandler.METHOD_CHANNEL
|
||||
)
|
||||
logcatMethodChannel.setMethodCallHandler(logcatChannelHandler)
|
||||
}
|
||||
|
||||
override fun onDetachedFromEngine(
|
||||
|
@ -114,6 +121,7 @@ class NcPhotosPlugin : FlutterPlugin, ActivityAware,
|
|||
contentUriMethodChannel.setMethodCallHandler(null)
|
||||
permissionChannel.setStreamHandler(null)
|
||||
permissionMethodChannel.setMethodCallHandler(null)
|
||||
logcatMethodChannel.setMethodCallHandler(null)
|
||||
}
|
||||
|
||||
override fun onAttachedToActivity(binding: ActivityPluginBinding) {
|
||||
|
@ -200,6 +208,7 @@ class NcPhotosPlugin : FlutterPlugin, ActivityAware,
|
|||
private lateinit var contentUriMethodChannel: MethodChannel
|
||||
private lateinit var permissionChannel: EventChannel
|
||||
private lateinit var permissionMethodChannel: MethodChannel
|
||||
private lateinit var logcatMethodChannel: MethodChannel
|
||||
|
||||
private lateinit var lockChannelHandler: LockChannelHandler
|
||||
private lateinit var mediaStoreChannelHandler: MediaStoreChannelHandler
|
||||
|
|
|
@ -4,6 +4,7 @@ export 'src/content_uri.dart';
|
|||
export 'src/exception.dart';
|
||||
export 'src/image_processor.dart';
|
||||
export 'src/lock.dart';
|
||||
export 'src/logcat.dart';
|
||||
export 'src/media_store.dart';
|
||||
export 'src/native_event.dart';
|
||||
export 'src/notification.dart';
|
||||
|
|
12
plugin/lib/src/logcat.dart
Normal file
12
plugin/lib/src/logcat.dart
Normal file
|
@ -0,0 +1,12 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:nc_photos_plugin/src/k.dart' as k;
|
||||
|
||||
class Logcat {
|
||||
static Future<String> dump() async {
|
||||
return await _methodChannel.invokeMethod("dump");
|
||||
}
|
||||
|
||||
static const _methodChannel = MethodChannel("${k.libId}/logcat_method");
|
||||
}
|
Loading…
Reference in a new issue