[ASUS ZenFone 8] bnsmb:
In the post Instructions touse the ASUS Hardware Testtool I described how to add the ASUS Hardware TestTool to a CustomROM using Magisk.

For CustomROMs that you compile yourself, the ASUS Hardware Test Tool can also be added as a prebuild app as described below.

This post only contains the commands necessary to add the ASUS Hardware TestTool as prebuild app. For details about adding a prebuild app to a self compiled Custom ROM see Howto add additional prebuild apks to a custom ROM and for detailed instructions to re-sign an apk file see How tore-sign an apk file .

In this example the CustomROM used is the OmniROM but the instructions should work for other CustomROMs also.

First copy the apks with the ASUS Hardware Testool and the ASUS calculator from the phone while the original ASUS Android OS is running on the phone:

# the directory may be different in your environment
#
cd /data/develop/android/SMMI_TEST

adb pull /system/app/SMMI_TEST/SMMI_TEST.apk

adb pull /system/priv-app/AsusCalculator/AsusCalculator.apk

Note:

The AsusCalculator is optional -- it's only required if you want to start the Hardware Tests via GUI on the phone

Now re-sign the apk file with the ASUS Hardware Testool using the certificate used to sign your self-compiled OS image:

# ----------------------------------------------------------------------------
# environment variables used in the commands below
#
APKSIGNER="/data/develop/android/android_sdk/build-tools/34.0.0/lib/apksigner.jar"

REPO_DIR="/data/develop/android/OmniROM_14.0"

DIR_WITH_KEYS="${REPO_DIR}/build/make/target/product/security/"

ZIPALIGN="/data/develop/android/otatools/bin/zipalign"

# ----------------------------------------------------------------------------
# re-sign both apks with the certificate used for your self compiled ROM
#

# ----------------------------------------------------------------------------
# re-sign the apk file for the Test app
#
zip -d SMMI_TEST.apk META-INF/CERT.SF META-INF/CERT.RSA

${ZIPALIGN} 4 SMMI_TEST.apk SMMI_TEST.apk.aligned

mv SMMI_TEST.apk.aligned SMMI_TEST.apk

# test the result of the zipalign (there should be no output from this command)
#
${ZIPALIGN} -c 4 SMMI_TEST.apk

# re-sign the apk with the certificate used for the new ROM
#
java -jar ${APKSIGNER} sign --key ${DIR_WITH_KEYS}/platform.pk8 --cert ${DIR_WITH_KEYS}/platform.x509.pem SMMI_TEST.apk

# check the result

keytool -printcert -jarfile SMMI_TEST.apk

Next re-sign the apk file with the ASUS Calculator using the certificate used to sign your self-compiled OS image:

# ----------------------------------------------------------------------------
# re-sign the apk file for the ASUS Calculator

zip -d AsusCalculator.apk META-INF/AMAX.SF META-INF/AMAX.RSA

${ZIPALIGN} 4 AsusCalculator.apk AsusCalculator.apk.aligned

mv AsusCalculator.apk.aligned AsusCalculator.apk

# test the result of the zipalign (there should be no output from this command)
#
${ZIPALIGN} -c 4 AsusCalculator.apk

# re-sign the apk with the certificate used for the new ROM
#
java -jar ${APKSIGNER} sign --key ${DIR_WITH_KEYS}/platform.pk8 --cert ${DIR_WITH_KEYS}/platform.x509.pem AsusCalculator.apk

# check the result
#
keytool -printcert -jarfile AsusCalculator.apk

Now create the config for the prebuild apps in the device tree with the source for the custom ROM:

# ----------------------------------------------------------------------------
# create the prebuild config for the ASUS Hardware Testool
#

cd ${REPO_DIR}/vendor/omni/prebuilt/app

mkdir SMMI_TEST

cd SMMI_TEST
cp /data/develop/android/SMMI_TEST/SMMI_TEST.apk SMMI_TEST.apk

cat >Android.mk <<-\EOT
LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := SMMI_TEST
LOCAL_SRC_FILES := SMMI_TEST.apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_TAGS := optional
LOCAL_CERTIFICATE := PRESIGNED
LOCAL_DEX_PREOPT := false
LOCAL_PRIVILEGED_MODULE = true
include $(BUILD_PREBUILT)
EOT

# ----------------------------------------------------------------------------
# create the prebuild config for the ASUS Calculator
#

cd ${REPO_DIR}/vendor/omni/prebuilt/app

mkdir AsusCalculator

cd AsusCalculator

cp /data/develop/android/SMMI_TEST/AsusCalculator.apk .

cat >Android.mk <<-\EOT
LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := AsusCalculator
LOCAL_SRC_FILES := AsusCalculator.apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_TAGS := optional
LOCAL_CERTIFICATE := PRESIGNED
LOCAL_DEX_PREOPT := false
LOCAL_PRIVILEGED_MODULE = true
include $(BUILD_PREBUILT)
EOT

Now add the packages to the file

${REPO_DIR}/vendor/omni/config/packages.mk

Use an editor and add these lines anywhere in the file BEFORE the last lines starting with "$("

PRODUCT_PACKAGES += \
SMMI_TEST \
AsusCalculator

Finally add the necessary SELinux policies for the ASUS Hardware Testtool:

echo "allow system_app proc_stat:file { ioctl read getattr lock map open watch watch_reads };" >${REPO_DIR}/device/asus/zenfone8/sepolicy/vendor/asus_hardware_testtool.te

Double check all files (especially the Android.mk files for leading or trailing whitespaces) and, if everything is fine, recreate the OS image using the standard commands and install the created OS image on the phone.

To start the Test App use either as user root in an adb shell:

# start the ASUS Hardware TestTool from within a shell
#
am start -n com.asus.atd.smmitest/com.asus.atd.smmitest.main.MAIN

or open the ASUS Calculator and enter

,12345+=

or (depending on your language settings)

.12345+=