Skip to content

Commit

Permalink
unica: patches: move to new Magisk module-like structure
Browse files Browse the repository at this point in the history
Change-Id: Ibaed2e15c9cc8a9ea2c353681740d31e3d278d9e
  • Loading branch information
salvogiangri committed Dec 5, 2023
1 parent 98b0a40 commit aef1a5a
Show file tree
Hide file tree
Showing 32 changed files with 127 additions and 189 deletions.
5 changes: 5 additions & 0 deletions scripts/internal/apply_modules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ APPLY_SMALI_PATCHES()
local COMMIT_NAME
COMMIT_NAME="$(grep "^Subject:" "$patch" | sed 's/.*PATCH] //')"

if [[ "$patch" == *"0000-"* ]]; then
[[ "$patch" == *"AOSP"* ]] && $ROM_IS_OFFICIAL && continue
[[ "$patch" == *"UNICA"* ]] && $ROM_IS_OFFICIAL || continue
fi

echo "Applying \"$COMMIT_NAME\" to $TARGET"
OUT="$(patch -p1 -s -t -N --dry-run < "$patch")" \
|| echo "$OUT" | grep -q "Skipping patch" || false
Expand Down
7 changes: 6 additions & 1 deletion scripts/make_rom.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,15 @@ if $BUILD_ROM; then
bash "$SRC_DIR/scripts/internal/apply_modules.sh" "$SRC_DIR/unica/packages"

echo -e "\n- Applying ROM patches..."
find "$SRC_DIR/unica/patches" -maxdepth 1 -executable -type f -exec bash {} \;
bash "$SRC_DIR/scripts/internal/apply_modules.sh" "$SRC_DIR/unica/patches"
[[ -d "$SRC_DIR/target/$TARGET_CODENAME/patches" ]] \
&& find "$SRC_DIR/target/$TARGET_CODENAME/patches" -maxdepth 1 -executable -type f -exec bash {} \;

echo -e "\n- Recompiling APKs/JARs..."
while read -r i; do
bash "$SRC_DIR/scripts/apktool.sh" b "$i"
done <<< "$(find "$OUT_DIR/apktool" -type d \( -name "*.apk" -o -name "*.jar" \) -printf "%p\n" | sed "s.$OUT_DIR/apktool..")"

echo ""
echo -n "$WORK_DIR_HASH" > "$WORK_DIR/.completed"
else
Expand Down
2 changes: 0 additions & 2 deletions unica/debloat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ system/etc/permissions/privapp-permissions-com.samsung.android.app.kfa.xml
system/etc/permissions/privapp-permissions-com.samsung.android.authfw.xml
system/etc/permissions/privapp-permissions-com.samsung.android.carkey.xml
system/etc/permissions/privapp-permissions-com.samsung.android.dkey.xml
system/etc/permissions/privapp-permissions-com.samsung.android.kgclient.xml
system/etc/permissions/privapp-permissions-com.samsung.android.samsungpass.xml
system/etc/permissions/privapp-permissions-com.samsung.android.spayfw.xml
system/etc/permissions/privapp-permissions-com.wssyncmldm.xml
Expand All @@ -113,7 +112,6 @@ system/priv-app/AuthFramework
system/priv-app/DigitalKey
system/priv-app/FotaAgent
system/priv-app/KnoxAIFrameworkApp
system/priv-app/KnoxGuard
system/priv-app/OneDrive_Samsung_v3
system/priv-app/PaymentFramework
system/priv-app/SamsungCarKeyFw
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
#====================================================
# FILE: floating_feature.sh
# AUTHOR: BlackMesa123, ImbaWind, xpirt
# DESCRIPTION: Read and applies all the configs
# defined in the "sff.sh" file inside
# the target folder.
#====================================================

# shellcheck disable=SC1091

set -e

# [
SRC_DIR="$(git rev-parse --show-toplevel)"
OUT_DIR="$SRC_DIR/out"
WORK_DIR="$OUT_DIR/work_dir"
SKIPUNZIP=1

SET_CONFIG()
{
Expand All @@ -35,7 +20,7 @@ SET_CONFIG()
echo "Adding \"$CONFIG\" config with \"$VALUE\" in /system/system/etc/floating_feature.xml"
sed -i "/<\/SecFloatingFeatureSet>/d" "$FILE"
if ! grep -q "Added by unica" "$FILE"; then
echo " <!-- Added by unica/patches/floating_feature.sh -->" >> "$FILE"
echo " <!-- Added by unica/patches/floating_feature/customize.sh -->" >> "$FILE"
fi
echo " <${CONFIG}>${VALUE}</${CONFIG}>" >> "$FILE"
echo "</SecFloatingFeatureSet>" >> "$FILE"
Expand Down Expand Up @@ -64,9 +49,6 @@ READ_AND_APPLY_CONFIGS()
fi
}

source "$OUT_DIR/config.sh"
# ]

# Apply target floating feature
READ_AND_APPLY_CONFIGS

Expand All @@ -80,5 +62,3 @@ fi

# Smart Tutor
SET_CONFIG "SEC_FLOATING_FEATURE_COMMON_CONFIG_SMARTTUTOR_PACKAGES_PATH" --delete

exit 0
4 changes: 4 additions & 0 deletions unica/patches/floating_feature/module.prop
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
id=floating_feature
name=floating_feature.xml patches
author=BlackMesa123
description=Reads target "sff.sh" config and applies all the changes in floating_feature.
24 changes: 24 additions & 0 deletions unica/patches/knoxguard/customize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
SKIPUNZIP=1

REMOVE_FROM_WORK_DIR()
{
local FILE_PATH="$1"

if [ -e "$FILE_PATH" ]; then
local FILE
local PARTITION
FILE="$(echo -n "$FILE_PATH" | sed "s.$WORK_DIR/..")"
PARTITION="$(echo -n "$FILE" | cut -d "/" -f 1)"

rm -rf "$FILE_PATH"

FILE="$(echo -n "$FILE" | sed 's/\//\\\//g')"
sed -i "/$FILE/d" "$WORK_DIR/configs/fs_config-$PARTITION"

FILE="$(echo -n "$FILE" | sed 's/\./\\./g')"
sed -i "/$FILE/d" "$WORK_DIR/configs/file_context-$PARTITION"
fi
}

REMOVE_FROM_WORK_DIR "$WORK_DIR/system/system/etc/permissions/privapp-permissions-com.samsung.android.kgclient.xml"
REMOVE_FROM_WORK_DIR "$WORK_DIR/system/system/priv-app/KnoxGuard"
4 changes: 4 additions & 0 deletions unica/patches/knoxguard/module.prop
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
id=knoxguard
name=Disable KnoxGuard
author=BlackMesa123
description=
37 changes: 37 additions & 0 deletions unica/patches/misc_smali_patches/customize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
SKIPUNZIP=1

set -Eeo pipefail

trap "echo 'Failed to apply'" ERR

APPLY_PATCHES()
{
local TARGET="$1"

local PATCHES="$(find "$SRC_DIR/target/$TARGET_CODENAME/patches/smali$TARGET" -type f -name "*.patch" -printf "%p ")"

[ ! -d "$APKTOOL_DIR$TARGET" ] && bash "$SRC_DIR/scripts/apktool.sh" d "$TARGET"

cd "$APKTOOL_DIR$TARGET"
for patch in $PATCHES; do
local OUT
local COMMIT_NAME
COMMIT_NAME="$(grep "^Subject:" "$patch" | sed 's/.*PATCH] //')"

if [[ "$patch" == *"0000-"* ]]; then
[[ "$patch" == *"AOSP"* ]] && $ROM_IS_OFFICIAL && continue
[[ "$patch" == *"UNICA"* ]] && $ROM_IS_OFFICIAL || continue
fi

echo "Applying \"$COMMIT_NAME\" to $TARGET"
OUT="$(patch -p1 -s -t -N --dry-run < "$patch")" \
|| echo "$OUT" | grep -q "Skipping patch" || false
patch -p1 -s -t -N < "$patch" &> /dev/null || true
done
cd - &> /dev/null
}

FILES_TO_PATCH+="$(find "$SRC_DIR/target/$TARGET_CODENAME/patches/smali" -type d \( -name "*.apk" -o -name "*.jar" \) -printf "\n%p" | sed 's/.*\/smali//')"
for i in $FILES_TO_PATCH; do
APPLY_PATCHES "$i"
done
4 changes: 4 additions & 0 deletions unica/patches/misc_smali_patches/module.prop
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
id=misc_smali_patches
name=Misc smali patches
author=BlackMesa123
description=
22 changes: 1 addition & 21 deletions unica/patches/nfc.sh → unica/patches/nfc/customize.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,4 @@
#====================================================
# FILE: nfc.sh
# AUTHOR: BlackMesa123
# DESCRIPTION: Replace source NFC system blobs with
# stock ones
#====================================================

# shellcheck disable=SC1091

set -e

# [
SRC_DIR="$(git rev-parse --show-toplevel)"
OUT_DIR="$SRC_DIR/out"
FW_DIR="$OUT_DIR/fw"
WORK_DIR="$OUT_DIR/work_dir"

source "$OUT_DIR/config.sh"
# ]
SKIPUNZIP=1

MODEL=$(echo -n "$TARGET_FIRMWARE" | cut -d "/" -f 1)
REGION=$(echo -n "$TARGET_FIRMWARE" | cut -d "/" -f 2)
Expand Down Expand Up @@ -74,5 +56,3 @@ if [[ ! -f "$WORK_DIR/system/system/lib64/libnfc_${TARGET_LIB_NAME}_jni.so" ]];
sed -i "/libstatslog_nfc_nxp/d" "$WORK_DIR/configs/fs_config-system"
fi
fi

exit 0
4 changes: 4 additions & 0 deletions unica/patches/nfc/module.prop
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
id=nfc
name=Stock NFC blobs
author=BlackMesa123
description=Replaces source NFC blobs with stock ones.
27 changes: 4 additions & 23 deletions unica/patches/apply_props.sh → unica/patches/props/customize.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
#====================================================
# FILE: apply_props.sh
# AUTHOR: BlackMesa123, xpirt
# DESCRIPTION: Read and applies all the ".prop"
# files inside the "props" folder in
# work_dir.
#====================================================

# shellcheck disable=SC1091

set -e

# [
SRC_DIR="$(git rev-parse --show-toplevel)"
OUT_DIR="$SRC_DIR/out"
WORK_DIR="$OUT_DIR/work_dir"
SKIPUNZIP=1

SET_PROP()
{
Expand All @@ -39,7 +24,7 @@ SET_PROP()
else
echo "Adding \"$PROP\" prop with \"$VALUE\" in $FILE" | sed "s.$WORK_DIR..g"
if ! grep -q "Added by unica" "$FILE"; then
echo "# Added by unica/patches/apply_props.sh" >> "$FILE"
echo "# Added by unica/patches/apply_props/customize.sh" >> "$FILE"
fi
echo "$PROP=$VALUE" >> "$FILE"
fi
Expand Down Expand Up @@ -70,7 +55,7 @@ READ_AND_APPLY_PROPS()
FILE="$WORK_DIR/vendor/build.prop"
;;
*)
return 1
continue
;;
esac

Expand All @@ -92,11 +77,7 @@ READ_AND_APPLY_PROPS()
done
}

source "$OUT_DIR/config.sh"
# ]

READ_AND_APPLY_PROPS "$SRC_DIR/unica/patches/props"

[[ -d "$SRC_DIR/target/$TARGET_CODENAME/patches/props" ]] \
&& READ_AND_APPLY_PROPS "$SRC_DIR/target/$TARGET_CODENAME/patches/props"

exit 0
4 changes: 4 additions & 0 deletions unica/patches/props/module.prop
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
id=props
name=Props patches
author=BlackMesa123
description=Reads target ".prop" files and applies all the changes in each target prop.
32 changes: 0 additions & 32 deletions unica/patches/rro.sh

This file was deleted.

11 changes: 11 additions & 0 deletions unica/patches/rro/customize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SKIPUNZIP=1

if [[ -d "$SRC_DIR/target/$TARGET_CODENAME/patches/overlay" ]]; then
bash -e "$SRC_DIR/scripts/apktool.sh" d -f "/product/overlay/framework-res__auto_generated_rro_product.apk"

echo "Applying stock overlay configs"
rm -f "$APKTOOL_DIR/product/overlay/framework-res__auto_generated_rro_product.apk/res/values/public.xml"
cp -a --preserve=all \
"$SRC_DIR/target/$TARGET_CODENAME/patches/overlay/"* \
"$APKTOOL_DIR/product/overlay/framework-res__auto_generated_rro_product.apk/res"
fi
4 changes: 4 additions & 0 deletions unica/patches/rro/module.prop
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
id=rro
name=/product RRO configs
author=BlackMesa123
description=Replaces /product RRO configs with target ones.
4 changes: 4 additions & 0 deletions unica/patches/sak-fix/module.prop
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
id=sak-fix
name=SAK fix
author=BlackMesa123
description=
4 changes: 4 additions & 0 deletions unica/patches/sf-fix/module.prop
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
id=sf-fix
name=Secure Folder/Work profile fix
author=BlackMesa123
description=
68 changes: 0 additions & 68 deletions unica/patches/smali.sh

This file was deleted.

Loading

0 comments on commit aef1a5a

Please sign in to comment.