|
4 | 4 | import android.content.Intent;
|
5 | 5 | import android.graphics.Color;
|
6 | 6 | import android.os.Bundle;
|
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 |
| - |
13 | 7 | import android.text.TextUtils;
|
14 | 8 | import android.util.Log;
|
15 | 9 | import android.view.LayoutInflater;
|
|
20 | 14 | import android.widget.TextView;
|
21 | 15 | import android.widget.Toast;
|
22 | 16 |
|
| 17 | +import androidx.annotation.Nullable; |
| 18 | +import androidx.appcompat.app.AlertDialog; |
| 19 | +import androidx.appcompat.app.AppCompatActivity; |
| 20 | +import androidx.appcompat.widget.Toolbar; |
| 21 | + |
23 | 22 | import com.espressif.AppConstants;
|
24 | 23 | import com.espressif.provision.R;
|
25 |
| -import com.espressif.provision.security.Security; |
26 |
| -import com.espressif.provision.security.Security0; |
27 |
| -import com.espressif.provision.security.Security1; |
28 |
| -import com.espressif.provision.session.Session; |
29 | 24 | import com.espressif.provision.transport.ResponseListener;
|
30 |
| -import com.espressif.provision.transport.SoftAPTransport; |
31 |
| -import com.espressif.provision.transport.Transport; |
32 | 25 | import com.espressif.ui.models.DeviceInfo;
|
33 | 26 | import com.google.protobuf.InvalidProtocolBufferException;
|
34 | 27 |
|
@@ -59,10 +52,6 @@ public class DeviceActivity extends AppCompatActivity {
|
59 | 52 | private String deviceName;
|
60 | 53 | private boolean isNewFw;
|
61 | 54 |
|
62 |
| - private Session session; |
63 |
| - private Security security; |
64 |
| - private Transport transport; |
65 |
| - |
66 | 55 | private boolean isAvsSignedIn = false;
|
67 | 56 |
|
68 | 57 | @Override
|
@@ -100,30 +89,7 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten
|
100 | 89 | protected void onResume() {
|
101 | 90 | super.onResume();
|
102 | 91 |
|
103 |
| - transport = new SoftAPTransport(deviceHostAddress + ":80"); |
104 |
| - if (deviceInfo.isNewFirmware()) { |
105 |
| - security = new Security1(getResources().getString(R.string.proof_of_possesion)); |
106 |
| - } else { |
107 |
| - security = new Security0(); |
108 |
| - } |
109 |
| - session = new Session(transport, security); |
110 |
| - session.init(null); |
111 |
| - |
112 |
| - session.sessionListener = new Session.SessionListener() { |
113 |
| - |
114 |
| - @Override |
115 |
| - public void OnSessionEstablished() { |
116 |
| - |
117 |
| - Log.d(TAG, "Session established"); |
118 |
| - getDeviceInfo(); |
119 |
| - } |
120 |
| - |
121 |
| - @Override |
122 |
| - public void OnSessionEstablishFailed(Exception e) { |
123 |
| - Log.d(TAG, "Session failed"); |
124 |
| - e.printStackTrace(); |
125 |
| - } |
126 |
| - }; |
| 92 | + getDeviceInfo(); |
127 | 93 | }
|
128 | 94 |
|
129 | 95 | private void initViews() {
|
@@ -177,29 +143,7 @@ public void onStartTrackingTouch(SeekBar seekBar) {
|
177 | 143 | public void onStopTrackingTouch(final SeekBar seekBar) {
|
178 | 144 |
|
179 | 145 | Log.e(TAG, "onStopTrackingTouch : " + seekBar.getProgress());
|
180 |
| - transport = new SoftAPTransport(deviceHostAddress + ":80"); |
181 |
| - if (deviceInfo.isNewFirmware()) { |
182 |
| - security = new Security1(getResources().getString(R.string.proof_of_possesion)); |
183 |
| - } else { |
184 |
| - security = new Security0(); |
185 |
| - } |
186 |
| - session = new Session(transport, security); |
187 |
| - session.init(null); |
188 |
| - |
189 |
| - session.sessionListener = new Session.SessionListener() { |
190 |
| - |
191 |
| - @Override |
192 |
| - public void OnSessionEstablished() { |
193 |
| - |
194 |
| - Log.d(TAG, "Session established"); |
195 |
| - changeVolume(seekBar.getProgress()); |
196 |
| - } |
197 |
| - |
198 |
| - @Override |
199 |
| - public void OnSessionEstablishFailed(Exception e) { |
200 |
| - Log.d(TAG, "Session failed"); |
201 |
| - } |
202 |
| - }; |
| 146 | + changeVolume(seekBar.getProgress()); |
203 | 147 | }
|
204 | 148 | };
|
205 | 149 |
|
@@ -291,30 +235,7 @@ public void onClick(DialogInterface dialog, int which) {
|
291 | 235 | return;
|
292 | 236 | }
|
293 | 237 |
|
294 |
| - transport = new SoftAPTransport(deviceHostAddress + ":80"); |
295 |
| - if (deviceInfo.isNewFirmware()) { |
296 |
| - security = new Security1(getResources().getString(R.string.proof_of_possesion)); |
297 |
| - } else { |
298 |
| - security = new Security0(); |
299 |
| - } |
300 |
| - session = new Session(transport, security); |
301 |
| - session.init(null); |
302 |
| - |
303 |
| - final String finalNewDeviceName = newDeviceName; |
304 |
| - session.sessionListener = new Session.SessionListener() { |
305 |
| - |
306 |
| - @Override |
307 |
| - public void OnSessionEstablished() { |
308 |
| - |
309 |
| - Log.d(TAG, "Session established"); |
310 |
| - setDeviceName(finalNewDeviceName); |
311 |
| - } |
312 |
| - |
313 |
| - @Override |
314 |
| - public void OnSessionEstablishFailed(Exception e) { |
315 |
| - Log.d(TAG, "Session failed"); |
316 |
| - } |
317 |
| - }; |
| 238 | + setDeviceName(newDeviceName); |
318 | 239 | }
|
319 | 240 | });
|
320 | 241 |
|
@@ -349,9 +270,9 @@ public void run() {
|
349 | 270 | .setCmdUserVisibleName(changeNameRequest)
|
350 | 271 | .build();
|
351 | 272 |
|
352 |
| - byte[] message = this.security.encrypt(payload.toByteArray()); |
| 273 | + byte[] message = ScanLocalDevices.security.encrypt(payload.toByteArray()); |
353 | 274 |
|
354 |
| - this.transport.sendConfigData(AppConstants.HANDLER_AVS_CONFIG, message, new ResponseListener() { |
| 275 | + ScanLocalDevices.transport.sendConfigData(AppConstants.HANDLER_AVS_CONFIG, message, new ResponseListener() { |
355 | 276 |
|
356 | 277 | @Override
|
357 | 278 | public void onSuccess(byte[] returnData) {
|
@@ -391,7 +312,7 @@ public void onFailure(Exception e) {
|
391 | 312 | private Avsconfig.AVSConfigStatus processDeviceNameChangeResponse(byte[] responseData) {
|
392 | 313 |
|
393 | 314 | Avsconfig.AVSConfigStatus status = Avsconfig.AVSConfigStatus.InvalidState;
|
394 |
| - byte[] decryptedData = this.security.decrypt(responseData); |
| 315 | + byte[] decryptedData = ScanLocalDevices.security.decrypt(responseData); |
395 | 316 |
|
396 | 317 | try {
|
397 | 318 |
|
@@ -427,8 +348,8 @@ public void run() {
|
427 | 348 | .setCmdSetVolume(volumeChangeRequest)
|
428 | 349 | .build();
|
429 | 350 |
|
430 |
| - byte[] message = this.security.encrypt(payload.toByteArray()); |
431 |
| - this.transport.sendConfigData(AppConstants.HANDLER_AVS_CONFIG, message, new ResponseListener() { |
| 351 | + byte[] message = ScanLocalDevices.security.encrypt(payload.toByteArray()); |
| 352 | + ScanLocalDevices.transport.sendConfigData(AppConstants.HANDLER_AVS_CONFIG, message, new ResponseListener() { |
432 | 353 |
|
433 | 354 | @Override
|
434 | 355 | public void onSuccess(byte[] returnData) {
|
@@ -463,7 +384,7 @@ public void onFailure(Exception e) {
|
463 | 384 | private Avsconfig.AVSConfigStatus processVolumeChangeResponse(byte[] responseData) {
|
464 | 385 |
|
465 | 386 | Avsconfig.AVSConfigStatus status = Avsconfig.AVSConfigStatus.InvalidState;
|
466 |
| - byte[] decryptedData = this.security.decrypt(responseData); |
| 387 | + byte[] decryptedData = ScanLocalDevices.security.decrypt(responseData); |
467 | 388 |
|
468 | 389 | try {
|
469 | 390 |
|
@@ -498,9 +419,9 @@ public void run() {
|
498 | 419 | .setMsg(msgType)
|
499 | 420 | .setCmdSigninStatus(configRequest)
|
500 | 421 | .build();
|
501 |
| - byte[] message = this.security.encrypt(payload.toByteArray()); |
| 422 | + byte[] message = ScanLocalDevices.security.encrypt(payload.toByteArray()); |
502 | 423 |
|
503 |
| - this.transport.sendConfigData(AppConstants.HANDLER_AVS_CONFIG, message, new ResponseListener() { |
| 424 | + ScanLocalDevices.transport.sendConfigData(AppConstants.HANDLER_AVS_CONFIG, message, new ResponseListener() { |
504 | 425 |
|
505 | 426 | @Override
|
506 | 427 | public void onSuccess(byte[] returnData) {
|
@@ -535,7 +456,7 @@ public void onFailure(Exception e) {
|
535 | 456 | private Avsconfig.AVSConfigStatus processSignInStatusResponse(byte[] responseData) {
|
536 | 457 |
|
537 | 458 | Avsconfig.AVSConfigStatus status = Avsconfig.AVSConfigStatus.InvalidState;
|
538 |
| - byte[] decryptedData = this.security.decrypt(responseData); |
| 459 | + byte[] decryptedData = ScanLocalDevices.security.decrypt(responseData); |
539 | 460 |
|
540 | 461 | try {
|
541 | 462 |
|
@@ -571,9 +492,9 @@ public void run() {
|
571 | 492 | .setCmdGetDeviceInfo(deviceInfoRequest)
|
572 | 493 | .build();
|
573 | 494 |
|
574 |
| - byte[] message = this.security.encrypt(payload.toByteArray()); |
| 495 | + byte[] message = ScanLocalDevices.security.encrypt(payload.toByteArray()); |
575 | 496 |
|
576 |
| - this.transport.sendConfigData(AppConstants.HANDLER_AVS_CONFIG, message, new ResponseListener() { |
| 497 | + ScanLocalDevices.transport.sendConfigData(AppConstants.HANDLER_AVS_CONFIG, message, new ResponseListener() { |
577 | 498 |
|
578 | 499 | @Override
|
579 | 500 | public void onSuccess(byte[] returnData) {
|
@@ -610,7 +531,7 @@ public void onFailure(Exception e) {
|
610 | 531 |
|
611 | 532 | private DeviceInfo processDeviceInfoResponse(byte[] responseData) {
|
612 | 533 |
|
613 |
| - byte[] decryptedData = this.security.decrypt(responseData); |
| 534 | + byte[] decryptedData = ScanLocalDevices.security.decrypt(responseData); |
614 | 535 | DeviceInfo deviceInfo = null;
|
615 | 536 |
|
616 | 537 | try {
|
|
0 commit comments