John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui.qs.tiles; |
| 18 | |
Jason Monk | 76c67aa | 2016-02-19 14:49:42 -0500 | [diff] [blame] | 19 | import android.content.Intent; |
Sudheer Shanka | b6fc931 | 2016-01-27 19:59:03 +0000 | [diff] [blame] | 20 | import android.os.UserManager; |
Jason Monk | 76c67aa | 2016-02-19 14:49:42 -0500 | [diff] [blame] | 21 | import android.provider.Settings; |
Jason Monk | 3250885 | 2017-01-18 09:17:13 -0500 | [diff] [blame] | 22 | import android.service.quicksettings.Tile; |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 23 | import android.widget.Switch; |
| 24 | |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 25 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 26 | import com.android.systemui.Dependency; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 27 | import com.android.systemui.R; |
Jason Monk | 395617f | 2017-05-05 14:07:58 -0400 | [diff] [blame] | 28 | import com.android.systemui.R.drawable; |
Jason Monk | ec34da8 | 2017-02-24 15:57:05 -0500 | [diff] [blame] | 29 | import com.android.systemui.plugins.ActivityStarter; |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 30 | import com.android.systemui.qs.QSHost; |
| 31 | import com.android.systemui.plugins.qs.QSTile.BooleanState; |
| 32 | import com.android.systemui.qs.tileimpl.QSTileImpl; |
John Spurlock | 657c62c | 2014-07-22 12:18:09 -0400 | [diff] [blame] | 33 | import com.android.systemui.statusbar.policy.KeyguardMonitor; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 34 | import com.android.systemui.statusbar.policy.LocationController; |
Jason Monk | 359bb74 | 2017-04-13 10:40:40 -0400 | [diff] [blame] | 35 | import com.android.systemui.statusbar.policy.LocationController.LocationChangeCallback; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 36 | |
| 37 | /** Quick settings tile: Location **/ |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 38 | public class LocationTile extends QSTileImpl<BooleanState> { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 39 | |
Evan Laird | bcdd046 | 2017-05-15 12:51:34 -0400 | [diff] [blame] | 40 | private final Icon mIcon = ResourceIcon.get(drawable.ic_signal_location); |
John Spurlock | c6df3cf | 2014-11-04 19:36:44 -0500 | [diff] [blame] | 41 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 42 | private final LocationController mController; |
John Spurlock | 657c62c | 2014-07-22 12:18:09 -0400 | [diff] [blame] | 43 | private final KeyguardMonitor mKeyguard; |
| 44 | private final Callback mCallback = new Callback(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 45 | |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 46 | public LocationTile(QSHost host) { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 47 | super(host); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 48 | mController = Dependency.get(LocationController.class); |
| 49 | mKeyguard = Dependency.get(KeyguardMonitor.class); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | @Override |
Jason Monk | 62b63a0 | 2016-02-02 15:15:31 -0500 | [diff] [blame] | 53 | public BooleanState newTileState() { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 54 | return new BooleanState(); |
| 55 | } |
| 56 | |
John Spurlock | ccb6b9a | 2014-05-17 15:54:40 -0400 | [diff] [blame] | 57 | @Override |
Jason Monk | 1c6116c | 2017-09-06 17:33:01 -0400 | [diff] [blame] | 58 | public void handleSetListening(boolean listening) { |
John Spurlock | ccb6b9a | 2014-05-17 15:54:40 -0400 | [diff] [blame] | 59 | if (listening) { |
Jason Monk | 8852905 | 2016-11-04 13:29:58 -0400 | [diff] [blame] | 60 | mController.addCallback(mCallback); |
John Spurlock | 657c62c | 2014-07-22 12:18:09 -0400 | [diff] [blame] | 61 | mKeyguard.addCallback(mCallback); |
John Spurlock | ccb6b9a | 2014-05-17 15:54:40 -0400 | [diff] [blame] | 62 | } else { |
Jason Monk | 8852905 | 2016-11-04 13:29:58 -0400 | [diff] [blame] | 63 | mController.removeCallback(mCallback); |
John Spurlock | 657c62c | 2014-07-22 12:18:09 -0400 | [diff] [blame] | 64 | mKeyguard.removeCallback(mCallback); |
John Spurlock | ccb6b9a | 2014-05-17 15:54:40 -0400 | [diff] [blame] | 65 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | @Override |
Jason Monk | 76c67aa | 2016-02-19 14:49:42 -0500 | [diff] [blame] | 69 | public Intent getLongClickIntent() { |
| 70 | return new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); |
| 71 | } |
| 72 | |
| 73 | @Override |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 74 | protected void handleClick() { |
Jason Monk | ba2318e | 2015-12-08 09:04:23 -0500 | [diff] [blame] | 75 | if (mKeyguard.isSecure() && mKeyguard.isShowing()) { |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 76 | Dependency.get(ActivityStarter.class).postQSRunnableDismissingKeyguard(() -> { |
| 77 | final boolean wasEnabled = mState.value; |
| 78 | mHost.openPanels(); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 79 | mController.setLocationEnabled(!wasEnabled); |
Jason Monk | ba2318e | 2015-12-08 09:04:23 -0500 | [diff] [blame] | 80 | }); |
| 81 | return; |
| 82 | } |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 83 | final boolean wasEnabled = mState.value; |
John Spurlock | d21df60 | 2014-08-28 14:25:05 -0400 | [diff] [blame] | 84 | mController.setLocationEnabled(!wasEnabled); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | @Override |
Jason Monk | 39c98e6 | 2016-03-16 09:18:35 -0400 | [diff] [blame] | 88 | public CharSequence getTileLabel() { |
| 89 | return mContext.getString(R.string.quick_settings_location_label); |
| 90 | } |
| 91 | |
| 92 | @Override |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 93 | protected void handleUpdateState(BooleanState state, Object arg) { |
Jason Monk | 395617f | 2017-05-05 14:07:58 -0400 | [diff] [blame] | 94 | if (state.slash == null) { |
| 95 | state.slash = new SlashState(); |
| 96 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 97 | final boolean locationEnabled = mController.isLocationEnabled(); |
Tom O'Neill | d528930 | 2014-09-05 08:22:47 -0700 | [diff] [blame] | 98 | |
| 99 | // Work around for bug 15916487: don't show location tile on top of lock screen. After the |
| 100 | // bug is fixed, this should be reverted to only hiding it on secure lock screens: |
| 101 | // state.visible = !(mKeyguard.isSecure() && mKeyguard.isShowing()); |
John Spurlock | 899f439 | 2014-06-11 10:59:11 -0400 | [diff] [blame] | 102 | state.value = locationEnabled; |
Sudheer Shanka | a8fbbb3 | 2016-02-11 17:17:57 +0000 | [diff] [blame] | 103 | checkIfRestrictionEnforcedByAdminOnly(state, UserManager.DISALLOW_SHARE_LOCATION); |
yuemingw | 281000b | 2018-01-08 22:12:05 +0000 | [diff] [blame] | 104 | if (state.disabledByPolicy == false) { |
| 105 | checkIfRestrictionEnforcedByAdminOnly(state, UserManager.DISALLOW_CONFIG_LOCATION_MODE); |
| 106 | } |
Jason Monk | 395617f | 2017-05-05 14:07:58 -0400 | [diff] [blame] | 107 | state.icon = mIcon; |
| 108 | state.slash.isSlashed = !state.value; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 109 | if (locationEnabled) { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 110 | state.label = mContext.getString(R.string.quick_settings_location_label); |
| 111 | state.contentDescription = mContext.getString( |
Selim Cinek | 4fda7b2 | 2014-08-18 22:07:25 +0200 | [diff] [blame] | 112 | R.string.accessibility_quick_settings_location_on); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 113 | } else { |
John Spurlock | 012d4a2 | 2014-06-04 00:40:18 -0400 | [diff] [blame] | 114 | state.label = mContext.getString(R.string.quick_settings_location_label); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 115 | state.contentDescription = mContext.getString( |
Selim Cinek | 4fda7b2 | 2014-08-18 22:07:25 +0200 | [diff] [blame] | 116 | R.string.accessibility_quick_settings_location_off); |
| 117 | } |
Jason Monk | 3250885 | 2017-01-18 09:17:13 -0500 | [diff] [blame] | 118 | state.state = state.value ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE; |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 119 | state.expandedAccessibilityClassName = Switch.class.getName(); |
Selim Cinek | 4fda7b2 | 2014-08-18 22:07:25 +0200 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | @Override |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 123 | public int getMetricsCategory() { |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 124 | return MetricsEvent.QS_LOCATION; |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | @Override |
Selim Cinek | 4fda7b2 | 2014-08-18 22:07:25 +0200 | [diff] [blame] | 128 | protected String composeChangeAnnouncement() { |
| 129 | if (mState.value) { |
| 130 | return mContext.getString(R.string.accessibility_quick_settings_location_changed_on); |
| 131 | } else { |
| 132 | return mContext.getString(R.string.accessibility_quick_settings_location_changed_off); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 133 | } |
| 134 | } |
| 135 | |
Jason Monk | 359bb74 | 2017-04-13 10:40:40 -0400 | [diff] [blame] | 136 | private final class Callback implements LocationChangeCallback, |
John Spurlock | 657c62c | 2014-07-22 12:18:09 -0400 | [diff] [blame] | 137 | KeyguardMonitor.Callback { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 138 | @Override |
| 139 | public void onLocationSettingsChanged(boolean enabled) { |
| 140 | refreshState(); |
| 141 | } |
John Spurlock | 657c62c | 2014-07-22 12:18:09 -0400 | [diff] [blame] | 142 | |
| 143 | @Override |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 144 | public void onKeyguardShowingChanged() { |
John Spurlock | 657c62c | 2014-07-22 12:18:09 -0400 | [diff] [blame] | 145 | refreshState(); |
| 146 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 147 | }; |
| 148 | } |