Fix AndroidDevice.get_prop, add tests.

Had messed this up while refactoring before I submitted and neglected
to add a test. Thanks to mazda@ for catching this.

Also disabled the root/unroot tests for user builds.

Change-Id: Icb819a820a2afa227d548d678ae471d5195f0b96
diff --git a/adb/device.py b/adb/device.py
index 601989b..57f17fc 100644
--- a/adb/device.py
+++ b/adb/device.py
@@ -60,6 +60,7 @@
         raise NoUniqueDeviceError()
     return AndroidDevice(devices[0], product)
 
+
 def _get_device_by_serial(serial, product=None):
     for device in get_devices():
         if device == serial:
@@ -220,7 +221,7 @@
         return self._simple_call(['wait-for-device'])
 
     def get_prop(self, prop_name):
-        output = self.shell(['getprop', prop_name])
+        output = self.shell(['getprop', prop_name]).splitlines()
         if len(output) != 1:
             raise RuntimeError('Too many lines in getprop output:\n' +
                                '\n'.join(output))
diff --git a/adb/test_device.py b/adb/test_device.py
index 6c20b6e..8003eaa 100644
--- a/adb/test_device.py
+++ b/adb/test_device.py
@@ -32,6 +32,26 @@
 import adb
 
 
+def requires_root(func):
+    def wrapper(self, *args):
+        if self.device.get_prop('ro.debuggable') != '1':
+            raise unittest.SkipTest('requires rootable build')
+
+        was_root = self.device.shell(['id', '-un']).strip() == 'root'
+        if not was_root:
+            self.device.root()
+            self.device.wait()
+
+        try:
+            func(self, *args)
+        finally:
+            if not was_root:
+                self.device.unroot()
+                self.device.wait()
+
+    return wrapper
+
+
 class GetDeviceTest(unittest.TestCase):
     def setUp(self):
         self.android_serial = os.getenv('ANDROID_SERIAL')
@@ -188,6 +208,9 @@
 
     def test_root_unroot(self):
         """Make sure that adb root and adb unroot work, using id(1)."""
+        if self.device.get_prop('ro.debuggable') != '1':
+            raise unittest.SkipTest('requires rootable build')
+
         original_user = self.device.shell(['id', '-un']).strip()
         try:
             if original_user == 'root':
@@ -216,6 +239,20 @@
             subprocess.CalledProcessError, self.device.tcpip, 'foo')
 
 
+class SystemPropertiesTest(DeviceTest):
+    def test_get_prop(self):
+        self.assertEqual(self.device.get_prop('init.svc.adbd'), 'running')
+
+    @requires_root
+    def test_set_prop(self):
+        prop_name = 'foo.bar'
+        self.device.shell(['setprop', prop_name, '""'])
+
+        self.device.set_prop(prop_name, 'qux')
+        self.assertEqual(
+            self.device.shell(['getprop', prop_name]).strip(), 'qux')
+
+
 def compute_md5(string):
     hsh = hashlib.md5()
     hsh.update(string)
@@ -393,7 +430,6 @@
             self.device.shell(['rm', '-rf', self.DEVICE_TEMP_DIR])
             shutil.rmtree(base_dir + self.DEVICE_TEMP_DIR)
 
-
     def test_unicode_paths(self):
         """Ensure that we can support non-ASCII paths, even on Windows."""
         name = u'로보카 폴리'.encode('utf-8')