17
17
import android .content .Intent ;
18
18
import android .os .Bundle ;
19
19
20
- import com .espressif .avs .ConfigureAVS ;
21
20
import com .espressif .provision .security .Security ;
22
21
import com .espressif .provision .session .Session ;
23
22
import com .espressif .provision .transport .ResponseListener ;
24
23
import com .espressif .provision .transport .Transport ;
25
- import com .espressif .ui .BLEProvisionLanding ;
26
- import com .espressif .ui .LoginWithAmazon ;
27
- import com .espressif .ui .ProvisionLanding ;
24
+ import com .espressif .ui .activities .BLEProvisionLanding ;
25
+ import com .espressif .ui .activities .ProvisionLanding ;
28
26
import com .google .protobuf .ByteString ;
29
27
import com .google .protobuf .InvalidProtocolBufferException ;
30
28
34
32
import espressif .Constants ;
35
33
import espressif .WifiConfig ;
36
34
import espressif .WifiConstants ;
37
- import espressif .WifiScan ;
38
35
39
36
import static java .lang .Thread .sleep ;
40
37
@@ -68,6 +65,7 @@ public class Provision {
68
65
* Initialize Provision class with a Session object.
69
66
* Session object should already have been
70
67
* successfully initialized by calling Session.init.
68
+ *
71
69
* @param session
72
70
*/
73
71
public Provision (Session session ) {
@@ -81,22 +79,23 @@ public Provision(Session session) {
81
79
* This UI will take the user through the following flow
82
80
* 1. Connect to the device via Wifi (AP) or Bluetooth (BLE)
83
81
* 2. Provide Network information like SSID and Passphrase
82
+ *
84
83
* @param activity parent activity which is typically part of the App
85
- * @param config Config dictionary.
86
- * Currently supported configurations are
87
- * HashMap<String, String> config = new HashMap<>();
88
- * config.put(Provision.CONFIG_TRANSPORT_KEY, transportVersion);
89
- * config.put(Provision.CONFIG_SECURITY_KEY, securityVersion);
90
- * config.put(Provision.CONFIG_PROOF_OF_POSSESSION_KEY, POP);
91
- * config.put(Provision.CONFIG_BASE_URL_KEY, BASE_URL);
92
- * config.put(Provision.CONFIG_WIFI_AP_KEY, NETWORK_NAME_PREFIX);
93
- * config.put(BLETransport.SERVICE_UUID_KEY, SERVICE_UUID);
94
- * config.put(BLETransport.SESSION_UUID_KEY, SESSION_UUID);
95
- * config.put(BLETransport.CONFIG_UUID_KEY, CONFIG_UUID);
96
- * config.put(BLETransport.DEVICE_NAME_PREFIX_KEY, DEVICE_NAME_PREFIX);
84
+ * @param config Config dictionary.
85
+ * Currently supported configurations are
86
+ * HashMap<String, String> config = new HashMap<>();
87
+ * config.put(Provision.CONFIG_TRANSPORT_KEY, transportVersion);
88
+ * config.put(Provision.CONFIG_SECURITY_KEY, securityVersion);
89
+ * config.put(Provision.CONFIG_PROOF_OF_POSSESSION_KEY, POP);
90
+ * config.put(Provision.CONFIG_BASE_URL_KEY, BASE_URL);
91
+ * config.put(Provision.CONFIG_WIFI_AP_KEY, NETWORK_NAME_PREFIX);
92
+ * config.put(BLETransport.SERVICE_UUID_KEY, SERVICE_UUID);
93
+ * config.put(BLETransport.SESSION_UUID_KEY, SESSION_UUID);
94
+ * config.put(BLETransport.CONFIG_UUID_KEY, CONFIG_UUID);
95
+ * config.put(BLETransport.DEVICE_NAME_PREFIX_KEY, DEVICE_NAME_PREFIX);
97
96
*/
98
- public static void showProvisioningUI (Activity activity ,
99
- HashMap <String , String > config ) {
97
+ public static void showProvisioningUI (Activity activity ,
98
+ HashMap <String , String > config ) {
100
99
final String transportVersion = config .get (Provision .CONFIG_TRANSPORT_KEY );
101
100
Class landingActivity = ProvisionLanding .class ;
102
101
if (transportVersion .equals (Provision .CONFIG_TRANSPORT_BLE )) {
@@ -121,22 +120,22 @@ public static void showProvisioningUI (Activity activity,
121
120
* 3. Provide Network information like SSID and Passphrase
122
121
*
123
122
* @param activity parent activity which is typically part of the app
124
- // * @param productId product ID in the Alexa Voice Services project
125
- // * @param productDSN device serial number
126
- // * @param codeVerifier random value used as a code challenge. This should typically be sent to
127
- // * to received from the device to use in its communication with Alexa
128
- * @param config Config dictionary
129
- * Currently supported configurations are
130
- * HashMap<String, String> config = new HashMap<>();
131
- * config.put(Provision.CONFIG_TRANSPORT_KEY, transportVersion);
132
- * config.put(Provision.CONFIG_SECURITY_KEY, securityVersion);
133
- * config.put(Provision.CONFIG_PROOF_OF_POSSESSION_KEY, POP);
134
- * config.put(Provision.CONFIG_BASE_URL_KEY, BASE_URL);
135
- * config.put(Provision.CONFIG_WIFI_AP_KEY, NETWORK_NAME_PREFIX);
136
- * config.put(BLETransport.SERVICE_UUID_KEY, SERVICE_UUID);
137
- * config.put(BLETransport.SESSION_UUID_KEY, SESSION_UUID);
138
- * config.put(BLETransport.CONFIG_UUID_KEY, CONFIG_UUID);
139
- * config.put(BLETransport.DEVICE_NAME_PREFIX_KEY, DEVICE_NAME_PREFIX);
123
+ * // * @param productId product ID in the Alexa Voice Services project
124
+ * // * @param productDSN device serial number
125
+ * // * @param codeVerifier random value used as a code challenge. This should typically be sent to
126
+ * // * to received from the device to use in its communication with Alexa
127
+ * @param config Config dictionary
128
+ * Currently supported configurations are
129
+ * HashMap<String, String> config = new HashMap<>();
130
+ * config.put(Provision.CONFIG_TRANSPORT_KEY, transportVersion);
131
+ * config.put(Provision.CONFIG_SECURITY_KEY, securityVersion);
132
+ * config.put(Provision.CONFIG_PROOF_OF_POSSESSION_KEY, POP);
133
+ * config.put(Provision.CONFIG_BASE_URL_KEY, BASE_URL);
134
+ * config.put(Provision.CONFIG_WIFI_AP_KEY, NETWORK_NAME_PREFIX);
135
+ * config.put(BLETransport.SERVICE_UUID_KEY, SERVICE_UUID);
136
+ * config.put(BLETransport.SESSION_UUID_KEY, SESSION_UUID);
137
+ * config.put(BLETransport.CONFIG_UUID_KEY, CONFIG_UUID);
138
+ * config.put(BLETransport.DEVICE_NAME_PREFIX_KEY, DEVICE_NAME_PREFIX);
140
139
*/
141
140
public static void showProvisioningWithAmazonUI (Activity activity ,
142
141
// String productId,
@@ -162,14 +161,15 @@ public static void showProvisioningWithAmazonUI(Activity activity,
162
161
/**
163
162
* Send Configuration information relating to the Home
164
163
* Wifi network which the device should use for Internet access
165
- * @param ssid ssid of the home network
166
- * @param passphrase passphrase
164
+ *
165
+ * @param ssid ssid of the home network
166
+ * @param passphrase passphrase
167
167
* @param actionListener listener to be called when config data is sent
168
168
*/
169
169
public void configureWifi (final String ssid ,
170
170
final String passphrase ,
171
171
final ProvisionActionListener actionListener ) {
172
- if (session .isEstablished ()) {
172
+ if (session .isEstablished ()) {
173
173
byte [] message = createSetWifiConfigRequest (ssid , passphrase );
174
174
transport .sendConfigData (PROVISIONING_CONFIG_PATH , message , new ResponseListener () {
175
175
@ Override
@@ -178,17 +178,17 @@ public void onSuccess(byte[] returnData) {
178
178
if (status != Constants .Status .Success && provisioningListener != null ) {
179
179
provisioningListener .OnProvisioningFailed (new RuntimeException ("Could not sent wifi credentials to device" ));
180
180
}
181
- if (actionListener != null ) {
181
+ if (actionListener != null ) {
182
182
actionListener .onComplete (status , null );
183
183
}
184
184
}
185
185
186
186
@ Override
187
187
public void onFailure (Exception e ) {
188
- if (provisioningListener != null ) {
188
+ if (provisioningListener != null ) {
189
189
provisioningListener .OnProvisioningFailed (e );
190
190
}
191
- if (actionListener != null ) {
191
+ if (actionListener != null ) {
192
192
actionListener .onComplete (Constants .Status .InternalError , e );
193
193
}
194
194
}
@@ -201,10 +201,11 @@ public void onFailure(Exception e) {
201
201
* A typical flow will be
202
202
* Initialize session -> Set config (1 or more times) -> Apply config
203
203
* This API call will also start a poll for getting Wifi connection status from the device
204
+ *
204
205
* @param actionListener listener to be called when apply config message is sent
205
206
*/
206
207
public void applyConfigurations (final ProvisionActionListener actionListener ) {
207
- if (session .isEstablished ()) {
208
+ if (session .isEstablished ()) {
208
209
byte [] message = createApplyConfigRequest ();
209
210
transport .sendConfigData (PROVISIONING_CONFIG_PATH , message , new ResponseListener () {
210
211
@ Override
@@ -231,7 +232,7 @@ public void onWifiStateUpdated(WifiConstants.WifiStationState stationState,
231
232
provisioningListener .OnApplyConfigurationsFailed ();
232
233
}
233
234
}
234
- if (actionListener != null ) {
235
+ if (actionListener != null ) {
235
236
actionListener .onComplete (status , null );
236
237
}
237
238
}
@@ -241,7 +242,7 @@ public void onFailure(Exception e) {
241
242
if (provisioningListener != null ) {
242
243
provisioningListener .OnApplyConfigurationsFailed ();
243
244
}
244
- if (actionListener != null ) {
245
+ if (actionListener != null ) {
245
246
actionListener .onComplete (Constants .Status .InternalError , e );
246
247
}
247
248
}
@@ -300,8 +301,8 @@ private Object[] processGetWifiConfigStatusResponse(byte[] responseData) {
300
301
WifiConstants .WifiStationState wifiStationState = WifiConstants .WifiStationState .Disconnected ;
301
302
WifiConstants .WifiConnectFailedReason failedReason = WifiConstants .WifiConnectFailedReason .UNRECOGNIZED ;
302
303
303
- if (responseData == null ) {
304
- return new Object [] { wifiStationState , failedReason };
304
+ if (responseData == null ) {
305
+ return new Object []{ wifiStationState , failedReason };
305
306
}
306
307
307
308
byte [] decryptedData = this .security .decrypt (responseData );
@@ -312,7 +313,7 @@ private Object[] processGetWifiConfigStatusResponse(byte[] responseData) {
312
313
} catch (InvalidProtocolBufferException e ) {
313
314
e .printStackTrace ();
314
315
}
315
- return new Object [] {wifiStationState , failedReason };
316
+ return new Object []{wifiStationState , failedReason };
316
317
}
317
318
318
319
private void pollForWifiConnectionStatus (final WifiStateListener wifiStateListener ) {
0 commit comments