1 /*
2  * Copyright (C) 2016 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 android.net.wifi.aware;
18 
19 import android.annotation.NonNull;
20 import android.util.Log;
21 
22 /**
23  * A class representing a Aware subscribe session. Created when
24  * {@link WifiAwareSession#subscribe(SubscribeConfig,
25  * DiscoverySessionCallback, android.os.Handler)}
26  * is called and a discovery session is created and returned in
27  * {@link DiscoverySessionCallback#onSubscribeStarted(SubscribeDiscoverySession)}.
28  * See baseline functionality of all discovery sessions in {@link DiscoverySession}.
29  * This object allows updating an existing/running subscribe discovery session using
30  * {@link #updateSubscribe(SubscribeConfig)}.
31  */
32 public class SubscribeDiscoverySession extends DiscoverySession {
33     private static final String TAG = "SubscribeDiscSession";
34 
35     /**
36      * {@hide}
37      */
SubscribeDiscoverySession(WifiAwareManager manager, int clientId, int sessionId)38     public SubscribeDiscoverySession(WifiAwareManager manager, int clientId,
39             int sessionId) {
40         super(manager, clientId, sessionId);
41     }
42 
43     /**
44      * Re-configure the currently active subscribe session. The
45      * {@link DiscoverySessionCallback} is not replaced - the same listener used
46      * at creation is still used. The results of the configuration are returned using
47      * {@link DiscoverySessionCallback}:
48      * <ul>
49      *     <li>{@link DiscoverySessionCallback#onSessionConfigUpdated()}: configuration
50      *     update succeeded.
51      *     <li>{@link DiscoverySessionCallback#onSessionConfigFailed()}: configuration
52      *     update failed. The subscribe discovery session is still running using its previous
53      *     configuration (i.e. update failure does not terminate the session).
54      * </ul>
55      *
56      * @param subscribeConfig The new discovery subscribe session configuration
57      *                        ({@link SubscribeConfig}).
58      */
updateSubscribe(@onNull SubscribeConfig subscribeConfig)59     public void updateSubscribe(@NonNull SubscribeConfig subscribeConfig) {
60         if (mTerminated) {
61             Log.w(TAG, "updateSubscribe: called on terminated session");
62             return;
63         } else {
64             WifiAwareManager mgr = mMgr.get();
65             if (mgr == null) {
66                 Log.w(TAG, "updateSubscribe: called post GC on WifiAwareManager");
67                 return;
68             }
69 
70             mgr.updateSubscribe(mClientId, mSessionId, subscribeConfig);
71         }
72     }
73 }
74