Fix NPE when null BackupObserver is passed into BackupManager#requestBackup()

BackupManagerService has the null check, but it doesn't work
because passed BackupObserver object is wrapped into
this BackupObserverWrapper.
This was found during GTS testing.

Bug: 27334738
Change-Id: I16dc0230824b326d3fae1f8489f58b0c0d4e1c7c
This commit is contained in:
Sergey Poromov
2016-02-24 17:21:59 +01:00
parent cf7518f78a
commit 899edf6f4f

View File

@@ -468,7 +468,7 @@ public class BackupManager {
*
* @param packages List of package names to backup.
* @param observer The {@link BackupObserver} to receive callbacks during the backup
* operation.
* operation. Could be {@code null}.
* @return {@link BackupManager#SUCCESS} on success; nonzero on error.
* @exception IllegalArgumentException on null or empty {@code packages} param.
*
@@ -479,8 +479,9 @@ public class BackupManager {
checkServiceBinder();
if (sService != null) {
try {
BackupObserverWrapper observerWrapper =
new BackupObserverWrapper(mContext, observer);
BackupObserverWrapper observerWrapper = observer == null
? null
: new BackupObserverWrapper(mContext, observer);
return sService.requestBackup(packages, observerWrapper);
} catch (RemoteException e) {
Log.e(TAG, "requestBackup() couldn't connect");