From 11a1b12fe73a6dd1a4905ac4390204740a3337d7 Mon Sep 17 00:00:00 2001 From: csf Date: Tue, 19 Apr 2022 17:53:35 +0800 Subject: [PATCH] remove dup Accessibility-Input solution;fix audio crash --- .../com/carriez/flutter_hbb/MainService.kt | 31 ++++++++++--------- lib/common.dart | 4 +-- lib/models/server_model.dart | 1 + lib/pages/chat_page.dart | 3 -- lib/pages/connection_page.dart | 4 --- lib/pages/home_page.dart | 16 +--------- lib/pages/server_page.dart | 4 --- lib/pages/settings_page.dart | 3 -- 8 files changed, 20 insertions(+), 46 deletions(-) diff --git a/android/app/src/main/kotlin/com/carriez/flutter_hbb/MainService.kt b/android/app/src/main/kotlin/com/carriez/flutter_hbb/MainService.kt index 47244de1a..88f31dca3 100644 --- a/android/app/src/main/kotlin/com/carriez/flutter_hbb/MainService.kt +++ b/android/app/src/main/kotlin/com/carriez/flutter_hbb/MainService.kt @@ -262,7 +262,8 @@ class MainService : Service() { _isReady = true } } - return super.onStartCommand(intent, flags, startId) + super.onStartCommand(intent, flags, startId) + return START_NOT_STICKY // don't use sticky (auto restart),the new service (from auto restart) will lose control } override fun onConfigurationChanged(newConfig: Configuration) { @@ -464,15 +465,19 @@ class MainService : Service() { private fun startAudioRecorder() { checkAudioRecorder() if (audioReader != null && audioRecorder != null && minBufferSize != 0) { - audioRecorder!!.startRecording() - audioRecordStat = true - thread { - while (audioRecordStat) { - audioReader!!.readSync(audioRecorder!!)?.let { - onAudioFrameUpdate(it) + try { + audioRecorder!!.startRecording() + audioRecordStat = true + thread { + while (audioRecordStat) { + audioReader!!.readSync(audioRecorder!!)?.let { + onAudioFrameUpdate(it) + } } + Log.d(logTag, "Exit audio thread") } - Log.d(logTag, "Exit audio thread") + } catch (e: Exception) { + Log.d(logTag, "startAudioRecorder fail:$e") } } else { Log.d(logTag, "startAudioRecorder fail") @@ -555,11 +560,7 @@ class MainService : Service() { addCategory(Intent.CATEGORY_LAUNCHER) putExtra("type", type) } - val pendingIntent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - PendingIntent.getActivity(this, 0, intent, FLAG_IMMUTABLE) - } else { - PendingIntent.getActivity(this, 0, intent, FLAG_UPDATE_CURRENT) - } + val pendingIntent = PendingIntent.getActivity(this, 0, intent, FLAG_UPDATE_CURRENT) val notification = notificationBuilder .setOngoing(true) .setSmallIcon(R.mipmap.ic_launcher) @@ -584,7 +585,7 @@ class MainService : Service() { ) { val notification = notificationBuilder .setOngoing(false) - .setPriority(NotificationCompat.PRIORITY_HIGH) + .setPriority(NotificationCompat.PRIORITY_MAX) .setContentTitle(translate("Do you accept?")) .setContentText("$type:$username-$peerId") // .setStyle(MediaStyle().setShowActionsInCompactView(0, 1)) @@ -603,7 +604,7 @@ class MainService : Service() { cancelNotification(clientID) val notification = notificationBuilder .setOngoing(false) - .setPriority(NotificationCompat.PRIORITY_HIGH) + .setPriority(NotificationCompat.PRIORITY_MAX) .setContentTitle("$type ${translate("Established")}") .setContentText("$username - $peerId") .build() diff --git a/lib/common.dart b/lib/common.dart index 585d53569..1c14aeb0c 100644 --- a/lib/common.dart +++ b/lib/common.dart @@ -44,8 +44,8 @@ final ButtonStyle flatButtonStyle = TextButton.styleFrom( ), ); -void showToast(String text,{Duration? duration}) { - SmartDialog.showToast(text,displayTime: duration); +void showToast(String text, {Duration? duration}) { + SmartDialog.showToast(text, displayTime: duration); } void showLoading(String text, {bool clickMaskDismiss = false}) { diff --git a/lib/models/server_model.dart b/lib/models/server_model.dart index 37538aaa5..b45d0236c 100644 --- a/lib/models/server_model.dart +++ b/lib/models/server_model.dart @@ -192,6 +192,7 @@ class ServerModel with ChangeNotifier { _isStart = true; notifyListeners(); FFI.setByName("ensure_init_event_queue"); + _interval?.cancel(); _interval = Timer.periodic(Duration(milliseconds: 30), (timer) { FFI.ffiModel.update(""); }); diff --git a/lib/pages/chat_page.dart b/lib/pages/chat_page.dart index 410d8f1fb..7316ae2bf 100644 --- a/lib/pages/chat_page.dart +++ b/lib/pages/chat_page.dart @@ -40,9 +40,6 @@ class ChatPage extends StatelessWidget implements PageShape { }) ]; - @override - final scrollController = FFI.chatModel.scroller; - @override Widget build(BuildContext context) { return ChangeNotifierProvider.value( diff --git a/lib/pages/connection_page.dart b/lib/pages/connection_page.dart index 282a98a3d..10d49e0ec 100644 --- a/lib/pages/connection_page.dart +++ b/lib/pages/connection_page.dart @@ -22,9 +22,6 @@ class ConnectionPage extends StatefulWidget implements PageShape { @override final appBarActions = !isAndroid ? [WebMenu()] : []; - @override - final scrollController = ScrollController(); - @override _ConnectionPageState createState() => _ConnectionPageState(); } @@ -50,7 +47,6 @@ class _ConnectionPageState extends State { Provider.of(context); if (_idController.text.isEmpty) _idController.text = FFI.getId(); return SingleChildScrollView( - controller: widget.scrollController, child: Column( mainAxisAlignment: MainAxisAlignment.start, mainAxisSize: MainAxisSize.max, diff --git a/lib/pages/home_page.dart b/lib/pages/home_page.dart index baa5659f7..c4f9e0c08 100644 --- a/lib/pages/home_page.dart +++ b/lib/pages/home_page.dart @@ -9,7 +9,6 @@ abstract class PageShape extends Widget { final String title = ""; final Icon icon = Icon(null); final List appBarActions = []; - final ScrollController? scrollController = null; } class HomePage extends StatefulWidget { @@ -72,20 +71,7 @@ class _HomePageState extends State { _selectedIndex = index; }), ), - body: Listener( - onPointerMove: (evt) { - final page = _pages.elementAt(_selectedIndex); - - /// Flutter can't not catch PointerMoveEvent when size is 1 - /// This will happen in Android AccessibilityService Input - /// android can't init dispatching size yet ,see: https://stackoverflow.com/questions/59960451/android-accessibility-dispatchgesture-is-it-possible-to-specify-pressure-for-a - /// use this temporary solution until flutter or android fixes the bug - if (evt.size == 1 && page.scrollController != null) { - final offset = page.scrollController!.offset.toDouble(); - page.scrollController!.jumpTo(offset - evt.delta.dy); - } - }, - child: _pages.elementAt(_selectedIndex)), + body: _pages.elementAt(_selectedIndex), )); } } diff --git a/lib/pages/server_page.dart b/lib/pages/server_page.dart index 01f0464c4..900d6b29e 100644 --- a/lib/pages/server_page.dart +++ b/lib/pages/server_page.dart @@ -58,9 +58,6 @@ class ServerPage extends StatelessWidget implements PageShape { }) ]; - @override - final scrollController = ScrollController(); - @override Widget build(BuildContext context) { checkService(); @@ -68,7 +65,6 @@ class ServerPage extends StatelessWidget implements PageShape { value: FFI.serverModel, child: Consumer( builder: (context, serverModel, child) => SingleChildScrollView( - controller: scrollController, child: Center( child: Column( mainAxisAlignment: MainAxisAlignment.start, diff --git a/lib/pages/settings_page.dart b/lib/pages/settings_page.dart index 9ab4ac491..ed4103f24 100644 --- a/lib/pages/settings_page.dart +++ b/lib/pages/settings_page.dart @@ -20,9 +20,6 @@ class SettingsPage extends StatefulWidget implements PageShape { @override final appBarActions = [ScanButton()]; - @override - final scrollController = null; - @override _SettingsState createState() => _SettingsState(); }