From: TrillGates Date: Wed, 8 Sep 2021 13:07:07 +0000 (+0800) Subject: update apn and app codes. X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=547f98a2dc37c11ff5dc8bc40934c9fc9fff8866;p=icsupport.git update apn and app codes. --- 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 30704f99..2f9ebf8f 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/APNUtil.java +++ b/app/src/main/java/com/enqualcomm/support/utils/APNUtil.java @@ -8,8 +8,10 @@ import java.lang.reflect.Method; public class APNUtil { - private static Phone mPhone=null; - public static void enableRoaming(Context context,boolean roaming) { + private static Phone mPhone = null; + + //暂未启用这种方式。无效 + public static void enableRoaming(Context context, boolean roaming) { String phoneFactoryName = "com.android.internal.telephony.PhoneFactory"; String phoneName = "com.android.internal.telephony.Phone"; @@ -23,33 +25,35 @@ public class APNUtil { Method getDefaultPhone = phoneFactoryClass.getMethod("getDefaultPhone"); Object phoneObject = getDefaultPhone.invoke(null); - mPhone = (Phone)phoneObject; + mPhone = (Phone) phoneObject; } - ICLogger.d("updatePhone:- isRoaming =" + mPhone.getDataRoamingEnabled() +" to " +roaming); + ICLogger.d("updatePhone:- isRoaming =" + mPhone.getDataRoamingEnabled() + " to " + roaming); mPhone.setDataRoamingEnabled(roaming); } catch (Exception e) { - ICLogger.e(e.getMessage(),e); + ICLogger.e(e.getMessage(), e); } } - public static String getCurrentAPN(Context context){ - String APNSTR=""; - APNSTR=ApnEditor.getApnEditorInstance(context).getCurrentAPN(); - ICLogger.i("当前APN "+APNSTR); + 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)){ - ICLogger.i("VPN 已经存在,不需要添加!"); + 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) { + APNUtil.selectAPN(mcc, mnc, apn, context); + ICLogger.i("VPN 已经存在,不需要添加!只是默认选择它"); return false; } //添加新的APN到系统 - boolean isAddSuccess=AddNewApn(apnName,apn,mcc,mnc,user,passwd,context); - + boolean isAddSuccess = AddNewApn(apnName, apn, mcc, mnc, user, passwd, context); if (isAddSuccess) { + APNUtil.selectAPN(mcc, mnc, apn, context); ICLogger.i("APN 添加成功!"); return true; // Toast.makeText(NewAPNActivity.this, "新增APN成功", Toast.LENGTH_SHORT).show(); @@ -69,37 +73,35 @@ public class APNUtil { * @param context * @return */ - public static boolean selectAPN(String mcc,String mnc,String apn,Context context) { - ApnEditor.getApnEditorInstance(context).setDefaultAPN(apn,mcc+mnc); + public static boolean selectAPN(String mcc, String mnc, String apn, Context context) { + ApnEditor.getApnEditorInstance(context).setDefaultAPN(apn, mcc + mnc); return true; } - public static boolean checkAPN(String mcc,String mnc,String apn,Context context) { + + public static boolean checkAPN(String mcc, String mnc, String apn, Context context) { // 检查系统已经写入的APN - String found=""; - found+=ApnEditor.getApnEditorInstance(context).queryApn(apn,mcc+mnc); + 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) { + public static String checkAPN(String mcc, String mnc, Context context) { // 检查系统已经写入的APN - String found=""; - found+=ApnEditor.getApnEditorInstance(context).queryApn(mcc+mnc); + 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 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){ + 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 bedd8297..b3523da4 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/ApnEditor.java +++ b/app/src/main/java/com/enqualcomm/support/utils/ApnEditor.java @@ -122,7 +122,7 @@ public class ApnEditor { private Uri mAPNUri; private Cursor mCursor; private boolean mNewApn; -// private boolean mFirstTime=true; + // 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; @@ -197,12 +197,11 @@ 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; - private static ApnEditor apnEditor=null; + private static ApnEditor apnEditor = null; - public static ApnEditor getApnEditorInstance(Context context){ - if (apnEditor==null && context!=null) - { - apnEditor=new ApnEditor(context); + public static ApnEditor getApnEditorInstance(Context context) { + if (apnEditor == null && context != null) { + apnEditor = new ApnEditor(context); } return apnEditor; } @@ -211,39 +210,56 @@ public class ApnEditor { mContext = context; mRes = context.getResources(); - 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); - mProtocolArray = mRes.getStringArray(R.array.apn_protocol_values); - mBearerArray = mRes.getStringArray(R.array.bearer_entries); - - mAPNUri = Telephony.Carriers.getContentUri(mPhoneId, null); mUri = mAPNUri; - mTelephonyManager = (TelephonyManager) mContext.getSystemService(TELEPHONY_SERVICE); } - public void setSelectedApnKey(String key) { - //s mSelectedKey = key; - ContentResolver resolver = mContext.getContentResolver(); + public void insertSelectedApnKey(String key) { - ContentValues values = new ContentValues(); - /* SPRD: for multi-sim @{ */ - // values.put(APN_ID, mSelectedKey); - // resolver.update(PREFERAPN_URI, values, null, null); - values.put("apn_id", key); - resolver.update( - Telephony.Carriers.getContentUri(0, Telephony.Carriers.PATH_PREFERAPN), - values, null, null); - /* @} */ + try { + //s mSelectedKey = key; + ContentResolver resolver = mContext.getContentResolver(); + + ContentValues values = new ContentValues(); + // values.put(APN_ID, mSelectedKey); + // resolver.update(PREFERAPN_URI, values, null, null); + values.put("apn_id", key); + + resolver.insert(Telephony.Carriers.getContentUri(0, Telephony.Carriers.PATH_PREFERAPN), values); +// resolver.update( +// Telephony.Carriers.getContentUri(0, Telephony.Carriers.PATH_PREFERAPN), +// values, null, null); + } catch (Exception e) { + ICLogger.e(e.getMessage(), e); + } } - public String getSelectedApnKey() { + public void setSelectedApnKey(String key) { + + try { + //s mSelectedKey = key; + ContentResolver resolver = mContext.getContentResolver(); + + ContentValues values = new ContentValues(); + // values.put(APN_ID, mSelectedKey); + // resolver.update(PREFERAPN_URI, values, null, null); + values.put("apn_id", key); + resolver.update( + Telephony.Carriers.getContentUri(0, Telephony.Carriers.PATH_PREFERAPN), + values, null, null); + } catch (Exception e) { + ICLogger.e(e.getMessage(), e); + } + } + + public String getSelectedApnKey() { String key = null; /* SPRD: for multi-sim @{ */ @@ -252,7 +268,7 @@ public class ApnEditor { // null, null, Telephony.Carriers.DEFAULT_SORT_ORDER); Cursor cursor = mContext.getContentResolver().query( Telephony.Carriers.getContentUri(0, Telephony.Carriers.PATH_PREFERAPN), - new String[] { + new String[]{ "_id" }, null, null, Telephony.Carriers.DEFAULT_SORT_ORDER); @@ -262,63 +278,65 @@ public class ApnEditor { key = cursor.getString(0); } cursor.close(); - ICLogger.d(" get default apnkey "+key); + ICLogger.d(" get default apnkey " + key); return key; } - public void setDefaultAPN(String apn, String mccmnc){ - String apnid=queryApnID(apn,mccmnc); - String currentapnid=getSelectedApnKey(); - ICLogger.d("current APN key "+apnid +" selected APN key " + currentapnid); + + public void setDefaultAPN(String apn, String mccmnc) { + String apnid = queryApnID(apn, mccmnc); + String currentapnid = getSelectedApnKey(); + ICLogger.d(apn + " " + mccmnc + " current APN key " + apnid + " selected APN key " + currentapnid); setSelectedApnKey(apnid); - currentapnid=getSelectedApnKey(); - ICLogger.d("after set APN key "+apnid +" selected APN key " + currentapnid); + currentapnid = getSelectedApnKey(); + ICLogger.d(apn + " " + mccmnc + " after set APN key " + apnid + " selected APN key " + currentapnid); } - public String queryApnID(String apn,String mccmnc) { + + public String queryApnID(String apn, String mccmnc) { String where; where = "numeric=\"" + mccmnc + "\""; where += " and name!='CMCC DM'"; - where += " and apn='"+apn+"'"; + where += " and type like '%default%' and apn='" + apn + "'"; - Log.d(TAG,"where = " + where + ",mccmnc =" + mccmnc); + Log.d(TAG, "where = " + where); 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(); + String apnsetings = ""; + if (mCursor != null && 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; } - ICLogger.d("get APN "+apnsetings); + ICLogger.d("get APN " + apnsetings); return mApnSetting.getID(); } - public String queryApn(String apn,String mccmnc){ + public String queryApn(String apn, String mccmnc) { String where; where = "numeric=\"" + mccmnc + "\""; where += " and name!='CMCC DM'"; - where += " and apn='"+apn+"'"; + where += " and type like '%default%' and apn='" + apn + "'"; - Log.d(TAG,"where = " + where + ",mccmnc =" + mccmnc); + Log.d(TAG, "where = " + where); 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(); + String apnsetings = ""; + if (mCursor != null && mCursor.moveToFirst()) { + + fill_apnSettings(mCursor, mApnSetting); + apnsetings += mApnSetting.toShortString(); + while (mCursor.moveToNext()) { + apnsetings += ";"; + fill_apnSettings(mCursor, mApnSetting); + apnsetings += mApnSetting.toShortString(); } } if (mCursor != null) { @@ -327,22 +345,23 @@ public class ApnEditor { } return apnsetings; } - public String queryApn(String mccmnc){ + + public String queryApn(String mccmnc) { String where; where = "numeric=\"" + mccmnc + "\""; - where += " and name!='CMCC DM'"; + where += " and type like '%default%' and name!='CMCC DM'"; - Log.d(TAG,"where = " + where + ",mccmnc =" + mccmnc); + Log.d(TAG, "where = " + where); 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(); + String apnsetings = ""; + if (mCursor != null && mCursor.moveToFirst()) { + + fill_apnSettings(mCursor, mApnSetting); + apnsetings += mApnSetting.toShortString(); + while (mCursor.moveToNext()) { + apnsetings += ";"; + fill_apnSettings(mCursor, mApnSetting); + apnsetings += mApnSetting.toShortString(); } } if (mCursor != null) { @@ -352,12 +371,12 @@ public class ApnEditor { return apnsetings; } - public String getCurrentAPN(){ + public String getCurrentAPN() { String where; String mccmnc; if (TelephonyManager.isMultiSim()) { - mccmnc = android.os.SystemProperties.get(TelephonyManager.getProperty( + mccmnc = 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 @@ -365,81 +384,80 @@ public class ApnEditor { where = "numeric=\"" + mccmnc + "\""; } else { - mccmnc = android.os.SystemProperties.get( + mccmnc = SystemProperties.get( TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC, ""); where = "numeric=\"" + mccmnc + "\""; - } - where += " and name!='CMCC DM'"; + where += " and type like '%default%' and name!='CMCC DM'"; - Log.d(TAG,"where = " + where + ",mccmnc =" + mccmnc); + Log.d(TAG, "where = " + where); // 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(); + String apnsetings = ""; + if (mCursor != null && 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; + String currentApnid = getSelectedApnKey(); + return apnsetings + "; Prefer ApnID=" + currentApnid; } - public boolean resetAPNtoDefault(){ + 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; + 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; + 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); + if (mCursor != 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; + } // } @@ -448,7 +466,6 @@ public class ApnEditor { } - private boolean getApnEditable(Cursor cursor) { String version = SystemProperties.get(CURRENT_CARRIER, "default"); if ("vodafone".equalsIgnoreCase(version) || @@ -460,93 +477,92 @@ public class ApnEditor { } } - private void fill_apnSettings(Cursor cursor,ApnSetting apnSetting) { + private void fill_apnSettings(Cursor cursor, ApnSetting apnSetting) { // SPRD: for bug 348288: while Cursor is null, return // mFirstTime = false; - mID = (cursor.getString(ID_INDEX)); - 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(cursor.getString(PRELOAD_INDEX))); - - if (mNewApn) { - /* SPRD: for multi-sim @{ */ - // String numeric = - // SystemProperties.get(TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC); - String numeric; - if (TelephonyManager.isMultiSim()) { - // APNs are automatically added with MCC+MNC. - // Get the value from appropriate Telephony Property based - // on the mPhoneId. - numeric = SystemProperties - .get(TelephonyManager.getProperty(TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC, mPhoneId)); - - } else { - numeric = SystemProperties.get(TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC); - } - /* @} */ - // MCC is first 3 chars and then in 2 - 3 chars of MNC - if (numeric != null && numeric.length() > 4) { - // Country code - String mcc = numeric.substring(0, 3); - // Network code - String mnc = numeric.substring(3); - // Auto populate MNC and MCC for new entries, based on what SIM reports - mMcc = (mcc); - mMnc = (mnc); - mCurMnc = mnc; - mCurMcc = mcc; - } - } - int authVal = cursor.getInt(AUTH_TYPE_INDEX); - if (authVal != -1) { - mAuthType = String.valueOf(authVal); + mID = (cursor.getString(ID_INDEX)); + 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(cursor.getString(PRELOAD_INDEX))); + + if (mNewApn) { + /* SPRD: for multi-sim @{ */ + // String numeric = + // SystemProperties.get(TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC); + String numeric; + if (TelephonyManager.isMultiSim()) { + // APNs are automatically added with MCC+MNC. + // Get the value from appropriate Telephony Property based + // on the mPhoneId. + numeric = SystemProperties + .get(TelephonyManager.getProperty(TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC, mPhoneId)); + } else { - mAuthType = (null); + numeric = SystemProperties.get(TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC); } - - 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(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 = (cursor.getString(MVNO_TYPE_INDEX)); - mMvnoMatchData = (cursor.getString(MVNO_MATCH_DATA_INDEX)); - - if (mNewApn && mMvnoTypeStr != null && mMvnoMatchDataStr != null) { - mMvnoType = (mMvnoTypeStr); - mMvnoMatchData = (mMvnoMatchDataStr); + /* @} */ + // MCC is first 3 chars and then in 2 - 3 chars of MNC + if (numeric != null && numeric.length() > 4) { + // Country code + String mcc = numeric.substring(0, 3); + // Network code + String mnc = numeric.substring(3); + // Auto populate MNC and MCC for new entries, based on what SIM reports + mMcc = (mcc); + mMnc = (mnc); + mCurMnc = mnc; + mCurMcc = mcc; } + } + int authVal = cursor.getInt(AUTH_TYPE_INDEX); + if (authVal != -1) { + mAuthType = String.valueOf(authVal); + } else { + mAuthType = (null); + } + 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(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 = (cursor.getString(MVNO_TYPE_INDEX)); + mMvnoMatchData = (cursor.getString(MVNO_MATCH_DATA_INDEX)); + + if (mNewApn && mMvnoTypeStr != null && mMvnoMatchDataStr != null) { + mMvnoType = (mMvnoTypeStr); + mMvnoMatchData = (mMvnoMatchDataStr); + } if (mNewApn && TextUtils.isEmpty(cursor.getString(TYPE_INDEX))) { @@ -583,10 +599,10 @@ public class ApnEditor { String mnc = checkNotSet(mMnc); mApnType = mApnTypeArray[0]; if (getErrorMsg() != null && !force) { - ICLogger.e(getErrorMsg()+" force="+force); + ICLogger.e(getErrorMsg() + " force=" + force); return false; } - if (mCursor!=null && !mCursor.moveToFirst()) { + if (mCursor != null && !mCursor.moveToFirst()) { ICLogger.w( "Could not go to the first row in the Cursor when saving data."); return false; @@ -595,7 +611,7 @@ public class ApnEditor { // SPRD: FEATURE_APN_CAN_BE_EMTPY if (force && mNewApn && name.length() < 1 && apn.length() < 1 && !mAllowEmptyApn) { mContext.getContentResolver().delete(mUri, null, null); - ICLogger.d( "The mUri has delete!"); + ICLogger.d("The mUri has delete!"); mIsdelete = true; return false; } @@ -619,69 +635,69 @@ public class ApnEditor { mNewApnSetting.setmBearerStr(checkNull(mBearer)); mNewApnSetting.setmMvnoTypeStr(checkNull(mMvnoType)); mNewApnSetting.setmMvnoMatchDataStr(checkNull(mMvnoMatchData)); - // boolean mIsApnChange = !mApnSetting.equals(mNewApnSetting); + // boolean mIsApnChange = !mApnSetting.equals(mNewApnSetting); // if (mIsApnChange) { - ICLogger.d( "mApnSetting: " + mApnSetting.toString()); - ICLogger.d( "mNewApnSetting: " + mNewApnSetting.toString()); - ContentValues values = new ContentValues(); + 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); - values.put(Telephony.Carriers.APN, apn); - 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)); - } + // 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); + values.put(Telephony.Carriers.APN, apn); + 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)); - values.put(Telephony.Carriers.ROAMING_PROTOCOL, checkNotSet(mRoamingProtocol)); + values.put(Telephony.Carriers.PROTOCOL, checkNotSet(mProtocol)); + values.put(Telephony.Carriers.ROAMING_PROTOCOL, checkNotSet(mRoamingProtocol)); - if (mApnType != null) { - values.put(Telephony.Carriers.TYPE, checkNotSet(mApnType)); - } + if (mApnType != null) { + values.put(Telephony.Carriers.TYPE, checkNotSet(mApnType)); + } - values.put(Telephony.Carriers.MCC, mcc); - values.put(Telephony.Carriers.MNC, mnc); + values.put(Telephony.Carriers.MCC, mcc); + values.put(Telephony.Carriers.MNC, mnc); - values.put(Telephony.Carriers.NUMERIC, mcc + mnc); + values.put(Telephony.Carriers.NUMERIC, mcc + mnc); - int mDDS = 0; - try { - mDDS = Settings.System.getInt(mContext.getContentResolver(), Settings.System.MULTI_SIM_DATA_CALL); - } catch (Exception e) { - ICLogger.e( "Exception Reading Dual Sim Data Subscription Value.", e); - } + int mDDS = 0; + try { + mDDS = Settings.System.getInt(mContext.getContentResolver(), Settings.System.MULTI_SIM_DATA_CALL); + } catch (Exception 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) { - values.put(Telephony.Carriers.CURRENT, 1); - } + if (mCurMnc != null && mCurMcc != null) { + // SPRD: add by spreadst + if (mCurMnc.equals(mnc) && mCurMcc.equals(mcc) && mPhoneId == mDDS) { + values.put(Telephony.Carriers.CURRENT, 1); } + } - String bearerVal = mBearer; - if (bearerVal != null) { - values.put(Telephony.Carriers.BEARER, Integer.parseInt(bearerVal)); - } + String bearerVal = mBearer; + if (bearerVal != null) { + values.put(Telephony.Carriers.BEARER, Integer.parseInt(bearerVal)); + } - values.put(Telephony.Carriers.MVNO_TYPE, checkNotSet(mMvnoType)); - values.put(Telephony.Carriers.MVNO_MATCH_DATA, checkNotSet(mMvnoMatchData)); + 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; + mContext.getContentResolver().update(mUri, values, null, null); + mNewApn = false; // } return true; } diff --git a/app/src/main/java/com/enqualcomm/support/utils/TimeUtil.java b/app/src/main/java/com/enqualcomm/support/utils/TimeUtil.java index 666e8d31..b050b7da 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/TimeUtil.java +++ b/app/src/main/java/com/enqualcomm/support/utils/TimeUtil.java @@ -31,6 +31,10 @@ public class TimeUtil { return (new SimpleDateFormat("MMddHHmmss")).format(new Date(paramLong)); } + public static String getLocalTimeYMD(String paramLong) { + return (new SimpleDateFormat("yyyy-MM-dd")).format(paramLong); + } + public static String getSystemTimeForCameraMark() { return (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date(System.currentTimeMillis())); } @@ -91,7 +95,8 @@ public class TimeUtil { public static String getUTCSystemTimeHHmmss() { return (new SimpleDateFormat("HHmmss")).format(new Date(System.currentTimeMillis() - TimeZone.getDefault().getRawOffset())); } - public static Date parsetiime( String time) { + + public static Date parsetiime(String time) { SimpleDateFormat df1 = new SimpleDateFormat("HH:mm");//需要转化成的时间格式 08:00:00,2016-01-12 Date date1 = null; try { @@ -106,6 +111,7 @@ public class TimeUtil { } } + public static Date parseDatetiime(String date, String time) { // SimpleDateFormat dff = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", Locale.ENGLISH);//输入的被转化的时间格式 @@ -264,15 +270,16 @@ public class TimeUtil { android.provider.Settings.Global.putInt(mContext.getContentResolver(), android.provider.Settings.Global.AUTO_TIME, checked); } + public static void setSysDateTime(Context mContext, Date datetime, String timezoneStr, boolean addtimezoneToTime) { AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); Locale.getDefault().getDisplayCountry(); String timezone_name = ""; - if(timezoneStr.startsWith("e")||timezoneStr.startsWith("E")){ - timezone_name = String.format("GMT+%1$s:%2$s",timezoneStr.substring(1,3),timezoneStr.substring(3,5)); - }else{ - timezone_name = String.format("GMT-%1$s:%2$s", timezoneStr.substring(1,3),timezoneStr.substring(3,5)); + if (timezoneStr.startsWith("e") || timezoneStr.startsWith("E")) { + timezone_name = String.format("GMT+%1$s:%2$s", timezoneStr.substring(1, 3), timezoneStr.substring(3, 5)); + } else { + timezone_name = String.format("GMT-%1$s:%2$s", timezoneStr.substring(1, 3), timezoneStr.substring(3, 5)); } ICLogger.i("====set timezone " + timezone_name); TimeZone tz = TimeZone.getTimeZone(timezone_name); @@ -282,21 +289,21 @@ public class TimeUtil { ICLogger.i("====origin time " + c.getTime().toString() + " time zone " + c.getTimeZone()); c.setTime(datetime); - int timezonehours=0; - int timezoneminutes=0; + int timezonehours = 0; + int timezoneminutes = 0; try { timezonehours = Integer.parseInt(timezoneStr.substring(1, 3)); timezoneminutes = Integer.parseInt(timezoneStr.substring(3, 5)); - }catch (Exception e){ - ICLogger.e(e.getMessage(),e); + } catch (Exception e) { + ICLogger.e(e.getMessage(), e); } if (addtimezoneToTime) { if (is24Hour(mContext)) { c.add(Calendar.HOUR_OF_DAY, timezonehours);//24小时制 - c.add(Calendar.MINUTE,timezoneminutes); + c.add(Calendar.MINUTE, timezoneminutes); } else { c.add(Calendar.HOUR, timezonehours);//12小时制 - c.add(Calendar.MINUTE,timezoneminutes); + c.add(Calendar.MINUTE, timezoneminutes); } c.setTimeZone(tz); } @@ -320,6 +327,7 @@ public class TimeUtil { } + public static void setSysDateTime(Context mContext, Date datetime, int timezone, boolean addtimezoneToTime) { AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); @@ -396,18 +404,20 @@ public class TimeUtil { TimeZone tz = TimeZone.getTimeZone(timeZone); now.setTimeZone(tz); } + //gator 使用,采用 e0800 格式 public static void setTimeZone(Context context, String timeZonedate) { String timezone_name = ""; - if(timeZonedate.startsWith("e")||timeZonedate.startsWith("E")){ - timezone_name = String.format("GMT+%1$s:%2$s",timeZonedate.substring(1,3),timeZonedate.substring(3,5)); - }else{ - timezone_name = String.format("GMT-%1$s:%2$s", timeZonedate.substring(1,3),timeZonedate.substring(3,5)); + if (timeZonedate.startsWith("e") || timeZonedate.startsWith("E")) { + timezone_name = String.format("GMT+%1$s:%2$s", timeZonedate.substring(1, 3), timeZonedate.substring(3, 5)); + } else { + timezone_name = String.format("GMT-%1$s:%2$s", timeZonedate.substring(1, 3), timeZonedate.substring(3, 5)); } ICLogger.i("====set timezone " + timezone_name); //TimeZone tz = TimeZone.getTimeZone(timezone_name); updateTimeZone(context, timezone_name); } + //当前设置timezone的方式,与语言选择方法一致。 public static void setTimeZone(Context context, int timeZone) { diff --git a/app/src/main/java/com/ic/protocols/protocol_s123.java b/app/src/main/java/com/ic/protocols/protocol_s123.java index addba2bc..328298b3 100644 --- a/app/src/main/java/com/ic/protocols/protocol_s123.java +++ b/app/src/main/java/com/ic/protocols/protocol_s123.java @@ -746,8 +746,18 @@ public class protocol_s123 { } //准备数据 String iccid = runtime.getIccid(); - String currentVersion = "V2.1.2.11"; + String currentVersion = android.os.Build.DISPLAY; String protocolReleaseDate = "2021-06-11"; + try { + //返回发布版本的时间戳 + String releaseTimeUtcStr = Util.getSystemProperties("ro.build.date.utc"); + ICLogger.d("releaseTimeUtcStr ==> " + releaseTimeUtcStr); + String localTimeYMD = TimeUtil.getLocalTimeYMD(releaseTimeUtcStr); + ICLogger.d("localTimeYMD ==> " + localTimeYMD); + protocolReleaseDate = localTimeYMD; + } catch (Exception e) { + e.printStackTrace(); + } String ip = runtime.getHost(); int port = runtime.getPort(); int csq = runtime.getCsq();