1 /* 2 * Copyright (C) 2018 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; 18 19 import android.annotation.IntDef; 20 import android.annotation.SystemApi; 21 import android.os.Handler; 22 23 import java.lang.annotation.Retention; 24 import java.lang.annotation.RetentionPolicy; 25 26 /** 27 * Easy Connect (DPP) Status Callback. Use this callback to get status updates (success, failure, 28 * progress) from the Easy Connect operation started with 29 * {@link WifiManager#startEasyConnectAsConfiguratorInitiator(String, 30 * int, int, Handler, EasyConnectStatusCallback)} or 31 * {@link WifiManager#startEasyConnectAsEnrolleeInitiator(String, 32 * Handler, EasyConnectStatusCallback)} 33 * 34 * @hide 35 */ 36 @SystemApi 37 public abstract class EasyConnectStatusCallback { 38 /** 39 * Easy Connect Success event: Configuration sent (Configurator mode). 40 */ 41 public static final int EASY_CONNECT_EVENT_SUCCESS_CONFIGURATION_SENT = 0; 42 43 /** @hide */ 44 @IntDef(prefix = {"EASY_CONNECT_EVENT_SUCCESS_"}, value = { 45 EASY_CONNECT_EVENT_SUCCESS_CONFIGURATION_SENT, 46 }) 47 @Retention(RetentionPolicy.SOURCE) 48 public @interface EasyConnectSuccessStatusCode { 49 } 50 51 /** 52 * Easy Connect Progress event: Initial authentication with peer succeeded. 53 */ 54 public static final int EASY_CONNECT_EVENT_PROGRESS_AUTHENTICATION_SUCCESS = 0; 55 56 /** 57 * Easy Connect Progress event: Peer requires more time to process bootstrapping. 58 */ 59 public static final int EASY_CONNECT_EVENT_PROGRESS_RESPONSE_PENDING = 1; 60 61 /** @hide */ 62 @IntDef(prefix = {"EASY_CONNECT_EVENT_PROGRESS_"}, value = { 63 EASY_CONNECT_EVENT_PROGRESS_AUTHENTICATION_SUCCESS, 64 EASY_CONNECT_EVENT_PROGRESS_RESPONSE_PENDING, 65 }) 66 @Retention(RetentionPolicy.SOURCE) 67 public @interface EasyConnectProgressStatusCode { 68 } 69 70 /** 71 * Easy Connect Failure event: Scanned QR code is either not a Easy Connect URI, or the Easy 72 * Connect URI has errors. 73 */ 74 public static final int EASY_CONNECT_EVENT_FAILURE_INVALID_URI = -1; 75 76 /** 77 * Easy Connect Failure event: Bootstrapping/Authentication initialization process failure. 78 */ 79 public static final int EASY_CONNECT_EVENT_FAILURE_AUTHENTICATION = -2; 80 81 /** 82 * Easy Connect Failure event: Both devices are implementing the same role and are incompatible. 83 */ 84 public static final int EASY_CONNECT_EVENT_FAILURE_NOT_COMPATIBLE = -3; 85 86 /** 87 * Easy Connect Failure event: Configuration process has failed due to malformed message. 88 */ 89 public static final int EASY_CONNECT_EVENT_FAILURE_CONFIGURATION = -4; 90 91 /** 92 * Easy Connect Failure event: Easy Connect request while in another Easy Connect exchange. 93 */ 94 public static final int EASY_CONNECT_EVENT_FAILURE_BUSY = -5; 95 96 /** 97 * Easy Connect Failure event: No response from the peer. 98 */ 99 public static final int EASY_CONNECT_EVENT_FAILURE_TIMEOUT = -6; 100 101 /** 102 * Easy Connect Failure event: General protocol failure. 103 */ 104 public static final int EASY_CONNECT_EVENT_FAILURE_GENERIC = -7; 105 106 /** 107 * Easy Connect Failure event: Feature or option is not supported. 108 */ 109 public static final int EASY_CONNECT_EVENT_FAILURE_NOT_SUPPORTED = -8; 110 111 /** 112 * Easy Connect Failure event: Invalid network provided to Easy Connect configurator. 113 * Network must either be WPA3-Personal (SAE) or WPA2-Personal (PSK). 114 */ 115 public static final int EASY_CONNECT_EVENT_FAILURE_INVALID_NETWORK = -9; 116 117 118 /** @hide */ 119 @IntDef(prefix = {"EASY_CONNECT_EVENT_FAILURE_"}, value = { 120 EASY_CONNECT_EVENT_FAILURE_INVALID_URI, 121 EASY_CONNECT_EVENT_FAILURE_AUTHENTICATION, 122 EASY_CONNECT_EVENT_FAILURE_NOT_COMPATIBLE, 123 EASY_CONNECT_EVENT_FAILURE_CONFIGURATION, 124 EASY_CONNECT_EVENT_FAILURE_BUSY, 125 EASY_CONNECT_EVENT_FAILURE_TIMEOUT, 126 EASY_CONNECT_EVENT_FAILURE_GENERIC, 127 EASY_CONNECT_EVENT_FAILURE_NOT_SUPPORTED, 128 EASY_CONNECT_EVENT_FAILURE_INVALID_NETWORK, 129 }) 130 @Retention(RetentionPolicy.SOURCE) 131 public @interface EasyConnectFailureStatusCode { 132 } 133 134 /** 135 * Called when local Easy Connect Enrollee successfully receives a new Wi-Fi configuration from 136 * the 137 * peer Easy Connect configurator. This callback marks the successful end of the Easy Connect 138 * current Easy Connect 139 * session, and no further callbacks will be called. This callback is the successful outcome 140 * of a Easy Connect flow starting with 141 * {@link WifiManager#startEasyConnectAsEnrolleeInitiator(String, 142 * Handler, 143 * EasyConnectStatusCallback)}. 144 * 145 * @param newNetworkId New Wi-Fi configuration with a network ID received from the configurator 146 */ onEnrolleeSuccess(int newNetworkId)147 public abstract void onEnrolleeSuccess(int newNetworkId); 148 149 /** 150 * Called when a Easy Connect success event takes place, except for when configuration is 151 * received from 152 * an external Configurator. The callback onSuccessConfigReceived will be used in this case. 153 * This callback marks the successful end of the current Easy Connect session, and no further 154 * callbacks will be called. This callback is the successful outcome of a Easy Connect flow 155 * starting with 156 * {@link WifiManager#startEasyConnectAsConfiguratorInitiator(String, int, int, Handler, 157 * EasyConnectStatusCallback)}. 158 * 159 * @param code Easy Connect success status code. 160 */ onConfiguratorSuccess(@asyConnectSuccessStatusCode int code)161 public abstract void onConfiguratorSuccess(@EasyConnectSuccessStatusCode int code); 162 163 /** 164 * Called when a Easy Connect Failure event takes place. This callback marks the unsuccessful 165 * end of the 166 * current Easy Connect session, and no further callbacks will be called. 167 * 168 * @param code Easy Connect failure status code. 169 */ onFailure(@asyConnectFailureStatusCode int code)170 public abstract void onFailure(@EasyConnectFailureStatusCode int code); 171 172 /** 173 * Called when Easy Connect events that indicate progress take place. Can be used by UI elements 174 * to show progress. 175 * 176 * @param code Easy Connect progress status code. 177 */ onProgress(@asyConnectProgressStatusCode int code)178 public abstract void onProgress(@EasyConnectProgressStatusCode int code); 179 } 180