Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,31 @@ android {
jvmTarget = '17'
}

// whether or not to build with the native Rust uStreamer
flavorDimensions = ["ustreamer"]
productFlavors {
withUStreamer {
// Assigns this product flavor to the "version" flavor dimension.
// If you are using only one dimension, this property is optional,
// and the plugin automatically assigns all the module's flavors to
// that dimension.
dimension "ustreamer"
}
withoutUStreamer {
dimension "ustreamer"
}
}

sourceSets {
main {
jniLibs.srcDirs = []
withUStreamer {
java {
srcDirs 'src/main/withUStreamer/java'
}
}
withoutUStreamer {
java {
srcDirs 'src/main/withoutUStreamer/java'
}
}
test.assets.srcDirs += files("$projectDir/src/test/".toString())
}
Expand Down
7 changes: 7 additions & 0 deletions service/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,12 @@
<action android:name="uprotocol.action.BIND_UBUS"/>
</intent-filter>
</service>

<meta-data
android:name="uprotocol.entity.name"
android:value="ustreamer_glue" />
<meta-data
android:name="uprotocol.entity.version"
android:value="1" />
</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.eclipse.uprotocol.common.util.log.Formatter;
import org.eclipse.uprotocol.common.util.log.Key;
import org.eclipse.uprotocol.core.ubus.UBusAdapter;
import org.eclipse.uprotocol.core.ustreamer.UStreamerManager;

import java.io.FileDescriptor;
import java.io.PrintWriter;
Expand All @@ -47,6 +48,7 @@ public class UCoreService extends Service {
private static final String TAG = Formatter.tag("core", "UCoreService");
private UCore mUCore;
private UBusAdapter mUBusAdapter;
private UStreamerManager mUStreamerManager;

public UCoreService() {
//Nothing to do
Expand All @@ -59,6 +61,9 @@ public void onCreate() {
mUCore = newUCore(this);
mUCore.init();
mUCore.startup();

mUStreamerManager = new UStreamerManager(this);
mUStreamerManager.connect();
}

@VisibleForTesting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ protected void clearCache() {

public @NonNull <T> UStatus registerClient(@NonNull String packageName, @NonNull UEntity entity,
@NonNull IBinder clientToken, @NonNull T listener) {
// TODO: PELE - Remove this logging eventually
Log.d(TAG, "ParcelableUEntity: " + entity);

return mClientManager.registerClient(packageName, entity, clientToken, listener);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public UBusAdapter(@NonNull UBus uBus) {
public ParcelableUStatus registerClient(String packageName, ParcelableUEntity entity, IBinder clientToken,
int flags, IUListener listener) {
try {
// TODO: PELE - Remove this logging eventually
Log.d("UBusAdapter", "ParcelableUEntity: " + entity);

return new ParcelableUStatus(mUBus.registerClient(packageName, entity.getWrapped(), clientToken, listener));
} catch (Exception e) {
return new ParcelableUStatus(toStatus(e));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ private static void checkCallerCredentials(int pid, int uid, @NonNull Client cli
public @NonNull <T> UStatus registerClient(@NonNull String packageName, @NonNull UEntity entity,
@NonNull IBinder clientToken, @NonNull T listener) {
try {
// TODO: PELE - Remove this logging eventually
Log.d(TAG, "ParcelableUEntity: " + entity);

checkStringNotEmpty(packageName, "Package name is empty");
checkStringNotEmpty(entity.getName(), "Entity name is empty");
checkArgument(entity.hasVersionMajor(), "Entity version is empty");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.eclipse.uprotocol.core.ustreamer;

import static android.content.Context.BIND_AUTO_CREATE;
import static java.util.Objects.requireNonNull;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.util.Log;

import androidx.annotation.NonNull;


public class UStreamerManager {

private static final String TAG = "UStreamerManager";

private final Context mContext;
private boolean mServiceBound;

public static final String ACTION_BIND_UBUS = "uprotocol.action.BIND_UBUS";

private final ServiceConnection mServiceConnectionCallback = new ServiceConnection() {

@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
Log.i(TAG, "inside mServiceConnectionCallback onServiceConnected()");
Log.d(TAG, UStreamerGlue.forwardJavaBinder(iBinder));
}

@Override
public void onServiceDisconnected(ComponentName componentName) {

}

@Override
public void onBindingDied(ComponentName name) {
ServiceConnection.super.onBindingDied(name);
}

@Override
public void onNullBinding(ComponentName name) {
ServiceConnection.super.onNullBinding(name);
}
};

public UStreamerManager(@NonNull Context context) {
mContext = requireNonNull(context);
Log.i(TAG, "inside UStreamerManager constructor");
}

public boolean connect() {
Log.i(TAG, "inside UStreamerManager connect()");
final Intent intent = new Intent(ACTION_BIND_UBUS);
String mServiceConfig = "org.eclipse.uprotocol.core";
intent.setPackage(mServiceConfig);
Log.d(TAG, "intent: " + intent);
mServiceBound = mContext.bindService(intent, mServiceConnectionCallback, BIND_AUTO_CREATE);
Log.i(TAG, "Made it back from calling into Rust!");
return mServiceBound;
}
}
Empty file.
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions service/src/main/rust/ustreamer_bridge/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/target

.idea/
Loading