Skip to content

Commit

Permalink
Internal change
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 718773322
  • Loading branch information
ZeekWang authored and copybara-github committed Jan 23, 2025
1 parent 2205b0b commit 946f66a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ public abstract class AndroidRealDeviceDelegate {

private static final FluentLogger logger = FluentLogger.forEnclosingClass();

// The property written to the device before resetting. The value of this property will be checked
// to confirm whether the device was reset successfully.
private static final String RESET_PROPERTY_LABEL = "debug.mobileharness.before_reset";

/** Last time record for checkPingGoogle method in order to call it every 30 minutes. */
private Instant lastCheckPingGoogleTime = null;

Expand Down Expand Up @@ -454,6 +458,10 @@ private void resetDevice() throws MobileHarnessException, InterruptedException {

boolean isOverTcpDevice = DeviceUtil.isOverTcpDevice(deviceId);
cacheDevice(deviceId, AndroidRealDeviceConstants.WAIT_FOR_REBOOT_TIMEOUT);

// Set the property to the device. Will check the value of this property after resetting to
// ensure the reset is successful.
androidAdbUtil.setProperty(deviceId, RESET_PROPERTY_LABEL, "true", /* ignoreError= */ false);
try {
logger.atInfo().log("Start to factory reset device %s via test harness", deviceId);
systemStateUtil.factoryResetViaTestHarness(deviceId, /* waitTime= */ null);
Expand All @@ -476,6 +484,20 @@ private void resetDevice() throws MobileHarnessException, InterruptedException {
} finally {
invalidateCacheDevice(deviceId);
}

try {
if (!Strings.isNullOrEmpty(
androidAdbUtil.getProperty(deviceId, ImmutableList.of(RESET_PROPERTY_LABEL)))) {
throw new MobileHarnessException(
AndroidErrorId.ANDROID_REAL_DEVICE_DELEGATE_RESET_DEVICE_FAILED,
String.format(
"The property %s is not deleted after resetting on device %s, which means the"
+ " device is not reset successfully.",
RESET_PROPERTY_LABEL, deviceId));
}
} finally {
androidAdbUtil.setProperty(deviceId, RESET_PROPERTY_LABEL, "", /* ignoreError= */ true);
}
logger.atInfo().log("Device %s reset is done", deviceId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ public enum AndroidErrorId implements ErrorId {
ANDROID_REAL_DEVICE_DELEGATE_RECOVERY_DEVICE_TO_REBOOT(111_201, ErrorType.INFRA_ISSUE),
ANDROID_REAL_DEVICE_DELEGATE_FASTBOOT_DEVICE_TO_REBOOT(111_202, ErrorType.INFRA_ISSUE),
ANDROID_REAL_DEVICE_DELEGATE_UNDETECTED_DURING_INIT(111_203, ErrorType.INFRA_ISSUE),
ANDROID_REAL_DEVICE_DELEGATE_RESET_DEVICE_FAILED(111_204, ErrorType.INFRA_ISSUE),

/** Android Drivers: 115_001 ~ 125_000 */
// Android Instrumentation: 115_001 ~ 115_500
Expand Down

0 comments on commit 946f66a

Please sign in to comment.