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 | |
Jake Whatley | ac7c5d2 | 2017-02-02 20:25:12 -0500 | [diff] [blame] | 19 | import android.content.ComponentName; |
Jason Monk | 76c67aa | 2016-02-19 14:49:42 -0500 | [diff] [blame] | 20 | import android.content.Intent; |
Jason Monk | 49a2796 | 2016-05-25 14:22:01 -0400 | [diff] [blame] | 21 | import android.content.IntentFilter; |
Sudheer Shanka | b6fc931 | 2016-01-27 19:59:03 +0000 | [diff] [blame] | 22 | import android.os.UserManager; |
| 23 | |
Jason Monk | 49a2796 | 2016-05-25 14:22:01 -0400 | [diff] [blame] | 24 | import android.provider.Settings.Global; |
jackqdyulei | 76471a5 | 2016-12-05 15:03:56 -0800 | [diff] [blame] | 25 | import android.service.quicksettings.Tile; |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 26 | import android.widget.Switch; |
| 27 | |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 28 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 29 | import com.android.systemui.Dependency; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 30 | import com.android.systemui.R; |
Jason Monk | 49a2796 | 2016-05-25 14:22:01 -0400 | [diff] [blame] | 31 | import com.android.systemui.qs.GlobalSetting; |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 32 | import com.android.systemui.qs.QSHost; |
| 33 | import com.android.systemui.plugins.qs.QSTile.AirplaneBooleanState; |
| 34 | import com.android.systemui.qs.tileimpl.QSTileImpl; |
Jason Monk | 51e4dc0 | 2014-07-22 12:00:47 -0400 | [diff] [blame] | 35 | import com.android.systemui.statusbar.policy.HotspotController; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 36 | |
| 37 | /** Quick settings tile: Hotspot **/ |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 38 | public class HotspotTile extends QSTileImpl<AirplaneBooleanState> { |
Jake Whatley | ac7c5d2 | 2017-02-02 20:25:12 -0500 | [diff] [blame] | 39 | static final Intent TETHER_SETTINGS = new Intent().setComponent(new ComponentName( |
| 40 | "com.android.settings", "com.android.settings.TetherSettings")); |
| 41 | |
Jason Monk | e645aee | 2017-03-31 13:19:26 -0400 | [diff] [blame] | 42 | private final Icon mEnabledStatic = ResourceIcon.get(R.drawable.ic_hotspot_disable); |
Jason Monk | ab17c98 | 2016-06-20 12:39:38 -0400 | [diff] [blame] | 43 | private final Icon mUnavailable = ResourceIcon.get(R.drawable.ic_hotspot_unavailable); |
| 44 | |
Jason Monk | 51e4dc0 | 2014-07-22 12:00:47 -0400 | [diff] [blame] | 45 | private final HotspotController mController; |
Jason Monk | 51e4dc0 | 2014-07-22 12:00:47 -0400 | [diff] [blame] | 46 | private final Callback mCallback = new Callback(); |
Jason Monk | 49a2796 | 2016-05-25 14:22:01 -0400 | [diff] [blame] | 47 | private final GlobalSetting mAirplaneMode; |
| 48 | private boolean mListening; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 49 | |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 50 | public HotspotTile(QSHost host) { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 51 | super(host); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 52 | mController = Dependency.get(HotspotController.class); |
Jason Monk | 49a2796 | 2016-05-25 14:22:01 -0400 | [diff] [blame] | 53 | mAirplaneMode = new GlobalSetting(mContext, mHandler, Global.AIRPLANE_MODE_ON) { |
| 54 | @Override |
| 55 | protected void handleValueChanged(int value) { |
| 56 | refreshState(); |
| 57 | } |
| 58 | }; |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | @Override |
Jason Monk | 28680c6 | 2016-04-19 09:31:20 -0400 | [diff] [blame] | 62 | public boolean isAvailable() { |
| 63 | return mController.isHotspotSupported(); |
| 64 | } |
| 65 | |
| 66 | @Override |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 67 | protected void handleDestroy() { |
| 68 | super.handleDestroy(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | @Override |
Jason Monk | ab17c98 | 2016-06-20 12:39:38 -0400 | [diff] [blame] | 72 | public AirplaneBooleanState newTileState() { |
| 73 | return new AirplaneBooleanState(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | @Override |
John Spurlock | ccb6b9a | 2014-05-17 15:54:40 -0400 | [diff] [blame] | 77 | public void setListening(boolean listening) { |
Jason Monk | 49a2796 | 2016-05-25 14:22:01 -0400 | [diff] [blame] | 78 | if (mListening == listening) return; |
| 79 | mListening = listening; |
Jason Monk | 51e4dc0 | 2014-07-22 12:00:47 -0400 | [diff] [blame] | 80 | if (listening) { |
| 81 | mController.addCallback(mCallback); |
Jason Monk | 49a2796 | 2016-05-25 14:22:01 -0400 | [diff] [blame] | 82 | final IntentFilter filter = new IntentFilter(); |
| 83 | filter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED); |
Jason Monk | 94f682e | 2016-06-23 13:23:01 -0400 | [diff] [blame] | 84 | refreshState(); |
Jason Monk | 51e4dc0 | 2014-07-22 12:00:47 -0400 | [diff] [blame] | 85 | } else { |
| 86 | mController.removeCallback(mCallback); |
Jason Monk | 51e4dc0 | 2014-07-22 12:00:47 -0400 | [diff] [blame] | 87 | } |
Jason Monk | 49a2796 | 2016-05-25 14:22:01 -0400 | [diff] [blame] | 88 | mAirplaneMode.setListening(listening); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | @Override |
Jason Monk | 76c67aa | 2016-02-19 14:49:42 -0500 | [diff] [blame] | 92 | public Intent getLongClickIntent() { |
Jake Whatley | ac7c5d2 | 2017-02-02 20:25:12 -0500 | [diff] [blame] | 93 | return new Intent(TETHER_SETTINGS); |
Jason Monk | 76c67aa | 2016-02-19 14:49:42 -0500 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | @Override |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 97 | protected void handleClick() { |
Jason Monk | 51e4dc0 | 2014-07-22 12:00:47 -0400 | [diff] [blame] | 98 | final boolean isEnabled = (Boolean) mState.value; |
Jason Monk | 49a2796 | 2016-05-25 14:22:01 -0400 | [diff] [blame] | 99 | if (!isEnabled && mAirplaneMode.getValue() != 0) { |
| 100 | return; |
| 101 | } |
Jason Monk | 51e4dc0 | 2014-07-22 12:00:47 -0400 | [diff] [blame] | 102 | mController.setHotspotEnabled(!isEnabled); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | @Override |
Jason Monk | 39c98e6 | 2016-03-16 09:18:35 -0400 | [diff] [blame] | 106 | public CharSequence getTileLabel() { |
| 107 | return mContext.getString(R.string.quick_settings_hotspot_label); |
| 108 | } |
| 109 | |
| 110 | @Override |
Jason Monk | ab17c98 | 2016-06-20 12:39:38 -0400 | [diff] [blame] | 111 | protected void handleUpdateState(AirplaneBooleanState state, Object arg) { |
Jason Monk | 395617f | 2017-05-05 14:07:58 -0400 | [diff] [blame^] | 112 | if (state.slash == null) { |
| 113 | state.slash = new SlashState(); |
| 114 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 115 | state.label = mContext.getString(R.string.quick_settings_hotspot_label); |
Jason Monk | 51e4dc0 | 2014-07-22 12:00:47 -0400 | [diff] [blame] | 116 | |
Sudheer Shanka | a8fbbb3 | 2016-02-11 17:17:57 +0000 | [diff] [blame] | 117 | checkIfRestrictionEnforcedByAdminOnly(state, UserManager.DISALLOW_CONFIG_TETHERING); |
Julia Reynolds | b8a46a6 | 2015-07-14 13:36:30 -0400 | [diff] [blame] | 118 | if (arg instanceof Boolean) { |
| 119 | state.value = (boolean) arg; |
| 120 | } else { |
Jason Monk | dd5bdc6 | 2015-07-20 12:18:38 -0400 | [diff] [blame] | 121 | state.value = mController.isHotspotEnabled(); |
Julia Reynolds | b8a46a6 | 2015-07-14 13:36:30 -0400 | [diff] [blame] | 122 | } |
Jason Monk | 395617f | 2017-05-05 14:07:58 -0400 | [diff] [blame^] | 123 | state.icon = mEnabledStatic; |
Jason Monk | ab17c98 | 2016-06-20 12:39:38 -0400 | [diff] [blame] | 124 | state.isAirplaneMode = mAirplaneMode.getValue() != 0; |
Jason Monk | e645aee | 2017-03-31 13:19:26 -0400 | [diff] [blame] | 125 | state.isTransient = mController.isHotspotTransient(); |
Jason Monk | 395617f | 2017-05-05 14:07:58 -0400 | [diff] [blame^] | 126 | state.slash.isSlashed = !state.value && !state.isTransient; |
Jason Monk | e645aee | 2017-03-31 13:19:26 -0400 | [diff] [blame] | 127 | if (state.isTransient) { |
| 128 | state.icon = ResourceIcon.get(R.drawable.ic_hotspot_transient_animation); |
Jason Monk | 49a2796 | 2016-05-25 14:22:01 -0400 | [diff] [blame] | 129 | } |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 130 | state.expandedAccessibilityClassName = Switch.class.getName(); |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 131 | state.contentDescription = state.label; |
Jason Monk | 3250885 | 2017-01-18 09:17:13 -0500 | [diff] [blame] | 132 | state.state = state.isAirplaneMode ? Tile.STATE_UNAVAILABLE |
Jason Monk | e645aee | 2017-03-31 13:19:26 -0400 | [diff] [blame] | 133 | : state.value || state.isTransient ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE; |
Jason Monk | 51e4dc0 | 2014-07-22 12:00:47 -0400 | [diff] [blame] | 134 | } |
| 135 | |
Selim Cinek | 4fda7b2 | 2014-08-18 22:07:25 +0200 | [diff] [blame] | 136 | @Override |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 137 | public int getMetricsCategory() { |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 138 | return MetricsEvent.QS_HOTSPOT; |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | @Override |
Selim Cinek | 4fda7b2 | 2014-08-18 22:07:25 +0200 | [diff] [blame] | 142 | protected String composeChangeAnnouncement() { |
| 143 | if (mState.value) { |
| 144 | return mContext.getString(R.string.accessibility_quick_settings_hotspot_changed_on); |
| 145 | } else { |
| 146 | return mContext.getString(R.string.accessibility_quick_settings_hotspot_changed_off); |
| 147 | } |
| 148 | } |
| 149 | |
John Spurlock | e2efefe | 2014-07-28 11:17:12 -0400 | [diff] [blame] | 150 | private final class Callback implements HotspotController.Callback { |
Jason Monk | 51e4dc0 | 2014-07-22 12:00:47 -0400 | [diff] [blame] | 151 | @Override |
| 152 | public void onHotspotChanged(boolean enabled) { |
Julia Reynolds | b8a46a6 | 2015-07-14 13:36:30 -0400 | [diff] [blame] | 153 | refreshState(enabled); |
Jason Monk | 51e4dc0 | 2014-07-22 12:00:47 -0400 | [diff] [blame] | 154 | } |
Jason Monk | 51e4dc0 | 2014-07-22 12:00:47 -0400 | [diff] [blame] | 155 | }; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 156 | } |