Skip to content

Modify Framework and Services #1713

Modify Framework and Services

Modify Framework and Services #1713

Workflow file for this run

name: Modify Framework and Services
on:
workflow_dispatch:
inputs:
jar_urls:
description: 'JSON object containing URLs to download the JAR files'
required: true
default: '{"framework_jar_url": "", "services_jar_url": "", "miui_services_jar_url": "", "miui_framework_jar_url": ""}'
android_api_level:
description: 'Android API level'
required: true
default: '34'
features:
description: 'JSON object containing feature flags'
required: true
default: '{"isCN": "true", "defaultcore": "true", "core": "false", "fixNotification": "true", "addGboard": "false", "disableFlagSecure": "true", "multiFloatingWindow": "true"}'
custom_device_name:
description: 'Device Name'
required: true
custom_version:
description: 'Version'
required: true
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
actions: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
- name: Install dependencies
run: |
sudo apt install -y default-jdk zipalign p7zip-full python3 aria2 jq
pip install gdown
- name: Write inputs to files
run: |
echo '${{ github.event.inputs.jar_urls }}' > jar_urls.json
echo '${{ github.event.inputs.features }}' > features.json
- name: Parse JSON inputs & Set environment variables
run: |
framework_jar_url=$(jq -r .framework_jar_url jar_urls.json)
services_jar_url=$(jq -r .services_jar_url jar_urls.json)
miui_services_jar_url=$(jq -r .miui_services_jar_url jar_urls.json)
miui_framework_jar_url=$(jq -r .miui_framework_jar_url jar_urls.json)
android_api_level=${{ github.event.inputs.android_api_level }}
isCN=$(jq -r .isCN features.json)
defaultcore=$(jq -r .defaultcore features.json)
core=$(jq -r .core features.json)
fixNotification=$(jq -r .fixNotification features.json)
addGboard=$(jq -r .addGboard features.json)
disableFlagSecure=$(jq -r .disableFlagSecure features.json)
multiFloatingWindow=$(jq -r .multiFloatingWindow features.json)
if [ $android_api_level -gt 34 ]; then
isa15=true
else
isa15=false
fi
# Export variables for use in subsequent steps
echo "framework_jar_url=$framework_jar_url" >> $GITHUB_ENV
echo "services_jar_url=$services_jar_url" >> $GITHUB_ENV
echo "miui_services_jar_url=$miui_services_jar_url" >> $GITHUB_ENV
echo "miui_framework_jar_url=$miui_framework_jar_url" >> $GITHUB_ENV
echo "isCN=$isCN" >> $GITHUB_ENV
echo "defaultcore=$defaultcore" >> $GITHUB_ENV
echo "core=$core" >> $GITHUB_ENV
echo "fixNotification=$fixNotification" >> $GITHUB_ENV
echo "addGboard=$addGboard" >> $GITHUB_ENV
echo "disableFlagSecure=$disableFlagSecure" >> $GITHUB_ENV
echo "multiFloatingWindow=$multiFloatingWindow" >> $GITHUB_ENV
echo "isa15=$isa15" >> $GITHUB_ENV
- name: Download and validate JARs
run: |
download_file() {
url=$1
output=$2
if echo "$url" | grep -q "drive.google.com"; then
gdown --fuzzy -O "$output" "$url"
else
curl -L -C - -o "$output" "$url"
fi
}
download_file "${{ env.framework_jar_url }}" framework.jar
download_file "${{ env.services_jar_url }}" services.jar
download_file "${{ env.miui_services_jar_url }}" miui-services.jar
download_file "${{ env.miui_framework_jar_url }}" miui-framework.jar
for jar in framework.jar services.jar miui-services.jar miui-framework.jar; do
file_size=$(stat -c%s "$jar")
if [ $file_size -lt 1500000 ]; then
echo "Error: $jar is too small. Download might have failed." >&2
exit 1
fi
done
- name: Extract framework.jar
run: 7z x framework.jar -oframework
- name: Extract services.jar
run: 7z x services.jar -oservices
- name: Extract miui-services.jar
run: 7z x miui-services.jar -omiui_services
- name: Extract miui-framework.jar
run: 7z x miui-framework.jar -omiui_framework
- name: Decompile framework dex files if available
run: |
if [ -f framework/classes.dex ]; then
java -jar baksmali.jar d -a ${{ github.event.inputs.android_api_level }} framework/classes.dex -o classes
else
echo "framework/classes.dex not found, skipping decompilation."
fi
for i in {2..5}; do
if [ -f "framework/classes${i}.dex" ]; then
java -jar baksmali.jar d -a ${{ github.event.inputs.android_api_level }} "framework/classes${i}.dex" -o "classes${i}"
else
echo "framework/classes${i}.dex not found, skipping decompile."
fi
done
- name: Decompile services dex files if available
run: |
if [ -f services/classes.dex ]; then
java -jar baksmali.jar d -a ${{ github.event.inputs.android_api_level }} services/classes.dex -o services_classes
else
echo "services/classes.dex not found, skipping decompilation."
fi
for i in {2..5}; do
if [ -f "services/classes${i}.dex" ]; then
java -jar baksmali.jar d -a ${{ github.event.inputs.android_api_level }} "services/classes${i}.dex" -o "services_classes${i}"
else
echo "services/classes${i}.dex not found, skipping decompile."
fi
done
- name: Decompile miui-services dex file
run: |
java -jar baksmali.jar d -a ${{ github.event.inputs.android_api_level }} miui_services/classes.dex -o miui_services_classes
- name: Decompile miui-framework dex file
run: |
java -jar baksmali.jar d -a ${{ github.event.inputs.android_api_level }} miui_framework/classes.dex -o miui_framework_classes
- name: Backup smali files
run: |
cp -r classes classes_backup || echo "classes directory not found, skipping backup."
cp -r classes2 classes2_backup || echo "classes2 directory not found, skipping backup."
cp -r classes3 classes3_backup || echo "classes3 directory not found, skipping backup."
cp -r classes4 classes4_backup || echo "classes4 directory not found, skipping backup."
cp -r classes5 classes5_backup || echo "classes5 directory not found, skipping backup."
cp -r services_classes services_classes_backup || echo "services_classes directory not found, skipping backup."
cp -r services_classes2 services_classes2_backup || echo "services_classes2 directory not found, skipping backup."
cp -r services_classes3 services_classes3_backup || echo "services_classes3 directory not found, skipping backup."
cp -r services_classes4 services_classes4_backup || echo "services_classes4 directory not found, skipping backup."
cp -r services_classes5 services_classes5_backup || echo "services_classes5 directory not found, skipping backup."
cp -r miui_services_classes miui_services_classes_backup
cp -r miui_framework_classes miui_framework_classes_backup
- name: Modify framework smali
run: |
python3 framework_patch.py "${{ env.defaultcore }}" "${{ env.core }}" "${{ env.isa15 }}"
- name: Modify services smali
run: |
python3 services_patch.py "${{ env.defaultcore }}" "${{ env.disableFlagSecure }}"
- name: Modify miui-services smali files
run: |
python3 miui-service_Patch.py "${{ env.isCN }}" "${{ env.fixNotification }}" "${{ env.multiFloatingWindow }}" "${{ env.addGboard }}" "${{ env.disableFlagSecure }}"
- name: Modify miui-framework smali files
run: |
python3 miui-framework_patch.py "${{ env.addGboard }}"
- name: Recompile framework dex files
run: |
if [ -d classes ]; then
java -jar smali.jar a -a ${{ github.event.inputs.android_api_level }} classes -o framework/classes.dex
else
echo "classes directory not found, skipping recompilation."
fi
for i in {2..5}; do
if [ -d "classes$i" ]; then
java -jar smali.jar a -a ${{ github.event.inputs.android_api_level }} "classes$i" -o "framework/classes$i.dex"
else
echo "classes$i directory not found, skipping recompilation."
fi
done
- name: Recompile services dex files
run: |
if [ -d services_classes ]; then
java -jar smali.jar a -a ${{ github.event.inputs.android_api_level }} services_classes -o services/classes.dex
else
echo "services_classes directory not found, skipping recompilation."
fi
for i in {2..5}; do
if [ -d "services_classes$i" ]; then
java -jar smali.jar a -a ${{ github.event.inputs.android_api_level }} "services_classes$i" -o "services/classes$i.dex"
else
echo "services_classes$i directory not found, skipping recompilation."
fi
done
- name: Recompile miui-services dex file
run: |
java -jar smali.jar a -a ${{ github.event.inputs.android_api_level }} miui_services_classes -o miui_services/classes.dex
- name: Recompile miui-framework dex file
run: |
java -jar smali.jar a -a ${{ github.event.inputs.android_api_level }} miui_framework_classes -o miui_framework/classes.dex
- name: Recompile framework.jar
run: |
cd framework
7z a -tzip ../framework_new.zip *
cd ..
- name: Recompile services.jar
run: |
cd services
7z a -tzip ../services_new.zip *
cd ..
- name: Recompile miui-services.jar
run: |
cd miui_services
7z a -tzip ../miui_services_new.zip *
cd ..
- name: Recompile miui-framework.jar
run: |
cd miui_framework
7z a -tzip ../miui_framework_new.zip *
cd ..
- name: Align the zips
run: |
zipalign -f -p -v -z 4 framework_new.zip aligned_framework.jar
zipalign -f -p -v -z 4 services_new.zip aligned_services.jar
zipalign -f -p -v -z 4 miui_services_new.zip aligned_miui_services.jar
zipalign -f -p -v -z 4 miui_framework_new.zip aligned_miui_framework.jar
- name: Copy aligned jars to Magisk module
run: |
mkdir -p magisk_module/system/framework
mkdir -p magisk_module/system/system_ext/framework
cp aligned_framework.jar magisk_module/system/framework/framework.jar
cp aligned_services.jar magisk_module/system/framework/services.jar
cp aligned_miui_services.jar magisk_module/system/system_ext/framework/miui-services.jar
cp aligned_miui_framework.jar magisk_module/system/system_ext/framework/miui-framework.jar
- name: Create Version From Link
run: |
if [ -z "${{ github.event.inputs.custom_version }}" ]; then
framework_url="${{ env.framework_jar_url }}"
version=$(echo $framework_url | grep -oP '(?<=V)[^/]*(?=/system)')
echo "version=${version}" >> $GITHUB_ENV
else
echo "version=${{ github.event.inputs.custom_version }}" >> $GITHUB_ENV
fi
if [ -z "${{ github.event.inputs.custom_device_name }}" ]; then
framework_url="${{ env.framework_jar_url }}"
device_name=$(echo $framework_url | grep -oP '(?<=redmi/)[^/]*(?=/-)')
echo "device_name=${device_name}" >> $GITHUB_ENV
else
echo "device_name=${{ github.event.inputs.custom_device_name }}" >> $GITHUB_ENV
fi
echo "version=${version}"
echo "device_name=${device_name}"
- name: Zip Magisk module
run: |
cd magisk_module
UNIQUE_NAME="moded_framework_services_${{ env.device_name }}_${{ env.version }}_$(date +%Y%m%d%H%M%S).zip"
zip -r ../$UNIQUE_NAME *
cd ..
mkdir -p out
chmod +w $UNIQUE_NAME
mv $UNIQUE_NAME out/
echo "UNIQUE_NAME=$UNIQUE_NAME" >> $GITHUB_ENV
- name: Create Release Notes
run: |
echo "## Release Notes" > release_notes.txt
echo "- Built modified jars from commit ${{ github.sha }}" >> release_notes.txt
echo "- Version: ${{ env.version }}" >> release_notes.txt
echo "- Device: ${{ env.device_name }}" >> release_notes.txt
echo "- Core patch: ${{ env.core }}" >> release_notes.txt
echo "- Default Core: ${{ env.defaultcore }}" >> release_notes.txt
echo "- Fix Notification: ${{ env.fixNotification }}" >> release_notes.txt
echo "- Add Gboard: ${{ env.addGboard }}" >> release_notes.txt
echo "- Disable Flag Secure: ${{ env.disableFlagSecure }}" >> release_notes.txt
echo "- Multi Floating Window: ${{ env.multiFloatingWindow }}" >> release_notes.txt
- name: Create Release
uses: ncipollo/release-action@v1
with:
artifacts: out/*
tag: ${{ env.version }}
name: moded_${{ env.device_name }}_${{ env.version }}
allowUpdates: true
makeLatest: true
bodyFile: release_notes.txt
token: ${{ secrets.GITHUB_TOKEN }}
- name: Notify via Telegram
run: |
curl -s -X POST https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage \
-d chat_id=@codes9488 \
-d message_thread_id=3 \
-d parse_mode="MarkdownV2" \
-d text="*Release *%0A%0A🔧 *Device:* \`${{ env.device_name }}\`%0A🔢 *Version:* \`${{ env.version }}\`%0A🌐 *Build ID:* \`${{ github.sha }}\`%0A📝 *Core Patch:* \`${{ env.core }}\`%0A🔧 *Default Core:* \`${{ env.defaultcore }}\`%0A🔧 *Fix Notification:* \`${{ env.fixNotification }}\`%0A🔧 *Add Gboard:* \`${{ env.addGboard }}\`%0A🔧 *Disable Flag Secure:* \`${{ env.disableFlagSecure }}\`%0A🔧 *Multi Floating Window:* \`${{ env.multiFloatingWindow }}\`%0A%0A🔗 [Download](https://github.com/${{ github.repository }}/releases/tag/${{ env.version }})%0A%0A \\#Release \\#${{ env.device_name }}"