[Treble-Enabled Device Guides, News, & Discussion] minadzuki:
Hello, when you using phh's GSIs, you may found bugs on auto brightness, battery usage data, etc (e.g: Xiaomi, Huawei, etc.). For this, you can make an overlay files for your mobiles.

Requirements:

framework-res.apk on your stock rom. (It may on /system/framework/framework-res.apk)

apktool (to extract framework-res.apk)

git (to clone repo)

Linux (to build overlay files)

Steps:

1. Fork phhusson/vendor_hardware_overlay on GitHub.

2. Clone Repository which you forked, and make a new branch for your works.

3. Copy a device which similar for your device, and rename it to your own device.

4. Edit <Your device>/Android.mk (Just modify the contents of the brackets, same as below)

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_PACKAGE_NAME := treble-overlay-[Manufacturer of your device]-[Name of your device]
LOCAL_MODULE_PATH := $(TARGET_OUT)/overlay
LOCAL_IS_RUNTIME_RESOURCE_OVERLAY := true
LOCAL_PRIVATE_PLATFORM_APIS := true
include $(BUILD_PACKAGE)

5. Edit <Your device>/AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="me.phh.treble.overlay.[Manufacturer of your device].[Name of your device]"
android:versionCode="1"
android:versionName="1.0">
<overlay android:targetPackage="android"
android:requiredSystemPropertyName="ro.vendor.build.fingerprint"
android:requiredSystemPropertyValue="+[write as similar format]*"
android:priority="[Take next number of last used]"
android:isStatic="true" />
</manifest>

If you don't know how to take android:priority, you can execute this commands to list priority which used already:

cd [Path of repository]
find -name AndroidManifest.xml |while read manifest;do packagename="$(xmlstarlet sel -t -m '//manifest' -v @package -n $manifest)";priority="$(xmlstarlet sel -t -m '//overlay' -v @android:priority -n $manifest)";echo -e "$priority\t$packagename";done|more

(the single line command split here, just for viewing or making a shell script):

find -name AndroidManifest.xml |while read manifest;do
packagename="$(xmlstarlet sel -t -m '//manifest' -v @package -n $manifest)";
priority="$(xmlstarlet sel -t -m '//overlay' -v @android:priority -n $manifest)";
echo -e "$priority\t$packagename";
done

It will print a list for you (unsorted), and you just take an unused priority.

You can find device fingerprint on /vendor/build.prop, or execute following commands (on your device or adb shell):

getprop ro.vendor.build.fingerprint

If you can't find ro.vendor.build.fingerprint, you can find ro.vendor.product.name or ro.product.vendor.device, then change android:requiredSystemPropertyName and android:requiredSystemPropertyValue what you found.

Huawei seems to use ro.hw.oemName to detect phone, and others manufacturer maybe have their own detection, too. But it should be unique for other phones with same manufacturer.

(It's NOT recommended unless your device don't have ro.vendor.build.fingerprint.)

6. Extract framework-res.apk with apktool on another side. (to avoid commited by mistake)

7. Replace <Your device>/res/xml/power_profile.xml to which power_profile.xml for your device.

It will on <Extracted framework-res.apk>/res/xml/power_profile.xml.

Or you can find whoever's device tree, it may have this file, too.

8. Edit <Your device>/res/values/config.xml

Find each key on following files what for your device:

[Extracted framework-res.apk]/res/values/arrays.xml
[Extracted framework-res.apk]/res/values/bools.xml
[Extracted framework-res.apk]/res/values/fractions.xml
[Extracted framework-res.apk]/res/values/integers.xml

And then replace values into <Your device>/res/values/config.xml

9. Add your device into <Path of repository>/overlay.mk

Just write like other lines.

10. Build overlays

Just execute following commands:

chmod u+x [Path of repository]/build/build.sh
[Path of repository]/build/build.sh

If You get this, Do what it said:

Please install aapt (apt install aapt should do)

Or if you get this:

OpenJDK Server VM warning: You have loaded library /root/overlay/vendor_hardware_overlay/build/signapk/libconscrypt_openjdk_jni.so which might have disabled stack guard. The VM will try to fix the stack guard now.
It's highly recommended that you fix the library with 'execstack -c <libfile>', or link it with '-z noexecstack'.
Exception in thread "main" java.lang.UnsatisfiedLinkError: org.conscrypt.NativeCrypto.get_cipher_names(Ljava/lang/String;)[Ljava/lang/String;
at org.conscrypt.NativeCrypto.get_cipher_names(Native Method)
at org.conscrypt.NativeCrypto.<clinit>(NativeCrypto.java:764)
at org.conscrypt.OpenSSLProvider.<init>(OpenSSLProvider.java:56)
at org.conscrypt.OpenSSLProvider.<init>(OpenSSLProvider.java:49)
at com.android.signapk.SignApk.main(SignApk.java:942)

I have no solution, either. Try to build on another computer.

11. Test overlay with tests.sh and yourself

For general checks (symtax, etc.), just execute following command:

chmod u+x [Path of repository]/tests/tests.sh
[Path of repository]/tests/tests.sh

You should fix errors what reported for your device, and then restart from step 10.

If it reported errors but not for your device, just ignore it.

When check passed, you can find overlay file on <Path of repository>/build/treble-overlay-<Manufacturer of your device>-<Name of your device>.apk, just copy it into your phone's /system/overlay/, and set permission to rw-r--r-- / 0644.

And then reboot your phone to test your overlay.

12. If it works for your device, don't forget to perform a pull request for phhusson/vendor_hardware_overlay, to support his awesome works.