Skip to content

Commit eaa2392

Browse files
committed
Use the Mobile API Android package
- the API files were removed from the repo, they are now distributed as an Android package from the GitHub Gradle registry, this repo now only contains the example app - the GitHub Gradle registry requires authentication, the setup is documented in the README file - the API documentation and sources are distributed in the package - the API documentation is also available on GitHub Pages: https://clariusdev.github.io/mobileapi/reference/9.4.0/ - added "sdk" in the package name: me.clarius.sdk.mobileapi
1 parent ccbc173 commit eaa2392

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+651
-1418
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
.gradle
33
.idea
44
/local.properties
5+
/secrets.properties
56
.DS_Store
67
/build
78
/captures

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Changelog
22
=========
33

4+
# 9.4.0
5+
6+
Changed:
7+
- The Mobile API is now distributed as an Android Package in the GitHub Gradle registry.
8+
- Renamed package from `me.clarius.mobileapi` to `me.clarius.sdk.mobileapi`.
9+
410
# 9.3.0
511

612
Fixed:

README.md

+46-13
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,41 @@ It also supports sending user commands such as changing the imaging depth or tak
1414
Note: Virtual scanners are supported without a license since version 8.0.1.
1515

1616

17-
# Quickstart
17+
# SDK reference
18+
19+
https://clariusdev.github.io/mobileapi/reference/9.4.0
20+
21+
22+
# Get the package
23+
24+
Starting with Clarius App version 9.4.0, the Mobile API is distributed as an Android package.
25+
The package is hosted in the GitHub Gradle registry which requires authentication (a GitHub account is needed).
26+
27+
1. Generate a GitHub Personal Access Token (PAT) with the `read:packages` scope.
28+
Refer to the [GitHub documentation][github-pat] for instructions to generate tokens.
29+
30+
1. Create a file `secrets.properties` in the project's root folder (which will be read by the Gradle build script) with the following content:
31+
32+
// file /secrets.properties
33+
// do not put quotes (') around the values
34+
gpr.user=your_user_name
35+
gpr.token=personal_access_token_with_read_packages_scope
36+
37+
3. Alternatively, if the secrets file is missing, the build script will attempt to read the environment variables `GITHUB_ACTOR` and `GITHUB_TOKEN`.
38+
39+
[github-pat]: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token
40+
[github-gradle]: https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-gradle-registry#using-a-published-package
41+
42+
43+
# Quick start
1844

1945
1. On your Android device, start the Clarius App and connect to your scanner.
2046

21-
2. Open this project in Android Studio, select the Quickstart App and run it on your Android device.
47+
2. Open this project in Android Studio and run the example application on your Android device.
2248

23-
3. Optional: run both apps in split screen, otherwise let the Clarius App run in the background.
49+
3. Optional: run both applications in split screen, otherwise let the Clarius App run in the background.
2450

25-
4. In the Quickstart App, select Menu `` > `connect` to start receiving images.
51+
4. In the example application, select Menu `` > `connect` to start receiving images.
2652

2753
<img height="450px" alt="connection menu" src="images/quickstart_connect.png"/>
2854

@@ -34,7 +60,7 @@ Usage:
3460

3561
* Menu `` > `Ask *`: obtain imaging information, like the current depth or gain.
3662

37-
* Menu `` > `settings`: configure the image sent over the Mobile API (this is the image rendered by the Clarius App and transmitted over the Mobile API).
63+
* Menu `` > `settings`: configure the image rendered by the Clarius App and sent over the API.
3864

3965

4066
# Architecture
@@ -63,32 +89,36 @@ The Clarius App takes care of connecting to the probe and pre-processing the ima
6389
| |
6490
+-----------------------+
6591

92+
6693
# API Description
6794

6895
On Android, the Mobile API is implemented as an Android _Bound Service_ running in the Clarius App itself.
69-
Refer to the Android developer guide for details about bound services.
70-
https://developer.android.com/guide/components/bound-services
96+
Refer to the [Android developer guide](android-bound-services) for details about bound services.
7197

7298
The interface to the bound service is provided by an Android _Messenger_.
7399
Android Messengers allow interprocess communications (IPC) by exchanging `Message` objects containing an action code and a payload.
74100
The sequence of messages and their content constitute the communication protocol which is described below.
75101

102+
[android-bound-services]: https://developer.android.com/guide/components/bound-services
103+
76104

77105
# Protocol
78106

79-
1. The client binds to the service by calling `Context.bindService()` and receives the server's `IBinder`. This `IBinder` is used to create a Messenger that can send messages _to the server_.
80-
2. The client sends its own Messenger to the server in the `replyTo` field of a `Message` object with code `MSG_REGISTER_CLIENT`. This Messenger is used by the server to send messages _to the client_.
107+
1. The client binds to the service by calling `Context.bindService()` and receives the server's `IBinder`.
108+
This `IBinder` is used to create a Messenger that can send messages _to the server_.
109+
2. The client sends its own Messenger to the server in the `replyTo` field of a `Message` object with code `MSG_REGISTER_CLIENT`.
110+
This Messenger is used by the server to send messages _to the client_.
81111
3. The client sends the image configuration to the server (`MSG_CONFIGURE_IMAGE`).
82112
4. During operation, the server will send the image data to the client (`MSG_NEW_PROCESSED_IMAGE`) and other notable events such as button presses, freeze state, etc.
83113
5. The client can request the execution of predefined functions such as "increase depth" or "capture image" (`MSG_USER_FN`).
84114

85-
All messages and their associated payload are described in the [MobileApi.java](mobileapi/src/main/java/me/clarius/mobileapi/MobileApi.java) file.
115+
All messages and their associated payload are described in the https://clariusdev.github.io/mobileapi repository.
86116

87117

88118
# Licensing
89119

90120
The service operates only when the Clarius App is connected to a scanner with the appropriate license.
91-
Contact Clarius for details: https://clarius.com/contact/
121+
Contact Clarius for licensing options: https://clarius.com/contact/.
92122

93123
However, the service accepts binding requests from clients even when no proper license is active to accommodate workflows where the license is removed for legitimate reasons, for example when a probe is disconnected to save battery.
94124
In this case, the service enters a restricted mode where it stops handling requests and sending updates, but will resume normal operation as soon as a licensed scanner is connected again.
@@ -98,12 +128,13 @@ The license check workflow is as follows:
98128
1. The client binds to the service
99129
2. The service starts and accepts the bind request, regardless of the license status
100130
3. Depending on the current license status:
101-
- if active, the service operates normally: all client requests are handled and all updates are sent to the clients;
131+
- if active, the service operates normally: all client requests are handled and all updates are sent to the clients
102132
- if inactive, the service enters restricted mode: no update is sent (except `MSG_LICENSE_UPDATE`) and no client request is handled (except `MSG_REGISTER_CLIENT` and `MSG_UNREGISTER_CLIENT`). The service will reply `MSG_NO_LICENSE` to any other request
103133
4. If the license status changes during operation, the service sends `MSG_LICENSE_UPDATE` and changes its mode of operation:
104134
- if the license becomes inactive: the service clears the image configuration and enter restricted mode
105135
- if the license becomes active: the service resumes normal operations, but the client must re-send the image configuration
106136

137+
107138
# Raw Data
108139

109140
Workflow to obtain raw data:
@@ -115,7 +146,9 @@ Workflow to obtain raw data:
115146
- notify the client with `MSG_RAW_DATA_AVAILABLE`
116147
3. In the client, send `MSG_COPY_RAW_DATA` to request a copy, include the following data:
117148
- the capture's identifier and
118-
- and a writable URI where the archive will be written, see https://developer.android.com/training/secure-file-sharing for details
149+
- and a writable URI where the archive will be written, refer to the [Android developer guide](android-file-sharing) for details about file sharing
119150
4. In the client, wait for the reply in message `MSG_RAW_DATA_COPIED`
120151

121152
Note: it is possible to trigger a capture via the Mobile API with `MSG_USER_FN`.
153+
154+
[android-file-sharing]: https://developer.android.com/training/secure-file-sharing

build.gradle

+13-2
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,31 @@ buildscript {
55
mavenCentral()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:7.0.0'
8+
classpath 'com.android.tools.build:gradle:7.2.1'
99

1010
// NOTE: Do not place your application dependencies here; they belong
1111
// in the individual module build.gradle files
1212
}
1313
}
1414

1515
allprojects {
16+
def secrets = new Properties()
17+
secrets.load(new FileInputStream(rootProject.file("secrets.properties")))
1618
repositories {
1719
google()
1820
mavenCentral()
21+
mavenLocal()
22+
maven {
23+
name = 'GitHubPackages'
24+
url = uri('https://maven.pkg.github.com/clariusdev/mobileapi')
25+
credentials {
26+
username = secrets['gpr.user'] ?: System.getenv('GITHUB_ACTOR')
27+
password = secrets['gpr.token'] ?: System.getenv('GITHUB_TOKEN')
28+
}
29+
}
1930
}
2031
}
2132

2233
task clean(type: Delete) {
2334
delete rootProject.buildDir
24-
}
35+
}
File renamed without changes.

example/build.gradle

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
plugins {
2+
id 'com.android.application'
3+
}
4+
5+
android {
6+
compileSdk 32
7+
8+
defaultConfig {
9+
applicationId "me.clarius.sdk.mobileapi.example"
10+
minSdk 26
11+
targetSdk 32
12+
versionCode 1
13+
versionName "1.0"
14+
15+
buildConfigField("String", "CLARIUS_PACKAGE_NAME", clariusPackageName)
16+
buildConfigField("String", "CLARIUS_SERVICE_NAME", clariusServiceName)
17+
buildConfigField("String", "FILE_PROVIDER_NAME", fileProviderName)
18+
buildConfigField("String", "FILE_PROVIDER_PATH", fileProviderPath)
19+
}
20+
21+
buildTypes {
22+
release {
23+
minifyEnabled false
24+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
25+
}
26+
}
27+
28+
compileOptions {
29+
sourceCompatibility JavaVersion.VERSION_1_8
30+
targetCompatibility JavaVersion.VERSION_1_8
31+
}
32+
33+
buildFeatures {
34+
viewBinding true
35+
}
36+
}
37+
38+
dependencies {
39+
implementation 'androidx.appcompat:appcompat:1.4.1'
40+
implementation 'com.google.android.material:material:1.6.0'
41+
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
42+
implementation 'androidx.navigation:navigation-fragment:2.4.2'
43+
implementation 'androidx.navigation:navigation-ui:2.4.2'
44+
implementation 'androidx.preference:preference:1.2.0'
45+
implementation 'me.clarius.sdk:mobileapi:9.4.0-SNAPSHOT'
46+
implementation project(path: ':helper')
47+
}
File renamed without changes.

quickstart/src/main/AndroidManifest.xml example/src/main/AndroidManifest.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="me.clarius.mobileapi.quickstart">
3+
package="me.clarius.sdk.mobileapi.example">
44

55
<queries>
66
<package android:name="me.clarius.clarius" />
77
<package android:name="me.clarius.clarius.release" />
8+
<package android:name="me.clarius.clarius.develop.developer.debug" />
89
</queries>
910

1011
<application
@@ -20,7 +21,6 @@
2021
android:exported="true">
2122
<intent-filter>
2223
<action android:name="android.intent.action.MAIN" />
23-
2424
<category android:name="android.intent.category.LAUNCHER" />
2525
</intent-filter>
2626
</activity>
@@ -30,7 +30,7 @@
3030
</activity>
3131
<provider
3232
android:name="androidx.core.content.FileProvider"
33-
android:authorities="me.clarius.mobileapi.quickstart.fileprovider"
33+
android:authorities="me.clarius.sdk.mobileapi.FileProvider"
3434
android:exported="false"
3535
android:grantUriPermissions="true">
3636
<meta-data

quickstart/src/main/java/me/clarius/mobileapi/quickstart/ImageFragment.java example/src/main/java/me/clarius/sdk/mobileapi/example/ImageFragment.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package me.clarius.mobileapi.quickstart;
1+
package me.clarius.sdk.mobileapi.example;
22

33
import android.os.Bundle;
44
import android.view.LayoutInflater;

quickstart/src/main/java/me/clarius/mobileapi/quickstart/ImageViewModel.java example/src/main/java/me/clarius/sdk/mobileapi/example/ImageViewModel.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package me.clarius.mobileapi.quickstart;
1+
package me.clarius.sdk.mobileapi.example;
22

33
import android.graphics.Bitmap;
44

@@ -7,7 +7,7 @@
77
import androidx.lifecycle.ViewModel;
88

99
/**
10-
* Communication with fragments
10+
* Share data from activity to fragments.
1111
* <p>
1212
* https://developer.android.com/guide/fragments/communicate
1313
*/

0 commit comments

Comments
 (0)