mirror of
				https://github.com/ARM-software/devlib.git
				synced 2025-11-04 07:51:21 +00:00 
			
		
		
		
	AdbConnection: Enable adb_as_root as a connection parameter
				
					
				
			To allow for connecting to an `AndroidTarget` as root before the target has been initialised, allow for passing `adb_as_root` as a connection parameter to the `AdbConnection`. This will restart `adbd` as root before attempting to connect to the target and will restart as unrooted once all connections to that target have been closed.
This commit is contained in:
		@@ -260,12 +260,16 @@ class AdbConnection(object):
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    # pylint: disable=unused-argument
 | 
			
		||||
    def __init__(self, device=None, timeout=None, platform=None, adb_server=None):
 | 
			
		||||
    def __init__(self, device=None, timeout=None, platform=None, adb_server=None,
 | 
			
		||||
                 adb_as_root=False):
 | 
			
		||||
        self.timeout = timeout if timeout is not None else self.default_timeout
 | 
			
		||||
        if device is None:
 | 
			
		||||
            device = adb_get_device(timeout=timeout, adb_server=adb_server)
 | 
			
		||||
        self.device = device
 | 
			
		||||
        self.adb_server = adb_server
 | 
			
		||||
        self.adb_as_root = adb_as_root
 | 
			
		||||
        if self.adb_as_root:
 | 
			
		||||
            self.adb_root(enable=True)
 | 
			
		||||
        adb_connect(self.device)
 | 
			
		||||
        AdbConnection.active_connections[self.device] += 1
 | 
			
		||||
        self._setup_ls()
 | 
			
		||||
@@ -312,6 +316,8 @@ class AdbConnection(object):
 | 
			
		||||
    def close(self):
 | 
			
		||||
        AdbConnection.active_connections[self.device] -= 1
 | 
			
		||||
        if AdbConnection.active_connections[self.device] <= 0:
 | 
			
		||||
            if self.adb_as_root:
 | 
			
		||||
                adb_root(self.device, enable=False)
 | 
			
		||||
            adb_disconnect(self.device)
 | 
			
		||||
            del AdbConnection.active_connections[self.device]
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user