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 | |
Amin Shaikh | 329c828 | 2018-03-09 14:50:59 -0500 | [diff] [blame] | 19 | import static com.android.systemui.Prefs.Key.QS_HAS_TURNED_OFF_MOBILE_DATA; |
| 20 | |
Jason Monk | 54ff0ef | 2017-07-25 14:44:28 -0400 | [diff] [blame] | 21 | import android.app.AlertDialog; |
Jason Monk | 9ca1848 | 2017-08-01 10:38:02 -0400 | [diff] [blame] | 22 | import android.app.AlertDialog.Builder; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 23 | import android.content.Context; |
| 24 | import android.content.Intent; |
| 25 | import android.content.res.Resources; |
Rohan Shah | 53f3f15 | 2018-02-28 15:13:31 -0800 | [diff] [blame] | 26 | import android.provider.Settings; |
Jason Monk | 3250885 | 2017-01-18 09:17:13 -0500 | [diff] [blame] | 27 | import android.service.quicksettings.Tile; |
Fabian Kozynski | 2594b93 | 2019-04-11 12:22:39 -0400 | [diff] [blame] | 28 | import android.telephony.SubscriptionManager; |
Amin Shaikh | 43ad7fe | 2018-03-05 14:34:44 -0500 | [diff] [blame] | 29 | import android.text.TextUtils; |
John Spurlock | b98f747 | 2014-07-08 17:09:42 -0400 | [diff] [blame] | 30 | import android.view.LayoutInflater; |
| 31 | import android.view.View; |
| 32 | import android.view.ViewGroup; |
Jason Monk | 9ca1848 | 2017-08-01 10:38:02 -0400 | [diff] [blame] | 33 | import android.view.WindowManager.LayoutParams; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 34 | import android.widget.Switch; |
Amin Shaikh | 0e00331 | 2018-03-08 11:39:01 -0500 | [diff] [blame] | 35 | |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 36 | import com.android.internal.logging.MetricsLogger; |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 37 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Jason Monk | f668d7c | 2016-01-14 10:38:41 -0500 | [diff] [blame] | 38 | import com.android.settingslib.net.DataUsageController; |
Amin Shaikh | 329c828 | 2018-03-09 14:50:59 -0500 | [diff] [blame] | 39 | import com.android.systemui.Prefs; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 40 | import com.android.systemui.R; |
Jason Monk | ec34da8 | 2017-02-24 15:57:05 -0500 | [diff] [blame] | 41 | import com.android.systemui.plugins.ActivityStarter; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 42 | import com.android.systemui.plugins.qs.DetailAdapter; |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 43 | import com.android.systemui.plugins.qs.QSTile.SignalState; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 44 | import com.android.systemui.qs.QSHost; |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 45 | import com.android.systemui.qs.tileimpl.QSTileImpl; |
Jason Monk | 54ff0ef | 2017-07-25 14:44:28 -0400 | [diff] [blame] | 46 | import com.android.systemui.statusbar.phone.SystemUIDialog; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 47 | import com.android.systemui.statusbar.policy.NetworkController; |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 48 | import com.android.systemui.statusbar.policy.NetworkController.IconState; |
Jason Monk | 0f0de13 | 2016-12-19 15:36:13 -0500 | [diff] [blame] | 49 | import com.android.systemui.statusbar.policy.NetworkController.SignalCallback; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 50 | |
Jason Monk | 5d57720 | 2018-12-26 15:43:06 -0500 | [diff] [blame] | 51 | import javax.inject.Inject; |
| 52 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 53 | /** Quick settings tile: Cellular **/ |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 54 | public class CellularTile extends QSTileImpl<SignalState> { |
Rajeev Kumar | a8981f3 | 2017-07-19 18:12:47 -0700 | [diff] [blame] | 55 | private static final String ENABLE_SETTINGS_DATA_PLAN = "enable.settings.data.plan"; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 56 | |
| 57 | private final NetworkController mController; |
Jason Monk | f668d7c | 2016-01-14 10:38:41 -0500 | [diff] [blame] | 58 | private final DataUsageController mDataController; |
John Spurlock | b98f747 | 2014-07-08 17:09:42 -0400 | [diff] [blame] | 59 | private final CellularDetailAdapter mDetailAdapter; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 60 | |
Jason Monk | 878c093 | 2015-07-21 10:18:01 -0400 | [diff] [blame] | 61 | private final CellSignalCallback mSignalCallback = new CellSignalCallback(); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 62 | private final ActivityStarter mActivityStarter; |
Jason Monk | 878c093 | 2015-07-21 10:18:01 -0400 | [diff] [blame] | 63 | |
Jason Monk | 5d57720 | 2018-12-26 15:43:06 -0500 | [diff] [blame] | 64 | @Inject |
Jason Monk | c0e0e2b | 2018-12-26 16:47:41 -0500 | [diff] [blame] | 65 | public CellularTile(QSHost host, NetworkController networkController, |
Fabian Kozynski | 88a1fe5 | 2019-03-25 14:58:55 -0400 | [diff] [blame] | 66 | ActivityStarter activityStarter) { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 67 | super(host); |
Jason Monk | c0e0e2b | 2018-12-26 16:47:41 -0500 | [diff] [blame] | 68 | mController = networkController; |
| 69 | mActivityStarter = activityStarter; |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 70 | mDataController = mController.getMobileDataController(); |
John Spurlock | b98f747 | 2014-07-08 17:09:42 -0400 | [diff] [blame] | 71 | mDetailAdapter = new CellularDetailAdapter(); |
Jason Monk | fa452ef | 2018-12-26 17:26:10 -0500 | [diff] [blame] | 72 | mController.observe(getLifecycle(), mSignalCallback); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | @Override |
Jason Monk | 62b63a0 | 2016-02-02 15:15:31 -0500 | [diff] [blame] | 76 | public SignalState newTileState() { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 77 | return new SignalState(); |
| 78 | } |
| 79 | |
| 80 | @Override |
John Spurlock | b98f747 | 2014-07-08 17:09:42 -0400 | [diff] [blame] | 81 | public DetailAdapter getDetailAdapter() { |
| 82 | return mDetailAdapter; |
| 83 | } |
| 84 | |
| 85 | @Override |
Jason Monk | 1c6116c | 2017-09-06 17:33:01 -0400 | [diff] [blame] | 86 | public void handleSetListening(boolean listening) { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | @Override |
Jason Monk | 76c67aa | 2016-02-19 14:49:42 -0500 | [diff] [blame] | 90 | public Intent getLongClickIntent() { |
Rohan Shah | 53f3f15 | 2018-02-28 15:13:31 -0800 | [diff] [blame] | 91 | return getCellularSettingIntent(); |
Jason Monk | 76c67aa | 2016-02-19 14:49:42 -0500 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | @Override |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 95 | protected void handleClick() { |
Evan Laird | b3f974f | 2017-09-07 19:02:23 -0400 | [diff] [blame] | 96 | if (getState().state == Tile.STATE_UNAVAILABLE) { |
| 97 | return; |
| 98 | } |
Jason Monk | 54ff0ef | 2017-07-25 14:44:28 -0400 | [diff] [blame] | 99 | if (mDataController.isMobileDataEnabled()) { |
Fabian Kozynski | 88a1fe5 | 2019-03-25 14:58:55 -0400 | [diff] [blame] | 100 | maybeShowDisableDialog(); |
Jason Monk | 54ff0ef | 2017-07-25 14:44:28 -0400 | [diff] [blame] | 101 | } else { |
| 102 | mDataController.setMobileDataEnabled(true); |
| 103 | } |
| 104 | } |
| 105 | |
Amin Shaikh | 26142a6 | 2018-04-11 15:20:32 -0400 | [diff] [blame] | 106 | private void maybeShowDisableDialog() { |
| 107 | if (Prefs.getBoolean(mContext, QS_HAS_TURNED_OFF_MOBILE_DATA, false)) { |
| 108 | // Directly turn off mobile data if the user has seen the dialog before. |
| 109 | mDataController.setMobileDataEnabled(false); |
| 110 | return; |
| 111 | } |
Amin Shaikh | 329c828 | 2018-03-09 14:50:59 -0500 | [diff] [blame] | 112 | String carrierName = mController.getMobileDataNetworkName(); |
| 113 | if (TextUtils.isEmpty(carrierName)) { |
| 114 | carrierName = mContext.getString(R.string.mobile_data_disable_message_default_carrier); |
| 115 | } |
Jason Monk | 9ca1848 | 2017-08-01 10:38:02 -0400 | [diff] [blame] | 116 | AlertDialog dialog = new Builder(mContext) |
Amin Shaikh | 329c828 | 2018-03-09 14:50:59 -0500 | [diff] [blame] | 117 | .setTitle(R.string.mobile_data_disable_title) |
| 118 | .setMessage(mContext.getString(R.string.mobile_data_disable_message, carrierName)) |
Jason Monk | 54ff0ef | 2017-07-25 14:44:28 -0400 | [diff] [blame] | 119 | .setNegativeButton(android.R.string.cancel, null) |
| 120 | .setPositiveButton( |
| 121 | com.android.internal.R.string.alert_windows_notification_turn_off_action, |
Amin Shaikh | 329c828 | 2018-03-09 14:50:59 -0500 | [diff] [blame] | 122 | (d, w) -> { |
| 123 | mDataController.setMobileDataEnabled(false); |
| 124 | Prefs.putBoolean(mContext, QS_HAS_TURNED_OFF_MOBILE_DATA, true); |
| 125 | }) |
Jason Monk | 9ca1848 | 2017-08-01 10:38:02 -0400 | [diff] [blame] | 126 | .create(); |
| 127 | dialog.getWindow().setType(LayoutParams.TYPE_KEYGUARD_DIALOG); |
| 128 | SystemUIDialog.setShowForAllUsers(dialog, true); |
| 129 | SystemUIDialog.registerDismissListener(dialog); |
| 130 | SystemUIDialog.setWindowOnTop(dialog); |
| 131 | dialog.show(); |
Jason Monk | 3250885 | 2017-01-18 09:17:13 -0500 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | @Override |
| 135 | protected void handleSecondaryClick() { |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 136 | if (mDataController.isMobileDataSupported()) { |
John Spurlock | b98f747 | 2014-07-08 17:09:42 -0400 | [diff] [blame] | 137 | showDetail(true); |
| 138 | } else { |
Rajeev Kumar | a8981f3 | 2017-07-19 18:12:47 -0700 | [diff] [blame] | 139 | mActivityStarter |
Rohan Shah | 53f3f15 | 2018-02-28 15:13:31 -0800 | [diff] [blame] | 140 | .postStartActivityDismissingKeyguard(getCellularSettingIntent(),0 /* delay */); |
John Spurlock | b98f747 | 2014-07-08 17:09:42 -0400 | [diff] [blame] | 141 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | @Override |
Jason Monk | 39c98e6 | 2016-03-16 09:18:35 -0400 | [diff] [blame] | 145 | public CharSequence getTileLabel() { |
| 146 | return mContext.getString(R.string.quick_settings_cellular_detail_title); |
| 147 | } |
| 148 | |
| 149 | @Override |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 150 | protected void handleUpdateState(SignalState state, Object arg) { |
Jason Monk | 878c093 | 2015-07-21 10:18:01 -0400 | [diff] [blame] | 151 | CallbackInfo cb = (CallbackInfo) arg; |
| 152 | if (cb == null) { |
| 153 | cb = mSignalCallback.mInfo; |
| 154 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 155 | |
| 156 | final Resources r = mContext.getResources(); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 157 | state.label = r.getString(R.string.mobile_data); |
Amin Shaikh | 43ad7fe | 2018-03-05 14:34:44 -0500 | [diff] [blame] | 158 | boolean mobileDataEnabled = mDataController.isMobileDataSupported() |
| 159 | && mDataController.isMobileDataEnabled(); |
| 160 | state.value = mobileDataEnabled; |
Amin Shaikh | 0a8155e0 | 2018-09-06 17:23:32 -0400 | [diff] [blame] | 161 | state.activityIn = mobileDataEnabled && cb.activityIn; |
| 162 | state.activityOut = mobileDataEnabled && cb.activityOut; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 163 | state.expandedAccessibilityClassName = Switch.class.getName(); |
Evan Laird | 4a7db95 | 2017-09-06 16:43:24 -0400 | [diff] [blame] | 164 | if (cb.noSim) { |
| 165 | state.icon = ResourceIcon.get(R.drawable.ic_qs_no_sim); |
| 166 | } else { |
Amin Shaikh | 0e00331 | 2018-03-08 11:39:01 -0500 | [diff] [blame] | 167 | state.icon = ResourceIcon.get(R.drawable.ic_swap_vert); |
Evan Laird | 4a7db95 | 2017-09-06 16:43:24 -0400 | [diff] [blame] | 168 | } |
| 169 | |
Amin Shaikh | 43ad7fe | 2018-03-05 14:34:44 -0500 | [diff] [blame] | 170 | if (cb.noSim) { |
Evan Laird | b3f974f | 2017-09-07 19:02:23 -0400 | [diff] [blame] | 171 | state.state = Tile.STATE_UNAVAILABLE; |
Amin Shaikh | 43ad7fe | 2018-03-05 14:34:44 -0500 | [diff] [blame] | 172 | state.secondaryLabel = r.getString(R.string.keyguard_missing_sim_message_short); |
| 173 | } else if (cb.airplaneModeEnabled) { |
| 174 | state.state = Tile.STATE_UNAVAILABLE; |
| 175 | state.secondaryLabel = r.getString(R.string.status_bar_airplane); |
| 176 | } else if (mobileDataEnabled) { |
Evan Laird | 3d1aad6 | 2017-06-20 16:10:44 -0400 | [diff] [blame] | 177 | state.state = Tile.STATE_ACTIVE; |
Fabian Kozynski | f1c32a0 | 2019-03-22 15:09:30 -0400 | [diff] [blame] | 178 | state.secondaryLabel = appendMobileDataType( |
| 179 | // Only show carrier name if there are more than 1 subscription |
| 180 | cb.multipleSubs ? cb.dataSubscriptionName : "", |
| 181 | getMobileDataContentName(cb)); |
Amin Shaikh | 43ad7fe | 2018-03-05 14:34:44 -0500 | [diff] [blame] | 182 | } else { |
| 183 | state.state = Tile.STATE_INACTIVE; |
| 184 | state.secondaryLabel = r.getString(R.string.cell_data_off); |
Evan Laird | 3d1aad6 | 2017-06-20 16:10:44 -0400 | [diff] [blame] | 185 | } |
Rohan Shah | 7bc3744 | 2018-04-10 00:34:50 -0400 | [diff] [blame] | 186 | |
| 187 | |
| 188 | // TODO(b/77881974): Instead of switching out the description via a string check for |
| 189 | // we need to have two strings provided by the MobileIconGroup. |
| 190 | final CharSequence contentDescriptionSuffix; |
| 191 | if (state.state == Tile.STATE_INACTIVE) { |
| 192 | contentDescriptionSuffix = r.getString(R.string.cell_data_off_content_description); |
| 193 | } else { |
| 194 | contentDescriptionSuffix = state.secondaryLabel; |
| 195 | } |
| 196 | |
| 197 | state.contentDescription = state.label + ", " + contentDescriptionSuffix; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 198 | } |
| 199 | |
Fabian Kozynski | c651e64 | 2019-02-21 13:20:34 -0500 | [diff] [blame] | 200 | private CharSequence appendMobileDataType(CharSequence current, CharSequence dataType) { |
| 201 | if (TextUtils.isEmpty(dataType)) { |
| 202 | return current; |
| 203 | } |
Fabian Kozynski | f1c32a0 | 2019-03-22 15:09:30 -0400 | [diff] [blame] | 204 | if (TextUtils.isEmpty(current)) { |
| 205 | return dataType; |
| 206 | } |
| 207 | return mContext.getString(R.string.mobile_carrier_text_format, current, dataType); |
Fabian Kozynski | c651e64 | 2019-02-21 13:20:34 -0500 | [diff] [blame] | 208 | } |
| 209 | |
Fabian Kozynski | f1c32a0 | 2019-03-22 15:09:30 -0400 | [diff] [blame] | 210 | private CharSequence getMobileDataContentName(CallbackInfo cb) { |
| 211 | if (cb.roaming && !TextUtils.isEmpty(cb.dataContentDescription)) { |
Amin Shaikh | 43ad7fe | 2018-03-05 14:34:44 -0500 | [diff] [blame] | 212 | String roaming = mContext.getString(R.string.data_connection_roaming); |
Fabian Kozynski | f1c32a0 | 2019-03-22 15:09:30 -0400 | [diff] [blame] | 213 | String dataDescription = cb.dataContentDescription.toString(); |
Amin Shaikh | 43ad7fe | 2018-03-05 14:34:44 -0500 | [diff] [blame] | 214 | return mContext.getString(R.string.mobile_data_text_format, roaming, dataDescription); |
| 215 | } |
| 216 | if (cb.roaming) { |
| 217 | return mContext.getString(R.string.data_connection_roaming); |
| 218 | } |
Fabian Kozynski | f1c32a0 | 2019-03-22 15:09:30 -0400 | [diff] [blame] | 219 | return cb.dataContentDescription; |
Amin Shaikh | 43ad7fe | 2018-03-05 14:34:44 -0500 | [diff] [blame] | 220 | } |
| 221 | |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 222 | @Override |
| 223 | public int getMetricsCategory() { |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 224 | return MetricsEvent.QS_CELLULAR; |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 225 | } |
| 226 | |
Jason Monk | c3f42c1 | 2016-02-05 12:33:13 -0500 | [diff] [blame] | 227 | @Override |
| 228 | public boolean isAvailable() { |
| 229 | return mController.hasMobileDataFeature(); |
| 230 | } |
| 231 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 232 | private static final class CallbackInfo { |
John Spurlock | d5cd2fd | 2014-07-27 11:36:33 -0400 | [diff] [blame] | 233 | boolean airplaneModeEnabled; |
Fabian Kozynski | 9d3fd6c | 2019-01-17 10:56:45 -0500 | [diff] [blame] | 234 | CharSequence dataSubscriptionName; |
Fabian Kozynski | c651e64 | 2019-02-21 13:20:34 -0500 | [diff] [blame] | 235 | CharSequence dataContentDescription; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 236 | boolean activityIn; |
| 237 | boolean activityOut; |
John Spurlock | 899f439 | 2014-06-11 10:59:11 -0400 | [diff] [blame] | 238 | boolean noSim; |
Jason Monk | 0f0de13 | 2016-12-19 15:36:13 -0500 | [diff] [blame] | 239 | boolean roaming; |
Fabian Kozynski | f1c32a0 | 2019-03-22 15:09:30 -0400 | [diff] [blame] | 240 | boolean multipleSubs; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 241 | } |
| 242 | |
Jason Monk | 0f0de13 | 2016-12-19 15:36:13 -0500 | [diff] [blame] | 243 | private final class CellSignalCallback implements SignalCallback { |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 244 | private final CallbackInfo mInfo = new CallbackInfo(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 245 | |
| 246 | @Override |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 247 | public void setMobileDataIndicators(IconState statusIcon, IconState qsIcon, int statusType, |
| 248 | int qsType, boolean activityIn, boolean activityOut, String typeContentDescription, |
| 249 | String description, boolean isWide, int subId, boolean roaming) { |
| 250 | if (qsIcon == null) { |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 251 | // Not data sim, don't display. |
| 252 | return; |
| 253 | } |
Fabian Kozynski | 9d3fd6c | 2019-01-17 10:56:45 -0500 | [diff] [blame] | 254 | mInfo.dataSubscriptionName = mController.getMobileDataNetworkName(); |
Fabian Kozynski | c651e64 | 2019-02-21 13:20:34 -0500 | [diff] [blame] | 255 | mInfo.dataContentDescription = (description != null) ? typeContentDescription : null; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 256 | mInfo.activityIn = activityIn; |
| 257 | mInfo.activityOut = activityOut; |
Jason Monk | 0f0de13 | 2016-12-19 15:36:13 -0500 | [diff] [blame] | 258 | mInfo.roaming = roaming; |
Fabian Kozynski | f1c32a0 | 2019-03-22 15:09:30 -0400 | [diff] [blame] | 259 | mInfo.multipleSubs = mController.getNumberSubscriptions() > 1; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 260 | refreshState(mInfo); |
| 261 | } |
| 262 | |
| 263 | @Override |
Jason Monk | 1ff7766 | 2017-09-29 11:17:05 -0400 | [diff] [blame] | 264 | public void setNoSims(boolean show, boolean simDetected) { |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 265 | mInfo.noSim = show; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 266 | refreshState(mInfo); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | @Override |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 270 | public void setIsAirplaneMode(IconState icon) { |
| 271 | mInfo.airplaneModeEnabled = icon.visible; |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 272 | refreshState(mInfo); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 273 | } |
John Spurlock | b98f747 | 2014-07-08 17:09:42 -0400 | [diff] [blame] | 274 | |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 275 | @Override |
| 276 | public void setMobileDataEnabled(boolean enabled) { |
John Spurlock | b98f747 | 2014-07-08 17:09:42 -0400 | [diff] [blame] | 277 | mDetailAdapter.setMobileDataEnabled(enabled); |
| 278 | } |
Rajeev Kumar | a8981f3 | 2017-07-19 18:12:47 -0700 | [diff] [blame] | 279 | } |
| 280 | |
Rohan Shah | 53f3f15 | 2018-02-28 15:13:31 -0800 | [diff] [blame] | 281 | static Intent getCellularSettingIntent() { |
Fabian Kozynski | 2594b93 | 2019-04-11 12:22:39 -0400 | [diff] [blame] | 282 | Intent intent = new Intent(Settings.ACTION_NETWORK_OPERATOR_SETTINGS); |
| 283 | int dataSub = SubscriptionManager.getDefaultDataSubscriptionId(); |
| 284 | if (dataSub != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 285 | intent.putExtra(Settings.EXTRA_SUB_ID, |
| 286 | SubscriptionManager.getDefaultDataSubscriptionId()); |
| 287 | } |
| 288 | return intent; |
Rajeev Kumar | a8981f3 | 2017-07-19 18:12:47 -0700 | [diff] [blame] | 289 | } |
John Spurlock | b98f747 | 2014-07-08 17:09:42 -0400 | [diff] [blame] | 290 | |
| 291 | private final class CellularDetailAdapter implements DetailAdapter { |
John Spurlock | b98f747 | 2014-07-08 17:09:42 -0400 | [diff] [blame] | 292 | |
| 293 | @Override |
Jason Monk | c06fbb1 | 2016-01-08 14:12:18 -0500 | [diff] [blame] | 294 | public CharSequence getTitle() { |
| 295 | return mContext.getString(R.string.quick_settings_cellular_detail_title); |
John Spurlock | b98f747 | 2014-07-08 17:09:42 -0400 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | @Override |
| 299 | public Boolean getToggleState() { |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 300 | return mDataController.isMobileDataSupported() |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 301 | ? mDataController.isMobileDataEnabled() |
| 302 | : null; |
John Spurlock | b98f747 | 2014-07-08 17:09:42 -0400 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | @Override |
| 306 | public Intent getSettingsIntent() { |
Rohan Shah | 53f3f15 | 2018-02-28 15:13:31 -0800 | [diff] [blame] | 307 | return getCellularSettingIntent(); |
John Spurlock | b98f747 | 2014-07-08 17:09:42 -0400 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | @Override |
| 311 | public void setToggleState(boolean state) { |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 312 | MetricsLogger.action(mContext, MetricsEvent.QS_CELLULAR_TOGGLE, state); |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 313 | mDataController.setMobileDataEnabled(state); |
John Spurlock | b98f747 | 2014-07-08 17:09:42 -0400 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | @Override |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 317 | public int getMetricsCategory() { |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 318 | return MetricsEvent.QS_DATAUSAGEDETAIL; |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | @Override |
John Spurlock | b98f747 | 2014-07-08 17:09:42 -0400 | [diff] [blame] | 322 | public View createDetailView(Context context, View convertView, ViewGroup parent) { |
Jorim Jaggi | e17c4b4 | 2014-08-26 17:27:31 +0200 | [diff] [blame] | 323 | final DataUsageDetailView v = (DataUsageDetailView) (convertView != null |
| 324 | ? convertView |
| 325 | : LayoutInflater.from(mContext).inflate(R.layout.data_usage, parent, false)); |
Jason Monk | f668d7c | 2016-01-14 10:38:41 -0500 | [diff] [blame] | 326 | final DataUsageController.DataUsageInfo info = mDataController.getDataUsageInfo(); |
John Spurlock | b98f747 | 2014-07-08 17:09:42 -0400 | [diff] [blame] | 327 | if (info == null) return v; |
Jorim Jaggi | e17c4b4 | 2014-08-26 17:27:31 +0200 | [diff] [blame] | 328 | v.bind(info); |
Jason Monk | 0f0de13 | 2016-12-19 15:36:13 -0500 | [diff] [blame] | 329 | v.findViewById(R.id.roaming_text).setVisibility(mSignalCallback.mInfo.roaming |
| 330 | ? View.VISIBLE : View.INVISIBLE); |
John Spurlock | b98f747 | 2014-07-08 17:09:42 -0400 | [diff] [blame] | 331 | return v; |
| 332 | } |
| 333 | |
| 334 | public void setMobileDataEnabled(boolean enabled) { |
| 335 | fireToggleStateChanged(enabled); |
| 336 | } |
John Spurlock | b98f747 | 2014-07-08 17:09:42 -0400 | [diff] [blame] | 337 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 338 | } |