From a190879fb215f71b9026bd3d5c03da7bf2619f50 Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 13:15:34 -0500 Subject: [PATCH 01/42] Remove redundant target API notices We have long past those versions. --- app/src/main/java/org/asteroidos/sync/services/NLService.java | 1 - .../java/org/asteroidos/sync/utils/NotificationParser.java | 3 --- 2 files changed, 4 deletions(-) diff --git a/app/src/main/java/org/asteroidos/sync/services/NLService.java b/app/src/main/java/org/asteroidos/sync/services/NLService.java index 73bb5c9e..a7b933ed 100644 --- a/app/src/main/java/org/asteroidos/sync/services/NLService.java +++ b/app/src/main/java/org/asteroidos/sync/services/NLService.java @@ -208,7 +208,6 @@ public void onNotificationRemoved(StatusBarNotification sbn) { } @Override - @TargetApi(Build.VERSION_CODES.N) public void onListenerDisconnected() { listenerConnected = false; // Notification listener disconnected - requesting rebind diff --git a/app/src/main/java/org/asteroidos/sync/utils/NotificationParser.java b/app/src/main/java/org/asteroidos/sync/utils/NotificationParser.java index 99e55e16..aaa734e1 100644 --- a/app/src/main/java/org/asteroidos/sync/utils/NotificationParser.java +++ b/app/src/main/java/org/asteroidos/sync/utils/NotificationParser.java @@ -35,7 +35,6 @@ public NotificationParser(Notification notification) getExtraBigData(notification); } - @TargetApi(value = Build.VERSION_CODES.JELLY_BEAN) private boolean tryParseNatively(Notification notification) { Bundle extras = notification.extras; @@ -130,7 +129,6 @@ public int compare(NotificationCompat.MessagingStyle.Message m1, NotificationCom return true; } - @TargetApi(value = Build.VERSION_CODES.JELLY_BEAN) private boolean parseInboxNotification(Bundle extras) { CharSequence summaryTextSequence = extras.getCharSequence(Notification.EXTRA_SUMMARY_TEXT); @@ -214,7 +212,6 @@ private void getExtraData(Notification notification) { parseRemoteView(views); } - @TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void getExtraBigData(Notification notification) { RemoteViews views; try { From 46c7680efd95e354cb703d935931d2e8c6f945d9 Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 13:19:23 -0500 Subject: [PATCH 02/42] Inline old sdk checks --- .../asteroidos/sync/PermissionsActivity.java | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/org/asteroidos/sync/PermissionsActivity.java b/app/src/main/java/org/asteroidos/sync/PermissionsActivity.java index 9c4ae711..ba60c967 100644 --- a/app/src/main/java/org/asteroidos/sync/PermissionsActivity.java +++ b/app/src/main/java/org/asteroidos/sync/PermissionsActivity.java @@ -227,13 +227,10 @@ public void setContext(Context ctx) { @Override public boolean hasAnyPermissionsToGrant() { - if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - String packageName = mCtx.getPackageName(); - PowerManager pm = (PowerManager) mCtx.getSystemService(POWER_SERVICE); - return (pm != null && !pm.isIgnoringBatteryOptimizations(packageName)); - } + String packageName = mCtx.getPackageName(); + PowerManager pm = (PowerManager) mCtx.getSystemService(POWER_SERVICE); + return (pm != null && !pm.isIgnoringBatteryOptimizations(packageName)); - return false; } // Ignore violation of play store content since @@ -241,15 +238,12 @@ public boolean hasAnyPermissionsToGrant() { @SuppressLint("BatteryLife") @Override public void askForPermissions() { - if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - Intent intent = new Intent(); - String packageName = mCtx.getPackageName(); - PowerManager pm = (PowerManager) mCtx.getSystemService(POWER_SERVICE); - intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); - intent.setData(Uri.parse("package:" + packageName)); - getActivity().startActivityForResult(intent, BATTERYOPTIM_REQUEST); - - } + Intent intent = new Intent(); + String packageName = mCtx.getPackageName(); + PowerManager pm = (PowerManager) mCtx.getSystemService(POWER_SERVICE); + intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); + intent.setData(Uri.parse("package:" + packageName)); + getActivity().startActivityForResult(intent, BATTERYOPTIM_REQUEST); } @Override From afd054a272353586aa41091c75ae8e67a6717311 Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 14:10:03 -0500 Subject: [PATCH 03/42] Update copyright There are dubious copyright due to using MIT licensed code. If we rewrite the code it should be fine. --- .idea/copyright/GPLv3.xml | 6 ++++++ .idea/copyright/profiles_settings.xml | 7 +++++++ AUTHORS | 4 ++++ .../org/asteroidos/sync/MainActivity.java | 18 ++++++++++++++++++ .../sync/NotificationPreferences.java | 18 ++++++++++++++++++ .../asteroidos/sync/PermissionsActivity.java | 18 ++++++++++++++++++ .../sync/adapters/AppInfoAdapter.java | 1 + .../sync/asteroid/AsteroidBleManager.java | 18 ++++++++++++++++++ .../sync/asteroid/IAsteroidDevice.java | 18 ++++++++++++++++++ .../connectivity/IConnectivityService.java | 18 ++++++++++++++++++ .../sync/connectivity/IService.java | 18 ++++++++++++++++++ .../sync/connectivity/IServiceCallback.java | 18 ++++++++++++++++++ .../sync/connectivity/MediaService.java | 3 ++- .../connectivity/NotificationService.java | 3 ++- .../sync/connectivity/ScreenshotService.java | 3 ++- .../sync/connectivity/SilentModeService.java | 3 ++- .../sync/connectivity/TimeService.java | 3 ++- .../sync/connectivity/WeatherService.java | 3 ++- .../sync/dataobjects/Notification.java | 18 ++++++++++++++++++ .../sync/fragments/AppListFragment.java | 18 ++++++++++++++++++ .../sync/fragments/DeviceDetailFragment.java | 4 ++-- .../sync/fragments/DeviceListFragment.java | 4 ++-- .../fragments/WeatherSettingsFragment.java | 18 ++++++++++++++++++ .../sync/services/AutostartService.java | 18 ++++++++++++++++++ .../asteroidos/sync/services/GPSTracker.java | 18 ++++++++++++++++++ .../sync/services/GenericFileProvider.java | 18 ++++++++++++++++++ .../asteroidos/sync/services/NLService.java | 3 ++- .../sync/services/PhoneStateReceiver.java | 18 ++++++++++++++++++ .../sync/services/SynchronizationService.java | 3 ++- .../org/asteroidos/sync/utils/AppInfo.java | 1 + .../asteroidos/sync/utils/AppInfoHelper.java | 19 +++++++++++++++++++ .../asteroidos/sync/utils/AsteroidUUIDS.java | 18 ++++++++++++++++++ .../sync/utils/NotificationParser.java | 18 ++++++++++++++++++ 33 files changed, 364 insertions(+), 12 deletions(-) create mode 100644 .idea/copyright/GPLv3.xml create mode 100644 .idea/copyright/profiles_settings.xml create mode 100644 AUTHORS diff --git a/.idea/copyright/GPLv3.xml b/.idea/copyright/GPLv3.xml new file mode 100644 index 00000000..bb6cb37e --- /dev/null +++ b/.idea/copyright/GPLv3.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 00000000..3b363ccf --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 00000000..86a0dbfb --- /dev/null +++ b/AUTHORS @@ -0,0 +1,4 @@ +Florent Revest revestflo@gmail.com +Doug Koellmer dougkoellmer@hotmail.com +Justus Tartz git@jrtberlin.de +Doomsdayrs doomsdayrs@gmail.com \ No newline at end of file diff --git a/app/src/main/java/org/asteroidos/sync/MainActivity.java b/app/src/main/java/org/asteroidos/sync/MainActivity.java index 84487647..3b5b387c 100644 --- a/app/src/main/java/org/asteroidos/sync/MainActivity.java +++ b/app/src/main/java/org/asteroidos/sync/MainActivity.java @@ -1,3 +1,21 @@ +/* + * AsteroidOSSync + * Copyright (c) 2023 AsteroidOS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package org.asteroidos.sync; import android.Manifest; diff --git a/app/src/main/java/org/asteroidos/sync/NotificationPreferences.java b/app/src/main/java/org/asteroidos/sync/NotificationPreferences.java index 5112801a..cf8aba0c 100644 --- a/app/src/main/java/org/asteroidos/sync/NotificationPreferences.java +++ b/app/src/main/java/org/asteroidos/sync/NotificationPreferences.java @@ -1,3 +1,21 @@ +/* + * AsteroidOSSync + * Copyright (c) 2023 AsteroidOS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package org.asteroidos.sync; import android.content.Context; diff --git a/app/src/main/java/org/asteroidos/sync/PermissionsActivity.java b/app/src/main/java/org/asteroidos/sync/PermissionsActivity.java index ba60c967..02960392 100644 --- a/app/src/main/java/org/asteroidos/sync/PermissionsActivity.java +++ b/app/src/main/java/org/asteroidos/sync/PermissionsActivity.java @@ -1,3 +1,21 @@ +/* + * AsteroidOSSync + * Copyright (c) 2023 AsteroidOS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package org.asteroidos.sync; import android.Manifest; diff --git a/app/src/main/java/org/asteroidos/sync/adapters/AppInfoAdapter.java b/app/src/main/java/org/asteroidos/sync/adapters/AppInfoAdapter.java index 16cf096a..ec549a4f 100644 --- a/app/src/main/java/org/asteroidos/sync/adapters/AppInfoAdapter.java +++ b/app/src/main/java/org/asteroidos/sync/adapters/AppInfoAdapter.java @@ -1,5 +1,6 @@ package org.asteroidos.sync.adapters; +// TODO Handle dubious copyright // copied from https://github.com/jensstein/oandbackup, used under MIT license import android.content.Context; diff --git a/app/src/main/java/org/asteroidos/sync/asteroid/AsteroidBleManager.java b/app/src/main/java/org/asteroidos/sync/asteroid/AsteroidBleManager.java index 1ac0a8c2..91ebd9e6 100644 --- a/app/src/main/java/org/asteroidos/sync/asteroid/AsteroidBleManager.java +++ b/app/src/main/java/org/asteroidos/sync/asteroid/AsteroidBleManager.java @@ -1,3 +1,21 @@ +/* + * AsteroidOSSync + * Copyright (c) 2023 AsteroidOS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package org.asteroidos.sync.asteroid; import android.Manifest; diff --git a/app/src/main/java/org/asteroidos/sync/asteroid/IAsteroidDevice.java b/app/src/main/java/org/asteroidos/sync/asteroid/IAsteroidDevice.java index 8645fcc2..3fe92ccf 100644 --- a/app/src/main/java/org/asteroidos/sync/asteroid/IAsteroidDevice.java +++ b/app/src/main/java/org/asteroidos/sync/asteroid/IAsteroidDevice.java @@ -1,3 +1,21 @@ +/* + * AsteroidOSSync + * Copyright (c) 2023 AsteroidOS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package org.asteroidos.sync.asteroid; import org.asteroidos.sync.connectivity.IConnectivityService; diff --git a/app/src/main/java/org/asteroidos/sync/connectivity/IConnectivityService.java b/app/src/main/java/org/asteroidos/sync/connectivity/IConnectivityService.java index 9b04436d..728b43d5 100644 --- a/app/src/main/java/org/asteroidos/sync/connectivity/IConnectivityService.java +++ b/app/src/main/java/org/asteroidos/sync/connectivity/IConnectivityService.java @@ -1,3 +1,21 @@ +/* + * AsteroidOSSync + * Copyright (c) 2023 AsteroidOS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package org.asteroidos.sync.connectivity; import java.util.HashMap; diff --git a/app/src/main/java/org/asteroidos/sync/connectivity/IService.java b/app/src/main/java/org/asteroidos/sync/connectivity/IService.java index ab989555..fcb5c1d6 100644 --- a/app/src/main/java/org/asteroidos/sync/connectivity/IService.java +++ b/app/src/main/java/org/asteroidos/sync/connectivity/IService.java @@ -1,3 +1,21 @@ +/* + * AsteroidOSSync + * Copyright (c) 2023 AsteroidOS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package org.asteroidos.sync.connectivity; /** diff --git a/app/src/main/java/org/asteroidos/sync/connectivity/IServiceCallback.java b/app/src/main/java/org/asteroidos/sync/connectivity/IServiceCallback.java index 7bd698ce..7d76ec4c 100644 --- a/app/src/main/java/org/asteroidos/sync/connectivity/IServiceCallback.java +++ b/app/src/main/java/org/asteroidos/sync/connectivity/IServiceCallback.java @@ -1,3 +1,21 @@ +/* + * AsteroidOSSync + * Copyright (c) 2023 AsteroidOS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package org.asteroidos.sync.connectivity; public interface IServiceCallback { diff --git a/app/src/main/java/org/asteroidos/sync/connectivity/MediaService.java b/app/src/main/java/org/asteroidos/sync/connectivity/MediaService.java index 787784b7..c50dab0b 100644 --- a/app/src/main/java/org/asteroidos/sync/connectivity/MediaService.java +++ b/app/src/main/java/org/asteroidos/sync/connectivity/MediaService.java @@ -1,5 +1,6 @@ /* - * Copyright (C) 2016 - Florent Revest + * AsteroidOSSync + * Copyright (c) 2023 AsteroidOS * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/app/src/main/java/org/asteroidos/sync/connectivity/NotificationService.java b/app/src/main/java/org/asteroidos/sync/connectivity/NotificationService.java index 18013759..368601e0 100644 --- a/app/src/main/java/org/asteroidos/sync/connectivity/NotificationService.java +++ b/app/src/main/java/org/asteroidos/sync/connectivity/NotificationService.java @@ -1,5 +1,6 @@ /* - * Copyright (C) 2016 - Florent Revest + * AsteroidOSSync + * Copyright (c) 2023 AsteroidOS * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/app/src/main/java/org/asteroidos/sync/connectivity/ScreenshotService.java b/app/src/main/java/org/asteroidos/sync/connectivity/ScreenshotService.java index 90e2d3ac..4a5f1495 100644 --- a/app/src/main/java/org/asteroidos/sync/connectivity/ScreenshotService.java +++ b/app/src/main/java/org/asteroidos/sync/connectivity/ScreenshotService.java @@ -1,5 +1,6 @@ /* - * Copyright (C) 2016 - Florent Revest + * AsteroidOSSync + * Copyright (c) 2023 AsteroidOS * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/app/src/main/java/org/asteroidos/sync/connectivity/SilentModeService.java b/app/src/main/java/org/asteroidos/sync/connectivity/SilentModeService.java index 4ba93ad9..8415dec8 100644 --- a/app/src/main/java/org/asteroidos/sync/connectivity/SilentModeService.java +++ b/app/src/main/java/org/asteroidos/sync/connectivity/SilentModeService.java @@ -1,5 +1,6 @@ /* - * Copyright (C) 2019 - Justus Tartz + * AsteroidOSSync + * Copyright (c) 2023 AsteroidOS * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/app/src/main/java/org/asteroidos/sync/connectivity/TimeService.java b/app/src/main/java/org/asteroidos/sync/connectivity/TimeService.java index 8254f800..7374cebd 100644 --- a/app/src/main/java/org/asteroidos/sync/connectivity/TimeService.java +++ b/app/src/main/java/org/asteroidos/sync/connectivity/TimeService.java @@ -1,5 +1,6 @@ /* - * Copyright (C) 2016 - Florent Revest + * AsteroidOSSync + * Copyright (c) 2023 AsteroidOS * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/app/src/main/java/org/asteroidos/sync/connectivity/WeatherService.java b/app/src/main/java/org/asteroidos/sync/connectivity/WeatherService.java index 115ffc92..7741489b 100644 --- a/app/src/main/java/org/asteroidos/sync/connectivity/WeatherService.java +++ b/app/src/main/java/org/asteroidos/sync/connectivity/WeatherService.java @@ -1,5 +1,6 @@ /* - * Copyright (C) 2016 - Florent Revest + * AsteroidOSSync + * Copyright (c) 2023 AsteroidOS * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/app/src/main/java/org/asteroidos/sync/dataobjects/Notification.java b/app/src/main/java/org/asteroidos/sync/dataobjects/Notification.java index 8dec8636..21263e08 100644 --- a/app/src/main/java/org/asteroidos/sync/dataobjects/Notification.java +++ b/app/src/main/java/org/asteroidos/sync/dataobjects/Notification.java @@ -1,3 +1,21 @@ +/* + * AsteroidOSSync + * Copyright (c) 2023 AsteroidOS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package org.asteroidos.sync.dataobjects; import java.nio.charset.StandardCharsets; diff --git a/app/src/main/java/org/asteroidos/sync/fragments/AppListFragment.java b/app/src/main/java/org/asteroidos/sync/fragments/AppListFragment.java index f5356f6f..2cd197f1 100644 --- a/app/src/main/java/org/asteroidos/sync/fragments/AppListFragment.java +++ b/app/src/main/java/org/asteroidos/sync/fragments/AppListFragment.java @@ -1,3 +1,21 @@ +/* + * AsteroidOSSync + * Copyright (c) 2023 AsteroidOS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package org.asteroidos.sync.fragments; import android.content.Context; diff --git a/app/src/main/java/org/asteroidos/sync/fragments/DeviceDetailFragment.java b/app/src/main/java/org/asteroidos/sync/fragments/DeviceDetailFragment.java index 7894a7f9..18dd628e 100644 --- a/app/src/main/java/org/asteroidos/sync/fragments/DeviceDetailFragment.java +++ b/app/src/main/java/org/asteroidos/sync/fragments/DeviceDetailFragment.java @@ -1,6 +1,6 @@ /* - * Copyright (C) 2016 - Florent Revest - * Doug Koellmer + * AsteroidOSSync + * Copyright (c) 2023 AsteroidOS * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/app/src/main/java/org/asteroidos/sync/fragments/DeviceListFragment.java b/app/src/main/java/org/asteroidos/sync/fragments/DeviceListFragment.java index 8d03ae3b..edb78596 100644 --- a/app/src/main/java/org/asteroidos/sync/fragments/DeviceListFragment.java +++ b/app/src/main/java/org/asteroidos/sync/fragments/DeviceListFragment.java @@ -1,6 +1,6 @@ /* - * Copyright (C) 2016 - Florent Revest - * Doug Koellmer + * AsteroidOSSync + * Copyright (c) 2023 AsteroidOS * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/app/src/main/java/org/asteroidos/sync/fragments/WeatherSettingsFragment.java b/app/src/main/java/org/asteroidos/sync/fragments/WeatherSettingsFragment.java index fb0fc387..9eb0745f 100644 --- a/app/src/main/java/org/asteroidos/sync/fragments/WeatherSettingsFragment.java +++ b/app/src/main/java/org/asteroidos/sync/fragments/WeatherSettingsFragment.java @@ -1,3 +1,21 @@ +/* + * AsteroidOSSync + * Copyright (c) 2023 AsteroidOS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package org.asteroidos.sync.fragments; import android.Manifest; diff --git a/app/src/main/java/org/asteroidos/sync/services/AutostartService.java b/app/src/main/java/org/asteroidos/sync/services/AutostartService.java index 51696df4..1f2aafbf 100644 --- a/app/src/main/java/org/asteroidos/sync/services/AutostartService.java +++ b/app/src/main/java/org/asteroidos/sync/services/AutostartService.java @@ -1,3 +1,21 @@ +/* + * AsteroidOSSync + * Copyright (c) 2023 AsteroidOS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package org.asteroidos.sync.services; import android.content.BroadcastReceiver; diff --git a/app/src/main/java/org/asteroidos/sync/services/GPSTracker.java b/app/src/main/java/org/asteroidos/sync/services/GPSTracker.java index b704c7d9..87c94ba5 100644 --- a/app/src/main/java/org/asteroidos/sync/services/GPSTracker.java +++ b/app/src/main/java/org/asteroidos/sync/services/GPSTracker.java @@ -1,3 +1,21 @@ +/* + * AsteroidOSSync + * Copyright (c) 2023 AsteroidOS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package org.asteroidos.sync.services; import android.app.Service; diff --git a/app/src/main/java/org/asteroidos/sync/services/GenericFileProvider.java b/app/src/main/java/org/asteroidos/sync/services/GenericFileProvider.java index 6296f2ee..0a04db07 100644 --- a/app/src/main/java/org/asteroidos/sync/services/GenericFileProvider.java +++ b/app/src/main/java/org/asteroidos/sync/services/GenericFileProvider.java @@ -1,3 +1,21 @@ +/* + * AsteroidOSSync + * Copyright (c) 2023 AsteroidOS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package org.asteroidos.sync.services; import androidx.core.content.FileProvider; diff --git a/app/src/main/java/org/asteroidos/sync/services/NLService.java b/app/src/main/java/org/asteroidos/sync/services/NLService.java index a7b933ed..addbfe66 100644 --- a/app/src/main/java/org/asteroidos/sync/services/NLService.java +++ b/app/src/main/java/org/asteroidos/sync/services/NLService.java @@ -1,5 +1,6 @@ /* - * Copyright (C) 2016 - Florent Revest + * AsteroidOSSync + * Copyright (c) 2023 AsteroidOS * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/app/src/main/java/org/asteroidos/sync/services/PhoneStateReceiver.java b/app/src/main/java/org/asteroidos/sync/services/PhoneStateReceiver.java index 1edbee17..3e8efc2b 100644 --- a/app/src/main/java/org/asteroidos/sync/services/PhoneStateReceiver.java +++ b/app/src/main/java/org/asteroidos/sync/services/PhoneStateReceiver.java @@ -1,3 +1,21 @@ +/* + * AsteroidOSSync + * Copyright (c) 2023 AsteroidOS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package org.asteroidos.sync.services; import android.app.Activity; diff --git a/app/src/main/java/org/asteroidos/sync/services/SynchronizationService.java b/app/src/main/java/org/asteroidos/sync/services/SynchronizationService.java index 906caf67..ef3a5f6c 100644 --- a/app/src/main/java/org/asteroidos/sync/services/SynchronizationService.java +++ b/app/src/main/java/org/asteroidos/sync/services/SynchronizationService.java @@ -1,5 +1,6 @@ /* - * Copyright (C) 2016 - Florent Revest + * AsteroidOSSync + * Copyright (c) 2023 AsteroidOS * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/app/src/main/java/org/asteroidos/sync/utils/AppInfo.java b/app/src/main/java/org/asteroidos/sync/utils/AppInfo.java index eade707e..81cc3035 100644 --- a/app/src/main/java/org/asteroidos/sync/utils/AppInfo.java +++ b/app/src/main/java/org/asteroidos/sync/utils/AppInfo.java @@ -1,5 +1,6 @@ package org.asteroidos.sync.utils; +// TODO Handle dubious copyright // copied from https://github.com/jensstein/oandbackup, used under MIT license import android.graphics.Bitmap; diff --git a/app/src/main/java/org/asteroidos/sync/utils/AppInfoHelper.java b/app/src/main/java/org/asteroidos/sync/utils/AppInfoHelper.java index 4ce4f3a2..5adb4d0e 100644 --- a/app/src/main/java/org/asteroidos/sync/utils/AppInfoHelper.java +++ b/app/src/main/java/org/asteroidos/sync/utils/AppInfoHelper.java @@ -1,5 +1,24 @@ +/* + * AsteroidOSSync + * Copyright (c) 2023 AsteroidOS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package org.asteroidos.sync.utils; +// TODO Handle dubious copyright // copied from https://github.com/jensstein/oandbackup, used under MIT license import android.content.Context; diff --git a/app/src/main/java/org/asteroidos/sync/utils/AsteroidUUIDS.java b/app/src/main/java/org/asteroidos/sync/utils/AsteroidUUIDS.java index 14f9c9ec..7bbdf43d 100644 --- a/app/src/main/java/org/asteroidos/sync/utils/AsteroidUUIDS.java +++ b/app/src/main/java/org/asteroidos/sync/utils/AsteroidUUIDS.java @@ -1,3 +1,21 @@ +/* + * AsteroidOSSync + * Copyright (c) 2023 AsteroidOS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + /* AsteroidOS UUID collection for ble characteristics and watch filtering */ package org.asteroidos.sync.utils; diff --git a/app/src/main/java/org/asteroidos/sync/utils/NotificationParser.java b/app/src/main/java/org/asteroidos/sync/utils/NotificationParser.java index aaa734e1..6201363a 100644 --- a/app/src/main/java/org/asteroidos/sync/utils/NotificationParser.java +++ b/app/src/main/java/org/asteroidos/sync/utils/NotificationParser.java @@ -1,3 +1,21 @@ +/* + * AsteroidOSSync + * Copyright (c) 2023 AsteroidOS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package org.asteroidos.sync.utils; import android.annotation.SuppressLint; From a61076440414d5f377cc7e6d5da14942386c2eee Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 14:28:32 -0500 Subject: [PATCH 04/42] Add NEARBY_WIFI_DEVICES permission A theoretical fix --- app/src/main/AndroidManifest.xml | 2 + .../asteroidos/sync/PermissionsActivity.java | 191 ++++++++++-------- 2 files changed, 104 insertions(+), 89 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 328e9e04..026a17b3 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -14,6 +14,8 @@ + + diff --git a/app/src/main/java/org/asteroidos/sync/PermissionsActivity.java b/app/src/main/java/org/asteroidos/sync/PermissionsActivity.java index 02960392..06b71a65 100644 --- a/app/src/main/java/org/asteroidos/sync/PermissionsActivity.java +++ b/app/src/main/java/org/asteroidos/sync/PermissionsActivity.java @@ -39,6 +39,8 @@ import org.asteroidos.sync.services.NLService; +import java.util.ArrayList; + import io.github.dreierf.materialintroscreen.MaterialIntroActivity; import io.github.dreierf.materialintroscreen.SlideFragment; import io.github.dreierf.materialintroscreen.SlideFragmentBuilder; @@ -59,105 +61,116 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { if (hasBLE) { if (!isLowRamDevice) { - SlideFragment welcomeFragment = new SlideFragmentBuilder() - .backgroundColor(R.color.colorintroslide1) - .buttonsColor(R.color.colorintroslide1button) - .image(R.drawable.introslide1icon) - .title(getString(R.string.intro_slide1_title)) - .description(getString(R.string.intro_slide1_subtitle)) - .build(); - - SlideFragment externalStorageFragment = new SlideFragmentBuilder() - .backgroundColor(R.color.colorintroslide2) - .buttonsColor(R.color.colorintroslide2button) - .neededPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}) - .image(R.drawable.introslide2icon) - .title(getString(R.string.intro_slide2_title)) - .description(getString(R.string.intro_slide2_subtitle)) - .build(); + SlideFragment welcomeFragment = new SlideFragmentBuilder() + .backgroundColor(R.color.colorintroslide1) + .buttonsColor(R.color.colorintroslide1button) + .image(R.drawable.introslide1icon) + .title(getString(R.string.intro_slide1_title)) + .description(getString(R.string.intro_slide1_subtitle)) + .build(); + + SlideFragment externalStorageFragment = new SlideFragmentBuilder() + .backgroundColor(R.color.colorintroslide2) + .buttonsColor(R.color.colorintroslide2button) + .neededPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}) + .image(R.drawable.introslide2icon) + .title(getString(R.string.intro_slide2_title)) + .description(getString(R.string.intro_slide2_subtitle)) + .build(); boolean externalStorageFragmentShown = false; - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { - externalStorageFragmentShown = (ContextCompat.checkSelfPermission(this, - Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED); - } + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { + externalStorageFragmentShown = (ContextCompat.checkSelfPermission(this, + Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED); + } - SlideFragmentBuilder localizationFragmentBuilder = new SlideFragmentBuilder() - .backgroundColor(R.color.colorintroslide3) - .buttonsColor(R.color.colorintroslide3button) - .neededPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}) - .image(R.drawable.introslide3icon) - .title(getString(R.string.intro_slide3_title)) - .description(getString(R.string.intro_slide3_subtitle)); + ArrayList permissions = new ArrayList<>(); + permissions.add(Manifest.permission.ACCESS_FINE_LOCATION); - if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { - localizationFragmentBuilder.neededPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.BLUETOOTH_CONNECT, Manifest.permission.BLUETOOTH_SCAN}); - } - SlideFragment localizationFragment = localizationFragmentBuilder.build(); - - boolean localizationFragmentShown = (ContextCompat.checkSelfPermission(this, - Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED); - if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { - localizationFragmentShown |= (ContextCompat.checkSelfPermission(this, - Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED); - localizationFragmentShown |= (ContextCompat.checkSelfPermission(this, - Manifest.permission.BLUETOOTH_SCAN) != PackageManager.PERMISSION_GRANTED); - } + if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + permissions.add(Manifest.permission.BLUETOOTH_CONNECT); + permissions.add(Manifest.permission.BLUETOOTH_SCAN); + } - boolean notificationsPermissionFragmentShown = false; - SlideFragment notificationsPermissionFragment = null; - if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - SlideFragmentBuilder notificationsPermissionSlideBuilder = new SlideFragmentBuilder() + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU){ + permissions.add(Manifest.permission.NEARBY_WIFI_DEVICES); + } + + SlideFragmentBuilder localizationFragmentBuilder = new SlideFragmentBuilder() .backgroundColor(R.color.colorintroslide3) .buttonsColor(R.color.colorintroslide3button) - .neededPermissions(new String[]{Manifest.permission.POST_NOTIFICATIONS}) - .image(R.drawable.ic_notifications) - .title(getString(R.string.intro_slide6_title)) - .description(getString(R.string.intro_slide6_subtitle)); - notificationsPermissionSlideBuilder.neededPermissions(new String[]{Manifest.permission.POST_NOTIFICATIONS}); - notificationsPermissionFragment = notificationsPermissionSlideBuilder.build(); - notificationsPermissionFragmentShown = (ContextCompat.checkSelfPermission(this, - Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED); - } + .neededPermissions(permissions.toArray(new String[]{})) + .image(R.drawable.introslide3icon) + .title(getString(R.string.intro_slide3_title)) + .description(getString(R.string.intro_slide3_subtitle)); - NotificationsSlide notificationFragment = new NotificationsSlide(); - notificationFragment.setContext(this); - boolean notificationFragmentShown = notificationFragment.hasAnyPermissionsToGrant(); - - BatteryOptimSlide batteryOptimFragment = new BatteryOptimSlide(); - batteryOptimFragment.setContext(this); - boolean batteryOptimFragmentShown = batteryOptimFragment.hasAnyPermissionsToGrant(); - - SlideFragment phoneStateFragment = new SlideFragmentBuilder() - .backgroundColor(R.color.colorintroslide2) - .buttonsColor(R.color.colorintroslide2button) - .neededPermissions(new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.READ_CALL_LOG, Manifest.permission.READ_CONTACTS}) - .image(R.drawable.ic_ring_volume) - .title(getString(R.string.intro_phonestateslide_title)) - .description(getString(R.string.intro_phonestateslide_subtitle)) - .build(); - boolean phoneStateFragmentShown = (ContextCompat.checkSelfPermission(this, - Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) || - (ContextCompat.checkSelfPermission(this, - Manifest.permission.READ_CALL_LOG) != PackageManager.PERMISSION_GRANTED) || - (ContextCompat.checkSelfPermission(this, - Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED); - - if (externalStorageFragmentShown || localizationFragmentShown || - notificationFragmentShown || notificationsPermissionFragmentShown || batteryOptimFragmentShown || phoneStateFragmentShown) { - addSlide(welcomeFragment); - if (externalStorageFragmentShown) addSlide(externalStorageFragment); - if (localizationFragmentShown) addSlide(localizationFragment); - if (notificationsPermissionFragmentShown && notificationsPermissionFragment != null) addSlide(notificationsPermissionFragment); - if (notificationFragmentShown) addSlide(notificationFragment); - if (batteryOptimFragmentShown) addSlide(batteryOptimFragment); - if (phoneStateFragmentShown) addSlide(phoneStateFragment); - } else - startMainActivity(); - } else { + + SlideFragment localizationFragment = localizationFragmentBuilder.build(); + + boolean localizationFragmentShown = (ContextCompat.checkSelfPermission(this, + Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED); + if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + localizationFragmentShown |= (ContextCompat.checkSelfPermission(this, + Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED); + localizationFragmentShown |= (ContextCompat.checkSelfPermission(this, + Manifest.permission.BLUETOOTH_SCAN) != PackageManager.PERMISSION_GRANTED); + } + + boolean notificationsPermissionFragmentShown = false; + SlideFragment notificationsPermissionFragment = null; + if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + SlideFragmentBuilder notificationsPermissionSlideBuilder = new SlideFragmentBuilder() + .backgroundColor(R.color.colorintroslide3) + .buttonsColor(R.color.colorintroslide3button) + .neededPermissions(new String[]{Manifest.permission.POST_NOTIFICATIONS}) + .image(R.drawable.ic_notifications) + .title(getString(R.string.intro_slide6_title)) + .description(getString(R.string.intro_slide6_subtitle)); + notificationsPermissionSlideBuilder.neededPermissions(new String[]{Manifest.permission.POST_NOTIFICATIONS}); + notificationsPermissionFragment = notificationsPermissionSlideBuilder.build(); + notificationsPermissionFragmentShown = (ContextCompat.checkSelfPermission(this, + Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED); + } + + NotificationsSlide notificationFragment = new NotificationsSlide(); + notificationFragment.setContext(this); + boolean notificationFragmentShown = notificationFragment.hasAnyPermissionsToGrant(); + + BatteryOptimSlide batteryOptimFragment = new BatteryOptimSlide(); + batteryOptimFragment.setContext(this); + boolean batteryOptimFragmentShown = batteryOptimFragment.hasAnyPermissionsToGrant(); + + SlideFragment phoneStateFragment = new SlideFragmentBuilder() + .backgroundColor(R.color.colorintroslide2) + .buttonsColor(R.color.colorintroslide2button) + .neededPermissions(new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.READ_CALL_LOG, Manifest.permission.READ_CONTACTS}) + .image(R.drawable.ic_ring_volume) + .title(getString(R.string.intro_phonestateslide_title)) + .description(getString(R.string.intro_phonestateslide_subtitle)) + .build(); + boolean phoneStateFragmentShown = (ContextCompat.checkSelfPermission(this, + Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) || + (ContextCompat.checkSelfPermission(this, + Manifest.permission.READ_CALL_LOG) != PackageManager.PERMISSION_GRANTED) || + (ContextCompat.checkSelfPermission(this, + Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED); + + if (externalStorageFragmentShown || localizationFragmentShown || + notificationFragmentShown || notificationsPermissionFragmentShown || batteryOptimFragmentShown || phoneStateFragmentShown) { + addSlide(welcomeFragment); + if (externalStorageFragmentShown) addSlide(externalStorageFragment); + if (localizationFragmentShown) addSlide(localizationFragment); + if (notificationsPermissionFragmentShown && notificationsPermissionFragment != null) + addSlide(notificationsPermissionFragment); + if (notificationFragmentShown) addSlide(notificationFragment); + if (batteryOptimFragmentShown) addSlide(batteryOptimFragment); + if (phoneStateFragmentShown) addSlide(phoneStateFragment); + } else + startMainActivity(); + } else { addSlide(new AndroidGoSlide()); } } else { - addSlide(new BLENotSupportedSlide()); + addSlide(new BLENotSupportedSlide()); } } From ac886d003cdcecc0bffc737aa09a67fb30c55168 Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 17:38:42 -0500 Subject: [PATCH 05/42] Remove redundant suppression in ScreenshotService --- .../java/org/asteroidos/sync/connectivity/ScreenshotService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/org/asteroidos/sync/connectivity/ScreenshotService.java b/app/src/main/java/org/asteroidos/sync/connectivity/ScreenshotService.java index 4a5f1495..a42d3e3b 100644 --- a/app/src/main/java/org/asteroidos/sync/connectivity/ScreenshotService.java +++ b/app/src/main/java/org/asteroidos/sync/connectivity/ScreenshotService.java @@ -55,7 +55,6 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; -@SuppressWarnings({"FieldCanBeLocal"}) // For clarity, we prefer having NOTIFICATION as a top level field public class ScreenshotService implements IConnectivityService { private static final String NOTIFICATION_CHANNEL_ID = "screenshotservice_channel_id_01"; private int NOTIFICATION = 2726; From f949e8853d1504085bb464c1082bf23f0993eada Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 17:40:13 -0500 Subject: [PATCH 06/42] Localize variables --- .../sync/connectivity/SilentModeService.java | 4 +--- .../sync/fragments/DeviceDetailFragment.java | 10 +++------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/org/asteroidos/sync/connectivity/SilentModeService.java b/app/src/main/java/org/asteroidos/sync/connectivity/SilentModeService.java index 8415dec8..a1e5df2f 100644 --- a/app/src/main/java/org/asteroidos/sync/connectivity/SilentModeService.java +++ b/app/src/main/java/org/asteroidos/sync/connectivity/SilentModeService.java @@ -30,14 +30,12 @@ public class SilentModeService implements SharedPreferences.OnSharedPreferenceCh private static final String PREF_ORIG_RINGER = "OriginalRingMode"; private SharedPreferences prefs; private Boolean notificationPref; - private Context context; private AudioManager am; public SilentModeService(Context con) { prefs = con.getSharedPreferences(PREFS_NAME, Activity.MODE_PRIVATE); - context = con; prefs.registerOnSharedPreferenceChangeListener(this); - am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); + am = (AudioManager) con.getSystemService(Context.AUDIO_SERVICE); } diff --git a/app/src/main/java/org/asteroidos/sync/fragments/DeviceDetailFragment.java b/app/src/main/java/org/asteroidos/sync/fragments/DeviceDetailFragment.java index 18dd628e..77bc5d10 100644 --- a/app/src/main/java/org/asteroidos/sync/fragments/DeviceDetailFragment.java +++ b/app/src/main/java/org/asteroidos/sync/fragments/DeviceDetailFragment.java @@ -56,10 +56,6 @@ public class DeviceDetailFragment extends Fragment { private SharedPreferences mSilenceModeSettings; private SharedPreferences mCallStateSettings; - private CheckBox mTimeSyncCheckBox; - private CheckBox mSilenceModeCheckBox; - private CheckBox mCallStateServiceCheckBox; - private FloatingActionButton mFab; private boolean mConnected = false; @@ -138,7 +134,7 @@ public void onViewCreated(View view, Bundle savedInstanceState) { mTimeSyncSettings = getActivity().getSharedPreferences(TimeService.PREFS_NAME, 0); - mTimeSyncCheckBox = view.findViewById(R.id.timeSyncCheckBox); + CheckBox mTimeSyncCheckBox = view.findViewById(R.id.timeSyncCheckBox); mTimeSyncCheckBox.setChecked(mTimeSyncSettings.getBoolean(TimeService.PREFS_SYNC_TIME, TimeService.PREFS_SYNC_TIME_DEFAULT)); mTimeSyncCheckBox.setOnCheckedChangeListener((ignored, checked) -> { SharedPreferences.Editor editor = mTimeSyncSettings.edit(); @@ -147,7 +143,7 @@ public void onViewCreated(View view, Bundle savedInstanceState) { }); mSilenceModeSettings = getActivity().getSharedPreferences(SilentModeService.PREFS_NAME, Context.MODE_PRIVATE); - mSilenceModeCheckBox = view.findViewById(R.id.SilentModeCheckBox); + CheckBox mSilenceModeCheckBox = view.findViewById(R.id.SilentModeCheckBox); mSilenceModeCheckBox.setChecked(mSilenceModeSettings.getBoolean(SilentModeService.PREF_RINGER, false)); mSilenceModeCheckBox.setOnCheckedChangeListener((buttonView, isChecked) -> { SharedPreferences.Editor editor = mSilenceModeSettings.edit(); @@ -156,7 +152,7 @@ public void onViewCreated(View view, Bundle savedInstanceState) { }); mCallStateSettings = getActivity().getSharedPreferences(PhoneStateReceiver.PREFS_NAME, Context.MODE_PRIVATE); - mCallStateServiceCheckBox = view.findViewById(R.id.CallStateServiceCheckBox); + CheckBox mCallStateServiceCheckBox = view.findViewById(R.id.CallStateServiceCheckBox); mCallStateServiceCheckBox.setChecked(mCallStateSettings.getBoolean(PhoneStateReceiver.PREF_SEND_CALL_STATE, true)); mCallStateServiceCheckBox.setOnCheckedChangeListener((buttonView, isChecked) -> { SharedPreferences.Editor editor = mCallStateSettings.edit(); From 8428b6b41fe123825cc4cfdc354725b51f0810a3 Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 17:40:50 -0500 Subject: [PATCH 07/42] Make value final in NotificationPreferences --- .../main/java/org/asteroidos/sync/NotificationPreferences.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/org/asteroidos/sync/NotificationPreferences.java b/app/src/main/java/org/asteroidos/sync/NotificationPreferences.java index cf8aba0c..503fa00b 100644 --- a/app/src/main/java/org/asteroidos/sync/NotificationPreferences.java +++ b/app/src/main/java/org/asteroidos/sync/NotificationPreferences.java @@ -39,7 +39,7 @@ public enum NotificationOption { STRONG_VIBRATION(4), RINGTONE_VIBRATION(5); - private int value; + private final int value; NotificationOption(int value) { this.value = value; } From d8b2f23ea1cfa56822fb14a8e1fe7d519f98b534 Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 17:50:57 -0500 Subject: [PATCH 08/42] Use Main looper in MainActivity.SynchronizationHandler --- app/src/main/java/org/asteroidos/sync/MainActivity.java | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/org/asteroidos/sync/MainActivity.java b/app/src/main/java/org/asteroidos/sync/MainActivity.java index 3b5b387c..ef9a17a9 100644 --- a/app/src/main/java/org/asteroidos/sync/MainActivity.java +++ b/app/src/main/java/org/asteroidos/sync/MainActivity.java @@ -458,6 +458,7 @@ static private class SynchronizationHandler extends Handler { private final MainActivity mActivity; SynchronizationHandler(MainActivity activity) { + super(Looper.getMainLooper()); mActivity = activity; } From ddbf9e99a234a8dc50d16204fcf951f36f518bea Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 17:55:48 -0500 Subject: [PATCH 09/42] Update method of name retrieval in NotificationParser --- .../java/org/asteroidos/sync/utils/NotificationParser.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/asteroidos/sync/utils/NotificationParser.java b/app/src/main/java/org/asteroidos/sync/utils/NotificationParser.java index 6201363a..28ed5b9a 100644 --- a/app/src/main/java/org/asteroidos/sync/utils/NotificationParser.java +++ b/app/src/main/java/org/asteroidos/sync/utils/NotificationParser.java @@ -131,10 +131,10 @@ public int compare(NotificationCompat.MessagingStyle.Message m1, NotificationCom for (NotificationCompat.MessagingStyle.Message message : messagesDescending) { String sender; - if (message.getSender() == null) - sender = formatCharSequence(messagingStyle.getUserDisplayName()); + if (message.getPerson() == null) + sender = formatCharSequence(messagingStyle.getUser().getName()); else - sender = formatCharSequence(message.getSender()); + sender = formatCharSequence(message.getPerson().getName()); sb.append(sender); sb.append(": "); From 3d665b461094723133e9950138e8778aa257f2fa Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 17:58:01 -0500 Subject: [PATCH 10/42] Use default super constructor in PhoneStateReceiver --- .../java/org/asteroidos/sync/services/PhoneStateReceiver.java | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/org/asteroidos/sync/services/PhoneStateReceiver.java b/app/src/main/java/org/asteroidos/sync/services/PhoneStateReceiver.java index 3e8efc2b..b412e87d 100644 --- a/app/src/main/java/org/asteroidos/sync/services/PhoneStateReceiver.java +++ b/app/src/main/java/org/asteroidos/sync/services/PhoneStateReceiver.java @@ -56,6 +56,7 @@ static class CallStateService extends PhoneStateListener { private SharedPreferences prefs; CallStateService(Context con) { + super(); context = con; prefs = con.getSharedPreferences(PREFS_NAME, Activity.MODE_PRIVATE); } From 6cb5321e3cb14d6caadd8b877e5f34a02a5c1e36 Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 17:58:47 -0500 Subject: [PATCH 11/42] Use main looper for SynchronizationService.SynchronizationHandler --- .../org/asteroidos/sync/services/SynchronizationService.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/org/asteroidos/sync/services/SynchronizationService.java b/app/src/main/java/org/asteroidos/sync/services/SynchronizationService.java index ef3a5f6c..bb1474ce 100644 --- a/app/src/main/java/org/asteroidos/sync/services/SynchronizationService.java +++ b/app/src/main/java/org/asteroidos/sync/services/SynchronizationService.java @@ -31,6 +31,7 @@ import android.os.Build; import android.os.Handler; import android.os.IBinder; +import android.os.Looper; import android.os.Message; import android.os.Messenger; import android.os.RemoteException; @@ -374,6 +375,7 @@ static private class SynchronizationHandler extends Handler { private final SynchronizationService mService; SynchronizationHandler(SynchronizationService service) { + super(Looper.getMainLooper()); mService = service; } From ba6ccc490424b188545e070bcc66bffccc05c80a Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 18:03:06 -0500 Subject: [PATCH 12/42] Replace setBuiltInZoomControls with direct call in WeatherSettingsFrag --- .../sync/fragments/WeatherSettingsFragment.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/asteroidos/sync/fragments/WeatherSettingsFragment.java b/app/src/main/java/org/asteroidos/sync/fragments/WeatherSettingsFragment.java index 9eb0745f..633e2252 100644 --- a/app/src/main/java/org/asteroidos/sync/fragments/WeatherSettingsFragment.java +++ b/app/src/main/java/org/asteroidos/sync/fragments/WeatherSettingsFragment.java @@ -23,12 +23,16 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; + import androidx.annotation.NonNull; import androidx.core.app.ActivityCompat; import androidx.fragment.app.Fragment; + import android.os.Bundle; + import androidx.annotation.Nullable; import androidx.core.content.ContextCompat; + import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; @@ -45,6 +49,7 @@ import org.osmdroid.api.IGeoPoint; import org.osmdroid.tileprovider.tilesource.TileSourceFactory; import org.osmdroid.util.GeoPoint; +import org.osmdroid.views.CustomZoomButtonsController; import org.osmdroid.views.MapView; import org.osmdroid.views.overlay.mylocation.GpsMyLocationProvider; import org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay; @@ -80,7 +85,7 @@ public void onViewCreated(View view, Bundle savedInstanceState) { mMapView = view.findViewById(R.id.map); mMapView.setTileSource(TileSourceFactory.MAPNIK); mMapView.setMultiTouchControls(true); - mMapView.setBuiltInZoomControls(false); + mMapView.getZoomController().setVisibility(CustomZoomButtonsController.Visibility.NEVER); mMapView.setZoomRounding(true); mMapView.setMaxZoomLevel(13.0); mMapView.setMinZoomLevel(5.0); @@ -94,7 +99,7 @@ public void onViewCreated(View view, Bundle savedInstanceState) { new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, WEATHER_LOCATION_PERMISSION_REQUEST); } else { - MyLocationNewOverlay mLocationOverlay = new MyLocationNewOverlay(new GpsMyLocationProvider(getContext()),mMapView); + MyLocationNewOverlay mLocationOverlay = new MyLocationNewOverlay(new GpsMyLocationProvider(getContext()), mMapView); mLocationOverlay.enableMyLocation(); mMapView.getOverlays().add(mLocationOverlay); } @@ -145,7 +150,7 @@ public void onCheckedChanged(CompoundButton ignored, boolean checked) { } @Override - public void onResume(){ + public void onResume() { super.onResume(); mMapView.onResume(); } @@ -164,7 +169,7 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { @Override public boolean onOptionsItemSelected(MenuItem menuItem) { - if (menuItem.getItemId() == R.id.customApiKey){ + if (menuItem.getItemId() == R.id.customApiKey) { View view = View.inflate(getActivity(), R.layout.dialog_api_key, null); EditText editText = view.findViewById(R.id.apikey); editText.setText(mOwmKey); @@ -195,7 +200,7 @@ private void handleLocationToggle(boolean enable) { editor.putBoolean(WeatherService.PREFS_SYNC_WEATHER, enable); editor.apply(); mButton.setVisibility(enable ? View.INVISIBLE : View.VISIBLE); - getActivity().sendBroadcast(new Intent(WeatherService.WEATHER_SYNC_INTENT)); + getActivity().sendBroadcast(new Intent(WeatherService.WEATHER_SYNC_INTENT)); } @Override From 26adbf09f45afbbc3738202b14cb3124a2d7c7a9 Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 18:03:44 -0500 Subject: [PATCH 13/42] Replace C Style array declaration in WeatherSettingsFragment --- .../org/asteroidos/sync/fragments/WeatherSettingsFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/org/asteroidos/sync/fragments/WeatherSettingsFragment.java b/app/src/main/java/org/asteroidos/sync/fragments/WeatherSettingsFragment.java index 633e2252..f363b523 100644 --- a/app/src/main/java/org/asteroidos/sync/fragments/WeatherSettingsFragment.java +++ b/app/src/main/java/org/asteroidos/sync/fragments/WeatherSettingsFragment.java @@ -205,7 +205,7 @@ private void handleLocationToggle(boolean enable) { @Override public void onRequestPermissionsResult(int requestCode, - @NonNull String permissions[], @NonNull int[] grantResults) { + @NonNull String[] permissions, @NonNull int[] grantResults) { switch (requestCode) { case WEATHER_LOCATION_SYNC_PERMISSION_REQUEST: { // If request is cancelled, the result arrays are empty. From 09b6aefbc5ccd49ae42d146354976a3f4b1d46f3 Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 18:06:27 -0500 Subject: [PATCH 14/42] Make various non-final variables final due to never being modified --- .../sync/adapters/AppInfoAdapter.java | 9 +-- .../connectivity/NotificationService.java | 6 +- .../sync/connectivity/ScreenshotService.java | 8 +-- .../sync/connectivity/SilentModeService.java | 4 +- .../sync/connectivity/TimeService.java | 6 +- .../sync/connectivity/WeatherService.java | 6 +- .../sync/services/PhoneStateReceiver.java | 4 +- .../org/asteroidos/sync/utils/AppInfo.java | 70 ++++++++++--------- .../asteroidos/sync/utils/AppInfoHelper.java | 8 +-- 9 files changed, 59 insertions(+), 62 deletions(-) diff --git a/app/src/main/java/org/asteroidos/sync/adapters/AppInfoAdapter.java b/app/src/main/java/org/asteroidos/sync/adapters/AppInfoAdapter.java index ec549a4f..f47c2bb4 100644 --- a/app/src/main/java/org/asteroidos/sync/adapters/AppInfoAdapter.java +++ b/app/src/main/java/org/asteroidos/sync/adapters/AppInfoAdapter.java @@ -31,9 +31,10 @@ public class AppInfoAdapter extends ArrayAdapter { private final static String TAG = AppInfoAdapter.class.getSimpleName(); - private Context context; - private ArrayList items; - private int iconSize, layout; + private final Context context; + private final ArrayList items; + private int iconSize; + private final int layout; public AppInfoAdapter(Context context, int layout, ArrayList items) { super(context, layout, items); @@ -145,7 +146,7 @@ abstract class MyOnItemSelectedListener implements AdapterView.OnItemSelectedLis private class SeenPackagesFilter extends Filter { - private List seenPackages; + private final List seenPackages; private SeenPackagesFilter(List seenPackages) { this.seenPackages = seenPackages; diff --git a/app/src/main/java/org/asteroidos/sync/connectivity/NotificationService.java b/app/src/main/java/org/asteroidos/sync/connectivity/NotificationService.java index 368601e0..1dcc503c 100644 --- a/app/src/main/java/org/asteroidos/sync/connectivity/NotificationService.java +++ b/app/src/main/java/org/asteroidos/sync/connectivity/NotificationService.java @@ -35,9 +35,9 @@ public class NotificationService implements IConnectivityService { public static final String TAG = NotificationService.class.toString(); - private Context mCtx; - private IAsteroidDevice mDevice; - private NotificationReceiver mNReceiver; + private final Context mCtx; + private final IAsteroidDevice mDevice; + private final NotificationReceiver mNReceiver; public NotificationService(Context ctx, IAsteroidDevice device) { this.mDevice = device; diff --git a/app/src/main/java/org/asteroidos/sync/connectivity/ScreenshotService.java b/app/src/main/java/org/asteroidos/sync/connectivity/ScreenshotService.java index a42d3e3b..840ee31d 100644 --- a/app/src/main/java/org/asteroidos/sync/connectivity/ScreenshotService.java +++ b/app/src/main/java/org/asteroidos/sync/connectivity/ScreenshotService.java @@ -57,10 +57,10 @@ public class ScreenshotService implements IConnectivityService { private static final String NOTIFICATION_CHANNEL_ID = "screenshotservice_channel_id_01"; - private int NOTIFICATION = 2726; + private final int NOTIFICATION = 2726; - private Context mCtx; - private IAsteroidDevice mDevice; + private final Context mCtx; + private final IAsteroidDevice mDevice; private ScreenshotReqReceiver mSReceiver; @@ -71,7 +71,7 @@ public class ScreenshotService implements IConnectivityService { private byte[] totalData; private ScheduledExecutorService processUpdate; - private NotificationManager mNM; + private final NotificationManager mNM; public ScreenshotService(Context ctx, IAsteroidDevice device) { mDevice = device; diff --git a/app/src/main/java/org/asteroidos/sync/connectivity/SilentModeService.java b/app/src/main/java/org/asteroidos/sync/connectivity/SilentModeService.java index a1e5df2f..d06a5bb6 100644 --- a/app/src/main/java/org/asteroidos/sync/connectivity/SilentModeService.java +++ b/app/src/main/java/org/asteroidos/sync/connectivity/SilentModeService.java @@ -28,9 +28,9 @@ public class SilentModeService implements SharedPreferences.OnSharedPreferenceCh public static final String PREFS_NAME = "AppPreferences"; public static final String PREF_RINGER = "PhoneRingModeOnConnection"; private static final String PREF_ORIG_RINGER = "OriginalRingMode"; - private SharedPreferences prefs; + private final SharedPreferences prefs; private Boolean notificationPref; - private AudioManager am; + private final AudioManager am; public SilentModeService(Context con) { prefs = con.getSharedPreferences(PREFS_NAME, Activity.MODE_PRIVATE); diff --git a/app/src/main/java/org/asteroidos/sync/connectivity/TimeService.java b/app/src/main/java/org/asteroidos/sync/connectivity/TimeService.java index 7374cebd..50d0b416 100644 --- a/app/src/main/java/org/asteroidos/sync/connectivity/TimeService.java +++ b/app/src/main/java/org/asteroidos/sync/connectivity/TimeService.java @@ -42,10 +42,10 @@ public class TimeService implements IConnectivityService, SharedPreferences.OnSh public static final boolean PREFS_SYNC_TIME_DEFAULT = true; public static final String TIME_SYNC_INTENT = "org.asteroidos.sync.TIME_SYNC_REQUEST_LISTENER"; - private IAsteroidDevice mDevice; - private Context mCtx; + private final IAsteroidDevice mDevice; + private final Context mCtx; - private SharedPreferences mTimeSyncSettings; + private final SharedPreferences mTimeSyncSettings; private TimeSyncReqReceiver mSReceiver; private PendingIntent alarmPendingIntent; diff --git a/app/src/main/java/org/asteroidos/sync/connectivity/WeatherService.java b/app/src/main/java/org/asteroidos/sync/connectivity/WeatherService.java index 7741489b..b5a7b1fa 100644 --- a/app/src/main/java/org/asteroidos/sync/connectivity/WeatherService.java +++ b/app/src/main/java/org/asteroidos/sync/connectivity/WeatherService.java @@ -62,9 +62,9 @@ public class WeatherService implements IConnectivityService { public static final boolean PREFS_SYNC_WEATHER_DEFAULT = false; public static final String WEATHER_SYNC_INTENT = "org.asteroidos.sync.WEATHER_SYNC_REQUEST_LISTENER"; - private IAsteroidDevice mDevice; - private Context mCtx; - private SharedPreferences mSettings; + private final IAsteroidDevice mDevice; + private final Context mCtx; + private final SharedPreferences mSettings; private WeatherSyncReqReceiver mSReceiver; private PendingIntent mAlarmPendingIntent; diff --git a/app/src/main/java/org/asteroidos/sync/services/PhoneStateReceiver.java b/app/src/main/java/org/asteroidos/sync/services/PhoneStateReceiver.java index b412e87d..8daa3e6a 100644 --- a/app/src/main/java/org/asteroidos/sync/services/PhoneStateReceiver.java +++ b/app/src/main/java/org/asteroidos/sync/services/PhoneStateReceiver.java @@ -52,8 +52,8 @@ public void onReceive(Context context, Intent intent) { } static class CallStateService extends PhoneStateListener { - private Context context; - private SharedPreferences prefs; + private final Context context; + private final SharedPreferences prefs; CallStateService(Context con) { super(); diff --git a/app/src/main/java/org/asteroidos/sync/utils/AppInfo.java b/app/src/main/java/org/asteroidos/sync/utils/AppInfo.java index 81cc3035..e365467d 100644 --- a/app/src/main/java/org/asteroidos/sync/utils/AppInfo.java +++ b/app/src/main/java/org/asteroidos/sync/utils/AppInfo.java @@ -6,72 +6,74 @@ import android.graphics.Bitmap; import android.os.Parcel; import android.os.Parcelable; + import androidx.annotation.NonNull; -public class AppInfo - implements Comparable, Parcelable -{ - private String label, packageName; - private boolean system, installed, checked, disabled; +public class AppInfo implements Comparable, Parcelable { + + private final String label, packageName; + private final boolean system, installed; + private boolean checked, disabled; + public Bitmap icon; - AppInfo(String packageName, String label, boolean system, boolean installed) - { + AppInfo(String packageName, String label, boolean system, boolean installed) { this.label = label; this.packageName = packageName; this.system = system; this.installed = installed; } - public String getPackageName() - { + + public String getPackageName() { return packageName; } - public String getLabel() - { + + public String getLabel() { return label; } - public void setDisabled(boolean disabled) - { + public void setDisabled(boolean disabled) { this.disabled = disabled; } - public boolean isDisabled() - { + + public boolean isDisabled() { return disabled; } - public boolean isSystem() - { + + public boolean isSystem() { return system; } - public int compareTo(@NonNull AppInfo appInfo) { return label.compareToIgnoreCase(appInfo.getLabel()); } - public String toString() - { + + public int compareTo(@NonNull AppInfo appInfo) { + return label.compareToIgnoreCase(appInfo.getLabel()); + } + + public String toString() { return label + " : " + packageName; } - public int describeContents() - { + + public int describeContents() { return 0; } - public void writeToParcel(Parcel out, int flags) - { + + public void writeToParcel(Parcel out, int flags) { out.writeString(label); out.writeString(packageName); - out.writeBooleanArray(new boolean[] {system, installed, checked}); + out.writeBooleanArray(new boolean[]{system, installed, checked}); out.writeParcelable(icon, flags); } - public static final Parcelable.Creator CREATOR = new Parcelable.Creator() - { - public AppInfo createFromParcel(Parcel in) - { - return new AppInfo (in); + + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { + public AppInfo createFromParcel(Parcel in) { + return new AppInfo(in); } - public AppInfo[] newArray(int size) - { + + public AppInfo[] newArray(int size) { return new AppInfo[size]; } }; - private AppInfo(Parcel in) - { + + private AppInfo(Parcel in) { label = in.readString(); packageName = in.readString(); boolean[] bools = new boolean[4]; diff --git a/app/src/main/java/org/asteroidos/sync/utils/AppInfoHelper.java b/app/src/main/java/org/asteroidos/sync/utils/AppInfoHelper.java index 5adb4d0e..059d116c 100644 --- a/app/src/main/java/org/asteroidos/sync/utils/AppInfoHelper.java +++ b/app/src/main/java/org/asteroidos/sync/utils/AppInfoHelper.java @@ -87,11 +87,5 @@ public static ArrayList getPackageInfo(Context context) } return list; } - private static Comparator pInfoPackageNameComparator = new Comparator() - { - public int compare(PackageInfo p1, PackageInfo p2) - { - return p1.packageName.compareToIgnoreCase(p2.packageName); - } - }; + private static final Comparator pInfoPackageNameComparator = (p1, p2) -> p1.packageName.compareToIgnoreCase(p2.packageName); } From e6f8ad2c8eea93e3a8caac20bf3681dfd7900f19 Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 18:06:47 -0500 Subject: [PATCH 15/42] Remove unnecessary toString calls --- .../main/java/org/asteroidos/sync/MainActivity.java | 2 +- .../sync/fragments/DeviceDetailFragment.java | 10 +++++----- .../asteroidos/sync/fragments/DeviceListFragment.java | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/asteroidos/sync/MainActivity.java b/app/src/main/java/org/asteroidos/sync/MainActivity.java index ef9a17a9..165fffe3 100644 --- a/app/src/main/java/org/asteroidos/sync/MainActivity.java +++ b/app/src/main/java/org/asteroidos/sync/MainActivity.java @@ -120,7 +120,7 @@ public void onScanResult(int callbackType, @NonNull ScanResult result) { } return; } - Log.d(TAG, "SCAN RESULT:" + result.getDevice().toString() + " Name:" + result.getDevice().getName()); + Log.d(TAG, "SCAN RESULT:" + result.getDevice() + " Name:" + result.getDevice().getName()); ParcelUuid[] arr = result.getDevice().getUuids(); } }; diff --git a/app/src/main/java/org/asteroidos/sync/fragments/DeviceDetailFragment.java b/app/src/main/java/org/asteroidos/sync/fragments/DeviceDetailFragment.java index 77bc5d10..c60833ac 100644 --- a/app/src/main/java/org/asteroidos/sync/fragments/DeviceDetailFragment.java +++ b/app/src/main/java/org/asteroidos/sync/fragments/DeviceDetailFragment.java @@ -231,31 +231,31 @@ public void onAttach(Context context) { if (context instanceof DeviceDetailFragment.OnDefaultDeviceUnselectedListener) mDeviceListener = (DeviceDetailFragment.OnDefaultDeviceUnselectedListener) context; else - throw new ClassCastException(context.toString() + throw new ClassCastException(context + " does not implement DeviceDetailFragment.OnDefaultDeviceUnselectedListener"); if (context instanceof DeviceDetailFragment.OnConnectRequestedListener) mConnectListener = (DeviceDetailFragment.OnConnectRequestedListener) context; else - throw new ClassCastException(context.toString() + throw new ClassCastException(context + " does not implement DeviceDetailFragment.OnConnectRequestedListener"); if (context instanceof DeviceDetailFragment.OnAppSettingsClickedListener) mAppSettingsListener = (DeviceDetailFragment.OnAppSettingsClickedListener) context; else - throw new ClassCastException(context.toString() + throw new ClassCastException(context + " does not implement DeviceDetailFragment.OnAppSettingsClickedListener"); if (context instanceof DeviceDetailFragment.OnWeatherSettingsClickedListener) mWeatherSettingsListener = (DeviceDetailFragment.OnWeatherSettingsClickedListener) context; else - throw new ClassCastException(context.toString() + throw new ClassCastException(context + " does not implement DeviceDetailFragment.OnWeatherSettingsClickedListener"); if (context instanceof DeviceDetailFragment.OnUpdateListener) mUpdateListener = (DeviceDetailFragment.OnUpdateListener) context; else - throw new ClassCastException(context.toString() + throw new ClassCastException(context + " does not implement DeviceDetailFragment.onUpdateListener"); } diff --git a/app/src/main/java/org/asteroidos/sync/fragments/DeviceListFragment.java b/app/src/main/java/org/asteroidos/sync/fragments/DeviceListFragment.java index edb78596..4b8f15c2 100644 --- a/app/src/main/java/org/asteroidos/sync/fragments/DeviceListFragment.java +++ b/app/src/main/java/org/asteroidos/sync/fragments/DeviceListFragment.java @@ -114,13 +114,13 @@ public void onAttach(Context context) { if (context instanceof OnDefaultDeviceSelectedListener) mDeviceListener = (OnDefaultDeviceSelectedListener) context; else - throw new ClassCastException(context.toString() + throw new ClassCastException(context + " does not implement DeviceListFragment.OnDeviceSelectedListener"); if (context instanceof OnScanRequestedListener) mScanListener = (OnScanRequestedListener) context; else - throw new ClassCastException(context.toString() + throw new ClassCastException(context + " does not implement DeviceListFragment.OnScanRequestedListener"); } From 2ef943ea03d2eee2ffd8638373678bf0237d4115 Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 18:07:54 -0500 Subject: [PATCH 16/42] Remove redundant public declaration in interface --- .../main/java/org/asteroidos/sync/connectivity/IService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/asteroidos/sync/connectivity/IService.java b/app/src/main/java/org/asteroidos/sync/connectivity/IService.java index fcb5c1d6..03461ab6 100644 --- a/app/src/main/java/org/asteroidos/sync/connectivity/IService.java +++ b/app/src/main/java/org/asteroidos/sync/connectivity/IService.java @@ -27,6 +27,6 @@ * ({@link IService#unsync()}) is called when the watch is disconnected. */ public interface IService { - public void sync(); - public void unsync(); + void sync(); + void unsync(); } From 19a8e9ac13a3892a2ea2076efdba11a607360e1f Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 18:08:28 -0500 Subject: [PATCH 17/42] Simplify if statement in AppInfoHelper --- .../main/java/org/asteroidos/sync/utils/AppInfoHelper.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/src/main/java/org/asteroidos/sync/utils/AppInfoHelper.java b/app/src/main/java/org/asteroidos/sync/utils/AppInfoHelper.java index 059d116c..ad19935f 100644 --- a/app/src/main/java/org/asteroidos/sync/utils/AppInfoHelper.java +++ b/app/src/main/java/org/asteroidos/sync/utils/AppInfoHelper.java @@ -50,11 +50,7 @@ public static ArrayList getPackageInfo(Context context) for(PackageInfo pinfo : pinfoList) { - boolean isSystem = false; - if((pinfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) - { - isSystem = true; - } + boolean isSystem = (pinfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0; Bitmap icon = null; Drawable apkIcon = pm.getApplicationIcon(pinfo.applicationInfo); try From 7cfa5c3c36c7a4ab6639e3dd69927ba35acbe454 Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 18:09:20 -0500 Subject: [PATCH 18/42] Make more fields final --- app/src/main/java/org/asteroidos/sync/MainActivity.java | 4 ++-- .../java/org/asteroidos/sync/adapters/AppInfoAdapter.java | 2 +- .../org/asteroidos/sync/asteroid/AsteroidBleManager.java | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/asteroidos/sync/MainActivity.java b/app/src/main/java/org/asteroidos/sync/MainActivity.java index 165fffe3..06f559fb 100644 --- a/app/src/main/java/org/asteroidos/sync/MainActivity.java +++ b/app/src/main/java/org/asteroidos/sync/MainActivity.java @@ -86,7 +86,7 @@ public class MainActivity extends AppCompatActivity implements DeviceListFragmen private static final String TAG = "MainActivity"; public static ArrayList appInfoList; final Messenger mDeviceDetailMessenger = new Messenger(new MainActivity.SynchronizationHandler(this)); - public ParcelUuid asteroidUUID = fromString(AsteroidUUIDS.SERVICE_UUID.toString()); + public final ParcelUuid asteroidUUID = fromString(AsteroidUUIDS.SERVICE_UUID.toString()); Messenger mSyncServiceMessenger; ActivityResultLauncher mLocationEnableActivityLauncher; LocationManager mLocationManager; @@ -107,7 +107,7 @@ public void onServiceDisconnected(ComponentName className) { ScanSettings mSettings; List mFilters; private DeviceListFragment mListFragment; - public ScanCallback scanCallback = new ScanCallback() { + public final ScanCallback scanCallback = new ScanCallback() { @Override public void onScanResult(int callbackType, @NonNull ScanResult result) { super.onScanResult(callbackType, result); diff --git a/app/src/main/java/org/asteroidos/sync/adapters/AppInfoAdapter.java b/app/src/main/java/org/asteroidos/sync/adapters/AppInfoAdapter.java index f47c2bb4..6c212b7a 100644 --- a/app/src/main/java/org/asteroidos/sync/adapters/AppInfoAdapter.java +++ b/app/src/main/java/org/asteroidos/sync/adapters/AppInfoAdapter.java @@ -137,7 +137,7 @@ private static class ViewHolder { } abstract class MyOnItemSelectedListener implements AdapterView.OnItemSelectedListener { - String packageName; + final String packageName; MyOnItemSelectedListener(String packageName) { this.packageName = packageName; diff --git a/app/src/main/java/org/asteroidos/sync/asteroid/AsteroidBleManager.java b/app/src/main/java/org/asteroidos/sync/asteroid/AsteroidBleManager.java index 91ebd9e6..4427be72 100644 --- a/app/src/main/java/org/asteroidos/sync/asteroid/AsteroidBleManager.java +++ b/app/src/main/java/org/asteroidos/sync/asteroid/AsteroidBleManager.java @@ -48,9 +48,9 @@ public class AsteroidBleManager extends BleManager { public static final String TAG = AsteroidBleManager.class.toString(); @Nullable public BluetoothGattCharacteristic batteryCharacteristic; - SynchronizationService mSynchronizationService; - ArrayList mGattServices; - public HashMap recvCallbacks; + final SynchronizationService mSynchronizationService; + final ArrayList mGattServices; + public final HashMap recvCallbacks; public HashMap sendingCharacteristics; public AsteroidBleManager(@NonNull final Context context, SynchronizationService syncService) { From 244854cd336d9d332851e15b0e0fa1abbfe7c360 Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 18:09:48 -0500 Subject: [PATCH 19/42] Remove empty method from AsteroidBleManager --- .../org/asteroidos/sync/asteroid/AsteroidBleManager.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/src/main/java/org/asteroidos/sync/asteroid/AsteroidBleManager.java b/app/src/main/java/org/asteroidos/sync/asteroid/AsteroidBleManager.java index 4427be72..7538209f 100644 --- a/app/src/main/java/org/asteroidos/sync/asteroid/AsteroidBleManager.java +++ b/app/src/main/java/org/asteroidos/sync/asteroid/AsteroidBleManager.java @@ -82,11 +82,6 @@ public final void abort() { cancelQueue(); } - @Override - protected final void finalize() throws Throwable { - super.finalize(); - } - public final void setBatteryLevel(Data data) { BatteryLevelEvent batteryLevelEvent = new BatteryLevelEvent(); batteryLevelEvent.battery = Objects.requireNonNull(data.getByte(0)).intValue(); From 6e4974cbf1d08607586389f5a8ffdd28a078b2d3 Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 18:10:35 -0500 Subject: [PATCH 20/42] Remove unnecessary imports --- .../java/org/asteroidos/sync/asteroid/AsteroidBleManager.java | 3 --- app/src/main/java/org/asteroidos/sync/services/NLService.java | 2 -- .../org/asteroidos/sync/services/SynchronizationService.java | 1 - .../java/org/asteroidos/sync/utils/NotificationParser.java | 1 - 4 files changed, 7 deletions(-) diff --git a/app/src/main/java/org/asteroidos/sync/asteroid/AsteroidBleManager.java b/app/src/main/java/org/asteroidos/sync/asteroid/AsteroidBleManager.java index 7538209f..a52c6666 100644 --- a/app/src/main/java/org/asteroidos/sync/asteroid/AsteroidBleManager.java +++ b/app/src/main/java/org/asteroidos/sync/asteroid/AsteroidBleManager.java @@ -18,17 +18,14 @@ package org.asteroidos.sync.asteroid; -import android.Manifest; import android.bluetooth.BluetoothGatt; import android.bluetooth.BluetoothGattCharacteristic; import android.bluetooth.BluetoothGattService; import android.content.Context; -import android.content.pm.PackageManager; import android.util.Log; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.core.app.ActivityCompat; import org.asteroidos.sync.connectivity.IConnectivityService; import org.asteroidos.sync.connectivity.IServiceCallback; diff --git a/app/src/main/java/org/asteroidos/sync/services/NLService.java b/app/src/main/java/org/asteroidos/sync/services/NLService.java index addbfe66..800d24dd 100644 --- a/app/src/main/java/org/asteroidos/sync/services/NLService.java +++ b/app/src/main/java/org/asteroidos/sync/services/NLService.java @@ -18,7 +18,6 @@ package org.asteroidos.sync.services; -import android.annotation.TargetApi; import android.app.Notification; import android.content.BroadcastReceiver; import android.content.ComponentName; @@ -27,7 +26,6 @@ import android.content.IntentFilter; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; -import android.os.Build; import android.os.Handler; import android.service.notification.NotificationListenerService; import android.service.notification.StatusBarNotification; diff --git a/app/src/main/java/org/asteroidos/sync/services/SynchronizationService.java b/app/src/main/java/org/asteroidos/sync/services/SynchronizationService.java index bb1474ce..f1894900 100644 --- a/app/src/main/java/org/asteroidos/sync/services/SynchronizationService.java +++ b/app/src/main/java/org/asteroidos/sync/services/SynchronizationService.java @@ -59,7 +59,6 @@ import java.util.HashMap; import java.util.List; import java.util.UUID; -import java.util.concurrent.atomic.AtomicBoolean; import no.nordicsemi.android.ble.observer.ConnectionObserver; diff --git a/app/src/main/java/org/asteroidos/sync/utils/NotificationParser.java b/app/src/main/java/org/asteroidos/sync/utils/NotificationParser.java index 28ed5b9a..f05fcb14 100644 --- a/app/src/main/java/org/asteroidos/sync/utils/NotificationParser.java +++ b/app/src/main/java/org/asteroidos/sync/utils/NotificationParser.java @@ -19,7 +19,6 @@ package org.asteroidos.sync.utils; import android.annotation.SuppressLint; -import android.annotation.TargetApi; import android.app.Notification; import android.graphics.Typeface; import android.os.Build; From 9eb6ccf2ef3d867b1818a6bb48f8a1ab29ccce7e Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 18:11:19 -0500 Subject: [PATCH 21/42] Replace wi <> in DeviceListFrag arraylist declaration --- .../java/org/asteroidos/sync/fragments/DeviceListFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/org/asteroidos/sync/fragments/DeviceListFragment.java b/app/src/main/java/org/asteroidos/sync/fragments/DeviceListFragment.java index 4b8f15c2..e3e9404a 100644 --- a/app/src/main/java/org/asteroidos/sync/fragments/DeviceListFragment.java +++ b/app/src/main/java/org/asteroidos/sync/fragments/DeviceListFragment.java @@ -144,7 +144,7 @@ private class LeDeviceListAdapter extends BaseAdapter { LeDeviceListAdapter() { super(); - mLeDevices = new ArrayList(); + mLeDevices = new ArrayList<>(); mInflator = requireActivity().getLayoutInflater(); } From ded3ab43d029f00372fbe1cbdba7b109a65cbd32 Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 18:12:04 -0500 Subject: [PATCH 22/42] Replace Anonymous type with lamba --- .../org/asteroidos/sync/MainActivity.java | 6 +-- .../sync/connectivity/TimeService.java | 7 +-- .../sync/connectivity/WeatherService.java | 7 +-- .../sync/fragments/AppListFragment.java | 6 +-- .../fragments/WeatherSettingsFragment.java | 54 +++++++++---------- .../sync/utils/NotificationParser.java | 7 +-- 6 files changed, 29 insertions(+), 58 deletions(-) diff --git a/app/src/main/java/org/asteroidos/sync/MainActivity.java b/app/src/main/java/org/asteroidos/sync/MainActivity.java index 06f559fb..63f4db81 100644 --- a/app/src/main/java/org/asteroidos/sync/MainActivity.java +++ b/app/src/main/java/org/asteroidos/sync/MainActivity.java @@ -139,11 +139,7 @@ protected void onCreate(Bundle savedInstanceState) { mPrefs = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); String defaultDevMacAddr = mPrefs.getString(PREFS_DEFAULT_MAC_ADDR, ""); - Thread appInfoRetrieval = new Thread(new Runnable() { - public void run() { - appInfoList = AppInfoHelper.getPackageInfo(MainActivity.this); - } - }); + Thread appInfoRetrieval = new Thread(() -> appInfoList = AppInfoHelper.getPackageInfo(MainActivity.this)); appInfoRetrieval.start(); mSettings = new ScanSettings.Builder() diff --git a/app/src/main/java/org/asteroidos/sync/connectivity/TimeService.java b/app/src/main/java/org/asteroidos/sync/connectivity/TimeService.java index 50d0b416..b0695d25 100644 --- a/app/src/main/java/org/asteroidos/sync/connectivity/TimeService.java +++ b/app/src/main/java/org/asteroidos/sync/connectivity/TimeService.java @@ -61,12 +61,7 @@ public TimeService(Context ctx, IAsteroidDevice device) { @Override public final void sync() { Handler handler = new Handler(); - handler.postDelayed(new Runnable() { - @Override - public void run() { - updateTime(); - } - }, 500); + handler.postDelayed(() -> updateTime(), 500); // Register a broadcast handler to use for the alarm Intent // Also listen for TIME_CHANGED and TIMEZONE_CHANGED events diff --git a/app/src/main/java/org/asteroidos/sync/connectivity/WeatherService.java b/app/src/main/java/org/asteroidos/sync/connectivity/WeatherService.java index b5a7b1fa..02a37595 100644 --- a/app/src/main/java/org/asteroidos/sync/connectivity/WeatherService.java +++ b/app/src/main/java/org/asteroidos/sync/connectivity/WeatherService.java @@ -133,12 +133,7 @@ private void updateWeather() { // We don't have a valid Location yet // Use the old location until we have a new one, recheck in 2 Minutes Handler handler = new Handler(); - handler.postDelayed(new Runnable() { - @Override - public void run() { - updateWeather(); - } - }, 1000 * 60 * 2); + handler.postDelayed(() -> updateWeather(), 1000 * 60 * 2); return; } } diff --git a/app/src/main/java/org/asteroidos/sync/fragments/AppListFragment.java b/app/src/main/java/org/asteroidos/sync/fragments/AppListFragment.java index 2cd197f1..05ecfc90 100644 --- a/app/src/main/java/org/asteroidos/sync/fragments/AppListFragment.java +++ b/app/src/main/java/org/asteroidos/sync/fragments/AppListFragment.java @@ -55,10 +55,6 @@ public void onViewCreated(View view, Bundle savedInstanceState) { listView.setAdapter(adapter); placeholder = view.findViewById(R.id.no_notification_placeholder); - adapter.getFilter().filter("", new Filter.FilterListener() { - public void onFilterComplete(int count) { - placeholder.setVisibility(count == 0 ? View.VISIBLE : View.INVISIBLE); - } - }); + adapter.getFilter().filter("", count -> placeholder.setVisibility(count == 0 ? View.VISIBLE : View.INVISIBLE)); } } diff --git a/app/src/main/java/org/asteroidos/sync/fragments/WeatherSettingsFragment.java b/app/src/main/java/org/asteroidos/sync/fragments/WeatherSettingsFragment.java index f363b523..67e0e3e9 100644 --- a/app/src/main/java/org/asteroidos/sync/fragments/WeatherSettingsFragment.java +++ b/app/src/main/java/org/asteroidos/sync/fragments/WeatherSettingsFragment.java @@ -105,44 +105,38 @@ public void onViewCreated(View view, Bundle savedInstanceState) { } mButton = view.findViewById(R.id.positionPickerButton); - mButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - IGeoPoint center = mMapView.getMapCenter(); - - float latitude = (float) center.getLatitude(); - float longitude = (float) center.getLongitude(); - float zoom = (float) mMapView.getZoomLevelDouble(); - - SharedPreferences.Editor editor = mSettings.edit(); - editor.putFloat(WeatherService.PREFS_LATITUDE, latitude); - editor.putFloat(WeatherService.PREFS_LONGITUDE, longitude); - editor.putFloat(WeatherService.PREFS_ZOOM, zoom); - editor.apply(); + mButton.setOnClickListener(v -> { + IGeoPoint center = mMapView.getMapCenter(); - // Update the Weather after changing it - getActivity().sendBroadcast(new Intent(WeatherService.WEATHER_SYNC_INTENT)); + float latitude1 = (float) center.getLatitude(); + float longitude1 = (float) center.getLongitude(); + float zoom1 = (float) mMapView.getZoomLevelDouble(); - getActivity().onBackPressed(); - } + SharedPreferences.Editor editor = mSettings.edit(); + editor.putFloat(WeatherService.PREFS_LATITUDE, latitude1); + editor.putFloat(WeatherService.PREFS_LONGITUDE, longitude1); + editor.putFloat(WeatherService.PREFS_ZOOM, zoom1); + editor.apply(); + + // Update the Weather after changing it + getActivity().sendBroadcast(new Intent(WeatherService.WEATHER_SYNC_INTENT)); + + getActivity().onBackPressed(); }); mWeatherSyncSettings = getActivity().getSharedPreferences(WeatherService.PREFS_NAME, 0); mWeatherSyncCheckBox = view.findViewById(R.id.autoLocationPickerButton); mWeatherSyncCheckBox.setChecked(mWeatherSyncSettings.getBoolean(WeatherService.PREFS_SYNC_WEATHER, WeatherService.PREFS_SYNC_WEATHER_DEFAULT)); - mWeatherSyncCheckBox.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton ignored, boolean checked) { - if (ContextCompat.checkSelfPermission(getActivity(), - Manifest.permission.ACCESS_FINE_LOCATION) - != PackageManager.PERMISSION_GRANTED) { - ActivityCompat.requestPermissions(getActivity(), - new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, - WEATHER_LOCATION_SYNC_PERMISSION_REQUEST); - } else { - handleLocationToggle(mWeatherSyncCheckBox.isChecked()); - } + mWeatherSyncCheckBox.setOnCheckedChangeListener((ignored, checked) -> { + if (ContextCompat.checkSelfPermission(getActivity(), + Manifest.permission.ACCESS_FINE_LOCATION) + != PackageManager.PERMISSION_GRANTED) { + ActivityCompat.requestPermissions(getActivity(), + new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, + WEATHER_LOCATION_SYNC_PERMISSION_REQUEST); + } else { + handleLocationToggle(mWeatherSyncCheckBox.isChecked()); } }); diff --git a/app/src/main/java/org/asteroidos/sync/utils/NotificationParser.java b/app/src/main/java/org/asteroidos/sync/utils/NotificationParser.java index f05fcb14..0d19959a 100644 --- a/app/src/main/java/org/asteroidos/sync/utils/NotificationParser.java +++ b/app/src/main/java/org/asteroidos/sync/utils/NotificationParser.java @@ -117,12 +117,7 @@ private boolean parseMessageStyleNotification(Notification notification, Bundle summary = ""; List messagesDescending = new ArrayList<>(messagingStyle.getMessages()); - Collections.sort(messagesDescending, new Comparator() { - @Override - public int compare(NotificationCompat.MessagingStyle.Message m1, NotificationCompat.MessagingStyle.Message m2) { - return (int) (m2.getTimestamp() - m1.getTimestamp()); - } - }); + Collections.sort(messagesDescending, (m1, m2) -> (int) (m2.getTimestamp() - m1.getTimestamp())); StringBuilder sb = new StringBuilder(); body = ""; From a53d58f62df6eb555267d277749728495b4d9ebd Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 18:12:22 -0500 Subject: [PATCH 23/42] Replace Collections.sort with list.sort --- app/src/main/java/org/asteroidos/sync/utils/AppInfoHelper.java | 2 +- .../main/java/org/asteroidos/sync/utils/NotificationParser.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/asteroidos/sync/utils/AppInfoHelper.java b/app/src/main/java/org/asteroidos/sync/utils/AppInfoHelper.java index ad19935f..f2b75353 100644 --- a/app/src/main/java/org/asteroidos/sync/utils/AppInfoHelper.java +++ b/app/src/main/java/org/asteroidos/sync/utils/AppInfoHelper.java @@ -45,7 +45,7 @@ public static ArrayList getPackageInfo(Context context) ArrayList list = new ArrayList<>(); PackageManager pm = context.getPackageManager(); List pinfoList = pm.getInstalledPackages(0); - Collections.sort(pinfoList, pInfoPackageNameComparator); + pinfoList.sort(pInfoPackageNameComparator); // list seemingly starts scrambled on 4.3 for(PackageInfo pinfo : pinfoList) diff --git a/app/src/main/java/org/asteroidos/sync/utils/NotificationParser.java b/app/src/main/java/org/asteroidos/sync/utils/NotificationParser.java index 0d19959a..17082cec 100644 --- a/app/src/main/java/org/asteroidos/sync/utils/NotificationParser.java +++ b/app/src/main/java/org/asteroidos/sync/utils/NotificationParser.java @@ -117,7 +117,7 @@ private boolean parseMessageStyleNotification(Notification notification, Bundle summary = ""; List messagesDescending = new ArrayList<>(messagingStyle.getMessages()); - Collections.sort(messagesDescending, (m1, m2) -> (int) (m2.getTimestamp() - m1.getTimestamp())); + messagesDescending.sort((m1, m2) -> (int) (m2.getTimestamp() - m1.getTimestamp())); StringBuilder sb = new StringBuilder(); body = ""; From ffb7627a593b57b4ea0e92176f5c6667152a9827 Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 18:12:42 -0500 Subject: [PATCH 24/42] Make AppInfoAdapter.MyOnItemSelectedListener static --- .../main/java/org/asteroidos/sync/adapters/AppInfoAdapter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/org/asteroidos/sync/adapters/AppInfoAdapter.java b/app/src/main/java/org/asteroidos/sync/adapters/AppInfoAdapter.java index 6c212b7a..85277576 100644 --- a/app/src/main/java/org/asteroidos/sync/adapters/AppInfoAdapter.java +++ b/app/src/main/java/org/asteroidos/sync/adapters/AppInfoAdapter.java @@ -136,7 +136,7 @@ private static class ViewHolder { Spinner spinner; } - abstract class MyOnItemSelectedListener implements AdapterView.OnItemSelectedListener { + abstract static class MyOnItemSelectedListener implements AdapterView.OnItemSelectedListener { final String packageName; MyOnItemSelectedListener(String packageName) { From 90c6e6551a941364c4e73490ab22af97bdce7782 Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 18:17:20 -0500 Subject: [PATCH 25/42] Add nullability annotations --- app/src/main/java/org/asteroidos/sync/MainActivity.java | 2 +- .../main/java/org/asteroidos/sync/PermissionsActivity.java | 5 +++-- .../java/org/asteroidos/sync/fragments/AppListFragment.java | 4 +++- .../org/asteroidos/sync/fragments/DeviceDetailFragment.java | 5 +++-- .../org/asteroidos/sync/fragments/DeviceListFragment.java | 3 ++- .../asteroidos/sync/fragments/WeatherSettingsFragment.java | 2 +- app/src/main/java/org/asteroidos/sync/utils/AppInfo.java | 1 + 7 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/asteroidos/sync/MainActivity.java b/app/src/main/java/org/asteroidos/sync/MainActivity.java index 63f4db81..6a407c7c 100644 --- a/app/src/main/java/org/asteroidos/sync/MainActivity.java +++ b/app/src/main/java/org/asteroidos/sync/MainActivity.java @@ -432,7 +432,7 @@ protected void onPause() { } @Override - public void onConfigurationChanged(Configuration newConfig) { + public void onConfigurationChanged(@NonNull Configuration newConfig) { super.onConfigurationChanged(newConfig); getDelegate().onConfigurationChanged(newConfig); int currentNightMode = newConfig.uiMode & Configuration.UI_MODE_NIGHT_MASK; diff --git a/app/src/main/java/org/asteroidos/sync/PermissionsActivity.java b/app/src/main/java/org/asteroidos/sync/PermissionsActivity.java index 06b71a65..54472e70 100644 --- a/app/src/main/java/org/asteroidos/sync/PermissionsActivity.java +++ b/app/src/main/java/org/asteroidos/sync/PermissionsActivity.java @@ -34,6 +34,7 @@ import android.view.View; import android.view.ViewGroup; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.core.content.ContextCompat; @@ -200,7 +201,7 @@ static public class NotificationsSlide extends SlideFragment { @Nullable @Override - public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { Bundle bundle = new Bundle(); bundle.putInt("background_color", R.color.colorintroslide4); bundle.putInt("buttons_color", R.color.colorintroslide4button); @@ -240,7 +241,7 @@ static public class BatteryOptimSlide extends SlideFragment { @Nullable @Override - public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { Bundle bundle = new Bundle(); bundle.putInt("background_color", R.color.colorintroslide5); bundle.putInt("buttons_color", R.color.colorintroslide5button); diff --git a/app/src/main/java/org/asteroidos/sync/fragments/AppListFragment.java b/app/src/main/java/org/asteroidos/sync/fragments/AppListFragment.java index 05ecfc90..4cd5e433 100644 --- a/app/src/main/java/org/asteroidos/sync/fragments/AppListFragment.java +++ b/app/src/main/java/org/asteroidos/sync/fragments/AppListFragment.java @@ -20,6 +20,8 @@ import android.content.Context; import android.os.Bundle; + +import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import android.view.LayoutInflater; @@ -38,7 +40,7 @@ public class AppListFragment extends Fragment { View placeholder; @Override - public void onAttach(Context context) { + public void onAttach(@NonNull Context context) { super.onAttach(context); adapter = new AppInfoAdapter(context, R.layout.app_list_item, MainActivity.appInfoList); adapter.restoreFilter(); diff --git a/app/src/main/java/org/asteroidos/sync/fragments/DeviceDetailFragment.java b/app/src/main/java/org/asteroidos/sync/fragments/DeviceDetailFragment.java index c60833ac..92cdbcf9 100644 --- a/app/src/main/java/org/asteroidos/sync/fragments/DeviceDetailFragment.java +++ b/app/src/main/java/org/asteroidos/sync/fragments/DeviceDetailFragment.java @@ -33,6 +33,7 @@ import android.widget.LinearLayout; import android.widget.TextView; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.cardview.widget.CardView; import androidx.fragment.app.Fragment; @@ -164,7 +165,7 @@ public void onViewCreated(View view, Bundle savedInstanceState) { } @Override - public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + public void onCreateOptionsMenu(@NonNull Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.device_detail_manu, menu); super.onCreateOptionsMenu(menu, inflater); } @@ -226,7 +227,7 @@ public void scanningStopped() { } @Override - public void onAttach(Context context) { + public void onAttach(@NonNull Context context) { super.onAttach(context); if (context instanceof DeviceDetailFragment.OnDefaultDeviceUnselectedListener) mDeviceListener = (DeviceDetailFragment.OnDefaultDeviceUnselectedListener) context; diff --git a/app/src/main/java/org/asteroidos/sync/fragments/DeviceListFragment.java b/app/src/main/java/org/asteroidos/sync/fragments/DeviceListFragment.java index e3e9404a..5e6755ea 100644 --- a/app/src/main/java/org/asteroidos/sync/fragments/DeviceListFragment.java +++ b/app/src/main/java/org/asteroidos/sync/fragments/DeviceListFragment.java @@ -29,6 +29,7 @@ import android.widget.ListView; import android.widget.TextView; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; @@ -109,7 +110,7 @@ public void deviceUndiscovered(BluetoothDevice dev) { } @Override - public void onAttach(Context context) { + public void onAttach(@NonNull Context context) { super.onAttach(context); if (context instanceof OnDefaultDeviceSelectedListener) mDeviceListener = (OnDefaultDeviceSelectedListener) context; diff --git a/app/src/main/java/org/asteroidos/sync/fragments/WeatherSettingsFragment.java b/app/src/main/java/org/asteroidos/sync/fragments/WeatherSettingsFragment.java index 67e0e3e9..0f021f11 100644 --- a/app/src/main/java/org/asteroidos/sync/fragments/WeatherSettingsFragment.java +++ b/app/src/main/java/org/asteroidos/sync/fragments/WeatherSettingsFragment.java @@ -156,7 +156,7 @@ public void onPause() { } @Override - public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + public void onCreateOptionsMenu(@NonNull Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.owm_position_picker_menu, menu); super.onCreateOptionsMenu(menu, inflater); } diff --git a/app/src/main/java/org/asteroidos/sync/utils/AppInfo.java b/app/src/main/java/org/asteroidos/sync/utils/AppInfo.java index e365467d..8381805d 100644 --- a/app/src/main/java/org/asteroidos/sync/utils/AppInfo.java +++ b/app/src/main/java/org/asteroidos/sync/utils/AppInfo.java @@ -48,6 +48,7 @@ public int compareTo(@NonNull AppInfo appInfo) { return label.compareToIgnoreCase(appInfo.getLabel()); } + @NonNull public String toString() { return label + " : " + packageName; } From 93bd2821910eed3315ad1d3202cf2a463ade3281 Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 18:18:38 -0500 Subject: [PATCH 26/42] Use requireActivity in DeviceDetailFragment --- .../sync/fragments/DeviceDetailFragment.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/asteroidos/sync/fragments/DeviceDetailFragment.java b/app/src/main/java/org/asteroidos/sync/fragments/DeviceDetailFragment.java index 92cdbcf9..981c6b5f 100644 --- a/app/src/main/java/org/asteroidos/sync/fragments/DeviceDetailFragment.java +++ b/app/src/main/java/org/asteroidos/sync/fragments/DeviceDetailFragment.java @@ -114,7 +114,7 @@ public void onViewCreated(View view, Bundle savedInstanceState) { Intent iremove = new Intent("org.asteroidos.sync.NOTIFICATION_LISTENER"); iremove.putExtra("event", "removed"); iremove.putExtra("id", 0xa57e401d); - getActivity().sendBroadcast(iremove); + requireActivity().sendBroadcast(iremove); Intent ipost = new Intent("org.asteroidos.sync.NOTIFICATION_LISTENER"); ipost.putExtra("event", "posted"); @@ -124,16 +124,16 @@ public void onViewCreated(View view, Bundle savedInstanceState) { ipost.putExtra("appIcon", "ios-watch-vibrating"); ipost.putExtra("summary", getString(R.string.watch_finder)); ipost.putExtra("body", getString(R.string.phone_is_searching)); - getActivity().sendBroadcast(ipost); + requireActivity().sendBroadcast(ipost); }); CardView screenshotCard = view.findViewById(R.id.card_view3); - screenshotCard.setOnClickListener(view1 -> getActivity().sendBroadcast(new Intent("org.asteroidos.sync.SCREENSHOT_REQUEST_LISTENER"))); + screenshotCard.setOnClickListener(view1 -> requireActivity().sendBroadcast(new Intent("org.asteroidos.sync.SCREENSHOT_REQUEST_LISTENER"))); CardView notifSettCard = view.findViewById(R.id.card_view4); notifSettCard.setOnClickListener(notifSettCardView -> mAppSettingsListener.onAppSettingsClicked()); - mTimeSyncSettings = getActivity().getSharedPreferences(TimeService.PREFS_NAME, 0); + mTimeSyncSettings = requireActivity().getSharedPreferences(TimeService.PREFS_NAME, 0); CheckBox mTimeSyncCheckBox = view.findViewById(R.id.timeSyncCheckBox); mTimeSyncCheckBox.setChecked(mTimeSyncSettings.getBoolean(TimeService.PREFS_SYNC_TIME, TimeService.PREFS_SYNC_TIME_DEFAULT)); @@ -143,7 +143,7 @@ public void onViewCreated(View view, Bundle savedInstanceState) { editor.apply(); }); - mSilenceModeSettings = getActivity().getSharedPreferences(SilentModeService.PREFS_NAME, Context.MODE_PRIVATE); + mSilenceModeSettings = requireActivity().getSharedPreferences(SilentModeService.PREFS_NAME, Context.MODE_PRIVATE); CheckBox mSilenceModeCheckBox = view.findViewById(R.id.SilentModeCheckBox); mSilenceModeCheckBox.setChecked(mSilenceModeSettings.getBoolean(SilentModeService.PREF_RINGER, false)); mSilenceModeCheckBox.setOnCheckedChangeListener((buttonView, isChecked) -> { @@ -152,7 +152,7 @@ public void onViewCreated(View view, Bundle savedInstanceState) { editor.apply(); }); - mCallStateSettings = getActivity().getSharedPreferences(PhoneStateReceiver.PREFS_NAME, Context.MODE_PRIVATE); + mCallStateSettings = requireActivity().getSharedPreferences(PhoneStateReceiver.PREFS_NAME, Context.MODE_PRIVATE); CheckBox mCallStateServiceCheckBox = view.findViewById(R.id.CallStateServiceCheckBox); mCallStateServiceCheckBox.setChecked(mCallStateSettings.getBoolean(PhoneStateReceiver.PREF_SEND_CALL_STATE, true)); mCallStateServiceCheckBox.setOnCheckedChangeListener((buttonView, isChecked) -> { @@ -179,7 +179,7 @@ public boolean onOptionsItemSelected(MenuItem menuItem) { } public void setLocalName(String name) { - getActivity().setTitle(name); + requireActivity().setTitle(name); } public void setStatus(IAsteroidDevice.ConnectionState status) { From ad474edacdcd431741a7b966cd6e4791381c4f42 Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 18:19:36 -0500 Subject: [PATCH 27/42] mDetailFragment = not null in MainActivity.onDefaultDeviceSelected --- app/src/main/java/org/asteroidos/sync/MainActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/org/asteroidos/sync/MainActivity.java b/app/src/main/java/org/asteroidos/sync/MainActivity.java index 6a407c7c..e44d7b7b 100644 --- a/app/src/main/java/org/asteroidos/sync/MainActivity.java +++ b/app/src/main/java/org/asteroidos/sync/MainActivity.java @@ -193,7 +193,7 @@ public void onDefaultDeviceSelected(BluetoothDevice mDevice) { mDetailFragment = new DeviceDetailFragment(); if (mListFragment != null) mListFragment.scanningStopped(); - else if (mDetailFragment != null) mDetailFragment.scanningStopped(); + else mDetailFragment.scanningStopped(); getSupportFragmentManager() .beginTransaction() From 073a1cffbc6231e72edc1bfe3f02f09d6d0a36e7 Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 18:22:59 -0500 Subject: [PATCH 28/42] Use requireActivity & requireContext in WeatherSettingsFragment --- .../sync/fragments/WeatherSettingsFragment.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/asteroidos/sync/fragments/WeatherSettingsFragment.java b/app/src/main/java/org/asteroidos/sync/fragments/WeatherSettingsFragment.java index 0f021f11..711f3e1b 100644 --- a/app/src/main/java/org/asteroidos/sync/fragments/WeatherSettingsFragment.java +++ b/app/src/main/java/org/asteroidos/sync/fragments/WeatherSettingsFragment.java @@ -69,7 +69,7 @@ public class WeatherSettingsFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup parent, @Nullable Bundle savedInstanceState) { - mSettings = getContext().getSharedPreferences(WeatherService.PREFS_NAME, 0); + mSettings = requireActivity().getSharedPreferences(WeatherService.PREFS_NAME, 0); setHasOptionsMenu(true); return inflater.inflate(R.layout.fragment_position_picker, parent, false); @@ -92,14 +92,14 @@ public void onViewCreated(View view, Bundle savedInstanceState) { mMapView.getController().setZoom(zoom); mMapView.getController().setCenter(new GeoPoint(latitude, longitude)); - if (ContextCompat.checkSelfPermission(getActivity(), + if (ContextCompat.checkSelfPermission(requireActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { - ActivityCompat.requestPermissions(getActivity(), + ActivityCompat.requestPermissions(requireActivity(), new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, WEATHER_LOCATION_PERMISSION_REQUEST); } else { - MyLocationNewOverlay mLocationOverlay = new MyLocationNewOverlay(new GpsMyLocationProvider(getContext()), mMapView); + MyLocationNewOverlay mLocationOverlay = new MyLocationNewOverlay(new GpsMyLocationProvider(requireContext()), mMapView); mLocationOverlay.enableMyLocation(); mMapView.getOverlays().add(mLocationOverlay); } @@ -194,7 +194,7 @@ private void handleLocationToggle(boolean enable) { editor.putBoolean(WeatherService.PREFS_SYNC_WEATHER, enable); editor.apply(); mButton.setVisibility(enable ? View.INVISIBLE : View.VISIBLE); - getActivity().sendBroadcast(new Intent(WeatherService.WEATHER_SYNC_INTENT)); + requireActivity().sendBroadcast(new Intent(WeatherService.WEATHER_SYNC_INTENT)); } @Override @@ -215,7 +215,7 @@ public void onRequestPermissionsResult(int requestCode, case WEATHER_LOCATION_PERMISSION_REQUEST: { if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - MyLocationNewOverlay mLocationOverlay = new MyLocationNewOverlay(new GpsMyLocationProvider(getContext()), mMapView); + MyLocationNewOverlay mLocationOverlay = new MyLocationNewOverlay(new GpsMyLocationProvider(requireContext()), mMapView); mLocationOverlay.enableMyLocation(); mMapView.getOverlays().add(mLocationOverlay); } From 8a49a138ed913697b13ed1662f96f7f7628d415c Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 18:24:20 -0500 Subject: [PATCH 29/42] Inline supported boolean in AsteroidBleManager --- .../sync/asteroid/AsteroidBleManager.java | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/org/asteroidos/sync/asteroid/AsteroidBleManager.java b/app/src/main/java/org/asteroidos/sync/asteroid/AsteroidBleManager.java index a52c6666..07550758 100644 --- a/app/src/main/java/org/asteroidos/sync/asteroid/AsteroidBleManager.java +++ b/app/src/main/java/org/asteroidos/sync/asteroid/AsteroidBleManager.java @@ -101,7 +101,6 @@ the characteristics in the isRequiredServiceSupported() function. */ public final boolean isRequiredServiceSupported(@NonNull final BluetoothGatt gatt) { final BluetoothGattService batteryService = gatt.getService(AsteroidUUIDS.BATTERY_SERVICE_UUID); - boolean supported = true; boolean notify = false; if (batteryService != null) { @@ -137,8 +136,7 @@ public final boolean isRequiredServiceSupported(@NonNull final BluetoothGatt gat }); } - supported = (batteryCharacteristic != null && notify); - return supported; + return (batteryCharacteristic != null && notify); } @Override @@ -152,20 +150,20 @@ protected final void initialize() { .enqueue(); setNotificationCallback(batteryCharacteristic).with(((device, data) -> setBatteryLevel(data))); - // Do not call readCharacteristic(batteryCharacteristic) here. - // Otherwise, on Android 12 and later, the BLE bond to the watch - // is lost, and communication no longer works. Arguably, reading - // and writing should not be done in initialize(), since it is - // part of the BLE manager's connect() request. Instead, do those - // IO operations _after_ that request finishes (-> read the - // characteristic in the SynchronizationService class, which is - // where the BLE manager's connect() function is called). + // Do not call readCharacteristic(batteryCharacteristic) here. + // Otherwise, on Android 12 and later, the BLE bond to the watch + // is lost, and communication no longer works. Arguably, reading + // and writing should not be done in initialize(), since it is + // part of the BLE manager's connect() request. Instead, do those + // IO operations _after_ that request finishes (-> read the + // characteristic in the SynchronizationService class, which is + // where the BLE manager's connect() function is called). enableNotifications(batteryCharacteristic).enqueue(); // Let all services know that we are connected. try { mSynchronizationService.syncServices(); - } catch (Exception e){ + } catch (Exception e) { e.printStackTrace(); } } From 27eb2d12092f2f40c1796abf9530df561ecc6a2a Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 18:24:51 -0500 Subject: [PATCH 30/42] Remove redundant default value for msgType & id in Notification --- .../java/org/asteroidos/sync/dataobjects/Notification.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/asteroidos/sync/dataobjects/Notification.java b/app/src/main/java/org/asteroidos/sync/dataobjects/Notification.java index 21263e08..3365b580 100644 --- a/app/src/main/java/org/asteroidos/sync/dataobjects/Notification.java +++ b/app/src/main/java/org/asteroidos/sync/dataobjects/Notification.java @@ -22,8 +22,8 @@ public class Notification { String packageName, appName, appIcon, summary, body, vibration = ""; - MsgType msgType = null; - int id = 0; + MsgType msgType; + int id; public Notification(MsgType msgType, String packageName, int id, String appName, String appIcon, String summary, String body, String vibration) { this.msgType = msgType; From daf11a611180f92f2c768d8c469b106afd9bb26d Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 18:27:09 -0500 Subject: [PATCH 31/42] Remove redundant byte setting in ScreenshotService --- .../java/org/asteroidos/sync/connectivity/ScreenshotService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/org/asteroidos/sync/connectivity/ScreenshotService.java b/app/src/main/java/org/asteroidos/sync/connectivity/ScreenshotService.java index 840ee31d..929eca7c 100644 --- a/app/src/main/java/org/asteroidos/sync/connectivity/ScreenshotService.java +++ b/app/src/main/java/org/asteroidos/sync/connectivity/ScreenshotService.java @@ -251,7 +251,6 @@ public void onReceive(Context context, Intent intent) { mFirstNotify = true; mDownloading = true; byte[] data = new byte[1]; - data[0] = 0x0; mDevice.send(AsteroidUUIDS.SCREENSHOT_REQUEST, data, ScreenshotService.this); } } From ef03207686e39267450a1f7e43132bef88670a19 Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 18:28:39 -0500 Subject: [PATCH 32/42] Make msgType & id in Notification final --- .../java/org/asteroidos/sync/dataobjects/Notification.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/asteroidos/sync/dataobjects/Notification.java b/app/src/main/java/org/asteroidos/sync/dataobjects/Notification.java index 3365b580..0b38f517 100644 --- a/app/src/main/java/org/asteroidos/sync/dataobjects/Notification.java +++ b/app/src/main/java/org/asteroidos/sync/dataobjects/Notification.java @@ -22,8 +22,8 @@ public class Notification { String packageName, appName, appIcon, summary, body, vibration = ""; - MsgType msgType; - int id; + final MsgType msgType; + final int id; public Notification(MsgType msgType, String packageName, int id, String appName, String appIcon, String summary, String body, String vibration) { this.msgType = msgType; From 8388d662d52956de9714dc18f5d4ccb1fe3ff80c Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 18:28:59 -0500 Subject: [PATCH 33/42] Clean imports --- .../java/org/asteroidos/sync/fragments/AppListFragment.java | 1 - .../org/asteroidos/sync/fragments/WeatherSettingsFragment.java | 1 - app/src/main/java/org/asteroidos/sync/utils/AppInfoHelper.java | 1 - .../main/java/org/asteroidos/sync/utils/NotificationParser.java | 2 -- 4 files changed, 5 deletions(-) diff --git a/app/src/main/java/org/asteroidos/sync/fragments/AppListFragment.java b/app/src/main/java/org/asteroidos/sync/fragments/AppListFragment.java index 4cd5e433..ee6a5b8c 100644 --- a/app/src/main/java/org/asteroidos/sync/fragments/AppListFragment.java +++ b/app/src/main/java/org/asteroidos/sync/fragments/AppListFragment.java @@ -27,7 +27,6 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.Filter; import android.widget.ListView; import org.asteroidos.sync.MainActivity; diff --git a/app/src/main/java/org/asteroidos/sync/fragments/WeatherSettingsFragment.java b/app/src/main/java/org/asteroidos/sync/fragments/WeatherSettingsFragment.java index 711f3e1b..61c42cd9 100644 --- a/app/src/main/java/org/asteroidos/sync/fragments/WeatherSettingsFragment.java +++ b/app/src/main/java/org/asteroidos/sync/fragments/WeatherSettingsFragment.java @@ -41,7 +41,6 @@ import android.view.ViewGroup; import android.widget.Button; import android.widget.CheckBox; -import android.widget.CompoundButton; import android.widget.EditText; import org.asteroidos.sync.R; diff --git a/app/src/main/java/org/asteroidos/sync/utils/AppInfoHelper.java b/app/src/main/java/org/asteroidos/sync/utils/AppInfoHelper.java index f2b75353..e3296083 100644 --- a/app/src/main/java/org/asteroidos/sync/utils/AppInfoHelper.java +++ b/app/src/main/java/org/asteroidos/sync/utils/AppInfoHelper.java @@ -32,7 +32,6 @@ import android.util.Log; import java.util.ArrayList; -import java.util.Collections; import java.util.Comparator; import java.util.List; diff --git a/app/src/main/java/org/asteroidos/sync/utils/NotificationParser.java b/app/src/main/java/org/asteroidos/sync/utils/NotificationParser.java index 17082cec..14f1b668 100644 --- a/app/src/main/java/org/asteroidos/sync/utils/NotificationParser.java +++ b/app/src/main/java/org/asteroidos/sync/utils/NotificationParser.java @@ -31,8 +31,6 @@ import java.lang.reflect.Field; import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; import java.util.List; // Originally from https://github.com/matejdro/PebbleNotificationCenter-Android written by Matej Drobnič under the terms of the GPLv3 From b8d26085de9211a8fc45d0c64525af00ce5e24ad Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 18:29:28 -0500 Subject: [PATCH 34/42] Use method references instead of lambas in TimeService & WeatherService --- .../main/java/org/asteroidos/sync/connectivity/TimeService.java | 2 +- .../java/org/asteroidos/sync/connectivity/WeatherService.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/asteroidos/sync/connectivity/TimeService.java b/app/src/main/java/org/asteroidos/sync/connectivity/TimeService.java index b0695d25..38f3558c 100644 --- a/app/src/main/java/org/asteroidos/sync/connectivity/TimeService.java +++ b/app/src/main/java/org/asteroidos/sync/connectivity/TimeService.java @@ -61,7 +61,7 @@ public TimeService(Context ctx, IAsteroidDevice device) { @Override public final void sync() { Handler handler = new Handler(); - handler.postDelayed(() -> updateTime(), 500); + handler.postDelayed(this::updateTime, 500); // Register a broadcast handler to use for the alarm Intent // Also listen for TIME_CHANGED and TIMEZONE_CHANGED events diff --git a/app/src/main/java/org/asteroidos/sync/connectivity/WeatherService.java b/app/src/main/java/org/asteroidos/sync/connectivity/WeatherService.java index 02a37595..733a067a 100644 --- a/app/src/main/java/org/asteroidos/sync/connectivity/WeatherService.java +++ b/app/src/main/java/org/asteroidos/sync/connectivity/WeatherService.java @@ -133,7 +133,7 @@ private void updateWeather() { // We don't have a valid Location yet // Use the old location until we have a new one, recheck in 2 Minutes Handler handler = new Handler(); - handler.postDelayed(() -> updateWeather(), 1000 * 60 * 2); + handler.postDelayed(this::updateWeather, 1000 * 60 * 2); return; } } From 67537bf429c1b0f0b9fd3a469d726f4c7930abb5 Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 18:35:07 -0500 Subject: [PATCH 35/42] Update gradle --- build.gradle.kts | 4 ++-- gradle/wrapper/gradle-wrapper.properties | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index e1a873fb..17f3a412 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,8 +5,8 @@ buildscript { google() } dependencies { - classpath("com.android.tools.build:gradle:7.3.0") - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21") + classpath("com.android.tools.build:gradle:7.4.1") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21") } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 73cd3fa1..d6c35de1 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip From ac26174cf496a991596766f237a1031da5508b30 Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 18:36:05 -0500 Subject: [PATCH 36/42] Update to java 11 --- app/build.gradle.kts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 4e5d1f06..af9ca720 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -35,8 +35,8 @@ android { } compileOptions { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 } lint { checkReleaseBuilds = true From 907ec67c4c91407af3bc7d3f0212ace1605e5e98 Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 18:36:18 -0500 Subject: [PATCH 37/42] Upgrade appcompat to 1.6.0 --- app/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index af9ca720..4ed3e70e 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -54,7 +54,7 @@ repositories { dependencies { implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar")))) testImplementation("junit:junit:4.13.2") - implementation("androidx.appcompat:appcompat:1.5.1") + implementation("androidx.appcompat:appcompat:1.6.0") implementation("androidx.legacy:legacy-support-v4:1.0.0") implementation("androidx.cardview:cardview:1.0.0") implementation("com.google.android.material:material:1.6.1") From 8629841abf6b09d5cf34c223f2786068de3009c3 Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 18:36:31 -0500 Subject: [PATCH 38/42] Upgrade material to 1.8.0 --- app/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 4ed3e70e..2d4238ca 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -57,7 +57,7 @@ dependencies { implementation("androidx.appcompat:appcompat:1.6.0") implementation("androidx.legacy:legacy-support-v4:1.0.0") implementation("androidx.cardview:cardview:1.0.0") - implementation("com.google.android.material:material:1.6.1") + implementation("com.google.android.material:material:1.8.0") implementation("com.github.MagneFire:EasyWeather:1.3") implementation("com.google.code.gson:gson:2.9.1") implementation("org.osmdroid:osmdroid-android:6.1.14") From 5dc5228d8579cc7a0b5c13027d1e607fd8d063f9 Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 18:38:06 -0500 Subject: [PATCH 39/42] Use <> instead of in AppInfo Parcelable.Creator --- app/src/main/java/org/asteroidos/sync/utils/AppInfo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/org/asteroidos/sync/utils/AppInfo.java b/app/src/main/java/org/asteroidos/sync/utils/AppInfo.java index 8381805d..142889c2 100644 --- a/app/src/main/java/org/asteroidos/sync/utils/AppInfo.java +++ b/app/src/main/java/org/asteroidos/sync/utils/AppInfo.java @@ -64,7 +64,7 @@ public void writeToParcel(Parcel out, int flags) { out.writeParcelable(icon, flags); } - public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { + public static final Parcelable.Creator CREATOR = new Parcelable.Creator<>() { public AppInfo createFromParcel(Parcel in) { return new AppInfo(in); } From 6cc66ea43ea52a5fb5c3aa70ee703238fd9ed982 Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 18:38:41 -0500 Subject: [PATCH 40/42] Use auto resource management with try body --- .../asteroidos/sync/connectivity/ScreenshotService.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/asteroidos/sync/connectivity/ScreenshotService.java b/app/src/main/java/org/asteroidos/sync/connectivity/ScreenshotService.java index 929eca7c..7cc10748 100644 --- a/app/src/main/java/org/asteroidos/sync/connectivity/ScreenshotService.java +++ b/app/src/main/java/org/asteroidos/sync/connectivity/ScreenshotService.java @@ -18,6 +18,7 @@ package org.asteroidos.sync.connectivity; +import android.annotation.SuppressLint; import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; @@ -194,14 +195,14 @@ private Uri createFile(byte[] totalData) throws IOException { metaInfo.put(MediaStore.Images.Media.DATE_TAKEN, System.currentTimeMillis()); Uri imageUri = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI , metaInfo); assert imageUri != null; + @SuppressLint("Recycle") OutputStream out = resolver.openOutputStream(imageUri); - assert out != null; - try { + try (out) { + assert out != null; out.write(totalData); } catch (IOException ioe) { ioe.printStackTrace(); } finally { - out.close(); uri = imageUri; } } else { From 4e9642da405a5c73a05f25cecfd43a7331cbb241 Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 18:41:50 -0500 Subject: [PATCH 41/42] Sleep spin in NLService to prevent cpu overuse --- .../asteroidos/sync/services/NLService.java | 40 ++++++++++++------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/org/asteroidos/sync/services/NLService.java b/app/src/main/java/org/asteroidos/sync/services/NLService.java index 800d24dd..d8626c73 100644 --- a/app/src/main/java/org/asteroidos/sync/services/NLService.java +++ b/app/src/main/java/org/asteroidos/sync/services/NLService.java @@ -26,6 +26,7 @@ import android.content.IntentFilter; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; +import android.os.Build; import android.os.Handler; import android.service.notification.NotificationListenerService; import android.service.notification.StatusBarNotification; @@ -37,6 +38,7 @@ import java.util.Arrays; import java.util.Hashtable; import java.util.Map; +import java.util.concurrent.TimeUnit; public class NLService extends NotificationListenerService { private NLServiceReceiver nlServiceReceiver; @@ -159,11 +161,11 @@ public void onNotificationPosted(StatusBarNotification sbn) { String packageName = sbn.getPackageName(); String[] allowedOngoingApps = {"com.google.android.apps.maps", "org.thoughtcrime.securesms"}; - if((notification.priority < Notification.PRIORITY_DEFAULT) || - ((notification.flags & Notification.FLAG_ONGOING_EVENT) != 0 - && !Arrays.asList(allowedOngoingApps).contains(packageName)) || - (NotificationCompat.getLocalOnly(notification)) || - (NotificationCompat.isGroupSummary(notification))) + if ((notification.priority < Notification.PRIORITY_DEFAULT) || + ((notification.flags & Notification.FLAG_ONGOING_EVENT) != 0 + && !Arrays.asList(allowedOngoingApps).contains(packageName)) || + (NotificationCompat.getLocalOnly(notification)) || + (NotificationCompat.isGroupSummary(notification))) return; NotificationParser notifParser = new NotificationParser(notification); @@ -177,16 +179,17 @@ public void onNotificationPosted(StatusBarNotification sbn) { final PackageManager pm = getApplicationContext().getPackageManager(); ApplicationInfo ai = pm.getApplicationInfo(packageName, 0); appName = pm.getApplicationLabel(ai).toString(); - } catch (PackageManager.NameNotFoundException ignored) {} + } catch (PackageManager.NameNotFoundException ignored) { + } - if(summary == null) summary = ""; - else summary = summary.trim(); - if(body == null) body = ""; - else body = body.trim(); - if(packageName == null) packageName = ""; - if(appIcon == null) appIcon = ""; + if (summary == null) summary = ""; + else summary = summary.trim(); + if (body == null) body = ""; + else body = body.trim(); + if (packageName == null) packageName = ""; + if (appIcon == null) appIcon = ""; - Intent i = new Intent("org.asteroidos.sync.NOTIFICATION_LISTENER"); + Intent i = new Intent("org.asteroidos.sync.NOTIFICATION_LISTENER"); i.putExtra("event", "posted"); i.putExtra("packageName", packageName); i.putExtra("id", id); @@ -225,9 +228,16 @@ public void onReceive(Context context, Intent intent) { if (intent.getStringExtra("command").equals("refresh")) { Handler handler = new Handler(); handler.postDelayed(() -> { - while (!listenerConnected); + while (!listenerConnected) { + // Sleep the spin + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + Thread.onSpinWait(); + }else { + // Will not delay here, as we can cause the entire UI to freeze + } + } StatusBarNotification[] notifs = getActiveNotifications(); - for(StatusBarNotification notif : notifs) + for (StatusBarNotification notif : notifs) onNotificationPosted(notif); }, 500); } From d5755facfc06abfebee3f083333dbf11a598f402 Mon Sep 17 00:00:00 2001 From: doomsdayrs Date: Mon, 6 Feb 2023 22:10:56 -0500 Subject: [PATCH 42/42] Implement view model foundation --- app/build.gradle.kts | 4 + .../org/asteroidos/sync/MainActivity.java | 90 +++----------- .../org/asteroidos/sync/common/ext/Log.kt | 113 ++++++++++++++++++ .../repository/base/MessageRepository.kt | 82 +++++++++++++ .../repository/base/WatchStatusRepository.kt | 60 ++++++++++ .../repository/impl/MessageRepositoryImpl.kt | 64 ++++++++++ .../impl/WatchStatusRepositoryImpl.kt | 44 +++++++ .../sync/services/SynchronizationService.java | 93 +++++--------- .../viewmodel/base/MainActivityViewModel.kt | 75 ++++++++++++ .../base/SynchronizationServiceModel.kt | 77 ++++++++++++ .../impl/MainActivityViewModelImpl.kt | 104 ++++++++++++++++ .../impl/SynchronizationServiceModelImpl.kt | 97 +++++++++++++++ build.gradle.kts | 2 +- 13 files changed, 764 insertions(+), 141 deletions(-) create mode 100644 app/src/main/java/org/asteroidos/sync/common/ext/Log.kt create mode 100644 app/src/main/java/org/asteroidos/sync/domain/repository/base/MessageRepository.kt create mode 100644 app/src/main/java/org/asteroidos/sync/domain/repository/base/WatchStatusRepository.kt create mode 100644 app/src/main/java/org/asteroidos/sync/domain/repository/impl/MessageRepositoryImpl.kt create mode 100644 app/src/main/java/org/asteroidos/sync/domain/repository/impl/WatchStatusRepositoryImpl.kt create mode 100644 app/src/main/java/org/asteroidos/sync/viewmodel/base/MainActivityViewModel.kt create mode 100644 app/src/main/java/org/asteroidos/sync/viewmodel/base/SynchronizationServiceModel.kt create mode 100644 app/src/main/java/org/asteroidos/sync/viewmodel/impl/MainActivityViewModelImpl.kt create mode 100644 app/src/main/java/org/asteroidos/sync/viewmodel/impl/SynchronizationServiceModelImpl.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 2d4238ca..2da65c64 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -1,5 +1,6 @@ plugins { id("com.android.application") + kotlin("android") } android { @@ -53,6 +54,9 @@ repositories { dependencies { implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar")))) + implementation("androidx.core:core-ktx:1.9.0") + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4") + implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1") testImplementation("junit:junit:4.13.2") implementation("androidx.appcompat:appcompat:1.6.0") implementation("androidx.legacy:legacy-support-v4:1.0.0") diff --git a/app/src/main/java/org/asteroidos/sync/MainActivity.java b/app/src/main/java/org/asteroidos/sync/MainActivity.java index e44d7b7b..e5bc8ffe 100644 --- a/app/src/main/java/org/asteroidos/sync/MainActivity.java +++ b/app/src/main/java/org/asteroidos/sync/MainActivity.java @@ -18,6 +18,8 @@ package org.asteroidos.sync; +import static android.os.ParcelUuid.fromString; + import android.Manifest; import android.app.AlertDialog; import android.bluetooth.BluetoothAdapter; @@ -35,10 +37,7 @@ import android.os.Handler; import android.os.IBinder; import android.os.Looper; -import android.os.Message; -import android.os.Messenger; import android.os.ParcelUuid; -import android.os.RemoteException; import android.provider.Settings; import android.util.Log; import android.view.MenuItem; @@ -53,6 +52,7 @@ import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentTransaction; +import androidx.lifecycle.ViewModelProvider; import org.asteroidos.sync.asteroid.IAsteroidDevice; import org.asteroidos.sync.fragments.AppListFragment; @@ -63,6 +63,8 @@ import org.asteroidos.sync.utils.AppInfo; import org.asteroidos.sync.utils.AppInfoHelper; import org.asteroidos.sync.utils.AsteroidUUIDS; +import org.asteroidos.sync.viewmodel.base.MainActivityViewModel; +import org.asteroidos.sync.viewmodel.impl.MainActivityViewModelImpl; import java.util.ArrayList; import java.util.List; @@ -73,8 +75,6 @@ import no.nordicsemi.android.support.v18.scanner.ScanResult; import no.nordicsemi.android.support.v18.scanner.ScanSettings; -import static android.os.ParcelUuid.fromString; - public class MainActivity extends AppCompatActivity implements DeviceListFragment.OnDefaultDeviceSelectedListener, DeviceListFragment.OnScanRequestedListener, DeviceDetailFragment.OnDefaultDeviceUnselectedListener, DeviceDetailFragment.OnConnectRequestedListener, DeviceDetailFragment.OnAppSettingsClickedListener, @@ -85,21 +85,17 @@ public class MainActivity extends AppCompatActivity implements DeviceListFragmen public static final String PREFS_DEFAULT_LOC_NAME = "defaultLocalName"; private static final String TAG = "MainActivity"; public static ArrayList appInfoList; - final Messenger mDeviceDetailMessenger = new Messenger(new MainActivity.SynchronizationHandler(this)); public final ParcelUuid asteroidUUID = fromString(AsteroidUUIDS.SERVICE_UUID.toString()); - Messenger mSyncServiceMessenger; ActivityResultLauncher mLocationEnableActivityLauncher; LocationManager mLocationManager; /* Synchronization service events handling */ private final ServiceConnection mConnection = new ServiceConnection() { public void onServiceConnected(ComponentName className, IBinder service) { - mSyncServiceMessenger = new Messenger(service); onUpdateRequested(); } public void onServiceDisconnected(ComponentName className) { - mSyncServiceMessenger = null; } }; Intent mSyncServiceIntent; @@ -128,11 +124,16 @@ public void onScanResult(int callbackType, @NonNull ScanResult result) { private Fragment mPreviousFragment; private BluetoothLeScannerCompat mScanner; private SharedPreferences mPrefs; + MainActivityViewModel viewModel; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + viewModel = new ViewModelProvider(this).get(MainActivityViewModelImpl.class); + viewModel.onWatchLocalNameChanged(this::handleSetLocalName); + viewModel.onWatchConnectionStateChanged(this::handleSetStatus); + viewModel.onWatchBatteryPercentageChanged(this::handleSetBatteryPercentage); mScanner = BluetoothLeScannerCompat.getScanner(); @@ -200,13 +201,7 @@ public void onDefaultDeviceSelected(BluetoothDevice mDevice) { .replace(R.id.flContainer, mDetailFragment) .commit(); - try { - Message msg = Message.obtain(null, SynchronizationService.MSG_SET_DEVICE); - msg.obj = mDevice; - msg.replyTo = mDeviceDetailMessenger; - mSyncServiceMessenger.send(msg); - } catch (RemoteException ignored) { - } + viewModel.onDefaultDeviceSelected(mDevice); onConnectRequested(); @@ -223,13 +218,7 @@ public void onDefaultDeviceUnselected() { .replace(R.id.flContainer, mListFragment) .commit(); - try { - Message msg = Message.obtain(null, SynchronizationService.MSG_UNSET_DEVICE); - msg.obj = ""; - msg.replyTo = mDeviceDetailMessenger; - mSyncServiceMessenger.send(msg); - } catch (RemoteException ignored) { - } + viewModel.requestUnsetDevice(); mDetailFragment = null; setTitle(R.string.app_name); @@ -237,35 +226,19 @@ public void onDefaultDeviceUnselected() { @Override public void onUpdateRequested() { - try { - Message msg = Message.obtain(null, SynchronizationService.MSG_UPDATE); - msg.replyTo = mDeviceDetailMessenger; - if (mSyncServiceMessenger != null) - mSyncServiceMessenger.send(msg); - } catch (RemoteException ignored) { - } + viewModel.requestUpdate(); } @Override public void onConnectRequested() { if (mScanner != null) mScanner.stopScan(scanCallback); - try { - Message msg = Message.obtain(null, SynchronizationService.MSG_CONNECT); - msg.replyTo = mDeviceDetailMessenger; - mSyncServiceMessenger.send(msg); - } catch (RemoteException ignored) { - } + viewModel.requestConnect(); } @Override public void onDisconnectRequested() { - try { - Message msg = Message.obtain(null, SynchronizationService.MSG_DISCONNECT); - msg.replyTo = mDeviceDetailMessenger; - mSyncServiceMessenger.send(msg); - } catch (RemoteException ignored) { - } + viewModel.requestDisconnect(); } @Override @@ -356,12 +329,7 @@ private void handleSetStatus(IAsteroidDevice.ConnectionState status) { mStatus = status; } if (status == IAsteroidDevice.ConnectionState.STATUS_CONNECTED) { - try { - Message msg = Message.obtain(null, SynchronizationService.MSG_REQUEST_BATTERY_LIFE); - msg.replyTo = mDeviceDetailMessenger; - mSyncServiceMessenger.send(msg); - } catch (RemoteException ignored) { - } + viewModel.requestBatteryLevel(); } } @@ -449,30 +417,4 @@ public void onConfigurationChanged(@NonNull Configuration newConfig) { overridePendingTransition(0, 0); startActivity(getIntent()); } - - static private class SynchronizationHandler extends Handler { - private final MainActivity mActivity; - - SynchronizationHandler(MainActivity activity) { - super(Looper.getMainLooper()); - mActivity = activity; - } - - @Override - public void handleMessage(Message msg) { - switch (msg.what) { - case SynchronizationService.MSG_SET_LOCAL_NAME: - mActivity.handleSetLocalName((String) msg.obj); - break; - case SynchronizationService.MSG_SET_STATUS: - mActivity.handleSetStatus((IAsteroidDevice.ConnectionState) msg.obj); - break; - case SynchronizationService.MSG_SET_BATTERY_PERCENTAGE: - mActivity.handleSetBatteryPercentage(msg.arg1); - break; - default: - super.handleMessage(msg); - } - } - } } diff --git a/app/src/main/java/org/asteroidos/sync/common/ext/Log.kt b/app/src/main/java/org/asteroidos/sync/common/ext/Log.kt new file mode 100644 index 00000000..0f3187cd --- /dev/null +++ b/app/src/main/java/org/asteroidos/sync/common/ext/Log.kt @@ -0,0 +1,113 @@ +/* + * This file is part of shosetsu & asteroidOS (imported to) + * + * shosetsu is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * shosetsu 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with shosetsu. If not, see . + * + * 14 / 08 / 2020 + */ +package org.asteroidos.sync.common.ext + +import android.util.Log.* +import java.io.PrintStream + +const val NULL_METHOD_NAME = "UnknownMethod" + +var fileOut: PrintStream? = null + +const val CRESET: String = "\u001B[0m" +const val CRED: String = "\u001B[31m" + +fun writeT(t: Throwable? = null) { + if (t != null) + fileOut?.println(t.stackTraceToString()) +} + +@Suppress("unused") +inline fun T.logI(message: String?, t: Throwable? = null): Int { + val name = Thread.currentThread().stackTrace[2].methodName ?: NULL_METHOD_NAME + val msg = "${name}:\t$message" + val tag = T::class.java.simpleName + + fileOut?.println("i:\t$tag:\t$msg") + + writeT(t) + + return i(tag, msg, t) +} + +@Suppress("unused") +inline fun T.logD(message: String?, t: Throwable? = null): Int { + val name = Thread.currentThread().stackTrace[2].methodName ?: NULL_METHOD_NAME + val msg = "${name}:\t$message" + val tag = T::class.java.simpleName + + fileOut?.println("D:\t$tag:\t$msg") + + writeT(t) + + return d(tag, msg, t) +} + +@Suppress("unused") +inline fun T.logE(message: String?, t: Throwable? = null): Int { + val name = Thread.currentThread().stackTrace[2].methodName ?: NULL_METHOD_NAME + val msg = "${name}:\t$message" + val tag = T::class.java.simpleName + + fileOut?.println("${CRED}e:\t$tag:\t$msg${CRESET}") + + writeT(t) + + return e(tag, msg, t) +} + +@Suppress("unused") +inline fun T.logW(message: String?, t: Throwable? = null): Int { + val name = Thread.currentThread().stackTrace[2].methodName ?: NULL_METHOD_NAME + val msg = "${name}:\t$message" + val tag = T::class.java.simpleName + + fileOut?.println("w:\t$tag:\t$msg") + + writeT(t) + + return w(tag, msg, t) +} + +@Suppress("unused") +inline fun T.logV(message: String?, t: Throwable? = null): Int { + val name = Thread.currentThread().stackTrace[2].methodName ?: NULL_METHOD_NAME + val msg = "${name}:\t$message" + val tag = T::class.java.simpleName + + fileOut?.println("v:\t$tag:\t$msg") + + writeT(t) + + return v(tag, msg, t) +} + +@Suppress("unused") +inline fun T.logWTF(message: String?, t: Throwable? = null): Int { + val name = Thread.currentThread().stackTrace[2].methodName ?: NULL_METHOD_NAME + val msg = "${name}:\t$message" + val tag = T::class.java.simpleName + + fileOut?.println("wtf:\t$tag:\t$msg") + + writeT(t) + + return wtf(tag, msg, t) +} + diff --git a/app/src/main/java/org/asteroidos/sync/domain/repository/base/MessageRepository.kt b/app/src/main/java/org/asteroidos/sync/domain/repository/base/MessageRepository.kt new file mode 100644 index 00000000..f2942a70 --- /dev/null +++ b/app/src/main/java/org/asteroidos/sync/domain/repository/base/MessageRepository.kt @@ -0,0 +1,82 @@ +/* + * AsteroidOSSync + * Copyright (c) 2023 AsteroidOS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.asteroidos.sync.domain.repository.base + +import android.bluetooth.BluetoothDevice +import kotlinx.coroutines.flow.Flow +import org.asteroidos.sync.domain.repository.impl.MessageRepositoryImpl +import org.asteroidos.sync.domain.repository.impl.WatchStatusRepositoryImpl + +/** + * Source of truth for all inter app message communication using flows. + */ +interface MessageRepository { + /** + * Emits when a device is selected + */ + val requestSetDeviceFlow: Flow + + fun requestSetDevice(device: BluetoothDevice) + + /** + * Emits when device should be unset + */ + val requestUnsetDeviceFlow: Flow + + fun requestUnsetDevice() + + /** + * Emits when a device update is requested + */ + val requestUpdateDeviceFlow: Flow + + fun requestUpdateDevice() + + /** + * Emits when a device should be connected to + */ + val requestConnectFlow: Flow + + fun requestConnect() + + /** + * Emits when a device should be disconnected from + */ + val requestDisconnectFlow: Flow + + fun requestDisconnect() + + /** + * Emits when a battery life update is requested + */ + val requestBatteryLifeFlow: Flow + + fun requestBatteryLife() + + companion object { + private var repo: MessageRepository? = null + + fun get(): MessageRepository { + if (repo == null) + repo = MessageRepositoryImpl() + + return repo!! + } + } +} \ No newline at end of file diff --git a/app/src/main/java/org/asteroidos/sync/domain/repository/base/WatchStatusRepository.kt b/app/src/main/java/org/asteroidos/sync/domain/repository/base/WatchStatusRepository.kt new file mode 100644 index 00000000..18821a6a --- /dev/null +++ b/app/src/main/java/org/asteroidos/sync/domain/repository/base/WatchStatusRepository.kt @@ -0,0 +1,60 @@ +/* + * AsteroidOSSync + * Copyright (c) 2023 AsteroidOS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.asteroidos.sync.domain.repository.base + +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.StateFlow +import org.asteroidos.sync.asteroid.IAsteroidDevice +import org.asteroidos.sync.asteroid.IAsteroidDevice.ConnectionState +import org.asteroidos.sync.domain.repository.impl.WatchStatusRepositoryImpl + +/** + * Source of truth on watch status + */ +interface WatchStatusRepository { + /** + * Battery percentage state + */ + val batteryPercentage: StateFlow + + fun setBatteryPercentage(batteryPercentage: Int) + + /** + * Connection state + */ + val connectionState: StateFlow + fun setConnectionState(state: ConnectionState) + + /** + * Device name + */ + val deviceName: StateFlow + fun setDeviceName(name: String) + + companion object { + private var repo: WatchStatusRepository? = null + + fun get(): WatchStatusRepository { + if (repo == null) + repo = WatchStatusRepositoryImpl() + + return repo!! + } + } +} \ No newline at end of file diff --git a/app/src/main/java/org/asteroidos/sync/domain/repository/impl/MessageRepositoryImpl.kt b/app/src/main/java/org/asteroidos/sync/domain/repository/impl/MessageRepositoryImpl.kt new file mode 100644 index 00000000..a9232830 --- /dev/null +++ b/app/src/main/java/org/asteroidos/sync/domain/repository/impl/MessageRepositoryImpl.kt @@ -0,0 +1,64 @@ +/* + * AsteroidOSSync + * Copyright (c) 2023 AsteroidOS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.asteroidos.sync.domain.repository.impl + +import android.bluetooth.BluetoothDevice +import kotlinx.coroutines.flow.* +import org.asteroidos.sync.domain.repository.base.MessageRepository + +class MessageRepositoryImpl : MessageRepository { + private val _requestSetDeviceFlow = MutableStateFlow(null) + + override val requestSetDeviceFlow: Flow = + _requestSetDeviceFlow.filterNotNull() + + override fun requestSetDevice(device: BluetoothDevice) { + _requestSetDeviceFlow.value = device + } + + override val requestUnsetDeviceFlow: MutableStateFlow = MutableStateFlow(0) + + override fun requestUnsetDevice() { + requestUnsetDeviceFlow.value = requestUnsetDeviceFlow.value++ + } + + override val requestUpdateDeviceFlow: MutableStateFlow = MutableStateFlow(0) + + override fun requestUpdateDevice() { + requestUpdateDeviceFlow.value = requestUpdateDeviceFlow.value++ + } + + override val requestConnectFlow: MutableStateFlow = MutableStateFlow(0) + + override fun requestConnect() { + requestConnectFlow.value = requestConnectFlow.value++ + } + + override val requestDisconnectFlow: MutableStateFlow = MutableStateFlow(0) + + override fun requestDisconnect() { + requestDisconnectFlow.value = requestDisconnectFlow.value++ + } + + override val requestBatteryLifeFlow: MutableStateFlow = MutableStateFlow(0) + + override fun requestBatteryLife() { + requestBatteryLifeFlow.value = requestBatteryLifeFlow.value++ + } +} \ No newline at end of file diff --git a/app/src/main/java/org/asteroidos/sync/domain/repository/impl/WatchStatusRepositoryImpl.kt b/app/src/main/java/org/asteroidos/sync/domain/repository/impl/WatchStatusRepositoryImpl.kt new file mode 100644 index 00000000..2c75f372 --- /dev/null +++ b/app/src/main/java/org/asteroidos/sync/domain/repository/impl/WatchStatusRepositoryImpl.kt @@ -0,0 +1,44 @@ +/* + * AsteroidOSSync + * Copyright (c) 2023 AsteroidOS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.asteroidos.sync.domain.repository.impl + +import kotlinx.coroutines.flow.MutableStateFlow +import org.asteroidos.sync.asteroid.IAsteroidDevice.ConnectionState +import org.asteroidos.sync.domain.repository.base.WatchStatusRepository + +class WatchStatusRepositoryImpl : WatchStatusRepository { + + override val batteryPercentage: MutableStateFlow = MutableStateFlow(0) + + override fun setBatteryPercentage(batteryPercentage: Int) { + this.batteryPercentage.value = batteryPercentage + } + + override val connectionState = MutableStateFlow(ConnectionState.STATUS_DISCONNECTED) + + override fun setConnectionState(state: ConnectionState) { + connectionState.value = state + } + + override val deviceName = MutableStateFlow("") + + override fun setDeviceName(name: String) { + deviceName.value = name + } +} \ No newline at end of file diff --git a/app/src/main/java/org/asteroidos/sync/services/SynchronizationService.java b/app/src/main/java/org/asteroidos/sync/services/SynchronizationService.java index f1894900..6831fc71 100644 --- a/app/src/main/java/org/asteroidos/sync/services/SynchronizationService.java +++ b/app/src/main/java/org/asteroidos/sync/services/SynchronizationService.java @@ -29,12 +29,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.os.Build; -import android.os.Handler; import android.os.IBinder; -import android.os.Looper; -import android.os.Message; -import android.os.Messenger; -import android.os.RemoteException; import android.util.Log; import androidx.annotation.NonNull; @@ -53,6 +48,8 @@ import org.asteroidos.sync.connectivity.SilentModeService; import org.asteroidos.sync.connectivity.TimeService; import org.asteroidos.sync.connectivity.WeatherService; +import org.asteroidos.sync.viewmodel.base.SynchronizationServiceModel; +import org.asteroidos.sync.viewmodel.impl.SynchronizationServiceModelImpl; import java.util.ArrayList; import java.util.Arrays; @@ -75,7 +72,6 @@ public class SynchronizationService extends Service implements IAsteroidDevice, public static final int MSG_UNSET_DEVICE = 9; private static final String NOTIFICATION_CHANNEL_ID = "synchronizationservice_channel_id_01"; - final Messenger mMessenger = new Messenger(new SynchronizationHandler(this)); private final int NOTIFICATION = 2725; public BluetoothDevice mDevice; public int batteryPercentage = 0; @@ -83,16 +79,18 @@ public class SynchronizationService extends Service implements IAsteroidDevice, List nonBleServices; private NotificationManager mNM; private ConnectionState mState = ConnectionState.STATUS_DISCONNECTED; - private Messenger replyTo; private SharedPreferences mPrefs; private AsteroidBleManager mBleMngr; + private final SynchronizationServiceModel model = new SynchronizationServiceModelImpl(); + final void handleConnect() { if (mBleMngr == null) { mBleMngr = new AsteroidBleManager(getApplicationContext(), SynchronizationService.this); mBleMngr.setConnectionObserver(this); } - if (mState == ConnectionState.STATUS_CONNECTED || mState == ConnectionState.STATUS_CONNECTING) return; + if (mState == ConnectionState.STATUS_CONNECTED || mState == ConnectionState.STATUS_CONNECTING) + return; mPrefs = getSharedPreferences(MainActivity.PREFS_NAME, Context.MODE_PRIVATE); String defaultDevMacAddr = mPrefs.getString(MainActivity.PREFS_DEFAULT_MAC_ADDR, ""); @@ -107,9 +105,9 @@ final void handleConnect() { .retry(3, 200) .done(device1 -> { Log.d(TAG, "Connected to " + device1.getName()); - // Now we read the current values of the GATT characteristics, - // _after_ the connection has been fully established, to avoid - // connection failures on Android 12 and later. + // Now we read the current values of the GATT characteristics, + // _after_ the connection has been fully established, to avoid + // connection failures on Android 12 and later. mBleMngr.readCharacteristics(); }) .fail((device2, error) -> Log.e(TAG, "Failed to connect to " + device.getName() + @@ -136,11 +134,8 @@ final void handleSetDevice(BluetoothDevice device) { mDevice = device; try { String name = mDevice.getName(); - Message answer = Message.obtain(null, MSG_SET_LOCAL_NAME); - answer.obj = name; - replyTo.send(answer); - replyTo.send(Message.obtain(null, MSG_SET_STATUS, mState)); - } catch (RemoteException | SecurityException | NullPointerException ignored) { + model.setLocalName(name); + } catch (SecurityException | NullPointerException ignored) { } editor.putString(MainActivity.PREFS_DEFAULT_LOC_NAME, name); editor.apply(); @@ -148,10 +143,7 @@ final void handleSetDevice(BluetoothDevice device) { final void handleUpdateConnectionStatus() { if (mDevice != null) { - try { - replyTo.send(Message.obtain(null, MSG_SET_STATUS, mState)); - } catch (RemoteException | NullPointerException ignored) { - } + model.setConnectionState(mState); } } @@ -289,6 +281,13 @@ public void onCreate() { handleConnect(); updateNotification(); + + model.onConnectRequested(this::handleConnect); + model.onDisconnectRequested(this::handleDisconnect); + model.onBatteryLifeRequested(this::handleUpdateBatteryPercentageRequest); + model.onDeviceSetRequested(this::handleSetDevice); + model.onDeviceUnsetRequested(this::handleUnSetDevice); + model.onDeviceUpdateRequested(this::handleUpdateConnectionStatus); } @Override @@ -338,7 +337,7 @@ public void onDestroy() { @Override public IBinder onBind(Intent intent) { - return mMessenger.getBinder(); + return null; } @Override @@ -359,53 +358,15 @@ private void handleUnSetDevice() { editor.apply(); } + public void handleUpdateBatteryPercentageRequest() { + AsteroidBleManager.BatteryLevelEvent batteryLevelEvent = new AsteroidBleManager.BatteryLevelEvent(); + batteryLevelEvent.battery = batteryPercentage; + handleUpdateBatteryPercentage(batteryLevelEvent); + } + public void handleUpdateBatteryPercentage(AsteroidBleManager.BatteryLevelEvent battery) { Log.d(TAG, "handleBattery: " + battery.battery + "%"); batteryPercentage = battery.battery; - try { - if (replyTo != null) - replyTo.send(Message.obtain(null, MSG_SET_BATTERY_PERCENTAGE, batteryPercentage, 0)); - } catch (RemoteException e) { - e.printStackTrace(); - } - } - - static private class SynchronizationHandler extends Handler { - private final SynchronizationService mService; - - SynchronizationHandler(SynchronizationService service) { - super(Looper.getMainLooper()); - mService = service; - } - - @Override - public void handleMessage(Message msg) { - mService.replyTo = msg.replyTo; - - switch (msg.what) { - case MSG_CONNECT: - mService.handleConnect(); - break; - case MSG_DISCONNECT: - mService.handleDisconnect(); - break; - case MSG_REQUEST_BATTERY_LIFE: - AsteroidBleManager.BatteryLevelEvent batteryLevelEvent = new AsteroidBleManager.BatteryLevelEvent(); - batteryLevelEvent.battery = mService.batteryPercentage; - mService.handleUpdateBatteryPercentage(batteryLevelEvent); - break; - case MSG_SET_DEVICE: - mService.handleSetDevice((BluetoothDevice) msg.obj); - break; - case MSG_UNSET_DEVICE: - mService.handleUnSetDevice(); - break; - case MSG_UPDATE: - mService.handleUpdateConnectionStatus(); - break; - default: - super.handleMessage(msg); - } - } + model.setBatteryPercentage(batteryPercentage); } } diff --git a/app/src/main/java/org/asteroidos/sync/viewmodel/base/MainActivityViewModel.kt b/app/src/main/java/org/asteroidos/sync/viewmodel/base/MainActivityViewModel.kt new file mode 100644 index 00000000..32eaf44e --- /dev/null +++ b/app/src/main/java/org/asteroidos/sync/viewmodel/base/MainActivityViewModel.kt @@ -0,0 +1,75 @@ +/* + * AsteroidOSSync + * Copyright (c) 2023 AsteroidOS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.asteroidos.sync.viewmodel.base + +import android.bluetooth.BluetoothDevice +import androidx.lifecycle.ViewModel +import org.asteroidos.sync.asteroid.IAsteroidDevice +import java.util.function.Consumer + +/** + * View model for the main activity + */ +abstract class MainActivityViewModel : ViewModel() { + + /** + * Listen to changes to local name + */ + abstract fun onWatchLocalNameChanged(consumer: Consumer) + + /** + * Listen to connection state changes + */ + abstract fun onWatchConnectionStateChanged(consumer: Consumer) + + /** + * Listen to battery percentage changes + */ + abstract fun onWatchBatteryPercentageChanged(consumer: Consumer) + + /** + * Request the device to be disconnected + */ + abstract fun requestDisconnect() + + /** + * Request to connect to the device + */ + abstract fun requestConnect() + + /** + * Request an update from the device + */ + abstract fun requestUpdate() + + /** + * Request the device to be unset + */ + abstract fun requestUnsetDevice() + + /** + * Select device + */ + abstract fun onDefaultDeviceSelected(mDevice: BluetoothDevice) + + /** + * Request battery level of the device + */ + abstract fun requestBatteryLevel() +} \ No newline at end of file diff --git a/app/src/main/java/org/asteroidos/sync/viewmodel/base/SynchronizationServiceModel.kt b/app/src/main/java/org/asteroidos/sync/viewmodel/base/SynchronizationServiceModel.kt new file mode 100644 index 00000000..e699495e --- /dev/null +++ b/app/src/main/java/org/asteroidos/sync/viewmodel/base/SynchronizationServiceModel.kt @@ -0,0 +1,77 @@ +/* + * AsteroidOSSync + * Copyright (c) 2023 AsteroidOS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.asteroidos.sync.viewmodel.base + +import android.bluetooth.BluetoothDevice +import androidx.core.util.Consumer +import kotlinx.coroutines.Runnable +import org.asteroidos.sync.asteroid.IAsteroidDevice +import org.asteroidos.sync.asteroid.IAsteroidDevice.ConnectionState + +/** + * Model for the synchronization service to bind to kotlin flows. + * In the future this can be removed. + */ +interface SynchronizationServiceModel { + + /** + * Listen to connection requests + */ + fun onConnectRequested(consumer: Runnable) + + /** + * Listen to disconnect requests + */ + fun onDisconnectRequested(consumer: Runnable) + + /** + * Listen to battery life requests + */ + fun onBatteryLifeRequested(consumer: Runnable) + + /** + * Listen to device set requests + */ + fun onDeviceSetRequested(consumer: Consumer) + + /** + * Listen to device unset requests + */ + fun onDeviceUnsetRequested(consumer: Runnable) + + /** + * Listen to device update requests + */ + fun onDeviceUpdateRequested(consumer: Runnable) + + /** + * Set the local name + */ + fun setLocalName(name: String) + + /** + * Set the device connection state + */ + fun setConnectionState(state: ConnectionState) + + /** + * Set the battery percentage + */ + fun setBatteryPercentage(percentage: Int) +} \ No newline at end of file diff --git a/app/src/main/java/org/asteroidos/sync/viewmodel/impl/MainActivityViewModelImpl.kt b/app/src/main/java/org/asteroidos/sync/viewmodel/impl/MainActivityViewModelImpl.kt new file mode 100644 index 00000000..0abbeb17 --- /dev/null +++ b/app/src/main/java/org/asteroidos/sync/viewmodel/impl/MainActivityViewModelImpl.kt @@ -0,0 +1,104 @@ +/* + * AsteroidOSSync + * Copyright (c) 2023 AsteroidOS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.asteroidos.sync.viewmodel.impl + +import android.bluetooth.BluetoothDevice +import androidx.lifecycle.viewModelScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import org.asteroidos.sync.asteroid.IAsteroidDevice +import org.asteroidos.sync.common.ext.logV +import org.asteroidos.sync.domain.repository.base.MessageRepository +import org.asteroidos.sync.domain.repository.base.WatchStatusRepository +import org.asteroidos.sync.viewmodel.base.MainActivityViewModel +import java.util.function.Consumer + +/** + * Implementation of the main activity view model + * + * TODO use android DI framework + */ +class MainActivityViewModelImpl( + private val messageRepo: MessageRepository = MessageRepository.get(), + private val watchStatusRepo: WatchStatusRepository = WatchStatusRepository.get() +) : MainActivityViewModel() { + + override fun onWatchLocalNameChanged(consumer: Consumer) { + viewModelScope.launch(Dispatchers.IO) { + watchStatusRepo.deviceName.collect { + logV("onWatchLocalNameChanged") + viewModelScope.launch { + consumer.accept(it) + } + } + } + } + + override fun onWatchConnectionStateChanged(consumer: Consumer) { + viewModelScope.launch(Dispatchers.IO) { + watchStatusRepo.connectionState.collect { + logV("onWatchConnectionStateChanged") + viewModelScope.launch { + consumer.accept(it) + } + } + } + } + + override fun onWatchBatteryPercentageChanged(consumer: Consumer) { + viewModelScope.launch(Dispatchers.IO) { + watchStatusRepo.batteryPercentage.collect { + logV("onWatchBatteryPercentageChanged") + viewModelScope.launch { + consumer.accept(it) + } + } + } + } + + override fun requestDisconnect() { + logV("") + messageRepo.requestDisconnect() + } + + override fun requestConnect() { + logV("") + messageRepo.requestConnect() + } + + override fun requestUpdate() { + logV("") + messageRepo.requestUpdateDevice() + } + + override fun requestUnsetDevice() { + logV("") + messageRepo.requestUnsetDevice() + } + + override fun onDefaultDeviceSelected(mDevice: BluetoothDevice) { + logV("") + messageRepo.requestSetDevice(mDevice) + } + + override fun requestBatteryLevel() { + logV("") + messageRepo.requestBatteryLife() + } +} \ No newline at end of file diff --git a/app/src/main/java/org/asteroidos/sync/viewmodel/impl/SynchronizationServiceModelImpl.kt b/app/src/main/java/org/asteroidos/sync/viewmodel/impl/SynchronizationServiceModelImpl.kt new file mode 100644 index 00000000..1bb6d1d8 --- /dev/null +++ b/app/src/main/java/org/asteroidos/sync/viewmodel/impl/SynchronizationServiceModelImpl.kt @@ -0,0 +1,97 @@ +/* + * AsteroidOSSync + * Copyright (c) 2023 AsteroidOS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.asteroidos.sync.viewmodel.impl + +import android.bluetooth.BluetoothDevice +import androidx.core.util.Consumer +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.Runnable +import kotlinx.coroutines.launch +import org.asteroidos.sync.asteroid.IAsteroidDevice.ConnectionState +import org.asteroidos.sync.domain.repository.base.MessageRepository +import org.asteroidos.sync.domain.repository.base.WatchStatusRepository +import org.asteroidos.sync.viewmodel.base.SynchronizationServiceModel + +class SynchronizationServiceModelImpl( + private val messageRepo: MessageRepository = MessageRepository.get(), + private val watchStatusRepo: WatchStatusRepository = WatchStatusRepository.get() +) : SynchronizationServiceModel { + private val modelScope = CoroutineScope(Dispatchers.IO) + + override fun onConnectRequested(consumer: Runnable) { + modelScope.launch { + messageRepo.requestConnectFlow.collect { + consumer.run() + } + } + } + + override fun onDisconnectRequested(consumer: Runnable) { + modelScope.launch { + messageRepo.requestDisconnectFlow.collect { + consumer.run() + } + } + } + + override fun onBatteryLifeRequested(consumer: Runnable) { + modelScope.launch { + messageRepo.requestBatteryLifeFlow.collect { + consumer.run() + } + } + } + + override fun onDeviceSetRequested(consumer: Consumer) { + modelScope.launch { + messageRepo.requestSetDeviceFlow.collect { + consumer.accept(it) + } + } + } + + override fun onDeviceUnsetRequested(consumer: Runnable) { + modelScope.launch { + messageRepo.requestUnsetDeviceFlow.collect { + consumer.run() + } + } + } + + override fun onDeviceUpdateRequested(consumer: Runnable) { + modelScope.launch { + messageRepo.requestUpdateDeviceFlow.collect { + consumer.run() + } + } + } + + override fun setLocalName(name: String) { + watchStatusRepo.setDeviceName(name) + } + + override fun setConnectionState(state: ConnectionState) { + watchStatusRepo.setConnectionState(state) + } + + override fun setBatteryPercentage(percentage: Int) { + watchStatusRepo.setBatteryPercentage(percentage) + } +} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 17f3a412..5f423d05 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,7 +6,7 @@ buildscript { } dependencies { classpath("com.android.tools.build:gradle:7.4.1") - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.10") } }