• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.utils;
18 
19 import static com.android.server.backup.BackupManagerService.TAG;
20 
21 import android.app.backup.BackupProgress;
22 import android.app.backup.IBackupObserver;
23 import android.os.RemoteException;
24 import android.util.Slog;
25 
26 /**
27  * Utility methods to communicate with BackupObserver.
28  */
29 public class BackupObserverUtils {
30     /**
31      * Wraps {@link IBackupObserver#onUpdate(String, BackupProgress)} to handle RemoteException,
32      * so that the caller doesn't have to.
33      */
sendBackupOnUpdate(IBackupObserver observer, String packageName, BackupProgress progress)34     public static void sendBackupOnUpdate(IBackupObserver observer, String packageName,
35             BackupProgress progress) {
36         if (observer != null) {
37             try {
38                 observer.onUpdate(packageName, progress);
39             } catch (RemoteException e) {
40                 Slog.w(TAG, "Backup observer went away: onUpdate");
41             }
42         }
43     }
44 
45     /**
46      * Wraps {@link IBackupObserver#onResult(String, int)} to handle RemoteException, so that the
47      * caller doesn't have to.
48      */
sendBackupOnPackageResult(IBackupObserver observer, String packageName, int status)49     public static void sendBackupOnPackageResult(IBackupObserver observer, String packageName,
50             int status) {
51         if (observer != null) {
52             try {
53                 observer.onResult(packageName, status);
54             } catch (RemoteException e) {
55                 Slog.w(TAG, "Backup observer went away: onResult");
56             }
57         }
58     }
59 
60     /**
61      * Wraps {@link IBackupObserver#backupFinished(int)} to handle RemoteException, so that the
62      * caller doesn't have to.
63      */
sendBackupFinished(IBackupObserver observer, int status)64     public static void sendBackupFinished(IBackupObserver observer, int status) {
65         if (observer != null) {
66             try {
67                 observer.backupFinished(status);
68             } catch (RemoteException e) {
69                 Slog.w(TAG, "Backup observer went away: backupFinished");
70             }
71         }
72     }
73 }
74