package com.ccp.xml;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import com.ccp.utils.ImsCapabilities;
import com.ccp.utils.TextUtils;
public class SaveXml {
XmlSerializer mSerializer = XmlObjectFactory.newFastXmlSerializer();
private boolean DBG = false;
private boolean mIsMtk = false;
public SaveXml(boolean isMTK) {
mIsMtk = isMTK;
}
public void generateConfigXml(String path, List<ImsCapabilities> finalConfig, boolean isDefaultConfigExisting) {
log("saveToXml begin");
try {
File file = new File(path);
OutputStream out = new FileOutputStream(file);
mSerializer.setOutput(out, "utf-8");
mSerializer.startDocument("utf-8", true);
// 加了这个和flush之后可以自动缩进
mSerializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
mSerializer.startTag(null, "carrier_config_list");
generateCarrierConfigHeader();
mSerializer.comment("\n\n");
generateDefaultConfig(finalConfig, isDefaultConfigExisting);
for (ImsCapabilities capability : finalConfig) {
boolean volte = capability.ismIsVolteSupport();
boolean vilte = capability.ismIsVilteSupport();
boolean vowifi = capability.ismIsVowifiSupport();
boolean viwifi = capability.ismIsViwifiSupport();
boolean evs = capability.ismIsEvsSupport();
String operator = capability.getOperator();
String mvnoType = capability.getMvnoType();
String mvnoData = capability.getMvnoData();
if (capability.ismIsImsConfig() && TextUtils.isEmpty(operator)) {
continue;
}
mSerializer.comment("\n");
if (capability.ismIsImsConfig()) {
String region = capability.getRegion();
mSerializer.comment(" <!-- " + region + " " + operator + " -->");
mSerializer.comment("\n");
}
mSerializer.startTag(null, "carrier_config");
if (!TextUtils.isEmpty(operator)) {
mSerializer.attribute(null, "operator", operator);
}
if (!capability.ismIsImsConfig()) {
String configName = capability.getmConfigName();
String configValue = capability.getmConfigValue();
if (!TextUtils.isEmpty(configName) && !TextUtils.isEmpty(configValue)) {
mSerializer.attribute(null, configName, configValue);
}
}
if(capability.getAllMccMnc().contains("21403")) {
System.out.println("mvnoType: " + mvnoType + ", mvnoData: " + mvnoData);
}
if (/*capability.isMvno() && */capability.ismIsImsConfig() && !TextUtils.isEmpty(mvnoType) && !TextUtils.isEmpty(mvnoData)) {
mSerializer.attribute(null, mvnoType, mvnoData);
}
if (volte || capability.isMvno()) {
XmlUtils.writeValueXml(volte, "carrier_volte_available_bool", mSerializer, null);
}
if (vilte || capability.isMvno()) {
XmlUtils.writeValueXml(vilte, "carrier_vt_available_bool", mSerializer, null);
}
if (vowifi || capability.isMvno()) {
XmlUtils.writeValueXml(vowifi, "carrier_wfc_ims_available_bool", mSerializer, null);
if (!"CMHK".equalsIgnoreCase(operator)) {
XmlUtils.writeValueXml(vowifi, "config_oplus_sms_ims_support_bool", mSerializer, null);
}
}
if (viwifi || capability.isMvno()) {
XmlUtils.writeValueXml(viwifi, "config_oplus_support_viwifi_bool", mSerializer, null);
}
if (evs || capability.isMvno()) {
if(mIsMtk) {
XmlUtils.writeValueXml(evs, "config_oplus_evs_sup