summaryrefslogtreecommitdiff
path: root/common/networkstackclient/src/android
diff options
context:
space:
mode:
authorRemi NGUYEN VAN <reminv@google.com>2020-03-19 01:21:29 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2020-03-19 01:21:29 +0000
commitb4ed5ab8f56c6e580772e7e812143329be678c2f (patch)
treeb02fa6d2a8a83bf7bd4d7a8cd056190301f9d0cd /common/networkstackclient/src/android
parent3c9c456f5c7b32b9d73d6c258e91c6d5ea0a44cb (diff)
parent62ea8f72dcb3d517ed0b44d58445b87ae2f9c324 (diff)
Merge "Use NetworkStack.getService in NetworkStackClient" into rvc-dev
Diffstat (limited to 'common/networkstackclient/src/android')
-rw-r--r--common/networkstackclient/src/android/net/networkstack/ModuleNetworkStackClient.java19
1 files changed, 8 insertions, 11 deletions
diff --git a/common/networkstackclient/src/android/net/networkstack/ModuleNetworkStackClient.java b/common/networkstackclient/src/android/net/networkstack/ModuleNetworkStackClient.java
index cfbb760..cbbae37 100644
--- a/common/networkstackclient/src/android/net/networkstack/ModuleNetworkStackClient.java
+++ b/common/networkstackclient/src/android/net/networkstack/ModuleNetworkStackClient.java
@@ -16,12 +16,12 @@
package android.net.networkstack;
-import static android.content.Context.NETWORK_STACK_SERVICE;
import static android.os.Build.VERSION.SDK_INT;
import android.annotation.NonNull;
import android.content.Context;
import android.net.INetworkStackConnector;
+import android.net.NetworkStack;
import android.os.Build;
import android.os.IBinder;
import android.util.Log;
@@ -47,14 +47,14 @@ public class ModuleNetworkStackClient extends NetworkStackClientBase {
// TODO(b/149676685): change this check to "< R" once R is defined
if (SDK_INT < Build.VERSION_CODES.Q
|| (SDK_INT == Build.VERSION_CODES.Q && "REL".equals(Build.VERSION.CODENAME))) {
- // NETWORK_STACK_SERVICE is not available through getSystemService before R
+ // The NetworkStack connector is not available through NetworkStack before R
throw new UnsupportedOperationException(
"ModuleNetworkStackClient is not supported on API " + SDK_INT);
}
if (sInstance == null) {
sInstance = new ModuleNetworkStackClient();
- sInstance.startPolling(packageContext);
+ sInstance.startPolling();
}
return sInstance;
}
@@ -64,10 +64,10 @@ public class ModuleNetworkStackClient extends NetworkStackClientBase {
sInstance = null;
}
- private void startPolling(Context context) {
+ private void startPolling() {
// If the service is already registered (as it will be most of the time), do not poll and
// fulfill requests immediately.
- final IBinder nss = (IBinder) context.getSystemService(NETWORK_STACK_SERVICE);
+ final IBinder nss = NetworkStack.getService();
if (nss != null) {
// Calling onNetworkStackConnected here means that pending oneway Binder calls to the
// NetworkStack get sent from the current thread and not a worker thread; this is fine
@@ -75,21 +75,18 @@ public class ModuleNetworkStackClient extends NetworkStackClientBase {
onNetworkStackConnected(INetworkStackConnector.Stub.asInterface(nss));
return;
}
- new Thread(new PollingRunner(context)).start();
+ new Thread(new PollingRunner()).start();
}
private class PollingRunner implements Runnable {
- private final Context mContext;
- private PollingRunner(Context context) {
- mContext = context;
- }
+ private PollingRunner() {}
@Override
public void run() {
// Block until the NetworkStack connector is registered in ServiceManager.
IBinder nss;
- while ((nss = (IBinder) mContext.getSystemService(NETWORK_STACK_SERVICE)) == null) {
+ while ((nss = NetworkStack.getService()) == null) {
try {
Thread.sleep(200);
} catch (InterruptedException e) {