Merge "Add a null check when getting TransportConnection in PFTBT" into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
64c8788e2c
@@ -2359,23 +2359,10 @@ public class UserBackupManagerService {
|
|||||||
}
|
}
|
||||||
} while (headBusy);
|
} while (headBusy);
|
||||||
|
|
||||||
if (!runBackup) {
|
if (runBackup) {
|
||||||
if (DEBUG_SCHEDULING) {
|
|
||||||
Slog.i(
|
|
||||||
TAG,
|
|
||||||
addUserIdToLogMessage(
|
|
||||||
mUserId,
|
|
||||||
"Nothing pending full backup; rescheduling +" + latency));
|
|
||||||
}
|
|
||||||
final long deferTime = latency; // pin for the closure
|
|
||||||
FullBackupJob.schedule(mUserId, mContext, deferTime, mConstants);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Okay, the top thing is ready for backup now. Do it.
|
|
||||||
mFullBackupQueue.remove(0);
|
|
||||||
CountDownLatch latch = new CountDownLatch(1);
|
CountDownLatch latch = new CountDownLatch(1);
|
||||||
String[] pkg = new String[]{entry.packageName};
|
String[] pkg = new String[]{entry.packageName};
|
||||||
|
try {
|
||||||
mRunningFullBackupTask = PerformFullTransportBackupTask.newWithCurrentTransport(
|
mRunningFullBackupTask = PerformFullTransportBackupTask.newWithCurrentTransport(
|
||||||
this,
|
this,
|
||||||
mOperationStorage,
|
mOperationStorage,
|
||||||
@@ -2389,6 +2376,28 @@ public class UserBackupManagerService {
|
|||||||
/* userInitiated */ false,
|
/* userInitiated */ false,
|
||||||
"BMS.beginFullBackup()",
|
"BMS.beginFullBackup()",
|
||||||
getEligibilityRulesForOperation(OperationType.BACKUP));
|
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 or failed to start the "
|
||||||
|
+ "operation; rescheduling +" + latency));
|
||||||
|
}
|
||||||
|
final long deferTime = latency; // pin for the closure
|
||||||
|
FullBackupJob.schedule(mUserId, mContext, deferTime, mConstants);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Okay, the top thing is ready for backup now. Do it.
|
||||||
|
mFullBackupQueue.remove(0);
|
||||||
// Acquiring wakelock for PerformFullTransportBackupTask before its start.
|
// Acquiring wakelock for PerformFullTransportBackupTask before its start.
|
||||||
mWakelock.acquire();
|
mWakelock.acquire();
|
||||||
(new Thread(mRunningFullBackupTask)).start();
|
(new Thread(mRunningFullBackupTask)).start();
|
||||||
@@ -2884,7 +2893,6 @@ public class UserBackupManagerService {
|
|||||||
public void fullTransportBackup(String[] pkgNames) {
|
public void fullTransportBackup(String[] pkgNames) {
|
||||||
mContext.enforceCallingPermission(android.Manifest.permission.BACKUP,
|
mContext.enforceCallingPermission(android.Manifest.permission.BACKUP,
|
||||||
"fullTransportBackup");
|
"fullTransportBackup");
|
||||||
|
|
||||||
final int callingUserHandle = UserHandle.getCallingUserId();
|
final int callingUserHandle = UserHandle.getCallingUserId();
|
||||||
// TODO: http://b/22388012
|
// TODO: http://b/22388012
|
||||||
if (callingUserHandle != UserHandle.USER_SYSTEM) {
|
if (callingUserHandle != UserHandle.USER_SYSTEM) {
|
||||||
@@ -2936,6 +2944,9 @@ public class UserBackupManagerService {
|
|||||||
for (String pkg : pkgNames) {
|
for (String pkg : pkgNames) {
|
||||||
enqueueFullBackup(pkg, now);
|
enqueueFullBackup(pkg, now);
|
||||||
}
|
}
|
||||||
|
} catch (IllegalStateException e) {
|
||||||
|
Slog.w(TAG, "Failed to start backup: ", e);
|
||||||
|
return;
|
||||||
} finally {
|
} finally {
|
||||||
Binder.restoreCallingIdentity(oldId);
|
Binder.restoreCallingIdentity(oldId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,6 +99,9 @@ import java.util.concurrent.atomic.AtomicLong;
|
|||||||
* mBackupRunner.getBackupResultBlocking().
|
* mBackupRunner.getBackupResultBlocking().
|
||||||
*/
|
*/
|
||||||
public class PerformFullTransportBackupTask extends FullBackupTask implements BackupRestoreTask {
|
public class PerformFullTransportBackupTask extends FullBackupTask implements BackupRestoreTask {
|
||||||
|
/**
|
||||||
|
* @throws IllegalStateException if there's no transport available.
|
||||||
|
*/
|
||||||
public static PerformFullTransportBackupTask newWithCurrentTransport(
|
public static PerformFullTransportBackupTask newWithCurrentTransport(
|
||||||
UserBackupManagerService backupManagerService,
|
UserBackupManagerService backupManagerService,
|
||||||
OperationStorage operationStorage,
|
OperationStorage operationStorage,
|
||||||
@@ -115,6 +118,9 @@ public class PerformFullTransportBackupTask extends FullBackupTask implements Ba
|
|||||||
TransportManager transportManager = backupManagerService.getTransportManager();
|
TransportManager transportManager = backupManagerService.getTransportManager();
|
||||||
TransportConnection transportConnection = transportManager.getCurrentTransportClient(
|
TransportConnection transportConnection = transportManager.getCurrentTransportClient(
|
||||||
caller);
|
caller);
|
||||||
|
if (transportConnection == null) {
|
||||||
|
throw new IllegalStateException("No TransportConnection available");
|
||||||
|
}
|
||||||
OnTaskFinishedListener listener =
|
OnTaskFinishedListener listener =
|
||||||
listenerCaller ->
|
listenerCaller ->
|
||||||
transportManager.disposeOfTransportClient(transportConnection,
|
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