Merge "Add a null check when getting TransportConnection in PFTBT" into tm-dev am: 64c8788e2c
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18321346 Change-Id: Ib10bf4562c9fbe73495fc26c82e9b6c8b2653b55 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -2359,13 +2359,37 @@ public class UserBackupManagerService {
|
||||
}
|
||||
} while (headBusy);
|
||||
|
||||
if (runBackup) {
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
String[] pkg = new String[]{entry.packageName};
|
||||
try {
|
||||
mRunningFullBackupTask = PerformFullTransportBackupTask.newWithCurrentTransport(
|
||||
this,
|
||||
mOperationStorage,
|
||||
/* observer */ null,
|
||||
pkg,
|
||||
/* updateSchedule */ true,
|
||||
scheduledJob,
|
||||
latch,
|
||||
/* backupObserver */ null,
|
||||
/* monitor */ null,
|
||||
/* userInitiated */ false,
|
||||
"BMS.beginFullBackup()",
|
||||
getEligibilityRulesForOperation(OperationType.BACKUP));
|
||||
} catch (IllegalStateException e) {
|
||||
Slog.w(TAG, "Failed to start backup", e);
|
||||
runBackup = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!runBackup) {
|
||||
if (DEBUG_SCHEDULING) {
|
||||
Slog.i(
|
||||
TAG,
|
||||
addUserIdToLogMessage(
|
||||
mUserId,
|
||||
"Nothing pending full backup; rescheduling +" + latency));
|
||||
"Nothing pending full backup or failed to start the "
|
||||
+ "operation; rescheduling +" + latency));
|
||||
}
|
||||
final long deferTime = latency; // pin for the closure
|
||||
FullBackupJob.schedule(mUserId, mContext, deferTime, mConstants);
|
||||
@@ -2374,21 +2398,6 @@ public class UserBackupManagerService {
|
||||
|
||||
// Okay, the top thing is ready for backup now. Do it.
|
||||
mFullBackupQueue.remove(0);
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
String[] pkg = new String[]{entry.packageName};
|
||||
mRunningFullBackupTask = PerformFullTransportBackupTask.newWithCurrentTransport(
|
||||
this,
|
||||
mOperationStorage,
|
||||
/* observer */ null,
|
||||
pkg,
|
||||
/* updateSchedule */ true,
|
||||
scheduledJob,
|
||||
latch,
|
||||
/* backupObserver */ null,
|
||||
/* monitor */ null,
|
||||
/* userInitiated */ false,
|
||||
"BMS.beginFullBackup()",
|
||||
getEligibilityRulesForOperation(OperationType.BACKUP));
|
||||
// Acquiring wakelock for PerformFullTransportBackupTask before its start.
|
||||
mWakelock.acquire();
|
||||
(new Thread(mRunningFullBackupTask)).start();
|
||||
@@ -2884,7 +2893,6 @@ public class UserBackupManagerService {
|
||||
public void fullTransportBackup(String[] pkgNames) {
|
||||
mContext.enforceCallingPermission(android.Manifest.permission.BACKUP,
|
||||
"fullTransportBackup");
|
||||
|
||||
final int callingUserHandle = UserHandle.getCallingUserId();
|
||||
// TODO: http://b/22388012
|
||||
if (callingUserHandle != UserHandle.USER_SYSTEM) {
|
||||
@@ -2936,6 +2944,9 @@ public class UserBackupManagerService {
|
||||
for (String pkg : pkgNames) {
|
||||
enqueueFullBackup(pkg, now);
|
||||
}
|
||||
} catch (IllegalStateException e) {
|
||||
Slog.w(TAG, "Failed to start backup: ", e);
|
||||
return;
|
||||
} finally {
|
||||
Binder.restoreCallingIdentity(oldId);
|
||||
}
|
||||
|
||||
@@ -99,6 +99,9 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||
* mBackupRunner.getBackupResultBlocking().
|
||||
*/
|
||||
public class PerformFullTransportBackupTask extends FullBackupTask implements BackupRestoreTask {
|
||||
/**
|
||||
* @throws IllegalStateException if there's no transport available.
|
||||
*/
|
||||
public static PerformFullTransportBackupTask newWithCurrentTransport(
|
||||
UserBackupManagerService backupManagerService,
|
||||
OperationStorage operationStorage,
|
||||
@@ -115,6 +118,9 @@ public class PerformFullTransportBackupTask extends FullBackupTask implements Ba
|
||||
TransportManager transportManager = backupManagerService.getTransportManager();
|
||||
TransportConnection transportConnection = transportManager.getCurrentTransportClient(
|
||||
caller);
|
||||
if (transportConnection == null) {
|
||||
throw new IllegalStateException("No TransportConnection available");
|
||||
}
|
||||
OnTaskFinishedListener listener =
|
||||
listenerCaller ->
|
||||
transportManager.disposeOfTransportClient(transportConnection,
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.server.backup.fullbackup;
|
||||
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.platform.test.annotations.Presubmit;
|
||||
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.android.server.backup.TransportManager;
|
||||
import com.android.server.backup.UserBackupManagerService;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
@Presubmit
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class PerformFullTransportBackupTaskTest {
|
||||
@Mock
|
||||
UserBackupManagerService mBackupManagerService;
|
||||
@Mock
|
||||
TransportManager mTransportManager;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
when(mBackupManagerService.getTransportManager()).thenReturn(mTransportManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNewWithCurrentTransport_noTransportConnection_throws() {
|
||||
when(mTransportManager.getCurrentTransportClient(any())).thenReturn(null);
|
||||
|
||||
assertThrows(IllegalStateException.class,
|
||||
() -> {
|
||||
PerformFullTransportBackupTask task = PerformFullTransportBackupTask
|
||||
.newWithCurrentTransport(
|
||||
mBackupManagerService,
|
||||
/* operationStorage */ null,
|
||||
/* observer */ null,
|
||||
/* whichPackages */ null,
|
||||
/* updateSchedule */ false,
|
||||
/* runningJob */ null,
|
||||
/* latch */ null,
|
||||
/* backupObserver */ null,
|
||||
/* monitor */ null,
|
||||
/* userInitiated */ false,
|
||||
/* caller */ null,
|
||||
/* backupEligibilityRules */ null);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user