summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoey <joey@lineageos.org>2015-06-20 15:37:04 +0000
committerBruno Martins <bgcngm@gmail.com>2019-11-16 22:14:37 +0000
commitf1bbf242b0839d9c4e3ff54737dc32315d3e379c (patch)
tree45283c026e662ab070bcab9d0d3009634ceb5e47
parente7f3c30e243b8eb4d689a902867c469b6b9044cf (diff)
downloadandroid_frameworks_base-f1bbf242b0839d9c4e3ff54737dc32315d3e379c.tar.gz
android_frameworks_base-f1bbf242b0839d9c4e3ff54737dc32315d3e379c.tar.bz2
android_frameworks_base-f1bbf242b0839d9c4e3ff54737dc32315d3e379c.zip
SystemUI: Advanced location tile
Includes the following: * base: LocationTile detail (I968e26b6e5e4ad0acdb347c4acc03994b73ca74b) * LocationTile: Behave like other tiles (I9767b9f2e812f85c664ff7721ff3d8dc9ba54aca) * UI improvements for Oreo changes * LocationTile: Improve strings * SystemUI: Improve location tile descriptions Change-Id: I8ce53f535a8d52fead2e518316b4bbb716a06d75 Signed-off-by: Joey <joey@lineageos.org>
-rw-r--r--packages/SystemUI/res/drawable/ic_qs_location_battery_saving.xml29
-rw-r--r--packages/SystemUI/res/drawable/ic_qs_location_sensors_only.xml29
-rw-r--r--packages/SystemUI/res/layout/location_mode_panel.xml64
-rw-r--r--packages/SystemUI/res/values/cm_strings.xml34
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/tiles/LocationTile.java212
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/policy/LocationController.java2
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/policy/LocationControllerImpl.java38
7 files changed, 395 insertions, 13 deletions
diff --git a/packages/SystemUI/res/drawable/ic_qs_location_battery_saving.xml b/packages/SystemUI/res/drawable/ic_qs_location_battery_saving.xml
new file mode 100644
index 00000000000..cef2fc52f8b
--- /dev/null
+++ b/packages/SystemUI/res/drawable/ic_qs_location_battery_saving.xml
@@ -0,0 +1,29 @@
+<!--
+ Copyright (C) 2017 The LineageOS Project
+ Copyright (C) 2016 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="64dp"
+ android:height="64dp"
+ android:viewportWidth="48.0"
+ android:viewportHeight="48.0">
+
+ <path
+ android:fillColor="#4DFFFFFF"
+ android:pathData="M24.0,4.0c-7.7,0.0 -14.0,6.3 -14.0,14.0c0.0,10.5 14.0,26.0 14.0,26.0s14.0,-15.5 14.0,-26.0C38.0,10.3 31.7,4.0 24.0,4.0zM24.0,23.0c-2.8,0.0 -5.0,-2.2 -5.0,-5.0s2.2,-5.0 5.0,-5.0c2.8,0.0 5.0,2.2 5.0,5.0S26.8,23.0 24.0,23.0z"/>
+ <path
+ android:pathData="M24.0,4.0c-7.7,0.0 -14.0,6.3 -14.0,14.0c0.0,10.5 14.0,26.0 14.0,26.0l0.0,-21.0 c-2.8,0.0 -5.0,-2.2 -5.0,-5.0s2.2,-5.0 5.0,-5.0l0.0,-9.0z"
+ android:fillColor="#FFFFFFFF"/>
+</vector>
diff --git a/packages/SystemUI/res/drawable/ic_qs_location_sensors_only.xml b/packages/SystemUI/res/drawable/ic_qs_location_sensors_only.xml
new file mode 100644
index 00000000000..f9a8804676e
--- /dev/null
+++ b/packages/SystemUI/res/drawable/ic_qs_location_sensors_only.xml
@@ -0,0 +1,29 @@
+<!--
+ Copyright (C) 2017 The LineageOS Project
+ Copyright (C) 2016 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="64dp"
+ android:height="64dp"
+ android:viewportWidth="48.0"
+ android:viewportHeight="48.0">
+
+ <path
+ android:fillColor="#FFFFFFFF"
+ android:pathData="M24.0,4.0c-7.7,0.0 -14.0,6.3 -14.0,14.0c0.0,10.5 14.0,26.0 14.0,26.0s14.0,-15.5 14.0,-26.0C38.0,10.3 31.7,4.0 24.0,4.0zM24.0,23.0c-2.8,0.0 -5.0,-2.2 -5.0,-5.0s2.2,-5.0 5.0,-5.0c2.8,0.0 5.0,2.2 5.0,5.0S26.8,23.0 24.0,23.0z"/>
+ <path
+ android:pathData="M24.0,4.0c-7.7,0.0 -14.0,6.3 -14.0,14.0c0.0,10.5 14.0,26.0 14.0,26.0l0.0,-21.0 c-2.8,0.0 -5.0,-2.2 -5.0,-5.0s2.2,-5.0 5.0,-5.0l0.0,-9.0z"
+ android:fillColor="#4DFFFFFF"/>
+</vector>
diff --git a/packages/SystemUI/res/layout/location_mode_panel.xml b/packages/SystemUI/res/layout/location_mode_panel.xml
new file mode 100644
index 00000000000..980454d5ffc
--- /dev/null
+++ b/packages/SystemUI/res/layout/location_mode_panel.xml
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2017 The LineageOS Project
+ Copyright (C) 2015-2017 The ParanoidAndroid Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/location_mode_panel"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:clipChildren="false"
+ android:orientation="vertical" >
+
+ <com.android.systemui.volume.SegmentedButtons
+ android:id="@+id/location_buttons"
+ android:background="@drawable/segmented_buttons_background"
+ android:baselineAligned="false"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="16dp"
+ android:layout_marginEnd="16dp"
+ android:layout_marginTop="8dp"
+ android:layout_marginBottom="8dp" />
+
+ <RelativeLayout
+ android:id="@+id/location_introduction"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="16dp"
+ android:layout_marginEnd="16dp"
+ android:paddingTop="8dp"
+ android:paddingBottom="8dp"
+ android:background="@drawable/zen_introduction_message_background" >
+
+ <TextView
+ android:id="@+id/location_introduction_message"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="12dp"
+ android:layout_marginStart="24dp"
+ android:layout_marginEnd="24dp"
+ android:textDirection="locale"
+ android:lineSpacingMultiplier="1.20029"
+ android:textAppearance="@style/TextAppearance.QS.Introduction" />
+
+ <View
+ android:layout_width="0dp"
+ android:layout_height="16dp"
+ android:layout_below="@id/location_introduction_message"
+ android:layout_alignParentEnd="true" />
+
+ </RelativeLayout>
+</LinearLayout>
diff --git a/packages/SystemUI/res/values/cm_strings.xml b/packages/SystemUI/res/values/cm_strings.xml
index a2876a955b8..a2e4b9d32f3 100644
--- a/packages/SystemUI/res/values/cm_strings.xml
+++ b/packages/SystemUI/res/values/cm_strings.xml
@@ -83,4 +83,38 @@
<!-- Volume panel QS tile -->
<string name="quick_settings_volume_panel_label">Volume panel</string>
+
+ <!-- Content description of the location tile in quick settings when on, battery saving mode (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_quick_settings_location_battery_saving">Location reporting: battery saving mode.</string>
+ <!-- Content description of the location tile in quick settings when on, sensors only mode (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_quick_settings_location_gps_only">Location reporting: sensors only mode.</string>
+ <!-- Content description of the location tile in quick settings when on, high accuracy mode (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_quick_settings_location_high_accuracy">Location reporting: high accuracy mode.</string>
+
+ <!-- QuickSettings: Location (On, low-power) [CHAR LIMIT=NONE] -->
+ <string name="quick_settings_location_battery_saving_label">Battery saving</string>
+ <string name="quick_settings_location_battery_saving_label_twoline">Battery\nsaving</string>
+ <!-- QuickSettings: Location (On, gps-only) [CHAR LIMIT=NONE] -->
+ <string name="quick_settings_location_gps_only_label">Device only</string>
+ <string name="quick_settings_location_gps_only_label_twoline">Device\nonly</string>
+ <!-- QuickSettings: Location (On, high-accuracy) [CHAR LIMIT=NONE] -->
+ <string name="quick_settings_location_high_accuracy_label">High accuracy</string>
+ <string name="quick_settings_location_high_accuracy_label_twoline">High\naccuracy</string>
+
+ <!-- QuickSettings: Location detail panel title [CHAR LIMIT=NONE] -->
+ <string name="quick_settings_location_detail_title">Location</string>
+ <!-- QuickSettings: Location detail panel menu title [CHAR LIMIT=NONE] -->
+ <string name="quick_settings_location_detail_menu_title">Select mode:</string>
+ <!-- [CHAR LIMIT=30] Location detail panel, high accuracy location mode -->
+ <string name="quick_settings_location_detail_mode_high_accuracy_title">High accuracy</string>
+ <!-- [CHAR LIMIT=30] Location detail panel, battery saving location mode -->
+ <string name="quick_settings_location_detail_mode_battery_saving_title">Battery saving</string>
+ <!-- [CHAR LIMIT=30] Location detail panel, device only location mode -->
+ <string name="quick_settings_location_detail_mode_sensors_only_title">Device only</string>
+ <!-- [CHAR LIMIT=130] Location detail panel, description for high accuracy mode -->
+ <string name="quick_settings_location_detail_mode_high_accuracy_description">Use GPS, Wi\u2011Fi, Bluetooth, or cellular networks to determine location</string>
+ <!-- [CHAR LIMIT=130] Location detail panel, description for battery saving mode -->
+ <string name="quick_settings_location_detail_mode_battery_saving_description">Use Wi\u2011Fi, Bluetooth, or cellular networks to determine location</string>
+ <!-- [CHAR LIMIT=130] Location detail panel, description for sensors only mode -->
+ <string name="quick_settings_location_detail_mode_sensors_only_description">Use GPS to determine location</string>
</resources>
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/LocationTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/LocationTile.java
index 837ea9fc5f4..497b4f3c182 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/LocationTile.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/LocationTile.java
@@ -1,5 +1,7 @@
/*
* Copyright (C) 2014 The Android Open Source Project
+ * Copyright (C) 2016 The ParanoidAndroid Project
+ * Copyright (C) 2017 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,21 +18,32 @@
package com.android.systemui.qs.tiles;
+import android.content.Context;
import android.content.Intent;
import android.os.UserManager;
import android.provider.Settings;
import android.service.quicksettings.Tile;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
import android.widget.Switch;
+import android.widget.TextView;
+import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.systemui.R;
import com.android.systemui.plugins.ActivityStarter;
+import com.android.systemui.plugins.qs.DetailAdapter;
import com.android.systemui.plugins.qs.QSTile.BooleanState;
import com.android.systemui.qs.QSHost;
import com.android.systemui.qs.tileimpl.QSTileImpl;
import com.android.systemui.statusbar.policy.KeyguardMonitor;
import com.android.systemui.statusbar.policy.LocationController;
import com.android.systemui.statusbar.policy.LocationController.LocationChangeCallback;
+import com.android.systemui.volume.SegmentedButtons;
+
+import org.lineageos.internal.logging.LineageMetricsLogger;
import javax.inject.Inject;
@@ -39,10 +52,15 @@ public class LocationTile extends QSTileImpl<BooleanState> {
private final Icon mIcon = ResourceIcon.get(R.drawable.ic_location);
+ private static final Intent LOCATION_SETTINGS_INTENT =
+ new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
+
private final LocationController mController;
+ private final LocationDetailAdapter mDetailAdapter;
private final KeyguardMonitor mKeyguard;
private final ActivityStarter mActivityStarter;
private final Callback mCallback = new Callback();
+ private int mLastState;
@Inject
public LocationTile(QSHost host, LocationController locationController,
@@ -53,6 +71,7 @@ public class LocationTile extends QSTileImpl<BooleanState> {
mActivityStarter = activityStarter;
mController.observe(this, mCallback);
mKeyguard.observe(this, mCallback);
+ mDetailAdapter = (LocationDetailAdapter) createDetailAdapter();
}
@Override
@@ -61,6 +80,17 @@ public class LocationTile extends QSTileImpl<BooleanState> {
}
@Override
+ public DetailAdapter getDetailAdapter() {
+ return mDetailAdapter;
+ }
+
+ @Override
+ protected DetailAdapter createDetailAdapter() {
+ return new LocationDetailAdapter();
+ }
+
+
+ @Override
public void handleSetListening(boolean listening) {
}
@@ -71,6 +101,13 @@ public class LocationTile extends QSTileImpl<BooleanState> {
@Override
protected void handleClick() {
+ final boolean wasEnabled = mState.value;
+ MetricsLogger.action(mContext, getMetricsCategory(), !wasEnabled);
+ mController.setLocationEnabled(!wasEnabled);
+ }
+
+ @Override
+ protected void handleSecondaryClick() {
if (mKeyguard.isSecure() && mKeyguard.isShowing()) {
mActivityStarter.postQSRunnableDismissingKeyguard(() -> {
final boolean wasEnabled = mState.value;
@@ -80,7 +117,10 @@ public class LocationTile extends QSTileImpl<BooleanState> {
return;
}
final boolean wasEnabled = mState.value;
- mController.setLocationEnabled(!wasEnabled);
+ if (!wasEnabled) {
+ mController.setLocationEnabled(!wasEnabled);
+ }
+ showDetail(true);
}
@Override
@@ -93,31 +133,70 @@ public class LocationTile extends QSTileImpl<BooleanState> {
if (state.slash == null) {
state.slash = new SlashState();
}
- final boolean locationEnabled = mController.isLocationEnabled();
+ int currentState = arg instanceof Integer ? (Integer) arg :
+ mController.getLocationCurrentState();
+ final boolean newValue = currentState != Settings.Secure.LOCATION_MODE_OFF;
+ final boolean valueChanged = state.value != newValue;
// Work around for bug 15916487: don't show location tile on top of lock screen. After the
// bug is fixed, this should be reverted to only hiding it on secure lock screens:
// state.visible = !(mKeyguard.isSecure() && mKeyguard.isShowing());
- state.value = locationEnabled;
+ state.value = newValue;
+ state.dualTarget = true;
checkIfRestrictionEnforcedByAdminOnly(state, UserManager.DISALLOW_SHARE_LOCATION);
if (state.disabledByPolicy == false) {
checkIfRestrictionEnforcedByAdminOnly(state, UserManager.DISALLOW_CONFIG_LOCATION);
}
- state.icon = mIcon;
- state.slash.isSlashed = !state.value;
- if (locationEnabled) {
- state.label = mContext.getString(R.string.quick_settings_location_label);
- state.contentDescription = mContext.getString(
- R.string.accessibility_quick_settings_location_on);
- } else {
- state.label = mContext.getString(R.string.quick_settings_location_label);
- state.contentDescription = mContext.getString(
- R.string.accessibility_quick_settings_location_off);
+ state.label = mContext.getString(getStateLabelRes(currentState));
+ state.slash.isSlashed = currentState == Settings.Secure.LOCATION_MODE_OFF;
+ switch (currentState) {
+ case Settings.Secure.LOCATION_MODE_OFF:
+ state.contentDescription = mContext.getString(
+ R.string.accessibility_quick_settings_location_off);
+ state.icon = mIcon;
+ break;
+ case Settings.Secure.LOCATION_MODE_HIGH_ACCURACY:
+ state.contentDescription = mContext.getString(
+ R.string.accessibility_quick_settings_location_high_accuracy);
+ state.icon = mIcon;
+ break;
+ case Settings.Secure.LOCATION_MODE_BATTERY_SAVING:
+ state.contentDescription = mContext.getString(
+ R.string.accessibility_quick_settings_location_battery_saving);
+ state.icon = ResourceIcon.get(R.drawable.ic_qs_location_battery_saving);
+ break;
+ case Settings.Secure.LOCATION_MODE_SENSORS_ONLY:
+ state.contentDescription = mContext.getString(
+ R.string.accessibility_quick_settings_location_gps_only);
+ state.icon = ResourceIcon.get(R.drawable.ic_qs_location_sensors_only);
+ break;
+ default:
+ state.contentDescription = mContext.getString(
+ R.string.accessibility_quick_settings_location_on);
+ state.icon = mIcon;
+ }
+ if (valueChanged) {
+ fireToggleStateChanged(state.value);
}
state.state = state.value ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE;
state.expandedAccessibilityClassName = Switch.class.getName();
}
+ private int getStateLabelRes(int currentState) {
+ switch (currentState) {
+ case Settings.Secure.LOCATION_MODE_OFF:
+ return R.string.quick_settings_location_off_label;
+ case Settings.Secure.LOCATION_MODE_HIGH_ACCURACY:
+ return R.string.quick_settings_location_high_accuracy_label;
+ case Settings.Secure.LOCATION_MODE_BATTERY_SAVING:
+ return R.string.quick_settings_location_battery_saving_label;
+ case Settings.Secure.LOCATION_MODE_SENSORS_ONLY:
+ return R.string.quick_settings_location_gps_only_label;
+ default:
+ return R.string.quick_settings_location_label;
+ }
+ }
+
@Override
public int getMetricsCategory() {
return MetricsEvent.QS_LOCATION;
@@ -144,4 +223,111 @@ public class LocationTile extends QSTileImpl<BooleanState> {
refreshState();
}
};
+
+ private class LocationDetailAdapter implements DetailAdapter {
+
+ private SegmentedButtons mButtons;
+ private ViewGroup mMessageContainer;
+ private TextView mMessageText;
+
+ @Override
+ public int getMetricsCategory() {
+ return LineageMetricsLogger.TILE_LOCATION_DETAIL;
+ }
+
+ @Override
+ public CharSequence getTitle() {
+ return mContext.getString(R.string.quick_settings_location_detail_title);
+ }
+
+ @Override
+ public Boolean getToggleState() {
+ return mState.value;
+ }
+
+ @Override
+ public Intent getSettingsIntent() {
+ return LOCATION_SETTINGS_INTENT;
+ }
+
+ @Override
+ public void setToggleState(boolean state) {
+ MetricsLogger.action(mContext, MetricsEvent.QS_DND_TOGGLE, state);
+ if (!state) {
+ mController.setLocationEnabled(state);
+ showDetail(false);
+ }
+ }
+
+ @Override
+ public View createDetailView(Context context, View convertView, ViewGroup parent) {
+ final LinearLayout details = convertView != null ? (LinearLayout) convertView
+ : (LinearLayout) LayoutInflater.from(context).inflate(
+ R.layout.location_mode_panel, parent, false);
+
+ mLastState = mController.getLocationCurrentState();
+
+ if (convertView == null) {
+ mButtons = (SegmentedButtons) details.findViewById(R.id.location_buttons);
+ mButtons.addButton(R.string.quick_settings_location_high_accuracy_label_twoline,
+ R.string.quick_settings_location_high_accuracy_label,
+ Settings.Secure.LOCATION_MODE_HIGH_ACCURACY);
+ mButtons.addButton(R.string.quick_settings_location_battery_saving_label_twoline,
+ R.string.quick_settings_location_battery_saving_label,
+ Settings.Secure.LOCATION_MODE_BATTERY_SAVING);
+ mButtons.addButton(R.string.quick_settings_location_gps_only_label_twoline,
+ R.string.quick_settings_location_gps_only_label,
+ Settings.Secure.LOCATION_MODE_SENSORS_ONLY);
+ mButtons.setCallback(mButtonsCallback);
+ mMessageContainer = (ViewGroup) details.findViewById(R.id.location_introduction);
+ mMessageText = (TextView) details.findViewById(R.id.location_introduction_message);
+ }
+
+ mButtons.setSelectedValue(mLastState, false /* fromClick */);
+ refresh(mLastState);
+
+ return details;
+ }
+
+ private void refresh(int state) {
+ switch (state) {
+ case Settings.Secure.LOCATION_MODE_HIGH_ACCURACY:
+ mMessageText.setText(mContext.getString(
+ R.string.quick_settings_location_detail_mode_high_accuracy_description));
+ mMessageContainer.setVisibility(View.VISIBLE);
+ break;
+ case Settings.Secure.LOCATION_MODE_BATTERY_SAVING:
+ mMessageText.setText(mContext.getString(
+ R.string.quick_settings_location_detail_mode_battery_saving_description));
+ mMessageContainer.setVisibility(View.VISIBLE);
+ break;
+ case Settings.Secure.LOCATION_MODE_SENSORS_ONLY:
+ mMessageText.setText(mContext.getString(
+ R.string.quick_settings_location_detail_mode_sensors_only_description));
+ mMessageContainer.setVisibility(View.VISIBLE);
+ break;
+ default:
+ mMessageContainer.setVisibility(View.GONE);
+ break;
+ }
+ }
+
+ private final SegmentedButtons.Callback mButtonsCallback = new SegmentedButtons.Callback() {
+ @Override
+ public void onSelected(final Object value, boolean fromClick) {
+ if (value != null && mButtons.isShown()) {
+ mLastState = (Integer) value;
+ if (fromClick) {
+ MetricsLogger.action(mContext, MetricsEvent.QS_LOCATION, mLastState);
+ mController.setLocationMode(mLastState);
+ refresh(mLastState);
+ }
+ }
+ }
+
+ @Override
+ public void onInteraction() {
+ }
+ };
+ }
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/LocationController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/LocationController.java
index 8e8a285f7d4..b1f512e60d4 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/LocationController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/LocationController.java
@@ -22,6 +22,8 @@ public interface LocationController extends CallbackController<LocationChangeCal
boolean isLocationActive();
boolean isLocationEnabled();
boolean setLocationEnabled(boolean enabled);
+ boolean setLocationMode(int mode);
+ int getLocationCurrentState();
/**
* A callback for change in location settings (the user has enabled/disabled location).
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/LocationControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/LocationControllerImpl.java
index 683cdbb326d..a62977af262 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/LocationControllerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/LocationControllerImpl.java
@@ -23,6 +23,7 @@ import android.app.ActivityManager;
import android.app.AppOpsManager;
import android.app.StatusBarManager;
import android.content.BroadcastReceiver;
+import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
@@ -121,6 +122,43 @@ public class LocationControllerImpl extends BroadcastReceiver implements Locatio
}
/**
+ * Enable or disable location in settings to a specific mode.
+ *
+ * <p>This will attempt to enable/disable every type of location setting
+ * (e.g. high and balanced power).
+ *
+ * <p>If enabling, a user consent dialog will pop up prompting the user to accept.
+ * If the user doesn't accept, network location won't be enabled.
+ *
+ * @return true if attempt to change setting was successful.
+ */
+ public boolean setLocationMode(int mode) {
+ int currentUserId = ActivityManager.getCurrentUser();
+ if (isUserLocationRestricted(currentUserId)) {
+ return false;
+ }
+ final ContentResolver cr = mContext.getContentResolver();
+ // When enabling location, a user consent dialog will pop up, and the
+ // setting won't be fully enabled until the user accepts the agreement.
+ // QuickSettings always runs as the owner, so specifically set the settings
+ // for the current foreground user.
+ return Settings.Secure.putIntForUser(cr, Settings.Secure.LOCATION_MODE, mode, currentUserId);
+ }
+
+ /**
+ * Returns int corresponding to current location mode in settings.
+ */
+ public int getLocationCurrentState() {
+ int currentUserId = ActivityManager.getCurrentUser();
+ if (isUserLocationRestricted(currentUserId)) {
+ return Settings.Secure.LOCATION_MODE_OFF;
+ }
+ final ContentResolver cr = mContext.getContentResolver();
+ return Settings.Secure.getIntForUser(cr, Settings.Secure.LOCATION_MODE,
+ Settings.Secure.LOCATION_MODE_OFF, currentUserId);
+ }
+
+ /**
* Returns true if location is enabled in settings.
*/
public boolean isLocationEnabled() {