aboutsummaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--Android.mk12
-rw-r--r--AndroidManifest.xml3
-rw-r--r--res/values/version.xml4
-rwxr-xr-xsrc/com/cyanogenmod/lockclock/weather/WeatherUpdateService.java13
4 files changed, 32 insertions, 0 deletions
diff --git a/Android.mk b/Android.mk
index 9c560d8..7809d91 100644
--- a/Android.mk
+++ b/Android.mk
@@ -24,6 +24,18 @@ LOCAL_PACKAGE_NAME := LockClock
LOCAL_PROGUARD_FLAG_FILES := proguard.flags
LOCAL_AAPT_INCLUDE_ALL_RESOURCES := true
+# Include res dir from chips
+google_play_dir := ../../../external/google/google_play_services/libproject/google-play-services_lib/res
+res_dir := $(google_play_dir) res
+
+LOCAL_RESOURCE_DIR := $(addprefix $(LOCAL_PATH)/, $(res_dir))
+LOCAL_AAPT_FLAGS := --auto-add-overlay
+LOCAL_AAPT_FLAGS += --extra-packages com.google.android.gms
+
+LOCAL_STATIC_JAVA_LIBRARIES := play
+LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := \
+ play:../../../external/google/google_play_services/libproject/google-play-services_lib/libs/google-play-services.jar
+
include $(BUILD_PACKAGE)
include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index ec70a33..4bdcd41 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -45,6 +45,9 @@
android:theme="@style/Theme.Main"
android:name=".WidgetApplication" >
+ <meta-data android:name="com.google.android.gms.version"
+ android:value="@integer/google_play_services_version" />
+
<activity
android:name=".preference.Preferences"
android:label="@string/app_name" >
diff --git a/res/values/version.xml b/res/values/version.xml
new file mode 100644
index 0000000..1e7fd4e
--- /dev/null
+++ b/res/values/version.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <integer name="google_play_services_version">4323000</integer>
+</resources>
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);