Merge "Fix a no-op uninstall being treated as a failure" into oc-mr1-dev

This commit is contained in:
Neil Fuller
2017-09-15 17:56:16 +00:00
committed by Android (Google) Code Review
2 changed files with 50 additions and 14 deletions

View File

@@ -343,16 +343,20 @@ public final class RulesManagerService extends IRulesManager.Stub {
@Override @Override
public void run() { public void run() {
EventLogTags.writeTimezoneUninstallStarted(toStringOrNull(mCheckToken)); EventLogTags.writeTimezoneUninstallStarted(toStringOrNull(mCheckToken));
boolean success = false; boolean packageTrackerStatus = false;
try { try {
success = mInstaller.stageUninstall(); int uninstallResult = mInstaller.stageUninstall();
// Right now we just have success (0) / failure (1). All clients should be checking packageTrackerStatus = (uninstallResult == TimeZoneDistroInstaller.UNINSTALL_SUCCESS
// against SUCCESS. More granular failures may be added in future. || uninstallResult == TimeZoneDistroInstaller.UNINSTALL_NOTHING_INSTALLED);
int resultCode = success ? Callback.SUCCESS
: Callback.ERROR_UNKNOWN_FAILURE; // Right now we just have Callback.SUCCESS / Callback.ERROR_UNKNOWN_FAILURE for
// uninstall. All clients should be checking against SUCCESS. More granular failures
// may be added in future.
int callbackResultCode =
packageTrackerStatus ? Callback.SUCCESS : Callback.ERROR_UNKNOWN_FAILURE;
EventLogTags.writeTimezoneUninstallComplete( EventLogTags.writeTimezoneUninstallComplete(
toStringOrNull(mCheckToken), resultCode); toStringOrNull(mCheckToken), callbackResultCode);
sendFinishedStatus(mCallback, resultCode); sendFinishedStatus(mCallback, callbackResultCode);
} catch (Exception e) { } catch (Exception e) {
EventLogTags.writeTimezoneUninstallComplete( EventLogTags.writeTimezoneUninstallComplete(
toStringOrNull(mCheckToken), Callback.ERROR_UNKNOWN_FAILURE); toStringOrNull(mCheckToken), Callback.ERROR_UNKNOWN_FAILURE);
@@ -360,7 +364,7 @@ public final class RulesManagerService extends IRulesManager.Stub {
sendFinishedStatus(mCallback, Callback.ERROR_UNKNOWN_FAILURE); sendFinishedStatus(mCallback, Callback.ERROR_UNKNOWN_FAILURE);
} finally { } finally {
// Notify the package tracker that the operation is now complete. // Notify the package tracker that the operation is now complete.
mPackageTracker.recordCheckResult(mCheckToken, success); mPackageTracker.recordCheckResult(mCheckToken, packageTrackerStatus);
mOperationInProgress.set(false); mOperationInProgress.set(false);
} }

View File

@@ -585,7 +585,39 @@ public class RulesManagerServiceTest {
verifyNoPackageTrackerCallsMade(); verifyNoPackageTrackerCallsMade();
// Set up the installer. // Set up the installer.
configureStageUninstallExpectation(true /* success */); configureStageUninstallExpectation(TimeZoneDistroInstaller.UNINSTALL_SUCCESS);
// Simulate the async execution.
mFakeExecutor.simulateAsyncExecutionOfLastCommand();
// Verify the expected calls were made to other components.
verifyStageUninstallCalled();
verifyPackageTrackerCalled(token, true /* success */);
// Check the callback was called.
callback.assertResultReceived(Callback.SUCCESS);
}
@Test
public void requestUninstall_asyncNothingInstalled() throws Exception {
configureCallerHasPermission();
CheckToken token = createArbitraryToken();
byte[] tokenBytes = token.toByteArray();
TestCallback callback = new TestCallback();
// Request the uninstall.
assertEquals(RulesManager.SUCCESS,
mRulesManagerService.requestUninstall(tokenBytes, callback));
// Assert nothing has happened yet.
callback.assertNoResultReceived();
verifyNoInstallerCallsMade();
verifyNoPackageTrackerCallsMade();
// Set up the installer.
configureStageUninstallExpectation(TimeZoneDistroInstaller.UNINSTALL_NOTHING_INSTALLED);
// Simulate the async execution. // Simulate the async execution.
mFakeExecutor.simulateAsyncExecutionOfLastCommand(); mFakeExecutor.simulateAsyncExecutionOfLastCommand();
@@ -613,7 +645,7 @@ public class RulesManagerServiceTest {
callback.assertNoResultReceived(); callback.assertNoResultReceived();
// Set up the installer. // Set up the installer.
configureStageUninstallExpectation(true /* success */); configureStageUninstallExpectation(TimeZoneDistroInstaller.UNINSTALL_SUCCESS);
// Simulate the async execution. // Simulate the async execution.
mFakeExecutor.simulateAsyncExecutionOfLastCommand(); mFakeExecutor.simulateAsyncExecutionOfLastCommand();
@@ -644,7 +676,7 @@ public class RulesManagerServiceTest {
callback.assertNoResultReceived(); callback.assertNoResultReceived();
// Set up the installer. // Set up the installer.
configureStageUninstallExpectation(false /* success */); configureStageUninstallExpectation(TimeZoneDistroInstaller.UNINSTALL_FAIL);
// Simulate the async execution. // Simulate the async execution.
mFakeExecutor.simulateAsyncExecutionOfLastCommand(); mFakeExecutor.simulateAsyncExecutionOfLastCommand();
@@ -849,8 +881,8 @@ public class RulesManagerServiceTest {
.thenReturn(resultCode); .thenReturn(resultCode);
} }
private void configureStageUninstallExpectation(boolean success) throws Exception { private void configureStageUninstallExpectation(int resultCode) throws Exception {
doReturn(success).when(mMockTimeZoneDistroInstaller).stageUninstall(); doReturn(resultCode).when(mMockTimeZoneDistroInstaller).stageUninstall();
} }
private void verifyStageInstallCalled() throws Exception { private void verifyStageInstallCalled() throws Exception {