aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRoman Birg <roman@cyngn.com>2014-05-28 14:56:47 -0700
committerRoman Birg <roman@cyngn.com>2014-05-28 14:56:47 -0700
commitc5a4398fae1116f0db5a6fe2b3a36fb74c4b723d (patch)
treeb7f449895d7b65f2c895e9ebe48efc02c5a030f3 /src
parent2be8453fb49fe37695c8f0cf8ec8b3b791c57ee2 (diff)
downloadandroid_packages_apps_LockClock-c5a4398fae1116f0db5a6fe2b3a36fb74c4b723d.tar.gz
android_packages_apps_LockClock-c5a4398fae1116f0db5a6fe2b3a36fb74c4b723d.tar.bz2
android_packages_apps_LockClock-c5a4398fae1116f0db5a6fe2b3a36fb74c4b723d.zip
LockClock: do not use GPS if Play Services is available
In order to conserve battery, if the device has Play Services installed (including the case where Play Services is outdated), ignore the GPS location provider. Change-Id: Iaeaa936128b91d5def10d2177a887f25c6a748f8 Signed-off-by: Roman Birg <roman@cyngn.com>
Diffstat (limited to 'src')
-rwxr-xr-xsrc/com/cyanogenmod/lockclock/weather/WeatherUpdateService.java13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/com/cyanogenmod/lockclock/weather/WeatherUpdateService.java b/src/com/cyanogenmod/lockclock/weather/WeatherUpdateService.java
index d073d8c..64fd5c6 100755
--- a/src/com/cyanogenmod/lockclock/weather/WeatherUpdateService.java
+++ b/src/com/cyanogenmod/lockclock/weather/WeatherUpdateService.java
@@ -40,6 +40,8 @@ import com.cyanogenmod.lockclock.ClockWidgetProvider;
import com.cyanogenmod.lockclock.misc.Constants;
import com.cyanogenmod.lockclock.misc.Preferences;
import com.cyanogenmod.lockclock.misc.WidgetUtils;
+import com.google.android.gms.common.ConnectionResult;
+import com.google.android.gms.common.GooglePlayServicesUtil;
import java.util.Date;
@@ -181,6 +183,11 @@ public class WeatherUpdateService extends Service {
String locationProvider = lm.getBestProvider(sLocationCriteria, true);
if (TextUtils.isEmpty(locationProvider)) {
Log.e(TAG, "No available location providers matching criteria.");
+ } else if (isGooglePlayServicesAvailable()
+ && locationProvider.equals(LocationManager.GPS_PROVIDER)) {
+ // Since Google Play services is available,
+ // let's conserve battery power and not depend on the device's GPS.
+ Log.i(TAG, "Google Play Services available; Ignoring GPS provider.");
} else {
WeatherLocationListener.registerIfNeeded(mContext, locationProvider);
}
@@ -189,6 +196,12 @@ public class WeatherUpdateService extends Service {
return location;
}
+ private boolean isGooglePlayServicesAvailable() {
+ int result = GooglePlayServicesUtil.isGooglePlayServicesAvailable(mContext);
+ return result == ConnectionResult.SUCCESS
+ || result == ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED;
+ }
+
@Override
protected WeatherInfo doInBackground(Void... params) {
WeatherProvider provider = Preferences.weatherProvider(mContext);