From daeeefa207ca53241f18ea99abaf79d5dcf913f0 Mon Sep 17 00:00:00 2001 From: Nikita Ioffe Date: Thu, 23 Jan 2020 17:03:53 +0000 Subject: Escape adb shell "setprop ${prop_name} '${value}'" This will allow passing an empty string as value, which is an equivalent of resetting property value (see another CL in this topic). Test: tools/tradefederation/core/tests/run_tradefed_tests.sh --class com.android.tradefed.device.NativeDeviceTest Test: presubmit Bug: 242332243 Change-Id: Ie375133df94bf0ffe15d78350f9d8fb8f15d1e18 Merged-In: Ie375133df94bf0ffe15d78350f9d8fb8f15d1e18 (cherry picked from commit eaba4425ceb6cfe57152bdf9aef9fb8cc8994896) --- src/com/android/tradefed/device/NativeDevice.java | 8 +++++--- tests/src/com/android/tradefed/device/NativeDeviceTest.java | 10 ++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/com/android/tradefed/device/NativeDevice.java b/src/com/android/tradefed/device/NativeDevice.java index cb1c91505..5850ebc3c 100644 --- a/src/com/android/tradefed/device/NativeDevice.java +++ b/src/com/android/tradefed/device/NativeDevice.java @@ -470,12 +470,14 @@ public class NativeDevice implements IManagedTestDevice { CLog.e("setProperty requires adb root = true."); return false; } - CommandResult result = - executeShellV2Command(String.format("setprop \"%s\" \"%s\"", propKey, propValue)); + String setPropCmd = String.format("\"setprop %s '%s'\"", propKey, propValue); + CommandResult result = executeShellV2Command(setPropCmd); if (CommandStatus.SUCCESS.equals(result.getStatus())) { return true; } - CLog.e("Something went wrong went setting property %s: %s", propKey, result.getStderr()); + CLog.e( + "Something went wrong went setting property %s (command: %s): %s", + propKey, setPropCmd, result.getStderr()); return false; } diff --git a/tests/src/com/android/tradefed/device/NativeDeviceTest.java b/tests/src/com/android/tradefed/device/NativeDeviceTest.java index 27d5ce6c2..430434e24 100644 --- a/tests/src/com/android/tradefed/device/NativeDeviceTest.java +++ b/tests/src/com/android/tradefed/device/NativeDeviceTest.java @@ -2471,8 +2471,14 @@ public class NativeDeviceTest { res.setStatus(CommandStatus.SUCCESS); EasyMock.expect( mMockRunUtil.runTimedCmd( - 120000, stdout, stderr, "adb", "-s", "serial", "shell", "setprop", - "test", "value")) + 120000, + stdout, + stderr, + "adb", + "-s", + "serial", + "shell", + "setprop test 'value'")) .andReturn(res); EasyMock.replay(mMockRunUtil, mMockIDevice); assertTrue(mTestDevice.setProperty("test", "value")); -- cgit v1.2.3