Artem Iglikov | bd476ea | 2017-09-01 10:57:26 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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.backup.testing; |
| 18 | |
| 19 | import com.android.internal.backup.IBackupTransport; |
| 20 | import com.android.server.backup.TransportManager; |
| 21 | |
| 22 | import java.util.HashSet; |
| 23 | import java.util.Set; |
| 24 | |
| 25 | /** |
| 26 | * Stub implementation of TransportBoundListener, which returns given result and can tell whether |
| 27 | * it was called for given transport. |
| 28 | */ |
| 29 | public class TransportBoundListenerStub implements |
| 30 | TransportManager.TransportBoundListener { |
| 31 | private boolean mAlwaysReturnSuccess; |
| 32 | private Set<IBackupTransport> mTransportsCalledFor = new HashSet<>(); |
| 33 | |
| 34 | public TransportBoundListenerStub(boolean alwaysReturnSuccess) { |
| 35 | this.mAlwaysReturnSuccess = alwaysReturnSuccess; |
| 36 | } |
| 37 | |
| 38 | @Override |
| 39 | public boolean onTransportBound(IBackupTransport binder) { |
| 40 | mTransportsCalledFor.add(binder); |
| 41 | return mAlwaysReturnSuccess; |
| 42 | } |
| 43 | |
Artem Iglikov | 19e1227 | 2017-05-31 17:12:28 +0100 | [diff] [blame] | 44 | /** |
| 45 | * Returns whether the listener was called for the specified transport at least once. |
| 46 | */ |
Artem Iglikov | bd476ea | 2017-09-01 10:57:26 +0100 | [diff] [blame] | 47 | public boolean isCalledForTransport(IBackupTransport binder) { |
| 48 | return mTransportsCalledFor.contains(binder); |
| 49 | } |
| 50 | |
Artem Iglikov | 19e1227 | 2017-05-31 17:12:28 +0100 | [diff] [blame] | 51 | /** |
| 52 | * Returns whether the listener was called at least once. |
| 53 | */ |
Artem Iglikov | bd476ea | 2017-09-01 10:57:26 +0100 | [diff] [blame] | 54 | public boolean isCalled() { |
| 55 | return !mTransportsCalledFor.isEmpty(); |
| 56 | } |
Artem Iglikov | 19e1227 | 2017-05-31 17:12:28 +0100 | [diff] [blame] | 57 | |
| 58 | /** |
| 59 | * Resets listener calls. |
| 60 | */ |
| 61 | public void resetState() { |
| 62 | mTransportsCalledFor.clear(); |
| 63 | } |
Artem Iglikov | bd476ea | 2017-09-01 10:57:26 +0100 | [diff] [blame] | 64 | } |