Skip to content

Commit 214e5ec

Browse files
committed
Merge branch 'bugfix/prov_crash' into 'master'
Bug fixes and improvements. See merge request idf/esp-idf-provisioning-android!36
2 parents 7a05d54 + 694b2c5 commit 214e5ec

File tree

14 files changed

+250
-56
lines changed

14 files changed

+250
-56
lines changed

app/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ android {
1818
minSdkVersion 23
1919
targetSdkVersion 29
2020
versionCode 6
21-
versionName "2.0.1 - ${getGitHash()}"
21+
versionName "2.0.2 - ${getGitHash()}"
2222
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
2323
}
2424

app/src/main/java/com/espressif/AppConstants.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class AppConstants {
3030

3131
public static final String ESP_PREFERENCES = "Esp_Preferences";
3232

33-
public static final String DEVICE_TYPE_SOFTAP = "wifi";
33+
public static final String DEVICE_TYPE_SOFTAP = "softap";
3434
public static final String DEVICE_TYPE_BLE = "ble";
3535
public static final String DEVICE_TYPE_BOTH = "both";
3636
public static final String DEVICE_TYPE_DEFAULT = DEVICE_TYPE_BOTH;

app/src/main/java/com/espressif/ui/activities/AddDeviceActivity.java

+85-24
Original file line numberDiff line numberDiff line change
@@ -356,38 +356,68 @@ public void run() {
356356
}
357357

358358
@Override
359-
public void deviceDetected(ESPDevice device) {
359+
public void deviceDetected(final ESPDevice device) {
360360

361361
Log.e(TAG, "Device detected");
362362
espDevice = device;
363-
if (ActivityCompat.checkSelfPermission(AddDeviceActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
364-
Log.e(TAG, "Location Permission not granted.");
365-
return;
366-
}
363+
final String deviceType = sharedPreferences.getString(AppConstants.KEY_DEVICE_TYPES, AppConstants.DEVICE_TYPE_DEFAULT);
367364

368-
String deviceType = sharedPreferences.getString(AppConstants.KEY_DEVICE_TYPES, AppConstants.DEVICE_TYPE_DEFAULT);
365+
runOnUiThread(new Runnable() {
369366

370-
if (deviceType.equals(AppConstants.DEVICE_TYPE_BLE)) {
367+
@Override
368+
public void run() {
371369

372-
if (espDevice != null && espDevice.getTransportType().equals(ESPConstants.TransportType.TRANSPORT_SOFTAP)) {
370+
if (ActivityCompat.checkSelfPermission(AddDeviceActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
371+
Log.e(TAG, "Location Permission not granted.");
372+
return;
373+
}
373374

374-
Toast.makeText(AddDeviceActivity.this, "Error! Device not supported", Toast.LENGTH_LONG).show();
375-
finish();
376-
} else {
377-
device.connectToDevice();
378-
}
379-
} else if (deviceType.equals(AppConstants.DEVICE_TYPE_SOFTAP)) {
375+
if (deviceType.equals(AppConstants.DEVICE_TYPE_BLE)) {
380376

381-
if (espDevice != null && espDevice.getTransportType().equals(ESPConstants.TransportType.TRANSPORT_BLE)) {
377+
if (espDevice != null && espDevice.getTransportType().equals(ESPConstants.TransportType.TRANSPORT_SOFTAP)) {
382378

383-
Toast.makeText(AddDeviceActivity.this, "Error! Device not supported", Toast.LENGTH_LONG).show();
384-
finish();
385-
} else {
386-
device.connectToDevice();
379+
Toast.makeText(AddDeviceActivity.this, "Error! Device not supported", Toast.LENGTH_LONG).show();
380+
finish();
381+
} else {
382+
device.connectToDevice();
383+
}
384+
} else if (deviceType.equals(AppConstants.DEVICE_TYPE_SOFTAP)) {
385+
386+
if (espDevice != null && espDevice.getTransportType().equals(ESPConstants.TransportType.TRANSPORT_BLE)) {
387+
388+
Toast.makeText(AddDeviceActivity.this, "Error! Device not supported", Toast.LENGTH_LONG).show();
389+
finish();
390+
} else {
391+
392+
if (espDevice.getTransportType().equals(ESPConstants.TransportType.TRANSPORT_SOFTAP)
393+
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
394+
395+
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
396+
397+
if (!wifiManager.isWifiEnabled()) {
398+
alertForWiFi();
399+
return;
400+
}
401+
}
402+
403+
device.connectToDevice();
404+
}
405+
} else {
406+
407+
if (espDevice.getTransportType().equals(ESPConstants.TransportType.TRANSPORT_SOFTAP)
408+
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
409+
410+
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
411+
412+
if (!wifiManager.isWifiEnabled()) {
413+
alertForWiFi();
414+
return;
415+
}
416+
}
417+
device.connectToDevice();
418+
}
387419
}
388-
} else {
389-
device.connectToDevice();
390-
}
420+
});
391421
}
392422

393423
@Override
@@ -421,6 +451,37 @@ private void goToProvisionActivity() {
421451
startActivity(provisionIntent);
422452
}
423453

454+
private void alertForWiFi() {
455+
456+
AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.AlertDialogTheme);
457+
builder.setCancelable(false);
458+
builder.setMessage(R.string.error_wifi_off);
459+
460+
// Set up the buttons
461+
builder.setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {
462+
463+
@Override
464+
public void onClick(DialogInterface dialog, int which) {
465+
466+
dialog.dismiss();
467+
espDevice = null;
468+
hideLoading();
469+
if (codeScanner != null) {
470+
codeScanner.releaseResources();
471+
codeScanner.startPreview();
472+
if (ActivityCompat.checkSelfPermission(AddDeviceActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
473+
&& ActivityCompat.checkSelfPermission(AddDeviceActivity.this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) {
474+
provisionManager.scanQRCode(codeScanner, qrCodeScanListener);
475+
} else {
476+
Log.e(TAG, "Permissions are not granted");
477+
}
478+
}
479+
}
480+
});
481+
482+
builder.show();
483+
}
484+
424485
private void askForManualDeviceConnection() {
425486

426487
AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.AlertDialogTheme);
@@ -492,7 +553,7 @@ private void startProvisioningFlow() {
492553

493554
} else {
494555

495-
final String[] deviceTypes = {"BLE", "Wi-Fi"};
556+
final String[] deviceTypes = {"BLE", "SoftAP"};
496557
AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.AlertDialogTheme);
497558
builder.setCancelable(true);
498559
builder.setTitle(R.string.dialog_msg_device_selection);
@@ -550,7 +611,7 @@ private void goToWiFiProvisionLandingActivity(int securityType) {
550611
wifiProvisioningIntent.putExtra(AppConstants.KEY_DEVICE_NAME, espDevice.getDeviceName());
551612
wifiProvisioningIntent.putExtra(AppConstants.KEY_PROOF_OF_POSSESSION, espDevice.getProofOfPossession());
552613
}
553-
getApplicationContext().startActivity(wifiProvisioningIntent);
614+
startActivity(wifiProvisioningIntent);
554615
}
555616

556617
private String getWifiSsid() {

app/src/main/java/com/espressif/ui/activities/EspMainActivity.java

+26-4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import android.view.Menu;
3232
import android.view.MenuItem;
3333
import android.view.View;
34+
import android.widget.ImageView;
3435
import android.widget.TextView;
3536
import android.widget.Toast;
3637

@@ -55,6 +56,7 @@ public class EspMainActivity extends AppCompatActivity {
5556

5657
private ESPProvisionManager provisionManager;
5758
private CardView btnAddDevice;
59+
private ImageView ivEsp;
5860
private SharedPreferences sharedPreferences;
5961
private String deviceType;
6062

@@ -71,6 +73,27 @@ protected void onCreate(Bundle savedInstanceState) {
7173
provisionManager = ESPProvisionManager.getInstance(getApplicationContext());
7274
}
7375

76+
@Override
77+
protected void onResume() {
78+
super.onResume();
79+
80+
deviceType = sharedPreferences.getString(AppConstants.KEY_DEVICE_TYPES, AppConstants.DEVICE_TYPE_DEFAULT);
81+
if (deviceType.equals("wifi")) {
82+
SharedPreferences.Editor editor = sharedPreferences.edit();
83+
editor.putString(AppConstants.KEY_DEVICE_TYPES, AppConstants.DEVICE_TYPE_DEFAULT);
84+
editor.apply();
85+
}
86+
87+
deviceType = sharedPreferences.getString(AppConstants.KEY_DEVICE_TYPES, AppConstants.DEVICE_TYPE_DEFAULT);
88+
if (deviceType.equals(AppConstants.DEVICE_TYPE_BLE)) {
89+
ivEsp.setImageResource(R.drawable.ic_esp_ble);
90+
} else if (deviceType.equals(AppConstants.DEVICE_TYPE_SOFTAP)) {
91+
ivEsp.setImageResource(R.drawable.ic_esp_softap);
92+
} else {
93+
ivEsp.setImageResource(R.drawable.ic_esp);
94+
}
95+
}
96+
7497
@Override
7598
public boolean onCreateOptionsMenu(Menu menu) {
7699

@@ -121,6 +144,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
121144

122145
private void initViews() {
123146

147+
ivEsp = findViewById(R.id.iv_esp);
124148
btnAddDevice = findViewById(R.id.btn_provision_device);
125149
btnAddDevice.findViewById(R.id.iv_arrow).setVisibility(View.GONE);
126150
btnAddDevice.setOnClickListener(addDeviceBtnClickListener);
@@ -162,8 +186,6 @@ private void addDeviceClick() {
162186

163187
} else {
164188

165-
deviceType = sharedPreferences.getString(AppConstants.KEY_DEVICE_TYPES, AppConstants.DEVICE_TYPE_DEFAULT);
166-
167189
if (deviceType.equals(AppConstants.DEVICE_TYPE_BLE) || deviceType.equals(AppConstants.DEVICE_TYPE_BOTH)) {
168190

169191
final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
@@ -183,7 +205,7 @@ private void addDeviceClick() {
183205

184206
private void startProvisioningFlow() {
185207

186-
String deviceType = sharedPreferences.getString(AppConstants.KEY_DEVICE_TYPES, AppConstants.DEVICE_TYPE_DEFAULT);
208+
deviceType = sharedPreferences.getString(AppConstants.KEY_DEVICE_TYPES, AppConstants.DEVICE_TYPE_DEFAULT);
187209
final boolean isSec1 = sharedPreferences.getBoolean(AppConstants.KEY_SECURITY_TYPE, true);
188210
Log.d(TAG, "Device Types : " + deviceType);
189211
Log.d(TAG, "isSec1 : " + isSec1);
@@ -212,7 +234,7 @@ private void startProvisioningFlow() {
212234

213235
} else {
214236

215-
final String[] deviceTypes = {"BLE", "Wi-Fi"};
237+
final String[] deviceTypes = {"BLE", "SoftAP"};
216238
AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.AlertDialogTheme);
217239
builder.setCancelable(true);
218240
builder.setTitle(R.string.dialog_msg_device_selection);

app/src/main/java/com/espressif/ui/activities/ProvisionLanding.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public void onEvent(DeviceConnectionEvent event) {
143143

144144
} else {
145145

146-
goToProvisionActivity();
146+
goToWiFiConfigActivity();
147147
}
148148

149149
} else {
@@ -158,7 +158,7 @@ public void onEvent(DeviceConnectionEvent event) {
158158

159159
} else {
160160

161-
goToProvisionActivity();
161+
goToWiFiConfigActivity();
162162
}
163163
}
164164
break;
@@ -259,16 +259,14 @@ private void goToWifiScanListActivity() {
259259

260260
finish();
261261
Intent wifiListIntent = new Intent(getApplicationContext(), WiFiScanActivity.class);
262-
wifiListIntent.putExtra(AppConstants.KEY_PROOF_OF_POSSESSION, "");
263262
startActivity(wifiListIntent);
264263
}
265264

266-
private void goToProvisionActivity() {
265+
private void goToWiFiConfigActivity() {
267266

268267
finish();
269-
Intent provisionIntent = new Intent(getApplicationContext(), ProvisionActivity.class);
270-
provisionIntent.putExtra(AppConstants.KEY_PROOF_OF_POSSESSION, "");
271-
startActivity(provisionIntent);
268+
Intent wifiConfigIntent = new Intent(getApplicationContext(), WiFiConfigActivity.class);
269+
startActivity(wifiConfigIntent);
272270
}
273271

274272
private boolean hasPermissions() {
-11.4 KB
Binary file not shown.

app/src/main/res/drawable/ic_esp.xml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<vector android:height="300dp" android:viewportHeight="730.5"
2+
android:viewportWidth="730.5" android:width="300dp" xmlns:android="http://schemas.android.com/apk/res/android">
3+
<path android:fillColor="#e5e5e5" android:pathData="m287.121,485.314c0,19.2 -15.6,34.8 -34.8,34.8s-34.8,-15.6 -34.8,-34.8s15.6,-34.8 34.8,-34.8l0,0c19.2,0.1 34.8,15.6 34.8,34.8l0,0"/>
4+
<path android:fillColor="#e5e5e5" android:pathData="m590.921,449.114c-22.3,-158.1 -147.7,-283.5 -305.9,-305.8c-18.4,9.8 -35.4,22 -50.5,36.4l0,33.6c157.8,0 286.2,128.4 286.2,286.2l33.7,0c14.4,-15 26.7,-32 36.5,-50.4"/>
5+
<path android:fillColor="#e5e5e5" android:pathData="m617.021,343.514c0,-125 -101.3,-226.4 -226.4,-226.4c-7.8,0 -15.6,0.5 -23.3,1.3l-5.2,14.9c111.5,39.2 199.2,126.8 238.5,238.4l15.1,-5.3c0.8,-7.6 1.3,-15.2 1.3,-22.9"/>
6+
<path android:fillColor="#e5e5e5" android:pathData="m393.221,612.414c-148.6,-0.1 -269.1,-120.5 -269.1,-269.2c0,-71.4 28.3,-139.8 78.8,-190.2l14.4,14.4c-97.1,97.1 -97.1,254.7 0,351.8s254.7,97.1 351.8,0l14.4,14.4c-50.4,50.6 -118.9,79 -190.3,78.8"/>
7+
<path android:fillColor="#e5e5e5" android:pathData="m390.321,515.114c8.5,-86 -54.3,-162.6 -140.2,-171.2c-7.7,-0.8 -13.3,-7.6 -12.6,-15.3c0.6,-7.6 7.2,-13.3 14.8,-12.7c0.2,0 0.4,0 0.6,0.1c101,9.6 175,99.3 165.4,200.3c-1.1,11.3 -3.2,22.5 -6.3,33.4l40.8,11.5c12.1,-3.4 24,-7.9 35.4,-13.3c3,-15.9 4.5,-32.1 4.5,-48.3c0,-129.5 -95.7,-237 -220.1,-255.4c-14.9,-2.1 -30.1,-2.3 -41.2,0.5c-47.2,12 -75.7,59.9 -63.8,107.1c7.5,29.5 29.7,53.1 58.7,62.3c6.7,2.1 17,3 22.2,4l0.2,0c44.9,7.7 75.1,50.3 67.5,95.3c-1.9,11 -5.9,21.4 -12,30.8l28.3,18.1c13.8,3.7 27.9,6 42.2,7.1c8.4,-17.1 13.7,-35.4 15.6,-54.3"/>
8+
<path android:fillAlpha="0" android:fillColor="#000000"
9+
android:fillType="evenOdd" android:pathData="M576.5,482.4a47.3,76.6 0,1 0,94.6 0a47.3,76.6 0,1 0,-94.6 0z"/>
10+
</vector>
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<vector android:height="300dp" android:viewportHeight="730.5"
2+
android:viewportWidth="730.5" android:width="300dp" xmlns:android="http://schemas.android.com/apk/res/android">
3+
<path android:fillColor="#e5e5e5" android:pathData="m233,497.9c0,19.2 -15.6,34.8 -34.8,34.8s-34.8,-15.6 -34.8,-34.8s15.6,-34.8 34.8,-34.8l0,0c19.2,0.1 34.8,15.6 34.8,34.8l0,0"/>
4+
<path android:fillColor="#e5e5e5" android:pathData="m536.8,461.7c-22.3,-158.1 -147.7,-283.5 -305.9,-305.8c-18.4,9.8 -35.4,22 -50.5,36.4l0,33.6c157.8,0 286.2,128.4 286.2,286.2l33.7,0c14.4,-15 26.7,-32 36.5,-50.4"/>
5+
<path android:fillColor="#e5e5e5" android:pathData="m562.9,356.1c0,-125 -101.3,-226.4 -226.4,-226.4c-7.8,0 -15.6,0.5 -23.3,1.3l-5.2,14.9c111.5,39.2 199.2,126.8 238.5,238.4l15.1,-5.3c0.8,-7.6 1.3,-15.2 1.3,-22.9"/>
6+
<path android:fillColor="#e5e5e5" android:pathData="m339.1,625c-148.6,-0.1 -269.1,-120.5 -269.1,-269.2c0,-71.4 28.3,-139.8 78.8,-190.2l14.4,14.4c-97.1,97.1 -97.1,254.7 0,351.8s254.7,97.1 351.8,0l14.4,14.4c-50.4,50.6 -118.9,79 -190.3,78.8"/>
7+
<path android:fillColor="#e5e5e5" android:pathData="m336.2,527.7c8.5,-86 -54.3,-162.6 -140.2,-171.2c-7.7,-0.8 -13.3,-7.6 -12.6,-15.3c0.6,-7.6 7.2,-13.3 14.8,-12.7c0.2,0 0.4,0 0.6,0.1c101,9.6 175,99.3 165.4,200.3c-1.1,11.3 -3.2,22.5 -6.3,33.4l40.8,11.5c12.1,-3.4 24,-7.9 35.4,-13.3c3,-15.9 4.5,-32.1 4.5,-48.3c0,-129.5 -95.7,-237 -220.1,-255.4c-14.9,-2.1 -30.1,-2.3 -41.2,0.5c-47.2,12 -75.7,59.9 -63.8,107.1c7.5,29.5 29.7,53.1 58.7,62.3c6.7,2.1 17,3 22.2,4l0.2,0c44.9,7.7 75.1,50.3 67.5,95.3c-1.9,11 -5.9,21.4 -12,30.8l28.3,18.1c13.8,3.7 27.9,6 42.2,7.1c8.4,-17.1 13.7,-35.4 15.6,-54.3"/>
8+
<path android:fillColor="#ffffff" android:fillType="evenOdd" android:pathData="M576.5,482.4a47.3,76.6 0,1 0,94.6 0a47.3,76.6 0,1 0,-94.6 0z"/>
9+
<path android:fillColor="#e5e5e5" android:fillType="evenOdd" android:pathData="m630.5,440.6l13.7,13.7l-13.6,13.6l-0.1,-27.3l0,0zM630.5,524.2l13.7,-13.7l-13.6,-13.6l-0.1,27.3l0,0zM615.9,482.4l-29.5,-29.6l8.6,-8.6l23.5,23.5l0,-56.4l42.8,42.8l-28.3,28.3l28.2,28.2l-42.8,42.8l0,-56.4l-23.4,23.5l-8.6,-8.6l29.5,-29.5l0,0zM623.8,564.9c36.1,0 60.9,-17.1 60.9,-82.6c0,-65.5 -24.9,-82.6 -60.9,-82.6c-36.1,0 -60.9,17.1 -60.9,82.6c0,65.5 24.9,82.6 60.9,82.6l0,0z"/>
10+
<path android:fillColor="#e5e5e5" android:pathData="m715.4,412.1c0,6.9 -5.8,12.7 -12.7,12.7c-7.2,0 -12.7,-5.5 -12.7,-12.7c0,-7 5.7,-12.7 12.7,-12.7c7.1,0 12.7,5.5 12.7,12.7zM692.8,412c0,5.4 4.4,10.1 9.8,10.1c5.5,0 9.8,-4.5 9.8,-9.9c0,-5.5 -4.3,-10.1 -9.8,-10.1c-5.4,0 -9.8,4.5 -9.8,9.9zM705,419l-3.9,-6.1l-0.1,0l0,6.1l-2.4,0l0,-13.9l4.2,0c3.3,0 4.6,1.4 4.6,3.5c0,2.4 -1.4,3.8 -3.7,4c0.3,0.4 0.8,1.1 1.4,2l2.9,4.4l-3,0zM702.5,407l-1.5,0l0,4.3l1,0c2.2,0 3,-1.3 3,-2.4c-0.1,-1.4 -0.7,-1.9 -2.5,-1.9z"/>
11+
</vector>

0 commit comments

Comments
 (0)