From ad3e1331f3311b0351856e29001610d6ff39f082 Mon Sep 17 00:00:00 2001 From: Neil Fuller Date: Mon, 22 Jan 2018 12:17:14 +0000 Subject: [PATCH] Improve dumpsys for installed distros The RuleManagerService would previously refuse to return the current distro install status if there was a staging operation in progress. Since a staging operation only affects what is staged, not what is actually installed, this restriction can be relaxed. This should make tests that were previously getting "Unknown" state more reliable. Test: PTS: run pts -m PtsTimeZoneTestCases Test: atest FrameworksServicesTests Change-Id: I06449bc8dad6d96adf7e9edceee69cfaf24facb0 --- .../java/android/app/timezone/RulesState.java | 3 -- .../server/timezone/RulesManagerService.java | 41 +++++++++---------- .../timezone/RulesManagerServiceTest.java | 4 +- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/core/java/android/app/timezone/RulesState.java b/core/java/android/app/timezone/RulesState.java index 16309fab0924b..e86d348a85fa1 100644 --- a/core/java/android/app/timezone/RulesState.java +++ b/core/java/android/app/timezone/RulesState.java @@ -126,9 +126,6 @@ public final class RulesState implements Parcelable { mStagedOperationType == STAGED_OPERATION_INSTALL /* requireNotNull */, "stagedDistroRulesVersion", stagedDistroRulesVersion); - if (operationInProgress && distroStatus != DISTRO_STATUS_UNKNOWN) { - throw new IllegalArgumentException("distroInstalled != DISTRO_STATUS_UNKNOWN"); - } this.mDistroStatus = validateDistroStatus(distroStatus); this.mInstalledDistroRulesVersion = validateConditionalNull( mDistroStatus == DISTRO_STATUS_INSTALLED/* requireNotNull */, diff --git a/services/core/java/com/android/server/timezone/RulesManagerService.java b/services/core/java/com/android/server/timezone/RulesManagerService.java index 30fc63c2a1b0b..be9b204721dbb 100644 --- a/services/core/java/com/android/server/timezone/RulesManagerService.java +++ b/services/core/java/com/android/server/timezone/RulesManagerService.java @@ -143,6 +143,26 @@ public final class RulesManagerService extends IRulesManager.Stub { return null; } + // Determine the installed distro state. This should be possible regardless of whether + // there's an operation in progress. + DistroVersion installedDistroVersion; + int distroStatus = DISTRO_STATUS_UNKNOWN; + DistroRulesVersion installedDistroRulesVersion = null; + try { + installedDistroVersion = mInstaller.getInstalledDistroVersion(); + if (installedDistroVersion == null) { + distroStatus = DISTRO_STATUS_NONE; + installedDistroRulesVersion = null; + } else { + distroStatus = DISTRO_STATUS_INSTALLED; + installedDistroRulesVersion = new DistroRulesVersion( + installedDistroVersion.rulesVersion, + installedDistroVersion.revision); + } + } catch (DistroException | IOException e) { + Slog.w(TAG, "Failed to read installed distro.", e); + } + boolean operationInProgress = this.mOperationInProgress.get(); // Determine the staged operation status, if possible. @@ -168,27 +188,6 @@ public final class RulesManagerService extends IRulesManager.Stub { Slog.w(TAG, "Failed to read staged distro.", e); } } - - // Determine the installed distro state, if possible. - DistroVersion installedDistroVersion; - int distroStatus = DISTRO_STATUS_UNKNOWN; - DistroRulesVersion installedDistroRulesVersion = null; - if (!operationInProgress) { - try { - installedDistroVersion = mInstaller.getInstalledDistroVersion(); - if (installedDistroVersion == null) { - distroStatus = DISTRO_STATUS_NONE; - installedDistroRulesVersion = null; - } else { - distroStatus = DISTRO_STATUS_INSTALLED; - installedDistroRulesVersion = new DistroRulesVersion( - installedDistroVersion.rulesVersion, - installedDistroVersion.revision); - } - } catch (DistroException | IOException e) { - Slog.w(TAG, "Failed to read installed distro.", e); - } - } return new RulesState(systemRulesVersion, DISTRO_FORMAT_VERSION_SUPPORTED, operationInProgress, stagedOperationStatus, stagedDistroRulesVersion, distroStatus, installedDistroRulesVersion); diff --git a/services/tests/servicestests/src/com/android/server/timezone/RulesManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/timezone/RulesManagerServiceTest.java index d09d0c8d9e5cd..1cfae1ef1a6d8 100644 --- a/services/tests/servicestests/src/com/android/server/timezone/RulesManagerServiceTest.java +++ b/services/tests/servicestests/src/com/android/server/timezone/RulesManagerServiceTest.java @@ -289,11 +289,13 @@ public class RulesManagerServiceTest { // Request the rules state while the async operation is "happening". RulesState actualRulesState = mRulesManagerService.getRulesState(); + DistroRulesVersion expectedInstalledDistroRulesVersion = + new DistroRulesVersion(installedRulesVersion, revision); RulesState expectedRuleState = new RulesState( systemRulesVersion, RulesManagerService.DISTRO_FORMAT_VERSION_SUPPORTED, true /* operationInProgress */, RulesState.STAGED_OPERATION_UNKNOWN, null /* stagedDistroRulesVersion */, - RulesState.DISTRO_STATUS_UNKNOWN, null /* installedDistroRulesVersion */); + RulesState.DISTRO_STATUS_INSTALLED, expectedInstalledDistroRulesVersion); assertEquals(expectedRuleState, actualRulesState); }