Skip to content

Commit b2db912

Browse files
committed
chore: sync with microG unofficial installer
Signed-off-by: ale5000 <15793015+ale5000-git@users.noreply.github.com>
1 parent a2a6821 commit b2db912

File tree

8 files changed

+130
-76
lines changed

8 files changed

+130
-76
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Google sync add-on
1515

1616
Description
1717
-----------
18-
Google sync add-on is a flashable zip created by ale5000 for a simple installation of Google sync adapters on Android from 4.4 to 15 (excluding Android 6.x).
18+
Google sync add-on is a flashable zip created by ale5000 for a simple installation of Google sync adapters on Android from 4.4 to 16 (excluding Android 6.x).
1919

2020
This project is available on GitHub_, on GitLab_ as well as on XDA_.
2121

zip-content/META-INF/com/google/android/update-binary.sh

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,13 @@ generate_random
274274
_ub_our_main_script="${TMPDIR:?}/${LAST_RANDOM:?}-customize.sh"
275275

276276
STATUS=1
277-
UNKNOWN_ERROR=1
278277

279278
package_extract_file 'customize.sh' "${_ub_our_main_script:?}"
280279

281280
echo "Loading ${LAST_RANDOM:?}-customize.sh..."
282281
# shellcheck source=SCRIPTDIR/../../../../customize.sh
283282
command . "${_ub_our_main_script:?}" || ui_error "Failed to source '${_ub_our_main_script?}'"
283+
if test "${UNKNOWN_ERROR:-1}" != '0' && test "${STATUS?}" = '0'; then STATUS=253; fi
284284

285285
if test -f "${_ub_our_main_script:?}"; then
286286
rm "${_ub_our_main_script:?}" || ui_error "Failed to delete '${_ub_our_main_script?}'"
@@ -294,10 +294,9 @@ if test -d '/tmp'; then
294294
fi
295295

296296
case "${STATUS?}" in
297-
'0') # Success
298-
test "${UNKNOWN_ERROR:?}" -eq 0 || ui_error 'Installation failed with an unknown error' ;;
299-
'250') # TEST mode
300-
ui_msg 'TEST mode completed!' ;;
301-
*) # Failure
302-
ui_error "Installation script failed" "${STATUS:?}" ;;
297+
'0') ;; # Success
298+
'250') ui_msg 'TEST mode completed' ;;
299+
'251') ui_error 'Restart the device and flash this again!' "${STATUS:?}" ;;
300+
'252') ui_error 'Restart the emulator and flash this again!' "${STATUS:?}" ;;
301+
*) ui_error "Installation script failed" "${STATUS?}" ;; # Failure
303302
esac

zip-content/customize.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,9 @@ DEVICE_DUMPSYS="$(command -v dumpsys)" || DEVICE_DUMPSYS=''
364364
DEVICE_STAT="$(command -v stat)" || DEVICE_STAT=''
365365
DEVICE_PM="$(command -v pm)" || DEVICE_PM=''
366366
DEVICE_AM="$(command -v am)" || DEVICE_AM=''
367-
readonly PREVIOUS_PATH DEVICE_TWRP DEVICE_GETPROP DEVICE_MOUNT DEVICE_DUMPSYS DEVICE_STAT DEVICE_PM DEVICE_AM
368-
export PREVIOUS_PATH DEVICE_TWRP DEVICE_GETPROP DEVICE_MOUNT DEVICE_DUMPSYS DEVICE_STAT DEVICE_PM DEVICE_AM
367+
DEVICE_APPOPS="$(command -v appops)" || DEVICE_APPOPS=''
368+
readonly PREVIOUS_PATH DEVICE_TWRP DEVICE_GETPROP DEVICE_MOUNT DEVICE_DUMPSYS DEVICE_STAT DEVICE_PM DEVICE_AM DEVICE_APPOPS
369+
export PREVIOUS_PATH DEVICE_TWRP DEVICE_GETPROP DEVICE_MOUNT DEVICE_DUMPSYS DEVICE_STAT DEVICE_PM DEVICE_AM DEVICE_APPOPS
369370

370371
if test "${TEST_INSTALL:-false}" = 'false'; then
371372
create_dir_safe "${TMP_PATH:?}/bin"

zip-content/inc/common-functions.sh

Lines changed: 75 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -364,16 +364,16 @@ _get_mount_info()
364364
{
365365
if test ! -e "${1:?}"; then return 2; fi
366366

367-
if test "${TEST_INSTALL:-false}" = 'false' && test -e '/proc/mounts'; then
368-
grep -m 1 -e '[[:blank:]]'"${1:?}"'[[:blank:]]' '/proc/mounts' 2> /dev/null || return 1
367+
if test "${TEST_INSTALL:-false}" = 'false' && test -f '/proc/mounts'; then
368+
grep -e '[[:blank:]]'"${1:?}"'[[:blank:]]' -- '/proc/mounts' 2> /dev/null || return 1
369369
return 0
370370
fi
371371

372372
local _mount_result
373373
if _mount_result="$(mount 2> /dev/null)" || {
374374
test -n "${DEVICE_MOUNT:-}" && _mount_result="$("${DEVICE_MOUNT:?}")"
375375
}; then
376-
if printf '%s' "${_mount_result:?}" | grep -m 1 -e '[[:blank:]]'"${1:?}"'[[:blank:]]'; then return 0; fi
376+
if printf '%s\n' "${_mount_result:?}" | grep -e '[[:blank:]]'"${1:?}"'[[:blank:]]'; then return 0; fi
377377
return 1
378378
fi
379379

@@ -397,15 +397,16 @@ is_mounted_read_write()
397397
local _mount_info
398398
_mount_info="$(_get_mount_info "${1:?}")" || ui_error "is_mounted_read_write has failed for '${1?}'"
399399

400-
# IMPORTANT: We have to avoid "printf: write error: Broken pipe" when a string is piped to "grep -q" or "grep -m1"
401-
if
402-
{
403-
(printf 2> /dev/null '%s\n' "${_mount_info:?}") || :
404-
} | grep -q -e '[[:blank:],(]rw[),[:blank:]]'
405-
then
406-
return 0
407-
fi
400+
# With an "overlay" there may be multiple entries, example:
401+
# /dev/block/dm-3 on /product type ext4 (ro,seclabel,relatime)
402+
# overlay on /product type overlay (rw,seclabel,noatime,lowerdir=/product,upperdir=/mnt/scratch/overlay/product/upper,workdir=/mnt/scratch/overlay/product/work,redirect_dir=nofollow,userxattr)
403+
#
404+
# or
405+
#
406+
# /dev/block/dm-3 /product ext4 ro,seclabel,relatime 0 0
407+
# overlay /product overlay rw,seclabel,noatime,lowerdir=/product,upperdir=/mnt/scratch/overlay/product/upper,workdir=/mnt/scratch/overlay/product/work,redirect_dir=nofollow,userxattr 0 0
408408

409+
if printf '%s\n' "${_mount_info:?}" | grep 1> /dev/null -e '[[:blank:],(]rw[),[:blank:]]'; then return 0; fi
409410
return 1
410411
}
411412

@@ -419,6 +420,24 @@ _disable_write_locks()
419420
fi
420421
}
421422

423+
_execute_system_remount()
424+
{
425+
local _remount_output
426+
test "${DRY_RUN:?}" -lt 2 || return 1
427+
428+
# Use the system remount binary if available (this will save us many problems)
429+
if test -f "${SYS_PATH:?}/bin/remount"; then
430+
ui_msg 'Executing the remount binary...'
431+
_remount_output="$("${SYS_PATH:?}/bin/remount" 2>&1)" || ui_warning 'Failed to execute the remount binary'
432+
ui_debug "${_remount_output?}"
433+
case "${_remount_output?}" in
434+
*'reboot your device'*) if test "${IS_EMU:?}" = 'true'; then exit 252; else exit 251; fi ;;
435+
*) ;;
436+
esac
437+
ui_debug ''
438+
fi
439+
}
440+
422441
_remount_read_write_helper()
423442
{
424443
test "${DRY_RUN:?}" -lt 2 || return 2
@@ -690,6 +709,9 @@ mount_partition_if_possible()
690709
elif test -n "${SYS_MOUNTPOINT-}" && test ! -L "${SYS_MOUNTPOINT:?}/${_partition_name:?}" && test -d "${SYS_MOUNTPOINT:?}/${_partition_name:?}"; then # Example: /system_root/odm
691710
_skip_warnings='true'
692711
ui_debug "Found ${_partition_name?} folder: ${SYS_MOUNTPOINT?}/${_partition_name?}"
712+
elif test ! -L "/${_partition_name:?}" && test -d "/${_partition_name:?}"; then # Example: /odm
713+
_skip_warnings='true'
714+
ui_debug "Found ${_partition_name?} folder: /${_partition_name?}"
693715
fi
694716
fi
695717

@@ -827,23 +849,48 @@ install_survival_script()
827849

828850
reset_runtime_permissions_if_needed()
829851
{
852+
local _found
853+
test "${FIRST_INSTALLATION:?}" = 'true' || return
854+
test -n "${DATA_PATH?}" || return
855+
830856
# Reset the runtime permissions to prevent issues on dirty flashing
831857
if test "${API:?}" -ge 23; then
832-
if test -e "${DATA_PATH:?}/system/users/0/runtime-permissions.xml"; then
833-
if test "${FIRST_INSTALLATION:?}" = 'true' || ! grep -q -F -e "${1:?}" -- "${DATA_PATH:?}"/system/users/*/runtime-permissions.xml; then
834-
ui_msg "Resetting Android runtime permissions..."
835-
test "${DRY_RUN:?}" -ne 0 || delete "${DATA_PATH:?}"/system/users/*/runtime-permissions.xml
836-
fi
858+
_found='false'
859+
if _something_exists "${DATA_PATH:?}"/system/users/*/runtime-permissions.xml; then
860+
ui_msg "Resetting runtime permissions..."
861+
_found='true'
862+
test "${DRY_RUN:?}" -ne 0 || delete "${DATA_PATH:?}"/system/users/*/runtime-permissions.xml
837863
fi
838-
if test -e "${DATA_PATH:?}/misc_de/0/apexdata/com.android.permission/runtime-permissions.xml"; then
839-
if test "${FIRST_INSTALLATION:?}" = 'true' || ! grep -q -F -e "${1:?}" -- "${DATA_PATH:?}"/misc_de/*/apexdata/com.android.permission/runtime-permissions.xml; then
840-
ui_msg "Resetting Android runtime permissions..."
841-
test "${DRY_RUN:?}" -ne 0 || delete "${DATA_PATH:?}"/misc_de/*/apexdata/com.android.permission/runtime-permissions.xml
842-
fi
864+
if _something_exists "${DATA_PATH:?}"/misc_de/*/apexdata/com.android.permission/runtime-permissions.xml*; then
865+
ui_msg "Resetting runtime permissions..."
866+
_found='true'
867+
test "${DRY_RUN:?}" -ne 0 || delete "${DATA_PATH:?}"/misc_de/*/apexdata/com.android.permission/runtime-permissions.xml*
868+
fi
869+
870+
if test "${_found:?}" = 'true' && test "${BOOTMODE:?}" = 'true' && test -n "${DEVICE_PM?}" && test "${DRY_RUN:?}" -eq 0; then
871+
PATH="${PREVIOUS_PATH?}" "${DEVICE_PM:?}" reset-permissions || ui_warning 'Failed to reset runtime permissions'
843872
fi
844873
fi
845874
}
846875

876+
reset_appops_if_needed()
877+
{
878+
test "${FIRST_INSTALLATION:?}" = 'true' || return
879+
test -n "${DATA_PATH?}" || return
880+
test "${API:?}" -ge 23 || return
881+
882+
ui_msg "Resetting App Ops..."
883+
test "${DRY_RUN:?}" -eq 0 || return
884+
885+
delete "${DATA_PATH:?}"/system/appops.xml
886+
delete "${DATA_PATH:?}"/system/appops_accesses.xml
887+
delete "${DATA_PATH:?}"/system/appops/discrete/*
888+
delete "${DATA_PATH:?}"/system/appops/history/*
889+
if test "${BOOTMODE:?}" = 'true' && test -n "${DEVICE_APPOPS?}"; then
890+
PATH="${PREVIOUS_PATH?}" "${DEVICE_APPOPS:?}" 1> /dev/null read-settings || ui_warning 'Failed to refresh App Ops'
891+
fi
892+
}
893+
847894
_write_test()
848895
{
849896
test "${DRY_RUN:?}" -lt 2 || return 0
@@ -1279,6 +1326,7 @@ initialize()
12791326
export SETUP_TYPE
12801327

12811328
_disable_write_locks
1329+
_execute_system_remount
12821330

12831331
remount_read_write "${SYS_MOUNTPOINT:?}" || {
12841332
deinitialize
@@ -3481,7 +3529,7 @@ soft_kill_app()
34813529
test "${DRY_RUN:?}" -eq 0 || return
34823530

34833531
if test "${BOOTMODE:?}" = 'true' && test -n "${DEVICE_AM?}"; then
3484-
PATH="${PREVIOUS_PATH?}" "${DEVICE_AM:?}" 2> /dev/null kill "${1:?}" || true
3532+
PATH="${PREVIOUS_PATH?}" "${DEVICE_AM:?}" kill "${1:?}" || :
34853533
fi
34863534
}
34873535

@@ -3490,7 +3538,7 @@ kill_app()
34903538
test "${DRY_RUN:?}" -eq 0 || return
34913539

34923540
if test "${BOOTMODE:?}" = 'true' && test -n "${DEVICE_AM?}"; then
3493-
PATH="${PREVIOUS_PATH?}" "${DEVICE_AM:?}" 2> /dev/null force-stop "${1:?}" || PATH="${PREVIOUS_PATH?}" "${DEVICE_AM:?}" 2> /dev/null kill "${1:?}" || true
3541+
PATH="${PREVIOUS_PATH?}" "${DEVICE_AM:?}" force-stop "${1:?}" || PATH="${PREVIOUS_PATH?}" "${DEVICE_AM:?}" kill "${1:?}" || :
34943542
fi
34953543
}
34963544

@@ -3499,7 +3547,7 @@ disable_app()
34993547
test "${DRY_RUN:?}" -eq 0 || return
35003548

35013549
if test "${BOOTMODE:?}" = 'true' && test -n "${DEVICE_PM?}"; then
3502-
PATH="${PREVIOUS_PATH?}" "${DEVICE_PM:?}" 2> /dev/null disable "${1:?}" || true
3550+
PATH="${PREVIOUS_PATH?}" "${DEVICE_PM:?}" 2> /dev/null disable "${1:?}" || :
35033551
fi
35043552
}
35053553

@@ -3508,7 +3556,7 @@ clear_app()
35083556
test "${DRY_RUN:?}" -eq 0 || return
35093557

35103558
if test "${BOOTMODE:?}" = 'true' && test -n "${DEVICE_PM?}"; then
3511-
PATH="${PREVIOUS_PATH?}" "${DEVICE_PM:?}" 2> /dev/null clear "${1:?}" || true
3559+
PATH="${PREVIOUS_PATH?}" "${DEVICE_PM:?}" 2> /dev/null 1>&2 clear "${1:?}" || :
35123560
fi
35133561
}
35143562

@@ -3517,8 +3565,8 @@ clear_and_enable_app()
35173565
test "${DRY_RUN:?}" -eq 0 || return
35183566

35193567
if test "${BOOTMODE:?}" = 'true' && test -n "${DEVICE_PM?}"; then
3520-
PATH="${PREVIOUS_PATH?}" "${DEVICE_PM:?}" 2> /dev/null clear "${1:?}" || true
3521-
PATH="${PREVIOUS_PATH?}" "${DEVICE_PM:?}" 2> /dev/null enable "${1:?}" || true
3568+
PATH="${PREVIOUS_PATH?}" "${DEVICE_PM:?}" 2> /dev/null 1>&2 clear "${1:?}" || :
3569+
PATH="${PREVIOUS_PATH?}" "${DEVICE_PM:?}" 2> /dev/null enable "${1:?}" || :
35223570
fi
35233571
}
35243572

zip-content/module.prop

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
numericId=928871
66
id=google-sync-addon
77
name=Google sync add-on
8-
version=v1.3.2.24-alpha
8+
version=v1.3.2.25-alpha
99
versionCode=6
1010
author=ale5000
1111
description=It installs Google sync adapters on Android.
1212
applicationId=net.ale5000.google_sync_addon.ota
1313
support=https://github.com/micro5k/google-sync-addon/issues
1414
donate=https://liberapay.com/microg-unofficial-by-ale5000/donate
1515
minApi=19
16-
maxApi=35
16+
maxApi=36

zip-content/scripts/install.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,14 @@ prepare_installation
6767

6868
# Install
6969
perform_installation
70+
reset_runtime_permissions_if_needed
71+
reset_appops_if_needed
7072
reset_authenticator_and_sync_adapter_caches
7173

7274
clear_and_enable_app 'com.google.android.backuptransport'
7375
clear_and_enable_app 'com.google.android.syncadapters.contacts'
7476
clear_and_enable_app 'com.google.android.syncadapters.calendar'
7577

76-
# Install survival script
7778
install_survival_script '00-1-google-sync'
7879

79-
# Resetting Android runtime permissions
80-
reset_runtime_permissions_if_needed 'com.google.android.syncadapters.contacts'
81-
8280
finalize_correctly

zip-content/scripts/uninstall.sh

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,13 @@ uninstall_list | while IFS='|' read -r FILENAME INTERNAL_NAME _; do
137137
delete "${SYS_PATH:?}/system_ext/app/${FILENAME}"
138138

139139
# Dalvik cache
140-
delete "${DATA_PATH:?}"/dalvik-cache/system@priv-app@"${FILENAME}"[@\.]*@classes*
141-
delete "${DATA_PATH:?}"/dalvik-cache/system@app@"${FILENAME}"[@\.]*@classes*
142-
delete "${DATA_PATH:?}"/dalvik-cache/*/system@priv-app@"${FILENAME}"[@\.]*@classes*
143-
delete "${DATA_PATH:?}"/dalvik-cache/*/system@app@"${FILENAME}"[@\.]*@classes*
140+
delete "${DATA_PATH:?}"/dalvik-cache/system@priv-app@"${FILENAME:?}"[@\.]*@classes*
141+
delete "${DATA_PATH:?}"/dalvik-cache/system@app@"${FILENAME:?}"[@\.]*@classes*
142+
delete "${DATA_PATH:?}"/dalvik-cache/*/system@priv-app@"${FILENAME:?}"[@\.]*@classes*
143+
delete "${DATA_PATH:?}"/dalvik-cache/*/system@app@"${FILENAME:?}"[@\.]*@classes*
144+
145+
# Package caches
146+
delete "${DATA_PATH:?}"/system/package_cache/*/"${FILENAME:?}"-*
144147

145148
# Delete legacy libs (very unlikely to be present but possible)
146149
delete "${SYS_PATH:?}/lib64/${FILENAME:?}"
@@ -157,15 +160,16 @@ uninstall_list | while IFS='|' read -r FILENAME INTERNAL_NAME _; do
157160
delete "${SYS_PATH:?}/etc/default-permissions/${FILENAME:?}-permissions.xml"
158161
fi
159162

160-
if test -n "${INTERNAL_NAME}"; then
163+
if test -n "${INTERNAL_NAME?}"; then
161164
# Only delete app updates during uninstallation or first-time installation
162165
if test "${SETUP_TYPE:?}" = 'uninstall' || test "${FIRST_INSTALLATION:?}" = 'true'; then
163-
delete "${DATA_PATH:?}/app/${INTERNAL_NAME}"
164-
delete "${DATA_PATH:?}/app/${INTERNAL_NAME}.apk"
165-
delete "${DATA_PATH:?}/app/${INTERNAL_NAME}"-*
166-
delete "/mnt/asec/${INTERNAL_NAME}"
167-
delete "/mnt/asec/${INTERNAL_NAME}.apk"
168-
delete "/mnt/asec/${INTERNAL_NAME}"-*
166+
delete "${DATA_PATH:?}/app/${INTERNAL_NAME:?}.apk"
167+
delete "${DATA_PATH:?}/app/${INTERNAL_NAME:?}"
168+
delete "${DATA_PATH:?}/app/${INTERNAL_NAME:?}"-*
169+
delete "${DATA_PATH:?}"/app/*/"${INTERNAL_NAME:?}"-* # Recent Android
170+
delete "/mnt/asec/${INTERNAL_NAME:?}.apk"
171+
delete "/mnt/asec/${INTERNAL_NAME:?}"
172+
delete "/mnt/asec/${INTERNAL_NAME:?}"-*
169173
# ToDO => Check also /data/app-private /data/app-asec /data/preload
170174

171175
# App libs
@@ -179,6 +183,10 @@ uninstall_list | while IFS='|' read -r FILENAME INTERNAL_NAME _; do
179183
delete "${DATA_PATH:?}"/dalvik-cache/*/data@app@"${INTERNAL_NAME:?}"-*@classes*
180184
delete "${DATA_PATH:?}"/dalvik-cache/profiles/"${INTERNAL_NAME:?}"
181185

186+
# Package caches
187+
delete "${DATA_PATH:?}"/system/package_cache/*/"${INTERNAL_NAME:?}"-*
188+
delete "${DATA_PATH:?}"/system_ce/*/shortcut_service/packages/"${INTERNAL_NAME:?}"*
189+
182190
# Caches
183191
delete_folder_content_silent "${DATA_PATH:?}/data/${INTERNAL_NAME:?}/code_cache"
184192
delete_folder_content_silent "${DATA_PATH:?}/data/${INTERNAL_NAME:?}/cache"
@@ -216,12 +224,16 @@ done
216224
STATUS="$?"
217225
if test "${STATUS}" -ne 0; then exit "${STATUS}"; fi
218226

219-
list_app_data_to_remove | while IFS='|' read -r FILENAME; do
220-
if test -z "${FILENAME}"; then continue; fi
221-
delete "${DATA_PATH:?}/data/${FILENAME}"
222-
delete "${DATA_PATH:?}"/user/*/"${FILENAME}"
223-
delete "${DATA_PATH:?}"/user_de/*/"${FILENAME}"
224-
delete "${INTERNAL_MEMORY_PATH}/Android/data/${FILENAME}"
227+
list_app_data_to_remove | while IFS='|' read -r INTERNAL_NAME; do
228+
if test -z "${INTERNAL_NAME?}"; then continue; fi
229+
delete "${DATA_PATH:?}"/misc/profiles/ref/"${INTERNAL_NAME:?}"
230+
delete "${DATA_PATH:?}"/misc/profiles/cur/*/"${INTERNAL_NAME:?}"
231+
delete "${DATA_PATH:?}"/user_de/*/"${INTERNAL_NAME:?}"
232+
delete "${DATA_PATH:?}"/user/*/"${INTERNAL_NAME:?}"
233+
234+
delete "${DATA_PATH:?}"/data/"${INTERNAL_NAME:?}"
235+
delete "${DATA_PATH:?}"/media/*/Android/data/"${INTERNAL_NAME:?}"
236+
delete "${INTERNAL_MEMORY_PATH}"/Android/data/"${INTERNAL_NAME:?}"
225237
done
226238

227239
delete "${SYS_PATH:?}"/etc/default-permissions/google-sync-permissions.xml
@@ -230,6 +242,6 @@ delete "${SYS_PATH:?}"/etc/default-permissions/contacts-calendar-sync.xml
230242
# Legacy file
231243
delete "${SYS_PATH:?}/etc/zips/google-sync.prop"
232244

233-
if test -z "${IS_INCLUDED:?}"; then
245+
if test "${IS_INCLUDED:-false}" = 'false'; then
234246
ui_debug 'Done.'
235247
fi

0 commit comments

Comments
 (0)