apn insert exception for duplicate apn entry
Test: Visual Test Fix: 321619947 Change-Id: I362cd0c5dec7b8fab9af081f67717c4633064cdd
This commit is contained in:
@@ -145,12 +145,7 @@ fun ApnPage(apnDataInit: ApnData, apnDataCur: MutableState<ApnData>, uriInit: Ur
|
|||||||
) {
|
) {
|
||||||
Column {
|
Column {
|
||||||
if (apnData.validEnabled) {
|
if (apnData.validEnabled) {
|
||||||
apnData = apnData.copy(
|
valid = validateApnData(apnData, context)
|
||||||
networkType = ApnNetworkTypes.getNetworkType(
|
|
||||||
networkTypeSelectedOptionsState
|
|
||||||
)
|
|
||||||
)
|
|
||||||
valid = validateApnData(uriInit, apnData, context)
|
|
||||||
valid?.let {
|
valid?.let {
|
||||||
Text(
|
Text(
|
||||||
text = it,
|
text = it,
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import android.content.ContentValues
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.provider.Telephony
|
import android.provider.Telephony
|
||||||
import android.telephony.TelephonyManager
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.android.settings.R
|
import com.android.settings.R
|
||||||
import com.android.settingslib.utils.ThreadUtils
|
import com.android.settingslib.utils.ThreadUtils
|
||||||
@@ -200,14 +199,21 @@ fun updateApnDataToDatabase(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isItemExist(uri: Uri, apnData: ApnData, context: Context): String? {
|
fun isItemExist(apnData: ApnData, context: Context): String? {
|
||||||
val contentValueMap = apnData.getContentValueMap(context)
|
var contentValueMap = apnData.getContentValueMap(context)
|
||||||
contentValueMap.remove(Telephony.Carriers.CARRIER_ENABLED)
|
val removedList = arrayListOf(
|
||||||
|
Telephony.Carriers.NAME, Telephony.Carriers.USER,
|
||||||
|
Telephony.Carriers.SERVER, Telephony.Carriers.PASSWORD, Telephony.Carriers.AUTH_TYPE,
|
||||||
|
Telephony.Carriers.TYPE, Telephony.Carriers.NETWORK_TYPE_BITMASK,
|
||||||
|
Telephony.Carriers.CARRIER_ENABLED
|
||||||
|
)
|
||||||
|
contentValueMap =
|
||||||
|
contentValueMap.filterNot { removedList.contains(it.key) } as MutableMap<String, Any>
|
||||||
val list = contentValueMap.entries.toList()
|
val list = contentValueMap.entries.toList()
|
||||||
val selection = list.joinToString(" AND ") { "${it.key} = ?" }
|
val selection = list.joinToString(" AND ") { "${it.key} = ?" }
|
||||||
val selectionArgs: Array<String> = list.map { it.value.toString() }.toTypedArray()
|
val selectionArgs: Array<String> = list.map { it.value.toString() }.toTypedArray()
|
||||||
context.contentResolver.query(
|
context.contentResolver.query(
|
||||||
uri,
|
Telephony.Carriers.CONTENT_URI,
|
||||||
sProjection,
|
sProjection,
|
||||||
selection /* selection */,
|
selection /* selection */,
|
||||||
selectionArgs /* selectionArgs */,
|
selectionArgs /* selectionArgs */,
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ fun validateAndSaveApnData(
|
|||||||
context: Context,
|
context: Context,
|
||||||
uriInit: Uri
|
uriInit: Uri
|
||||||
): String? {
|
): String? {
|
||||||
val errorMsg = validateApnData(uriInit, newApnData, context)
|
val errorMsg = validateApnData(newApnData, context)
|
||||||
if (errorMsg != null) {
|
if (errorMsg != null) {
|
||||||
return errorMsg
|
return errorMsg
|
||||||
}
|
}
|
||||||
@@ -194,7 +194,7 @@ fun validateAndSaveApnData(
|
|||||||
*
|
*
|
||||||
* @return An error message if the apn data is invalid, otherwise return null.
|
* @return An error message if the apn data is invalid, otherwise return null.
|
||||||
*/
|
*/
|
||||||
fun validateApnData(uri: Uri, apnData: ApnData, context: Context): String? {
|
fun validateApnData(apnData: ApnData, context: Context): String? {
|
||||||
var errorMsg: String?
|
var errorMsg: String?
|
||||||
val name = apnData.name
|
val name = apnData.name
|
||||||
val apn = apnData.apn
|
val apn = apnData.apn
|
||||||
@@ -206,7 +206,7 @@ fun validateApnData(uri: Uri, apnData: ApnData, context: Context): String? {
|
|||||||
validateMMSC(true, apnData.mmsc, context)
|
validateMMSC(true, apnData.mmsc, context)
|
||||||
}
|
}
|
||||||
if (errorMsg == null) {
|
if (errorMsg == null) {
|
||||||
errorMsg = isItemExist(uri, apnData, context)
|
errorMsg = isItemExist(apnData, context)
|
||||||
}
|
}
|
||||||
if (errorMsg == null) {
|
if (errorMsg == null) {
|
||||||
errorMsg = validateAPNType(
|
errorMsg = validateAPNType(
|
||||||
|
|||||||
Reference in New Issue
Block a user