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 if (shared) { 57 throw new XmlPullParserException("Share data not supported"); 58 } 59 60 while (!XmlUtil.isNextSectionEnd(in, outerTagDepth)) { 61 String[] valueName = new String[1]; 62 Object value = XmlUtil.readCurrentValue(in, valueName); 63 if (valueName[0] == null) { 64 throw new XmlPullParserException("Missing value name"); 65 } 66 switch (valueName[0]) { 67 case XML_TAG_SSID_LIST: 68 mSsidList = (Set<String>) value; 69 break; 70 default: 71 throw new XmlPullParserException("Unknown tag under " 72 + XML_TAG_SECTION_HEADER_DELETED_EPHEMERAL_SSID_LIST 73 + ": " + valueName[0]); 74 } 75 } 76 } 77 78 @Override 79 public void resetData(boolean shared) { 80 if (!shared) { 81 mSsidList = null; 82 } 83 } 84 85 @Override 86 public String getName() { 87 return XML_TAG_SECTION_HEADER_DELETED_EPHEMERAL_SSID_LIST; 88 } 89 90 @Override 91 public boolean supportShareData() { 92 return false; 93 } 94 95 /** 96 * An empty set will be returned for null SSID list. 97 * 98 * @return Set of SSIDs 99 */ 100 public Set<String> getSsidList() { 101 if (mSsidList == null) { 102 return new HashSet<String>(); 103 } 104 return mSsidList; 105 } 106 107 public void setSsidList(Set<String> ssidList) { 108 mSsidList = ssidList; 109 } 110 } 111 112