diff options
author | Luis Vidal <lvidal@cyngn.com> | 2016-06-17 17:57:46 -0700 |
---|---|---|
committer | Luis Vidal <lvidal@cyngn.com> | 2016-06-17 18:00:39 -0700 |
commit | 3e0e7fcbd0946de689fc5fec5a71f5fcdc0af815 (patch) | |
tree | 0d8e6e98bb8b1c5249f86a70fbdeb658d288215c /src | |
parent | 875f16e15ac94a04ce6f98912b63abe97167fc3c (diff) | |
download | android_packages_apps_LockClock-3e0e7fcbd0946de689fc5fec5a71f5fcdc0af815.tar.gz android_packages_apps_LockClock-3e0e7fcbd0946de689fc5fec5a71f5fcdc0af815.tar.bz2 android_packages_apps_LockClock-3e0e7fcbd0946de689fc5fec5a71f5fcdc0af815.zip |
Verifies if weather service is available
Checks if the weather service is available in the device to make
sure we don't spend time trying to update the weather or update
the widget.
Change-Id: I3f9adcfa260fea5cde62c0a45b355fd6946c69f1
Diffstat (limited to 'src')
4 files changed, 43 insertions, 7 deletions
diff --git a/src/com/cyanogenmod/lockclock/ClockWidgetProvider.java b/src/com/cyanogenmod/lockclock/ClockWidgetProvider.java index c2ea11c..fbab355 100644 --- a/src/com/cyanogenmod/lockclock/ClockWidgetProvider.java +++ b/src/com/cyanogenmod/lockclock/ClockWidgetProvider.java @@ -27,6 +27,7 @@ import com.cyanogenmod.lockclock.misc.Constants; import com.cyanogenmod.lockclock.misc.Preferences; import com.cyanogenmod.lockclock.misc.WidgetUtils; import com.cyanogenmod.lockclock.weather.ForecastActivity; +import com.cyanogenmod.lockclock.weather.Utils; import com.cyanogenmod.lockclock.weather.WeatherSourceListenerService; import com.cyanogenmod.lockclock.weather.WeatherUpdateService; @@ -49,7 +50,8 @@ public class ClockWidgetProvider extends AppWidgetProvider { if (D) Log.v(TAG, "Received intent " + intent); // Network connection has changed, make sure the weather update service knows about it - if (ConnectivityManager.CONNECTIVITY_ACTION.equals(action)) { + if (ConnectivityManager.CONNECTIVITY_ACTION.equals(action) + && Utils.isWeatherServiceAvailable(context)) { boolean hasConnection = !intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false); @@ -123,8 +125,10 @@ public class ClockWidgetProvider extends AppWidgetProvider { @Override public void onEnabled(Context context) { if (D) Log.d(TAG, "Scheduling next weather update"); - context.startService(new Intent(context, WeatherSourceListenerService.class)); - WeatherUpdateService.scheduleNextUpdate(context, true); + if (Utils.isWeatherServiceAvailable(context)) { + context.startService(new Intent(context, WeatherSourceListenerService.class)); + WeatherUpdateService.scheduleNextUpdate(context, true); + } // Start the broadcast receiver (API 16 devices) // This will schedule a repeating alarm every minute to handle the clock refresh @@ -138,9 +142,11 @@ public class ClockWidgetProvider extends AppWidgetProvider { @Override public void onDisabled(Context context) { if (D) Log.d(TAG, "Cleaning up: Clearing all pending alarms"); - context.stopService(new Intent(context, WeatherSourceListenerService.class)); - ClockWidgetService.cancelUpdates(context); - WeatherUpdateService.cancelUpdates(context); + if (Utils.isWeatherServiceAvailable(context)) { + context.stopService(new Intent(context, WeatherSourceListenerService.class)); + ClockWidgetService.cancelUpdates(context); + WeatherUpdateService.cancelUpdates(context); + } // Stop the clock update event (API 16 devices) if (!WidgetUtils.isTextClockAvailable()) { diff --git a/src/com/cyanogenmod/lockclock/misc/Preferences.java b/src/com/cyanogenmod/lockclock/misc/Preferences.java index 49a4632..0e1062e 100644 --- a/src/com/cyanogenmod/lockclock/misc/Preferences.java +++ b/src/com/cyanogenmod/lockclock/misc/Preferences.java @@ -19,6 +19,7 @@ package com.cyanogenmod.lockclock.misc; import android.content.Context; import android.content.SharedPreferences; import android.graphics.Color; +import com.cyanogenmod.lockclock.weather.Utils; import cyanogenmod.weather.WeatherInfo; import cyanogenmod.weather.WeatherLocation; import org.json.JSONArray; @@ -72,7 +73,8 @@ public class Preferences { } public static boolean showWeather(Context context) { - return getPrefs(context).getBoolean(Constants.SHOW_WEATHER, true); + return getPrefs(context).getBoolean(Constants.SHOW_WEATHER, true) + && Utils.isWeatherServiceAvailable(context); } public static boolean showCalendar(Context context) { diff --git a/src/com/cyanogenmod/lockclock/preference/Preferences.java b/src/com/cyanogenmod/lockclock/preference/Preferences.java index a138c75..dc70081 100644 --- a/src/com/cyanogenmod/lockclock/preference/Preferences.java +++ b/src/com/cyanogenmod/lockclock/preference/Preferences.java @@ -25,6 +25,7 @@ import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import com.cyanogenmod.lockclock.R; +import com.cyanogenmod.lockclock.weather.Utils; import java.util.List; @@ -37,6 +38,15 @@ public class Preferences extends PreferenceActivity { public void onBuildHeaders(List<Header> target) { loadHeadersFromResource(R.xml.preferences_headers, target); + if (!Utils.isWeatherServiceAvailable(this)) { + for (Header header : target) { + if (header.titleRes == R.string.weather_category) { + target.remove(header); + break; + } + } + } + // Check if triggered from adding a new widget Intent intent = getIntent(); if (intent != null diff --git a/src/com/cyanogenmod/lockclock/weather/Utils.java b/src/com/cyanogenmod/lockclock/weather/Utils.java index 411fe29..6c95867 100644 --- a/src/com/cyanogenmod/lockclock/weather/Utils.java +++ b/src/com/cyanogenmod/lockclock/weather/Utils.java @@ -19,6 +19,7 @@ package com.cyanogenmod.lockclock.weather; import android.content.Context; import android.content.res.Resources; import com.cyanogenmod.lockclock.R; +import cyanogenmod.app.CMContextConstants; import cyanogenmod.providers.WeatherContract; import static cyanogenmod.providers.WeatherContract.WeatherColumns.WeatherCode.NOT_AVAILABLE; @@ -42,6 +43,9 @@ public final class Utils { private static final double DIRECTION_WEST = 293d; private static final double DIRECTION_NORTH_WEST = 338d; + private static boolean weatherServiceFeatureCached; + private static boolean weatherServiceAvailable; + /** * Returns a localized string of the wind direction * @param context Application context to access resources @@ -178,4 +182,18 @@ public final class Utils { return NOT_AVAILABLE; } } + + /** + * Checks if the CM Weather service is available in this device + * @param context + * @return true if service is available, false otherwise + */ + public static boolean isWeatherServiceAvailable(Context context) { + if (!weatherServiceFeatureCached) { + weatherServiceAvailable = context.getPackageManager() + .hasSystemFeature(CMContextConstants.CM_WEATHER_SERVICE); + weatherServiceFeatureCached = true; + } + return weatherServiceAvailable; + } } |