From 8fdf200ab35788de06664453b3bc4e5dbde0c584 Mon Sep 17 00:00:00 2001 From: Kangping Dong Date: Sat, 10 Aug 2024 18:23:21 +0800 Subject: [PATCH] [android] consolidate "app" and "service" into a single gradle project --- android/build-commissioner-libs.sh | 8 +- android/openthread_commissioner/.gitignore | 4 +- .../openthread_commissioner/app/.gitignore | 1 - .../openthread_commissioner/app/build.gradle | 25 +++- .../ActiveOperationalDatasetTest.java | 0 .../app/src/main/AndroidManifest.xml | 11 +- .../app}/BorderAgentDiscoverer.java | 2 +- .../commissioner/app}/BorderAgentInfo.java | 6 +- .../commissioner/app}/CameraSourceView.java | 2 +- .../commissioner/app}/CommissionerUtils.java | 2 +- .../commissioner/app}/Constants.java | 2 +- .../app}/FetchCredentialDialogFragment.java | 2 +- .../commissioner/app}/FragmentCallback.java | 2 +- .../InputNetworkPasswordDialogFragment.java | 2 +- .../commissioner/app}/JoinerDeviceInfo.java | 2 +- .../commissioner/app/MainActivity.java | 6 - .../commissioner/app}/MeshcopFragment.java | 4 +- .../app}/NativeCommissionerLogger.java | 2 +- .../commissioner/app}/NetworkAdapter.java | 12 +- .../commissioner/app}/ScanQrCodeFragment.java | 2 +- .../app}/SelectNetworkFragment.java | 5 +- .../app}/ThreadCommissionerException.java | 2 +- .../app}/ThreadCommissionerService.java | 2 +- .../app}/ThreadCommissionerServiceImpl.java | 7 +- .../commissioner/app}/ThreadNetworkInfo.java | 2 +- .../app}/ThreadNetworkInfoHolder.java | 2 +- .../src/main/res/drawable/ic_done_icon.xml | 0 .../src/main/res/drawable/ic_error_icon.xml | 0 .../res/drawable/ic_network_selected_icon.xml | 0 .../res/drawable/ic_wireless_network_icon.xml | 0 .../main/res/layout/activity_commissioner.xml | 0 .../fragment_fetch_credential_dialog.xml | 0 .../src/main/res/layout/fragment_meshcop.xml | 2 +- .../fragment_network_password_dialog.xml | 0 .../main/res/layout/fragment_scan_qrcode.xml | 6 +- .../res/layout/fragment_select_network.xml | 0 .../src/main/res/layout/network_list_item.xml | 0 .../app/src/main/res/values/colors.xml | 3 + .../app/src/main/res/values/strings.xml | 20 +++ .../src/main/res/values/styles.xml | 0 .../service/.gitignore | 3 - .../service/build.gradle | 87 ------------ .../service/consumer-rules.pro | 0 .../service/proguard-rules.pro | 21 --- .../service/src/main/AndroidManifest.xml | 19 --- .../service/CommissionerActivity.java | 126 ------------------ .../service/CommissionerServiceApp.java | 51 ------- .../service/src/main/res/values/colors.xml | 6 - .../service/src/main/res/values/strings.xml | 22 --- 49 files changed, 96 insertions(+), 387 deletions(-) delete mode 100644 android/openthread_commissioner/app/.gitignore rename android/openthread_commissioner/{service => app}/src/androidTest/java/io/openthread/commissioner/ActiveOperationalDatasetTest.java (100%) rename android/openthread_commissioner/{service/src/main/java/io/openthread/commissioner/service => app/src/main/java/io/openthread/commissioner/app}/BorderAgentDiscoverer.java (99%) rename android/openthread_commissioner/{service/src/main/java/io/openthread/commissioner/service => app/src/main/java/io/openthread/commissioner/app}/BorderAgentInfo.java (95%) rename android/openthread_commissioner/{service/src/main/java/io/openthread/commissioner/service => app/src/main/java/io/openthread/commissioner/app}/CameraSourceView.java (99%) rename android/openthread_commissioner/{service/src/main/java/io/openthread/commissioner/service => app/src/main/java/io/openthread/commissioner/app}/CommissionerUtils.java (98%) rename android/openthread_commissioner/{service/src/main/java/io/openthread/commissioner/service => app/src/main/java/io/openthread/commissioner/app}/Constants.java (97%) rename android/openthread_commissioner/{service/src/main/java/io/openthread/commissioner/service => app/src/main/java/io/openthread/commissioner/app}/FetchCredentialDialogFragment.java (99%) rename android/openthread_commissioner/{service/src/main/java/io/openthread/commissioner/service => app/src/main/java/io/openthread/commissioner/app}/FragmentCallback.java (97%) rename android/openthread_commissioner/{service/src/main/java/io/openthread/commissioner/service => app/src/main/java/io/openthread/commissioner/app}/InputNetworkPasswordDialogFragment.java (98%) rename android/openthread_commissioner/{service/src/main/java/io/openthread/commissioner/service => app/src/main/java/io/openthread/commissioner/app}/JoinerDeviceInfo.java (98%) rename android/openthread_commissioner/{service/src/main/java/io/openthread/commissioner/service => app/src/main/java/io/openthread/commissioner/app}/MeshcopFragment.java (98%) rename android/openthread_commissioner/{service/src/main/java/io/openthread/commissioner/service => app/src/main/java/io/openthread/commissioner/app}/NativeCommissionerLogger.java (97%) rename android/openthread_commissioner/{service/src/main/java/io/openthread/commissioner/service => app/src/main/java/io/openthread/commissioner/app}/NetworkAdapter.java (92%) rename android/openthread_commissioner/{service/src/main/java/io/openthread/commissioner/service => app/src/main/java/io/openthread/commissioner/app}/ScanQrCodeFragment.java (99%) rename android/openthread_commissioner/{service/src/main/java/io/openthread/commissioner/service => app/src/main/java/io/openthread/commissioner/app}/SelectNetworkFragment.java (98%) rename android/openthread_commissioner/{service/src/main/java/io/openthread/commissioner/service => app/src/main/java/io/openthread/commissioner/app}/ThreadCommissionerException.java (98%) rename android/openthread_commissioner/{service/src/main/java/io/openthread/commissioner/service => app/src/main/java/io/openthread/commissioner/app}/ThreadCommissionerService.java (98%) rename android/openthread_commissioner/{service/src/main/java/io/openthread/commissioner/service => app/src/main/java/io/openthread/commissioner/app}/ThreadCommissionerServiceImpl.java (98%) rename android/openthread_commissioner/{service/src/main/java/io/openthread/commissioner/service => app/src/main/java/io/openthread/commissioner/app}/ThreadNetworkInfo.java (98%) rename android/openthread_commissioner/{service/src/main/java/io/openthread/commissioner/service => app/src/main/java/io/openthread/commissioner/app}/ThreadNetworkInfoHolder.java (98%) rename android/openthread_commissioner/{service => app}/src/main/res/drawable/ic_done_icon.xml (100%) rename android/openthread_commissioner/{service => app}/src/main/res/drawable/ic_error_icon.xml (100%) rename android/openthread_commissioner/{service => app}/src/main/res/drawable/ic_network_selected_icon.xml (100%) rename android/openthread_commissioner/{service => app}/src/main/res/drawable/ic_wireless_network_icon.xml (100%) rename android/openthread_commissioner/{service => app}/src/main/res/layout/activity_commissioner.xml (100%) rename android/openthread_commissioner/{service => app}/src/main/res/layout/fragment_fetch_credential_dialog.xml (100%) rename android/openthread_commissioner/{service => app}/src/main/res/layout/fragment_meshcop.xml (97%) rename android/openthread_commissioner/{service => app}/src/main/res/layout/fragment_network_password_dialog.xml (100%) rename android/openthread_commissioner/{service => app}/src/main/res/layout/fragment_scan_qrcode.xml (91%) rename android/openthread_commissioner/{service => app}/src/main/res/layout/fragment_select_network.xml (100%) rename android/openthread_commissioner/{service => app}/src/main/res/layout/network_list_item.xml (100%) rename android/openthread_commissioner/{service => app}/src/main/res/values/styles.xml (100%) delete mode 100644 android/openthread_commissioner/service/.gitignore delete mode 100644 android/openthread_commissioner/service/build.gradle delete mode 100644 android/openthread_commissioner/service/consumer-rules.pro delete mode 100644 android/openthread_commissioner/service/proguard-rules.pro delete mode 100644 android/openthread_commissioner/service/src/main/AndroidManifest.xml delete mode 100644 android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/CommissionerActivity.java delete mode 100644 android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/CommissionerServiceApp.java delete mode 100644 android/openthread_commissioner/service/src/main/res/values/colors.xml delete mode 100644 android/openthread_commissioner/service/src/main/res/values/strings.xml diff --git a/android/build-commissioner-libs.sh b/android/build-commissioner-libs.sh index 1054904d8..ed9c40e95 100755 --- a/android/build-commissioner-libs.sh +++ b/android/build-commissioner-libs.sh @@ -77,7 +77,7 @@ cd ../../../ ## Copy shared native libraries cp "$BUILD_DIR"/src/java/libcommissioner-java.so "$BUILD_DIR"/libs -mkdir -p openthread_commissioner/service/libs -mkdir -p openthread_commissioner/service/src/main/jniLibs/"${ANDROID_ABI}" -cp "$BUILD_DIR"/libs/libotcommissioner.jar openthread_commissioner/service/libs -cp "$BUILD_DIR"/libs/*.so openthread_commissioner/service/src/main/jniLibs/"${ANDROID_ABI}" +mkdir -p openthread_commissioner/app/libs +mkdir -p openthread_commissioner/app/src/main/jniLibs/"${ANDROID_ABI}" +cp "$BUILD_DIR"/libs/libotcommissioner.jar openthread_commissioner/app/libs +cp "$BUILD_DIR"/libs/*.so openthread_commissioner/app/src/main/jniLibs/"${ANDROID_ABI}" diff --git a/android/openthread_commissioner/.gitignore b/android/openthread_commissioner/.gitignore index aa724b770..f4aeed1df 100644 --- a/android/openthread_commissioner/.gitignore +++ b/android/openthread_commissioner/.gitignore @@ -8,8 +8,10 @@ /.idea/navEditor.xml /.idea/assetWizardSettings.xml .DS_Store -/build +build/ /captures .externalNativeBuild .cxx local.properties +*.jar +*.so diff --git a/android/openthread_commissioner/app/.gitignore b/android/openthread_commissioner/app/.gitignore deleted file mode 100644 index 796b96d1c..000000000 --- a/android/openthread_commissioner/app/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/android/openthread_commissioner/app/build.gradle b/android/openthread_commissioner/app/build.gradle index 45b4ad1f8..6aa612ab2 100644 --- a/android/openthread_commissioner/app/build.gradle +++ b/android/openthread_commissioner/app/build.gradle @@ -78,6 +78,11 @@ android { } } +// This is for the local tests (src/test) to find the native libraries. +tasks.withType(Test) { + systemProperty "java.library.path", "/usr/local/lib" +} + configurations.all { resolutionStrategy { force 'androidx.test:core:1.5.0' @@ -85,12 +90,22 @@ configurations.all { } dependencies { - implementation project(':service') + implementation 'org.jetbrains:annotations:15.0' + def room_version = "2.2.5" + implementation "androidx.room:room-runtime:$room_version" + annotationProcessor "androidx.room:room-compiler:$room_version" + + implementation fileTree(dir: "libs", include: ["*.jar"]) + implementation 'com.google.guava:guava:31.1-jre' implementation 'androidx.appcompat:appcompat:1.2.0' + implementation "androidx.concurrent:concurrent-futures:1.1.0" + implementation 'androidx.constraintlayout:constraintlayout:2.0.2' + implementation 'androidx.navigation:navigation-fragment:2.3.0' + implementation 'com.google.android.gms:play-services-vision:20.1.3+' + implementation 'com.google.android.gms:play-services-threadnetwork:16.0.0' implementation 'com.google.android.material:material:1.2.1' - implementation 'androidx.constraintlayout:constraintlayout:2.0.1' - testImplementation 'junit:junit:4.0' - androidTestImplementation 'androidx.test.ext:junit:1.1.2' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' + androidTestImplementation 'com.google.truth:truth:1.4.4' + androidTestImplementation 'androidx.test.ext:junit:1.1.5' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0' } diff --git a/android/openthread_commissioner/service/src/androidTest/java/io/openthread/commissioner/ActiveOperationalDatasetTest.java b/android/openthread_commissioner/app/src/androidTest/java/io/openthread/commissioner/ActiveOperationalDatasetTest.java similarity index 100% rename from android/openthread_commissioner/service/src/androidTest/java/io/openthread/commissioner/ActiveOperationalDatasetTest.java rename to android/openthread_commissioner/app/src/androidTest/java/io/openthread/commissioner/ActiveOperationalDatasetTest.java diff --git a/android/openthread_commissioner/app/src/main/AndroidManifest.xml b/android/openthread_commissioner/app/src/main/AndroidManifest.xml index b9beb9581..7430cd07b 100644 --- a/android/openthread_commissioner/app/src/main/AndroidManifest.xml +++ b/android/openthread_commissioner/app/src/main/AndroidManifest.xml @@ -1,5 +1,15 @@ + + + + + + + + - diff --git a/android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/BorderAgentDiscoverer.java b/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/BorderAgentDiscoverer.java similarity index 99% rename from android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/BorderAgentDiscoverer.java rename to android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/BorderAgentDiscoverer.java index 6e4214d12..38c1eca3c 100644 --- a/android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/BorderAgentDiscoverer.java +++ b/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/BorderAgentDiscoverer.java @@ -26,7 +26,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -package io.openthread.commissioner.service; +package io.openthread.commissioner.app; import android.Manifest.permission; import android.content.Context; diff --git a/android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/BorderAgentInfo.java b/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/BorderAgentInfo.java similarity index 95% rename from android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/BorderAgentInfo.java rename to android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/BorderAgentInfo.java index 0a9babede..a916be670 100644 --- a/android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/BorderAgentInfo.java +++ b/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/BorderAgentInfo.java @@ -26,7 +26,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -package io.openthread.commissioner.service; +package io.openthread.commissioner.app; import android.os.Parcel; import android.os.Parcelable; @@ -48,9 +48,9 @@ public BorderAgentInfo( @NonNull byte[] extendedPanId, @NonNull InetAddress host, @NonNull int port) { - this.id = id.clone(); + this.id = id == null ? null : id.clone(); this.networkName = networkName; - this.extendedPanId = extendedPanId.clone(); + this.extendedPanId = extendedPanId == null ? null : extendedPanId.clone(); this.host = host; this.port = port; } diff --git a/android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/CameraSourceView.java b/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/CameraSourceView.java similarity index 99% rename from android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/CameraSourceView.java rename to android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/CameraSourceView.java index 7ca189bf8..3b2b30502 100644 --- a/android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/CameraSourceView.java +++ b/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/CameraSourceView.java @@ -26,7 +26,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -package io.openthread.commissioner.service; +package io.openthread.commissioner.app; import android.Manifest; import android.content.Context; diff --git a/android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/CommissionerUtils.java b/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/CommissionerUtils.java similarity index 98% rename from android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/CommissionerUtils.java rename to android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/CommissionerUtils.java index b31748886..952e18d3f 100644 --- a/android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/CommissionerUtils.java +++ b/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/CommissionerUtils.java @@ -26,7 +26,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -package io.openthread.commissioner.service; +package io.openthread.commissioner.app; import androidx.annotation.Nullable; import androidx.concurrent.futures.CallbackToFutureAdapter; diff --git a/android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/Constants.java b/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/Constants.java similarity index 97% rename from android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/Constants.java rename to android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/Constants.java index 92255dfcd..01958487c 100644 --- a/android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/Constants.java +++ b/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/Constants.java @@ -26,7 +26,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -package io.openthread.commissioner.service; +package io.openthread.commissioner.app; public class Constants { public static final String KEY_DEVICE_INFO = "deviceinfo"; diff --git a/android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/FetchCredentialDialogFragment.java b/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/FetchCredentialDialogFragment.java similarity index 99% rename from android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/FetchCredentialDialogFragment.java rename to android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/FetchCredentialDialogFragment.java index 7331e61b3..65b87f8ee 100644 --- a/android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/FetchCredentialDialogFragment.java +++ b/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/FetchCredentialDialogFragment.java @@ -26,7 +26,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -package io.openthread.commissioner.service; +package io.openthread.commissioner.app; import android.app.AlertDialog; import android.app.Dialog; diff --git a/android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/FragmentCallback.java b/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/FragmentCallback.java similarity index 97% rename from android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/FragmentCallback.java rename to android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/FragmentCallback.java index 98aeeb2f4..e147a07dd 100644 --- a/android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/FragmentCallback.java +++ b/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/FragmentCallback.java @@ -26,7 +26,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -package io.openthread.commissioner.service; +package io.openthread.commissioner.app; import androidx.annotation.Nullable; diff --git a/android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/InputNetworkPasswordDialogFragment.java b/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/InputNetworkPasswordDialogFragment.java similarity index 98% rename from android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/InputNetworkPasswordDialogFragment.java rename to android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/InputNetworkPasswordDialogFragment.java index 8e966ad08..104261c18 100644 --- a/android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/InputNetworkPasswordDialogFragment.java +++ b/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/InputNetworkPasswordDialogFragment.java @@ -26,7 +26,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -package io.openthread.commissioner.service; +package io.openthread.commissioner.app; import android.app.AlertDialog; import android.app.Dialog; diff --git a/android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/JoinerDeviceInfo.java b/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/JoinerDeviceInfo.java similarity index 98% rename from android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/JoinerDeviceInfo.java rename to android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/JoinerDeviceInfo.java index aacdc2a61..bea6807f5 100644 --- a/android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/JoinerDeviceInfo.java +++ b/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/JoinerDeviceInfo.java @@ -26,7 +26,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -package io.openthread.commissioner.service; +package io.openthread.commissioner.app; import android.os.Parcel; import android.os.Parcelable; diff --git a/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/MainActivity.java b/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/MainActivity.java index 22df9feca..31ae188c4 100644 --- a/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/MainActivity.java +++ b/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/MainActivity.java @@ -40,12 +40,6 @@ import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentTransaction; -import io.openthread.commissioner.service.FragmentCallback; -import io.openthread.commissioner.service.JoinerDeviceInfo; -import io.openthread.commissioner.service.MeshcopFragment; -import io.openthread.commissioner.service.ScanQrCodeFragment; -import io.openthread.commissioner.service.SelectNetworkFragment; -import io.openthread.commissioner.service.ThreadNetworkInfoHolder; public class MainActivity extends AppCompatActivity implements FragmentCallback { diff --git a/android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/MeshcopFragment.java b/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/MeshcopFragment.java similarity index 98% rename from android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/MeshcopFragment.java rename to android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/MeshcopFragment.java index 2ba0eb6ab..cafa26cb0 100644 --- a/android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/MeshcopFragment.java +++ b/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/MeshcopFragment.java @@ -26,7 +26,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -package io.openthread.commissioner.service; +package io.openthread.commissioner.app; import android.app.Activity; import android.os.Bundle; @@ -67,7 +67,7 @@ public class MeshcopFragment extends Fragment @NonNull private final JoinerDeviceInfo joinerDeviceInfo; private final ThreadCommissionerServiceImpl commissionerService = - ThreadCommissionerServiceImpl.newInstance(this); + ThreadCommissionerServiceImpl.newInstance(getActivity(), this); private ListenableFuture commissionFuture; public MeshcopFragment( diff --git a/android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/NativeCommissionerLogger.java b/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/NativeCommissionerLogger.java similarity index 97% rename from android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/NativeCommissionerLogger.java rename to android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/NativeCommissionerLogger.java index 06031e54e..60afa57fc 100644 --- a/android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/NativeCommissionerLogger.java +++ b/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/NativeCommissionerLogger.java @@ -26,7 +26,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -package io.openthread.commissioner.service; +package io.openthread.commissioner.app; import android.util.Log; import io.openthread.commissioner.LogLevel; diff --git a/android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/NetworkAdapter.java b/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/NetworkAdapter.java similarity index 92% rename from android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/NetworkAdapter.java rename to android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/NetworkAdapter.java index ebb259621..24ef05598 100644 --- a/android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/NetworkAdapter.java +++ b/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/NetworkAdapter.java @@ -26,7 +26,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -package io.openthread.commissioner.service; +package io.openthread.commissioner.app; import android.content.Context; import android.os.Handler; @@ -36,7 +36,7 @@ import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.TextView; -import io.openthread.commissioner.service.BorderAgentDiscoverer.BorderAgentListener; +import io.openthread.commissioner.app.BorderAgentDiscoverer.BorderAgentListener; import java.util.Arrays; import java.util.Vector; @@ -66,7 +66,7 @@ public void addBorderAgent(BorderAgentInfo borderAgent) { networks.add(new ThreadNetworkInfoHolder(borderAgent)); } - new Handler(Looper.getMainLooper()).post(() -> notifyDataSetChanged()); + notifyDataSetChanged(); } public void removeBorderAgent(byte[] lostBorderAgentId) { @@ -78,7 +78,7 @@ public void removeBorderAgent(byte[] lostBorderAgentId) { networks.remove(networkInfoHolder); } - new Handler(Looper.getMainLooper()).post(() -> notifyDataSetChanged()); + notifyDataSetChanged(); return; } } @@ -116,11 +116,11 @@ public View getView(int position, View convertView, ViewGroup container) { @Override public void onBorderAgentFound(BorderAgentInfo borderAgentInfo) { - addBorderAgent(borderAgentInfo); + new Handler(Looper.getMainLooper()).post(() -> addBorderAgent(borderAgentInfo)); } @Override public void onBorderAgentLost(byte[] borderAgentId) { - removeBorderAgent(borderAgentId); + new Handler(Looper.getMainLooper()).post(() -> removeBorderAgent(borderAgentId)); } } diff --git a/android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/ScanQrCodeFragment.java b/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/ScanQrCodeFragment.java similarity index 99% rename from android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/ScanQrCodeFragment.java rename to android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/ScanQrCodeFragment.java index 229a6003d..9ce610d58 100644 --- a/android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/ScanQrCodeFragment.java +++ b/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/ScanQrCodeFragment.java @@ -26,7 +26,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -package io.openthread.commissioner.service; +package io.openthread.commissioner.app; import android.Manifest; import android.app.AlertDialog; diff --git a/android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/SelectNetworkFragment.java b/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/SelectNetworkFragment.java similarity index 98% rename from android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/SelectNetworkFragment.java rename to android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/SelectNetworkFragment.java index c34ede3a4..0a3de0027 100644 --- a/android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/SelectNetworkFragment.java +++ b/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/SelectNetworkFragment.java @@ -26,7 +26,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -package io.openthread.commissioner.service; +package io.openthread.commissioner.app; import android.app.Activity; import android.os.Bundle; @@ -207,7 +207,8 @@ public void onClick(View view) { } ThreadCommissionerServiceImpl commissionerService = - ThreadCommissionerServiceImpl.newInstance(null); + ThreadCommissionerServiceImpl.newInstance( + getActivity(), /* intermediateStateCallback= */ null); FluentFuture.from(commissionerService.getThreadNetworkCredentials(selectedBorderAgent)) .addCallback( diff --git a/android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/ThreadCommissionerException.java b/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/ThreadCommissionerException.java similarity index 98% rename from android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/ThreadCommissionerException.java rename to android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/ThreadCommissionerException.java index 2d8512b23..acec43adf 100644 --- a/android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/ThreadCommissionerException.java +++ b/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/ThreadCommissionerException.java @@ -26,7 +26,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -package io.openthread.commissioner.service; +package io.openthread.commissioner.app; import androidx.annotation.NonNull; import io.openthread.commissioner.ErrorCode; diff --git a/android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/ThreadCommissionerService.java b/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/ThreadCommissionerService.java similarity index 98% rename from android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/ThreadCommissionerService.java rename to android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/ThreadCommissionerService.java index 87add5fca..25c233a18 100644 --- a/android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/ThreadCommissionerService.java +++ b/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/ThreadCommissionerService.java @@ -26,7 +26,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -package io.openthread.commissioner.service; +package io.openthread.commissioner.app; import androidx.annotation.NonNull; import com.google.android.gms.threadnetwork.ThreadNetworkCredentials; diff --git a/android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/ThreadCommissionerServiceImpl.java b/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/ThreadCommissionerServiceImpl.java similarity index 98% rename from android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/ThreadCommissionerServiceImpl.java rename to android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/ThreadCommissionerServiceImpl.java index e2490118e..0db8ebee6 100644 --- a/android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/ThreadCommissionerServiceImpl.java +++ b/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/ThreadCommissionerServiceImpl.java @@ -26,8 +26,9 @@ * POSSIBILITY OF SUCH DAMAGE. */ -package io.openthread.commissioner.service; +package io.openthread.commissioner.app; +import android.content.Context; import android.os.ConditionVariable; import android.util.Log; import androidx.annotation.NonNull; @@ -77,9 +78,9 @@ public interface IntermediateStateCallback { private ConditionVariable curJoinerCommissioned = new ConditionVariable(); public static ThreadCommissionerServiceImpl newInstance( - @Nullable IntermediateStateCallback intermediateStateCallback) { + Context context, @Nullable IntermediateStateCallback intermediateStateCallback) { return new ThreadCommissionerServiceImpl( - ThreadNetwork.getClient(CommissionerServiceApp.getContext()), + ThreadNetwork.getClient(context), Executors.newSingleThreadExecutor(), intermediateStateCallback); } diff --git a/android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/ThreadNetworkInfo.java b/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/ThreadNetworkInfo.java similarity index 98% rename from android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/ThreadNetworkInfo.java rename to android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/ThreadNetworkInfo.java index 87b6b4036..6afed98df 100644 --- a/android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/ThreadNetworkInfo.java +++ b/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/ThreadNetworkInfo.java @@ -26,7 +26,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -package io.openthread.commissioner.service; +package io.openthread.commissioner.app; import android.os.Parcel; import android.os.Parcelable; diff --git a/android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/ThreadNetworkInfoHolder.java b/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/ThreadNetworkInfoHolder.java similarity index 98% rename from android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/ThreadNetworkInfoHolder.java rename to android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/ThreadNetworkInfoHolder.java index 9aa068437..59b27fc32 100644 --- a/android/openthread_commissioner/service/src/main/java/io/openthread/commissioner/service/ThreadNetworkInfoHolder.java +++ b/android/openthread_commissioner/app/src/main/java/io/openthread/commissioner/app/ThreadNetworkInfoHolder.java @@ -26,7 +26,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -package io.openthread.commissioner.service; +package io.openthread.commissioner.app; import android.os.Parcel; import android.os.Parcelable; diff --git a/android/openthread_commissioner/service/src/main/res/drawable/ic_done_icon.xml b/android/openthread_commissioner/app/src/main/res/drawable/ic_done_icon.xml similarity index 100% rename from android/openthread_commissioner/service/src/main/res/drawable/ic_done_icon.xml rename to android/openthread_commissioner/app/src/main/res/drawable/ic_done_icon.xml diff --git a/android/openthread_commissioner/service/src/main/res/drawable/ic_error_icon.xml b/android/openthread_commissioner/app/src/main/res/drawable/ic_error_icon.xml similarity index 100% rename from android/openthread_commissioner/service/src/main/res/drawable/ic_error_icon.xml rename to android/openthread_commissioner/app/src/main/res/drawable/ic_error_icon.xml diff --git a/android/openthread_commissioner/service/src/main/res/drawable/ic_network_selected_icon.xml b/android/openthread_commissioner/app/src/main/res/drawable/ic_network_selected_icon.xml similarity index 100% rename from android/openthread_commissioner/service/src/main/res/drawable/ic_network_selected_icon.xml rename to android/openthread_commissioner/app/src/main/res/drawable/ic_network_selected_icon.xml diff --git a/android/openthread_commissioner/service/src/main/res/drawable/ic_wireless_network_icon.xml b/android/openthread_commissioner/app/src/main/res/drawable/ic_wireless_network_icon.xml similarity index 100% rename from android/openthread_commissioner/service/src/main/res/drawable/ic_wireless_network_icon.xml rename to android/openthread_commissioner/app/src/main/res/drawable/ic_wireless_network_icon.xml diff --git a/android/openthread_commissioner/service/src/main/res/layout/activity_commissioner.xml b/android/openthread_commissioner/app/src/main/res/layout/activity_commissioner.xml similarity index 100% rename from android/openthread_commissioner/service/src/main/res/layout/activity_commissioner.xml rename to android/openthread_commissioner/app/src/main/res/layout/activity_commissioner.xml diff --git a/android/openthread_commissioner/service/src/main/res/layout/fragment_fetch_credential_dialog.xml b/android/openthread_commissioner/app/src/main/res/layout/fragment_fetch_credential_dialog.xml similarity index 100% rename from android/openthread_commissioner/service/src/main/res/layout/fragment_fetch_credential_dialog.xml rename to android/openthread_commissioner/app/src/main/res/layout/fragment_fetch_credential_dialog.xml diff --git a/android/openthread_commissioner/service/src/main/res/layout/fragment_meshcop.xml b/android/openthread_commissioner/app/src/main/res/layout/fragment_meshcop.xml similarity index 97% rename from android/openthread_commissioner/service/src/main/res/layout/fragment_meshcop.xml rename to android/openthread_commissioner/app/src/main/res/layout/fragment_meshcop.xml index d2f55e18f..15f21dc97 100644 --- a/android/openthread_commissioner/service/src/main/res/layout/fragment_meshcop.xml +++ b/android/openthread_commissioner/app/src/main/res/layout/fragment_meshcop.xml @@ -4,7 +4,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context="io.openthread.commissioner.service.CommissionerActivity"> + tools:context=".MainActivity"> + tools:context=".MainActivity"> - + app:layout_constraintTop_toBottomOf="@id/title_text">