@@ -255,3 +255,125 @@ def get_package_data_dir(conn: ADBConnect):
255255
256256 except sp .CalledProcessError :
257257 return None
258+
259+ @staticmethod
260+ def set_property (conn : ADBConnect , property : str , value : str ) -> bool :
261+ '''
262+ Set an Android system property to a value.
263+
264+ Args:
265+ conn: The adb connection.
266+ property: The name of the property to set.
267+ value: The desired value of the property.
268+
269+ Returns:
270+ True on success, False otherwise.
271+ '''
272+ try :
273+ conn .adb ('shell' , 'setprop' , property , value )
274+ return True
275+
276+ except sp .CalledProcessError :
277+ return False
278+
279+ @staticmethod
280+ def get_property (conn : ADBConnect , property : str ) -> Optional [str ]:
281+ '''
282+ Get an Android system property value.
283+
284+ Args:
285+ conn: The adb connection.
286+ property: The name of the property to get.
287+
288+ Returns:
289+ The value of the property on success, None otherwise. Note that
290+ deleted settings that do not exist will also return None.
291+ '''
292+ try :
293+ value = conn .adb ('shell' , 'getprop' , property )
294+ return value .strip ()
295+
296+ except sp .CalledProcessError :
297+ return None
298+
299+ @staticmethod
300+ def clear_property (conn : ADBConnect , property : str ) -> bool :
301+ '''
302+ Set an Android system property to an empty value.
303+
304+ Args:
305+ conn: The adb connection.
306+ property: The name of the property to set.
307+
308+ Returns:
309+ True on success, False otherwise.
310+ '''
311+ try :
312+ conn .adb ('shell' , 'setprop' , property , '""' )
313+ return True
314+
315+ except sp .CalledProcessError :
316+ return False
317+
318+ @staticmethod
319+ def set_setting (conn : ADBConnect , setting : str , value : str ) -> bool :
320+ '''
321+ Set an Android system setting to a value.
322+
323+ Args:
324+ conn: The adb connection.
325+ setting: The name of the setting to set.
326+ value: The desired value of the setting.
327+
328+ Returns:
329+ True on success, False otherwise.
330+ '''
331+ try :
332+ conn .adb ('shell' , 'settings' , 'put' , 'global' , setting , value )
333+ return True
334+
335+ except sp .CalledProcessError :
336+ return False
337+
338+ @staticmethod
339+ def get_setting (conn : ADBConnect , setting : str ) -> Optional [str ]:
340+ '''
341+ Get an Android system property setting.
342+
343+ Args:
344+ conn: The adb connection.
345+ setting: The name of the setting to get.
346+
347+ Returns:
348+ The value of the setting on success, None otherwise.
349+ '''
350+ try :
351+ value = conn .adb ('shell' , 'settings' , 'get' , 'global' , setting )
352+ value = value .strip ()
353+
354+ if value == 'null' :
355+ return None
356+
357+ return value
358+
359+ except sp .CalledProcessError :
360+ return None
361+
362+ @staticmethod
363+ def clear_setting (conn : ADBConnect , setting : str ) -> bool :
364+ '''
365+ Clear an Android system setting.
366+
367+ Args:
368+ conn: The adb connection.
369+ setting: The name of the setting to set.
370+
371+ Returns:
372+ True on success, False otherwise.
373+ '''
374+ try :
375+ conn .adb ('shell' , 'settings' , 'delete' , 'global' , setting )
376+ return True
377+
378+ except sp .CalledProcessError :
379+ return False
0 commit comments