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 android.quickaccesswallet; 18 19 import android.content.Intent; 20 import android.os.IBinder; 21 import android.service.quickaccesswallet.WalletServiceEvent; 22 23 import androidx.annotation.NonNull; 24 import androidx.annotation.Nullable; 25 26 import java.lang.ref.WeakReference; 27 28 public class TestQuickAccessWalletService extends TestBaseQuickAccessWalletService { 29 30 private static WeakReference<TestQuickAccessWalletService> sServiceRef = 31 new WeakReference<>(null); 32 33 @Nullable 34 @Override onBind(@onNull Intent intent)35 public IBinder onBind(@NonNull Intent intent) { 36 sServiceRef = new WeakReference<>(this); 37 return super.onBind(intent); 38 } 39 40 @Override onUnbind(Intent intent)41 public boolean onUnbind(Intent intent) { 42 sServiceRef.clear(); 43 return super.onUnbind(intent); 44 } 45 sendEvent(WalletServiceEvent event)46 public static void sendEvent(WalletServiceEvent event) { 47 TestQuickAccessWalletService service = sServiceRef.get(); 48 if (service != null) { 49 service.sendWalletServiceEvent(event); 50 } 51 } 52 } 53