mirror of https://github.com/Genymobile/scrcpy
Wrap settings management into a Settings class
Until now, the code that needed to read/write the Android settings had to explicitly open and close a ContentProvider. Wrap these details into a Settings class. This paves the way to provide an alternative implementation of settings read/write for Android >= 12. PR #2802 <https://github.com/Genymobile/scrcpy/pull/2802>settings
parent
9cb14b5166
commit
67170437f1
@ -0,0 +1,39 @@
|
||||
package com.genymobile.scrcpy;
|
||||
|
||||
import com.genymobile.scrcpy.wrappers.ContentProvider;
|
||||
import com.genymobile.scrcpy.wrappers.ServiceManager;
|
||||
|
||||
public class Settings {
|
||||
|
||||
public static final String TABLE_SYSTEM = ContentProvider.TABLE_SYSTEM;
|
||||
public static final String TABLE_SECURE = ContentProvider.TABLE_SECURE;
|
||||
public static final String TABLE_GLOBAL = ContentProvider.TABLE_GLOBAL;
|
||||
|
||||
private final ServiceManager serviceManager;
|
||||
|
||||
public Settings(ServiceManager serviceManager) {
|
||||
this.serviceManager = serviceManager;
|
||||
}
|
||||
|
||||
public String getValue(String table, String key) {
|
||||
try (ContentProvider provider = serviceManager.getActivityManager().createSettingsProvider()) {
|
||||
return provider.getValue(table, key);
|
||||
}
|
||||
}
|
||||
|
||||
public void putValue(String table, String key, String value) {
|
||||
try (ContentProvider provider = serviceManager.getActivityManager().createSettingsProvider()) {
|
||||
provider.putValue(table, key, value);
|
||||
}
|
||||
}
|
||||
|
||||
public String getAndPutValue(String table, String key, String value) {
|
||||
try (ContentProvider provider = serviceManager.getActivityManager().createSettingsProvider()) {
|
||||
String oldValue = provider.getValue(table, key);
|
||||
if (!value.equals(oldValue)) {
|
||||
provider.putValue(table, key, value);
|
||||
}
|
||||
return oldValue;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue