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.IntDef;
20 import android.annotation.NonNull;
21 import android.net.MacAddress;
22 
23 import java.lang.annotation.Retention;
24 import java.lang.annotation.RetentionPolicy;
25 /**
26  * Base class for Aware identity/cluster changes callbacks. Should be extended by applications and
27  * set when calling {@link WifiAwareManager#attach(AttachCallback, IdentityChangedListener,
28  * android.os.Handler)}. These are callbacks applying to the Aware connection as a whole - not to
29  * specific publish or subscribe sessions - for that see {@link DiscoverySessionCallback}.
30  */
31 public class IdentityChangedListener {
32     /** @hide */
33     @IntDef(prefix = {"CLUSTER_CHANGE_EVENT_"}, value = {
34         CLUSTER_CHANGE_EVENT_STARTED,
35         CLUSTER_CHANGE_EVENT_JOINED
36     })
37     @Retention(RetentionPolicy.SOURCE)
38     public @interface ClusterChangeEvent {}
39 
40     /**
41      * Wi-Fi Aware cluster change event type when starting a cluster.
42      */
43     public static final int CLUSTER_CHANGE_EVENT_STARTED = 0;
44     /**
45      * Wi-Fi Aware cluster change event type when joining a cluster.
46      */
47     public static final int CLUSTER_CHANGE_EVENT_JOINED = 1;
48 
49     /**
50      * Identity change may be due to device joining a cluster, starting a cluster, or discovery
51      * interface change (addresses are randomized at regular intervals). The implication is that
52      * peers you've been communicating with may no longer recognize you and you need to re-establish
53      * your identity - e.g. by starting a discovery session.
54      *
55      * @param mac The MAC address of the Aware discovery interface. The application must have the
56      * {@link android.Manifest.permission#ACCESS_FINE_LOCATION} to get the actual MAC address,
57      *            otherwise all 0's will be provided.
58      */
onIdentityChanged(byte[] mac)59     public void onIdentityChanged(byte[] mac) {
60         /* empty */
61     }
62 
63     /**
64      * Cluster ID changes could be trigger by either cluster started event or cluster joined event.
65      * @param clusterEventType The type of events that triggered the change of the cluster ID.
66      * @param clusterId The cluster id that the device just joined.
67      */
onClusterIdChanged(@lusterChangeEvent int clusterEventType, @NonNull MacAddress clusterId)68     public void onClusterIdChanged(@ClusterChangeEvent int clusterEventType,
69             @NonNull MacAddress clusterId) {
70         /* empty */
71     }
72 }
73