2 * Copyright (C) 2006 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.settings;
19 import android.app.AlertDialog;
20 import android.app.Dialog;
21 import android.content.ContentUris;
22 import android.content.ContentValues;
23 import android.content.Intent;
24 import android.content.res.Resources;
25 import android.database.Cursor;
26 import android.net.Uri;
27 import android.os.Bundle;
28 import android.provider.Telephony;
29 import android.support.v14.preference.MultiSelectListPreference;
30 import android.support.v14.preference.SwitchPreference;
31 import android.support.v7.preference.EditTextPreference;
32 import android.support.v7.preference.ListPreference;
33 import android.support.v7.preference.Preference;
34 import android.telephony.ServiceState;
35 import android.telephony.SubscriptionManager;
36 import android.telephony.TelephonyManager;
37 import android.text.TextUtils;
38 import android.util.Log;
39 import android.view.KeyEvent;
40 import android.view.Menu;
41 import android.view.MenuItem;
42 import com.android.internal.logging.MetricsProto.MetricsEvent;
44 import java.util.HashSet;
47 public class ApnEditor extends InstrumentedPreferenceActivity
48 implements Preference.OnPreferenceChangeListener {
50 private final static String TAG = ApnEditor.class.getSimpleName();
52 private final static String SAVED_POS = "pos";
53 private final static String KEY_AUTH_TYPE = "auth_type";
54 private final static String KEY_PROTOCOL = "apn_protocol";
55 private final static String KEY_ROAMING_PROTOCOL = "apn_roaming_protocol";
56 private final static String KEY_CARRIER_ENABLED = "carrier_enabled";
57 private final static String KEY_BEARER_MULTI = "bearer_multi";
58 private final static String KEY_MVNO_TYPE = "mvno_type";
60 private static final int MENU_DELETE = Menu.FIRST;
61 private static final int MENU_SAVE = Menu.FIRST + 1;
62 private static final int MENU_CANCEL = Menu.FIRST + 2;
63 private static final int ERROR_DIALOG_ID = 0;
65 private static String sNotSet;
66 private EditTextPreference mName;
67 private EditTextPreference mApn;
68 private EditTextPreference mProxy;
69 private EditTextPreference mPort;
70 private EditTextPreference mUser;
71 private EditTextPreference mServer;
72 private EditTextPreference mPassword;
73 private EditTextPreference mMmsc;
74 private EditTextPreference mMcc;
75 private EditTextPreference mMnc;
76 private EditTextPreference mMmsProxy;
77 private EditTextPreference mMmsPort;
78 private ListPreference mAuthType;
79 private EditTextPreference mApnType;
80 private ListPreference mProtocol;
81 private ListPreference mRoamingProtocol;
82 private SwitchPreference mCarrierEnabled;
83 private MultiSelectListPreference mBearerMulti;
84 private ListPreference mMvnoType;
85 private EditTextPreference mMvnoMatchData;
87 private String mCurMnc;
88 private String mCurMcc;
91 private Cursor mCursor;
92 private boolean mNewApn;
93 private boolean mFirstTime;
95 private Resources mRes;
96 private TelephonyManager mTelephonyManager;
97 private int mBearerInitialVal = 0;
98 private String mMvnoTypeStr;
99 private String mMvnoMatchDataStr;
102 * Standard projection for the interesting columns of a normal note.
104 private static final String[] sProjection = new String[] {
105 Telephony.Carriers._ID, // 0
106 Telephony.Carriers.NAME, // 1
107 Telephony.Carriers.APN, // 2
108 Telephony.Carriers.PROXY, // 3
109 Telephony.Carriers.PORT, // 4
110 Telephony.Carriers.USER, // 5
111 Telephony.Carriers.SERVER, // 6
112 Telephony.Carriers.PASSWORD, // 7
113 Telephony.Carriers.MMSC, // 8
114 Telephony.Carriers.MCC, // 9
115 Telephony.Carriers.MNC, // 10
116 Telephony.Carriers.NUMERIC, // 11
117 Telephony.Carriers.MMSPROXY,// 12
118 Telephony.Carriers.MMSPORT, // 13
119 Telephony.Carriers.AUTH_TYPE, // 14
120 Telephony.Carriers.TYPE, // 15
121 Telephony.Carriers.PROTOCOL, // 16
122 Telephony.Carriers.CARRIER_ENABLED, // 17
123 Telephony.Carriers.BEARER, // 18
124 Telephony.Carriers.BEARER_BITMASK, // 19
125 Telephony.Carriers.ROAMING_PROTOCOL, // 20
126 Telephony.Carriers.MVNO_TYPE, // 21
127 Telephony.Carriers.MVNO_MATCH_DATA // 22
130 private static final int ID_INDEX = 0;
131 private static final int NAME_INDEX = 1;
132 private static final int APN_INDEX = 2;
133 private static final int PROXY_INDEX = 3;
134 private static final int PORT_INDEX = 4;
135 private static final int USER_INDEX = 5;
136 private static final int SERVER_INDEX = 6;
137 private static final int PASSWORD_INDEX = 7;
138 private static final int MMSC_INDEX = 8;
139 private static final int MCC_INDEX = 9;
140 private static final int MNC_INDEX = 10;
141 private static final int MMSPROXY_INDEX = 12;
142 private static final int MMSPORT_INDEX = 13;
143 private static final int AUTH_TYPE_INDEX = 14;
144 private static final int TYPE_INDEX = 15;
145 private static final int PROTOCOL_INDEX = 16;
146 private static final int CARRIER_ENABLED_INDEX = 17;
147 private static final int BEARER_INDEX = 18;
148 private static final int BEARER_BITMASK_INDEX = 19;
149 private static final int ROAMING_PROTOCOL_INDEX = 20;
150 private static final int MVNO_TYPE_INDEX = 21;
151 private static final int MVNO_MATCH_DATA_INDEX = 22;
155 protected void onCreate(Bundle icicle) {
156 super.onCreate(icicle);
158 addPreferencesFromResource(R.xml.apn_editor);
160 sNotSet = getResources().getString(R.string.apn_not_set);
161 mName = (EditTextPreference) findPreference("apn_name");
162 mApn = (EditTextPreference) findPreference("apn_apn");
163 mProxy = (EditTextPreference) findPreference("apn_http_proxy");
164 mPort = (EditTextPreference) findPreference("apn_http_port");
165 mUser = (EditTextPreference) findPreference("apn_user");
166 mServer = (EditTextPreference) findPreference("apn_server");
167 mPassword = (EditTextPreference) findPreference("apn_password");
168 mMmsProxy = (EditTextPreference) findPreference("apn_mms_proxy");
169 mMmsPort = (EditTextPreference) findPreference("apn_mms_port");
170 mMmsc = (EditTextPreference) findPreference("apn_mmsc");
171 mMcc = (EditTextPreference) findPreference("apn_mcc");
172 mMnc = (EditTextPreference) findPreference("apn_mnc");
173 mApnType = (EditTextPreference) findPreference("apn_type");
175 mAuthType = (ListPreference) findPreference(KEY_AUTH_TYPE);
176 mAuthType.setOnPreferenceChangeListener(this);
178 mProtocol = (ListPreference) findPreference(KEY_PROTOCOL);
179 mProtocol.setOnPreferenceChangeListener(this);
181 mRoamingProtocol = (ListPreference) findPreference(KEY_ROAMING_PROTOCOL);
182 mRoamingProtocol.setOnPreferenceChangeListener(this);
184 mCarrierEnabled = (SwitchPreference) findPreference(KEY_CARRIER_ENABLED);
186 mBearerMulti = (MultiSelectListPreference) findPreference(KEY_BEARER_MULTI);
187 mBearerMulti.setOnPreferenceChangeListener(this);
189 mMvnoType = (ListPreference) findPreference(KEY_MVNO_TYPE);
190 mMvnoType.setOnPreferenceChangeListener(this);
191 mMvnoMatchData = (EditTextPreference) findPreference("mvno_match_data");
193 mRes = getResources();
195 final Intent intent = getIntent();
196 final String action = intent.getAction();
197 mSubId = intent.getIntExtra(ApnSettings.SUB_ID,
198 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
200 mFirstTime = icicle == null;
202 if (action.equals(Intent.ACTION_EDIT)) {
203 Uri uri = intent.getData();
204 if (!uri.isPathPrefixMatch(Telephony.Carriers.CONTENT_URI)) {
205 Log.e(TAG, "Edit request not for carrier table. Uri: " + uri);
210 } else if (action.equals(Intent.ACTION_INSERT)) {
211 if (mFirstTime || icicle.getInt(SAVED_POS) == 0) {
212 Uri uri = intent.getData();
213 if (!uri.isPathPrefixMatch(Telephony.Carriers.CONTENT_URI)) {
214 Log.e(TAG, "Insert request not for carrier table. Uri: " + uri);
218 mUri = getContentResolver().insert(uri, new ContentValues());
220 mUri = ContentUris.withAppendedId(Telephony.Carriers.CONTENT_URI,
221 icicle.getInt(SAVED_POS));
224 mMvnoTypeStr = intent.getStringExtra(ApnSettings.MVNO_TYPE);
225 mMvnoMatchDataStr = intent.getStringExtra(ApnSettings.MVNO_MATCH_DATA);
226 // If we were unable to create a new note, then just finish
227 // this activity. A RESULT_CANCELED will be sent back to the
228 // original activity if they requested a result.
230 Log.w(TAG, "Failed to insert new telephony provider into "
231 + getIntent().getData());
236 // The new entry was created, so assume all will end well and
237 // set the result to be returned.
238 setResult(RESULT_OK, (new Intent()).setAction(mUri.toString()));
245 mCursor = managedQuery(mUri, sProjection, null, null);
246 mCursor.moveToFirst();
248 mTelephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
250 for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); i++) {
251 getPreferenceScreen().getPreference(i).setOnPreferenceChangeListener(this);
258 protected int getMetricsCategory() {
259 return MetricsEvent.APN_EDITOR;
263 public void onResume() {
268 public void onPause() {
272 private void fillUi() {
275 // Fill in all the values from the db in both text editor and summary
276 mName.setText(mCursor.getString(NAME_INDEX));
277 mApn.setText(mCursor.getString(APN_INDEX));
278 mProxy.setText(mCursor.getString(PROXY_INDEX));
279 mPort.setText(mCursor.getString(PORT_INDEX));
280 mUser.setText(mCursor.getString(USER_INDEX));
281 mServer.setText(mCursor.getString(SERVER_INDEX));
282 mPassword.setText(mCursor.getString(PASSWORD_INDEX));
283 mMmsProxy.setText(mCursor.getString(MMSPROXY_INDEX));
284 mMmsPort.setText(mCursor.getString(MMSPORT_INDEX));
285 mMmsc.setText(mCursor.getString(MMSC_INDEX));
286 mMcc.setText(mCursor.getString(MCC_INDEX));
287 mMnc.setText(mCursor.getString(MNC_INDEX));
288 mApnType.setText(mCursor.getString(TYPE_INDEX));
290 String numeric = mTelephonyManager.getSimOperator(mSubId);
291 // MCC is first 3 chars and then in 2 - 3 chars of MNC
292 if (numeric != null && numeric.length() > 4) {
294 String mcc = numeric.substring(0, 3);
296 String mnc = numeric.substring(3);
297 // Auto populate MNC and MCC for new entries, based on what SIM reports
304 int authVal = mCursor.getInt(AUTH_TYPE_INDEX);
306 mAuthType.setValueIndex(authVal);
308 mAuthType.setValue(null);
311 mProtocol.setValue(mCursor.getString(PROTOCOL_INDEX));
312 mRoamingProtocol.setValue(mCursor.getString(ROAMING_PROTOCOL_INDEX));
313 mCarrierEnabled.setChecked(mCursor.getInt(CARRIER_ENABLED_INDEX)==1);
314 mBearerInitialVal = mCursor.getInt(BEARER_INDEX);
316 HashSet<String> bearers = new HashSet<String>();
317 int bearerBitmask = mCursor.getInt(BEARER_BITMASK_INDEX);
318 if (bearerBitmask == 0) {
319 if (mBearerInitialVal == 0) {
324 while (bearerBitmask != 0) {
325 if ((bearerBitmask & 1) == 1) {
333 if (mBearerInitialVal != 0 && bearers.contains("" + mBearerInitialVal) == false) {
334 // add mBearerInitialVal to bearers
335 bearers.add("" + mBearerInitialVal);
337 mBearerMulti.setValues(bearers);
339 mMvnoType.setValue(mCursor.getString(MVNO_TYPE_INDEX));
340 mMvnoMatchData.setEnabled(false);
341 mMvnoMatchData.setText(mCursor.getString(MVNO_MATCH_DATA_INDEX));
342 if (mNewApn && mMvnoTypeStr != null && mMvnoMatchDataStr != null) {
343 mMvnoType.setValue(mMvnoTypeStr);
344 mMvnoMatchData.setText(mMvnoMatchDataStr);
348 mName.setSummary(checkNull(mName.getText()));
349 mApn.setSummary(checkNull(mApn.getText()));
350 mProxy.setSummary(checkNull(mProxy.getText()));
351 mPort.setSummary(checkNull(mPort.getText()));
352 mUser.setSummary(checkNull(mUser.getText()));
353 mServer.setSummary(checkNull(mServer.getText()));
354 mPassword.setSummary(starify(mPassword.getText()));
355 mMmsProxy.setSummary(checkNull(mMmsProxy.getText()));
356 mMmsPort.setSummary(checkNull(mMmsPort.getText()));
357 mMmsc.setSummary(checkNull(mMmsc.getText()));
358 mMcc.setSummary(checkNull(mMcc.getText()));
359 mMnc.setSummary(checkNull(mMnc.getText()));
360 mApnType.setSummary(checkNull(mApnType.getText()));
362 String authVal = mAuthType.getValue();
363 if (authVal != null) {
364 int authValIndex = Integer.parseInt(authVal);
365 mAuthType.setValueIndex(authValIndex);
367 String []values = mRes.getStringArray(R.array.apn_auth_entries);
368 mAuthType.setSummary(values[authValIndex]);
370 mAuthType.setSummary(sNotSet);
373 mProtocol.setSummary(
374 checkNull(protocolDescription(mProtocol.getValue(), mProtocol)));
375 mRoamingProtocol.setSummary(
376 checkNull(protocolDescription(mRoamingProtocol.getValue(), mRoamingProtocol)));
377 mBearerMulti.setSummary(
378 checkNull(bearerMultiDescription(mBearerMulti.getValues())));
379 mMvnoType.setSummary(
380 checkNull(mvnoDescription(mMvnoType.getValue())));
381 mMvnoMatchData.setSummary(checkNull(mMvnoMatchData.getText()));
382 // allow user to edit carrier_enabled for some APN
383 boolean ceEditable = getResources().getBoolean(R.bool.config_allow_edit_carrier_enabled);
385 mCarrierEnabled.setEnabled(true);
387 mCarrierEnabled.setEnabled(false);
392 * Returns the UI choice (e.g., "IPv4/IPv6") corresponding to the given
393 * raw value of the protocol preference (e.g., "IPV4V6"). If unknown,
396 private String protocolDescription(String raw, ListPreference protocol) {
397 int protocolIndex = protocol.findIndexOfValue(raw);
398 if (protocolIndex == -1) {
401 String[] values = mRes.getStringArray(R.array.apn_protocol_entries);
403 return values[protocolIndex];
404 } catch (ArrayIndexOutOfBoundsException e) {
410 private String bearerDescription(String raw) {
411 int mBearerIndex = mBearerMulti.findIndexOfValue(raw);
412 if (mBearerIndex == -1) {
415 String[] values = mRes.getStringArray(R.array.bearer_entries);
417 return values[mBearerIndex];
418 } catch (ArrayIndexOutOfBoundsException e) {
424 private String bearerMultiDescription(Set<String> raw) {
425 String[] values = mRes.getStringArray(R.array.bearer_entries);
426 StringBuilder retVal = new StringBuilder();
427 boolean first = true;
428 for (String bearer : raw) {
429 int bearerIndex = mBearerMulti.findIndexOfValue(bearer);
432 retVal.append(values[bearerIndex]);
435 retVal.append(", " + values[bearerIndex]);
437 } catch (ArrayIndexOutOfBoundsException e) {
441 String val = retVal.toString();
442 if (!TextUtils.isEmpty(val)) {
448 private String mvnoDescription(String newValue) {
449 int mvnoIndex = mMvnoType.findIndexOfValue(newValue);
450 String oldValue = mMvnoType.getValue();
452 if (mvnoIndex == -1) {
455 String[] values = mRes.getStringArray(R.array.mvno_type_entries);
456 if (values[mvnoIndex].equals("None")) {
457 mMvnoMatchData.setEnabled(false);
459 mMvnoMatchData.setEnabled(true);
461 if (newValue != null && newValue.equals(oldValue) == false) {
462 if (values[mvnoIndex].equals("SPN")) {
463 mMvnoMatchData.setText(mTelephonyManager.getSimOperatorName());
464 } else if (values[mvnoIndex].equals("IMSI")) {
465 String numeric = mTelephonyManager.getSimOperator(mSubId);
466 mMvnoMatchData.setText(numeric + "x");
467 } else if (values[mvnoIndex].equals("GID")) {
468 mMvnoMatchData.setText(mTelephonyManager.getGroupIdLevel1());
473 return values[mvnoIndex];
474 } catch (ArrayIndexOutOfBoundsException e) {
480 public boolean onPreferenceChange(Preference preference, Object newValue) {
481 String key = preference.getKey();
482 if (KEY_AUTH_TYPE.equals(key)) {
484 int index = Integer.parseInt((String) newValue);
485 mAuthType.setValueIndex(index);
487 String[] values = mRes.getStringArray(R.array.apn_auth_entries);
488 mAuthType.setSummary(values[index]);
489 } catch (NumberFormatException e) {
492 } else if (KEY_PROTOCOL.equals(key)) {
493 String protocol = protocolDescription((String) newValue, mProtocol);
494 if (protocol == null) {
497 mProtocol.setSummary(protocol);
498 mProtocol.setValue((String) newValue);
499 } else if (KEY_ROAMING_PROTOCOL.equals(key)) {
500 String protocol = protocolDescription((String) newValue, mRoamingProtocol);
501 if (protocol == null) {
504 mRoamingProtocol.setSummary(protocol);
505 mRoamingProtocol.setValue((String) newValue);
506 } else if (KEY_BEARER_MULTI.equals(key)) {
507 String bearer = bearerMultiDescription((Set<String>) newValue);
508 if (bearer == null) {
511 mBearerMulti.setValues((Set<String>) newValue);
512 mBearerMulti.setSummary(bearer);
513 } else if (KEY_MVNO_TYPE.equals(key)) {
514 String mvno = mvnoDescription((String) newValue);
518 mMvnoType.setValue((String) newValue);
519 mMvnoType.setSummary(mvno);
521 if (preference.equals(mPassword)) {
522 preference.setSummary(starify(newValue != null ? String.valueOf(newValue) : ""));
523 } else if (preference.equals(mCarrierEnabled) || preference.equals(mBearerMulti)) {
526 preference.setSummary(checkNull(newValue != null ? String.valueOf(newValue) : null));
533 public boolean onCreateOptionsMenu(Menu menu) {
534 super.onCreateOptionsMenu(menu);
535 // If it's a new APN, then cancel will delete the new entry in onPause
537 menu.add(0, MENU_DELETE, 0, R.string.menu_delete)
538 .setIcon(R.drawable.ic_menu_delete);
540 menu.add(0, MENU_SAVE, 0, R.string.menu_save)
541 .setIcon(android.R.drawable.ic_menu_save);
542 menu.add(0, MENU_CANCEL, 0, R.string.menu_cancel)
543 .setIcon(android.R.drawable.ic_menu_close_clear_cancel);
548 public boolean onOptionsItemSelected(MenuItem item) {
549 switch (item.getItemId()) {
554 if (validateAndSave(false)) {
560 getContentResolver().delete(mUri, null, null);
565 return super.onOptionsItemSelected(item);
569 public boolean onKeyDown(int keyCode, KeyEvent event) {
571 case KeyEvent.KEYCODE_BACK: {
572 if (validateAndSave(false)) {
578 return super.onKeyDown(keyCode, event);
582 protected void onSaveInstanceState(Bundle icicle) {
583 super.onSaveInstanceState(icicle);
584 if (validateAndSave(true)) {
585 icicle.putInt(SAVED_POS, mCursor.getInt(ID_INDEX));
590 * Check the key fields' validity and save if valid.
591 * @param force save even if the fields are not valid, if the app is
593 * @return true if the data was saved
595 private boolean validateAndSave(boolean force) {
596 String name = checkNotSet(mName.getText());
597 String apn = checkNotSet(mApn.getText());
598 String mcc = checkNotSet(mMcc.getText());
599 String mnc = checkNotSet(mMnc.getText());
601 if (getErrorMsg() != null && !force) {
602 showDialog(ERROR_DIALOG_ID);
606 if (!mCursor.moveToFirst()) {
608 "Could not go to the first row in the Cursor when saving data.");
612 // If it's a new APN and a name or apn haven't been entered, then erase the entry
613 if (force && mNewApn && name.length() < 1 && apn.length() < 1) {
614 getContentResolver().delete(mUri, null, null);
618 ContentValues values = new ContentValues();
620 // Add a dummy name "Untitled", if the user exits the screen without adding a name but
621 // entered other information worth keeping.
622 values.put(Telephony.Carriers.NAME,
623 name.length() < 1 ? getResources().getString(R.string.untitled_apn) : name);
624 values.put(Telephony.Carriers.APN, apn);
625 values.put(Telephony.Carriers.PROXY, checkNotSet(mProxy.getText()));
626 values.put(Telephony.Carriers.PORT, checkNotSet(mPort.getText()));
627 values.put(Telephony.Carriers.MMSPROXY, checkNotSet(mMmsProxy.getText()));
628 values.put(Telephony.Carriers.MMSPORT, checkNotSet(mMmsPort.getText()));
629 values.put(Telephony.Carriers.USER, checkNotSet(mUser.getText()));
630 values.put(Telephony.Carriers.SERVER, checkNotSet(mServer.getText()));
631 values.put(Telephony.Carriers.PASSWORD, checkNotSet(mPassword.getText()));
632 values.put(Telephony.Carriers.MMSC, checkNotSet(mMmsc.getText()));
634 String authVal = mAuthType.getValue();
635 if (authVal != null) {
636 values.put(Telephony.Carriers.AUTH_TYPE, Integer.parseInt(authVal));
639 values.put(Telephony.Carriers.PROTOCOL, checkNotSet(mProtocol.getValue()));
640 values.put(Telephony.Carriers.ROAMING_PROTOCOL, checkNotSet(mRoamingProtocol.getValue()));
642 values.put(Telephony.Carriers.TYPE, checkNotSet(mApnType.getText()));
644 values.put(Telephony.Carriers.MCC, mcc);
645 values.put(Telephony.Carriers.MNC, mnc);
647 values.put(Telephony.Carriers.NUMERIC, mcc + mnc);
649 if (mCurMnc != null && mCurMcc != null) {
650 if (mCurMnc.equals(mnc) && mCurMcc.equals(mcc)) {
651 values.put(Telephony.Carriers.CURRENT, 1);
655 Set<String> bearerSet = mBearerMulti.getValues();
656 int bearerBitmask = 0;
657 for (String bearer : bearerSet) {
658 if (Integer.parseInt(bearer) == 0) {
662 bearerBitmask |= ServiceState.getBitmaskForTech(Integer.parseInt(bearer));
665 values.put(Telephony.Carriers.BEARER_BITMASK, bearerBitmask);
668 if (bearerBitmask == 0 || mBearerInitialVal == 0) {
670 } else if (ServiceState.bitmaskHasTech(bearerBitmask, mBearerInitialVal)) {
671 bearerVal = mBearerInitialVal;
673 // bearer field was being used but bitmask has changed now and does not include the
674 // initial bearer value -- setting bearer to 0 but maybe better behavior is to choose a
675 // random tech from the new bitmask??
678 values.put(Telephony.Carriers.BEARER, bearerVal);
680 values.put(Telephony.Carriers.MVNO_TYPE, checkNotSet(mMvnoType.getValue()));
681 values.put(Telephony.Carriers.MVNO_MATCH_DATA, checkNotSet(mMvnoMatchData.getText()));
683 values.put(Telephony.Carriers.CARRIER_ENABLED, mCarrierEnabled.isChecked() ? 1 : 0);
684 getContentResolver().update(mUri, values, null, null);
689 private String getErrorMsg() {
690 String errorMsg = null;
692 String name = checkNotSet(mName.getText());
693 String apn = checkNotSet(mApn.getText());
694 String mcc = checkNotSet(mMcc.getText());
695 String mnc = checkNotSet(mMnc.getText());
697 if (name.length() < 1) {
698 errorMsg = mRes.getString(R.string.error_name_empty);
699 } else if (apn.length() < 1) {
700 errorMsg = mRes.getString(R.string.error_apn_empty);
701 } else if (mcc.length() != 3) {
702 errorMsg = mRes.getString(R.string.error_mcc_not3);
703 } else if ((mnc.length() & 0xFFFE) != 2) {
704 errorMsg = mRes.getString(R.string.error_mnc_not23);
711 protected Dialog onCreateDialog(int id) {
713 if (id == ERROR_DIALOG_ID) {
714 String msg = getErrorMsg();
716 return new AlertDialog.Builder(this)
717 .setTitle(R.string.error_title)
718 .setPositiveButton(android.R.string.ok, null)
723 return super.onCreateDialog(id);
727 protected void onPrepareDialog(int id, Dialog dialog) {
728 super.onPrepareDialog(id, dialog);
730 if (id == ERROR_DIALOG_ID) {
731 String msg = getErrorMsg();
734 ((AlertDialog)dialog).setMessage(msg);
739 private void deleteApn() {
740 getContentResolver().delete(mUri, null, null);
744 private String starify(String value) {
745 if (value == null || value.length() == 0) {
748 char[] password = new char[value.length()];
749 for (int i = 0; i < password.length; i++) {
752 return new String(password);
756 private String checkNull(String value) {
757 if (value == null || value.length() == 0) {
764 private String checkNotSet(String value) {
765 if (value == null || value.equals(sNotSet)) {