From 19c207d671359371511e8063d84d6957eb3ee611 Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Mon, 30 Oct 2023 08:55:38 +0100 Subject: [PATCH 1/4] Remove DeviceStatusService --- app/src/main/AndroidManifest.xml | 1 - .../features/launcher/LauncherActivity.java | 7 -- .../features/weather/DeviceStatusService.java | 68 ------------------- .../features/weather/WeatherInfoView.java | 10 --- 4 files changed, 86 deletions(-) delete mode 100644 app/src/main/java/foundation/e/blisslauncher/features/weather/DeviceStatusService.java diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ae712d85e2..a6875c99df 100755 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -128,7 +128,6 @@ - diff --git a/app/src/main/java/foundation/e/blisslauncher/features/launcher/LauncherActivity.java b/app/src/main/java/foundation/e/blisslauncher/features/launcher/LauncherActivity.java index f74e5a067a..91753c8cac 100755 --- a/app/src/main/java/foundation/e/blisslauncher/features/launcher/LauncherActivity.java +++ b/app/src/main/java/foundation/e/blisslauncher/features/launcher/LauncherActivity.java @@ -75,7 +75,6 @@ import androidx.core.graphics.ColorUtils; import androidx.core.view.GestureDetectorCompat; import androidx.core.view.WindowInsetsCompat; import androidx.core.view.WindowInsetsControllerCompat; -import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import androidx.viewpager.widget.PagerAdapter; @@ -146,7 +145,6 @@ import foundation.e.blisslauncher.features.suggestions.SearchSuggestionUtil; import foundation.e.blisslauncher.features.suggestions.SuggestionProvider; import foundation.e.blisslauncher.features.suggestions.SuggestionsResult; import foundation.e.blisslauncher.features.usagestats.AppUsageStats; -import foundation.e.blisslauncher.features.weather.DeviceStatusService; import foundation.e.blisslauncher.features.weather.WeatherPreferences; import foundation.e.blisslauncher.features.weather.WeatherSourceListenerService; import foundation.e.blisslauncher.features.weather.WeatherUpdateService; @@ -176,7 +174,6 @@ public class LauncherActivity extends AppCompatActivity private static final int REQUEST_PERMISSION_CALL_PHONE = 14; private static final int REQUEST_LOCATION_SOURCE_SETTING = 267; private static final int STORAGE_PERMISSION_REQUEST_CODE = 586; - public static final String ACTION_LAUNCHER_RESUME = "foundation.e.blisslauncher.LauncherActivity.LAUNCHER_RESUME"; public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key"; public static final String EXTRA_SHOW_FRAGMENT_ARGS = ":settings:show_fragment_args"; public static final String NOTIFICATION_SETTING = "enabled_notification_listeners"; @@ -532,9 +529,6 @@ public class LauncherActivity extends AppCompatActivity refreshSuggestedApps(widgetsPage, forceRefreshSuggestedApps); } - final Intent resumeIntent = new Intent(ACTION_LAUNCHER_RESUME); - LocalBroadcastManager.getInstance(this).sendBroadcast(resumeIntent); - if (widgetContainer != null) { WidgetManager widgetManager = WidgetManager.getInstance(); Integer id = widgetManager.dequeRemoveId(); @@ -1474,7 +1468,6 @@ public class LauncherActivity extends AppCompatActivity if (WeatherUtils.isWeatherServiceAvailable(this)) { startService(new Intent(this, WeatherSourceListenerService.class)); - startService(new Intent(this, DeviceStatusService.class)); } if (!Preferences.useCustomWeatherLocation(this)) { diff --git a/app/src/main/java/foundation/e/blisslauncher/features/weather/DeviceStatusService.java b/app/src/main/java/foundation/e/blisslauncher/features/weather/DeviceStatusService.java deleted file mode 100644 index 5367100594..0000000000 --- a/app/src/main/java/foundation/e/blisslauncher/features/weather/DeviceStatusService.java +++ /dev/null @@ -1,68 +0,0 @@ -package foundation.e.blisslauncher.features.weather; - -import android.app.Service; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.net.ConnectivityManager; -import android.os.IBinder; -import foundation.e.blisslauncher.core.utils.Constants; -import timber.log.Timber; - -public class DeviceStatusService extends Service { - - private static final String TAG = DeviceStatusService.class.getSimpleName(); - private static final boolean D = Constants.DEBUG; - - private BroadcastReceiver mDeviceStatusListenerReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - String action = intent.getAction(); - - // Network connection has changed, make sure the weather update service knows - // about it - if (ConnectivityManager.CONNECTIVITY_ACTION.equals(action)) { - boolean hasConnection = !intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false); - - if (D) - Timber.tag(TAG).d("Got connectivity change, has connection: " + hasConnection); - - Intent i = new Intent(context, WeatherUpdateService.class); - if (hasConnection) { - context.startService(i); - } else { - context.stopService(i); - } - } - } - }; - - @Override - public void onCreate() { - IntentFilter deviceStatusFilter = new IntentFilter(); - deviceStatusFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); - deviceStatusFilter.addAction(Intent.ACTION_SCREEN_OFF); - deviceStatusFilter.addAction(Intent.ACTION_SCREEN_ON); - registerReceiver(mDeviceStatusListenerReceiver, deviceStatusFilter); - } - - @Override - public void onDestroy() { - if (D) - Timber.tag(TAG).d("Stopping service"); - unregisterReceiver(mDeviceStatusListenerReceiver); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - if (D) - Timber.tag(TAG).d("Starting service"); - return START_STICKY; - } - - @Override - public IBinder onBind(Intent intent) { - return null; - } -} diff --git a/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherInfoView.java b/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherInfoView.java index 54d8927ca1..89354bb2d4 100644 --- a/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherInfoView.java +++ b/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherInfoView.java @@ -12,7 +12,6 @@ import android.widget.TextView; import androidx.localbroadcastmanager.content.LocalBroadcastManager; import foundation.e.blisslauncher.R; import foundation.e.blisslauncher.core.Preferences; -import foundation.e.blisslauncher.features.launcher.LauncherActivity; import timber.log.Timber; public class WeatherInfoView extends LinearLayout { @@ -37,13 +36,6 @@ public class WeatherInfoView extends LinearLayout { } }; - private final BroadcastReceiver mResumeReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - updateWeatherPanel(); - } - }; - public WeatherInfoView(Context context, AttributeSet attrs) { super(context, attrs); } @@ -76,7 +68,6 @@ public class WeatherInfoView extends LinearLayout { intentFilter.addAction(WeatherUpdateService.ACTION_UPDATE_CITY_FINISHED); broadcastManager.registerReceiver(mWeatherReceiver, intentFilter); - broadcastManager.registerReceiver(mResumeReceiver, new IntentFilter(LauncherActivity.ACTION_LAUNCHER_RESUME)); updateWeatherPanel(); } @@ -85,7 +76,6 @@ public class WeatherInfoView extends LinearLayout { super.onDetachedFromWindow(); final LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(getContext()); broadcastManager.unregisterReceiver(mWeatherReceiver); - broadcastManager.unregisterReceiver(mResumeReceiver); } private void updateWeatherPanel() { -- GitLab From 9ebab9e5a552b5f06bbbaf996215d3e048d259b7 Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Mon, 30 Oct 2023 09:09:27 +0100 Subject: [PATCH 2/4] Increase weather check period --- .../e/blisslauncher/features/weather/WeatherUpdateService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherUpdateService.java b/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherUpdateService.java index 5668135c8a..4ba7fd5a4c 100644 --- a/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherUpdateService.java +++ b/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherUpdateService.java @@ -19,7 +19,7 @@ public class WeatherUpdateService extends Service { public static final String ACTION_UPDATE_CITY_FINISHED = "org.indin.blisslauncher.action.WEATHER_UPDATE_CITY_FINISHED"; public static final String EXTRA_UPDATE_CITY_KEY = "city"; - private static final long UPDATE_PERIOD_IN_MS = 5L * 1000L; + private static final long UPDATE_PERIOD_IN_MS = 60L * 1000L; private HandlerThread mHandlerThread; private Handler mHandler; -- GitLab From 2cccac6122deca2da998ed7060e4ce11dbeb715d Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Mon, 30 Oct 2023 09:10:36 +0100 Subject: [PATCH 3/4] Fallback to the previous weather location in background When a service is in background, location is only updated a few times every hour (https://developer.android.com/about/versions/oreo/background-location-limits). When the weather service was in background, the location returned was always null. We now fallback to the previous weather location. --- .../e/blisslauncher/features/weather/WeatherUpdater.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherUpdater.java b/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherUpdater.java index 1f68471460..1bb1f56b6c 100644 --- a/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherUpdater.java +++ b/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherUpdater.java @@ -49,6 +49,8 @@ public class WeatherUpdater { private long mLastWeatherUpdateInMs = 0; + private Location mLastLocation; + private static WeatherUpdater mInstance = null; public static WeatherUpdater getInstance(@NonNull Context context) { @@ -134,11 +136,16 @@ public class WeatherUpdater { } private synchronized void onNewLocationFetched(@Nullable Location location) { - if (location == null) { + if (location == null && mLastLocation == null) { Timber.tag(TAG).i("Could not fetch any location"); return; } + if (location != null) { + mLastLocation = location; + } + + location = mLastLocation; Timber.tag(TAG).i("New location fetched:%s", location); requestWeatherUpdate(location); -- GitLab From b7df3015d0021930f9b8890f8cd3487dd5009d24 Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Mon, 30 Oct 2023 13:14:14 +0100 Subject: [PATCH 4/4] Fix default weather update period to 15 min --- .../main/java/foundation/e/blisslauncher/core/Preferences.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/foundation/e/blisslauncher/core/Preferences.java b/app/src/main/java/foundation/e/blisslauncher/core/Preferences.java index 01bba9b348..0f6a5ce3d2 100644 --- a/app/src/main/java/foundation/e/blisslauncher/core/Preferences.java +++ b/app/src/main/java/foundation/e/blisslauncher/core/Preferences.java @@ -86,7 +86,7 @@ public class Preferences { } public static long weatherRefreshIntervalInMs(Context context) { - String value = getPrefs(context).getString(Constants.WEATHER_REFRESH_INTERVAL, "60"); + String value = getPrefs(context).getString(Constants.WEATHER_REFRESH_INTERVAL, "15"); return Long.parseLong(value) * 60L * 1000L; } -- GitLab