1*8975f5c5SAndroid Build Coastguard Worker# ANGLE Settings UI 2*8975f5c5SAndroid Build Coastguard Worker 3*8975f5c5SAndroid Build Coastguard Worker## Introduction 4*8975f5c5SAndroid Build Coastguard Worker 5*8975f5c5SAndroid Build Coastguard WorkerANGLE Settings UI is a UI shipped as part of the ANGLE apk. The ANGLE apk can ship with a list rules 6*8975f5c5SAndroid Build Coastguard Workerof applications using different OpenGL ES driver. The UI provides two functionalities: 7*8975f5c5SAndroid Build Coastguard Worker 8*8975f5c5SAndroid Build Coastguard Worker1) Enable to show a message when ANGLE is loaded into the launched application; 9*8975f5c5SAndroid Build Coastguard Worker2) Allow to select driver choice in the UI for applications. 10*8975f5c5SAndroid Build Coastguard Worker 11*8975f5c5SAndroid Build Coastguard Worker## The rule file 12*8975f5c5SAndroid Build Coastguard Worker 13*8975f5c5SAndroid Build Coastguard WorkerCurrently the ANGLE apk supports two rules: ANGLE and native OpenGL ES driver. 14*8975f5c5SAndroid Build Coastguard Worker 15*8975f5c5SAndroid Build Coastguard WorkerThe rule file is a file that contains a JSON string, the format is shown below: 16*8975f5c5SAndroid Build Coastguard Worker 17*8975f5c5SAndroid Build Coastguard Worker``` 18*8975f5c5SAndroid Build Coastguard Worker{ 19*8975f5c5SAndroid Build Coastguard Worker "rules":[ 20*8975f5c5SAndroid Build Coastguard Worker { 21*8975f5c5SAndroid Build Coastguard Worker "description": "Applications in this list will use ANGLE", 22*8975f5c5SAndroid Build Coastguard Worker "choice": "angle", 23*8975f5c5SAndroid Build Coastguard Worker "apps": [ 24*8975f5c5SAndroid Build Coastguard Worker { 25*8975f5c5SAndroid Build Coastguard Worker "packageName": "com.android.example.a" 26*8975f5c5SAndroid Build Coastguard Worker }, 27*8975f5c5SAndroid Build Coastguard Worker { 28*8975f5c5SAndroid Build Coastguard Worker "packageName": "com.android.example.b" 29*8975f5c5SAndroid Build Coastguard Worker } 30*8975f5c5SAndroid Build Coastguard Worker ] 31*8975f5c5SAndroid Build Coastguard Worker }, 32*8975f5c5SAndroid Build Coastguard Worker { 33*8975f5c5SAndroid Build Coastguard Worker "description": "Applications in this list will not use ANGLE", 34*8975f5c5SAndroid Build Coastguard Worker "choice": "native", 35*8975f5c5SAndroid Build Coastguard Worker "apps":[ 36*8975f5c5SAndroid Build Coastguard Worker { 37*8975f5c5SAndroid Build Coastguard Worker "packageName": "com.android.example.c" 38*8975f5c5SAndroid Build Coastguard Worker } 39*8975f5c5SAndroid Build Coastguard Worker ] 40*8975f5c5SAndroid Build Coastguard Worker } 41*8975f5c5SAndroid Build Coastguard Worker ] 42*8975f5c5SAndroid Build Coastguard Worker} 43*8975f5c5SAndroid Build Coastguard Worker``` 44*8975f5c5SAndroid Build Coastguard Worker 45*8975f5c5SAndroid Build Coastguard WorkerThe ANGLE JSON rules are parsed only when `ACTION_BOOT_COMPLETED` or `ACTION_MY_PACKAGE_REPLACED` is 46*8975f5c5SAndroid Build Coastguard Workerreceived. After the JSON rules are parsed, the result will be stored in `SharedPreferences` as 47*8975f5c5SAndroid Build Coastguard Workerkey-value pair, with the key being the package name and the value being the driver selection choice. 48*8975f5c5SAndroid Build Coastguard WorkerThe JSON parsing code is in `AngleRuleHelper`. 49*8975f5c5SAndroid Build Coastguard Worker 50*8975f5c5SAndroid Build Coastguard WorkerAfter parsing, the rules are converted to global settings variables and applied to the system. This 51*8975f5c5SAndroid Build Coastguard Workeris done in `Receiver`. 52*8975f5c5SAndroid Build Coastguard Worker 53*8975f5c5SAndroid Build Coastguard WorkerThe UI logic is mainly in `MainFragment`, and the `GlobalSettings` is merely for manipulating 54*8975f5c5SAndroid Build Coastguard Workersettings global variables and updating `SharedPreferences`. When a user changes the driver choice 55*8975f5c5SAndroid Build Coastguard Workerof an application, the update will go into `GlobalSettings` and `SharedPreferences` respectively. 56*8975f5c5SAndroid Build Coastguard Worker 57*8975f5c5SAndroid Build Coastguard WorkerThe `SharedPreferences` is the source of truth and the code should always query the driver choice 58*8975f5c5SAndroid Build Coastguard Workerfrom it with the package name. The `SharedPreferences` should only be updated within 59*8975f5c5SAndroid Build Coastguard Worker`GlobalSettings` and `AngleRuleHelper`. 60*8975f5c5SAndroid Build Coastguard Worker 61*8975f5c5SAndroid Build Coastguard WorkerThe settings global variables may also be changed via `adb` command by the users, often time ANGLE 62*8975f5c5SAndroid Build Coastguard Workerfor Android developers. Note that every time a boot event happens, it is expected that all previous 63*8975f5c5SAndroid Build Coastguard Workervalues in settings global variables will be cleared and only values from the ANGLE JSON rule file 64*8975f5c5SAndroid Build Coastguard Workerwill take effect. 65*8975f5c5SAndroid Build Coastguard Worker 66*8975f5c5SAndroid Build Coastguard Worker## Developer options 67*8975f5c5SAndroid Build Coastguard Worker 68*8975f5c5SAndroid Build Coastguard WorkerThe ANGLE Settings UI is registered as a dynamic setting entry in the development component via 69*8975f5c5SAndroid Build Coastguard Worker 70*8975f5c5SAndroid Build Coastguard Worker``` 71*8975f5c5SAndroid Build Coastguard Worker<intent-filter> 72*8975f5c5SAndroid Build Coastguard Worker <action android:name="com.android.settings.action.IA_SETTINGS" /> 73*8975f5c5SAndroid Build Coastguard Worker</intent-filter> 74*8975f5c5SAndroid Build Coastguard Worker<meta-data android:name="com.android.settings.category" 75*8975f5c5SAndroid Build Coastguard Worker android:value="com.android.settings.category.ia.development" /> 76*8975f5c5SAndroid Build Coastguard Worker``` 77*8975f5c5SAndroid Build Coastguard Worker 78*8975f5c5SAndroid Build Coastguard WorkerAnd hence the UI shows up in Developer options. If the Developer options are disabled, all settings 79*8975f5c5SAndroid Build Coastguard Workerglobal variables will be cleared. 80