Skip to content

Commit 2ac8112

Browse files
committed
1. Added App info screen for version display.
2. Wi-Fi Auth mode handled for both old and new firmware. 3. Changed targetSdkVersion to 28.
1 parent affe21f commit 2ac8112

19 files changed

+499
-253
lines changed

app/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ android {
1515
defaultConfig {
1616
applicationId "com.espressif.provbleavs"
1717
minSdkVersion 21
18-
targetSdkVersion 27
18+
targetSdkVersion 28
1919
versionCode 10
2020
versionName "2.0"
2121
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

app/src/main/AndroidManifest.xml

+5
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@
118118
android:label="@string/title_activity_sound"
119119
android:screenOrientation="portrait"
120120
android:theme="@style/AppTheme.NoActionBar" />
121+
<activity
122+
android:name="com.espressif.ui.activities.AppInfoActivity"
123+
android:label="@string/title_activity_app_info"
124+
android:screenOrientation="portrait"
125+
android:theme="@style/AppTheme.NoActionBar" />
121126

122127
</application>
123128

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

+2
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ public class AppConstants {
2626
public static final String KEY_STATUS_MSG = "status_msg";
2727
public static final String KEY_DEVICE_INFO = "device_info";
2828
public static final String KEY_DEVICE_LANGUAGE = "device_language";
29+
30+
public static final String ESP_PREFERENCES = "Esp_Preferences";
2931
}

app/src/main/java/com/espressif/provision/transport/BLETransportLatest.java

+13-4
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222
import android.bluetooth.BluetoothGattService;
2323
import android.bluetooth.BluetoothProfile;
2424
import android.os.Build;
25+
import android.text.TextUtils;
2526
import android.util.Log;
2627

2728
import com.espressif.AppConstants;
29+
import com.espressif.ui.activities.ProvisionActivity;
2830

2931
import org.json.JSONArray;
3032
import org.json.JSONException;
@@ -261,8 +263,8 @@ public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descrip
261263
BluetoothGattCharacteristic characteristic = service.getCharacteristic(UUID.fromString(uuidMap.get(AppConstants.HANDLER_PROTO_VER)));
262264

263265
if (characteristic != null) {
264-
// Write anything. It doesn't matter. We need to read characteristic and for that we need to write something.
265-
characteristic.setValue("V0.1");
266+
// Write V0.2 to read characteristic.
267+
characteristic.setValue("V0.2");
266268
bluetoothGatt.writeCharacteristic(characteristic);
267269
}
268270
}
@@ -313,7 +315,14 @@ public void onCharacteristicRead(BluetoothGatt gatt,
313315

314316
} catch (JSONException e) {
315317
e.printStackTrace();
316-
Log.d(TAG, "Capabilities JSON not available.");
318+
Log.e(TAG, "Capabilities JSON not available.");
319+
Log.e(TAG, "Value : " + data);
320+
321+
// If received data is "SUCCESS" then consider that WiFi auth mode will be available in WiFi Scan list.
322+
if (!TextUtils.isEmpty(data) && data.equalsIgnoreCase("SUCCESS")) {
323+
Log.e(TAG, "Received version V0.2");
324+
ProvisionActivity.isWiFiAuthModeAvailable = true;
325+
}
317326
}
318327

319328
if (transportListener != null) {
@@ -408,7 +417,7 @@ private void readNextDescriptor() {
408417
BluetoothGattCharacteristic characteristic = service.getCharacteristic(UUID.fromString(uuidMap.get(AppConstants.HANDLER_PROTO_VER)));
409418

410419
if (characteristic != null) {
411-
characteristic.setValue("V0.1");
420+
characteristic.setValue("V0.2");
412421
bluetoothGatt.writeCharacteristic(characteristic);
413422
}
414423
}

app/src/main/java/com/espressif/provision/transport/BLETransportLegacy.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public void onServicesDiscovered(BluetoothGatt gatt, int status) {
158158
}
159159
service = gatt.getService(serviceUuid);
160160
bluetoothGatt = gatt;
161-
bluetoothGatt.requestMtu(400);
161+
// bluetoothGatt.requestMtu(400);
162162

163163
for (BluetoothGattCharacteristic characteristic : service.getCharacteristics()) {
164164
characteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.espressif.ui.activities;
2+
3+
import android.content.pm.PackageInfo;
4+
import android.content.pm.PackageManager;
5+
import android.os.Bundle;
6+
import android.support.annotation.Nullable;
7+
import android.support.v7.app.AppCompatActivity;
8+
import android.support.v7.widget.Toolbar;
9+
import android.widget.TextView;
10+
11+
import com.espressif.provision.R;
12+
13+
public class AppInfoActivity extends AppCompatActivity {
14+
15+
private TextView tvVersion;
16+
17+
@Override
18+
protected void onCreate(@Nullable Bundle savedInstanceState) {
19+
super.onCreate(savedInstanceState);
20+
setContentView(R.layout.activity_app_info);
21+
Toolbar toolbar = findViewById(R.id.toolbar);
22+
toolbar.setTitle(R.string.title_activity_app_info);
23+
setSupportActionBar(toolbar);
24+
25+
initViews();
26+
}
27+
28+
private void initViews() {
29+
30+
tvVersion = findViewById(R.id.tv_app_version);
31+
String version = getString(R.string.app_version);
32+
33+
try {
34+
35+
PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
36+
version = version + " " + pInfo.versionName;
37+
38+
} catch (PackageManager.NameNotFoundException e) {
39+
e.printStackTrace();
40+
}
41+
42+
tvVersion.setText(version);
43+
}
44+
}

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

+27-56
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import android.content.Context;
2424
import android.content.DialogInterface;
2525
import android.content.Intent;
26+
import android.content.SharedPreferences;
2627
import android.content.pm.PackageManager;
2728
import android.os.Build;
2829
import android.os.Bundle;
@@ -34,10 +35,8 @@
3435
import android.support.v7.widget.Toolbar;
3536
import android.util.Log;
3637
import android.view.HapticFeedbackConstants;
37-
import android.view.LayoutInflater;
3838
import android.view.View;
3939
import android.widget.AdapterView;
40-
import android.widget.EditText;
4140
import android.widget.ImageView;
4241
import android.widget.ListView;
4342
import android.widget.ProgressBar;
@@ -71,8 +70,6 @@
7170

7271
import avs.Avsconfig;
7372

74-
import static com.espressif.avs.ConfigureAVS.AVS_CONFIG_PATH;
75-
7673
public class BLEProvisionLanding extends AppCompatActivity {
7774

7875
private static final String TAG = "Espressif::" + BLEProvisionLanding.class.getSimpleName();
@@ -95,7 +92,6 @@ public class BLEProvisionLanding extends AppCompatActivity {
9592
private Security security;
9693
public static BLETransport bleTransport;
9794
private BLETransport.BLETransportListener transportListener;
98-
// FIXME : Remove static BLE_TRANSPORT and think for another solution.
9995

10096
private String deviceName;
10197
private String deviceNamePrefix;
@@ -108,6 +104,7 @@ public class BLEProvisionLanding extends AppCompatActivity {
108104
private BLEScanner bleScanner;
109105
private ArrayList<BluetoothDevice> deviceList;
110106
private HashMap<BluetoothDevice, EspBtDevice> bluetoothDevices;
107+
private SharedPreferences sharedPreferences;
111108
private Handler handler;
112109

113110
@Override
@@ -136,14 +133,14 @@ protected void onCreate(Bundle savedInstanceState) {
136133
return;
137134
}
138135

139-
deviceNamePrefix = getIntent().getStringExtra(AppConstants.KEY_BLE_DEVICE_NAME_PREFIX);
140-
141136
isConnecting = false;
142137
isDeviceConnected = false;
143138
handler = new Handler();
144139
bluetoothDevices = new HashMap<>();
145140
Collection<BluetoothDevice> keySet = bluetoothDevices.keySet();
146141
deviceList = new ArrayList<>(keySet);
142+
sharedPreferences = getSharedPreferences(AppConstants.ESP_PREFERENCES, Context.MODE_PRIVATE);
143+
deviceNamePrefix = sharedPreferences.getString(AppConstants.KEY_BLE_DEVICE_NAME_PREFIX, "");
147144

148145
initViews();
149146
bleScanner = new BLEScanner(this, SCAN_TIMEOUT, bleScanListener);
@@ -209,7 +206,9 @@ protected void onResume() {
209206
}
210207

211208
if (isBleWorkDone) {
212-
bleTransport.disconnect();
209+
if (bleTransport != null) {
210+
bleTransport.disconnect();
211+
}
213212
btnScan.setVisibility(View.VISIBLE);
214213
startScan();
215214
}
@@ -219,7 +218,9 @@ protected void onResume() {
219218
@Override
220219
public void onBackPressed() {
221220
isBleWorkDone = true;
222-
bleTransport.disconnect();
221+
if (bleTransport != null) {
222+
bleTransport.disconnect();
223+
}
223224
super.onBackPressed();
224225
}
225226

@@ -344,6 +345,7 @@ private void stopScan() {
344345
private void bleDeviceConfigured(final Boolean isConfigured) {
345346

346347
runOnUiThread(new Runnable() {
348+
347349
@Override
348350
public void run() {
349351

@@ -357,7 +359,7 @@ public void run() {
357359

358360
if (!bleTransport.deviceCapabilities.contains("no_pop") && securityVersion.equals(Provision.CONFIG_SECURITY_SECURITY1)) {
359361

360-
askForPop();
362+
goToProofOfPossessionActivity();
361363
}
362364
} else {
363365
pop = getResources().getString(R.string.proof_of_possesion);
@@ -393,14 +395,6 @@ private void updateProgressAndScanBtn() {
393395
}
394396
}
395397

396-
private void goToProofOfPossessionActivity() {
397-
398-
Intent alexaProvisioningIntent = new Intent(getApplicationContext(), ProofOfPossessionActivity.class);
399-
alexaProvisioningIntent.putExtras(getIntent());
400-
alexaProvisioningIntent.putExtra(LoginWithAmazon.KEY_IS_PROVISIONING, true);
401-
startActivity(alexaProvisioningIntent);
402-
}
403-
404398
private void getStatus() {
405399

406400
Avsconfig.CmdSignInStatus configRequest = Avsconfig.CmdSignInStatus.newBuilder()
@@ -414,7 +408,7 @@ private void getStatus() {
414408

415409
byte[] message = security.encrypt(payload.toByteArray());
416410

417-
BLEProvisionLanding.bleTransport.sendConfigData(AVS_CONFIG_PATH, message, new ResponseListener() {
411+
bleTransport.sendConfigData(AppConstants.HANDLER_AVS_CONFIG, message, new ResponseListener() {
418412

419413
@Override
420414
public void onSuccess(byte[] returnData) {
@@ -424,7 +418,7 @@ public void onSuccess(byte[] returnData) {
424418

425419
if (deviceStatus.equals(Avsconfig.AVSConfigStatus.SignedIn)) {
426420

427-
goToProvisionActivity();
421+
goToWiFiScanActivity();
428422

429423
} else {
430424
goToLoginActivity();
@@ -457,6 +451,15 @@ private Avsconfig.AVSConfigStatus processSignInStatusResponse(byte[] responseDat
457451
return status;
458452
}
459453

454+
private void goToProofOfPossessionActivity() {
455+
456+
Intent alexaProvisioningIntent = new Intent(getApplicationContext(), ProofOfPossessionActivity.class);
457+
alexaProvisioningIntent.putExtras(getIntent());
458+
alexaProvisioningIntent.putExtra(LoginWithAmazon.KEY_IS_PROVISIONING, true);
459+
alexaProvisioningIntent.putExtra(LoginWithAmazon.KEY_DEVICE_NAME, deviceName);
460+
startActivity(alexaProvisioningIntent);
461+
}
462+
460463
private void goToLoginActivity() {
461464

462465
Intent alexaProvisioningIntent = new Intent(getApplicationContext(), LoginWithAmazon.class);
@@ -467,7 +470,7 @@ private void goToLoginActivity() {
467470
startActivity(alexaProvisioningIntent);
468471
}
469472

470-
private void goToProvisionActivity() {
473+
private void goToWiFiScanActivity() {
471474

472475
Intent launchProvisionInstructions = new Intent(getApplicationContext(), WiFiScanActivity.class);
473476
launchProvisionInstructions.putExtras(getIntent());
@@ -506,13 +509,13 @@ public void OnSessionEstablishFailed(Exception e) {
506509
session.init(null);
507510
}
508511

509-
private void alertForDeviceNotSupported() {
512+
private void alertForDeviceConnectionFailed() {
510513

511514
AlertDialog.Builder builder = new AlertDialog.Builder(this);
512515
builder.setCancelable(false);
513516

514517
builder.setTitle("Error!");
515-
builder.setMessage(R.string.error_device_not_supported);
518+
builder.setMessage(R.string.error_device_connection_failed);
516519

517520
// Set up the buttons
518521
builder.setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {
@@ -632,42 +635,10 @@ public void run() {
632635
bleTransport.disconnect();
633636
}
634637
progressBar.setVisibility(View.GONE);
635-
alertForDeviceNotSupported();
638+
alertForDeviceConnectionFailed();
636639
}
637640
};
638641

639-
private void askForPop() {
640-
641-
AlertDialog.Builder builder = new AlertDialog.Builder(this);
642-
builder.setCancelable(false);
643-
644-
LayoutInflater layoutInflaterAndroid = LayoutInflater.from(this);
645-
View view = layoutInflaterAndroid.inflate(R.layout.dialog_pop, null);
646-
builder.setView(view);
647-
final EditText etPop = view.findViewById(R.id.et_prefix);
648-
etPop.setHint(R.string.hint_txt_pop);
649-
etPop.setText(getResources().getString(R.string.proof_of_possesion));
650-
etPop.setSelection(etPop.getText().length());
651-
652-
// Set up the buttons
653-
builder.setPositiveButton(R.string.btn_save, new DialogInterface.OnClickListener() {
654-
655-
@Override
656-
public void onClick(DialogInterface dialog, int which) {
657-
658-
pop = etPop.getText().toString();
659-
660-
if (pop != null) {
661-
pop = pop.trim();
662-
}
663-
664-
initSession();
665-
}
666-
});
667-
668-
builder.show();
669-
}
670-
671642
private boolean parseAdvertisementPacket(final byte[] scanRecord) {
672643

673644
byte[] advertisedData = Arrays.copyOf(scanRecord, scanRecord.length);

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

+2
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@ private void enableAlexaFeatures() {
627627
rlVolume.setClickable(true);
628628
rlSound.setClickable(true);
629629
rlLanguage.setClickable(true);
630+
volumeBar.setEnabled(true);
630631
rlVolume.setAlpha(1f);
631632
rlSound.setAlpha(1f);
632633
rlLanguage.setAlpha(1f);
@@ -636,6 +637,7 @@ private void enableAlexaFeatures() {
636637
rlVolume.setClickable(false);
637638
rlSound.setClickable(false);
638639
rlLanguage.setClickable(false);
640+
volumeBar.setEnabled(false);
639641
rlVolume.setAlpha(0.5f);
640642
rlSound.setAlpha(0.5f);
641643
rlLanguage.setAlpha(0.5f);

0 commit comments

Comments
 (0)