diff options
| author | 2018-12-04 20:20:56 +0900 | |
|---|---|---|
| committer | 2019-01-11 15:00:36 +0900 | |
| commit | 8c141bdb8f63b23115e82cacf06bb073e5b33f4f (patch) | |
| tree | 0d19475a3df4c94d7ad09d11f3988a527f982288 | |
| parent | 81552d610a297edc8ebe93f997d587a1fa4c44de (diff) | |
[MS01] Add the IP memory store service.
Bug: 116512211
Test: Added initial tests
Change-Id: I9d9af4097e3e2d7afd9956b9cbfa29a9f9558ae0
| -rw-r--r-- | Android.bp | 11 | ||||
| -rw-r--r-- | core/java/android/app/SystemServiceRegistry.java | 21 | ||||
| -rw-r--r-- | core/java/android/content/Context.java | 9 | ||||
| -rw-r--r-- | core/java/android/net/IIpMemoryStore.aidl | 27 | ||||
| -rw-r--r-- | core/java/android/net/IpMemoryStore.java | 53 | ||||
| -rw-r--r-- | services/Android.bp | 1 | ||||
| -rw-r--r-- | services/ipmemorystore/Android.bp | 4 | ||||
| -rw-r--r-- | services/ipmemorystore/java/com/android/server/net/ipmemorystore/IpMemoryStoreService.java | 43 | ||||
| -rw-r--r-- | services/java/com/android/server/SystemServer.java | 27 | ||||
| -rw-r--r-- | tests/net/Android.mk | 1 | ||||
| -rw-r--r-- | tests/net/java/android/net/IpMemoryStoreTest.java | 53 | ||||
| -rw-r--r-- | tests/net/java/com/android/server/net/ipmemorystore/IpMemoryStoreServiceTest.java | 49 |
12 files changed, 287 insertions, 12 deletions
diff --git a/Android.bp b/Android.bp index 8b3e259ef30e..dad71a21451e 100644 --- a/Android.bp +++ b/Android.bp @@ -697,6 +697,7 @@ java_defaults { "android.hardware.radio-V1.3-java", "android.hardware.radio-V1.4-java", "android.hardware.usb.gadget-V1.0-java", + "networkstack-aidl-interfaces-java", "netd_aidl_interface-java", ], @@ -715,6 +716,16 @@ java_defaults { } +// AIDL interfaces between the core system and the networking mainline module. +aidl_interface { + name: "networkstack-aidl-interfaces", + local_include_dir: "core/java", + srcs: [ + "core/java/android/net/IIpMemoryStore.aidl", + ], + api_dir: "aidl/networkstack", +} + filegroup { name: "libincident_aidl", srcs: [ diff --git a/core/java/android/app/SystemServiceRegistry.java b/core/java/android/app/SystemServiceRegistry.java index 15005d094af4..83c93fb3019c 100644 --- a/core/java/android/app/SystemServiceRegistry.java +++ b/core/java/android/app/SystemServiceRegistry.java @@ -82,8 +82,10 @@ import android.net.ConnectivityThread; import android.net.EthernetManager; import android.net.IConnectivityManager; import android.net.IEthernetManager; +import android.net.IIpMemoryStore; import android.net.IIpSecService; import android.net.INetworkPolicyManager; +import android.net.IpMemoryStore; import android.net.IpSecManager; import android.net.NetworkPolicyManager; import android.net.NetworkScoreManager; @@ -286,10 +288,21 @@ final class SystemServiceRegistry { registerService(Context.NETWORK_STACK_SERVICE, NetworkStack.class, new StaticServiceFetcher<NetworkStack>() { - @Override - public NetworkStack createService() { - return new NetworkStack(); - }}); + @Override + public NetworkStack createService() { + return new NetworkStack(); + }}); + + registerService(Context.IP_MEMORY_STORE_SERVICE, IpMemoryStore.class, + new CachedServiceFetcher<IpMemoryStore>() { + @Override + public IpMemoryStore createService(final ContextImpl ctx) + throws ServiceNotFoundException { + IBinder b = ServiceManager.getServiceOrThrow( + Context.IP_MEMORY_STORE_SERVICE); + IIpMemoryStore service = IIpMemoryStore.Stub.asInterface(b); + return new IpMemoryStore(ctx, service); + }}); registerService(Context.IPSEC_SERVICE, IpSecManager.class, new CachedServiceFetcher<IpSecManager>() { diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java index 81e72ccafe4d..9532f2bf9cd7 100644 --- a/core/java/android/content/Context.java +++ b/core/java/android/content/Context.java @@ -3015,6 +3015,7 @@ public abstract class Context { VIBRATOR_SERVICE, //@hide: STATUS_BAR_SERVICE, CONNECTIVITY_SERVICE, + //@hide: IP_MEMORY_STORE_SERVICE, IPSEC_SERVICE, //@hide: UPDATE_LOCK_SERVICE, //@hide: NETWORKMANAGEMENT_SERVICE, @@ -3514,6 +3515,14 @@ public abstract class Context { /** * Use with {@link #getSystemService(String)} to retrieve a + * {@link android.net.IpMemoryStore} to store and read information about + * known networks. + * @hide + */ + public static final String IP_MEMORY_STORE_SERVICE = "ipmemorystore"; + + /** + * Use with {@link #getSystemService(String)} to retrieve a * {@link android.net.IpSecManager} for encrypting Sockets or Networks with * IPSec. * diff --git a/core/java/android/net/IIpMemoryStore.aidl b/core/java/android/net/IIpMemoryStore.aidl new file mode 100644 index 000000000000..8662bd109c19 --- /dev/null +++ b/core/java/android/net/IIpMemoryStore.aidl @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * 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 android.net; + +/** {@hide} */ +interface IIpMemoryStore { + /** + * Returns the version of the memory store. + * This is just a fake method returning 1 to have some method in there + * without adding any actual complexity to review. + */ + int version(); +} diff --git a/core/java/android/net/IpMemoryStore.java b/core/java/android/net/IpMemoryStore.java new file mode 100644 index 000000000000..177992e045f9 --- /dev/null +++ b/core/java/android/net/IpMemoryStore.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * 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 android.net; + +import android.annotation.NonNull; +import android.annotation.SystemService; +import android.content.Context; +import android.os.RemoteException; + +import com.android.internal.util.Preconditions; + +/** + * The interface for system components to access the IP memory store. + * @see com.android.server.net.ipmemorystore.IpMemoryStoreService + * @hide + */ +@SystemService(Context.IP_MEMORY_STORE_SERVICE) +public class IpMemoryStore { + @NonNull final Context mContext; + @NonNull final IIpMemoryStore mService; + + public IpMemoryStore(@NonNull final Context context, @NonNull final IIpMemoryStore service) { + mContext = Preconditions.checkNotNull(context, "missing context"); + mService = Preconditions.checkNotNull(service, "missing IIpMemoryStore"); + } + + /** + * Returns the version of the memory store + * @hide + **/ + // TODO : remove this + public int version() { + try { + return mService.version(); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } +} diff --git a/services/Android.bp b/services/Android.bp index bea51be321c9..a416ca0b6977 100644 --- a/services/Android.bp +++ b/services/Android.bp @@ -23,6 +23,7 @@ java_library { "services.companion", "services.coverage", "services.devicepolicy", + "services.ipmemorystore", "services.midi", "services.net", "services.print", diff --git a/services/ipmemorystore/Android.bp b/services/ipmemorystore/Android.bp new file mode 100644 index 000000000000..013cf5616904 --- /dev/null +++ b/services/ipmemorystore/Android.bp @@ -0,0 +1,4 @@ +java_library_static { + name: "services.ipmemorystore", + srcs: ["java/**/*.java"], +} diff --git a/services/ipmemorystore/java/com/android/server/net/ipmemorystore/IpMemoryStoreService.java b/services/ipmemorystore/java/com/android/server/net/ipmemorystore/IpMemoryStoreService.java new file mode 100644 index 000000000000..8680b8db0249 --- /dev/null +++ b/services/ipmemorystore/java/com/android/server/net/ipmemorystore/IpMemoryStoreService.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * 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 com.android.server.net.ipmemorystore; + +import android.annotation.NonNull; +import android.content.Context; +import android.net.IIpMemoryStore; + +/** + * Implementation for the IP memory store. + * This component offers specialized services for network components to store and retrieve + * knowledge about networks, and provides intelligence that groups level 2 networks together + * into level 3 networks. + * @hide + */ +public class IpMemoryStoreService extends IIpMemoryStore.Stub { + final Context mContext; + + public IpMemoryStoreService(@NonNull final Context context) { + mContext = context; + } + + /** + * TODO : remove this useless method. + */ + public int version() { + return 1; + } +} diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java index 2d07fd6c6442..479fb9a89200 100644 --- a/services/java/com/android/server/SystemServer.java +++ b/services/java/com/android/server/SystemServer.java @@ -16,6 +16,13 @@ package com.android.server; +import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_CRITICAL; +import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_HIGH; +import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_NORMAL; +import static android.os.IServiceManager.DUMP_FLAG_PROTO; +import static android.view.Display.DEFAULT_DISPLAY; + +import android.annotation.NonNull; import android.app.ActivityThread; import android.app.INotificationManager; import android.app.usage.UsageStatsManagerInternal; @@ -84,11 +91,12 @@ import com.android.server.job.JobSchedulerService; import com.android.server.lights.LightsService; import com.android.server.media.MediaResourceMonitorService; import com.android.server.media.MediaRouterService; -import com.android.server.media.MediaUpdateService; import com.android.server.media.MediaSessionService; +import com.android.server.media.MediaUpdateService; import com.android.server.media.projection.MediaProjectionManagerService; import com.android.server.net.NetworkPolicyManagerService; import com.android.server.net.NetworkStatsService; +import com.android.server.net.ipmemorystore.IpMemoryStoreService; import com.android.server.net.watchlist.NetworkWatchlistService; import com.android.server.notification.NotificationManagerService; import com.android.server.oemlock.OemLockService; @@ -133,12 +141,6 @@ import java.util.Timer; import java.util.concurrent.CountDownLatch; import java.util.concurrent.Future; -import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_CRITICAL; -import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_HIGH; -import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_NORMAL; -import static android.os.IServiceManager.DUMP_FLAG_PROTO; -import static android.view.Display.DEFAULT_DISPLAY; - public final class SystemServer { private static final String TAG = "SystemServer"; @@ -1098,6 +1100,15 @@ public final class SystemServer { } traceEnd(); + traceBeginAndSlog("StartIpMemoryStoreService"); + try { + ServiceManager.addService(Context.IP_MEMORY_STORE_SERVICE, + new IpMemoryStoreService(context)); + } catch (Throwable e) { + reportWtf("starting IP Memory Store Service", e); + } + traceEnd(); + traceBeginAndSlog("StartIpSecService"); try { ipSecService = IpSecService.create(context); @@ -1981,7 +1992,7 @@ public final class SystemServer { windowManager.onSystemUiStarted(); } - private static void traceBeginAndSlog(String name) { + private static void traceBeginAndSlog(@NonNull String name) { Slog.i(TAG, name); BOOT_TIMINGS_TRACE_LOG.traceBegin(name); } diff --git a/tests/net/Android.mk b/tests/net/Android.mk index 9d1edbf1eaf0..f6f35fdadcd1 100644 --- a/tests/net/Android.mk +++ b/tests/net/Android.mk @@ -18,6 +18,7 @@ LOCAL_STATIC_JAVA_LIBRARIES := \ mockito-target-minus-junit4 \ platform-test-annotations \ services.core \ + services.ipmemorystore \ services.net LOCAL_JAVA_LIBRARIES := \ diff --git a/tests/net/java/android/net/IpMemoryStoreTest.java b/tests/net/java/android/net/IpMemoryStoreTest.java new file mode 100644 index 000000000000..0de7302c218c --- /dev/null +++ b/tests/net/java/android/net/IpMemoryStoreTest.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * 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 android.net; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.doReturn; + +import android.content.Context; +import android.os.RemoteException; +import android.support.test.filters.SmallTest; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +@RunWith(AndroidJUnit4.class) +@SmallTest +public class IpMemoryStoreTest { + @Mock + Context mMockContext; + @Mock + IIpMemoryStore mMockService; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + } + + // TODO : remove this useless test + @Test + public void testVersion() throws RemoteException { + doReturn(30).when(mMockService).version(); + final IpMemoryStore store = new IpMemoryStore(mMockContext, mMockService); + assertEquals(store.version(), 30); + } +} diff --git a/tests/net/java/com/android/server/net/ipmemorystore/IpMemoryStoreServiceTest.java b/tests/net/java/com/android/server/net/ipmemorystore/IpMemoryStoreServiceTest.java new file mode 100644 index 000000000000..b2cf41526d6d --- /dev/null +++ b/tests/net/java/com/android/server/net/ipmemorystore/IpMemoryStoreServiceTest.java @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * 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 com.android.server.net.ipmemorystore; + +import static org.junit.Assert.assertEquals; + +import android.content.Context; +import android.support.test.filters.SmallTest; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +/** Unit tests for {@link IpMemoryStoreServiceTest}. */ +@SmallTest +@RunWith(AndroidJUnit4.class) +public class IpMemoryStoreServiceTest { + @Mock + Context mMockContext; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + } + + // TODO : remove this useless test + @Test + public void testVersion() { + final IpMemoryStoreService service = new IpMemoryStoreService(mMockContext); + assertEquals(service.version(), 1); + } +} |