Skip to content
Snippets Groups Projects
Commit 121caab8 authored by Sebastian's avatar Sebastian
Browse files

Add basic Mobly interaction into app

parent 2d3247bb
No related branches found
No related tags found
No related merge requests found
# Mobly LSD branch (Lan Service Discovery)
This branch has some RPC functionality built in so that the testbed app can
be remote-controlled from a host system and using mobly end-to-end testing
infrastructure.
You need to have Mobly installed to be able to execute any of the following
commands. Consult the projects [README](https://github.com/google/mobly#installation)
on instructions. In short, you can run `pip install mobly`.
After installing the APK built from this branch onto a device, for example
from AS, you can launch the snippet shell with our package name passed as
the first argument:
snippet_shell.py org.briarproject.publicmesh
This will put you into the REPL. From there you can go on:
>>> s.help()
RPCs provided by PublicMeshSnippet:
@Rpc startActivity() returns void // Launches the main activity.
@Rpc startAdvertising() returns void // Starts advertising this node.
@Rpc startDiscovery() returns void // Starts discovering other nodes.
@Rpc stopAdvertising() returns void // Stops advertising this node.
@Rpc stopDiscovery() returns void // Stops discovering other nodes.
you can call the remote procedure `startActivity()` etc:
>>> s.startActivity()
>>> s.startAdvertising()
>>> s.startDiscovery()
......@@ -7,7 +7,7 @@ android {
defaultConfig {
applicationId "org.briarproject.publicmesh"
minSdk 21
minSdk 26
targetSdk 32
versionCode 1
versionName "0.0.1"
......@@ -31,6 +31,8 @@ dependencies {
implementation 'com.google.dagger:dagger:2.40'
implementation 'com.google.code.findbugs:jsr305:3.0.2'
implementation 'org.briarproject:null-safety:0.1'
implementation 'com.google.android.mobly:mobly-snippet-lib:1.3.1'
implementation 'androidx.test:runner:1.3.0'
annotationProcessor 'com.google.dagger:dagger-compiler:2.40'
}
\ No newline at end of file
}
......@@ -21,6 +21,10 @@
android:supportsRtl="true"
android:theme="@style/Theme.PublicMesh">
<meta-data
android:name="mobly-snippets"
android:value="org.briarproject.publicmesh.PublicMeshSnippet" />
<service
android:name=".MeshService"
android:enabled="true"
......@@ -40,4 +44,8 @@
</application>
</manifest>
\ No newline at end of file
<instrumentation
android:name="com.google.android.mobly.snippet.SnippetRunner"
android:targetPackage="org.briarproject.publicmesh" />
</manifest>
......@@ -40,6 +40,8 @@ public interface AppComponent {
void inject(PermissionsFragment f);
void inject(PublicMeshSnippet f);
class Helper {
public static void injectEagerSingletons(AppComponent c) {
c.inject(new LanModule.EagerSingletons());
......
......@@ -149,4 +149,4 @@ public class MainFragment extends BaseFragment {
private void onLocalAddress(String address) {
ownAddress.setText(getString(R.string.own_address, address));
}
}
\ No newline at end of file
}
package org.briarproject.publicmesh;
import android.content.Context;
import android.content.Intent;
import com.google.android.mobly.snippet.Snippet;
import com.google.android.mobly.snippet.rpc.Rpc;
import org.briarproject.publicmesh.lan.LsdService;
import java.util.logging.Logger;
import javax.inject.Inject;
import androidx.test.platform.app.InstrumentationRegistry;
import static java.util.logging.Logger.getLogger;
public class PublicMeshSnippet implements Snippet {
private static final Logger LOG = getLogger(PublicMeshSnippet.class.getName());
private final Context ctx;
@Inject
LsdService service;
public PublicMeshSnippet() {
ctx = InstrumentationRegistry.getInstrumentation().getContext();
MeshApplication app = (MeshApplication) ctx.getApplicationContext();
app.getAppComponent().inject(this);
}
@Rpc(description = "Launches the main activity.")
public void startActivity() {
Intent intent = new Intent(ctx, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ctx.startActivity(intent);
}
@Rpc(description = "Starts advertising this node.")
public void startAdvertising() {
LOG.info("starting advertising");
service.startAdvertising();
}
@Rpc(description = "Stops advertising this node.")
public void stopAdvertising() {
LOG.info("stopping advertising");
service.stopAdvertising();
}
@Rpc(description = "Starts discovering other nodes.")
public void startDiscovery() {
LOG.info("starting discovery");
service.startDiscovery();
}
@Rpc(description = "Stops discovering other nodes.")
public void stopDiscovery() {
LOG.info("stopping discovery");
service.stopDiscovery();
}
@Override
public void shutdown() {
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment