Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1a5da2b5 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge changes I69c1931b,I6b08f52d

* changes:
  wifi: hotspot2: omadm: add XML parser for parsing OMA-DM XML string
  wifi: hotspot2: initial implementation of PasspointConfiguration
parents e266c375 bae4becf
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
/**
 * Copyright (c) 2016, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.net.wifi.hotspot2;

parcelable PasspointConfiguration;
+78 −0
Original line number Diff line number Diff line
/**
 * Copyright (c) 2016, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.net.wifi.hotspot2;

import android.net.wifi.hotspot2.pps.Credential;
import android.net.wifi.hotspot2.pps.HomeSP;
import android.os.Parcelable;
import android.os.Parcel;

/**
 * Class representing Passpoint configuration.  This contains configurations specified in
 * PerProviderSubscription (PPS) Management Object (MO) tree.
 *
 * For more info, refer to Hotspot 2.0 PPS MO defined in section 9.1 of the Hotspot 2.0
 * Release 2 Technical Specification.
 *
 * Currently, only HomeSP and Credential subtrees are supported.
 *
 * @hide
 */
public final class PasspointConfiguration implements Parcelable {
    public HomeSP homeSp = null;
    public Credential credential = null;

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeParcelable(homeSp, flags);
        dest.writeParcelable(credential, flags);
    }

    @Override
    public boolean equals(Object thatObject) {
        if (this == thatObject) {
            return true;
        }
        if (!(thatObject instanceof PasspointConfiguration)) {
            return false;
        }
        PasspointConfiguration that = (PasspointConfiguration) thatObject;
        return (homeSp == null ? that.homeSp == null : homeSp.equals(that.homeSp)) &&
                (credential == null ? that.credential == null :
                    credential.equals(that.credential));
    }

    public static final Creator<PasspointConfiguration> CREATOR =
        new Creator<PasspointConfiguration>() {
            @Override
            public PasspointConfiguration createFromParcel(Parcel in) {
                PasspointConfiguration config = new PasspointConfiguration();
                config.homeSp = in.readParcelable(null);
                config.credential = in.readParcelable(null);
                return config;
            }
            @Override
            public PasspointConfiguration[] newArray(int size) {
                return new PasspointConfiguration[size];
            }
        };
}
+103 −0
Original line number Diff line number Diff line
/**
 * Copyright (c) 2016, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.net.wifi.hotspot2.omadm;

import android.text.TextUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * A class represent a node in an XML tree. Each node is an XML element.
 * Used by {@link XMLParser} for parsing/converting each XML element to XMLNode.
 *
 * @hide
 */
public class XMLNode {
    private final String mTag;
    private final List<XMLNode> mChildren;
    private final XMLNode mParent;
    private StringBuilder mTextBuilder;
    private String mText;

    public XMLNode(XMLNode parent, String tag) {
        mTag = tag;
        mParent = parent;
        mChildren = new ArrayList<>();
        mTextBuilder = new StringBuilder();
        mText = null;
    }

    /**
     * Adding a text to this node. Invoked by {@link XMLParser#characters}.
     *
     * @param text String to be added
     */
    public void addText(String text) {
        mTextBuilder.append(text);
    }

    /**
     * Adding a child node to this node. Invoked by {@link XMLParser#startElement}.
     *
     * @param child XMLNode to be added
     */
    public void addChild(XMLNode child) {
        mChildren.add(child);
    }

    /**
     * Invoked when the end of the XML element is detected. Used for further processing
     * of the text enclosed within this XML element. Invoked by {@link XMLParser#endElement}.
     */
    public void close() {
        // Remove the leading and the trailing whitespaces.
        mText = mTextBuilder.toString().trim();
        mTextBuilder = null;
    }

    public String getTag() {
        return mTag;
    }

    public XMLNode getParent() {
        return mParent;
    }

    public String getText() {
        return mText;
    }

    public List<XMLNode> getChildren() {
        return mChildren;
    }

    @Override
    public boolean equals(Object thatObject) {
        if (this == thatObject) {
            return true;
        }
        if (!(thatObject instanceof XMLNode)) {
            return false;
        }
        XMLNode that = (XMLNode) thatObject;

        return TextUtils.equals(mTag, that.mTag) &&
                TextUtils.equals(mText, that.mText) &&
                mChildren.equals(that.mChildren);
    }
}
+108 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.net.wifi.hotspot2.omadm;

import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import android.text.TextUtils;

import java.io.IOException;
import java.io.StringReader;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

/**
 * Class for parsing an XML string to an XML tree represented by {@link XMLNode}.
 *
 * The original XML string:
 * <root>
 *   <tag1>text1</tag1>
 *   <tag2>
 *     <tag3>text3</tag3>
 *   </tag2>
 * </root>
 *
 * The XML tree representation:
 *                  [root]
 *                     |
 *                     |
 *   [tag1, text1]-----|-----[tag2]
 *                             |
 *                             |
 *                       [tag3, text3]
 *
 * @hide
 */
public class XMLParser extends DefaultHandler {
    private XMLNode mRoot = null;
    private XMLNode mCurrent = null;

    public XMLNode parse(String text) throws IOException, SAXException {
        if (TextUtils.isEmpty(text)) {
            throw new IOException("XML string not provided");
        }

        // Reset pointers.
        mRoot = null;
        mCurrent = null;

        try {
            SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
            parser.parse(new InputSource(new StringReader(text)), this);
            return mRoot;
        } catch (ParserConfigurationException pce) {
            throw new SAXException(pce);
        }
    }

    @Override
    public void startElement(String uri, String localName, String qName, Attributes attributes)
            throws SAXException {
        XMLNode parent = mCurrent;

        mCurrent = new XMLNode(parent, qName);

        if (mRoot == null) {
            mRoot = mCurrent;
        } else if (parent == null) {
            throw new SAXException("More than one root nodes");
        } else {
            parent.addChild(mCurrent);
        }
    }

    @Override
    public void endElement(String uri, String localName, String qName) throws SAXException {
        if (!qName.equals(mCurrent.getTag())) {
            throw new SAXException("End tag '" + qName + "' doesn't match current node: " +
                    mCurrent);
        }

        mCurrent.close();
        mCurrent = mCurrent.getParent();
    }

    @Override
    public void characters(char[] ch, int start, int length) throws SAXException {
        mCurrent.addText(new String(ch, start, length));
    }
}
+19 −0
Original line number Diff line number Diff line
/**
 * Copyright (c) 2016, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.net.wifi.hotspot2.pps;

parcelable Credential;
Loading