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 17package com.android.server.backup.fullbackup; 18 19import static com.android.server.backup.BackupManagerService.TAG; 20 21import android.app.backup.IFullBackupRestoreObserver; 22import android.os.RemoteException; 23import android.util.Slog; 24 25/** 26 * Generic driver skeleton for full backup operations. 27 */ 28public abstract class FullBackupTask implements Runnable { 29 30 IFullBackupRestoreObserver mObserver; 31 32 FullBackupTask(IFullBackupRestoreObserver observer) { 33 mObserver = observer; 34 } 35 36 // wrappers for observer use 37 final void sendStartBackup() { 38 if (mObserver != null) { 39 try { 40 mObserver.onStartBackup(); 41 } catch (RemoteException e) { 42 Slog.w(TAG, "full backup observer went away: startBackup"); 43 mObserver = null; 44 } 45 } 46 } 47 48 final void sendOnBackupPackage(String name) { 49 if (mObserver != null) { 50 try { 51 // TODO: use a more user-friendly name string 52 mObserver.onBackupPackage(name); 53 } catch (RemoteException e) { 54 Slog.w(TAG, "full backup observer went away: backupPackage"); 55 mObserver = null; 56 } 57 } 58 } 59 60 final void sendEndBackup() { 61 if (mObserver != null) { 62 try { 63 mObserver.onEndBackup(); 64 } catch (RemoteException e) { 65 Slog.w(TAG, "full backup observer went away: endBackup"); 66 mObserver = null; 67 } 68 } 69 } 70} 71