remove dup Accessibility-Input solution;fix audio crash

This commit is contained in:
csf 2022-04-19 17:53:35 +08:00
parent 56e195b018
commit 11a1b12fe7
8 changed files with 20 additions and 46 deletions

View File

@ -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()

View File

@ -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}) {

View File

@ -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("");
});

View File

@ -40,9 +40,6 @@ class ChatPage extends StatelessWidget implements PageShape {
})
];
@override
final scrollController = FFI.chatModel.scroller;
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider.value(

View File

@ -22,9 +22,6 @@ class ConnectionPage extends StatefulWidget implements PageShape {
@override
final appBarActions = !isAndroid ? <Widget>[WebMenu()] : <Widget>[];
@override
final scrollController = ScrollController();
@override
_ConnectionPageState createState() => _ConnectionPageState();
}
@ -50,7 +47,6 @@ class _ConnectionPageState extends State<ConnectionPage> {
Provider.of<FfiModel>(context);
if (_idController.text.isEmpty) _idController.text = FFI.getId();
return SingleChildScrollView(
controller: widget.scrollController,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.max,

View File

@ -9,7 +9,6 @@ abstract class PageShape extends Widget {
final String title = "";
final Icon icon = Icon(null);
final List<Widget> appBarActions = [];
final ScrollController? scrollController = null;
}
class HomePage extends StatefulWidget {
@ -72,20 +71,7 @@ class _HomePageState extends State<HomePage> {
_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),
));
}
}

View File

@ -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<ServerModel>(
builder: (context, serverModel, child) => SingleChildScrollView(
controller: scrollController,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,

View File

@ -20,9 +20,6 @@ class SettingsPage extends StatefulWidget implements PageShape {
@override
final appBarActions = [ScanButton()];
@override
final scrollController = null;
@override
_SettingsState createState() => _SettingsState();
}