summaryrefslogtreecommitdiff
path: root/common/networkstackclient/src
diff options
context:
space:
mode:
authorRemi NGUYEN VAN <reminv@google.com>2020-03-18 18:24:43 +0900
committerRemi NGUYEN VAN <reminv@google.com>2020-03-18 18:24:43 +0900
commit62ea8f72dcb3d517ed0b44d58445b87ae2f9c324 (patch)
treea1ba8d9c83822948eb63395ac794dcd726823b1d /common/networkstackclient/src
parentaa561db2185e79ef3cf91932864b7007f902dadd (diff)
Use NetworkStack.getService in NetworkStackClient
This avoids returning IBinder in Context.getSystemService, having a dedicated getter for the NetworkStack AIDL interface instead. Test: atest FrameworksNetTests NetworkStackTests Bug: 151243982 Change-Id: Ibeaeff5890631e14581a084863d9aeb3178c5d5c
Diffstat (limited to 'common/networkstackclient/src')
-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) {