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 17package com.android.server.testing.shadows; 18 19import android.annotation.Nullable; 20import android.app.backup.IBackupManagerMonitor; 21import android.app.backup.IRestoreObserver; 22import android.content.pm.PackageInfo; 23 24import com.android.server.backup.BackupManagerService; 25import com.android.server.backup.internal.OnTaskFinishedListener; 26import com.android.server.backup.restore.PerformUnifiedRestoreTask; 27import com.android.server.backup.transport.TransportClient; 28 29import org.robolectric.annotation.Implementation; 30import org.robolectric.annotation.Implements; 31 32@Implements(PerformUnifiedRestoreTask.class) 33public class ShadowPerformUnifiedRestoreTask { 34 @Nullable private static ShadowPerformUnifiedRestoreTask sLastShadow; 35 36 /** 37 * Retrieves the shadow for the last {@link PerformUnifiedRestoreTask} object created. 38 * 39 * @return The shadow or {@code null} if no object created since last {@link #reset()}. 40 */ 41 @Nullable 42 public static ShadowPerformUnifiedRestoreTask getLastCreated() { 43 return sLastShadow; 44 } 45 46 public static void reset() { 47 sLastShadow = null; 48 } 49 50 private BackupManagerService mBackupManagerService; 51 @Nullable private PackageInfo mPackage; 52 private boolean mIsFullSystemRestore; 53 @Nullable private String[] mFilterSet; 54 private OnTaskFinishedListener mListener; 55 56 @Implementation 57 public void __constructor__( 58 BackupManagerService backupManagerService, 59 TransportClient transportClient, 60 IRestoreObserver observer, 61 IBackupManagerMonitor monitor, 62 long restoreSetToken, 63 @Nullable PackageInfo targetPackage, 64 int pmToken, 65 boolean isFullSystemRestore, 66 @Nullable String[] filterSet, 67 OnTaskFinishedListener listener) { 68 mBackupManagerService = backupManagerService; 69 mPackage = targetPackage; 70 mIsFullSystemRestore = isFullSystemRestore; 71 mFilterSet = filterSet; 72 mListener = listener; 73 sLastShadow = this; 74 } 75 76 @Implementation 77 public void execute() { 78 mBackupManagerService.setRestoreInProgress(false); 79 mListener.onFinished("ShadowPerformUnifiedRestoreTask.execute()"); 80 } 81 82 public PackageInfo getPackage() { 83 return mPackage; 84 } 85 86 public String[] getFilterSet() { 87 return mFilterSet; 88 } 89 90 public boolean isFullSystemRestore() { 91 return mIsFullSystemRestore; 92 } 93} 94