1 /* 2 * Copyright (C) 2020 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.wifi.util; 18 19 import android.annotation.Nullable; 20 import android.net.wifi.IActionListener; 21 import android.os.RemoteException; 22 23 /** 24 * Simple wrapper around {@link IActionListener} that triggers onSuccess/onFailure 25 * on a best effort basis. 26 */ 27 public class ActionListenerWrapper { 28 private final IActionListener mListener; 29 ActionListenerWrapper(@ullable IActionListener listener)30 public ActionListenerWrapper(@Nullable IActionListener listener) { 31 mListener = listener; 32 } 33 34 /** Trigger the failure callback with a reason if the listener is non-null. */ sendFailure(int reason)35 public void sendFailure(int reason) { 36 if (mListener != null) { 37 try { 38 mListener.onFailure(reason); 39 } catch (RemoteException e) { 40 // no-op (client may be dead, nothing to be done) 41 } 42 } 43 } 44 45 /** Trigger the success callback with a reason if the listener is non-null. */ sendSuccess()46 public void sendSuccess() { 47 if (mListener != null) { 48 try { 49 mListener.onSuccess(); 50 } catch (RemoteException e) { 51 // no-op (client may be dead, nothing to be done) 52 } 53 } 54 } 55 } 56