4
4
import android .content .Intent ;
5
5
import android .graphics .Color ;
6
6
import android .os .Bundle ;
7
- import android .support .annotation .Nullable ;
8
- import android .support .v7 .app .AlertDialog ;
9
- import android .support .v7 .app .AppCompatActivity ;
10
- import android .support .v7 .widget .Toolbar ;
7
+
8
+ import androidx .annotation .Nullable ;
9
+ import androidx .appcompat .app .AlertDialog ;
10
+ import androidx .appcompat .app .AppCompatActivity ;
11
+ import androidx .appcompat .widget .Toolbar ;
12
+
11
13
import android .text .TextUtils ;
12
14
import android .util .Log ;
13
15
import android .view .LayoutInflater ;
22
24
import com .espressif .provision .R ;
23
25
import com .espressif .provision .security .Security ;
24
26
import com .espressif .provision .security .Security0 ;
27
+ import com .espressif .provision .security .Security1 ;
25
28
import com .espressif .provision .session .Session ;
26
29
import com .espressif .provision .transport .ResponseListener ;
27
30
import com .espressif .provision .transport .SoftAPTransport ;
@@ -54,6 +57,7 @@ public class DeviceActivity extends AppCompatActivity {
54
57
private DeviceInfo deviceInfo ;
55
58
private String deviceHostAddress ;
56
59
private String deviceName ;
60
+ private boolean isNewFw ;
57
61
58
62
private Session session ;
59
63
private Security security ;
@@ -70,6 +74,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
70
74
deviceHostAddress = intent .getStringExtra (LoginWithAmazon .KEY_HOST_ADDRESS );
71
75
deviceName = intent .getStringExtra (LoginWithAmazon .KEY_DEVICE_NAME );
72
76
deviceInfo = intent .getParcelableExtra (AppConstants .KEY_DEVICE_INFO );
77
+ isNewFw = deviceInfo .isNewFirmware ();
73
78
74
79
toolbar = findViewById (R .id .toolbar );
75
80
toolbar .setTitle (deviceName );
@@ -96,7 +101,11 @@ protected void onResume() {
96
101
super .onResume ();
97
102
98
103
transport = new SoftAPTransport (deviceHostAddress + ":80" );
99
- security = new Security0 ();
104
+ if (deviceInfo .isNewFirmware ()) {
105
+ security = new Security1 (getResources ().getString (R .string .proof_of_possesion ));
106
+ } else {
107
+ security = new Security0 ();
108
+ }
100
109
session = new Session (transport , security );
101
110
session .init (null );
102
111
@@ -169,7 +178,11 @@ public void onStopTrackingTouch(final SeekBar seekBar) {
169
178
170
179
Log .e (TAG , "onStopTrackingTouch : " + seekBar .getProgress ());
171
180
transport = new SoftAPTransport (deviceHostAddress + ":80" );
172
- security = new Security0 ();
181
+ if (deviceInfo .isNewFirmware ()) {
182
+ security = new Security1 (getResources ().getString (R .string .proof_of_possesion ));
183
+ } else {
184
+ security = new Security0 ();
185
+ }
173
186
session = new Session (transport , security );
174
187
session .init (null );
175
188
@@ -216,7 +229,7 @@ public void onClick(View v) {
216
229
217
230
Intent languageIntent = new Intent (DeviceActivity .this , LanguageListActivity .class );
218
231
languageIntent .putExtra (LoginWithAmazon .KEY_HOST_ADDRESS , deviceHostAddress );
219
- languageIntent .putExtra (AppConstants .KEY_DEVICE_LANGUAGE , deviceInfo . getLanguage () );
232
+ languageIntent .putExtra (AppConstants .KEY_DEVICE_INFO , deviceInfo );
220
233
startActivityForResult (languageIntent , REQUEST_CODE_LANGUAGE );
221
234
}
222
235
};
@@ -272,10 +285,18 @@ public void onClick(DialogInterface dialog, int which) {
272
285
if (TextUtils .isEmpty (newDeviceName )) {
273
286
Toast .makeText (DeviceActivity .this , R .string .error_device_name_empty , Toast .LENGTH_SHORT ).show ();
274
287
return ;
288
+ } else if (newDeviceName .contains ("::" )) {
289
+ String errMsg = "Please enter a valid name which does not contain ::" ;
290
+ Toast .makeText (DeviceActivity .this , errMsg , Toast .LENGTH_SHORT ).show ();
291
+ return ;
275
292
}
276
293
277
294
transport = new SoftAPTransport (deviceHostAddress + ":80" );
278
- security = new Security0 ();
295
+ if (deviceInfo .isNewFirmware ()) {
296
+ security = new Security1 (getResources ().getString (R .string .proof_of_possesion ));
297
+ } else {
298
+ security = new Security0 ();
299
+ }
279
300
session = new Session (transport , security );
280
301
session .init (null );
281
302
@@ -561,6 +582,7 @@ public void onSuccess(byte[] returnData) {
561
582
if (device != null ) {
562
583
563
584
deviceInfo = device ;
585
+ deviceInfo .setNewFirmware (isNewFw );
564
586
runOnUiThread (new Runnable () {
565
587
566
588
@ Override
@@ -612,6 +634,7 @@ private DeviceInfo processDeviceInfoResponse(byte[] responseData) {
612
634
deviceInfo .setEndToneEnabled (specificInfo .getEORAudioCue ());
613
635
deviceInfo .setVolume (specificInfo .getVolume ());
614
636
deviceInfo .setLanguage (specificInfo .getAssistantLangValue ());
637
+ deviceInfo .setNewFirmware (isNewFw );
615
638
}
616
639
617
640
} catch (InvalidProtocolBufferException e ) {
@@ -650,6 +673,7 @@ private void goToLoginActivity() {
650
673
alexaProvisioningIntent .putExtra (LoginWithAmazon .KEY_HOST_ADDRESS , deviceHostAddress );
651
674
alexaProvisioningIntent .putExtra (LoginWithAmazon .KEY_DEVICE_NAME , deviceName );
652
675
alexaProvisioningIntent .putExtra (LoginWithAmazon .KEY_IS_PROVISIONING , false );
676
+ alexaProvisioningIntent .putExtra (AppConstants .KEY_IS_NEW_FIRMWARE , deviceInfo .isNewFirmware ());
653
677
startActivity (alexaProvisioningIntent );
654
678
}
655
679
@@ -658,6 +682,7 @@ private void goToAlexaActivity() {
658
682
Intent alexaIntent = new Intent (getApplicationContext (), AlexaActivity .class );
659
683
alexaIntent .putExtra (LoginWithAmazon .KEY_HOST_ADDRESS , deviceHostAddress );
660
684
alexaIntent .putExtra (LoginWithAmazon .KEY_DEVICE_NAME , deviceName );
685
+ alexaIntent .putExtra (AppConstants .KEY_IS_NEW_FIRMWARE , deviceInfo .isNewFirmware ());
661
686
alexaIntent .putExtras (getIntent ());
662
687
startActivity (alexaIntent );
663
688
}
0 commit comments