1 /*
2  * Copyright (C) 2023 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 android.app.backup;
18 
19 import android.os.ParcelFileDescriptor;
20 
21 /**
22  * Utility class for writing BackupHelpers with added logging capabilities.
23  * Used for passing a logger object to Helper in key shared backup agents
24  *
25  * @hide
26  */
27 public abstract class BackupHelperWithLogger implements BackupHelper {
28     private BackupRestoreEventLogger mLogger;
29     private boolean mIsLoggerSet = false;
30 
writeNewStateDescription(ParcelFileDescriptor newState)31     public abstract void writeNewStateDescription(ParcelFileDescriptor newState);
32 
restoreEntity(BackupDataInputStream data)33     public abstract void restoreEntity(BackupDataInputStream data);
34 
performBackup(ParcelFileDescriptor oldState, BackupDataOutput data, ParcelFileDescriptor newState)35     public abstract void performBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
36             ParcelFileDescriptor newState);
37 
38     /**
39      * Gets the logger so that the backuphelper can log success/error for each datatype handled
40      */
getLogger()41     public BackupRestoreEventLogger getLogger() {
42         return mLogger;
43     }
44 
45     /**
46      * Allow the shared backup agent to pass a logger to each of its backup helper
47      */
setLogger(BackupRestoreEventLogger logger)48     public void setLogger(BackupRestoreEventLogger logger) {
49         mLogger = logger;
50         mIsLoggerSet = true;
51     }
52 
53     /**
54      * Allow the helper to check if its shared backup agent has passed a logger
55      */
isLoggerSet()56     public boolean isLoggerSet() {
57         return mIsLoggerSet;
58     }
59 }
60