Skip to content

Commit

Permalink
Merge branch 'feature/avs_ble_support_idf_4_0' into 'versions/avs-ble'
Browse files Browse the repository at this point in the history
Added support for IDF 4.0

See merge request idf/esp-idf-provisioning-android!23
  • Loading branch information
shahpiyushv committed Mar 11, 2020
2 parents b599fea + d72174f commit ea45b2c
Show file tree
Hide file tree
Showing 13 changed files with 485 additions and 509 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ android {
applicationId "com.espressif.provbleavs"
minSdkVersion 21
targetSdkVersion 28
versionCode 13
versionName "2.1"
versionCode 15
versionName "2.1.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
signingConfig signingConfigs.config
}
Expand Down
55 changes: 5 additions & 50 deletions app/src/main/java/com/espressif/ui/activities/AlexaActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ public class AlexaActivity extends AppCompatActivity {

private AvsEmberLightText txtAlexaAppLink;

private Session session;
private Security security;
private Transport transport;

private String hostAddress;
private String deviceName;

Expand All @@ -71,32 +67,6 @@ public void onCreate(Bundle savedInstanceState) {
if (!TextUtils.isEmpty(deviceName)) {
txtDeviceName.setText(deviceName);
}

if (!isProv) {

transport = new SoftAPTransport(hostAddress + ":80");

if (isNewFw) {
security = new Security1(getResources().getString(R.string.proof_of_possesion));
} else {
security = new Security0();
}
session = new Session(transport, security);
session.init(null);

session.sessionListener = new Session.SessionListener() {

@Override
public void OnSessionEstablished() {
Log.d(TAG, "Session established");
}

@Override
public void OnSessionEstablishFailed(Exception e) {
Log.d(TAG, "Session failed");
}
};
}
}

@Override
Expand All @@ -122,10 +92,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
//noinspection SimplifiableIfStatement
if (id == R.id.action_sign_out) {

if (session.isEstablished()) {
sendSignOutCommand();
}
sendSignOutCommand();
return true;

} else if (id == R.id.action_done) {

finish();
Expand Down Expand Up @@ -185,20 +154,6 @@ public void openApplication(String packageN) {
}
}

private View.OnClickListener signOutBtnClickListener = new View.OnClickListener() {

@Override
public void onClick(View v) {

Vibrator vib = (Vibrator) getSystemService(VIBRATOR_SERVICE);
vib.vibrate(HapticFeedbackConstants.VIRTUAL_KEY);

if (session.isEstablished()) {
sendSignOutCommand();
}
}
};

private void sendSignOutCommand() {

Avsconfig.CmdSignInStatus configRequest = Avsconfig.CmdSignInStatus.newBuilder()
Expand All @@ -210,8 +165,8 @@ private void sendSignOutCommand() {
.setCmdSigninStatus(configRequest)
.build();

byte[] message = security.encrypt(payload.toByteArray());
transport.sendConfigData(AVS_CONFIG_PATH, message, new ResponseListener() {
byte[] message = ScanLocalDevices.security.encrypt(payload.toByteArray());
ScanLocalDevices.transport.sendConfigData(AVS_CONFIG_PATH, message, new ResponseListener() {

@Override
public void onSuccess(byte[] returnData) {
Expand All @@ -237,7 +192,7 @@ public void onFailure(Exception e) {
private Avsconfig.AVSConfigStatus processAVSConfigResponse(byte[] responseData) {

Avsconfig.AVSConfigStatus status = Avsconfig.AVSConfigStatus.InvalidState;
byte[] decryptedData = this.security.decrypt(responseData);
byte[] decryptedData = ScanLocalDevices.security.decrypt(responseData);

try {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
import android.os.Handler;
import android.os.ParcelUuid;
import android.os.Vibrator;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import android.util.Log;
import android.view.HapticFeedbackConstants;
import android.view.View;
Expand Down Expand Up @@ -88,8 +90,8 @@ public class BLEProvisionLanding extends AppCompatActivity {
private ProgressBar progressBar;
private ListView listView;

private Session session;
private Security security;
public static Session session;
public static Security security;
public static BLETransport bleTransport;
private BLETransport.BLETransportListener transportListener;

Expand Down Expand Up @@ -321,6 +323,10 @@ private void startScan() {
if (bleTransport != null) {
bleTransport.disconnect();
}
security = null;
session = null;
Log.e(TAG, "Make session null");
isBleWorkDone = false;

deviceList.clear();
bluetoothDevices.clear();
Expand Down
119 changes: 20 additions & 99 deletions app/src/main/java/com/espressif/ui/activities/DeviceActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
Expand All @@ -20,15 +14,14 @@
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import com.espressif.AppConstants;
import com.espressif.provision.R;
import com.espressif.provision.security.Security;
import com.espressif.provision.security.Security0;
import com.espressif.provision.security.Security1;
import com.espressif.provision.session.Session;
import com.espressif.provision.transport.ResponseListener;
import com.espressif.provision.transport.SoftAPTransport;
import com.espressif.provision.transport.Transport;
import com.espressif.ui.models.DeviceInfo;
import com.google.protobuf.InvalidProtocolBufferException;

Expand Down Expand Up @@ -59,10 +52,6 @@ public class DeviceActivity extends AppCompatActivity {
private String deviceName;
private boolean isNewFw;

private Session session;
private Security security;
private Transport transport;

private boolean isAvsSignedIn = false;

@Override
Expand Down Expand Up @@ -100,30 +89,7 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten
protected void onResume() {
super.onResume();

transport = new SoftAPTransport(deviceHostAddress + ":80");
if (deviceInfo.isNewFirmware()) {
security = new Security1(getResources().getString(R.string.proof_of_possesion));
} else {
security = new Security0();
}
session = new Session(transport, security);
session.init(null);

session.sessionListener = new Session.SessionListener() {

@Override
public void OnSessionEstablished() {

Log.d(TAG, "Session established");
getDeviceInfo();
}

@Override
public void OnSessionEstablishFailed(Exception e) {
Log.d(TAG, "Session failed");
e.printStackTrace();
}
};
getDeviceInfo();
}

private void initViews() {
Expand Down Expand Up @@ -177,29 +143,7 @@ public void onStartTrackingTouch(SeekBar seekBar) {
public void onStopTrackingTouch(final SeekBar seekBar) {

Log.e(TAG, "onStopTrackingTouch : " + seekBar.getProgress());
transport = new SoftAPTransport(deviceHostAddress + ":80");
if (deviceInfo.isNewFirmware()) {
security = new Security1(getResources().getString(R.string.proof_of_possesion));
} else {
security = new Security0();
}
session = new Session(transport, security);
session.init(null);

session.sessionListener = new Session.SessionListener() {

@Override
public void OnSessionEstablished() {

Log.d(TAG, "Session established");
changeVolume(seekBar.getProgress());
}

@Override
public void OnSessionEstablishFailed(Exception e) {
Log.d(TAG, "Session failed");
}
};
changeVolume(seekBar.getProgress());
}
};

Expand Down Expand Up @@ -291,30 +235,7 @@ public void onClick(DialogInterface dialog, int which) {
return;
}

transport = new SoftAPTransport(deviceHostAddress + ":80");
if (deviceInfo.isNewFirmware()) {
security = new Security1(getResources().getString(R.string.proof_of_possesion));
} else {
security = new Security0();
}
session = new Session(transport, security);
session.init(null);

final String finalNewDeviceName = newDeviceName;
session.sessionListener = new Session.SessionListener() {

@Override
public void OnSessionEstablished() {

Log.d(TAG, "Session established");
setDeviceName(finalNewDeviceName);
}

@Override
public void OnSessionEstablishFailed(Exception e) {
Log.d(TAG, "Session failed");
}
};
setDeviceName(newDeviceName);
}
});

Expand Down Expand Up @@ -349,9 +270,9 @@ public void run() {
.setCmdUserVisibleName(changeNameRequest)
.build();

byte[] message = this.security.encrypt(payload.toByteArray());
byte[] message = ScanLocalDevices.security.encrypt(payload.toByteArray());

this.transport.sendConfigData(AppConstants.HANDLER_AVS_CONFIG, message, new ResponseListener() {
ScanLocalDevices.transport.sendConfigData(AppConstants.HANDLER_AVS_CONFIG, message, new ResponseListener() {

@Override
public void onSuccess(byte[] returnData) {
Expand Down Expand Up @@ -391,7 +312,7 @@ public void onFailure(Exception e) {
private Avsconfig.AVSConfigStatus processDeviceNameChangeResponse(byte[] responseData) {

Avsconfig.AVSConfigStatus status = Avsconfig.AVSConfigStatus.InvalidState;
byte[] decryptedData = this.security.decrypt(responseData);
byte[] decryptedData = ScanLocalDevices.security.decrypt(responseData);

try {

Expand Down Expand Up @@ -427,8 +348,8 @@ public void run() {
.setCmdSetVolume(volumeChangeRequest)
.build();

byte[] message = this.security.encrypt(payload.toByteArray());
this.transport.sendConfigData(AppConstants.HANDLER_AVS_CONFIG, message, new ResponseListener() {
byte[] message = ScanLocalDevices.security.encrypt(payload.toByteArray());
ScanLocalDevices.transport.sendConfigData(AppConstants.HANDLER_AVS_CONFIG, message, new ResponseListener() {

@Override
public void onSuccess(byte[] returnData) {
Expand Down Expand Up @@ -463,7 +384,7 @@ public void onFailure(Exception e) {
private Avsconfig.AVSConfigStatus processVolumeChangeResponse(byte[] responseData) {

Avsconfig.AVSConfigStatus status = Avsconfig.AVSConfigStatus.InvalidState;
byte[] decryptedData = this.security.decrypt(responseData);
byte[] decryptedData = ScanLocalDevices.security.decrypt(responseData);

try {

Expand Down Expand Up @@ -498,9 +419,9 @@ public void run() {
.setMsg(msgType)
.setCmdSigninStatus(configRequest)
.build();
byte[] message = this.security.encrypt(payload.toByteArray());
byte[] message = ScanLocalDevices.security.encrypt(payload.toByteArray());

this.transport.sendConfigData(AppConstants.HANDLER_AVS_CONFIG, message, new ResponseListener() {
ScanLocalDevices.transport.sendConfigData(AppConstants.HANDLER_AVS_CONFIG, message, new ResponseListener() {

@Override
public void onSuccess(byte[] returnData) {
Expand Down Expand Up @@ -535,7 +456,7 @@ public void onFailure(Exception e) {
private Avsconfig.AVSConfigStatus processSignInStatusResponse(byte[] responseData) {

Avsconfig.AVSConfigStatus status = Avsconfig.AVSConfigStatus.InvalidState;
byte[] decryptedData = this.security.decrypt(responseData);
byte[] decryptedData = ScanLocalDevices.security.decrypt(responseData);

try {

Expand Down Expand Up @@ -571,9 +492,9 @@ public void run() {
.setCmdGetDeviceInfo(deviceInfoRequest)
.build();

byte[] message = this.security.encrypt(payload.toByteArray());
byte[] message = ScanLocalDevices.security.encrypt(payload.toByteArray());

this.transport.sendConfigData(AppConstants.HANDLER_AVS_CONFIG, message, new ResponseListener() {
ScanLocalDevices.transport.sendConfigData(AppConstants.HANDLER_AVS_CONFIG, message, new ResponseListener() {

@Override
public void onSuccess(byte[] returnData) {
Expand Down Expand Up @@ -610,7 +531,7 @@ public void onFailure(Exception e) {

private DeviceInfo processDeviceInfoResponse(byte[] responseData) {

byte[] decryptedData = this.security.decrypt(responseData);
byte[] decryptedData = ScanLocalDevices.security.decrypt(responseData);
DeviceInfo deviceInfo = null;

try {
Expand Down
Loading

0 comments on commit ea45b2c

Please sign in to comment.