wangzhibo
4 天以前 ae6f40460dcd56af6c5f60ba52c883854c3bac55
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
/*  Copyright (C) 2015-2024 Alicia Hormann, Andreas Böhler, Andreas Shimokawa,
    Arjan Schrijver, Carsten Pfeiffer, Daniele Gobbetti, Davis Mosenkovs,
    Dmitriy Bogdanov, foxstidious, Ganblejs, José Rebelo, Pauli Salmenrinne,
    Petr Vaněk, Taavi Eomäe, Yoran Vulker
 
    This file is part of Gadgetbridge.
 
    Gadgetbridge is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published
    by the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
 
    Gadgetbridge is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.
 
    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.service;
 
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.bluetooth.BluetoothAdapter;
import android.companion.CompanionDeviceManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.location.Location;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.text.TextUtils;
 
import androidx.annotation.RequiresApi;
import androidx.core.app.NotificationCompat;
import androidx.core.content.FileProvider;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
 
import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.Locale;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
 
import nodomain.freeyourgadget.gadgetbridge.BuildConfig;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.CameraActivity;
import nodomain.freeyourgadget.gadgetbridge.activities.FindPhoneActivity;
import nodomain.freeyourgadget.gadgetbridge.activities.appmanager.AbstractAppManagerFragment;
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
import nodomain.freeyourgadget.gadgetbridge.activities.musicmanager.MusicManagerActivity;
import nodomain.freeyourgadget.gadgetbridge.capabilities.loyaltycards.LoyaltyCard;
import nodomain.freeyourgadget.gadgetbridge.database.DBAccess;
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventAppInfo;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventBatteryInfo;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventCallControl;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventCameraRemote;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventDisplayMessage;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFmFrequency;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSleepStateDetection;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSilentMode;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdateDeviceInfo;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventLEDColor;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicControl;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventNotificationControl;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdateDeviceState;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdatePreferences;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventScreenshot;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventVersionInfo;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventWearState;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceMusicData;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceMusicUpdate;
import nodomain.freeyourgadget.gadgetbridge.entities.BatteryLevel;
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
import nodomain.freeyourgadget.gadgetbridge.externalevents.NotificationListener;
import nodomain.freeyourgadget.gadgetbridge.externalevents.opentracks.OpenTracksController;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceMusic;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceMusicPlaylist;
import nodomain.freeyourgadget.gadgetbridge.model.Alarm;
import nodomain.freeyourgadget.gadgetbridge.model.BatteryConfig;
import nodomain.freeyourgadget.gadgetbridge.model.BatteryState;
import nodomain.freeyourgadget.gadgetbridge.model.CalendarEventSpec;
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
import nodomain.freeyourgadget.gadgetbridge.model.CannedMessagesSpec;
import nodomain.freeyourgadget.gadgetbridge.model.Contact;
import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec;
import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec;
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
import nodomain.freeyourgadget.gadgetbridge.model.Reminder;
import nodomain.freeyourgadget.gadgetbridge.model.SleepState;
import nodomain.freeyourgadget.gadgetbridge.model.WearingState;
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
import nodomain.freeyourgadget.gadgetbridge.model.WorldClock;
import nodomain.freeyourgadget.gadgetbridge.model.NavigationInfoSpec;
import nodomain.freeyourgadget.gadgetbridge.service.receivers.GBCallControlReceiver;
import nodomain.freeyourgadget.gadgetbridge.service.receivers.GBMusicControlReceiver;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
import nodomain.freeyourgadget.gadgetbridge.util.PendingIntentUtils;
import nodomain.freeyourgadget.gadgetbridge.util.SilentMode;
import nodomain.freeyourgadget.gadgetbridge.util.preferences.DevicePrefs;
 
import static nodomain.freeyourgadget.gadgetbridge.util.GB.NOTIFICATION_CHANNEL_HIGH_PRIORITY_ID;
 
// TODO: support option for a single reminder notification when notifications could not be delivered?
// conditions: app was running and received notifications, but device was not connected.
// maybe need to check for "unread notifications" on device for that.
 
/**
 * Abstract implementation of DeviceSupport with some implementations for
 * common functionality. Still transport independent.
 */
public abstract class AbstractDeviceSupport implements DeviceSupport {
    private static final Logger LOG = LoggerFactory.getLogger(AbstractDeviceSupport.class);
    private static final int NOTIFICATION_ID_SCREENSHOT = 8000;
 
    protected GBDevice gbDevice;
    private BluetoothAdapter btAdapter;
    private Context context;
    private boolean autoReconnect, scanReconnect;
 
 
 
    @Override
    public void setContext(GBDevice gbDevice, BluetoothAdapter btAdapter, Context context) {
        this.gbDevice = gbDevice;
        this.btAdapter = btAdapter;
        this.context = context;
    }
 
    /**
     * Default implementation just calls #connect()
     */
    @Override
    public boolean connectFirstTime() {
        return connect();
    }
 
    @Override
    public boolean isConnected() {
        return gbDevice.isConnected();
    }
 
    /**
     * Returns true if the device is not only connected, but also
     * initialized.
     *
     * @see GBDevice#isInitialized()
     */
    protected boolean isInitialized() {
        return gbDevice.isInitialized();
    }
 
    @Override
    public void setAutoReconnect(boolean enable) {
        autoReconnect = enable;
    }
 
    @Override
    public boolean getAutoReconnect() {
        return autoReconnect;
    }
 
    @Override
    public void setScanReconnect(boolean scanReconnect) {
        this.scanReconnect = scanReconnect;
    }
 
    @Override
    public boolean getScanReconnect(){
        return this.scanReconnect;
    }
 
    @Override
    public GBDevice getDevice() {
        return gbDevice;
    }
 
    @Override
    public BluetoothAdapter getBluetoothAdapter() {
        return btAdapter;
    }
 
    @Override
    public Context getContext() {
        return context;
    }
 
    public void evaluateGBDeviceEvent(GBDeviceEvent deviceEvent) {
        if (deviceEvent instanceof GBDeviceEventMusicControl) {
            handleGBDeviceEvent((GBDeviceEventMusicControl) deviceEvent);
        } else if (deviceEvent instanceof GBDeviceEventCallControl) {
            handleGBDeviceEvent((GBDeviceEventCallControl) deviceEvent);
        } else if (deviceEvent instanceof GBDeviceEventCameraRemote) {
            handleGBDeviceEvent((GBDeviceEventCameraRemote) deviceEvent);
        } else if (deviceEvent instanceof GBDeviceEventVersionInfo) {
            handleGBDeviceEvent((GBDeviceEventVersionInfo) deviceEvent);
        } else if (deviceEvent instanceof GBDeviceEventAppInfo) {
            handleGBDeviceEvent((GBDeviceEventAppInfo) deviceEvent);
        } else if (deviceEvent instanceof GBDeviceEventScreenshot) {
            handleGBDeviceEvent((GBDeviceEventScreenshot) deviceEvent);
        } else if (deviceEvent instanceof GBDeviceEventNotificationControl) {
            handleGBDeviceEvent((GBDeviceEventNotificationControl) deviceEvent);
        } else if (deviceEvent instanceof GBDeviceEventBatteryInfo) {
            handleGBDeviceEvent((GBDeviceEventBatteryInfo) deviceEvent);
        } else if (deviceEvent instanceof GBDeviceEventFindPhone) {
            handleGBDeviceEvent((GBDeviceEventFindPhone) deviceEvent);
        } else if (deviceEvent instanceof GBDeviceEventLEDColor) {
            handleGBDeviceEvent((GBDeviceEventLEDColor) deviceEvent);
        } else if (deviceEvent instanceof GBDeviceEventUpdateDeviceInfo) {
            handleGBDeviceEvent((GBDeviceEventUpdateDeviceInfo) deviceEvent);
        } else if (deviceEvent instanceof GBDeviceEventUpdatePreferences) {
            handleGBDeviceEvent((GBDeviceEventUpdatePreferences) deviceEvent);
        } else if (deviceEvent instanceof GBDeviceEventUpdateDeviceState) {
            handleGBDeviceEvent((GBDeviceEventUpdateDeviceState) deviceEvent);
        } else if (deviceEvent instanceof GBDeviceEventSilentMode) {
            handleGBDeviceEvent((GBDeviceEventSilentMode) deviceEvent);
        } else if (deviceEvent instanceof GBDeviceEventFmFrequency) {
            handleGBDeviceEvent((GBDeviceEventFmFrequency) deviceEvent);
        } else if (deviceEvent instanceof GBDeviceEventWearState) {
            handleGBDeviceEvent((GBDeviceEventWearState) deviceEvent);
        } else if (deviceEvent instanceof GBDeviceEventSleepStateDetection) {
            handleGBDeviceEvent((GBDeviceEventSleepStateDetection) deviceEvent);
        } else if (deviceEvent instanceof GBDeviceMusicData) {
            handleGBDeviceEvent((GBDeviceMusicData) deviceEvent);
        } else if (deviceEvent instanceof GBDeviceMusicUpdate) {
            handleGBDeviceEvent((GBDeviceMusicUpdate) deviceEvent);
        }
 
    }
 
    private void handleGBDeviceEvent(GBDeviceEventSilentMode deviceEvent) {
        LOG.info("Got GBDeviceEventSilentMode: enabled = {}", deviceEvent.isEnabled());
 
        SilentMode.setPhoneSilentMode(getDevice().getAddress(), deviceEvent.isEnabled());
    }
 
    private void handleGBDeviceEvent(final GBDeviceEventFindPhone deviceEvent) {
        final Context context = getContext();
        LOG.info("Got GBDeviceEventFindPhone: {}", deviceEvent.event);
        switch (deviceEvent.event) {
            case START:
                handleGBDeviceEventFindPhoneStart(true);
                break;
            case START_VIBRATE:
                handleGBDeviceEventFindPhoneStart(false);
                break;
            case VIBRATE:
                final Intent intentVibrate = new Intent(FindPhoneActivity.ACTION_VIBRATE);
                intentVibrate.setPackage(BuildConfig.APPLICATION_ID);
                LocalBroadcastManager.getInstance(context).sendBroadcast(intentVibrate);
                break;
            case RING:
                final Intent intentRing = new Intent(FindPhoneActivity.ACTION_RING);
                intentRing.setPackage(BuildConfig.APPLICATION_ID);
                LocalBroadcastManager.getInstance(context).sendBroadcast(intentRing);
                break;
            case STOP:
                final Intent intentStop = new Intent(FindPhoneActivity.ACTION_FOUND);
                intentStop.setPackage(BuildConfig.APPLICATION_ID);
                LocalBroadcastManager.getInstance(context).sendBroadcast(intentStop);
                break;
            default:
                LOG.warn("unknown GBDeviceEventFindPhone");
        }
    }
 
    private void handleGBDeviceEventFindPhoneStart(final boolean ring) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { // this could be used if app in foreground // TODO: Below Q?
            Intent startIntent = new Intent(getContext(), FindPhoneActivity.class);
            startIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startIntent.putExtra(FindPhoneActivity.EXTRA_RING, ring);
            context.startActivity(startIntent);
        } else {
            handleGBDeviceEventFindPhoneStartNotification(ring);
        }
    }
 
    @RequiresApi(Build.VERSION_CODES.Q)
    private void handleGBDeviceEventFindPhoneStartNotification(final boolean ring) {
        LOG.info("Got handleGBDeviceEventFindPhoneStartNotification");
        final CompanionDeviceManager manager = (CompanionDeviceManager) context.getSystemService(Context.COMPANION_DEVICE_SERVICE);
        if (manager.getAssociations().isEmpty()) {
            // On Android Q and above, we need the device to be paired as companion. If it is not, display a notification
            // notifying the user and linking to further instructions
            final Intent instructionsIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://gadgetbridge.org/basics/pairing/companion-device/"));
            final PendingIntent pi = PendingIntentUtils.getActivity(context, 0, instructionsIntent, PendingIntent.FLAG_ONE_SHOT, false);
            final NotificationCompat.Builder notification = new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_HIGH_PRIORITY_ID)
                    .setSmallIcon(R.drawable.ic_warning)
                    .setOngoing(false)
                    .setPriority(NotificationCompat.PRIORITY_HIGH)
                    .setContentIntent(pi)
                    .setAutoCancel(true)
                    .setContentTitle(context.getString(R.string.find_my_phone_notification))
                    .setContentText(context.getString(R.string.find_my_phone_companion_warning));
 
            GB.notify(GB.NOTIFICATION_ID_PHONE_FIND, notification.build(), context);
 
            return;
        }
 
        final Intent intent = new Intent(context, FindPhoneActivity.class);
        intent.setPackage(BuildConfig.APPLICATION_ID);
        intent.putExtra(FindPhoneActivity.EXTRA_RING, ring);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
 
        final PendingIntent pi = PendingIntentUtils.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT, false);
 
        final NotificationCompat.Builder notification = new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_HIGH_PRIORITY_ID)
                .setSmallIcon(R.drawable.ic_notification)
                .setOngoing(false)
                .setFullScreenIntent(pi, true)
                .setPriority(NotificationCompat.PRIORITY_HIGH)
                .setAutoCancel(true)
                .setGroup("BackgroundService")
                .setContentTitle(context.getString(R.string.find_my_phone_notification));
 
        GB.notify(GB.NOTIFICATION_ID_PHONE_FIND, notification.build(), context);
        context.startActivity(intent);
        LOG.debug("CompanionDeviceManager associations were found, starting intent");
    }
 
 
    private void handleGBDeviceEvent(GBDeviceEventMusicControl musicEvent) {
        Context context = getContext();
        LOG.info("Got event for MUSIC_CONTROL");
        Intent musicIntent = new Intent(GBMusicControlReceiver.ACTION_MUSICCONTROL);
        musicIntent.putExtra("event", musicEvent.event.ordinal());
        musicIntent.setPackage(context.getPackageName());
        context.sendBroadcast(musicIntent);
    }
 
    private void handleGBDeviceEvent(GBDeviceEventCallControl callEvent) {
        Context context = getContext();
        LOG.info("Got event for CALL_CONTROL");
        if(callEvent.event == GBDeviceEventCallControl.Event.IGNORE) {
            LOG.info("Sending intent for mute");
            Intent broadcastIntent = new Intent(context.getPackageName() + ".MUTE_CALL");
            broadcastIntent.setPackage(context.getPackageName());
            context.sendBroadcast(broadcastIntent);
            return;
        }
        Intent callIntent = new Intent(GBCallControlReceiver.ACTION_CALLCONTROL);
        callIntent.putExtra("event", callEvent.event.ordinal());
        callIntent.setPackage(context.getPackageName());
        context.sendBroadcast(callIntent);
    }
 
    protected void handleGBDeviceEvent(GBDeviceEventCameraRemote cameraRemoteEvent) {
        Intent cameraIntent = new Intent(getContext(), CameraActivity.class);
        cameraIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        cameraIntent.putExtra(CameraActivity.intentExtraEvent, GBDeviceEventCameraRemote.eventToInt(cameraRemoteEvent.event));
        getContext().startActivity(cameraIntent);
    }
 
    protected void handleGBDeviceEvent(GBDeviceEventVersionInfo infoEvent) {
        Context context = getContext();
        LOG.info("Got event for VERSION_INFO: " + infoEvent);
        if (gbDevice == null) {
            return;
        }
        if (infoEvent.fwVersion != null) {
            gbDevice.setFirmwareVersion(infoEvent.fwVersion);
        }
        if (infoEvent.fwVersion2 != null) {
            gbDevice.setFirmwareVersion2(infoEvent.fwVersion2);
        }
        gbDevice.setModel(infoEvent.hwVersion);
        gbDevice.sendDeviceUpdateIntent(context);
    }
 
    protected void handleGBDeviceEvent(GBDeviceEventLEDColor colorEvent) {
        Context context = getContext();
        LOG.info("Got event for LED Color: #" + Integer.toHexString(colorEvent.color).toUpperCase(Locale.ROOT));
        if (gbDevice == null) {
            return;
        }
        gbDevice.setExtraInfo("led_color", colorEvent.color);
        gbDevice.sendDeviceUpdateIntent(context);
    }
 
    protected void handleGBDeviceEvent(GBDeviceEventUpdateDeviceInfo itemEvent) {
        if (gbDevice == null) {
            return;
        }
 
        gbDevice.addDeviceInfo(itemEvent.item);
        gbDevice.sendDeviceUpdateIntent(context);
    }
 
    protected void handleGBDeviceEvent(GBDeviceEventUpdatePreferences savePreferencesEvent) {
        if (gbDevice == null) {
            return;
        }
 
        savePreferencesEvent.update(GBApplication.getDeviceSpecificSharedPrefs(getDevice().getAddress()));
        gbDevice.sendDeviceUpdateIntent(context);
    }
 
    protected void handleGBDeviceEvent(GBDeviceEventUpdateDeviceState updateDeviceState) {
        if (gbDevice == null) {
            return;
        }
 
        gbDevice.setState(updateDeviceState.state);
        gbDevice.sendDeviceUpdateIntent(getContext());
    }
 
    protected void handleGBDeviceEvent(GBDeviceEventFmFrequency frequencyEvent) {
        Context context = getContext();
        LOG.info("Got event for FM Frequency");
        if (gbDevice == null) {
            return;
        }
        gbDevice.setExtraInfo("fm_frequency", frequencyEvent.frequency);
        gbDevice.sendDeviceUpdateIntent(context);
    }
 
    private void handleGBDeviceEvent(GBDeviceEventAppInfo appInfoEvent) {
        Context context = getContext();
        LOG.info("Got event for APP_INFO");
 
        Intent appInfoIntent = new Intent(AbstractAppManagerFragment.ACTION_REFRESH_APPLIST);
        int appCount = appInfoEvent.apps.length;
        appInfoIntent.putExtra("app_count", appCount);
        for (int i = 0; i < appCount; i++) {
            appInfoIntent.putExtra("app_name" + i, appInfoEvent.apps[i].getName());
            appInfoIntent.putExtra("app_creator" + i, appInfoEvent.apps[i].getCreator());
            appInfoIntent.putExtra("app_version" + i, appInfoEvent.apps[i].getVersion());
            appInfoIntent.putExtra("app_uuid" + i, appInfoEvent.apps[i].getUUID().toString());
            appInfoIntent.putExtra("app_type" + i, appInfoEvent.apps[i].getType().ordinal());
        }
        LocalBroadcastManager.getInstance(context).sendBroadcast(appInfoIntent);
    }
 
    private void handleGBDeviceEvent(GBDeviceEventScreenshot screenshot) {
        if (screenshot.getData() == null) {
            LOG.warn("Screnshot data is null");
            return;
        }
 
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd-hhmmss", Locale.US);
        String filename = "screenshot_" + dateFormat.format(new Date()) + ".bmp";
 
        try {
            String fullpath = GB.writeScreenshot(screenshot, filename);
            Bitmap bmp = BitmapFactory.decodeFile(fullpath);
            Intent intent = new Intent();
            intent.setAction(android.content.Intent.ACTION_VIEW);
            Uri screenshotURI = FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".screenshot_provider", new File(fullpath));
            intent.setDataAndType(screenshotURI, "image/*");
            intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
 
            PendingIntent pIntent = PendingIntentUtils.getActivity(context, 0, intent, 0, false);
 
            Intent shareIntent = new Intent(Intent.ACTION_SEND);
            shareIntent.setType("image/*");
            shareIntent.putExtra(Intent.EXTRA_STREAM, screenshotURI);
 
            PendingIntent pendingShareIntent = PendingIntentUtils.getActivity(context, 0, Intent.createChooser(shareIntent, context.getString(R.string.share_screenshot)),
                    PendingIntent.FLAG_UPDATE_CURRENT, false);
 
            NotificationCompat.Action action = new NotificationCompat.Action.Builder(android.R.drawable.ic_menu_share, context.getString(R.string.share), pendingShareIntent).build();
 
            Notification notif = new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_HIGH_PRIORITY_ID)
                    .setContentTitle(context.getString(R.string.screenshot_taken))
                    .setTicker(context.getString(R.string.screenshot_taken))
                    .setContentText(filename)
                    .setSmallIcon(R.drawable.ic_notification)
                    .setStyle(new NotificationCompat.BigPictureStyle()
                            .bigPicture(bmp))
                    .setContentIntent(pIntent)
                    .addAction(action)
                    .setAutoCancel(true)
                    .build();
 
            GB.notify(NOTIFICATION_ID_SCREENSHOT, notif, context);
        } catch (IOException ex) {
            LOG.error("Error writing screenshot", ex);
        }
    }
 
    private void handleGBDeviceEvent(GBDeviceEventNotificationControl deviceEvent) {
        Context context = getContext();
        LOG.info("Got NOTIFICATION CONTROL device event");
        String action = null;
        switch (deviceEvent.event) {
            case DISMISS:
                action = NotificationListener.ACTION_DISMISS;
                break;
            case DISMISS_ALL:
                action = NotificationListener.ACTION_DISMISS_ALL;
                break;
            case OPEN:
                action = NotificationListener.ACTION_OPEN;
                break;
            case MUTE:
                action = NotificationListener.ACTION_MUTE;
                break;
            case REPLY:
                if (deviceEvent.phoneNumber == null) {
                    deviceEvent.phoneNumber = GBApplication.getIDSenderLookup().lookup((int) (deviceEvent.handle >> 4));
                }
                if (deviceEvent.phoneNumber != null) {
                    LOG.info("Got notification reply for SMS from " + deviceEvent.phoneNumber + " : " + deviceEvent.reply);
                    SmsManager.getDefault().sendTextMessage(deviceEvent.phoneNumber, null, deviceEvent.reply, null, null);
                } else {
                    LOG.info("Got notification reply for notification id " + deviceEvent.handle + " : " + deviceEvent.reply);
                    action = NotificationListener.ACTION_REPLY;
                }
                break;
        }
        if (action != null) {
            Intent notificationListenerIntent = new Intent(action);
            notificationListenerIntent.putExtra("handle", deviceEvent.handle);
            notificationListenerIntent.putExtra("title", deviceEvent.title);
            if (deviceEvent.reply != null) {
                SharedPreferences prefs = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress());
                String suffix = prefs.getString("canned_reply_suffix", null);
                if (suffix != null && !Objects.equals(suffix, "")) {
                    deviceEvent.reply += suffix;
                }
                notificationListenerIntent.putExtra("reply", deviceEvent.reply);
            }
            LocalBroadcastManager.getInstance(context).sendBroadcast(notificationListenerIntent);
        }
    }
 
    protected void handleGBDeviceEvent(GBDeviceEventBatteryInfo deviceEvent) {
        Context context = getContext();
        LOG.info("Got BATTERY_INFO device event");
        gbDevice.setBatteryLevel(deviceEvent.level, deviceEvent.batteryIndex);
        gbDevice.setBatteryState(deviceEvent.state);
        gbDevice.setBatteryVoltage(deviceEvent.voltage, deviceEvent.batteryIndex);
 
        final DevicePrefs devicePrefs = GBApplication.getDevicePrefs(gbDevice);
        final BatteryConfig batteryConfig = gbDevice.getDeviceCoordinator().getBatteryConfig(gbDevice)[deviceEvent.batteryIndex];
 
        if (deviceEvent.level == GBDevice.BATTERY_UNKNOWN) {
            // no level available, just "high" or "low"
            GB.removeBatteryFullNotification(context);
            if (devicePrefs.getBatteryNotifyLowEnabled(batteryConfig) && BatteryState.BATTERY_LOW.equals(deviceEvent.state)) {
                GB.updateBatteryLowNotification(context.getString(R.string.notif_battery_low, gbDevice.getAliasOrName()),
                        deviceEvent.extendedInfoAvailable() ?
                                context.getString(R.string.notif_battery_low_extended, gbDevice.getAliasOrName(),
                                        context.getString(R.string.notif_battery_low_bigtext_last_charge_time, DateFormat.getDateTimeInstance().format(deviceEvent.lastChargeTime.getTime())) +
                                        context.getString(R.string.notif_battery_low_bigtext_number_of_charges, String.valueOf(deviceEvent.numCharges)))
                                : ""
                        , context);
            } else if (devicePrefs.getBatteryNotifyFullEnabled(batteryConfig) && BatteryState.BATTERY_CHARGING_FULL.equals(deviceEvent.state)) {
                GB.removeBatteryLowNotification(context);
                GB.updateBatteryFullNotification(context.getString(R.string.notif_battery_full, gbDevice.getAliasOrName()), "", context);
            } else {
                GB.removeBatteryLowNotification(context);
                GB.removeBatteryFullNotification(context);
            }
        } else {
            createStoreTask("Storing battery data", context, deviceEvent).execute();
 
            final boolean batteryNotifyLowEnabled = devicePrefs.getBatteryNotifyLowEnabled(batteryConfig);
            final boolean isBatteryLow = deviceEvent.level <= devicePrefs.getBatteryNotifyLowThreshold(batteryConfig) &&
                    (BatteryState.BATTERY_LOW.equals(deviceEvent.state) || BatteryState.BATTERY_NORMAL.equals(deviceEvent.state));
 
            final boolean batteryNotifyFullEnabled = devicePrefs.getBatteryNotifyFullEnabled(batteryConfig);
            final boolean isBatteryFull = deviceEvent.level >= devicePrefs.getBatteryNotifyFullThreshold(batteryConfig) &&
                    (BatteryState.BATTERY_CHARGING.equals(deviceEvent.state) || BatteryState.BATTERY_CHARGING_FULL.equals(deviceEvent.state));
 
            //show the notification if the battery level is below threshold and only if not connected to charger
            if (batteryNotifyLowEnabled && isBatteryLow) {
                GB.removeBatteryFullNotification(context);
                GB.updateBatteryLowNotification(context.getString(R.string.notif_battery_low_percent, gbDevice.getAliasOrName(), String.valueOf(deviceEvent.level)),
                        deviceEvent.extendedInfoAvailable() ?
                                context.getString(R.string.notif_battery_low_percent, gbDevice.getAliasOrName(), String.valueOf(deviceEvent.level)) + "\n" +
                                        context.getString(R.string.notif_battery_low_bigtext_last_charge_time, DateFormat.getDateTimeInstance().format(deviceEvent.lastChargeTime.getTime())) +
                                        context.getString(R.string.notif_battery_low_bigtext_number_of_charges, String.valueOf(deviceEvent.numCharges))
                                : ""
                        , context);
            } else if (batteryNotifyFullEnabled && isBatteryFull) {
                GB.removeBatteryLowNotification(context);
                GB.updateBatteryFullNotification(context.getString(R.string.notif_battery_full, gbDevice.getAliasOrName()), "", context);
            } else {
                GB.removeBatteryLowNotification(context);
                GB.removeBatteryFullNotification(context);
            }
        }
 
        gbDevice.sendDeviceUpdateIntent(context);
    }
 
    /**
     * Helper method to run specific actions configured in the device preferences, upon wear state
     * or awake/asleep events.
     *
     * @param actions
     * @param message
     */
    private void handleDeviceAction(Set<String> actions, String message) {
        if (actions.isEmpty()) {
            return;
        }
 
        LOG.debug("Handing device actions: {}", TextUtils.join(",", actions));
 
        final String actionBroadcast = getContext().getString(R.string.pref_device_action_broadcast_value);
        final String actionFitnessControlStart = getContext().getString(R.string.pref_device_action_fitness_app_control_start_value);
        final String actionFitnessControlStop = getContext().getString(R.string.pref_device_action_fitness_app_control_stop_value);
        final String actionFitnessControlToggle = getContext().getString(R.string.pref_device_action_fitness_app_control_toggle_value);
        final String actionMediaPlay = getContext().getString(R.string.pref_media_play_value);
        final String actionMediaPause = getContext().getString(R.string.pref_media_pause_value);
        final String actionMediaPlayPause = getContext().getString(R.string.pref_media_playpause_value);
        final String actionDndOff = getContext().getString(R.string.pref_device_action_dnd_off_value);
        final String actionDndpriority = getContext().getString(R.string.pref_device_action_dnd_priority_value);
        final String actionDndAlarms = getContext().getString(R.string.pref_device_action_dnd_alarms_value);
        final String actionDndOn = getContext().getString(R.string.pref_device_action_dnd_on_value);
 
        if (actions.contains(actionBroadcast)) {
            if (message != null) {
                Intent in = new Intent();
                in.setAction(message);
                LOG.info("Sending broadcast {}", message);
                getContext().getApplicationContext().sendBroadcast(in);
            }
        }
 
        if (actions.contains(actionFitnessControlStart)) {
            OpenTracksController.startRecording(getContext());
        } else if (actions.contains(actionFitnessControlStop)) {
            OpenTracksController.stopRecording(getContext());
        } else if (actions.contains(actionFitnessControlToggle)) {
            OpenTracksController.toggleRecording(getContext());
        }
 
        final String mediaAction;
        if (actions.contains(actionMediaPlayPause)) {
            mediaAction = actionMediaPlayPause;
        } else if (actions.contains(actionMediaPause)) {
            mediaAction = actionMediaPause;
        } else if (actions.contains(actionMediaPlay)) {
            mediaAction = actionMediaPlay;
        } else {
            mediaAction = null;
        }
 
        if (mediaAction != null) {
            GBDeviceEventMusicControl deviceEventMusicControl = new GBDeviceEventMusicControl();
            deviceEventMusicControl.event = GBDeviceEventMusicControl.Event.valueOf(mediaAction);
            evaluateGBDeviceEvent(deviceEventMusicControl);
        }
 
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            final NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
 
            final int interruptionFilter;
            if (actions.contains(actionDndOff)) {
                interruptionFilter = NotificationManager.INTERRUPTION_FILTER_ALL;
            } else if (actions.contains(actionDndpriority)) {
                interruptionFilter = NotificationManager.INTERRUPTION_FILTER_PRIORITY;
            } else if (actions.contains(actionDndAlarms)) {
                interruptionFilter = NotificationManager.INTERRUPTION_FILTER_ALARMS;
            } else if (actions.contains(actionDndOn)) {
                interruptionFilter = NotificationManager.INTERRUPTION_FILTER_NONE;
            } else {
                interruptionFilter = NotificationManager.INTERRUPTION_FILTER_UNKNOWN;
            }
 
            if (interruptionFilter != NotificationManager.INTERRUPTION_FILTER_UNKNOWN) {
                LOG.debug("Setting do not disturb to {}", interruptionFilter);
 
                if (!notificationManager.isNotificationPolicyAccessGranted()) {
                    LOG.warn("Do not disturb permissions not granted");
                }
 
                notificationManager.setInterruptionFilter(interruptionFilter);
            }
        }
    }
 
    private void handleGBDeviceEvent(GBDeviceEventSleepStateDetection event) {
        LOG.debug("Got SLEEP_STATE_DETECTION device event, detected sleep state = {}", event.sleepState);
 
        if (event.sleepState == SleepState.UNKNOWN) {
            return;
        }
 
        String actionPreferenceKey, messagePreferenceKey;
        int defaultBroadcastMessageResource;
 
        switch (event.sleepState) {
            case AWAKE:
                actionPreferenceKey = DeviceSettingsPreferenceConst.PREF_DEVICE_ACTION_WOKE_UP_SELECTIONS;
                messagePreferenceKey = DeviceSettingsPreferenceConst.PREF_DEVICE_ACTION_WOKE_UP_BROADCAST;
                defaultBroadcastMessageResource = R.string.prefs_events_forwarding_wokeup_broadcast_default_value;
                break;
            case ASLEEP:
                actionPreferenceKey = DeviceSettingsPreferenceConst.PREF_DEVICE_ACTION_FELL_SLEEP_SELECTIONS;
                messagePreferenceKey = DeviceSettingsPreferenceConst.PREF_DEVICE_ACTION_FELL_SLEEP_BROADCAST;
                defaultBroadcastMessageResource = R.string.prefs_events_forwarding_fellsleep_broadcast_default_value;
                break;
            default:
                LOG.warn("Unable to deduce action and broadcast message preference key for sleep state {}", event.sleepState);
                return;
        }
 
        Set<String> actions = getDevicePrefs().getStringSet(actionPreferenceKey, Collections.emptySet());
 
        if (actions.isEmpty()) {
            return;
        }
 
        String broadcastMessage = getDevicePrefs().getString(messagePreferenceKey, context.getString(defaultBroadcastMessageResource));
        handleDeviceAction(actions, broadcastMessage);
    }
 
    private void handleGBDeviceEvent(GBDeviceEventWearState event) {
        LOG.debug("Got WEAR_STATE device event, wearingState = {}", event.wearingState);
 
        if (event.wearingState == WearingState.UNKNOWN) {
            LOG.warn("WEAR_STATE state is UNKNOWN, aborting further evaluation");
            return;
        }
 
        if (event.wearingState != WearingState.NOT_WEARING) {
            LOG.debug("WEAR_STATE state is not NOT_WEARING, aborting further evaluation");
        }
 
        Set<String> actionOnUnwear = getDevicePrefs().getStringSet(
                DeviceSettingsPreferenceConst.PREF_DEVICE_ACTION_START_NON_WEAR_SELECTIONS,
                Collections.emptySet()
        );
 
        // check if an action is set
        if (actionOnUnwear.isEmpty()) {
            return;
        }
 
        String broadcastMessage = getDevicePrefs().getString(
                DeviceSettingsPreferenceConst.PREF_DEVICE_ACTION_START_NON_WEAR_BROADCAST,
                getContext().getString(R.string.prefs_events_forwarding_startnonwear_broadcast_default_value)
        );
 
        handleDeviceAction(actionOnUnwear, broadcastMessage);
    }
 
    private void handleGBDeviceEvent(GBDeviceMusicData deviceEvent) {
        Context context = getContext();
        LOG.info("Got event for ACTION_MUSIC_DATA");
 
        Intent intent = new Intent(MusicManagerActivity.ACTION_MUSIC_DATA);
 
        intent.putExtra("type", deviceEvent.type);
 
        if(deviceEvent.list != null) {
            ArrayList<GBDeviceMusic> list = new ArrayList<>(deviceEvent.list);
            intent.putExtra("musicList", list);
        }
 
        if(deviceEvent.playlists != null) {
            ArrayList<GBDeviceMusicPlaylist> list = new ArrayList<>(deviceEvent.playlists);
            intent.putExtra("musicPlaylist", list);
        }
 
        if(!TextUtils.isEmpty(deviceEvent.deviceInfo)) {
            intent.putExtra("deviceInfo", deviceEvent.deviceInfo);
        }
 
        if(deviceEvent.maxMusicCount > 0) {
            intent.putExtra("maxMusicCount", deviceEvent.maxMusicCount);
        }
        if(deviceEvent.maxPlaylistCount > 0) {
            intent.putExtra("maxPlaylistCount", deviceEvent.maxPlaylistCount);
        }
 
        LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
    }
 
    private void handleGBDeviceEvent(GBDeviceMusicUpdate deviceEvent) {
        Context context = getContext();
        LOG.info("Got event for ACTION_MUSIC_UPDATE");
 
        Intent intent = new Intent(MusicManagerActivity.ACTION_MUSIC_UPDATE);
 
        intent.putExtra("success", deviceEvent.success);
        intent.putExtra("operation", deviceEvent.operation);
        intent.putExtra("playlistIndex", deviceEvent.playlistIndex);
        intent.putExtra("playlistName", deviceEvent.playlistName);
        intent.putExtra("musicIds", deviceEvent.musicIds);
 
        LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
    }
 
    private StoreDataTask createStoreTask(String task, Context context, GBDeviceEventBatteryInfo deviceEvent) {
        return new StoreDataTask(task, context, deviceEvent);
    }
 
    public class StoreDataTask extends DBAccess {
        GBDeviceEventBatteryInfo deviceEvent;
 
        public StoreDataTask(String task, Context context, GBDeviceEventBatteryInfo deviceEvent) {
            super(task, context);
            this.deviceEvent = deviceEvent;
        }
 
        @Override
        protected void doInBackground(DBHandler handler) {
            DaoSession daoSession = handler.getDaoSession();
            Device device = DBHelper.getDevice(gbDevice, daoSession);
            int ts = (int) (System.currentTimeMillis() / 1000);
            BatteryLevel batteryLevel = new BatteryLevel();
            batteryLevel.setTimestamp(ts);
            batteryLevel.setBatteryIndex(deviceEvent.batteryIndex);
            batteryLevel.setDevice(device);
            batteryLevel.setLevel(deviceEvent.level);
            handler.getDaoSession().getBatteryLevelDao().insert(batteryLevel);
        }
    }
 
    public void handleGBDeviceEvent(GBDeviceEventDisplayMessage message) {
        GB.log(message.message, message.severity, null);
 
        Intent messageIntent = new Intent(GB.ACTION_DISPLAY_MESSAGE);
        messageIntent.putExtra(GB.DISPLAY_MESSAGE_MESSAGE, message.message);
        messageIntent.putExtra(GB.DISPLAY_MESSAGE_DURATION, message.duration);
        messageIntent.putExtra(GB.DISPLAY_MESSAGE_SEVERITY, message.severity);
 
        LocalBroadcastManager.getInstance(context).sendBroadcast(messageIntent);
    }
 
    public DevicePrefs getDevicePrefs() {
        return GBApplication.getDevicePrefs(gbDevice);
    }
 
    @Override
    public String customStringFilter(String inputString) {
        return inputString;
    }
 
 
    // Empty functions following, leaving optional implementation up to child classes
 
    /**
     * If the device supports a "find phone" functionality, this method can
     * be overridden and implemented by the device support class.
     * @param start true if starting the search, false if stopping
     */
    @Override
    public void onFindPhone(boolean start) {
 
    }
 
    /**
     * If the device supports a "find device" functionality, this method can
     * be overridden and implemented by the device support class.
     * @param start true if starting the search, false if stopping
     */
    @Override
    public void onFindDevice(boolean start) {
 
    }
 
    /**
     * If the device supports a "set FM frequency" functionality, this method
     * can be overridden and implemented by the device support class.
     * @param frequency the FM frequency to set
     */
    @Override
    public void onSetFmFrequency(float frequency) {
 
    }
 
    /**
     * If the device supports a "set LED color" functionality, this method
     * can be overridden and implemented by the device support class.
     * @param color the new color, in ARGB, with alpha = 255
     */
    @Override
    public void onSetLedColor(int color) {
 
    }
 
    /**
     * If the device can be turned off by sending a command, this method
     * can be overridden and implemented by the device support class.
     */
    @Override
    public void onPowerOff() {
 
    }
 
    /**
     * If the device has a functionality to set the phone volume, this method
     * can be overridden and implemented by the device support class.
     * @param volume the volume percentage (0 to 100).
     */
    @Override
    public void onSetPhoneVolume(final float volume) {
 
    }
 
    /**
     * Called when the phone's interruption filter or ringer mode is changed.
     * @param ringerMode as per {@link android.media.AudioManager#getRingerMode()}
     */
    @Override
    public void onChangePhoneSilentMode(int ringerMode) {
 
    }
 
    /**
     * If the device can receive the GPS location from the phone, this method
     * can be overridden and implemented by the device support class.
     * @param location {@link android.location.Location} object containing the current GPS coordinates
     */
    @Override
    public void onSetGpsLocation(Location location) {
 
    }
 
    /**
     * If reminders can be set on the device, this method can be
     * overridden and implemented by the device support class.
     * @param reminders {@link java.util.ArrayList} containing {@link nodomain.freeyourgadget.gadgetbridge.model.Reminder} instances
     */
    @Override
    public void onSetReminders(ArrayList<? extends Reminder> reminders) {
 
    }
 
    /**
     * If loyalty cards can be set on the device, this method can be
     * overridden and implemented by the device support class.
     * @param cards {@link java.util.ArrayList} containing {@link LoyaltyCard} instances
     */
    @Override
    public void onSetLoyaltyCards(ArrayList<LoyaltyCard> cards) {
 
    }
 
    /**
     * If world clocks can be configured on the device, this method can be
     * overridden and implemented by the device support class.
     * @param clocks {@link java.util.ArrayList} containing {@link nodomain.freeyourgadget.gadgetbridge.model.WorldClock} instances
     */
    @Override
    public void onSetWorldClocks(ArrayList<? extends WorldClock> clocks) {
 
    }
 
    /**
     * If contacts can be configured on the device, this method can be
     * overridden and implemented by the device support class.
     * @param contacts {@link java.util.ArrayList} containing {@link nodomain.freeyourgadget.gadgetbridge.model.Contact} instances
     */
    @Override
    public void onSetContacts(ArrayList<? extends Contact> contacts) {
 
    }
 
    /**
     * If the device can receive and display notifications, this method
     * can be overridden and implemented by the device support class.
     * @param notificationSpec notification details
     */
    @Override
    public void onNotification(NotificationSpec notificationSpec) {
 
    }
 
    /**
     * If notifications can be deleted from the device, this method can be
     * overridden and implemented by the device support class.
     * @param id the unique notification identifier
     */
    @Override
    public void onDeleteNotification(int id) {
 
    }
 
    /**
     * If the time can be set on the device, this method can be
     * overridden and implemented by the device support class.
     */
    @Override
    public void onSetTime() {
 
    }
 
    /**
     * If alarms can be set on the device, this method can be
     * overridden and implemented by the device support class.
     * @param alarms {@link java.util.ArrayList} containing {@link nodomain.freeyourgadget.gadgetbridge.model.Alarm} instances
     */
    @Override
    public void onSetAlarms(ArrayList<? extends Alarm> alarms) {
 
    }
 
    /**
     * If the device can receive and show or handle phone call details, this
     * method can be overridden and implemented by the device support class.
     * @param callSpec the call state details
     */
    @Override
    public void onSetCallState(CallSpec callSpec) {
 
    }
 
    /**
     * If the device has a "canned messages" functionality, this method
     * can be overridden and implemented by the device support class.
     * @param cannedMessagesSpec the canned messages to send to the device
     */
    @Override
    public void onSetCannedMessages(CannedMessagesSpec cannedMessagesSpec) {
 
    }
 
    /**
     * If the music play state can be set on the device, this method
     * can be overridden and implemented by the device support class.
     * @param stateSpec the current state of music playback
     */
    @Override
    public void onSetMusicState(MusicStateSpec stateSpec) {
 
    }
 
    /**
     * If the music information can be shown on the device, this method can be
     * overridden and implemented by the device support class.
     * @param musicSpec the current music information, like track name and artist
     */
    @Override
    public void onSetMusicInfo(MusicSpec musicSpec) {
 
    }
 
    /**
     * If apps can be installed on the device, this method can be
     * overridden and implemented by the device support class.
     * @param uri reference to a watch app file
     */
    @Override
    public void onInstallApp(Uri uri) {
 
    }
 
    /**
     * If the list of apps on the device can be retrieved, this method
     * can be overridden and implemented by the device support class.
     */
    @Override
    public void onAppInfoReq() {
 
    }
 
    /**
     * If the device supports starting an app with a command, this method
     * can be overridden and implemented by the device support class.
     * @param uuid the Gadgetbridge internal UUID of the app
     * @param start true to start, false to stop the app (if supported)
     */
    @Override
    public void onAppStart(UUID uuid, boolean start) {
 
    }
 
    /**
     * If apps can be downloaded from the device, this method can be
     * overridden and implemented by the device support class.
     * @param uuid the Gadgetbridge internal UUID of the app
     */
    @Override
    public void onAppDownload(UUID uuid) {
 
    }
 
    /**
     * If apps on the device can be deleted with a command, this method
     * can be overridden and implemented by the device support class.
     * @param uuid the Gadgetbridge internal UUID of the app
     */
    @Override
    public void onAppDelete(UUID uuid) {
 
    }
 
    /**
     * If apps on the device can be configured, this method can be
     * overridden and implemented by the device support class.
     * @param appUuid the Gadgetbridge internal UUID of the app
     * @param config the configuration of the app
     * @param id
     */
    @Override
    public void onAppConfiguration(UUID appUuid, String config, Integer id) {
 
    }
 
    /**
     * If apps on the device can be reordered, this method can be
     * overridden and implemented by the device support class.
     * @param uuids array of Gadgetbridge internal UUIDs of the apps
     */
    @Override
    public void onAppReorder(UUID[] uuids) {
 
    }
 
    /**
     * If recorded data can be fetched from the device, this method
     * can be overridden and implemented by the device support class.
     * @param dataTypes which data types to fetch
     */
    @Override
    public void onFetchRecordedData(int dataTypes) {
 
    }
 
    /**
     * If a device can be reset with a command, this method can be
     * overridden and implemented by the device support class.
     * @param flags can be used to pass flags with the reset command
     */
    @Override
    public void onReset(int flags) {
 
    }
 
    /**
     * If the device can perform a heart rate measurement on request, this
     * method can be overridden and implemented by the device support class.
     */
    @Override
    public void onHeartRateTest() {
 
    }
 
    /**
     * If the device has the functionality to enable/disable realtime heart rate measurement,
     * this method can be overridden and implemented by the device support class.
     * @param enable true to enable, false to disable realtime heart rate measurement
     */
    @Override
    public void onEnableRealtimeHeartRateMeasurement(boolean enable) {
 
    }
 
    /**
     * If the device has the functionality to enable/disable realtime steps information,
     * this method can be overridden and implemented by the device support class.
     * @param enable true to enable, false to disable realtime steps
     */
    @Override
    public void onEnableRealtimeSteps(boolean enable) {
 
    }
 
    /**
     * If the device has a functionality to enable constant vibration, this
     * method can be overridden and implemented by the device support class.
     * @param integer the vibration intensity
     */
    @Override
    public void onSetConstantVibration(int integer) {
 
    }
 
    /**
     * If the device supports taking screenshots of the screen, this method can
     * be overridden and implemented by the device support class.
     */
    @Override
    public void onScreenshotReq() {
 
    }
 
    /**
     * If the device has a toggle to enable the use of heart rate for sleep detection,
     * this method can be overridden and implemented by the device support class.
     * @param enable true to enable, false to disable using heart rate for sleep detection
     */
    @Override
    public void onEnableHeartRateSleepSupport(boolean enable) {
 
    }
 
    /**
     * If the heart rate measurement interval can be changed on the device,
     * this method can be overridden and implemented by the device support class.
     * @param seconds the interval to configure on the device
     */
    @Override
    public void onSetHeartRateMeasurementInterval(int seconds) {
 
    }
 
    /**
     * If calendar events can be sent to the device, this method can be
     * overridden and implemented by the device support class.
     * @param calendarEventSpec calendar event details
     */
    @Override
    public void onAddCalendarEvent(CalendarEventSpec calendarEventSpec) {
 
    }
 
    /**
     * If calendar events can be deleted from the device, this method can
     * be overridden and implemented by the device support class.
     * @param type type of calendar event
     * @param id id of calendar event
     */
    @Override
    public void onDeleteCalendarEvent(byte type, long id) {
 
    }
 
    /**
     * If configuration options can be set on the device, this method
     * can be overridden and implemented by the device support class.
     * @param config the device specific option to set on the device
     */
    @Override
    public void onSendConfiguration(String config) {
 
    }
 
    /**
     * If the configuration can be retrieved from the device, this method
     * can be overridden and implemented by the device support class.
     * @param config the device specific option to get from the device
     */
    @Override
    public void onReadConfiguration(String config) {
 
    }
 
    /**
     * If the device can receive weather information, this method can be
     * overridden and implemented by the device support class. It's guaranteed
     * that there is always at least one weatherSpec, with the first being the
     * primary weather (not necessarily current location).
     * @param weatherSpecs weather information
     */
    @Override
    public void onSendWeather(ArrayList<WeatherSpec> weatherSpecs) {
 
    }
 
    /**
     * For testing new features, this method can be overridden and
     * implemented by the device support class.
     * It's called by clicking the "test new functionality" button
     * in the Debug menu.
     */
    @Override
    public void onTestNewFunction() {
 
    }
 
    @Override
    public void onSetNavigationInfo(NavigationInfoSpec navigationInfoSpec) {
 
    }
 
    @Override
    public void onSleepAsAndroidAction(String action, Bundle extras) {
 
    }
 
    @Override
    public void onCameraStatusChange(GBDeviceEventCameraRemote.Event event, String filename) {}
 
    @Override
    public void onMusicListReq() {}
 
    @Override
    public void onMusicOperation(int operation, int playlistIndex, String playlistName, ArrayList<Integer> musicIds) {}
}