mirror of
https://github.com/revanced/jadb.git
synced 2025-05-08 10:24:30 +02:00
Merge pull request #51 from nuumio/PropertyManager
Property manager improvements
This commit is contained in:
commit
2d89d91db1
@ -15,6 +15,7 @@ import java.util.regex.Pattern;
|
|||||||
* A class which works with properties, uses getprop and setprop methods of android shell
|
* A class which works with properties, uses getprop and setprop methods of android shell
|
||||||
*/
|
*/
|
||||||
public class PropertyManager {
|
public class PropertyManager {
|
||||||
|
private final Pattern pattern = Pattern.compile("^\\[([a-zA-Z0-9_.-]*)\\]:.\\[([^\\[\\]]*)\\]");
|
||||||
private final JadbDevice device;
|
private final JadbDevice device;
|
||||||
|
|
||||||
public PropertyManager(JadbDevice device) {
|
public PropertyManager(JadbDevice device) {
|
||||||
@ -22,13 +23,13 @@ public class PropertyManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, String> getprop() throws IOException, JadbException {
|
public Map<String, String> getprop() throws IOException, JadbException {
|
||||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(device.executeShell("getprop")));
|
try (BufferedReader bufferedReader =
|
||||||
return parseProp(bufferedReader);
|
new BufferedReader(new InputStreamReader(device.executeShell("getprop")))) {
|
||||||
|
return parseProp(bufferedReader);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, String> parseProp(BufferedReader bufferedReader) throws IOException {
|
private Map<String, String> parseProp(BufferedReader bufferedReader) throws IOException {
|
||||||
final Pattern pattern = Pattern.compile("^\\[([a-zA-Z0-9_.-]*)\\]:.\\[([a-zA-Z0-9_.-]*)\\]");
|
|
||||||
|
|
||||||
HashMap<String, String> result = new HashMap<>();
|
HashMap<String, String> result = new HashMap<>();
|
||||||
|
|
||||||
String line;
|
String line;
|
||||||
|
@ -55,6 +55,38 @@ public class PropertyManagerTest {
|
|||||||
assertEquals(expected, actual);
|
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
|
@Test
|
||||||
public void testGetPropsMalformedIgnoredString() throws Exception {
|
public void testGetPropsMalformedIgnoredString() throws Exception {
|
||||||
//Arrange
|
//Arrange
|
||||||
|
Loading…
x
Reference in New Issue
Block a user