Hash :
a06f5f89
Author :
Date :
2024-01-10T21:50:42
Android: Apply rules to global settings on boot When we receive BOOT_COMPLETE or MY_PACKAGE_REPLACED broadcasts, parse the rules and apply them to global settings. Bug: b/293503000 Test: Manually built and installed on Android Change-Id: If081f707f5acf0f22d10837177823bac59c3d4df Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5191963 Reviewed-by: Peiyong Lin <lpy@google.com> Auto-Submit: Cody Northrop <cnorthrop@google.com> Commit-Queue: Cody Northrop <cnorthrop@google.com>
ANGLE Settings UI is a UI shipped as part of the ANGLE apk. The ANGLE apk can ship with a list rules of applications using different OpenGL ES driver. The UI provides two functionalities:
Currently the ANGLE apk supports two rules: ANGLE and native OpenGL ES driver.
The rule file is a file that contains a JSON string, the format is shown below:
{
"rules":[
{
"description": "Applications in this list will use ANGLE",
"choice": "angle",
"apps": [
{
"packageName": "com.android.example.a"
},
{
"packageName": "com.android.example.b"
}
]
},
{
"description": "Applications in this list will not use ANGLE",
"choice": "native",
"apps":[
{
"packageName": "com.android.example.c"
}
]
}
]
}
The ANGLE JSON rules are parsed only when ACTION_BOOT_COMPLETED or ACTION_MY_PACKAGE_REPLACED is
received. After the JSON rules are parsed, the result will be stored in SharedPreferences as
key-value pair, with the key being the package name and the value being the driver selection choice.
The JSON parsing code is in AngleRuleHelper.
After parsing, the rules are converted to global settings variables and applied to the system. This
is done in Receiver.
The UI logic is mainly in MainFragment, and the GlobalSettings is merely for manipulating
settings global variables and updating SharedPreferences. When a user changes the driver choice
of an application, the update will go into GlobalSettings and SharedPreferences respectively.
The SharedPreferences is the source of truth and the code should always query the driver choice
from it with the package name. The SharedPreferences should only be updated within
GlobalSettings and AngleRuleHelper.
The settings global variables may also be changed via adb command by the users, often time ANGLE
for Android developers. Note that every time a boot event happens, it is expected that all previous
values in settings global variables will be cleared and only values from the ANGLE JSON rule file
will take effect.
The ANGLE Settings UI is registered as a dynamic setting entry in the development component via
<intent-filter>
<action android:name="com.android.settings.action.IA_SETTINGS" />
</intent-filter>
<meta-data android:name="com.android.settings.category"
android:value="com.android.settings.category.ia.development" />
And hence the UI shows up in Developer options. If the Developer options are disabled, all settings global variables will be cleared.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
# ANGLE Settings UI
## Introduction
ANGLE Settings UI is a UI shipped as part of the ANGLE apk. The ANGLE apk can ship with a list rules
of applications using different OpenGL ES driver. The UI provides two functionalities:
1) Enable to show a message when ANGLE is loaded into the launched application;
2) Allow to select driver choice in the UI for applications.
## The rule file
Currently the ANGLE apk supports two rules: ANGLE and native OpenGL ES driver.
The rule file is a file that contains a JSON string, the format is shown below:
```
{
"rules":[
{
"description": "Applications in this list will use ANGLE",
"choice": "angle",
"apps": [
{
"packageName": "com.android.example.a"
},
{
"packageName": "com.android.example.b"
}
]
},
{
"description": "Applications in this list will not use ANGLE",
"choice": "native",
"apps":[
{
"packageName": "com.android.example.c"
}
]
}
]
}
```
The ANGLE JSON rules are parsed only when `ACTION_BOOT_COMPLETED` or `ACTION_MY_PACKAGE_REPLACED` is
received. After the JSON rules are parsed, the result will be stored in `SharedPreferences` as
key-value pair, with the key being the package name and the value being the driver selection choice.
The JSON parsing code is in `AngleRuleHelper`.
After parsing, the rules are converted to global settings variables and applied to the system. This
is done in `Receiver`.
The UI logic is mainly in `MainFragment`, and the `GlobalSettings` is merely for manipulating
settings global variables and updating `SharedPreferences`. When a user changes the driver choice
of an application, the update will go into `GlobalSettings` and `SharedPreferences` respectively.
The `SharedPreferences` is the source of truth and the code should always query the driver choice
from it with the package name. The `SharedPreferences` should only be updated within
`GlobalSettings` and `AngleRuleHelper`.
The settings global variables may also be changed via `adb` command by the users, often time ANGLE
for Android developers. Note that every time a boot event happens, it is expected that all previous
values in settings global variables will be cleared and only values from the ANGLE JSON rule file
will take effect.
## Developer options
The ANGLE Settings UI is registered as a dynamic setting entry in the development component via
```
<intent-filter>
<action android:name="com.android.settings.action.IA_SETTINGS" />
</intent-filter>
<meta-data android:name="com.android.settings.category"
android:value="com.android.settings.category.ia.development" />
```
And hence the UI shows up in Developer options. If the Developer options are disabled, all settings
global variables will be cleared.