Allow any character except square brackets in property values

PropertyManager failed to get all properties from certain devices
because it allowed only [a-zA-Z0-9_.-] characters in values but
they can contain other characters too. For example in Nexus 9
ro.product.model is "Nexus 9" (has space).

This commit changes allowed characters in property value to contain
anything except square brackets.
This commit is contained in:
Jari Hämäläinen 2017-01-28 16:53:13 +02:00
parent 0cb9550b50
commit 206b9c4352
2 changed files with 33 additions and 1 deletions

View File

@ -27,7 +27,7 @@ public class PropertyManager {
}
private Map<String, String> parseProp(BufferedReader bufferedReader) throws IOException {
final Pattern pattern = Pattern.compile("^\\[([a-zA-Z0-9_.-]*)\\]:.\\[([a-zA-Z0-9_.-]*)\\]");
final Pattern pattern = Pattern.compile("^\\[([a-zA-Z0-9_.-]*)\\]:.\\[([^\\[\\]]*)\\]");
HashMap<String, String> result = new HashMap<>();

View File

@ -55,6 +55,38 @@ public class PropertyManagerTest {
assertEquals(expected, actual);
}
@Test
public void testGetPropsValueHasSpecialCharacters() throws Exception {
/* Some example properties from Nexus 9:
[ro.product.model]: [Nexus 9]
[ro.product.cpu.abilist]: [arm64-v8a,armeabi-v7a,armeabi]
[ro.retaildemo.video_path]: [/data/preloads/demo/retail_demo.mp4]
[ro.url.legal]: [http://www.google.com/intl/%s/mobile/android/basic/phone-legal.html]
[ro.vendor.build.date]: [Tue Nov 1 18:21:23 UTC 2016]
*/
//Arrange
Map<String, String> expected = new HashMap<>();
expected.put("ro.product.model", "Nexus 9");
expected.put("ro.product.cpu.abilist", "arm64-v8a,armeabi-v7a,armeabi");
expected.put("ro.retaildemo.video_path", "/data/preloads/demo/retail_demo.mp4");
expected.put("ro.url.legal", "http://www.google.com/intl/%s/mobile/android/basic/phone-legal.html");
expected.put("ro.vendor.build.date", "Tue Nov 1 18:21:23 UTC 2016");
String response = "[ro.product.model]: [Nexus 9]\n" +
"[ro.product.cpu.abilist]: [arm64-v8a,armeabi-v7a,armeabi]\n" +
"[ro.retaildemo.video_path]: [/data/preloads/demo/retail_demo.mp4]\n" +
"[ro.url.legal]: [http://www.google.com/intl/%s/mobile/android/basic/phone-legal.html]\n" +
"[ro.vendor.build.date]: [Tue Nov 1 18:21:23 UTC 2016]";
server.expectShell(DEVICE_SERIAL, "getprop").returns(response);
//Act
Map<String, String> actual = new PropertyManager(device).getprop();
//Assert
assertEquals(expected, actual);
}
@Test
public void testGetPropsMalformedIgnoredString() throws Exception {
//Arrange