예제 #1
0
func syncMoibleConnectionId(data connectionData) {
	// sync connection name
	if !isSettingSectionExists(data, sectionCache) {
		return
	}
	providerName := getSettingVkMobileProvider(data)
	if providerName == mobileProviderValueCustom {
		switch getSettingVkMobileServiceType(data) {
		case connectionMobileGsm:
			setSettingConnectionId(data, Tr("Custom")+" GSM")
		case connectionMobileCdma:
			setSettingConnectionId(data, Tr("Custom")+" CDMA")
		}
	} else {
		if plan, err := mobileprovider.UnmarshalPlan(getSettingVkMobilePlan(data)); err == nil {
			if plan.IsGSM {
				if len(plan.Name) > 0 {
					setSettingConnectionId(data, providerName+" "+plan.Name)
				} else {
					setSettingConnectionId(data, providerName+" "+Tr("Default"))
				}
			} else {
				setSettingConnectionId(data, providerName)
			}
		}
	}
}
func logicSetSettingVkMobilePlan(data connectionData, planValue string) (err error) {
	logger.Info("set", NM_SETTING_VK_MOBILE_PLAN, planValue)
	setSettingCacheKey(data, NM_SETTING_VK_MOBILE_PLAN, planValue)
	p, err := mobileprovider.UnmarshalPlan(planValue)
	if err != nil {
		logger.Error(err)
		return
	}

	countryCode := getSettingVkMobileCountry(data)
	providerName := getSettingVkMobileProvider(data)
	if p.IsGSM {
		logicSetSettingVkMobileServiceType(data, connectionMobileGsm)
		apn, err := mobileprovider.GetAPN(countryCode, providerName, p.APNValue, p.APNUsageType)
		if err == nil {
			setSettingGsmApn(data, apn.Value)
			if len(apn.Username) > 0 {
				setSettingGsmUsername(data, apn.Username)
			}
			if len(apn.Password) > 0 {
				setSettingGsmPassword(data, apn.Password)
			}
		}
	} else {
		logicSetSettingVkMobileServiceType(data, connectionMobileCdma)
		cdma, err := mobileprovider.GetCDMA(countryCode, providerName)
		if err == nil {
			if len(cdma.Username) > 0 {
				setSettingCdmaUsername(data, cdma.Username)
			}
			if len(cdma.Password) > 0 {
				setSettingCdmaPassword(data, cdma.Password)
			}
		}
	}
	return
}