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

Commit f421d608 authored by Erik Kline's avatar Erik Kline Committed by android-build-merger
Browse files

Merge "Add tethering offload HAL call via JNI"

am: 8f65e470

Change-Id: Ib8403f685371b44f0fdad6d15ae372787d457d13
parents a37b511b 8f65e470
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -18,10 +18,18 @@ LOCAL_SRC_FILES += \
LOCAL_AIDL_INCLUDES += \
    system/netd/server/binder

LOCAL_JAVA_LIBRARIES := services.net
LOCAL_STATIC_JAVA_LIBRARIES := tzdata_shared2 tzdata_update2
LOCAL_PROTOC_OPTIMIZE_TYPE := nano

LOCAL_JAVA_LIBRARIES := \
    services.net \
    android.hidl.manager-V1.0-java \

LOCAL_STATIC_JAVA_LIBRARIES := \
    tzdata_shared2 \
    tzdata_update2 \
    android.hidl.base-V1.0-java-static \
    android.hardware.tetheroffload.control-V1.0-java-static \

ifneq ($(INCREMENTAL_BUILDS),)
    LOCAL_PROGUARD_ENABLED := disabled
    LOCAL_JACK_ENABLED := incremental
+10 −2
Original line number Diff line number Diff line
@@ -145,6 +145,7 @@ import com.android.server.connectivity.NetworkNotificationManager.NotificationTy
import com.android.server.connectivity.PacManager;
import com.android.server.connectivity.PermissionMonitor;
import com.android.server.connectivity.Tethering;
import com.android.server.connectivity.tethering.TetheringDependencies;
import com.android.server.connectivity.Vpn;
import com.android.server.net.BaseNetworkObserver;
import com.android.server.net.LockdownVpnTracker;
@@ -802,8 +803,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
        mTestMode = mSystemProperties.get("cm.test.mode").equals("true")
                && mSystemProperties.get("ro.build.type").equals("eng");

        mTethering = new Tethering(mContext, mNetd, statsService, mPolicyManager,
                                   IoThread.get().getLooper(), new MockableSystemProperties());
        mTethering = makeTethering();

        mPermissionMonitor = new PermissionMonitor(mContext, mNetd);

@@ -853,6 +853,14 @@ public class ConnectivityService extends IConnectivityManager.Stub
        mMultinetworkPolicyTracker.start();
    }

    private Tethering makeTethering() {
        // TODO: Move other elements into @Overridden getters.
        final TetheringDependencies deps = new TetheringDependencies();
        return new Tethering(mContext, mNetd, mStatsService, mPolicyManager,
                IoThread.get().getLooper(), new MockableSystemProperties(),
                deps);
    }

    private NetworkRequest createInternetRequestForTransport(
            int transportType, NetworkRequest.Type type) {
        NetworkCapabilities netCap = new NetworkCapabilities();
+7 −3
Original line number Diff line number Diff line
@@ -81,6 +81,7 @@ import com.android.server.connectivity.tethering.OffloadController;
import com.android.server.connectivity.tethering.SimChangeListener;
import com.android.server.connectivity.tethering.TetherInterfaceStateMachine;
import com.android.server.connectivity.tethering.TetheringConfiguration;
import com.android.server.connectivity.tethering.TetheringDependencies;
import com.android.server.connectivity.tethering.UpstreamNetworkMonitor;
import com.android.server.net.BaseNetworkObserver;

@@ -178,7 +179,8 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering

    public Tethering(Context context, INetworkManagementService nmService,
            INetworkStatsService statsService, INetworkPolicyManager policyManager,
            Looper looper, MockableSystemProperties systemProperties) {
            Looper looper, MockableSystemProperties systemProperties,
            TetheringDependencies deps) {
        mLocalLog.log("CONSTRUCTED");
        mContext = context;
        mNMService = nmService;
@@ -194,7 +196,8 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
        mTetherMasterSM = new TetherMasterSM("TetherMaster", mLooper);
        mTetherMasterSM.start();

        mOffloadController = new OffloadController(mTetherMasterSM.getHandler());
        mOffloadController = new OffloadController(mTetherMasterSM.getHandler(),
                deps.getOffloadHardwareInterface());
        mUpstreamNetworkMonitor = new UpstreamNetworkMonitor(
                mContext, mTetherMasterSM, TetherMasterSM.EVENT_UPSTREAM_CALLBACK);
        mForwardedDownstreams = new HashSet<>();
@@ -1474,7 +1477,8 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
                        handleInterfaceServingStateInactive(who);

                        if (mNotifyList.isEmpty()) {
                            // transitions appropriately
                            // This transitions us out of TetherModeAliveState,
                            // either to InitialState or an error state.
                            turnOffMasterTetherSettings();
                            break;
                        }
+31 −6
Original line number Diff line number Diff line
@@ -18,10 +18,12 @@ package com.android.server.connectivity.tethering;

import android.net.LinkProperties;
import android.os.Handler;
import android.os.RemoteException;
import android.util.Log;

/**
 * A wrapper around hardware offload interface.
 * A class to encapsulate the business logic of programming the tethering
 * hardware offload interface.
 *
 * @hide
 */
@@ -29,25 +31,48 @@ public class OffloadController {
    private static final String TAG = OffloadController.class.getSimpleName();

    private final Handler mHandler;
    private final OffloadHardwareInterface mHwInterface;
    private boolean mConfigInitialized;
    private boolean mControlInitialized;
    private LinkProperties mUpstreamLinkProperties;

    public OffloadController(Handler h) {
    public OffloadController(Handler h, OffloadHardwareInterface hwi) {
        mHandler = h;
        mHwInterface = hwi;
    }

    public void start() {
        // TODO: initOffload() and configure callbacks to be handled on our
        // preferred Handler.
        Log.d(TAG, "tethering offload not supported");
        if (started()) return;

        if (!mConfigInitialized) {
            mConfigInitialized = mHwInterface.initOffloadConfig();
            if (!mConfigInitialized) {
                Log.d(TAG, "tethering offload config not supported");
                return;
            }
        }

        // TODO: Create and register ITetheringOffloadCallback.
        mControlInitialized = mHwInterface.initOffloadControl();
    }

    public void stop() {
        // TODO: stopOffload().
        mUpstreamLinkProperties = null;
        mHwInterface.stopOffloadControl();
        mControlInitialized = false;
        mConfigInitialized = false;
    }

    public void setUpstreamLinkProperties(LinkProperties lp) {
        if (!started()) return;

        // TODO: setUpstreamParameters().
        mUpstreamLinkProperties = lp;
    }

    // TODO: public void addDownStream(...)

    private boolean started() {
        return mConfigInitialized && mControlInitialized;
    }
}
+77 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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.connectivity.tethering;

import android.hardware.tetheroffload.control.V1_0.IOffloadControl;
import android.hardware.tetheroffload.control.V1_0.IOffloadControl.stopOffloadCallback;
import android.os.RemoteException;
import android.util.Log;


/**
 * Capture tethering dependencies, for injection.
 *
 * @hide
 */
public class OffloadHardwareInterface {
    private static final String TAG = OffloadHardwareInterface.class.getSimpleName();

    private static native boolean configOffload();

    private IOffloadControl mOffloadControl;

    public OffloadHardwareInterface() {}

    public boolean initOffloadConfig() {
        return configOffload();
    }

    // TODO: Extend this to take a TetheringControlCallback for registration.
    public boolean initOffloadControl() {
        if (mOffloadControl == null) {
            try {
                mOffloadControl = IOffloadControl.getService();
            } catch (RemoteException e) {
                Log.d(TAG, "tethering offload control not supported: " + e);
                return false;
            }
        }

        // TODO: call mOffloadControl.initOffload(...callback...);

        return true;
    }

    public void stopOffloadControl() {
        if (mOffloadControl == null) return;

        try {
            final stopOffloadCallback cb = new stopOffloadCallback() {
                @Override
                public void onValues(boolean success, String errMsg) {
                    if (success) return;

                    Log.e(TAG, "stopOffload failed: " + errMsg);
                }
            };
            mOffloadControl.stopOffload(cb);
        } catch (RemoteException e) {
            Log.d(TAG, "failed to stopOffload: " + e);
        }
        mOffloadControl = null;
    }
}
Loading