Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5b678764 authored by Chalard Jean's avatar Chalard Jean Committed by Xiao Ma
Browse files

Move the IpMemoryStore to the network stack.

Test: atest FrameworksNetTests
Change-Id: Ic5bd6ff54b09a6fa92b6863f240a5b053011acb6
parent d9a4d511
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ android_library {
        ":services-networkstack-shared-srcs",
    ],
    static_libs: [
        "ipmemorystore-client",
        "netd_aidl_interface-java",
        "networkstack-aidl-interfaces-java",
        "datastallprotosnano",
+42 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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.content.Context;

/**
 * service used to communicate with the ip memory store service in network stack,
 * which is running in the same module.
 * @see com.android.server.connectivity.ipmemorystore.IpMemoryStoreService
 * @hide
 */
public class NetworkStackIpMemoryStore extends IpMemoryStoreClient {
    @NonNull private final IIpMemoryStore mService;

    public NetworkStackIpMemoryStore(@NonNull final Context context,
            @NonNull final IIpMemoryStore service) {
        super(context);
        mService = service;
    }

    @Override
    @NonNull
    protected IIpMemoryStore getService() {
        return mService;
    }
}
+9 −3
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.net.INetd;
import android.net.IpPrefix;
import android.net.LinkAddress;
import android.net.LinkProperties;
import android.net.NetworkStackIpMemoryStore;
import android.net.ProvisioningConfigurationParcelable;
import android.net.ProxyInfo;
import android.net.RouteInfo;
@@ -61,6 +62,7 @@ import com.android.internal.util.State;
import com.android.internal.util.StateMachine;
import com.android.internal.util.WakeupMessage;
import com.android.server.NetworkObserverRegistry;
import com.android.server.NetworkStackService.NetworkStackServiceManager;

import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -100,6 +102,7 @@ public class IpClient extends StateMachine {
    // One holds StateMachine logs and the other connectivity packet logs.
    private static final ConcurrentHashMap<String, SharedLog> sSmLogs = new ConcurrentHashMap<>();
    private static final ConcurrentHashMap<String, LocalLog> sPktLogs = new ConcurrentHashMap<>();
    private final NetworkStackIpMemoryStore mIpMemoryStore;

    /**
     * Dump all state machine and connectivity packet logs to the specified writer.
@@ -388,13 +391,14 @@ public class IpClient extends StateMachine {
    }

    public IpClient(Context context, String ifName, IIpClientCallbacks callback,
            NetworkObserverRegistry observerRegistry) {
        this(context, ifName, callback, observerRegistry, new Dependencies());
            NetworkObserverRegistry observerRegistry, NetworkStackServiceManager nssManager) {
        this(context, ifName, callback, observerRegistry, nssManager, new Dependencies());
    }

    @VisibleForTesting
    IpClient(Context context, String ifName, IIpClientCallbacks callback,
            NetworkObserverRegistry observerRegistry, Dependencies deps) {
            NetworkObserverRegistry observerRegistry, NetworkStackServiceManager nssManager,
            Dependencies deps) {
        super(IpClient.class.getSimpleName() + "." + ifName);
        Preconditions.checkNotNull(ifName);
        Preconditions.checkNotNull(callback);
@@ -408,6 +412,8 @@ public class IpClient extends StateMachine {
        mShutdownLatch = new CountDownLatch(1);
        mCm = mContext.getSystemService(ConnectivityManager.class);
        mObserverRegistry = observerRegistry;
        mIpMemoryStore =
                new NetworkStackIpMemoryStore(context, nssManager.getIpMemoryStoreService());

        sSmLogs.putIfAbsent(mInterfaceName, new SharedLog(MAX_LOG_RECORDS, mTag));
        mLog = sSmLogs.get(mInterfaceName);
+30 −2
Original line number Diff line number Diff line
@@ -29,6 +29,8 @@ import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.IIpMemoryStore;
import android.net.IIpMemoryStoreCallbacks;
import android.net.INetd;
import android.net.INetworkMonitor;
import android.net.INetworkMonitorCallbacks;
@@ -49,6 +51,7 @@ import android.os.RemoteException;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.IndentingPrintWriter;
import com.android.server.connectivity.NetworkMonitor;
import com.android.server.connectivity.ipmemorystore.IpMemoryStoreService;

import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -86,7 +89,19 @@ public class NetworkStackService extends Service {
        return makeConnector(this);
    }

    private static class NetworkStackConnector extends INetworkStackConnector.Stub {
    /**
     * An interface for internal clients of the network stack service that can return
     * or create inline instances of the service it manages.
     */
    public interface NetworkStackServiceManager {
        /**
         * Get an instance of the IpMemoryStoreService.
         */
        IIpMemoryStore getIpMemoryStoreService();
    }

    private static class NetworkStackConnector extends INetworkStackConnector.Stub
            implements NetworkStackServiceManager {
        private static final int NUM_VALIDATION_LOG_LINES = 20;
        private final Context mContext;
        private final INetd mNetd;
@@ -94,6 +109,7 @@ public class NetworkStackService extends Service {
        private final ConnectivityManager mCm;
        @GuardedBy("mIpClients")
        private final ArrayList<WeakReference<IpClient>> mIpClients = new ArrayList<>();
        private final IpMemoryStoreService mIpMemoryStoreService;

        private static final int MAX_VALIDATION_LOGS = 10;
        @GuardedBy("mValidationLogs")
@@ -116,6 +132,7 @@ public class NetworkStackService extends Service {
                    (IBinder) context.getSystemService(Context.NETD_SERVICE));
            mObserverRegistry = new NetworkObserverRegistry();
            mCm = context.getSystemService(ConnectivityManager.class);
            mIpMemoryStoreService = new IpMemoryStoreService(context);

            try {
                mObserverRegistry.register(mNetd);
@@ -159,7 +176,7 @@ public class NetworkStackService extends Service {

        @Override
        public void makeIpClient(String ifName, IIpClientCallbacks cb) throws RemoteException {
            final IpClient ipClient = new IpClient(mContext, ifName, cb, mObserverRegistry);
            final IpClient ipClient = new IpClient(mContext, ifName, cb, mObserverRegistry, this);

            synchronized (mIpClients) {
                final Iterator<WeakReference<IpClient>> it = mIpClients.iterator();
@@ -175,6 +192,17 @@ public class NetworkStackService extends Service {
            cb.onIpClientCreated(ipClient.makeConnector());
        }

        @Override
        public IIpMemoryStore getIpMemoryStoreService() {
            return mIpMemoryStoreService;
        }

        @Override
        public void fetchIpMemoryStore(@NonNull final IIpMemoryStoreCallbacks cb)
                throws RemoteException {
            cb.onIpMemoryStoreFetched(mIpMemoryStoreService);
        }

        @Override
        protected void dump(@NonNull FileDescriptor fd, @NonNull PrintWriter fout,
                @Nullable String[] args) {
+515 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading