Home | History | Annotate | Download | only in aware
      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 publish session. Created when
     24  * {@link WifiAwareSession#publish(PublishConfig, DiscoverySessionCallback,
     25  * android.os.Handler)} is called and a discovery session is created and returned in
     26  * {@link DiscoverySessionCallback#onPublishStarted(PublishDiscoverySession)}. See
     27  * baseline functionality of all discovery sessions in {@link DiscoverySession}. This
     28  * object allows updating an existing/running publish discovery session using
     29  * {@link #updatePublish(PublishConfig)}.
     30  */
     31 public class PublishDiscoverySession extends DiscoverySession {
     32     private static final String TAG = "PublishDiscoverySession";
     33 
     34     /** @hide */
     35     public PublishDiscoverySession(WifiAwareManager manager, int clientId, int sessionId) {
     36         super(manager, clientId, sessionId);
     37     }
     38 
     39     /**
     40      * Re-configure the currently active publish session. The
     41      * {@link DiscoverySessionCallback} is not replaced - the same listener used
     42      * at creation is still used. The results of the configuration are returned using
     43      * {@link DiscoverySessionCallback}:
     44      * <ul>
     45      *     <li>{@link DiscoverySessionCallback#onSessionConfigUpdated()}: configuration
     46      *     update succeeded.
     47      *     <li>{@link DiscoverySessionCallback#onSessionConfigFailed()}: configuration
     48      *     update failed. The publish discovery session is still running using its previous
     49      *     configuration (i.e. update failure does not terminate the session).
     50      * </ul>
     51      *
     52      * @param publishConfig The new discovery publish session configuration ({@link PublishConfig}).
     53      */
     54     public void updatePublish(@NonNull PublishConfig publishConfig) {
     55         if (mTerminated) {
     56             Log.w(TAG, "updatePublish: called on terminated session");
     57             return;
     58         } else {
     59             WifiAwareManager mgr = mMgr.get();
     60             if (mgr == null) {
     61                 Log.w(TAG, "updatePublish: called post GC on WifiAwareManager");
     62                 return;
     63             }
     64 
     65             mgr.updatePublish(mClientId, mSessionId, publishConfig);
     66         }
     67     }
     68 }
     69