120d329b08df7d1a94e6caee781f09e812a79c913Etan Cohen/*
220d329b08df7d1a94e6caee781f09e812a79c913Etan Cohen * Copyright (C) 2016 The Android Open Source Project
320d329b08df7d1a94e6caee781f09e812a79c913Etan Cohen *
420d329b08df7d1a94e6caee781f09e812a79c913Etan Cohen * Licensed under the Apache License, Version 2.0 (the "License");
520d329b08df7d1a94e6caee781f09e812a79c913Etan Cohen * you may not use this file except in compliance with the License.
620d329b08df7d1a94e6caee781f09e812a79c913Etan Cohen * You may obtain a copy of the License at
720d329b08df7d1a94e6caee781f09e812a79c913Etan Cohen *
820d329b08df7d1a94e6caee781f09e812a79c913Etan Cohen *      http://www.apache.org/licenses/LICENSE-2.0
920d329b08df7d1a94e6caee781f09e812a79c913Etan Cohen *
1020d329b08df7d1a94e6caee781f09e812a79c913Etan Cohen * Unless required by applicable law or agreed to in writing, software
1120d329b08df7d1a94e6caee781f09e812a79c913Etan Cohen * distributed under the License is distributed on an "AS IS" BASIS,
1220d329b08df7d1a94e6caee781f09e812a79c913Etan Cohen * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1320d329b08df7d1a94e6caee781f09e812a79c913Etan Cohen * See the License for the specific language governing permissions and
1420d329b08df7d1a94e6caee781f09e812a79c913Etan Cohen * limitations under the License.
1520d329b08df7d1a94e6caee781f09e812a79c913Etan Cohen */
1620d329b08df7d1a94e6caee781f09e812a79c913Etan Cohen
170849ded00879dc05175c079011aa038c5ba0770aEtan Cohenpackage android.net.wifi.aware;
1820d329b08df7d1a94e6caee781f09e812a79c913Etan Cohen
195e680daad8096611c9bd2e4fc788d099089b09ccEtan Cohenimport android.annotation.NonNull;
2051181fb85d490b16fa3b8cff5ee3c906d148533bEtan Cohenimport android.util.Log;
2151181fb85d490b16fa3b8cff5ee3c906d148533bEtan Cohen
2220d329b08df7d1a94e6caee781f09e812a79c913Etan Cohen/**
230849ded00879dc05175c079011aa038c5ba0770aEtan Cohen * A class representing a Aware publish session. Created when
243de35a5e5573828838bfa6359a1ac1bf22b19303Etan Cohen * {@link WifiAwareSession#publish(PublishConfig, DiscoverySessionCallback,
256831f93725f9efd9c13a278acac62a5d7dcf4a4dEtan Cohen * android.os.Handler)} is called and a discovery session is created and returned in
263de35a5e5573828838bfa6359a1ac1bf22b19303Etan Cohen * {@link DiscoverySessionCallback#onPublishStarted(PublishDiscoverySession)}. See
273de35a5e5573828838bfa6359a1ac1bf22b19303Etan Cohen * baseline functionality of all discovery sessions in {@link DiscoverySession}. This
283855370c24b575e0943a9a3c146fda980cd71e24Etan Cohen * object allows updating an existing/running publish discovery session using
293855370c24b575e0943a9a3c146fda980cd71e24Etan Cohen * {@link #updatePublish(PublishConfig)}.
3020d329b08df7d1a94e6caee781f09e812a79c913Etan Cohen */
313de35a5e5573828838bfa6359a1ac1bf22b19303Etan Cohenpublic class PublishDiscoverySession extends DiscoverySession {
323de35a5e5573828838bfa6359a1ac1bf22b19303Etan Cohen    private static final String TAG = "PublishDiscoverySession";
3351181fb85d490b16fa3b8cff5ee3c906d148533bEtan Cohen
34b0214c4cd56e26a26c2bec61c287fc008ed3e551Etan Cohen    /** @hide */
353de35a5e5573828838bfa6359a1ac1bf22b19303Etan Cohen    public PublishDiscoverySession(WifiAwareManager manager, int clientId, int sessionId) {
36bd4bf35d22a04b0c5a39bdf6543cec0af9df2306Etan Cohen        super(manager, clientId, sessionId);
3720d329b08df7d1a94e6caee781f09e812a79c913Etan Cohen    }
3820d329b08df7d1a94e6caee781f09e812a79c913Etan Cohen
3920d329b08df7d1a94e6caee781f09e812a79c913Etan Cohen    /**
40b0214c4cd56e26a26c2bec61c287fc008ed3e551Etan Cohen     * Re-configure the currently active publish session. The
413de35a5e5573828838bfa6359a1ac1bf22b19303Etan Cohen     * {@link DiscoverySessionCallback} is not replaced - the same listener used
42b0214c4cd56e26a26c2bec61c287fc008ed3e551Etan Cohen     * at creation is still used. The results of the configuration are returned using
433de35a5e5573828838bfa6359a1ac1bf22b19303Etan Cohen     * {@link DiscoverySessionCallback}:
44b0214c4cd56e26a26c2bec61c287fc008ed3e551Etan Cohen     * <ul>
453de35a5e5573828838bfa6359a1ac1bf22b19303Etan Cohen     *     <li>{@link DiscoverySessionCallback#onSessionConfigUpdated()}: configuration
463855370c24b575e0943a9a3c146fda980cd71e24Etan Cohen     *     update succeeded.
473de35a5e5573828838bfa6359a1ac1bf22b19303Etan Cohen     *     <li>{@link DiscoverySessionCallback#onSessionConfigFailed()}: configuration
483855370c24b575e0943a9a3c146fda980cd71e24Etan Cohen     *     update failed. The publish discovery session is still running using its previous
49b0214c4cd56e26a26c2bec61c287fc008ed3e551Etan Cohen     *     configuration (i.e. update failure does not terminate the session).
50b0214c4cd56e26a26c2bec61c287fc008ed3e551Etan Cohen     * </ul>
5120d329b08df7d1a94e6caee781f09e812a79c913Etan Cohen     *
52b0214c4cd56e26a26c2bec61c287fc008ed3e551Etan Cohen     * @param publishConfig The new discovery publish session configuration ({@link PublishConfig}).
5320d329b08df7d1a94e6caee781f09e812a79c913Etan Cohen     */
545e680daad8096611c9bd2e4fc788d099089b09ccEtan Cohen    public void updatePublish(@NonNull PublishConfig publishConfig) {
55231859c2aa3930892a81b2d3cc368a79fbcfaed0Etan Cohen        if (mTerminated) {
5651181fb85d490b16fa3b8cff5ee3c906d148533bEtan Cohen            Log.w(TAG, "updatePublish: called on terminated session");
57231859c2aa3930892a81b2d3cc368a79fbcfaed0Etan Cohen            return;
58231859c2aa3930892a81b2d3cc368a79fbcfaed0Etan Cohen        } else {
590849ded00879dc05175c079011aa038c5ba0770aEtan Cohen            WifiAwareManager mgr = mMgr.get();
6051181fb85d490b16fa3b8cff5ee3c906d148533bEtan Cohen            if (mgr == null) {
610849ded00879dc05175c079011aa038c5ba0770aEtan Cohen                Log.w(TAG, "updatePublish: called post GC on WifiAwareManager");
6251181fb85d490b16fa3b8cff5ee3c906d148533bEtan Cohen                return;
6351181fb85d490b16fa3b8cff5ee3c906d148533bEtan Cohen            }
6451181fb85d490b16fa3b8cff5ee3c906d148533bEtan Cohen
65bd4bf35d22a04b0c5a39bdf6543cec0af9df2306Etan Cohen            mgr.updatePublish(mClientId, mSessionId, publishConfig);
66231859c2aa3930892a81b2d3cc368a79fbcfaed0Etan Cohen        }
6720d329b08df7d1a94e6caee781f09e812a79c913Etan Cohen    }
6820d329b08df7d1a94e6caee781f09e812a79c913Etan Cohen}
69