Skip to content

Commit

Permalink
Merge branch 'feature/thread_device_provisioning_support' into 'master'
Browse files Browse the repository at this point in the history
Feature: Thread Provisioning

See merge request idf/esp-idf-provisioning-android!69
  • Loading branch information
adwait-esp committed Jul 5, 2024
2 parents 4103281 + 6a2d30c commit d7b295e
Show file tree
Hide file tree
Showing 26 changed files with 1,799 additions and 373 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ To get this app please clone this repository using the below command:

## Requirements

- Supports Android 6.0 (API level 23) and above.
- Supports Android 8.0 (API level 26) and above.

## How to include

Expand All @@ -48,7 +48,7 @@ To get this app please clone this repository using the below command:
```
And add a dependency code to your app module's `build.gradle` file.
```
implementation 'com.github.espressif:esp-idf-provisioning-android:lib-2.1.4'
implementation 'com.github.espressif:esp-idf-provisioning-android:lib-2.2.0'
```

## Using Provisioning Library
Expand Down
12 changes: 7 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ def getGitHash = { ->

android {

compileSdkVersion 33
compileSdkVersion 34

defaultConfig {
applicationId "com.espressif.wifi_provisioning"
minSdkVersion 23
targetSdkVersion 33
versionCode 19
versionName "2.1.4 - ${getGitHash()}"
minSdkVersion 26
targetSdkVersion 34
versionCode 20
versionName "2.2.0 - ${getGitHash()}"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

Expand Down Expand Up @@ -65,6 +65,8 @@ dependencies {
implementation 'com.github.yuriy-budiyev:code-scanner:2.1.2'
implementation 'com.github.firdausmaulan:AVLoadingIndicatorView:2.3.0'

implementation 'com.google.android.gms:play-services-threadnetwork:16.0.1'

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@
// limitations under the License.
package com.espressif.espressif;

import static org.junit.Assert.assertEquals;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
Expand All @@ -32,7 +33,7 @@ public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();

assertEquals("com.espressif.espressif", appContext.getPackageName());
}
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@
android:label="@string/title_activity_wifi_scan_list"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name="com.espressif.ui.activities.ThreadConfigActivity"
android:label="@string/title_activity_wifi_scan_list"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name="com.espressif.ui.activities.ProofOfPossessionActivity"
android:label="@string/title_activity_pop"
Expand Down
12 changes: 10 additions & 2 deletions app/src/main/java/com/espressif/AppConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ public class AppConstants {
public static final String KEY_WIFI_PASSWORD = "password";
public static final String KEY_DEVICE_TYPES = "device_types";
public static final String KEY_SECURITY_TYPE = "security_type";
public static final String KEY_USER_NAME = "sec2_username";
public static final String KEY_USER_NAME_WIFI = "sec2_username_wifi";
public static final String KEY_USER_NAME_THREAD = "sec2_username_thread";
public static final String KEY_THREAD_DATASET = "thread_dataset";
public static final String KEY_THREAD_SCAN_AVAILABLE = "thread_scan_available";

public static final String ESP_PREFERENCES = "Esp_Preferences";

Expand All @@ -40,5 +43,10 @@ public class AppConstants {
public static final int SEC_TYPE_1 = 1;
public static final int SEC_TYPE_2 = 2;
public static final int SEC_TYPE_DEFAULT = SEC_TYPE_2;
public static final String DEFAULT_USER_NAME = "wifiprov";
public static final String DEFAULT_USER_NAME_WIFI = "wifiprov";
public static final String DEFAULT_USER_NAME_THREAD = "threadprov";

public static final String CAPABILITY_WIFI_SCAN = "wifi_scan";
public static final String CAPABILITY_THREAD_SCAN = "thread_scan";
public static final String CAPABILITY_THREAD_PROV = "thread_prov";
}
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,6 @@ public void onEvent(DeviceConnectionEvent event) {

case ESPConstants.EVENT_DEVICE_CONNECTED:

if (TextUtils.isEmpty(provisionManager.getEspDevice().getUserName())) {
String userName = sharedPreferences.getString(AppConstants.KEY_USER_NAME, AppConstants.DEFAULT_USER_NAME);
provisionManager.getEspDevice().setUserName(userName);
}
Log.d(TAG, "Device Connected Event Received");
setSecurityTypeFromVersionInfo();
break;
Expand Down Expand Up @@ -540,6 +536,14 @@ private void goToWiFiScanActivity() {
startActivity(wifiListIntent);
}

private void goToThreadScanActivity(boolean scanCapAvailable) {

finish();
Intent threadConfigIntent = new Intent(getApplicationContext(), ThreadConfigActivity.class);
threadConfigIntent.putExtra(AppConstants.KEY_THREAD_SCAN_AVAILABLE, scanCapAvailable);
startActivity(threadConfigIntent);
}

private void goToWiFiConfigActivity() {

finish();
Expand Down Expand Up @@ -724,6 +728,17 @@ private void setSecurityTypeFromVersionInfo() {
default:
securityType = AppConstants.SEC_TYPE_2;
provisionManager.getEspDevice().setSecurityType(ESPConstants.SecurityType.SECURITY_2);
ArrayList<String> deviceCaps = provisionManager.getEspDevice().getDeviceCapabilities();

if (deviceCaps != null && deviceCaps.size() > 0
&& (deviceCaps.contains(AppConstants.CAPABILITY_THREAD_SCAN) || deviceCaps.contains(AppConstants.CAPABILITY_THREAD_PROV))
) {
String userName = sharedPreferences.getString(AppConstants.KEY_USER_NAME_THREAD, AppConstants.DEFAULT_USER_NAME_THREAD);
provisionManager.getEspDevice().setUserName(userName);
} else if (TextUtils.isEmpty(provisionManager.getEspDevice().getUserName())) {
String userName = sharedPreferences.getString(AppConstants.KEY_USER_NAME_WIFI, AppConstants.DEFAULT_USER_NAME_WIFI);
provisionManager.getEspDevice().setUserName(userName);
}
break;
}
} else {
Expand Down Expand Up @@ -754,8 +769,12 @@ private void setSecurityTypeFromVersionInfo() {

private void processDeviceCapabilities() {
ArrayList<String> deviceCaps = espDevice.getDeviceCapabilities();
if (deviceCaps.contains("wifi_scan")) {
if (deviceCaps.contains(AppConstants.CAPABILITY_WIFI_SCAN)) {
goToWiFiScanActivity();
} else if (deviceCaps.contains(AppConstants.CAPABILITY_THREAD_SCAN)) {
goToThreadScanActivity(true);
} else if (deviceCaps.contains(AppConstants.CAPABILITY_THREAD_PROV)) {
goToThreadScanActivity(false);
} else {
goToWiFiConfigActivity();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,16 +325,19 @@ private void requestLocationAndBtPermission() {
private void processDeviceCapabilities() {
ArrayList<String> deviceCaps = provisionManager.getEspDevice().getDeviceCapabilities();

if (deviceCaps != null && !deviceCaps.contains("no_pop") && securityType != AppConstants.SEC_TYPE_0) {

goToPopActivity();

} else if (deviceCaps.contains("wifi_scan")) {

goToWifiScanListActivity();

if (deviceCaps != null) {
if (!deviceCaps.contains("no_pop") && securityType != AppConstants.SEC_TYPE_0) {
goToPopActivity();
} else if (deviceCaps.contains(AppConstants.CAPABILITY_WIFI_SCAN)) {
goToWifiScanListActivity();
} else if (deviceCaps.contains(AppConstants.CAPABILITY_THREAD_SCAN)) {
goToThreadScanActivity(true);
} else if (deviceCaps.contains(AppConstants.CAPABILITY_THREAD_PROV)) {
goToThreadScanActivity(false);
} else {
goToWiFiConfigActivity();
}
} else {

goToWiFiConfigActivity();
}
}
Expand Down Expand Up @@ -568,6 +571,15 @@ private void goToWifiScanListActivity() {
startActivity(wifiListIntent);
}

private void goToThreadScanActivity(boolean scanCapAvailable) {

finish();
Intent threadConfigIntent = new Intent(getApplicationContext(), ThreadConfigActivity.class);
threadConfigIntent.putExtra(AppConstants.KEY_DEVICE_NAME, deviceList.get(position).getName());
threadConfigIntent.putExtra(AppConstants.KEY_THREAD_SCAN_AVAILABLE, scanCapAvailable);
startActivity(threadConfigIntent);
}

private void goToWiFiConfigActivity() {

finish();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

public class ManualProvBaseActivity extends AppCompatActivity {

private static final String TAG = ManualProvBaseActivity.class.getSimpleName();
Expand Down Expand Up @@ -92,8 +94,15 @@ void setSecurityTypeFromVersionInfo() {
default:
securityType = AppConstants.SEC_TYPE_2;
provisionManager.getEspDevice().setSecurityType(ESPConstants.SecurityType.SECURITY_2);
if (TextUtils.isEmpty(provisionManager.getEspDevice().getUserName())) {
String userName = sharedPreferences.getString(AppConstants.KEY_USER_NAME, AppConstants.DEFAULT_USER_NAME);
ArrayList<String> deviceCaps = provisionManager.getEspDevice().getDeviceCapabilities();

if (deviceCaps != null && deviceCaps.size() > 0
&& (deviceCaps.contains(AppConstants.CAPABILITY_THREAD_SCAN) || deviceCaps.contains(AppConstants.CAPABILITY_THREAD_PROV))
) {
String userName = sharedPreferences.getString(AppConstants.KEY_USER_NAME_THREAD, AppConstants.DEFAULT_USER_NAME_THREAD);
provisionManager.getEspDevice().setUserName(userName);
} else if (TextUtils.isEmpty(provisionManager.getEspDevice().getUserName())) {
String userName = sharedPreferences.getString(AppConstants.KEY_USER_NAME_WIFI, AppConstants.DEFAULT_USER_NAME_WIFI);
provisionManager.getEspDevice().setUserName(userName);
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;

import com.espressif.AppConstants;
import com.espressif.provisioning.DeviceConnectionEvent;
import com.espressif.provisioning.ESPConstants;
import com.espressif.provisioning.ESPProvisionManager;
Expand Down Expand Up @@ -131,8 +132,12 @@ public void run() {
btnNext.setAlpha(1f);
progressBar.setVisibility(View.GONE);
ArrayList<String> deviceCaps = provisionManager.getEspDevice().getDeviceCapabilities();
if (deviceCaps.contains("wifi_scan")) {
if (deviceCaps.contains(AppConstants.CAPABILITY_WIFI_SCAN)) {
goToWiFiScanListActivity();
} else if (deviceCaps.contains(AppConstants.CAPABILITY_THREAD_SCAN)) {
goToThreadScanActivity(true);
} else if (deviceCaps.contains(AppConstants.CAPABILITY_THREAD_PROV)) {
goToThreadScanActivity(false);
} else {
goToWiFiConfigActivity();
}
Expand Down Expand Up @@ -197,6 +202,15 @@ private void goToWiFiScanListActivity() {
finish();
}

private void goToThreadScanActivity(boolean scanCapAvailable) {

Intent threadConfigIntent = new Intent(getApplicationContext(), ThreadConfigActivity.class);
threadConfigIntent.putExtras(getIntent());
threadConfigIntent.putExtra(AppConstants.KEY_THREAD_SCAN_AVAILABLE, scanCapAvailable);
startActivity(threadConfigIntent);
finish();
}

private void goToWiFiConfigActivity() {

Intent wifiConfigIntent = new Intent(getApplicationContext(), WiFiConfigActivity.class);
Expand Down
Loading

0 comments on commit d7b295e

Please sign in to comment.