aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Desprez <jdesprez@google.com>2019-05-28 09:09:49 -0700
committerHsin-Yi Chen <hsinyichen@google.com>2019-06-10 18:11:18 +0800
commit09dc2f2f6805b67b9ce42a7a1f27613dff52adf6 (patch)
treea426f5143ed862e30310b450c2fc053a2c86d076
parentad7ca52458974dcdd00f8c0f3436783a53643945 (diff)
downloadtradefederation-09dc2f2f6805b67b9ce42a7a1f27613dff52adf6.tar.gz
Fix the encryption support detection
use the ro.crypto.state property to properly get the device support of encryption. Test: unit tests Bug: 132275223 Change-Id: Ia873a6f9d0750ede3fb7436fd3f6d00ec951896b Merged-In: Ia873a6f9d0750ede3fb7436fd3f6d00ec951896b (cherry picked from commit f10e205267f29438f8573e04abf9d4ce1e97d567)
-rw-r--r--src/com/android/tradefed/device/NativeDevice.java13
-rw-r--r--tests/src/com/android/tradefed/device/TestDeviceTest.java12
2 files changed, 12 insertions, 13 deletions
diff --git a/src/com/android/tradefed/device/NativeDevice.java b/src/com/android/tradefed/device/NativeDevice.java
index 3e702ec9e..d03ad9fda 100644
--- a/src/com/android/tradefed/device/NativeDevice.java
+++ b/src/com/android/tradefed/device/NativeDevice.java
@@ -3188,7 +3188,7 @@ public class NativeDevice implements IManagedTestDevice {
CLog.w("Property ro.crypto.state is null on device %s", getSerialNumber());
}
- return "encrypted".equals(output);
+ return "encrypted".equals(output.trim());
}
/**
@@ -3205,11 +3205,13 @@ public class NativeDevice implements IManagedTestDevice {
return mIsEncryptionSupported.booleanValue();
}
enableAdbRoot();
- String output = executeShellCommand("vdc cryptfs enablecrypto").trim();
- mIsEncryptionSupported =
- (output != null
- && Pattern.matches("(500)(\\s+)(\\d+)(\\s+)(Usage)(.*)(:)(.*)", output));
+ String output = getProperty("ro.crypto.state");
+ if (output == null || "unsupported".equals(output.trim())) {
+ mIsEncryptionSupported = false;
+ return mIsEncryptionSupported;
+ }
+ mIsEncryptionSupported = true;
return mIsEncryptionSupported;
}
@@ -3944,6 +3946,7 @@ public class NativeDevice implements IManagedTestDevice {
/** {@inheritDoc} */
@Override
public void postInvocationTearDown() {
+ mIsEncryptionSupported = null;
// Default implementation
if (getIDevice() instanceof StubDevice) {
return;
diff --git a/tests/src/com/android/tradefed/device/TestDeviceTest.java b/tests/src/com/android/tradefed/device/TestDeviceTest.java
index d82415ebc..66a7bcd3d 100644
--- a/tests/src/com/android/tradefed/device/TestDeviceTest.java
+++ b/tests/src/com/android/tradefed/device/TestDeviceTest.java
@@ -1170,7 +1170,7 @@ public class TestDeviceTest extends TestCase {
*/
private void setEncryptedUnsupportedExpectations() throws Exception {
setEnableAdbRootExpectations();
- injectShellResponse("vdc cryptfs enablecrypto", "\r\n");
+ injectSystemProperty("ro.crypto.state", "unsupported");
}
/**
@@ -1178,9 +1178,7 @@ public class TestDeviceTest extends TestCase {
*/
private void setEncryptedSupported() throws Exception {
setEnableAdbRootExpectations();
- injectShellResponse("vdc cryptfs enablecrypto",
- "500 29805 Usage: cryptfs enablecrypto <wipe|inplace> "
- + "default|password|pin|pattern [passwd] [noui]\r\n");
+ injectSystemProperty("ro.crypto.state", "encrypted");
}
/**
@@ -3633,9 +3631,7 @@ public class TestDeviceTest extends TestCase {
return true;
}
};
- injectShellResponse(
- "vdc cryptfs enablecrypto",
- "500 8674 Usage with ext4crypt: cryptfs enablecrypto inplace default noui\r\n");
+ injectSystemProperty("ro.crypto.state", "encrypted");
EasyMock.replay(mMockIDevice, mMockStateMonitor, mMockDvcMonitor);
assertTrue(mTestDevice.isEncryptionSupported());
EasyMock.verify(mMockIDevice, mMockStateMonitor, mMockDvcMonitor);
@@ -3655,7 +3651,7 @@ public class TestDeviceTest extends TestCase {
return true;
}
};
- injectShellResponse("vdc cryptfs enablecrypto", "500 8674 Command not recognized\r\n");
+ injectSystemProperty("ro.crypto.state", "unsupported");
EasyMock.replay(mMockIDevice, mMockStateMonitor, mMockDvcMonitor);
assertFalse(mTestDevice.isEncryptionSupported());
EasyMock.verify(mMockIDevice, mMockStateMonitor, mMockDvcMonitor);