Skip to content

Commit

Permalink
[android] cleanup Android sample app
Browse files Browse the repository at this point in the history
  • Loading branch information
wgtdkp committed May 11, 2024
1 parent 7b12b9f commit 7c8b44c
Show file tree
Hide file tree
Showing 22 changed files with 245 additions and 665 deletions.
2 changes: 1 addition & 1 deletion android/openthread_commissioner/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ android {

defaultConfig {
applicationId "io.openthread.commissioner.app"
minSdkVersion 24
minSdkVersion 26
targetSdkVersion 34
versionCode 1
versionName "0.0.1"
Expand Down
5 changes: 5 additions & 0 deletions android/openthread_commissioner/examples/qrcode/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# QR code

- file `v=1&&eui=0000b57fffe15d68&&cc=J01NU5.png` is the Thread joiner device QR
code which encodes the joiner EUI and PSKd as a text string (the content
is `v=1&&eui=0000b57fffe15d68&&cc=J01NU5`)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion android/openthread_commissioner/service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ android {
compileSdkVersion 34

defaultConfig {
minSdkVersion 24
minSdkVersion 26
targetSdkVersion 34

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down Expand Up @@ -73,10 +73,13 @@ dependencies {

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'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import android.net.nsd.NsdServiceInfo;
import android.net.wifi.WifiManager;
import android.util.Log;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresPermission;
import java.util.Map;
import java.util.concurrent.ArrayBlockingQueue;
Expand All @@ -47,7 +48,7 @@ public class BorderAgentDiscoverer implements NsdManager.DiscoveryListener {
private static final String TAG = BorderAgentDiscoverer.class.getSimpleName();

private static final String SERVICE_TYPE = "_meshcop._udp";
private static final String KEY_DISCRIMINATOR = "discriminator";
private static final String KEY_ID = "id";
private static final String KEY_NETWORK_NAME = "nn";
private static final String KEY_EXTENDED_PAN_ID = "xp";

Expand All @@ -62,9 +63,10 @@ public class BorderAgentDiscoverer implements NsdManager.DiscoveryListener {
private boolean isScanning = false;

public interface BorderAgentListener {

void onBorderAgentFound(BorderAgentInfo borderAgentInfo);

void onBorderAgentLost(String discriminator);
void onBorderAgentLost(byte[] id);
}

@RequiresPermission(permission.INTERNET)
Expand Down Expand Up @@ -182,10 +184,10 @@ public void onServiceFound(NsdServiceInfo nsdServiceInfo) {

@Override
public void onServiceLost(NsdServiceInfo nsdServiceInfo) {
String discriminator = getBorderAgentDiscriminator(nsdServiceInfo);
if (discriminator != null) {
Log.d(TAG, "a Border Agent service is gone");
borderAgentListener.onBorderAgentLost(discriminator);
byte[] id = getBorderAgentId(nsdServiceInfo);
if (id != null) {
Log.d(TAG, "a Border Agent service is gone: " + nsdServiceInfo.getServiceName());
borderAgentListener.onBorderAgentLost(id);
}
}

Expand All @@ -199,40 +201,29 @@ public void onStopDiscoveryFailed(String serviceType, int errorCode) {
Log.d(TAG, "stop discovering Border Agent failed: " + errorCode);
}

@Nullable
private BorderAgentInfo getBorderAgentInfo(NsdServiceInfo serviceInfo) {
Map<String, byte[]> attrs = serviceInfo.getAttributes();

// Use the host address as default discriminator.
String discriminator = serviceInfo.getHost().getHostAddress();

if (attrs.containsKey(KEY_DISCRIMINATOR)) {
discriminator = new String(attrs.get(KEY_DISCRIMINATOR));
}
byte[] id = getBorderAgentId(serviceInfo);

if (!attrs.containsKey(KEY_NETWORK_NAME) || !attrs.containsKey(KEY_EXTENDED_PAN_ID)) {
return null;
}

return new BorderAgentInfo(
discriminator,
id,
new String(attrs.get(KEY_NETWORK_NAME)),
attrs.get(KEY_EXTENDED_PAN_ID),
serviceInfo.getHost(),
serviceInfo.getPort());
}

private String getBorderAgentDiscriminator(NsdServiceInfo serviceInfo) {
@Nullable
private byte[] getBorderAgentId(NsdServiceInfo serviceInfo) {
Map<String, byte[]> attrs = serviceInfo.getAttributes();

if (attrs.containsKey(KEY_DISCRIMINATOR)) {
return new String(attrs.get(KEY_DISCRIMINATOR));
}

if (serviceInfo.getHost() != null) {
// Use the host address as default discriminator.
return serviceInfo.getHost().getHostAddress();
if (attrs.containsKey(KEY_ID)) {
return attrs.get(KEY_ID).clone();
}

return null;
}
}
Loading

0 comments on commit 7c8b44c

Please sign in to comment.