blob: 6987d92e949a8ddfc626b776222e9a963e523fa8 [file] [log] [blame]
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001package com.android.settings;
2
3import android.app.Activity;
Jason Monk39b46742015-09-10 15:52:51 -04004import android.content.DialogInterface;
5import android.os.AsyncResult;
6import android.os.Bundle;
7import android.os.Handler;
8import android.os.Message;
9import android.util.Log;
10import android.view.View;
11import android.view.Window;
Jason Monk39b46742015-09-10 15:52:51 -040012import android.widget.AdapterView;
13import android.widget.ArrayAdapter;
14import android.widget.ListView;
15
Fan Zhang23f8d592018-08-28 15:11:40 -070016import androidx.appcompat.app.AlertDialog;
17
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080018import com.android.internal.telephony.Phone;
19import com.android.internal.telephony.PhoneFactory;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080020
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080021/**
22 * Radio Band Mode Selection Class
23 *
24 * It will query baseband about all available band modes and display them
25 * in screen. It will display all six band modes if the query failed.
26 *
27 * After user select one band, it will send the selection to baseband.
28 *
29 * It will alter user the result of select operation and exit, no matter success
30 * or not.
31 *
32 */
33public class BandMode extends Activity {
34 private static final String LOG_TAG = "phone";
35 private static final boolean DBG = false;
36
37 private static final int EVENT_BAND_SCAN_COMPLETED = 100;
38 private static final int EVENT_BAND_SELECTION_DONE = 200;
39
Nathan Harold575fe1a2016-02-12 10:03:36 -080040 //Directly maps to RIL_RadioBandMode from ril.h
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080041 private static final String[] BAND_NAMES = new String[] {
42 "Automatic",
Nathan Harold575fe1a2016-02-12 10:03:36 -080043 "Europe",
44 "United States",
45 "Japan",
46 "Australia",
47 "Australia 2",
48 "Cellular 800",
49 "PCS",
50 "Class 3 (JTACS)",
51 "Class 4 (Korea-PCS)",
52 "Class 5",
53 "Class 6 (IMT2000)",
54 "Class 7 (700Mhz-Upper)",
55 "Class 8 (1800Mhz-Upper)",
56 "Class 9 (900Mhz)",
57 "Class 10 (800Mhz-Secondary)",
58 "Class 11 (Europe PAMR 400Mhz)",
59 "Class 15 (US-AWS)",
60 "Class 16 (US-2500Mhz)"
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080061 };
62
63 private ListView mBandList;
64 private ArrayAdapter mBandListAdapter;
65 private BandListItem mTargetBand = null;
66 private DialogInterface mProgressPanel;
67
68 private Phone mPhone = null;
69
70 @Override
71 protected void onCreate(Bundle icicle) {
72 super.onCreate(icicle);
73
74 requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080075 setContentView(R.layout.band_mode);
76
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080077 mPhone = PhoneFactory.getDefaultPhone();
78
79 mBandList = (ListView) findViewById(R.id.band);
80 mBandListAdapter = new ArrayAdapter<BandListItem>(this,
81 android.R.layout.simple_list_item_1);
82 mBandList.setAdapter(mBandListAdapter);
83 mBandList.setOnItemClickListener(mBandSelectionHandler);
84
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080085 loadBandList();
86 }
87
88 private AdapterView.OnItemClickListener mBandSelectionHandler =
89 new AdapterView.OnItemClickListener () {
90 public void onItemClick(AdapterView parent, View v,
91 int position, long id) {
92
93 getWindow().setFeatureInt(
94 Window.FEATURE_INDETERMINATE_PROGRESS,
95 Window.PROGRESS_VISIBILITY_ON);
96
97 mTargetBand = (BandListItem) parent.getAdapter().getItem(position);
98
99 if (DBG) log("Select band : " + mTargetBand.toString());
100
101 Message msg =
102 mHandler.obtainMessage(EVENT_BAND_SELECTION_DONE);
103 mPhone.setBandMode(mTargetBand.getBand(), msg);
104 }
105 };
106
Michael Chan87620932009-05-14 17:47:02 -0700107 static private class BandListItem {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800108 private int mBandMode = Phone.BM_UNSPECIFIED;
109
110 public BandListItem(int bm) {
111 mBandMode = bm;
112 }
113
114 public int getBand() {
115 return mBandMode;
116 }
117
118 public String toString() {
Derek Taneb4575e2014-04-25 16:47:54 -0700119 if (mBandMode >= BAND_NAMES.length) return "Band mode " + mBandMode;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800120 return BAND_NAMES[mBandMode];
121 }
122 }
123
124 private void loadBandList() {
125 String str = getString(R.string.band_mode_loading);
126
127 if (DBG) log(str);
128
129
130 //ProgressDialog.show(this, null, str, true, true, null);
131 mProgressPanel = new AlertDialog.Builder(this)
132 .setMessage(str)
133 .show();
134
135 Message msg = mHandler.obtainMessage(EVENT_BAND_SCAN_COMPLETED);
136 mPhone.queryAvailableBandMode(msg);
137
138 }
139
140 private void bandListLoaded(AsyncResult result) {
141 if (DBG) log("network list loaded");
142
143 if (mProgressPanel != null) mProgressPanel.dismiss();
144
145 clearList();
146
147 boolean addBandSuccess = false;
148 BandListItem item;
149
150 if (result.result != null) {
151 int bands[] = (int[])result.result;
Nathan Harold575fe1a2016-02-12 10:03:36 -0800152
153 if(bands.length == 0) {
154 Log.wtf(LOG_TAG, "No Supported Band Modes");
155 return;
156 }
157
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800158 int size = bands[0];
159
160 if (size > 0) {
Nathan Haroldf8555e42016-12-19 18:04:52 -0800161 mBandListAdapter.add(
162 new BandListItem(Phone.BM_UNSPECIFIED)); //Always include AUTOMATIC
Nathan Harold575fe1a2016-02-12 10:03:36 -0800163 for (int i=1; i<=size; i++) {
Nathan Haroldf8555e42016-12-19 18:04:52 -0800164 if (bands[i] == Phone.BM_UNSPECIFIED) {
165 continue;
166 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800167 item = new BandListItem(bands[i]);
168 mBandListAdapter.add(item);
169 if (DBG) log("Add " + item.toString());
170 }
171 addBandSuccess = true;
172 }
173 }
174
175 if (addBandSuccess == false) {
176 if (DBG) log("Error in query, add default list");
Nathan Harold575fe1a2016-02-12 10:03:36 -0800177 for (int i=0; i<Phone.BM_NUM_BAND_MODES; i++) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800178 item = new BandListItem(i);
179 mBandListAdapter.add(item);
180 if (DBG) log("Add default " + item.toString());
181 }
182 }
183 mBandList.requestFocus();
184 }
185
186 private void displayBandSelectionResult(Throwable ex) {
187 String status = getString(R.string.band_mode_set)
188 +" [" + mTargetBand.toString() + "] ";
189
190 if (ex != null) {
191 status = status + getString(R.string.band_mode_failed);
192 } else {
193 status = status + getString(R.string.band_mode_succeeded);
194 }
195
196 mProgressPanel = new AlertDialog.Builder(this)
197 .setMessage(status)
198 .setPositiveButton(android.R.string.ok, null).show();
199 }
200
201 private void clearList() {
202 while(mBandListAdapter.getCount() > 0) {
203 mBandListAdapter.remove(
204 mBandListAdapter.getItem(0));
205 }
206 }
207
208 private void log(String msg) {
209 Log.d(LOG_TAG, "[BandsList] " + msg);
210 }
211
212 private Handler mHandler = new Handler() {
213 public void handleMessage(Message msg) {
214 AsyncResult ar;
215 switch (msg.what) {
216 case EVENT_BAND_SCAN_COMPLETED:
217 ar = (AsyncResult) msg.obj;
218
219 bandListLoaded(ar);
220 break;
221
222 case EVENT_BAND_SELECTION_DONE:
223 ar = (AsyncResult) msg.obj;
224
225 getWindow().setFeatureInt(
226 Window.FEATURE_INDETERMINATE_PROGRESS,
227 Window.PROGRESS_VISIBILITY_OFF);
228
Jeevaka Badrappan26ef2c32012-06-01 10:57:31 +0300229 if (!isFinishing()) {
230 displayBandSelectionResult(ar.exception);
231 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800232 break;
233 }
234 }
235 };
236
237
238}