From a305c791e58337f3967078d7230ff5ba8560a922 Mon Sep 17 00:00:00 2001 From: raihan <54474184+ryihan@users.noreply.github.com> Date: Tue, 26 Oct 2021 03:51:34 +0600 Subject: [PATCH] Update --- .../cpp/exampleclient/ButtonPressHandler.java | 15 ++ .../cpp/exampleclient/MainActivity.java | 26 +++ .../cpp/exampleserver/ButtonPressHandler.java | 13 ++ .../ExportedEndpointService.java | 25 +++ .../cpp/exampleserver/MainActivity.java | 27 +++ .../cpp/HelloworldActivity.java | 167 ++++++++++++++++++ .../java/io/grpc/interop/cpp/InteropTest.java | 77 ++++++++ .../io/grpc/interop/cpp/InteropActivity.java | 120 +++++++++++++ .../grpc/binder/cpp/GrpcBinderConnection.java | 85 +++++++++ .../grpc/binder/cpp/GrpcCppServerBuilder.java | 38 ++++ .../binder/cpp/NativeConnectionHelper.java | 39 ++++ 11 files changed, 632 insertions(+) create mode 100644 examples/android/binder/java/io/grpc/binder/cpp/exampleclient/ButtonPressHandler.java create mode 100644 examples/android/binder/java/io/grpc/binder/cpp/exampleclient/MainActivity.java create mode 100644 examples/android/binder/java/io/grpc/binder/cpp/exampleserver/ButtonPressHandler.java create mode 100644 examples/android/binder/java/io/grpc/binder/cpp/exampleserver/ExportedEndpointService.java create mode 100644 examples/android/binder/java/io/grpc/binder/cpp/exampleserver/MainActivity.java create mode 100644 examples/android/helloworld/app/src/main/java/io/grpc/helloworldexample/cpp/HelloworldActivity.java create mode 100644 src/android/test/interop/app/src/androidTest/java/io/grpc/interop/cpp/InteropTest.java create mode 100644 src/android/test/interop/app/src/main/java/io/grpc/interop/cpp/InteropActivity.java create mode 100644 src/core/ext/transport/binder/java/io/grpc/binder/cpp/GrpcBinderConnection.java create mode 100644 src/core/ext/transport/binder/java/io/grpc/binder/cpp/GrpcCppServerBuilder.java create mode 100644 src/core/ext/transport/binder/java/io/grpc/binder/cpp/NativeConnectionHelper.java diff --git a/examples/android/binder/java/io/grpc/binder/cpp/exampleclient/ButtonPressHandler.java b/examples/android/binder/java/io/grpc/binder/cpp/exampleclient/ButtonPressHandler.java new file mode 100644 index 00000000..ed9d11a4 --- /dev/null +++ b/examples/android/binder/java/io/grpc/binder/cpp/exampleclient/ButtonPressHandler.java @@ -0,0 +1,15 @@ +package io.grpc.binder.cpp.exampleclient; + +import android.app.Application; + +public class ButtonPressHandler { + static { + System.loadLibrary("app"); + } + + public native String native_entry(Application application); + + public String onPressed(Application application) { + return native_entry(application); + } +} diff --git a/examples/android/binder/java/io/grpc/binder/cpp/exampleclient/MainActivity.java b/examples/android/binder/java/io/grpc/binder/cpp/exampleclient/MainActivity.java new file mode 100644 index 00000000..3cbf70d1 --- /dev/null +++ b/examples/android/binder/java/io/grpc/binder/cpp/exampleclient/MainActivity.java @@ -0,0 +1,26 @@ +package io.grpc.binder.cpp.exampleclient; + +import android.app.Activity; +import android.os.Bundle; +import android.util.Log; +import android.widget.Button; +import android.widget.TextView; + +/** Main class for the example app. */ +public class MainActivity extends Activity { + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + Log.v("Example", "hello, world"); + + setContentView(R.layout.activity_main); + + Button clickMeButton = findViewById(R.id.clickMeButton); + TextView exampleTextView = findViewById(R.id.exampleTextView); + + ButtonPressHandler h = new ButtonPressHandler(); + + clickMeButton.setOnClickListener( + v -> exampleTextView.setText(h.onPressed(getApplication()))); + } +} diff --git a/examples/android/binder/java/io/grpc/binder/cpp/exampleserver/ButtonPressHandler.java b/examples/android/binder/java/io/grpc/binder/cpp/exampleserver/ButtonPressHandler.java new file mode 100644 index 00000000..34d38ccf --- /dev/null +++ b/examples/android/binder/java/io/grpc/binder/cpp/exampleserver/ButtonPressHandler.java @@ -0,0 +1,13 @@ +package io.grpc.binder.cpp.exampleserver; + +import android.app.Application; + +public class ButtonPressHandler { + static { + System.loadLibrary("app"); + } + + public String onPressed(Application application) { + return "Server Button Pressed"; + } +} diff --git a/examples/android/binder/java/io/grpc/binder/cpp/exampleserver/ExportedEndpointService.java b/examples/android/binder/java/io/grpc/binder/cpp/exampleserver/ExportedEndpointService.java new file mode 100644 index 00000000..78412e60 --- /dev/null +++ b/examples/android/binder/java/io/grpc/binder/cpp/exampleserver/ExportedEndpointService.java @@ -0,0 +1,25 @@ +package io.grpc.binder.cpp.exampleserver; + +import android.app.Service; +import android.content.Intent; +import android.os.IBinder; +import io.grpc.binder.cpp.GrpcCppServerBuilder; + +/** Exposes gRPC services running in the main process */ +public final class ExportedEndpointService extends Service { + static { + System.loadLibrary("app"); + } + + public ExportedEndpointService() { + init_grpc_server(); + } + + @Override + public IBinder onBind(Intent intent) { + // The argument should match the URI passed into grpc::ServerBuilder::AddListeningPort + return GrpcCppServerBuilder.GetEndpointBinder("binder:example.service"); + } + + public native void init_grpc_server(); +} diff --git a/examples/android/binder/java/io/grpc/binder/cpp/exampleserver/MainActivity.java b/examples/android/binder/java/io/grpc/binder/cpp/exampleserver/MainActivity.java new file mode 100644 index 00000000..d252e5f2 --- /dev/null +++ b/examples/android/binder/java/io/grpc/binder/cpp/exampleserver/MainActivity.java @@ -0,0 +1,27 @@ +package io.grpc.binder.cpp.exampleserver; + +import android.app.Activity; +import android.os.Bundle; +import android.util.Log; +import android.widget.Button; +import android.widget.TextView; +import io.grpc.binder.cpp.exampleserver.R; + +/** Main class for the example app. */ +public class MainActivity extends Activity { + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + Log.v("Example", "hello, world"); + + setContentView(R.layout.activity_main); + + Button clickMeButton = findViewById(R.id.clickMeButton); + TextView exampleTextView = findViewById(R.id.exampleTextView); + + ButtonPressHandler h = new ButtonPressHandler(); + + clickMeButton.setOnClickListener( + v -> exampleTextView.setText(h.onPressed(getApplication()))); + } +} diff --git a/examples/android/helloworld/app/src/main/java/io/grpc/helloworldexample/cpp/HelloworldActivity.java b/examples/android/helloworld/app/src/main/java/io/grpc/helloworldexample/cpp/HelloworldActivity.java new file mode 100644 index 00000000..ae5c88b2 --- /dev/null +++ b/examples/android/helloworld/app/src/main/java/io/grpc/helloworldexample/cpp/HelloworldActivity.java @@ -0,0 +1,167 @@ +/* + * Copyright 2018, gRPC Authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.grpc.helloworldexample.cpp; + +import android.content.Context; +import android.os.AsyncTask; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.text.TextUtils; +import android.text.method.ScrollingMovementMethod; +import android.view.View; +import android.view.inputmethod.InputMethodManager; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; +import android.widget.Toast; +import java.lang.ref.WeakReference; + +public class HelloworldActivity extends AppCompatActivity { + + static { + System.loadLibrary("grpc-helloworld"); + } + + private Button sendButton; + private Button serverButton; + private EditText hostEdit; + private EditText portEdit; + private EditText messageEdit; + private EditText serverPortEdit; + private TextView resultText; + private GrpcTask grpcTask; + private RunServerTask runServerTask; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_helloworld); + sendButton = (Button) findViewById(R.id.send_button); + serverButton = (Button) findViewById(R.id.server_button); + hostEdit = (EditText) findViewById(R.id.host_edit_text); + portEdit = (EditText) findViewById(R.id.port_edit_text); + messageEdit = (EditText) findViewById(R.id.message_edit_text); + serverPortEdit = (EditText) findViewById(R.id.server_port_edit_text); + resultText = (TextView) findViewById(R.id.grpc_response_text); + resultText.setMovementMethod(new ScrollingMovementMethod()); + } + + @Override + protected void onPause() { + super.onPause(); + if (runServerTask != null) { + runServerTask.cancel(true); + runServerTask = null; + serverButton.setText("Start gRPC Server"); + } + if (grpcTask != null) { + grpcTask.cancel(true); + grpcTask = null; + } + } + + public void sendMessage(View view) { + ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)) + .hideSoftInputFromWindow(hostEdit.getWindowToken(), 0); + sendButton.setEnabled(false); + resultText.setText(""); + grpcTask = new GrpcTask(this); + grpcTask.executeOnExecutor( + AsyncTask.THREAD_POOL_EXECUTOR, + hostEdit.getText().toString(), + messageEdit.getText().toString(), + portEdit.getText().toString()); + } + + public void startOrStopServer(View view) { + if (runServerTask != null) { + runServerTask.cancel(true); + runServerTask = null; + serverButton.setText("Start gRPC Server"); + Toast.makeText(this, "Server stopped", Toast.LENGTH_SHORT).show(); + } else { + runServerTask = new RunServerTask(this); + String portStr = serverPortEdit.getText().toString(); + int port = TextUtils.isEmpty(portStr) ? 50051 : Integer.valueOf(portStr); + runServerTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, port); + serverButton.setText("Stop gRPC Server"); + Toast.makeText(this, "Server started on port " + port, Toast.LENGTH_SHORT).show(); + } + } + + private static class RunServerTask extends AsyncTask { + private final WeakReference activityReference; + + private RunServerTask(HelloworldActivity activity) { + this.activityReference = new WeakReference(activity); + } + + @Override + protected Void doInBackground(Integer... params) { + int port = params[0]; + HelloworldActivity activity = activityReference.get(); + if (activity != null) { + activity.startServer(port); + } + return null; + } + } + + private static class GrpcTask extends AsyncTask { + private final WeakReference activityReference; + + private GrpcTask(HelloworldActivity activity) { + this.activityReference = new WeakReference(activity); + } + + @Override + protected String doInBackground(String... params) { + String host = params[0]; + String message = params[1]; + String portStr = params[2]; + int port = TextUtils.isEmpty(portStr) ? 50051 : Integer.valueOf(portStr); + return sayHello(host, port, message); + } + + @Override + protected void onPostExecute(String result) { + HelloworldActivity activity = activityReference.get(); + if (activity == null || isCancelled()) { + return; + } + TextView resultText = (TextView) activity.findViewById(R.id.grpc_response_text); + Button sendButton = (Button) activity.findViewById(R.id.send_button); + resultText.setText(result); + sendButton.setEnabled(true); + } + } + + /** + * Invoked by native code to stop server when RunServerTask has been canceled, either by user + * request or upon app moving to background. + */ + public boolean isRunServerTaskCancelled() { + if (runServerTask != null) { + return runServerTask.isCancelled(); + } + return false; + } + + public static native String sayHello(String host, int port, String message); + + public native void startServer(int port); +} diff --git a/src/android/test/interop/app/src/androidTest/java/io/grpc/interop/cpp/InteropTest.java b/src/android/test/interop/app/src/androidTest/java/io/grpc/interop/cpp/InteropTest.java new file mode 100644 index 00000000..8673354a --- /dev/null +++ b/src/android/test/interop/app/src/androidTest/java/io/grpc/interop/cpp/InteropTest.java @@ -0,0 +1,77 @@ +/* + * Copyright 2018, gRPC Authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.grpc.interop.cpp; + +import static junit.framework.Assert.assertTrue; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; +import java.io.File; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.OutputStream; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(AndroidJUnit4.class) +public class InteropTest { + private String host; + private int port; + private boolean useTls; + + @Before + public void setUp() throws Exception { + host = + InstrumentationRegistry.getArguments() + .getString("server_host", "grpc-test.sandbox.googleapis.com"); + port = Integer.parseInt(InstrumentationRegistry.getArguments().getString("server_port", "443")); + useTls = + Boolean.parseBoolean(InstrumentationRegistry.getArguments().getString("use_tls", "true")); + } + + @Test + public void emptyUnary() { + assertTrue(InteropActivity.doEmpty(host, port, useTls)); + } + + @Test + public void largeUnary() { + assertTrue(InteropActivity.doLargeUnary(host, port, useTls)); + } + + @Test + public void emptyStream() { + assertTrue(InteropActivity.doEmptyStream(host, port, useTls)); + } + + @Test + public void requestStreaming() { + assertTrue(InteropActivity.doRequestStreaming(host, port, useTls)); + } + + @Test + public void responseStreaming() { + assertTrue(InteropActivity.doResponseStreaming(host, port, useTls)); + } + + @Test + public void pingPong() { + assertTrue(InteropActivity.doPingPong(host, port, useTls)); + } +} diff --git a/src/android/test/interop/app/src/main/java/io/grpc/interop/cpp/InteropActivity.java b/src/android/test/interop/app/src/main/java/io/grpc/interop/cpp/InteropActivity.java new file mode 100644 index 00000000..05e736fe --- /dev/null +++ b/src/android/test/interop/app/src/main/java/io/grpc/interop/cpp/InteropActivity.java @@ -0,0 +1,120 @@ +/* + * Copyright 2018, gRPC Authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.grpc.interop.cpp; + +import android.content.Context; +import android.os.AsyncTask; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.text.TextUtils; +import android.text.method.ScrollingMovementMethod; +import android.view.View; +import android.view.inputmethod.InputMethodManager; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; +import java.lang.ref.WeakReference; + +public class InteropActivity extends AppCompatActivity { + + static { + System.loadLibrary("grpc-interop"); + } + + private Button sendButton; + private EditText hostEdit; + private EditText portEdit; + private TextView resultText; + private GrpcTask grpcTask; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_interop); + sendButton = (Button) findViewById(R.id.ping_pong_button); + hostEdit = (EditText) findViewById(R.id.host_edit_text); + portEdit = (EditText) findViewById(R.id.port_edit_text); + resultText = (TextView) findViewById(R.id.grpc_result_text); + resultText.setMovementMethod(new ScrollingMovementMethod()); + } + + @Override + protected void onPause() { + super.onPause(); + if (grpcTask != null) { + grpcTask.cancel(true); + grpcTask = null; + } + } + + public void doPingPong(View view) { + ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)) + .hideSoftInputFromWindow(hostEdit.getWindowToken(), 0); + sendButton.setEnabled(false); + resultText.setText(""); + grpcTask = new GrpcTask(this); + grpcTask.executeOnExecutor( + AsyncTask.THREAD_POOL_EXECUTOR, + hostEdit.getText().toString(), + portEdit.getText().toString()); + } + + private static class GrpcTask extends AsyncTask { + private final WeakReference activityReference; + + private GrpcTask(InteropActivity activity) { + this.activityReference = new WeakReference(activity); + } + + @Override + protected String doInBackground(String... params) { + String host = params[0]; + String portStr = params[1]; + int port = TextUtils.isEmpty(portStr) ? 50051 : Integer.valueOf(portStr); + // TODO(ericgribkoff) Support other test cases in the app UI + if (doPingPong(host, port, false)) { + return "Success"; + } else { + return "Failure"; + } + } + + @Override + protected void onPostExecute(String result) { + InteropActivity activity = activityReference.get(); + if (activity == null || isCancelled()) { + return; + } + TextView resultText = (TextView) activity.findViewById(R.id.grpc_result_text); + Button sendButton = (Button) activity.findViewById(R.id.ping_pong_button); + resultText.setText(result); + sendButton.setEnabled(true); + } + } + + public static native boolean doEmpty(String host, int port, boolean useTls); + + public static native boolean doLargeUnary(String host, int port, boolean useTls); + + public static native boolean doEmptyStream(String host, int port, boolean useTls); + + public static native boolean doRequestStreaming(String host, int port, boolean useTls); + + public static native boolean doResponseStreaming(String host, int port, boolean useTls); + + public static native boolean doPingPong(String host, int port, boolean useTls); +} diff --git a/src/core/ext/transport/binder/java/io/grpc/binder/cpp/GrpcBinderConnection.java b/src/core/ext/transport/binder/java/io/grpc/binder/cpp/GrpcBinderConnection.java new file mode 100644 index 00000000..4953113f --- /dev/null +++ b/src/core/ext/transport/binder/java/io/grpc/binder/cpp/GrpcBinderConnection.java @@ -0,0 +1,85 @@ +// Copyright 2021 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package io.grpc.binder.cpp; + +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.ServiceConnection; +import android.os.IBinder; +import android.util.Log; + +/* Handles the binder connection state with OnDeviceServer server */ +public class GrpcBinderConnection implements ServiceConnection { + private static final String logTag = "GrpcBinderConnection"; + + private Context mContext; + private IBinder mService; + + // A string that identifies this service connection + private final String mConnId; + + public GrpcBinderConnection(Context context, String connId) { + mContext = context; + mConnId = connId; + } + + @Override + public void onNullBinding(ComponentName className) { + // TODO(mingcl): Notify C++ that the connection is never going to happen + Log.e(logTag, "Service returned null IBinder. mConnId = " + mConnId); + } + + @Override + public void onServiceConnected(ComponentName className, IBinder service) { + Log.e(logTag, "Service has connected. mConnId = " + mConnId); + if (service == null) { + // This should not happen since onNullBinding should be invoked instead + throw new IllegalArgumentException("service was null"); + } + synchronized (this) { + mService = service; + } + notifyConnected(mConnId, mService); + } + + @Override + public void onServiceDisconnected(ComponentName className) { + Log.e(logTag, "Service has disconnected. mConnId = " + mConnId); + } + + public void tryConnect(String pkg, String cls) { + synchronized (this) { + Intent intent = new Intent("grpc.io.action.BIND"); + ComponentName compName = new ComponentName(pkg, cls); + intent.setComponent(compName); + // Will return true if the system is in the process of bringing up a service that your client + // has permission to bind to; false if the system couldn't find the service or if your client + // doesn't have permission to bind to it + boolean result = mContext.bindService(intent, this, Context.BIND_AUTO_CREATE); + if (result) { + Log.e(logTag, "bindService returns ok"); + } else { + Log.e( + logTag, + "bindService failed. Maybe the system couldn't find the service or the" + + " client doesn't have permission to bind to it."); + } + } + } + + // Calls a function defined in endpoint_binder_pool.cc + private static native void notifyConnected(String connId, IBinder service); +} diff --git a/src/core/ext/transport/binder/java/io/grpc/binder/cpp/GrpcCppServerBuilder.java b/src/core/ext/transport/binder/java/io/grpc/binder/cpp/GrpcCppServerBuilder.java new file mode 100644 index 00000000..c5ccfd39 --- /dev/null +++ b/src/core/ext/transport/binder/java/io/grpc/binder/cpp/GrpcCppServerBuilder.java @@ -0,0 +1,38 @@ +// Copyright 2021 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package io.grpc.binder.cpp; + +import android.os.IBinder; +import android.util.Log; + +/* EXPERIMENTAL. Provides a interface to get endpoint binder from C++ */ +public class GrpcCppServerBuilder { + private static final String logTag = "GrpcCppServerBuilder"; + + public static IBinder GetEndpointBinder(String uri) { + String scheme = "binder:"; + if (uri.startsWith(scheme)) { + String path = uri.substring(scheme.length()); + // TODO(mingcl): Consider if we would like to make sure the path only contain valid + // characters here + return GetEndpointBinderInternal(path); + } else { + Log.e(logTag, "URI " + uri + " does not start with 'binder:'"); + return null; + } + } + + private static native IBinder GetEndpointBinderInternal(String conn_id); +} diff --git a/src/core/ext/transport/binder/java/io/grpc/binder/cpp/NativeConnectionHelper.java b/src/core/ext/transport/binder/java/io/grpc/binder/cpp/NativeConnectionHelper.java new file mode 100644 index 00000000..adc67e9d --- /dev/null +++ b/src/core/ext/transport/binder/java/io/grpc/binder/cpp/NativeConnectionHelper.java @@ -0,0 +1,39 @@ +// Copyright 2021 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package io.grpc.binder.cpp; + +import android.content.Context; +import android.os.Parcel; +import java.util.HashMap; +import java.util.Map; + +/** + * This class will be invoked by gRPC binder transport internal implementation to perform operations + * that are only possible in Java + */ +final class NativeConnectionHelper { + // Maps connection id to GrpcBinderConnection instances + static Map s = new HashMap<>(); + + static void tryEstablishConnection(Context context, String pkg, String cls, String connId) { + // TODO(mingcl): Assert that connId is unique + s.put(connId, new GrpcBinderConnection(context, connId)); + s.get(connId).tryConnect(pkg, cls); + } + + static Parcel getEmptyParcel() { + return Parcel.obtain(); + } +}