Skip to content

Commit

Permalink
Attempt to fix triple-reboot issue
Browse files Browse the repository at this point in the history
  • Loading branch information
rapperskull committed Jun 1, 2023
1 parent 63bd9a9 commit cd82971
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 21 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.12)
project(RealmeGPSL5Enabler
VERSION "0.0.1"
VERSION "0.0.2"
DESCRIPTION "Enable L5/E5a/B2a GPS bands on realme devices."
HOMEPAGE_URL "https://github.com/rapperskull/realme_gps_l5_enabler/"
LANGUAGES C
Expand All @@ -26,7 +26,7 @@ target_link_libraries(gnss_patcher nvbk)

if(ANDROID)
set(MAGISK_LONG_NAME "realme GPS L5 Enabler")
set(MAGISK_VERSION_CODE 1)
set(MAGISK_VERSION_CODE 2)
set(MAGISK_UPDATE_JSON "https://raw.githubusercontent.com/rapperskull/realme_gps_l5_enabler/master/update.json")

set(MAGISK_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/magisk/)
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

Magisk module to enable L5/E5a/B2a GPS bands on realme/OPPO/OnePlus devices with Qualcomm Snapdragon processors. It has been tested only on realme GT 2 Pro (RMX3301), but it should work on other devices too if there's hardware support.

## Changelog

### v0.0.2

- Attempt to fix triple-reboot issue

### v0.0.1

- First release

## How it works

At each boot, it extracts the `oplusstanvbk` partition, patches it by changing the `/nv/item_files/gps/cgps/me/gnss_multiband_configuration` property, and saves it in the module's directory.
Expand Down
49 changes: 33 additions & 16 deletions src/magisk/post-fs-data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,54 @@ exec 2>&1

echo "Slot: ${SLOT}"
echo
ls -la "$PATH1" "$PATH2"
ls -laZ "$PATH1" "$PATH2"
echo
if [ -L "$PATH1" ] || [ -L "$PATH2" ]; then
rm -f "$MODFILE"
if [ -L "$PATH1" ]; then
orig="$(readlink -fn ${PATH1})"
ORIG="$(readlink -fn "$PATH1")"
else
orig="$(readlink -fn ${PATH2})"
ORIG="$(readlink -fn "$PATH2")"
fi
DEV="${ORIG}_mod"
chmod +x "$PATCHER"
echo "Running patcher"
"$PATCHER" -i "$orig" -o "$MODFILE"
"$PATCHER" -i "$ORIG" -o "$MODFILE"
ret=$?
if [ $ret -ne 0 ]; then
echo "Patcher failed!!!"
else
echo
DEV="$(/system/bin/losetup -sf $MODFILE)"
if [ -z "$DEV" ]; then
echo "ERROR: Cannot create loop device"
# The loop device path must be in the form '/dev/block/sdX...' because mark_boot_successful()
# will ultimately call gpt_get_header() in gpt-utils and it will try to open the device name
# truncated to length 'sizeof("/dev/block/sda") - 1'. This means that if the original partition
# is '/dev/block/sdX00', it will try to open '/dev/block/sdX', so if we just use the next available
# loop device, it will fail opening '/dev/block/loo'. Using the same prefix as the original
# partition will solve the issue, but requires a "hack" to work.
# We first associate our patched file with the next available loop device, then we rename it.
NEXT_LOOP="$(/system/bin/losetup -sf "$MODFILE")"
if [ -z "$NEXT_LOOP" ]; then
echo "ERROR: Cannot create loop device"
else
echo "Created loop device" "$DEV"
chcon -v "u:object_r:vendor_custom_ab_block_device:s0" "${DEV}"
if [ -L "$PATH1" ]; then
ln -sfv "${DEV}" "$PATH1"
mv -f "$NEXT_LOOP" "$DEV"
ret=$?
if [ $ret -ne 0 ]; then
echo "ERROR: Cannot rename loop device"
else
chcon -v "u:object_r:vendor_custom_ab_block_device:s0" "$DEV" # Set correct SELinux context
echo "Created loop device" "$DEV"
ls -laZ "$DEV"
echo
# Create symlinks to newly created loop device
if [ -L "$PATH1" ]; then
ln -sfv "$DEV" "$PATH1"
fi
if [ -L "$PATH2" ]; then
ln -sfv "$DEV" "$PATH2"
fi
echo
ls -laZ "$PATH1" "$PATH2"
fi
if [ -L "$PATH2" ]; then
ln -sfv "${DEV}" "$PATH2"
fi
echo
ls -la "$PATH1" "$PATH2"
fi
fi
fi
6 changes: 3 additions & 3 deletions update.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"version": "0.0.1",
"versionCode": "1",
"zipUrl": "https://github.com/rapperskull/realme_gps_l5_enabler/releases/download/v0.0.1/RealmeGPSL5Enabler-v0.0.1.zip",
"version": "0.0.2",
"versionCode": "2",
"zipUrl": "https://github.com/rapperskull/realme_gps_l5_enabler/releases/download/v0.0.2/RealmeGPSL5Enabler-v0.0.2.zip",
"changelog": "https://raw.githubusercontent.com/rapperskull/realme_gps_l5_enabler/master/README.md"
}

0 comments on commit cd82971

Please sign in to comment.