From 3c8c6b10b263d947f4e97200905919995c489157 Mon Sep 17 00:00:00 2001 From: XuXiangJun Date: Tue, 25 Jun 2019 14:57:08 +0800 Subject: [PATCH] update --- README.md | 6 +- app/build.gradle | 32 ++- app/signature/espdebug | Bin 0 -> 2581 bytes app/src/main/AndroidManifest.xml | 6 +- .../demo_activity/EsptouchDemoActivity.java | 188 +++++++----------- .../res/layout/esptouch_demo_activity.xml | 147 +++++++------- app/src/main/res/values/colors.xml | 6 +- app/src/main/res/values/styles.xml | 6 +- build.gradle | 2 +- esptouch/build.gradle | 10 +- .../iot/esptouch/EsptouchResult.java | 5 + .../espressif/iot/esptouch/EsptouchTask.java | 21 +- .../espressif/iot/esptouch/IEsptouchTask.java | 6 +- .../iot/esptouch/protocol/DatumCode.java | 17 +- .../esptouch/protocol/EsptouchGenerator.java | 9 +- .../esptouch/security/ITouchEncryptor.java | 5 + .../EspAES.java => security/TouchAES.java} | 12 +- .../esptouch/task/EsptouchTaskParameter.java | 2 - .../iot/esptouch/task/__EsptouchTask.java | 23 +-- .../iot/esptouch/util/TouchNetUtil.java | 6 - gradle.properties | 2 + gradle/wrapper/gradle-wrapper.properties | 4 +- log/log-en.md | 8 + log/log-zh-rCN.md | 10 +- 24 files changed, 253 insertions(+), 280 deletions(-) create mode 100644 app/signature/espdebug create mode 100644 esptouch/src/main/java/com/espressif/iot/esptouch/security/ITouchEncryptor.java rename esptouch/src/main/java/com/espressif/iot/esptouch/{util/EspAES.java => security/TouchAES.java} (90%) create mode 100644 gradle.properties diff --git a/README.md b/README.md index 9dd6e7b..751f12e 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ # EspTouch for Android -This APP is used to configure ESP devices to connect target AP, the devices need run smart config. +This APP is used to configure ESP devices to connect target AP, the devices need run [smart config](https://github.com/espressif/esp-idf/tree/master/examples/wifi/smart_config). ## Licence - See [Licence](ESPRESSIF_MIT_LICENSE) ## Version Log -- See [Log](log) +- See [Log](log/log-en.md) ## Releases - See [releases](https://github.com/EspressifApp/EspRelease/tree/master/EspTouch), contain APK and Jar -- For developer, if you don't want use [esptouch](esptouch) module, download the jar into your own project. \ No newline at end of file +- For programmer, if you don't want use [esptouch](esptouch) module, download the jar into your own project. diff --git a/app/build.gradle b/app/build.gradle index 9cbecbf..2575525 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,28 +1,44 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 27 - buildToolsVersion '28.0.3' + compileSdkVersion 29 defaultConfig { applicationId "com.espressif.iot_esptouch_demo" minSdkVersion 14 - targetSdkVersion 27 - versionCode 21 - versionName "v1.0.0" + targetSdkVersion 29 + versionCode 22 + versionName "v1.1.0" } + signingConfigs { + debug { + storeFile file('signature/espdebug') + storePassword 'espdebug' + keyAlias 'esp_debug' + keyPassword 'espdebug' + } + } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' } + debug { + signingConfig signingConfigs.debug + } + } + + compileOptions { + sourceCompatibility 1.8 + targetCompatibility 1.8 } } dependencies { - implementation fileTree(include: ['*.jar'], dir: 'libs') - implementation 'com.android.support:appcompat-v7:27.1.1' - implementation 'com.android.support:design:27.1.1' + implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs') + implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'com.google.android.material:material:1.0.0' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation project(':esptouch') } diff --git a/app/signature/espdebug b/app/signature/espdebug new file mode 100644 index 0000000000000000000000000000000000000000..d7adf0f7f6d769878279472ba379100fb64e6dcf GIT binary patch literal 2581 zcmY+EcRU-47RQr_ktlMBU1Ae6(FRqe_GoLQ!yeb(yC|L#G0WB3tM(|Ba*e7H<7!Z9 zhoY!el=M=2lsxZ!-n;MJKhEcz&-a}3`}2#!L4N@OX;3)G03Ad!RxkF52}lnt!a>@= zI7ss)Zb0E^eg3whwFBd5tuC?IWj&x{{Lj}FC=gVH1D~OA;3E{04*Fkw8O{raCky;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+Kqw|J;&XYsl87lKmD zhiilF6rmUnSSk{wiV{RY=xC*wX+S)*05H5tl&*Cfxc-@S_`0d|8&X~K4Q7X1_35yG7S literal 0 HcmV?d00001 diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ff0dc4e..a4d615a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,5 +1,6 @@ @@ -7,13 +8,14 @@ - + + android:theme="@style/AppTheme" + tools:ignore="GoogleAppIndexingWarning"> > { + private static class EsptouchAsyncTask4 extends AsyncTask> { private WeakReference mActivity; - // without the lock, if the user tap confirm and cancel quickly enough, - // the bug will arise. the reason is follows: - // 0. task is starting created, but not finished - // 1. the task is cancel for the task hasn't been created, it do nothing - // 2. task is created - // 3. Oops, the task should be cancelled, but it is running private final Object mLock = new Object(); private ProgressDialog mProgressDialog; private AlertDialog mResultDialog; @@ -346,36 +298,35 @@ protected void onPreExecute() { mProgressDialog = new ProgressDialog(activity); mProgressDialog.setMessage(activity.getString(R.string.configuring_message)); mProgressDialog.setCanceledOnTouchOutside(false); - mProgressDialog.setOnCancelListener(new OnCancelListener() { - @Override - public void onCancel(DialogInterface dialog) { - synchronized (mLock) { - if (__IEsptouchTask.DEBUG) { - Log.i(TAG, "progress dialog back pressed canceled"); - } - if (mEsptouchTask != null) { - mEsptouchTask.interrupt(); - } + mProgressDialog.setOnCancelListener(dialog -> { + synchronized (mLock) { + if (mEsptouchTask != null) { + mEsptouchTask.interrupt(); } } }); mProgressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, activity.getText(android.R.string.cancel), - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - synchronized (mLock) { - if (__IEsptouchTask.DEBUG) { - Log.i(TAG, "progress dialog cancel button canceled"); - } - if (mEsptouchTask != null) { - mEsptouchTask.interrupt(); - } + (dialog, which) -> { + synchronized (mLock) { + if (mEsptouchTask != null) { + mEsptouchTask.interrupt(); } } }); mProgressDialog.show(); } + @Override + protected void onProgressUpdate(IEsptouchResult... values) { + Context context = mActivity.get(); + if (context != null) { + IEsptouchResult result = values[0]; + Log.i(TAG, "EspTouchResult: " + result); + String text = result.getBssid() + " is connected to the wifi"; + Toast.makeText(context, text, Toast.LENGTH_SHORT).show(); + } + } + @Override protected List doInBackground(byte[]... params) { EsptouchDemoActivity activity = mActivity.get(); @@ -390,7 +341,7 @@ protected List doInBackground(byte[]... params) { Context context = activity.getApplicationContext(); mEsptouchTask = new EsptouchTask(apSsid, apBssid, apPassword, context); mEsptouchTask.setPackageBroadcast(broadcastData[0] == 1); - mEsptouchTask.setEsptouchListener(activity.myListener); + mEsptouchTask.setEsptouchListener(this::publishProgress); } return mEsptouchTask.executeForResults(taskResultCount); } @@ -398,6 +349,7 @@ protected List doInBackground(byte[]... params) { @Override protected void onPostExecute(List result) { EsptouchDemoActivity activity = mActivity.get(); + activity.mTask = null; mProgressDialog.dismiss(); if (result == null) { mResultDialog = new AlertDialog.Builder(activity) @@ -408,36 +360,36 @@ protected void onPostExecute(List result) { return; } - IEsptouchResult firstResult = result.get(0); // check whether the task is cancelled and no results received - if (!firstResult.isCancelled()) { - // the task received some results including cancelled while - // executing before receiving enough results - if (firstResult.isSuc()) { - ArrayList resultMsgList = new ArrayList<>(result.size()); - for (IEsptouchResult touchResult : result) { - String message = activity.getString(R.string.configure_result_success_item, - touchResult.getBssid(), touchResult.getInetAddress().getHostAddress()); - resultMsgList.add(message); - } + IEsptouchResult firstResult = result.get(0); + if (firstResult.isCancelled()) { + return; + } + // the task received some results including cancelled while + // executing before receiving enough results - CharSequence[] items = new CharSequence[resultMsgList.size()]; - mResultDialog = new AlertDialog.Builder(activity) - .setTitle(R.string.configure_result_success) - .setItems(resultMsgList.toArray(items), null) - .setPositiveButton(android.R.string.ok, null) - .show(); - mResultDialog.setCanceledOnTouchOutside(false); - } else { - mResultDialog = new AlertDialog.Builder(activity) - .setMessage(R.string.configure_result_failed) - .setPositiveButton(android.R.string.ok, null) - .show(); - mResultDialog.setCanceledOnTouchOutside(false); - } + if (!firstResult.isSuc()) { + mResultDialog = new AlertDialog.Builder(activity) + .setMessage(R.string.configure_result_failed) + .setPositiveButton(android.R.string.ok, null) + .show(); + mResultDialog.setCanceledOnTouchOutside(false); + return; } - activity.mTask = null; + ArrayList resultMsgList = new ArrayList<>(result.size()); + for (IEsptouchResult touchResult : result) { + String message = activity.getString(R.string.configure_result_success_item, + touchResult.getBssid(), touchResult.getInetAddress().getHostAddress()); + resultMsgList.add(message); + } + CharSequence[] items = new CharSequence[resultMsgList.size()]; + mResultDialog = new AlertDialog.Builder(activity) + .setTitle(R.string.configure_result_success) + .setItems(resultMsgList.toArray(items), null) + .setPositiveButton(android.R.string.ok, null) + .show(); + mResultDialog.setCanceledOnTouchOutside(false); } } } diff --git a/app/src/main/res/layout/esptouch_demo_activity.xml b/app/src/main/res/layout/esptouch_demo_activity.xml index 7c6fde5..4e4bcba 100644 --- a/app/src/main/res/layout/esptouch_demo_activity.xml +++ b/app/src/main/res/layout/esptouch_demo_activity.xml @@ -1,100 +1,92 @@ - - - - - - - + android:singleLine="true" + android:text="@string/ssid_title" + android:textAppearance="?android:attr/textAppearanceMedium" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> - + android:layout_marginStart="4dp" + android:layout_marginLeft="4dp" + android:singleLine="true" + android:textAppearance="?android:attr/textAppearanceMedium" + app:layout_constraintStart_toEndOf="@id/ap_ssid_label" + app:layout_constraintTop_toTopOf="parent" /> - - - - + - + + + android:layout_marginTop="8dp" + android:hint="@string/password_title" + app:layout_constraintTop_toBottomOf="@id/ap_bssid_label" + app:passwordToggleEnabled="true"> - - - - + - - - + android:layout_marginTop="8dp" + android:hint="@string/device_count_title" + app:layout_constraintTop_toBottomOf="@id/ap_password_layout"> - - + + android:layout_marginTop="8dp" + android:orientation="horizontal" + app:layout_constraintTop_toBottomOf="@id/device_count_layout"> @@ -115,17 +108,15 @@ android:id="@+id/message" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginTop="5dp" - android:textColor="@android:color/holo_red_dark" /> - - + android:gravity="top" + android:textColor="@android:color/holo_red_dark" + app:layout_constraintTop_toBottomOf="@id/package_mode_group" + app:layout_goneMarginStart="4dp" /> -