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