1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.server.wifi; 18 19 import com.android.server.wifi.util.XmlUtil; 20 21 import org.xmlpull.v1.XmlPullParser; 22 import org.xmlpull.v1.XmlPullParserException; 23 import org.xmlpull.v1.XmlSerializer; 24 25 import java.io.IOException; 26 import java.util.HashSet; 27 import java.util.Set; 28 29 /** 30 * This class performs serialization and parsing of XML data block that contain the list of 31 * deleted ephemeral SSIDs (XML block data inside <DeletedEphemeralSSIDList> tag). 32 */ 33 public class DeletedEphemeralSsidsStoreData implements WifiConfigStore.StoreData { 34 private static final String XML_TAG_SECTION_HEADER_DELETED_EPHEMERAL_SSID_LIST = 35 "DeletedEphemeralSSIDList"; 36 private static final String XML_TAG_SSID_LIST = "SSIDList"; 37 38 private Set<String> mSsidList; 39 40 DeletedEphemeralSsidsStoreData() {} 41 42 @Override 43 public void serializeData(XmlSerializer out, boolean shared) 44 throws XmlPullParserException, IOException { 45 if (shared) { 46 throw new XmlPullParserException("Share data not supported"); 47 } 48 if (mSsidList != null) { 49 XmlUtil.writeNextValue(out, XML_TAG_SSID_LIST, mSsidList); 50 } 51 } 52 53 @Override 54 public void deserializeData(XmlPullParser in, int outerTagDepth, boolean shared) 55 throws XmlPullParserException, IOException { 56 // Ignore empty reads. 57 if (in == null) { 58 return; 59 } 60 if (shared) { 61 throw new XmlPullParserException("Share data not supported"); 62 } 63 64 while (!XmlUtil.isNextSectionEnd(in, outerTagDepth)) { 65 String[] valueName = new String[1]; 66 Object value = XmlUtil.readCurrentValue(in, valueName); 67 if (valueName[0] == null) { 68 throw new XmlPullParserException("Missing value name"); 69 } 70 switch (valueName[0]) { 71 case XML_TAG_SSID_LIST: 72 mSsidList = (Set<String>) value; 73 break; 74 default: 75 throw new XmlPullParserException("Unknown tag under " 76 + XML_TAG_SECTION_HEADER_DELETED_EPHEMERAL_SSID_LIST 77 + ": " + valueName[0]); 78 } 79 } 80 } 81 82 @Override 83 public void resetData(boolean shared) { 84 if (!shared) { 85 mSsidList = null; 86 } 87 } 88 89 @Override 90 public String getName() { 91 return XML_TAG_SECTION_HEADER_DELETED_EPHEMERAL_SSID_LIST; 92 } 93 94 @Override 95 public boolean supportShareData() { 96 return false; 97 } 98 99 /** 100 * An empty set will be returned for null SSID list. 101 * 102 * @return Set of SSIDs 103 */ 104 public Set<String> getSsidList() { 105 if (mSsidList == null) { 106 return new HashSet<String>(); 107 } 108 return mSsidList; 109 } 110 111 public void setSsidList(Set<String> ssidList) { 112 mSsidList = ssidList; 113 } 114 } 115 116