Skip to content

Commit

Permalink
[android] consolidate "app" and "service" into a single gradle project
Browse files Browse the repository at this point in the history
  • Loading branch information
wgtdkp committed Aug 10, 2024
1 parent 639e627 commit 8fdf200
Show file tree
Hide file tree
Showing 49 changed files with 96 additions and 387 deletions.
8 changes: 4 additions & 4 deletions android/build-commissioner-libs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
4 changes: 3 additions & 1 deletion android/openthread_commissioner/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
build/
/captures
.externalNativeBuild
.cxx
local.properties
*.jar
*.so
1 change: 0 additions & 1 deletion android/openthread_commissioner/app/.gitignore

This file was deleted.

25 changes: 20 additions & 5 deletions android/openthread_commissioner/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,34 @@ 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'
}
}

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'
}
11 changes: 10 additions & 1 deletion android/openthread_commissioner/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-feature
android:name="android.hardware.camera"
android:required="false" />

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
Expand All @@ -14,7 +24,6 @@
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/

package io.openthread.commissioner.service;
package io.openthread.commissioner.app;

import androidx.annotation.Nullable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Void> commissionFuture;

public MeshcopFragment(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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) {
Expand All @@ -78,7 +78,7 @@ public void removeBorderAgent(byte[] lostBorderAgentId) {
networks.remove(networkInfoHolder);
}

new Handler(Looper.getMainLooper()).post(() -> notifyDataSetChanged());
notifyDataSetChanged();
return;
}
}
Expand Down Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<ProgressBar
android:id="@+id/commissioning_progress"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<TextView
android:id="@+id/title_text"
Expand All @@ -16,7 +16,7 @@
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<io.openthread.commissioner.service.CameraSourceView
<io.openthread.commissioner.app.CameraSourceView
android:id="@+id/camera_view"
android:layout_width="0dp"
android:layout_height="0dp"
Expand All @@ -26,7 +26,7 @@
app:layout_constraintBottom_toTopOf="@+id/scan_instruction_text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/title_text"></io.openthread.commissioner.service.CameraSourceView>
app:layout_constraintTop_toBottomOf="@id/title_text"></io.openthread.commissioner.app.CameraSourceView>
<Button
android:id="@+id/cancel_button"
android:layout_width="wrap_content"
Expand Down
Loading

0 comments on commit 8fdf200

Please sign in to comment.