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.restore; 18 19 import android.app.IBackupAgent; 20 import android.os.ParcelFileDescriptor; 21 import android.os.RemoteException; 22 23 import com.android.server.backup.FileMetadata; 24 import com.android.server.backup.BackupManagerService; 25 26 import java.io.IOException; 27 28 /** 29 * Runner that can be placed in a separate thread to do in-process invocations of the full restore 30 * API asynchronously. Used by adb restore. 31 */ 32 class RestoreFileRunnable implements Runnable { 33 34 private final IBackupAgent mAgent; 35 private final FileMetadata mInfo; 36 private final ParcelFileDescriptor mSocket; 37 private final int mToken; 38 private final BackupManagerService mBackupManagerService; 39 40 RestoreFileRunnable(BackupManagerService backupManagerService, IBackupAgent agent, 41 FileMetadata info, ParcelFileDescriptor socket, int token) throws IOException { 42 mAgent = agent; 43 mInfo = info; 44 mToken = token; 45 46 // This class is used strictly for process-local binder invocations. The 47 // semantics of ParcelFileDescriptor differ in this case; in particular, we 48 // do not automatically get a 'dup'ed descriptor that we can can continue 49 // to use asynchronously from the caller. So, we make sure to dup it ourselves 50 // before proceeding to do the restore. 51 mSocket = ParcelFileDescriptor.dup(socket.getFileDescriptor()); 52 this.mBackupManagerService = backupManagerService; 53 } 54 55 @Override 56 public void run() { 57 try { 58 mAgent.doRestoreFile(mSocket, mInfo.size, mInfo.type, 59 mInfo.domain, mInfo.path, mInfo.mode, mInfo.mtime, 60 mToken, mBackupManagerService.getBackupManagerBinder()); 61 } catch (RemoteException e) { 62 // never happens; this is used strictly for local binder calls 63 } 64 } 65 } 66