/*
* 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;
}
}