From 100c4beeaa4d13788f1bbd68a8d7e38af8ff000a Mon Sep 17 00:00:00 2001 From: snickersun Date: Tue, 16 Mar 2021 22:29:10 +0800 Subject: [PATCH] =?utf8?q?APN=20=E6=9F=A5=E8=AF=A2=E5=B7=B2=E7=BB=8F?= =?utf8?q?=E6=AD=A3=E5=B8=B8=E5=B7=A5=E4=BD=9C=EF=BC=8Creset=E5=92=8Cadd?= =?utf8?q?=20=E8=BF=98=E9=9C=80=E7=BB=A7=E7=BB=AD=E6=B5=8B=E8=AF=95?= =?utf8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 2 +- .../com/enqualcomm/support/ICSmsManager.java | 14 +- .../enqualcomm/support/bean/ApnSetting.java | 11 + .../com/enqualcomm/support/utils/APNUtil.java | 277 ++----- .../enqualcomm/support/utils/ApnEditor.java | 784 ++++++++---------- build.gradle | 5 +- 6 files changed, 419 insertions(+), 674 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 8433f163..06641db7 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -86,9 +86,9 @@ android { // } } dependencies { + compileOnly files ('libs/telephony-common-full-debug.jar') compileOnly files ('libs/frameworks-full-debug.jar') compileOnly files ('libs/frameworks-2-full-debug.jar') - compileOnly files ('libs/telephony-common-full-debug.jar') implementation 'com.android.support.constraint:constraint-layout:1.1.3' //compile fileTree(include: ['*.jar', '*.aar'], dir: 'libs') diff --git a/app/src/main/java/com/enqualcomm/support/ICSmsManager.java b/app/src/main/java/com/enqualcomm/support/ICSmsManager.java index 664ec455..4ed46f41 100644 --- a/app/src/main/java/com/enqualcomm/support/ICSmsManager.java +++ b/app/src/main/java/com/enqualcomm/support/ICSmsManager.java @@ -317,7 +317,7 @@ public class ICSmsManager extends BroadcastReceiver { String apn = apnvalues[3]; String user = ""; String password = ""; - if (APNUtil.addVPN(mcc, mnc, apnName, apn, user, password, mContext) == true) { + if (APNUtil.addVPN(apnName, apn,mcc, mnc, user, password, mContext) == true) { sendSMS(phonenumber, "apn add success!"); } else { sendSMS(phonenumber, "apn add failed!"); @@ -329,7 +329,7 @@ public class ICSmsManager extends BroadcastReceiver { String apn = apnvalues[3]; String user = apnvalues[4]; String password = apnvalues[5]; - if (APNUtil.addVPN(mcc, mnc, apnName, apn, user, password, mContext) == true) { + if (APNUtil.addVPN( apnName, apn,mcc, mnc, user, password, mContext) == true) { sendSMS(phonenumber, "apn add success!"); } else { sendSMS(phonenumber, "apn add failed!"); @@ -339,11 +339,9 @@ public class ICSmsManager extends BroadcastReceiver { String apnstr = APNUtil.getCurrentAPN(mContext); sendSMS(phonenumber, apnstr); - }else if (apnvalues[0].equals("check")) { - String mcc=runtime.getLocationInstance().getMCC(); - String mnc=runtime.getLocationInstance().getMNC(); - String apnstr = APNUtil.checkAPN(mcc,mnc,mContext); - sendSMS(phonenumber, apnstr); + } else if (apnvalues[0].equals("reset")) { + boolean apnret=APNUtil.resetAPN(mContext); + sendSMS(phonenumber, "Reset APN to default "+apnret); } else { sendSMS(phonenumber, "apn cmd format error!"); } @@ -1295,4 +1293,4 @@ public class ICSmsManager extends BroadcastReceiver { } } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/enqualcomm/support/bean/ApnSetting.java b/app/src/main/java/com/enqualcomm/support/bean/ApnSetting.java index 1e594432..71936ba4 100644 --- a/app/src/main/java/com/enqualcomm/support/bean/ApnSetting.java +++ b/app/src/main/java/com/enqualcomm/support/bean/ApnSetting.java @@ -150,6 +150,17 @@ public class ApnSetting { + mMvnoTypeStr + ", mMvnoMatchDataStr=" + mMvnoMatchDataStr + "]"; } + + public String toShortString() { + + return "APNSettings name = " +mNameStr+ + " ,mcc="+mMccStr+ + " ,mnc="+mMncStr+ + " ,apn="+mApnStr+ + " ,user="+mUserStr+ + " ,password="+mPasswordStr+ + " ,type="+mApnTypeStr; + } @Override public boolean equals(Object obj) { if (obj == null) { diff --git a/app/src/main/java/com/enqualcomm/support/utils/APNUtil.java b/app/src/main/java/com/enqualcomm/support/utils/APNUtil.java index bbca3a6d..3b91b873 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/APNUtil.java +++ b/app/src/main/java/com/enqualcomm/support/utils/APNUtil.java @@ -1,206 +1,71 @@ -package com.enqualcomm.support.utils; - -import android.content.ContentResolver; -import android.content.ContentValues; -import android.content.Context; -import android.database.Cursor; -import android.net.Uri; -import android.telephony.TelephonyManager; -import android.widget.Toast; - -public class APNUtil { - - /** - * 当前连接APN - * */ - private static Uri APN_URI_NOW =Uri.parse("content://telephony/carriers/current"); - /** - * 所有APN - * */ - private static Uri APN_URI = Uri.parse("content://telephony/carriers"); //apn列表uri - - private static Uri CURRENT_APN_URI = Uri.parse("content://telephony/carriers/preferapn"); //主apn的uri - - final String MY_APN = "my apn"; - - public static String getCurrentAPN(Context context){ - ContentResolver resolver = context.getContentResolver(); - Cursor c = resolver.query(APN_URI_NOW, null, null, null, null); //从apn列表中查找apn名称为myapn的apn信息 - String APNSTR=""; - String Columns=""; - for (String column :c.getColumnNames()) - { - Columns+=column+","; - } - -// APN不存在 columns=_id,name,numeric,mcc,mnc,apn,user,server,password,proxy,port,mmsproxy,mmsport,mmsc,authtype,type,current,protocol,preload,roaming_protocol,editable,traffic_class,carrier_enabled,bearer,mvno_type,mvno_match_data, - if (c != null && c.moveToNext()) { - int id = c.getShort(c.getColumnIndex("_id")); //获取该apn的id信息 - String mcc=c.getString(c.getColumnIndex("mcc")); - String mnc=c.getString(c.getColumnIndex("mnc")); - String name=c.getString(c.getColumnIndex("name")); - String apnname=c.getString(c.getColumnIndex("apn")); - String user=c.getString(c.getColumnIndex("user")); - String pwd=c.getString(c.getColumnIndex("password")); - String _type=c.getString(c.getColumnIndex("type")); - APNSTR="[Current APN name = "+apnname+ - ",_id="+id+ - ",mcc="+mcc+ - ",mnc="+mnc+ - ",name="+name+ - ",user="+user+ - ",password="+pwd+ - ",type="+_type+ - "]"; - ICLogger.i(APNSTR); - } else { - ICLogger.i("APN不存在"); - return "APN 不存在"; - } - return APNSTR; - } - public static boolean addVPN(String apnName, String apn, String mcc,String mnc , String user,String passwd,Context context) { - - if (checkAPN(mcc,mnc,apn,context)==true){ - ICLogger.i("VPN 已经存在,不需要添加!"); - return false; - } - //添加新的APN到系统 - int id= AddNewApn(apnName,apn,mcc,mnc,user,passwd,context); - - //添加后设置为当前指定APN - SetAPN(id,context); - - - boolean isAddSuccess = checkAPN(mcc,mnc,apn,context); - if (isAddSuccess) { - ICLogger.i("APN 添加成功!"); - return true; -// Toast.makeText(NewAPNActivity.this, "新增APN成功", Toast.LENGTH_SHORT).show(); - } else { - ICLogger.i("APN 添加失败!"); - return false; -// Toast.makeText(NewAPNActivity.this, "新增APN失败", Toast.LENGTH_SHORT).show(); - } - } - // 设置接入点 - public static void SetAPN(int id,Context context) { - ContentResolver resolver = context.getContentResolver(); - ContentValues values = new ContentValues(); - values.put("apn_id", id); - resolver.update(CURRENT_APN_URI, values, null, null); - } - public static boolean checkAPN(String mcc,String mnc,String apn,Context context) { - // 检查系统已经写入的APN - Cursor cr = context.getContentResolver().query(APN_URI, null, null, null, null); - while (cr != null && cr.moveToNext()) { - if(cr.getString(cr.getColumnIndex("apn")).equals(apn) - && cr.getString(cr.getColumnIndex("mcc")).equals(mcc) - && cr.getString(cr.getColumnIndex("mnc")).equals(mnc)){ - return true; - } - } - return false; - } - - public static String checkAPN(String mcc,String mnc,Context context) { - // 检查系统已经写入的APN - Cursor cr = context.getContentResolver().query(APN_URI, null, null, null, null); - -// String Columns=""; -// for (String column :cr.getColumnNames()) -// { -// Columns+=column+","; -// } - -// APN name = mms,mcc=655,mnc=07,column names :_id,name,numeric,mcc,mnc,apn,user,server,password,proxy,port,mmsproxy,mmsport,mmsc,authtype,type,current,protocol,preload,roaming_protocol,editable,traffic_class,carrier_enabled,bearer,mvno_type,mvno_match_data, - - String found=""; - - while (cr != null && cr.moveToNext()) { - -// ",column names :"+Columns); - if(cr.getString(cr.getColumnIndex("mcc")).equals(mcc) - && cr.getString(cr.getColumnIndex("mnc")).equals(mnc)){ - - int id = cr.getShort(cr.getColumnIndex("_id")); //获取该apn的id信息 - String name=cr.getString(cr.getColumnIndex("name")); - String apnname=cr.getString(cr.getColumnIndex("apn")); - String user=cr.getString(cr.getColumnIndex("user")); - String pwd=cr.getString(cr.getColumnIndex("password")); - String _type=cr.getString(cr.getColumnIndex("type")); - String msg="[APN name = "+apnname+ - ",_id="+id+ - ",mcc="+mcc+ - ",mnc="+mnc+ - ",name="+name+ - ",user="+user+ - ",password="+pwd+ - ",type="+_type+ - "],"; - found +=msg; - } - } - found+=getCurrentAPN(context); - ICLogger.i(found); - - return found; - } - - - - - public static int AddNewApn(String apnName,String apn, String mcc,String mnc , String user,String passwd, Context context) { - ICLogger.i("添加一个新的apn ==> "+apnName+", mcc="+mcc+", mnc="+mnc+", user="+user+", password="+passwd); - int apnId = -1; - ContentResolver resolver = context.getContentResolver(); - ContentValues values = new ContentValues(); - values.put("name", apnName); //apn中文描述 - values.put("apn", apn); //apn名称 - values.put("type", "default"); - values.put("numeric", mcc+mnc); - values.put("mcc", mcc); - values.put("mnc", mnc); - values.put("proxy", ""); - values.put("port", ""); - values.put("mmsproxy", ""); - values.put("mmsport", ""); - values.put("user", user); - values.put("server", ""); - values.put("password", passwd); - values.put("mmsc", ""); - Cursor c = null; -// 获取新添加的apn的ID - try { - Uri newRow = resolver.insert(APN_URI, values); - if (newRow != null) { - c = resolver.query(newRow, null, null, null, null); - int idindex = c.getColumnIndex("_id"); - c.moveToFirst(); - apnId = idindex; - } - } catch (Exception e) { - e.printStackTrace(); - } - if (c != null) - c.close(); - return apnId; - } - - private boolean hasMyApn(Context context) { - ContentResolver resolver = context.getContentResolver(); - Cursor cursor = resolver.query(APN_URI, new String[]{"_id", "name"}, null, null, null); - for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()){ - int nameIndex = cursor.getColumnIndex("name"); - int idIndex = cursor.getColumnIndex("_id"); - String name = cursor.getString(nameIndex); - ICLogger.i( name); - if (MY_APN.equals(name)) { - //myId = cursor.getShort(idIndex); - return true; - } - } - return false; - } - -} +package com.enqualcomm.support.utils; + +import android.content.ContentResolver; +import android.content.ContentValues; +import android.content.Context; +import android.database.Cursor; +import android.net.Uri; +import android.telephony.TelephonyManager; +import android.widget.Toast; + +import com.enqualcomm.support.bean.ApnSetting; + +public class APNUtil { + + public static String getCurrentAPN(Context context){ + String APNSTR=""; + APNSTR=ApnEditor.getApnEditorInstance(context).getCurrentAPN(); + ICLogger.i("当前APN "+APNSTR); + return APNSTR; + } + public static boolean addVPN(String apnName, String apn, String mcc,String mnc , String user,String passwd,Context context) { + + if (checkAPN(mcc,mnc,apn,context)==true){ + ICLogger.i("VPN 已经存在,不需要添加!"); + return false; + } + //添加新的APN到系统 + boolean isAddSuccess=AddNewApn(apnName,apn,mcc,mnc,user,passwd,context); + + if (isAddSuccess) { + ICLogger.i("APN 添加成功!"); + return true; +// Toast.makeText(NewAPNActivity.this, "新增APN成功", Toast.LENGTH_SHORT).show(); + } else { + ICLogger.i("APN 添加失败!"); + return false; +// Toast.makeText(NewAPNActivity.this, "新增APN失败", Toast.LENGTH_SHORT).show(); + } + } + + public static boolean checkAPN(String mcc,String mnc,String apn,Context context) { + // 检查系统已经写入的APN + String found=""; + found+=ApnEditor.getApnEditorInstance(context).queryApn(apn,mcc+mnc); + ICLogger.i(found); + + return !found.isEmpty(); + } + + public static String checkAPN(String mcc,String mnc,Context context) { + // 检查系统已经写入的APN + String found=""; + found+=ApnEditor.getApnEditorInstance(context).queryApn(mcc+mnc); + ICLogger.i(found); + return found; + } + + + + + public static boolean AddNewApn(String apnName,String apn, String mcc,String mnc , String user,String passwd, Context context) { + ICLogger.i("添加一个新的apn ==> "+apnName+", mcc="+mcc+", mnc="+mnc+", user="+user+", password="+passwd); + return ApnEditor.getApnEditorInstance(context).addVPN(apnName,apn,mcc,mnc,user,passwd); + } + + + public static boolean resetAPN(Context context){ + return ApnEditor.getApnEditorInstance(context).resetAPNtoDefault(); + } + +} diff --git a/app/src/main/java/com/enqualcomm/support/utils/ApnEditor.java b/app/src/main/java/com/enqualcomm/support/utils/ApnEditor.java index f91a6109..40610e91 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/ApnEditor.java +++ b/app/src/main/java/com/enqualcomm/support/utils/ApnEditor.java @@ -56,10 +56,10 @@ import com.enqualcomm.support.bean.ApnSetting; import static android.content.Context.TELEPHONY_SERVICE; -public class ApnEditor { +public class ApnEditor { private final static String TAG = ApnEditor.class.getSimpleName(); - private Context mContext=null; + private Context mContext = null; private final static String SAVED_POS = "pos"; private final static String KEY_AUTH_TYPE = "auth_type"; private final static String KEY_PROTOCOL = "apn_protocol"; @@ -70,78 +70,81 @@ public class ApnEditor { private final static String KEY_APN_TYPE = "apn_type"; public final static String APN_EDITABLE = "editable"; - private static final int MENU_DELETE = Menu.FIRST; - private static final int MENU_SAVE = Menu.FIRST + 1; - private static final int MENU_CANCEL = Menu.FIRST + 2; - private static final int ERROR_DIALOG_ID = 0; private static final String APN_TYPE = "APN_TYPE"; private static final String IS_RELOADED = "IS_PRELOADED"; - /* SPRD: add for bug717733 @{ */ + private static final String CUCC = "cucc"; private final static String XCAP = ",xcap"; private final static String CURRENT_CARRIER = "ro.operator"; public final static String SPECIAL_CTCC_NUMERIC = "20404"; public final static String CTCC_ICCID = "898603,898611"; - /* @} */ + private static String sNotSet; - private EditTextPreference mName; - private EditTextPreference mApn; - private EditTextPreference mProxy; - private EditTextPreference mPort; - private EditTextPreference mUser; - private EditTextPreference mServer; - private EditTextPreference mPassword; - private EditTextPreference mMmsc; - private EditTextPreference mMcc; - private EditTextPreference mMnc; - private EditTextPreference mMmsProxy; - private EditTextPreference mMmsPort; - private ListPreference mAuthType; - private Preference mApnType; - private ListPreference mProtocol; - private ListPreference mRoamingProtocol; - private CheckBoxPreference mCarrierEnabled; - private ListPreference mBearer; - private ListPreference mMvnoType; - private EditTextPreference mMvnoMatchData; + private String mName; + private String mApn; + private String mProxy; + private String mPort; + private String mUser; + private String mServer; + private String mPassword; + private String mMmsc; + private String mMcc; + private String mMnc; + private String mMmsProxy; + private String mMmsPort; + + private String[] mApnTypeArray; + private String[] mFullApnTypeArray; + private String mApnType; + private String mAuthType; + private String[] mAuthTypeArray; + private String mProtocol; + private String[] mProtocolArray; + + private String mRoamingProtocol; + + private String mBearer; + private String[] mBearerArray; + private String mMvnoType; + + + private String mMvnoMatchData; + private String mMvnoTypeStr; + private String mMvnoMatchDataStr; + private String mCurMnc; private String mCurMcc; private int mPhoneId = 0; // SPRD: add by spreadst private Uri mUri; + private Uri mAPNUri; private Cursor mCursor; private boolean mNewApn; - private boolean mFirstTime; +// private boolean mFirstTime=true; private boolean mIsPreloaded = false; // SPRD: for cmcc case, preloaded apns should not be editable or deleted. private Resources mRes; private TelephonyManager mTelephonyManager; private String mRecordApnType; - // SPRD: modify for bug271734 + private String mApnTypeSummary; private boolean mIsdelete = false; //compare apn setting values whether change private ApnSetting mApnSetting = new ApnSetting(); private ApnSetting mNewApnSetting = new ApnSetting(); + // SPRD: FEATURE_APN_CAN_BE_EMTPY private boolean mAllowEmptyApn = SystemProperties.get(CURRENT_CARRIER, "default") .equals("orange"); // SPRD: FEATURE_APN_NOT_EDITABLE - /* SPRD: add for bug675438 @{ */ - private boolean mApnEditable = true; - /* @} */ - /* SPRD: Bug 628333 modify for support virtual operator @{ */ - private String mMvnoTypeStr; - private String mMvnoMatchDataStr; - /* @} */ + public boolean mApnEditable = true; + // SPRD: Bug 645213 don't allow to modify mvno value private boolean mVirtualOperator = false; - /** - * Standard projection for the interesting columns of a normal note. - */ - private static final String[] sProjection = new String[] { + + private static final String[] sProjection = new String[]{ Telephony.Carriers._ID, // 0 Telephony.Carriers.NAME, // 1 Telephony.Carriers.APN, // 2 @@ -193,199 +196,184 @@ public class ApnEditor { private static final int PRELOAD_INDEX = 22; // SPRD: for cmcc case, preloaded apns should not be editable or deleted. private static final int EDITABLE_INDEX = 23; - /* SPRD: add for bug685803 @{ */ -// private FeatureBarHelper mFeatureBarHelper; -// private TextView mLeftSkView; -// private TextView mCenterSkView; -// private TextView mRightSkView; - /* @} */ + private static ApnEditor apnEditor=null; + public static ApnEditor getApnEditorInstance(Context context){ + if (apnEditor==null && context!=null) + { + apnEditor=new ApnEditor(context); + } + return apnEditor; + } public ApnEditor(Context context) { - mContext=context; -// addPreferencesFromResource(R.xml.apn_editor); - - /* SPRD: add for bug685803 @{ */ -// mFeatureBarHelper = new FeatureBarHelper(this); -// mLeftSkView = (TextView) mFeatureBarHelper.getOptionsKeyView(); -// mCenterSkView = (TextView) mFeatureBarHelper.getCenterKeyView(); -// mCenterSkView.setText(R.string.default_feature_bar_center); -// mRightSkView = (TextView) mFeatureBarHelper.getBackKeyView(); - /* @} */ - -// sNotSet = getResources().getString(R.string.apn_not_set); -// mName = (EditTextPreference) findPreference("apn_name"); -// mApn = (EditTextPreference) findPreference("apn_apn"); -// mProxy = (EditTextPreference) findPreference("apn_http_proxy"); -// mPort = (EditTextPreference) findPreference("apn_http_port"); -// mUser = (EditTextPreference) findPreference("apn_user"); -// mServer = (EditTextPreference) findPreference("apn_server"); -// mPassword = (EditTextPreference) findPreference("apn_password"); -// mMmsProxy = (EditTextPreference) findPreference("apn_mms_proxy"); -// mMmsPort = (EditTextPreference) findPreference("apn_mms_port"); -// mMmsc = (EditTextPreference) findPreference("apn_mmsc"); -// mMcc = (EditTextPreference) findPreference("apn_mcc"); -// mMnc = (EditTextPreference) findPreference("apn_mnc"); -// mApnType = (Preference) findPreference(KEY_APN_TYPE); -// -// mAuthType = (ListPreference) findPreference(KEY_AUTH_TYPE); -// -// -// mProtocol = (ListPreference) findPreference(KEY_PROTOCOL); -// -// -// mRoamingProtocol = (ListPreference) findPreference(KEY_ROAMING_PROTOCOL); -// -// mCarrierEnabled = (CheckBoxPreference) findPreference(KEY_CARRIER_ENABLED); -// -// -// mBearer = (ListPreference) findPreference(KEY_BEARER); -// mBearer.setOnPreferenceChangeListener(this); -// -// mMvnoType = (ListPreference) findPreference(KEY_MVNO_TYPE); -// mMvnoType.setOnPreferenceChangeListener(this); -// mMvnoMatchData = (EditTextPreference) findPreference("mvno_match_data"); - + mContext = context; mRes = context.getResources(); -// final Intent intent = getIntent(); -// final String action = intent.getAction(); - - /* SPRD: for multi-sim @{ */ -// if (TelephonyManager.isMultiSim()) { -// // Read the mPhoneId received from Phone settings. -// mPhoneId = intent.getIntExtra(WirelessSettings.SUB_ID, 0); -// this.setTitle(mRes.getString(R.string.apn_edit_ex, mPhoneId + 1)); -// Log.d(TAG, "ApnEditor onCreate received mPhoneId: " + mPhoneId); -// } else { -// this.setTitle(R.string.apn_edit); -// } - /* @} */ - -// mFirstTime = icicle == null; -// /* SPRD: modify for bug271734 @{ */ -// if(icicle != null){ -// mApnTypeSummary = icicle.getString(APN_TYPE,""); -// // SPRD: modify for bug271736 -// mIsPreloaded = icicle.getBoolean(IS_RELOADED,false); -// } -// /* @} */ -// if (action.equals(Intent.ACTION_EDIT)) { -// mUri = intent.getData(); -// } else if (action.equals(Intent.ACTION_INSERT)) { -// if (mFirstTime || icicle.getInt(SAVED_POS) == 0) { -// mUri = context.getContentResolver().insert(intent.getData(), new ContentValues()); -// } else { -// /* SPRD: for multi-sim @{ */ -// // mUri = -// // ContentUris.withAppendedId(Telephony.Carriers.CONTENT_URI, -// // icicle.getInt(SAVED_POS)); -// mUri = ContentUris.withAppendedId( -// Telephony.Carriers.getContentUri(mPhoneId,null), icicle -// .getInt(SAVED_POS)); -// /* @} */ -// } -// mNewApn = true; -// /* SPRD: Bug 628333 modify for support virtual operator @{ */ -// mMvnoTypeStr = intent.getStringExtra(ApnSettings.MVNO_TYPE); -// mMvnoMatchDataStr = intent.getStringExtra(ApnSettings.MVNO_MATCH_DATA); -// /* @} */ -// -// // If we were unable to create a new note, then just finish -// // this activity. A RESULT_CANCELED will be sent back to the -// // original activity if they requested a result. -// if (mUri == null) { -// Log.w(TAG, "Failed to insert new telephony provider into " -// + getIntent().getData()); -//// finish(); -// return; -// } -// -// // The new entry was created, so assume all will end well and -// // set the result to be returned. -//// setResult(RESULT_OK, (new Intent()).setAction(mUri.toString())); -// -// } else { -//// finish(); -// return; -// } + mApnTypeArray = mRes.getStringArray(R.array.apn_type_array); + mFullApnTypeArray = mRes.getStringArray(R.array.full_apn_type_array); + mAuthTypeArray = mRes.getStringArray(R.array.apn_auth_values); - /* SPRD: for bug 297172: Use common query management Cursor @{ */ - // mCursor = managedQuery(mUri, sProjection, null, null); - mCursor = mContext.getContentResolver().query(mUri, sProjection, null, null,null); - /* @} */ - mCursor.moveToFirst(); + mProtocolArray = mRes.getStringArray(R.array.apn_protocol_values); - mTelephonyManager = (TelephonyManager) mContext.getSystemService(TELEPHONY_SERVICE); + mBearerArray = mRes.getStringArray(R.array.bearer_entries); - fillUi(); - } + mAPNUri = Telephony.Carriers.getContentUri(mPhoneId, null); + mUri = mAPNUri; - public void onResume() { + mTelephonyManager = (TelephonyManager) mContext.getSystemService(TELEPHONY_SERVICE); + } - /* SPRD: for bug 297172: After hanging up the phone, can not save the new apn normally @{ */ - if(mIsdelete) { - if(mCursor != null) { - mCursor.close(); - mCursor = null; + public String queryApn(String apn,String mccmnc){ + String where; + where = "numeric=\"" + mccmnc + "\""; + where += " and name!='CMCC DM'"; + where += " and apn='"+apn+"'"; + + Log.d(TAG,"where = " + where + ",mccmnc =" + mccmnc); + mCursor = mContext.getContentResolver().query(mAPNUri, sProjection, where, null, Telephony.Carriers.DEFAULT_SORT_ORDER); + String apnsetings=""; + if (mCursor.moveToFirst()) { + + fill_apnSettings(mCursor,mApnSetting); + apnsetings+= mApnSetting.toShortString(); + while (mCursor.moveToNext()){ + apnsetings+=";"; + fill_apnSettings(mCursor,mApnSetting); + apnsetings+= mApnSetting.toShortString(); + } + } + if (mCursor != null) { + mCursor.close(); + mCursor = null; + } + return apnsetings; + } + public String queryApn(String mccmnc){ + String where; + where = "numeric=\"" + mccmnc + "\""; + where += " and name!='CMCC DM'"; + + Log.d(TAG,"where = " + where + ",mccmnc =" + mccmnc); + mCursor = mContext.getContentResolver().query(mAPNUri, sProjection, where, null, Telephony.Carriers.DEFAULT_SORT_ORDER); + String apnsetings=""; + if (mCursor.moveToFirst()) { + + fill_apnSettings(mCursor,mApnSetting); + apnsetings+= mApnSetting.toShortString(); + while (mCursor.moveToNext()){ + apnsetings+=";"; + fill_apnSettings(mCursor,mApnSetting); + apnsetings+= mApnSetting.toShortString(); } - // final Intent intent = getIntent(); - Log.d(TAG, "Get mUri again!"); -// mUri = mContext.getContentResolver().insert(intent.getData(), new ContentValues()); - mCursor = mContext.getContentResolver().query(mUri, sProjection, null, null,null); - mCursor.moveToFirst(); - mIsdelete = false; } - /* @} */ + if (mCursor != null) { + mCursor.close(); + mCursor = null; + } + return apnsetings; + } + public String getCurrentAPN(){ - /* SPRD: for cucc case @{ */ -// PreferenceScreen prefSet = getPreferenceScreen(); -// if (mIsPreloaded && "cucc".equals(SystemProperties.get("ro.operator", ""))) { -// prefSet.setEnabled(false); -// } else { -// prefSet.setEnabled(true); -// } - /* @} */ + String where; + String mccmnc; + if (TelephonyManager.isMultiSim()) { + mccmnc = android.os.SystemProperties.get(TelephonyManager.getProperty( + TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC, mPhoneId), ""); + // APNs are listed based on the MCC+MNC. + // Get the value from appropriate Telephony Property based on the + // subscription. + where = "numeric=\"" + mccmnc + "\""; - /* SPRD: FEATURE_APN_NOT_EDITABLE @{ */ -// if (!mNewApn && !mApnEditable) { -// prefSet.setEnabled(false); -// } - /* @} */ + } else { + mccmnc = android.os.SystemProperties.get( + TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC, ""); + where = "numeric=\"" + mccmnc + "\""; - /* SPRD: Bug 645213 don't allow to modify mvno value @{ */ -// if (!mNewApn && mVirtualOperator) { -// mMvnoType.setEnabled(false); -// mMvnoMatchData.setEnabled(false); -// } - /* @} */ + } + where += " and name!='CMCC DM'"; + + Log.d(TAG,"where = " + where + ",mccmnc =" + mccmnc); +// mCursor = mContext.getContentResolver().query(mAPNUri, new String[] { +// "_id", "name", "apn", "type", "mvno_type", "mvno_match_data" }, where, null, +// Telephony.Carriers.DEFAULT_SORT_ORDER); + mCursor = mContext.getContentResolver().query(mAPNUri, sProjection, where, null, Telephony.Carriers.DEFAULT_SORT_ORDER); +// mCursor = mContext.getContentResolver().query(mAPNUri, sProjection, null, null, null); + String apnsetings=""; + if (mCursor.moveToFirst()) { + + fill_apnSettings(mCursor,mApnSetting); + apnsetings+= mApnSetting.toShortString(); + while (mCursor.moveToNext()){ + apnsetings+=";"; + fill_apnSettings(mCursor,mApnSetting); + apnsetings+= mApnSetting.toShortString(); + } + } + if (mCursor != null) { + mCursor.close(); + mCursor = null; + } + return apnsetings; + } -// getPreferenceScreen().getSharedPreferences() -// .registerOnSharedPreferenceChangeListener(this); + public boolean resetAPNtoDefault(){ + // resolver.delete(DEFAULTAPN_URI, null, null); + int rows = mContext.getContentResolver().delete(Telephony.Carriers.getContentUri(mPhoneId, + Telephony.Carriers.PATH_RESTORE),null,null); + return rows>=0; } + public boolean addVPN(String apnName, String apn, String mcc, String mnc, String user, String passwd) { + +// if (mIsdelete) { + + ContentValues contentValues=new ContentValues(); + contentValues.put(Telephony.Carriers.NAME,apnName); + contentValues.put(Telephony.Carriers.MCC,mcc); + contentValues.put(Telephony.Carriers.MNC,mnc); + contentValues.put(Telephony.Carriers.APN,apn); + mName = apnName; + mApn = apn; + mMcc = mcc; + mMnc = mnc; + ICLogger.d( "Get mUri again! mAPNUri="+mAPNUri.toString()); + mUri = mContext.getContentResolver().insert(mAPNUri, contentValues); + + if (mUri!=null) + { + ICLogger.d( "Get mUri again! mUri="+mUri.toString()); + mCursor = mContext.getContentResolver().query(mUri, sProjection, null, null, null); + mCursor.moveToFirst(); + + fill_apnSettings(mCursor,mApnSetting); + mApnSetting.setmNameStr(checkNull(apnName)); + mApnSetting.setmApnStr(checkNull(apn)); + mApnSetting.setmMccStr(checkNull(mcc)); + mApnSetting.setmMncStr(checkNull(mnc)); + mApnSetting.setmUserStr(checkNull(user)); + mApnSetting.setmPasswordStr(checkNull(passwd)); + mIsdelete = false; + + }else{ + ICLogger.d( "Get mUri again! mUri=null"); + } + if (mCursor != null) { + mCursor.close(); + mCursor = null; + } +// } - public void onPause() { -// getPreferenceScreen().getSharedPreferences() -// .unregisterOnSharedPreferenceChangeListener(this); -// super.onPause(); + return validateAndSave(false); + } - /* SPRD: for bug 297172: Use common query management Cursor @{ */ - protected void onDestroy() { - // TODO Auto-generated method stub -// super.onDestroy(); - if(mCursor != null) { - mCursor.close(); - mCursor = null; - } - } - /* @} */ + private boolean getApnEditable(Cursor cursor) { String version = SystemProperties.get(CURRENT_CARRIER, "default"); @@ -398,35 +386,36 @@ public class ApnEditor { } } - private void fillUi() { + private void fill_apnSettings(Cursor cursor,ApnSetting apnSetting) { + // SPRD: for bug 348288: while Cursor is null, return - if (mFirstTime && mCursor.moveToFirst()) { - mFirstTime = false; - // Fill in all the values from the db in both text editor and summary - mName.setText(mCursor.getString(NAME_INDEX)); - mApn.setText(mCursor.getString(APN_INDEX)); - mProxy.setText(mCursor.getString(PROXY_INDEX)); - mPort.setText(mCursor.getString(PORT_INDEX)); - mUser.setText(mCursor.getString(USER_INDEX)); - mServer.setText(mCursor.getString(SERVER_INDEX)); - mPassword.setText(mCursor.getString(PASSWORD_INDEX)); - mMmsProxy.setText(mCursor.getString(MMSPROXY_INDEX)); - mMmsPort.setText(mCursor.getString(MMSPORT_INDEX)); - mMmsc.setText(mCursor.getString(MMSC_INDEX)); - mMcc.setText(mCursor.getString(MCC_INDEX)); - mMnc.setText(mCursor.getString(MNC_INDEX)); - // SPRD: modify for bug271734 - /* SPRD: add for bug717733 @{ */ - String strApnType = mCursor.getString(TYPE_INDEX); - mApnEditable = getApnEditable(mCursor); - Log.i(TAG, "fillUi : mApnEditable = " + mApnEditable + +// mFirstTime = false; + + mName = (cursor.getString(NAME_INDEX)); + mApn = (cursor.getString(APN_INDEX)); + mProxy = (cursor.getString(PROXY_INDEX)); + mPort = (cursor.getString(PORT_INDEX)); + mUser = (cursor.getString(USER_INDEX)); + mServer = (cursor.getString(SERVER_INDEX)); + mPassword = (cursor.getString(PASSWORD_INDEX)); + mMmsProxy = (cursor.getString(MMSPROXY_INDEX)); + mMmsPort = (cursor.getString(MMSPORT_INDEX)); + mMmsc = (cursor.getString(MMSC_INDEX)); + mMcc = (cursor.getString(MCC_INDEX)); + mMnc = (cursor.getString(MNC_INDEX)); + + String strApnType = cursor.getString(TYPE_INDEX); + mApnEditable = getApnEditable(cursor); + ICLogger.i( "fillUi : mApnEditable = " + mApnEditable + ", strApnType = " + strApnType); + mApnType = strApnType; mApnTypeSummary = checkNull(strApnType); /* @} */ // SPRD: for cmcc case, preloaded apns should not be editable or deleted. - mIsPreloaded = ("1".equals(mCursor.getString(PRELOAD_INDEX))); + mIsPreloaded = ("1".equals(cursor.getString(PRELOAD_INDEX))); if (mNewApn) { /* SPRD: for multi-sim @{ */ @@ -438,7 +427,7 @@ public class ApnEditor { // Get the value from appropriate Telephony Property based // on the mPhoneId. numeric = SystemProperties - .get(TelephonyManager.getProperty(TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC, mPhoneId)); + .get(TelephonyManager.getProperty(TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC, mPhoneId)); } else { numeric = SystemProperties.get(TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC); @@ -451,240 +440,140 @@ public class ApnEditor { // Network code String mnc = numeric.substring(3); // Auto populate MNC and MCC for new entries, based on what SIM reports - mMcc.setText(mcc); - mMnc.setText(mnc); + mMcc = (mcc); + mMnc = (mnc); mCurMnc = mnc; mCurMcc = mcc; } } - int authVal = mCursor.getInt(AUTH_TYPE_INDEX); + int authVal = cursor.getInt(AUTH_TYPE_INDEX); if (authVal != -1) { - mAuthType.setValueIndex(authVal); + mAuthType = String.valueOf(authVal); } else { - mAuthType.setValue(null); + mAuthType = (null); } - mProtocol.setValue(mCursor.getString(PROTOCOL_INDEX)); - mRoamingProtocol.setValue(mCursor.getString(ROAMING_PROTOCOL_INDEX)); - mCarrierEnabled.setChecked(mCursor.getInt(CARRIER_ENABLED_INDEX)==1); - mBearer.setValue(mCursor.getString(BEARER_INDEX)); + mProtocol = (cursor.getString(PROTOCOL_INDEX)); + mRoamingProtocol = (cursor.getString(ROAMING_PROTOCOL_INDEX)); + // mCarrierEnabled.setChecked(mCursor.getInt(CARRIER_ENABLED_INDEX)==1); + mBearer = (cursor.getString(BEARER_INDEX)); /* SPRD: Bug 645213 don't allow to modify mvno value @{ */ - String mvnoType = checkNull(mCursor.getString(MVNO_TYPE_INDEX)); - String mvnoMatchData = checkNull(mCursor.getString(MVNO_TYPE_INDEX)); - Log.d(TAG, "fillUi mvnoType = " + mvnoType + ",mvnoMatchData = " + mvnoMatchData); - if (mvnoType.equals(sNotSet) && mvnoMatchData.equals(sNotSet)) { + String mvnoType = checkNull(cursor.getString(MVNO_TYPE_INDEX)); + String mvnoMatchData = checkNull(cursor.getString(MVNO_TYPE_INDEX)); + ICLogger.d( "fillUi mvnoType = " + mvnoType + ",mvnoMatchData = " + mvnoMatchData); + // if (mvnoType.equals(sNotSet) && mvnoMatchData.equals(sNotSet)) { mVirtualOperator = true; - } - /* @} */ - mMvnoType.setValue(mCursor.getString(MVNO_TYPE_INDEX)); - mMvnoMatchData.setEnabled(false); - mMvnoMatchData.setText(mCursor.getString(MVNO_MATCH_DATA_INDEX)); - /* SPRD: Bug 628333 modify for support virtual operator @{ */ - if (mNewApn && mMvnoTypeStr != null && mMvnoMatchDataStr != null) { - mMvnoType.setValue(mMvnoTypeStr); - mMvnoMatchData.setText(mMvnoMatchDataStr); - } - /* @} */ - } - // SPRD: modify for bug271734 - /* SPRD: add for bug713689 @{ */ - if (mNewApn && TextUtils.isEmpty(mCursor.getString(TYPE_INDEX))) { - String[] array = mContext.getResources().getStringArray(R.array.apn_type_array); - mApnTypeSummary = array[0]; - } - /* @} */ - mApnType.setSummary(mApnTypeSummary); - mName.setSummary(checkNull(mName.getText())); - mApn.setSummary(checkNull(mApn.getText())); - mProxy.setSummary(checkNull(mProxy.getText())); - mPort.setSummary(checkNull(mPort.getText())); - mUser.setSummary(checkNull(mUser.getText())); - mServer.setSummary(checkNull(mServer.getText())); - mPassword.setSummary(starify(mPassword.getText())); - mMmsProxy.setSummary(checkNull(mMmsProxy.getText())); - mMmsPort.setSummary(checkNull(mMmsPort.getText())); - mMmsc.setSummary(checkNull(mMmsc.getText())); - mMcc.setSummary(checkNull(mMcc.getText())); - mMnc.setSummary(checkNull(mMnc.getText())); - - String authVal = mAuthType.getValue(); - if (authVal != null) { - int authValIndex = Integer.parseInt(authVal); - mAuthType.setValueIndex(authValIndex); - - String[]values = mRes.getStringArray(R.array.apn_auth_entries); - mAuthType.setSummary(values[authValIndex]); - } else { - mAuthType.setSummary(sNotSet); - } + //} - mProtocol.setSummary( - checkNull(protocolDescription(mProtocol.getValue(), mProtocol))); - mRoamingProtocol.setSummary( - checkNull(protocolDescription(mRoamingProtocol.getValue(), mRoamingProtocol))); - mBearer.setSummary( - checkNull(bearerDescription(mBearer.getValue()))); -// mMvnoType.setSummary( -// checkNull(mvnoDescription(mMvnoType.getValue()))); - - String mvnoMatchDataSummery = mMvnoMatchData.getText(); -// if (isSpecificApnForCdma(mvnoMatchDataSummery)) { - mvnoMatchDataSummery = sNotSet; -// } - mMvnoMatchData.setSummary(checkNull(mvnoMatchDataSummery)); - //mApnSetting - mApnSetting.setmNameStr(checkNull(mName.getText())); - mApnSetting.setmApnStr(checkNull(mApn.getText())); - mApnSetting.setmProxyStr(checkNull(mProxy.getText())); - mApnSetting.setmPortStr(checkNull(mPort.getText())); - mApnSetting.setmUserStr(checkNull(mUser.getText())); - mApnSetting.setmServerStr(checkNull(mServer.getText())); - mApnSetting.setmPasswordStr(checkNull(mPassword.getText())); - mApnSetting.setmMmsProxyStr(checkNull(mMmsProxy.getText())); - mApnSetting.setmMmsPortStr(checkNull(mMmsPort.getText())); - mApnSetting.setmMmscStr(checkNull(mMmsc.getText())); - mApnSetting.setmMccStr(checkNull(mMcc.getText())); - mApnSetting.setmMncStr(checkNull(mMnc.getText())); - mApnSetting.setmApnTypeStr(mApnTypeSummary); - mApnSetting.setmAuthTypeStr(checkNull(mAuthType.getValue())); - mApnSetting.setmProtocolStr(checkNull(mProtocol.getValue())); - mApnSetting.setmRoamingProtocolStr(checkNull(mRoamingProtocol.getValue())); - mApnSetting.setmBearerStr(checkNull(mBearer.getValue())); - mApnSetting.setmMvnoTypeStr(checkNull(mMvnoType.getValue())); - mApnSetting.setmMvnoMatchDataStr(checkNull(mMvnoMatchData.getText())); - } + mMvnoType = (cursor.getString(MVNO_TYPE_INDEX)); + mMvnoMatchData = (cursor.getString(MVNO_MATCH_DATA_INDEX)); - /** - * Returns the UI choice (e.g., "IPv4/IPv6") corresponding to the given - * raw value of the protocol preference (e.g., "IPV4V6"). If unknown, - * return null. - */ - private String protocolDescription(String raw, ListPreference protocol) { - int protocolIndex = protocol.findIndexOfValue(raw); - if (protocolIndex == -1) { - return null; - } else { - String[] values = mRes.getStringArray(R.array.apn_protocol_entries); - try { - return values[protocolIndex]; - } catch (ArrayIndexOutOfBoundsException e) { - return null; + if (mNewApn && mMvnoTypeStr != null && mMvnoMatchDataStr != null) { + mMvnoType = (mMvnoTypeStr); + mMvnoMatchData = (mMvnoMatchDataStr); } - } - } - private String bearerDescription(String raw) { - int mBearerIndex = mBearer.findIndexOfValue(raw); - if (mBearerIndex == -1) { - return null; - } else { - String[] values = mRes.getStringArray(R.array.bearer_entries); - try { - return values[mBearerIndex]; - } catch (ArrayIndexOutOfBoundsException e) { - return null; - } - } - } - public boolean onKeyDown(int keyCode, KeyEvent event) { - switch (keyCode) { - case KeyEvent.KEYCODE_BACK: { - if (validateAndSave(false)) { -// finish(); - } - return true; - } + if (mNewApn && TextUtils.isEmpty(cursor.getString(TYPE_INDEX))) { + mApnTypeSummary = mApnTypeArray[0]; } - return false; -// return super.onKeyDown(keyCode, event); + + //mApnSetting + apnSetting.setmNameStr(checkNull(mName)); + apnSetting.setmApnStr(checkNull(mApn)); + apnSetting.setmProxyStr(checkNull(mProxy)); + apnSetting.setmPortStr(checkNull(mPort)); + apnSetting.setmUserStr(checkNull(mUser)); + apnSetting.setmServerStr(checkNull(mServer)); + apnSetting.setmPasswordStr(checkNull(mPassword)); + apnSetting.setmMmsProxyStr(checkNull(mMmsProxy)); + apnSetting.setmMmsPortStr(checkNull(mMmsPort)); + apnSetting.setmMmscStr(checkNull(mMmsc)); + apnSetting.setmMccStr(checkNull(mMcc)); + apnSetting.setmMncStr(checkNull(mMnc)); + apnSetting.setmApnTypeStr(mApnTypeSummary); + apnSetting.setmAuthTypeStr(checkNull(mAuthType)); + apnSetting.setmProtocolStr(checkNull(mProtocol)); + apnSetting.setmRoamingProtocolStr(checkNull(mRoamingProtocol)); + apnSetting.setmBearerStr(checkNull(mBearer)); + apnSetting.setmMvnoTypeStr(checkNull(mMvnoType)); + apnSetting.setmMvnoMatchDataStr(checkNull(mMvnoMatchData)); } - /** - * Check the key fields' validity and save if valid. - * @param force save even if the fields are not valid, if the app is - * being suspended - * @return true if the data was saved - */ private boolean validateAndSave(boolean force) { - String name = checkNotSet(mName.getText()); - String apn = checkNotSet(mApn.getText()); - String mcc = checkNotSet(mMcc.getText()); - String mnc = checkNotSet(mMnc.getText()); - + String name = checkNotSet(mName); + String apn = checkNotSet(mApn); + String mcc = checkNotSet(mMcc); + String mnc = checkNotSet(mMnc); + mApnType = mApnTypeArray[0]; if (getErrorMsg() != null && !force) { -// showDialog(ERROR_DIALOG_ID); + ICLogger.e(getErrorMsg()+" force="+force); return false; } - - if (!mCursor.moveToFirst()) { - Log.w(TAG, + if (mCursor!=null && !mCursor.moveToFirst()) { + ICLogger.w( "Could not go to the first row in the Cursor when saving data."); return false; } - // If it's a new APN and a name or apn haven't been entered, then erase the entry // SPRD: FEATURE_APN_CAN_BE_EMTPY if (force && mNewApn && name.length() < 1 && apn.length() < 1 && !mAllowEmptyApn) { mContext.getContentResolver().delete(mUri, null, null); - - /* SPRD: for bug 297172: After hanging up the phone, can not save the new apn normally @{ */ - Log.d(TAG, "The mUri has delete!"); + ICLogger.d( "The mUri has delete!"); mIsdelete = true; - /* @} */ return false; } //mNewApnSetting - mNewApnSetting.setmNameStr(checkNull(mName.getText())); - mNewApnSetting.setmApnStr(checkNull(mApn.getText())); - mNewApnSetting.setmProxyStr(checkNull(mProxy.getText())); - mNewApnSetting.setmPortStr(checkNull(mPort.getText())); - mNewApnSetting.setmUserStr(checkNull(mUser.getText())); - mNewApnSetting.setmServerStr(checkNull(mServer.getText())); - mNewApnSetting.setmPasswordStr(checkNull(mPassword.getText())); - mNewApnSetting.setmMmsProxyStr(checkNull(mMmsProxy.getText())); - mNewApnSetting.setmMmsPortStr(checkNull(mMmsPort.getText())); - mNewApnSetting.setmMmscStr(checkNull(mMmsc.getText())); - mNewApnSetting.setmMccStr(checkNull(mMcc.getText())); - mNewApnSetting.setmMncStr(checkNull(mMnc.getText())); - mNewApnSetting.setmApnTypeStr(checkNull(mApnType.getSummary().toString())); - mNewApnSetting.setmAuthTypeStr(checkNull(mAuthType.getValue())); - mNewApnSetting.setmProtocolStr(checkNull(mProtocol.getValue())); - mNewApnSetting.setmRoamingProtocolStr(checkNull(mRoamingProtocol.getValue())); - mNewApnSetting.setmBearerStr(checkNull(mBearer.getValue())); - mNewApnSetting.setmMvnoTypeStr(checkNull(mMvnoType.getValue())); - mNewApnSetting.setmMvnoMatchDataStr(checkNull(mMvnoMatchData.getText())); - boolean mIsApnChange = mApnSetting.equals(mNewApnSetting) ; - if (!mIsApnChange) { - Log.d(TAG, "mApnSetting: " + mApnSetting.toString()); - Log.d(TAG, "mNewApnSetting: " + mNewApnSetting.toString()); + mNewApnSetting.setmNameStr(checkNull(mName)); + mNewApnSetting.setmApnStr(checkNull(mApn)); + mNewApnSetting.setmProxyStr(checkNull(mProxy)); + mNewApnSetting.setmPortStr(checkNull(mPort)); + mNewApnSetting.setmUserStr(checkNull(mUser)); + mNewApnSetting.setmServerStr(checkNull(mServer)); + mNewApnSetting.setmPasswordStr(checkNull(mPassword)); + mNewApnSetting.setmMmsProxyStr(checkNull(mMmsProxy)); + mNewApnSetting.setmMmsPortStr(checkNull(mMmsPort)); + mNewApnSetting.setmMmscStr(checkNull(mMmsc)); + mNewApnSetting.setmMccStr(checkNull(mMcc)); + mNewApnSetting.setmMncStr(checkNull(mMnc)); + mNewApnSetting.setmApnTypeStr(checkNull(mApnType)); + mNewApnSetting.setmAuthTypeStr(checkNull(mAuthType)); + mNewApnSetting.setmProtocolStr(checkNull(mProtocol)); + mNewApnSetting.setmRoamingProtocolStr(checkNull(mRoamingProtocol)); + mNewApnSetting.setmBearerStr(checkNull(mBearer)); + mNewApnSetting.setmMvnoTypeStr(checkNull(mMvnoType)); + mNewApnSetting.setmMvnoMatchDataStr(checkNull(mMvnoMatchData)); + // boolean mIsApnChange = !mApnSetting.equals(mNewApnSetting); +// if (mIsApnChange) { + ICLogger.d( "mApnSetting: " + mApnSetting.toString()); + ICLogger.d( "mNewApnSetting: " + mNewApnSetting.toString()); ContentValues values = new ContentValues(); // Add a dummy name "Untitled", if the user exits the screen without adding a name but // entered other information worth keeping. values.put(Telephony.Carriers.NAME, - name.length() < 1 ? mContext.getResources().getString(R.string.untitled_apn) : name); + name.length() < 1 ? mContext.getResources().getString(R.string.untitled_apn) : name); values.put(Telephony.Carriers.APN, apn); - values.put(Telephony.Carriers.PROXY, checkNotSet(mProxy.getText())); - values.put(Telephony.Carriers.PORT, checkNotSet(mPort.getText())); - values.put(Telephony.Carriers.MMSPROXY, checkNotSet(mMmsProxy.getText())); - values.put(Telephony.Carriers.MMSPORT, checkNotSet(mMmsPort.getText())); - values.put(Telephony.Carriers.USER, checkNotSet(mUser.getText())); - values.put(Telephony.Carriers.SERVER, checkNotSet(mServer.getText())); - values.put(Telephony.Carriers.PASSWORD, checkNotSet(mPassword.getText())); - values.put(Telephony.Carriers.MMSC, checkNotSet(mMmsc.getText())); - - String authVal = mAuthType.getValue(); + values.put(Telephony.Carriers.PROXY, checkNotSet(mProxy)); + values.put(Telephony.Carriers.PORT, checkNotSet(mPort)); + values.put(Telephony.Carriers.MMSPROXY, checkNotSet(mMmsProxy)); + values.put(Telephony.Carriers.MMSPORT, checkNotSet(mMmsPort)); + values.put(Telephony.Carriers.USER, checkNotSet(mUser)); + values.put(Telephony.Carriers.SERVER, checkNotSet(mServer)); + values.put(Telephony.Carriers.PASSWORD, checkNotSet(mPassword)); + values.put(Telephony.Carriers.MMSC, checkNotSet(mMmsc)); + + String authVal = mAuthType; if (authVal != null) { values.put(Telephony.Carriers.AUTH_TYPE, Integer.parseInt(authVal)); } - values.put(Telephony.Carriers.PROTOCOL, checkNotSet(mProtocol.getValue())); - values.put(Telephony.Carriers.ROAMING_PROTOCOL, checkNotSet(mRoamingProtocol.getValue())); + values.put(Telephony.Carriers.PROTOCOL, checkNotSet(mProtocol)); + values.put(Telephony.Carriers.ROAMING_PROTOCOL, checkNotSet(mRoamingProtocol)); - if (mApnType.getSummary() != null) { - values.put(Telephony.Carriers.TYPE, checkNotSet(mApnType.getSummary().toString())); + if (mApnType != null) { + values.put(Telephony.Carriers.TYPE, checkNotSet(mApnType)); } values.put(Telephony.Carriers.MCC, mcc); @@ -692,54 +581,49 @@ public class ApnEditor { values.put(Telephony.Carriers.NUMERIC, mcc + mnc); - /* SPRD: for multi-sim @{ */ int mDDS = 0; try { - mDDS = Settings.System - .getInt(mContext.getContentResolver(), Settings.System.MULTI_SIM_DATA_CALL); + mDDS = Settings.System.getInt(mContext.getContentResolver(), Settings.System.MULTI_SIM_DATA_CALL); } catch (Exception e) { - Log.e(TAG, "Exception Reading Dual Sim Data Subscription Value.", e); + ICLogger.e( "Exception Reading Dual Sim Data Subscription Value.", e); } - /* @} */ + if (mCurMnc != null && mCurMcc != null) { // SPRD: add by spreadst if (mCurMnc.equals(mnc) && mCurMcc.equals(mcc) && mPhoneId == mDDS) { - // if (mCurMnc.equals(mnc) && mCurMcc.equals(mcc)) { values.put(Telephony.Carriers.CURRENT, 1); } } - String bearerVal = mBearer.getValue(); + String bearerVal = mBearer; if (bearerVal != null) { values.put(Telephony.Carriers.BEARER, Integer.parseInt(bearerVal)); } -// if (SPECIAL_CTCC_NUMERIC.equals(mcc+mnc) && isSpecificApnForCdma(CTCC_ICCID)) { -// values.put(Telephony.Carriers.MVNO_TYPE, "iccid"); -// values.put(Telephony.Carriers.MVNO_MATCH_DATA, CTCC_ICCID); -// } else { - values.put(Telephony.Carriers.MVNO_TYPE, checkNotSet(mMvnoType.getValue())); - values.put(Telephony.Carriers.MVNO_MATCH_DATA, checkNotSet(mMvnoMatchData.getText())); -// } + + values.put(Telephony.Carriers.MVNO_TYPE, checkNotSet(mMvnoType)); + values.put(Telephony.Carriers.MVNO_MATCH_DATA, checkNotSet(mMvnoMatchData)); + mContext.getContentResolver().update(mUri, values, null, null); - } + mNewApn=false; +// } return true; } private String getErrorMsg() { String errorMsg = null; - String name = checkNotSet(mName.getText()); - String apn = checkNotSet(mApn.getText()); - String mcc = checkNotSet(mMcc.getText()); - String mnc = checkNotSet(mMnc.getText()); - String apnString = (String) mApnType.getSummary(); - String apnType = checkNotSet(apnString); + String name = checkNotSet(mName); + String apn = checkNotSet(mApn); + String mcc = checkNotSet(mMcc); + String mnc = checkNotSet(mMnc); + + String apnType = checkNotSet(mApnType); if (name.length() < 1) { errorMsg = mRes.getString(R.string.error_name_empty); - // SPRD: FEATURE_APN_CAN_BE_EMTPY + // SPRD: FEATURE_APN_CAN_BE_EMTPY } else if (apn.length() < 1 && !mAllowEmptyApn) { errorMsg = mRes.getString(R.string.error_apn_empty); } else if (mcc.length() != 3) { @@ -754,22 +638,8 @@ public class ApnEditor { } - - private void deleteApn() { + public void deleteApn() { mContext.getContentResolver().delete(mUri, null, null); -// finish(); - } - - private String starify(String value) { - if (value == null || value.length() == 0) { - return sNotSet; - } else { - char[] password = new char[value.length()]; - for (int i = 0; i < password.length; i++) { - password[i] = '*'; - } - return new String(password); - } } private String checkNull(String value) { diff --git a/build.gradle b/build.gradle index 3ee80266..e9f3aa3b 100644 --- a/build.gradle +++ b/build.gradle @@ -35,8 +35,9 @@ allprojects { gradle.projectsEvaluated { tasks.withType(JavaCompile) { - options.compilerArgs.add('-Xbootclasspath/p:app\\libs\\frameworks-full-debug.jar') -// options.compilerArgs.add('-Xbootclasspath/p:app\\libs\\frameworks-2-full-debug.jar') +// options.compilerArgs.add('-Xbootclasspath/p:app\\libs\\telephony-common-full-debug.jar') +// options.compilerArgs.add('-Xbootclasspath/p:app\\libs\\frameworks-full-debug.jar') + options.compilerArgs << '-Xbootclasspath/p:app\\libs\\frameworks-full-debug.jar;app\\libs\\telephony-common-full-debug.jar' } } } -- 2.17.1