summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/location/LocationSettings.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/settings/location/LocationSettings.java')
-rw-r--r--src/com/android/settings/location/LocationSettings.java99
1 files changed, 97 insertions, 2 deletions
diff --git a/src/com/android/settings/location/LocationSettings.java b/src/com/android/settings/location/LocationSettings.java
index 2628c7f..9783ff2 100644
--- a/src/com/android/settings/location/LocationSettings.java
+++ b/src/com/android/settings/location/LocationSettings.java
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2011 The Android Open Source Project
+ * Copyright (C) 2015 The CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,10 +17,16 @@
package com.android.settings.location;
+import static cyanogenmod.hardware.CMHardwareManager.FEATURE_LONG_TERM_ORBITS;
+
+import android.app.AlarmManager;
+import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.content.SharedPreferences;
+import android.content.pm.PackageManager;
import android.location.SettingInjectorService;
import android.os.Bundle;
import android.os.UserHandle;
@@ -27,7 +34,10 @@ import android.os.UserManager;
import android.preference.Preference;
import android.preference.PreferenceCategory;
import android.preference.PreferenceGroup;
+import android.preference.PreferenceManager;
import android.preference.PreferenceScreen;
+import android.preference.SwitchPreference;
+import android.preference.Preference.OnPreferenceChangeListener;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
@@ -37,8 +47,11 @@ import com.android.internal.logging.MetricsLogger;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.Utils;
+import com.android.settings.cyanogenmod.LtoService;
import com.android.settings.widget.SwitchBar;
+import cyanogenmod.hardware.CMHardwareManager;
+
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
@@ -69,7 +82,7 @@ import java.util.List;
* implementation.
*/
public class LocationSettings extends LocationSettingsBase
- implements SwitchBar.OnSwitchChangeListener {
+ implements SwitchBar.OnSwitchChangeListener, OnPreferenceChangeListener {
private static final String TAG = "LocationSettings";
@@ -93,12 +106,16 @@ public class LocationSettings extends LocationSettingsBase
private static final int MENU_SCANNING = Menu.FIRST;
+ /** Key for preference LTO over Wi-Fi only */
+ public static final String KEY_LTO_DOWNLOAD_DATA_WIFI_ONLY = "lto_download_data_wifi_only";
+
private SwitchBar mSwitchBar;
private Switch mSwitch;
private boolean mValidListener = false;
private UserHandle mManagedProfile;
private Preference mManagedProfilePreference;
private Preference mLocationMode;
+ private SwitchPreference mLtoDownloadDataWifiOnly;
private PreferenceCategory mCategoryRecentLocationRequests;
/** Receives UPDATE_INTENT */
private BroadcastReceiver mReceiver;
@@ -120,6 +137,7 @@ public class LocationSettings extends LocationSettingsBase
mSwitchBar = activity.getSwitchBar();
mSwitch = mSwitchBar.getSwitch();
mSwitchBar.show();
+ setHasOptionsMenu(true);
}
@Override
@@ -191,6 +209,17 @@ public class LocationSettings extends LocationSettingsBase
}
});
+ mLtoDownloadDataWifiOnly =
+ (SwitchPreference) root.findPreference(KEY_LTO_DOWNLOAD_DATA_WIFI_ONLY);
+ if (mLtoDownloadDataWifiOnly != null) {
+ if (!isLtoSupported(activity) || !checkGpsDownloadWiFiOnly(activity)) {
+ root.removePreference(mLtoDownloadDataWifiOnly);
+ mLtoDownloadDataWifiOnly = null;
+ } else {
+ mLtoDownloadDataWifiOnly.setOnPreferenceChangeListener(this);
+ }
+ }
+
mCategoryRecentLocationRequests =
(PreferenceCategory) root.findPreference(KEY_RECENT_LOCATION_REQUESTS);
RecentLocationApps recentApps = new RecentLocationApps(activity);
@@ -253,7 +282,7 @@ public class LocationSettings extends LocationSettingsBase
boolean lockdownOnLocationAccess) {
PreferenceCategory categoryLocationServices =
(PreferenceCategory) root.findPreference(KEY_LOCATION_SERVICES);
- injector = new SettingsInjector(context);
+ injector = IzatSettingsInjector.getSettingInjector(context);
// If location access is locked down by device policy then we only show injected settings
// for the primary profile.
List<Preference> locationServices = injector.getInjectedSettings(lockdownOnLocationAccess ?
@@ -334,6 +363,9 @@ public class LocationSettings extends LocationSettingsBase
// Disable the whole switch bar instead of the switch itself. If we disabled the switch
// only, it would be re-enabled again if the switch bar is not disabled.
mSwitchBar.setEnabled(!restricted);
+ if (mLtoDownloadDataWifiOnly != null) {
+ mLtoDownloadDataWifiOnly.setEnabled(enabled && !restricted);
+ }
mLocationMode.setEnabled(enabled && !restricted);
mCategoryRecentLocationRequests.setEnabled(enabled);
@@ -377,4 +409,67 @@ public class LocationSettings extends LocationSettingsBase
setLocationMode(android.provider.Settings.Secure.LOCATION_MODE_OFF);
}
}
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ if (mLtoDownloadDataWifiOnly != null && preference.equals(mLtoDownloadDataWifiOnly)) {
+ updateLtoServiceStatus(getActivity(), isLocationModeEnabled(getActivity()));
+ }
+ return true;
+ }
+
+ private static void updateLtoServiceStatus(Context context, boolean start) {
+ Intent intent = new Intent(context, LtoService.class);
+ if (start) {
+ context.startService(intent);
+ } else {
+ context.stopService(intent);
+ }
+ }
+
+ private static boolean checkGpsDownloadWiFiOnly(Context context) {
+ PackageManager pm = context.getPackageManager();
+ boolean supportsTelephony = pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
+ boolean supportsWifi = pm.hasSystemFeature(PackageManager.FEATURE_WIFI);
+ if (!supportsWifi || !supportsTelephony) {
+ SharedPreferences.Editor editor =
+ PreferenceManager.getDefaultSharedPreferences(context).edit();
+ editor.putBoolean(KEY_LTO_DOWNLOAD_DATA_WIFI_ONLY, supportsWifi);
+ editor.apply();
+ return false;
+ }
+ return true;
+ }
+
+ public static boolean isLocationModeEnabled(Context context) {
+ int mode = android.provider.Settings.Secure.getInt(context.getContentResolver(),
+ android.provider.Settings.Secure.LOCATION_MODE,
+ android.provider.Settings.Secure.LOCATION_MODE_OFF);
+ return (mode != android.provider.Settings.Secure.LOCATION_MODE_OFF);
+ }
+
+ /**
+ * Restore the properties associated with this preference on boot
+ * @param ctx A valid context
+ */
+ public static void restore(final Context context) {
+ if (isLtoSupported(context) && isLocationModeEnabled(context)) {
+ // Check and adjust the value for Gps download data on wifi only
+ checkGpsDownloadWiFiOnly(context);
+
+ // Starts the LtoService, but delayed 2 minutes after boot (this should give a
+ // proper time to start all device services)
+ AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
+ Intent intent = new Intent(context, LtoService.class);
+ PendingIntent pi = PendingIntent.getService(context, 0, intent,
+ PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);
+ long nextLtoDownload = System.currentTimeMillis() + (1000 * 60 * 2L);
+ am.set(AlarmManager.RTC, nextLtoDownload, pi);
+ }
+ }
+
+ private static boolean isLtoSupported(Context context) {
+ final CMHardwareManager hardware = CMHardwareManager.getInstance(context);
+ return hardware != null && hardware.isSupported(FEATURE_LONG_TERM_ORBITS);
+ }
}