1 /* 2 * Copyright (C) 2018 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.testing.shadows; 18 19 import android.annotation.Nullable; 20 21 import com.android.server.backup.DataChangedJournal; 22 import com.android.server.backup.OperationStorage; 23 import com.android.server.backup.UserBackupManagerService; 24 import com.android.server.backup.internal.OnTaskFinishedListener; 25 import com.android.server.backup.keyvalue.KeyValueBackupReporter; 26 import com.android.server.backup.keyvalue.KeyValueBackupTask; 27 import com.android.server.backup.transport.TransportConnection; 28 import com.android.server.backup.utils.BackupEligibilityRules; 29 30 import org.robolectric.annotation.Implementation; 31 import org.robolectric.annotation.Implements; 32 33 import java.util.List; 34 35 @Implements(KeyValueBackupTask.class) 36 public class ShadowKeyValueBackupTask { 37 @Nullable private static ShadowKeyValueBackupTask sLastShadow; 38 39 /** 40 * Retrieves the shadow for the last {@link KeyValueBackupTask} object created. 41 * 42 * @return The shadow or {@code null} if no object created since last {@link #reset()}. 43 */ 44 @Nullable getLastCreated()45 public static ShadowKeyValueBackupTask getLastCreated() { 46 return sLastShadow; 47 } 48 reset()49 public static void reset() { 50 sLastShadow = null; 51 } 52 53 private OnTaskFinishedListener mListener; 54 private List<String> mQueue; 55 private List<String> mPendingFullBackups; 56 57 @Implementation __constructor__( UserBackupManagerService backupManagerService, OperationStorage operationStorage, TransportConnection transportConnection, String transportDirName, List<String> queue, @Nullable DataChangedJournal dataChangedJournal, KeyValueBackupReporter reporter, OnTaskFinishedListener listener, List<String> pendingFullBackups, boolean userInitiated, boolean nonIncremental, BackupEligibilityRules backupEligibilityRules)58 protected void __constructor__( 59 UserBackupManagerService backupManagerService, 60 OperationStorage operationStorage, 61 TransportConnection transportConnection, 62 String transportDirName, 63 List<String> queue, 64 @Nullable DataChangedJournal dataChangedJournal, 65 KeyValueBackupReporter reporter, 66 OnTaskFinishedListener listener, 67 List<String> pendingFullBackups, 68 boolean userInitiated, 69 boolean nonIncremental, 70 BackupEligibilityRules backupEligibilityRules) { 71 mListener = listener; 72 mQueue = queue; 73 mPendingFullBackups = pendingFullBackups; 74 sLastShadow = this; 75 } 76 77 @Implementation execute()78 protected void execute() { 79 mListener.onFinished("ShadowKeyValueBackupTask.execute()"); 80 } 81 getQueue()82 public List<String> getQueue() { 83 return mQueue; 84 } 85 getPendingFullBackups()86 public List<String> getPendingFullBackups() { 87 return mPendingFullBackups; 88 } 89 } 90