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

Commit e4c50de7 authored by Etan Cohen's avatar Etan Cohen
Browse files

[NAN]: API update - consolidate Puslish|Subscribe Data+Subscribe -> Config [DO NOT MERGE]

Simplify configuration and consolidate structures whose difference
wasn't very clear.

Bug: 27122760
Change-Id: I0651cade71eb146d9ea9219baf6d2253588db3de
parent aa36f071
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -480,10 +480,8 @@ aidl_files := \
	frameworks/base/media/java/android/media/browse/MediaBrowser.aidl \
	frameworks/base/wifi/java/android/net/wifi/ScanSettings.aidl \
	frameworks/base/wifi/java/android/net/wifi/nan/ConfigRequest.aidl \
	frameworks/base/wifi/java/android/net/wifi/nan/PublishData.aidl \
	frameworks/base/wifi/java/android/net/wifi/nan/SubscribeData.aidl \
	frameworks/base/wifi/java/android/net/wifi/nan/PublishSettings.aidl \
	frameworks/base/wifi/java/android/net/wifi/nan/SubscribeSettings.aidl \
	frameworks/base/wifi/java/android/net/wifi/nan/PublishConfig.aidl \
	frameworks/base/wifi/java/android/net/wifi/nan/SubscribeConfig.aidl \
	frameworks/base/wifi/java/android/net/wifi/p2p/WifiP2pInfo.aidl \
	frameworks/base/wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.aidl \
	frameworks/base/wifi/java/android/net/wifi/p2p/WifiP2pConfig.aidl \
+4 −8
Original line number Diff line number Diff line
@@ -21,10 +21,8 @@ import android.app.PendingIntent;
import android.net.wifi.nan.ConfigRequest;
import android.net.wifi.nan.IWifiNanEventListener;
import android.net.wifi.nan.IWifiNanSessionListener;
import android.net.wifi.nan.PublishData;
import android.net.wifi.nan.PublishSettings;
import android.net.wifi.nan.SubscribeData;
import android.net.wifi.nan.SubscribeSettings;
import android.net.wifi.nan.PublishConfig;
import android.net.wifi.nan.SubscribeConfig;

/**
 * Interface that WifiNanService implements
@@ -40,10 +38,8 @@ interface IWifiNanManager

    // session API
    int createSession(int clientId, in IWifiNanSessionListener listener, int events);
    void publish(int clientId, int sessionId, in PublishData publishData,
            in PublishSettings publishSettings);
    void subscribe(int clientId, int sessionId, in SubscribeData subscribeData,
            in SubscribeSettings subscribeSettings);
    void publish(int clientId, int sessionId, in PublishConfig publishConfig);
    void subscribe(int clientId, int sessionId, in SubscribeConfig subscribeConfig);
    void sendMessage(int clientId, int sessionId, int peerId, in byte[] message, int messageLength,
            int messageId);
    void stopSession(int clientId, int sessionId);
+1 −1
Original line number Diff line number Diff line
@@ -16,4 +16,4 @@

package android.net.wifi.nan;

parcelable PublishData;
parcelable PublishConfig;
+137 −30
Original line number Diff line number Diff line
@@ -22,13 +22,29 @@ import android.os.Parcelable;
import java.util.Arrays;

/**
 * Defines the data for a NAN publish session. Built using
 * {@link PublishData.Builder}. Publish is done using
 * {@link WifiNanManager#publish(PublishData, PublishSettings, WifiNanSessionListener, int)}
 * or {@link WifiNanPublishSession#publish(PublishData, PublishSettings)}.
 * Defines the configuration of a NAN publish session. Built using
 * {@link PublishConfig.Builder}. Publish is done using
 * {@link WifiNanManager#publish(PublishConfig, WifiNanSessionListener, int)} or
 * {@link WifiNanPublishSession#publish(PublishConfig)}.
 *
 * @hide PROPOSED_NAN_API
 */
public class PublishData implements Parcelable {
public class PublishConfig implements Parcelable {
    /**
     * Defines an unsolicited publish session - i.e. a publish session where
     * publish packets are transmitted over-the-air. Configuration is done using
     * {@link PublishConfig.Builder#setPublishType(int)}.
     */
    public static final int PUBLISH_TYPE_UNSOLICITED = 0;

    /**
     * Defines a solicited publish session - i.e. a publish session where
     * publish packets are not transmitted over-the-air and the device listens
     * and matches to transmitted subscribe packets. Configuration is done using
     * {@link PublishConfig.Builder#setPublishType(int)}.
     */
    public static final int PUBLISH_TYPE_SOLICITED = 1;

    /**
     * @hide
     */
@@ -64,9 +80,24 @@ public class PublishData implements Parcelable {
     */
    public final byte[] mRxFilter;

    private PublishData(String serviceName, byte[] serviceSpecificInfo,
    /**
     * @hide
     */
    public final int mPublishType;

    /**
     * @hide
     */
    public final int mPublishCount;

    /**
     * @hide
     */
    public final int mTtlSec;

    private PublishConfig(String serviceName, byte[] serviceSpecificInfo,
            int serviceSpecificInfoLength, byte[] txFilter, int txFilterLength, byte[] rxFilter,
            int rxFilterLength) {
            int rxFilterLength, int publishType, int publichCount, int ttlSec) {
        mServiceName = serviceName;
        mServiceSpecificInfoLength = serviceSpecificInfoLength;
        mServiceSpecificInfo = serviceSpecificInfo;
@@ -74,17 +105,21 @@ public class PublishData implements Parcelable {
        mTxFilter = txFilter;
        mRxFilterLength = rxFilterLength;
        mRxFilter = rxFilter;
        mPublishType = publishType;
        mPublishCount = publichCount;
        mTtlSec = ttlSec;
    }

    @Override
    public String toString() {
        return "PublishData [mServiceName='" + mServiceName + "', mServiceSpecificInfo='"
        return "PublishConfig [mServiceName='" + mServiceName + "', mServiceSpecificInfo='"
                + (new String(mServiceSpecificInfo, 0, mServiceSpecificInfoLength))
                + "', mTxFilter="
                + (new TlvBufferUtils.TlvIterable(0, 1, mTxFilter, mTxFilterLength)).toString()
                + ", mRxFilter="
                + (new TlvBufferUtils.TlvIterable(0, 1, mRxFilter, mRxFilterLength)).toString()
                + "']";
                + ", mPublishType=" + mPublishType + ", mPublishCount=" + mPublishCount
                + ", mTtlSec=" + mTtlSec + "']";
    }

    @Override
@@ -92,7 +127,6 @@ public class PublishData implements Parcelable {
        return 0;
    }


    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(mServiceName);
@@ -108,16 +142,19 @@ public class PublishData implements Parcelable {
        if (mRxFilterLength != 0) {
            dest.writeByteArray(mRxFilter, 0, mRxFilterLength);
        }
        dest.writeInt(mPublishType);
        dest.writeInt(mPublishCount);
        dest.writeInt(mTtlSec);
    }

    public static final Creator<PublishData> CREATOR = new Creator<PublishData>() {
    public static final Creator<PublishConfig> CREATOR = new Creator<PublishConfig>() {
        @Override
        public PublishData[] newArray(int size) {
            return new PublishData[size];
        public PublishConfig[] newArray(int size) {
            return new PublishConfig[size];
        }

        @Override
        public PublishData createFromParcel(Parcel in) {
        public PublishConfig createFromParcel(Parcel in) {
            String serviceName = in.readString();
            int ssiLength = in.readInt();
            byte[] ssi = new byte[ssiLength];
@@ -134,9 +171,11 @@ public class PublishData implements Parcelable {
            if (rxFilterLength != 0) {
                in.readByteArray(rxFilter);
            }

            return new PublishData(serviceName, ssi, ssiLength, txFilter, txFilterLength, rxFilter,
                    rxFilterLength);
            int publishType = in.readInt();
            int publishCount = in.readInt();
            int ttlSec = in.readInt();
            return new PublishConfig(serviceName, ssi, ssiLength, txFilter, txFilterLength,
                    rxFilter, rxFilterLength, publishType, publishCount, ttlSec);
        }
    };

@@ -146,11 +185,11 @@ public class PublishData implements Parcelable {
            return true;
        }

        if (!(o instanceof PublishData)) {
        if (!(o instanceof PublishConfig)) {
            return false;
        }

        PublishData lhs = (PublishData) o;
        PublishConfig lhs = (PublishConfig) o;

        if (!mServiceName.equals(lhs.mServiceName)
                || mServiceSpecificInfoLength != lhs.mServiceSpecificInfoLength
@@ -189,7 +228,8 @@ public class PublishData implements Parcelable {
            return false; // invalid != invalid
        }

        return true;
        return mPublishType == lhs.mPublishType && mPublishCount == lhs.mPublishCount
                && mTtlSec == lhs.mTtlSec;
    }

    @Override
@@ -203,12 +243,15 @@ public class PublishData implements Parcelable {
        result = 31 * result + Arrays.hashCode(mTxFilter);
        result = 31 * result + mRxFilterLength;
        result = 31 * result + Arrays.hashCode(mRxFilter);
        result = 31 * result + mPublishType;
        result = 31 * result + mPublishCount;
        result = 31 * result + mTtlSec;

        return result;
    }

    /**
     * Builder used to build {@link PublishData} objects.
     * Builder used to build {@link PublishConfig} objects.
     */
    public static final class Builder {
        private String mServiceName;
@@ -218,6 +261,9 @@ public class PublishData implements Parcelable {
        private byte[] mTxFilter = new byte[0];
        private int mRxFilterLength;
        private byte[] mRxFilter = new byte[0];
        private int mPublishType;
        private int mPublishCount;
        private int mTtlSec;

        /**
         * Specify the service name of the publish session. The actual on-air
@@ -260,7 +306,7 @@ public class PublishData implements Parcelable {

        /**
         * Specify service specific information for the publish session - same
         * as {@link PublishData.Builder#setServiceSpecificInfo(byte[], int)}
         * as {@link PublishConfig.Builder#setServiceSpecificInfo(byte[], int)}
         * but obtaining the data from a String.
         *
         * @param serviceSpecificInfoStr The service specific information string
@@ -277,8 +323,8 @@ public class PublishData implements Parcelable {

        /**
         * The transmit filter for an active publish session
         * {@link PublishSettings.Builder#setPublishType(int)} and
         * {@link PublishSettings#PUBLISH_TYPE_UNSOLICITED}. Included in
         * {@link PublishConfig.Builder#setPublishType(int)} and
         * {@link PublishConfig#PUBLISH_TYPE_UNSOLICITED}. Included in
         * transmitted publish packets and used by receivers (subscribers) to
         * determine whether they match - in addition to just relying on the
         * service name.
@@ -305,8 +351,8 @@ public class PublishData implements Parcelable {

        /**
         * The transmit filter for a passive publish session
         * {@link PublishSettings.Builder#setPublishType(int)} and
         * {@link PublishSettings#PUBLISH_TYPE_SOLICITED}. Used by the publisher
         * {@link PublishConfig.Builder#setPublishType(int)} and
         * {@link PublishConfig#PUBLISH_TYPE_SOLICITED}. Used by the publisher
         * to determine whether they match transmitted subscriber packets
         * (active subscribers) - in addition to just relying on the service
         * name.
@@ -332,12 +378,73 @@ public class PublishData implements Parcelable {
        }

        /**
         * Build {@link PublishData} given the current requests made on the
         * Sets the type of the publish session: solicited (aka active - publish
         * packets are transmitted over-the-air), or unsolicited (aka passive -
         * no publish packets are transmitted, a match is made against an active
         * subscribe session whose packets are transmitted over-the-air).
         *
         * @param publishType Publish session type: solicited (
         *            {@link PublishConfig#PUBLISH_TYPE_SOLICITED}) or
         *            unsolicited (
         *            {@link PublishConfig#PUBLISH_TYPE_UNSOLICITED}).
         * @return The builder to facilitate chaining
         *         {@code builder.setXXX(..).setXXX(..)}.
         */
        public Builder setPublishType(int publishType) {
            if (publishType < PUBLISH_TYPE_UNSOLICITED || publishType > PUBLISH_TYPE_SOLICITED) {
                throw new IllegalArgumentException("Invalid publishType - " + publishType);
            }
            mPublishType = publishType;
            return this;
        }

        /**
         * Sets the number of times a solicited (
         * {@link PublishConfig.Builder#setPublishType(int)}) publish session
         * will transmit a packet. When the count is reached an event will be
         * generated for {@link WifiNanSessionListener#onPublishTerminated(int)}
         * with reason={@link WifiNanSessionListener#TERMINATE_REASON_DONE}.
         *
         * @param publishCount Number of publish packets to transmit.
         * @return The builder to facilitate chaining
         *         {@code builder.setXXX(..).setXXX(..)}.
         */
        public Builder setPublishCount(int publishCount) {
            if (publishCount < 0) {
                throw new IllegalArgumentException("Invalid publishCount - must be non-negative");
            }
            mPublishCount = publishCount;
            return this;
        }

        /**
         * Sets the time interval (in seconds) a solicited (
         * {@link PublishConfig.Builder#setPublishCount(int)}) publish session
         * will be alive - i.e. transmitting a packet. When the TTL is reached
         * an event will be generated for
         * {@link WifiNanSessionListener#onPublishTerminated(int)} with reason=
         * {@link WifiNanSessionListener#TERMINATE_REASON_DONE}.
         *
         * @param ttlSec Lifetime of a publish session in seconds.
         * @return The builder to facilitate chaining
         *         {@code builder.setXXX(..).setXXX(..)}.
         */
        public Builder setTtlSec(int ttlSec) {
            if (ttlSec < 0) {
                throw new IllegalArgumentException("Invalid ttlSec - must be non-negative");
            }
            mTtlSec = ttlSec;
            return this;
        }

        /**
         * Build {@link PublishConfig} given the current requests made on the
         * builder.
         */
        public PublishData build() {
            return new PublishData(mServiceName, mServiceSpecificInfo, mServiceSpecificInfoLength,
                    mTxFilter, mTxFilterLength, mRxFilter, mRxFilterLength);
        public PublishConfig build() {
            return new PublishConfig(mServiceName, mServiceSpecificInfo, mServiceSpecificInfoLength,
                    mTxFilter, mTxFilterLength, mRxFilter, mRxFilterLength, mPublishType,
                    mPublishCount, mTtlSec);
        }
    }
}
+0 −19
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.nan;

parcelable PublishSettings;
Loading