Whitespace only

Before

1package com.genymobile.scrcpy;
2
3import com.genymobile.scrcpy.wrappers.ContentProvider;
4import com.genymobile.scrcpy.wrappers.ServiceManager;
5
6import android.os.Build;
7
8import java.io.IOException;
9
10public final class Settings {
11
12 public static final String TABLE_SYSTEM = ContentProvider.TABLE_SYSTEM;
13 public static final String TABLE_SECURE = ContentProvider.TABLE_SECURE;
14 public static final String TABLE_GLOBAL = ContentProvider.TABLE_GLOBAL;
15
16 private Settings() {
17 /* not instantiable */
18 }
19
20 private static void execSettingsPut(String table, String key, String value) throws SettingsException {
21 try {
22 Command.exec("settings", "put", table, key, value);
23 } catch (IOException | InterruptedException e) {
24 throw new SettingsException("put", table, key, value, e);
25 }
26 }
27
28 private static String execSettingsGet(String table, String key) throws SettingsException {
29 try {
30 return Command.execReadLine("settings", "get", table, key);
31 } catch (IOException | InterruptedException e) {
32 throw new SettingsException("get", table, key, null, e);
33 }
34 }
35
36 public static String getValue(String table, String key) throws SettingsException {
37 if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.R) {
38 // on Android >= 12, it always fails: <https://github.com/Genymobile/scrcpy/issues/2788>
39 try (ContentProvider provider = ServiceManager.getActivityManager().createSettingsProvider()) {
40 return provider.getValue(table, key);
41 } catch (SettingsException e) {
42 Ln.w("Could not get settings value via ContentProvider, fallback to settings process", e);
43 }
44 }
45
46 return execSettingsGet(table, key);
47 }
48
49 public static void putValue(String table, String key, String value) throws SettingsException {
50 if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.R) {
51 // on Android >= 12, it always fails: <https://github.com/Genymobile/scrcpy/issues/2788>
52 try (ContentProvider provider = ServiceManager.getActivityManager().createSettingsProvider()) {
53 provider.putValue(table, key, value);
54 } catch (SettingsException e) {
55 Ln.w("Could not put settings value via ContentProvider, fallback to settings process", e);
56 }
57 }
58
59 execSettingsPut(table, key, value);
60 }
61
62 public static String getAndPutValue(String table, String key, String value) throws SettingsException {
63 if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.R) {
64 // on Android >= 12, it always fails: <https://github.com/Genymobile/scrcpy/issues/2788>
65 try (ContentProvider provider = ServiceManager.getActivityManager().createSettingsProvider()) {
66 String oldValue = provider.getValue(table, key);
67 if (!value.equals(oldValue)) {
68 provider.putValue(table, key, value);
69 }
70 return oldValue;
71 } catch (SettingsException e) {
72 Ln.w("Could not get and put settings value via ContentProvider, fallback to settings process", e);
73 }
74 }
75
76 String oldValue = getValue(table, key);
77 if (!value.equals(oldValue)) {
78 putValue(table, key, value);
79 }
80 return oldValue;
81 }
82}
83

After

1package com.genymobile.scrcpy;
2
3import com.genymobile.scrcpy.wrappers.ContentProvider;
4import com.genymobile.scrcpy.wrappers.ServiceManager;
5
6import android.os.Build;
7
8import java.io.IOException;
9
10public final class Settings {
11
12 public static final String TABLE_SYSTEM = ContentProvider.TABLE_SYSTEM;
13 public static final String TABLE_SECURE = ContentProvider.TABLE_SECURE;
14 public static final String TABLE_GLOBAL = ContentProvider.TABLE_GLOBAL;
15
16 private Settings() {
17 /* not instantiable */
18 }
19
20 private static void execSettingsPut(String table, String key, String value) throws SettingsException {
21 try {
22 Command.exec("settings", "put", table, key, value);
23 } catch (IOException | InterruptedException e) {
24 throw new SettingsException("put", table, key, value, e);
25 }
26 }
27
28 private static String execSettingsGet(String table, String key) throws SettingsException {
29 try {
30 return Command.execReadLine("settings", "get", table, key);
31 } catch (IOException | InterruptedException e) {
32 throw new SettingsException("get", table, key, null, e);
33 }
34 }
35
36 public static String getValue(String table, String key) throws SettingsException {
37 if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.R) {
38 // on Android >= 12, it always fails: <https://github.com/Genymobile/scrcpy/issues/2788>
39 try (ContentProvider provider = ServiceManager.getActivityManager().createSettingsProvider()) {
40 return provider.getValue(table, key);
41 } catch (SettingsException e) {
42 Ln.w("Could not get settings value via ContentProvider, fallback to settings process", e);
43 }
44 }
45
46 return execSettingsGet(table, key);
47 }
48
49 public static void putValue(String table, String key, String value) throws SettingsException {
50 if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.R) {
51 // on Android >= 12, it always fails: <https://github.com/Genymobile/scrcpy/issues/2788>
52 try (ContentProvider provider = ServiceManager.getActivityManager().createSettingsProvider()) {
53 provider.putValue(table, key, value);
54 } catch (SettingsException e) {
55 Ln.w("Could not put settings value via ContentProvider, fallback to settings process", e);
56 }
57 }
58
59 execSettingsPut(table, key, value);
60 }
61
62 public static String getAndPutValue(String table, String key, String value) throws SettingsException {
63 if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.R) {
64 // on Android >= 12, it always fails: <https://github.com/Genymobile/scrcpy/issues/2788>
65 try (ContentProvider provider = ServiceManager.getActivityManager().createSettingsProvider()) {
66 String oldValue = provider.getValue(table, key);
67 if (!value.equals(oldValue)) {
68 provider.putValue(table, key, value);
69 }
70 return oldValue;
71 } catch (SettingsException e) {
72 Ln.w("Could not get and put settings value via ContentProvider, fallback to settings process", e);
73 }
74 }
75
76 String oldValue = getValue(table, key);
77 if (!value.equals(oldValue)) {
78 putValue(table, key, value);
79 }
80 return oldValue;
81 }
82}
83

Before

program
package_declaration
package "package"
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "genymobile"
. "."
identifier "scrcpy"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "genymobile"
. "."
identifier "scrcpy"
. "."
identifier "wrappers"
. "."
identifier "ContentProvider"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "genymobile"
. "."
identifier "scrcpy"
. "."
identifier "wrappers"
. "."
identifier "ServiceManager"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "android"
. "."
identifier "os"
. "."
identifier "Build"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "io"
. "."
identifier "IOException"
; ";"
class_declaration (+687 nodes collapsed)

After

program
package_declaration
package "package"
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "genymobile"
. "."
identifier "scrcpy"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "genymobile"
. "."
identifier "scrcpy"
. "."
identifier "wrappers"
. "."
identifier "ContentProvider"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "genymobile"
. "."
identifier "scrcpy"
. "."
identifier "wrappers"
. "."
identifier "ServiceManager"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "android"
. "."
identifier "os"
. "."
identifier "Build"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "io"
. "."
identifier "IOException"
; ";"
class_declaration (+687 nodes collapsed)