[MS01] Add the IP memory store service.

Bug: 116512211
Test: Added initial tests
Change-Id: I9d9af4097e3e2d7afd9956b9cbfa29a9f9558ae0
This commit is contained in:
Chalard Jean
2018-12-04 20:20:56 +09:00
parent 81552d610a
commit 8c141bdb8f
12 changed files with 287 additions and 12 deletions

View File

@@ -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: [

View File

@@ -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>() {

View File

@@ -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,
@@ -3512,6 +3513,14 @@ public abstract class Context {
*/
public static final String NETWORK_STACK_SERVICE = "network_stack";
/**
* 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

View File

@@ -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();
}

View File

@@ -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();
}
}
}

View File

@@ -23,6 +23,7 @@ java_library {
"services.companion",
"services.coverage",
"services.devicepolicy",
"services.ipmemorystore",
"services.midi",
"services.net",
"services.print",

View File

@@ -0,0 +1,4 @@
java_library_static {
name: "services.ipmemorystore",
srcs: ["java/**/*.java"],
}

View File

@@ -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;
}
}

View File

@@ -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);
}

View File

@@ -18,6 +18,7 @@ LOCAL_STATIC_JAVA_LIBRARIES := \
mockito-target-minus-junit4 \
platform-test-annotations \
services.core \
services.ipmemorystore \
services.net
LOCAL_JAVA_LIBRARIES := \

View File

@@ -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);
}
}

View File

@@ -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);
}
}