1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.server.ethernet; 18 19 import android.net.EthernetNetworkManagementException; 20 import android.net.INetworkInterfaceOutcomeReceiver; 21 import android.os.RemoteException; 22 import android.util.Log; 23 24 import com.android.internal.annotations.VisibleForTesting; 25 26 /** Convenience wrapper for INetworkInterfaceOutcomeReceiver */ 27 @VisibleForTesting 28 public class EthernetCallback { 29 private static final String TAG = EthernetCallback.class.getSimpleName(); 30 private final INetworkInterfaceOutcomeReceiver mReceiver; 31 EthernetCallback(INetworkInterfaceOutcomeReceiver receiver)32 public EthernetCallback(INetworkInterfaceOutcomeReceiver receiver) { 33 mReceiver = receiver; 34 } 35 36 /** Calls INetworkInterfaceOutcomeReceiver#onResult */ onResult(String ifname)37 public void onResult(String ifname) { 38 try { 39 if (mReceiver != null) { 40 mReceiver.onResult(ifname); 41 } 42 } catch (RemoteException e) { 43 Log.e(TAG, "Failed to report error to OutcomeReceiver", e); 44 } 45 } 46 47 /** Calls INetworkInterfaceOutcomeReceiver#onError */ onError(String msg)48 public void onError(String msg) { 49 try { 50 if (mReceiver != null) { 51 mReceiver.onError(new EthernetNetworkManagementException(msg)); 52 } 53 } catch (RemoteException e) { 54 Log.e(TAG, "Failed to report error to OutcomeReceiver", e); 55 } 56 } 57 } 58