· 6 years ago · Sep 27, 2019, 04:56 PM
1#This file is part of The Open GApps script of @mfonville.
2#
3# The Open GApps scripts are free software: you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation, either version 3 of the License, or
6# (at your option) any later version.
7#
8# These scripts are distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13makegprop(){
14 echo "# begin addon properties
15ro.addon.type=gapps
16ro.addon.arch=$ARCH
17ro.addon.sdk=$API
18ro.addon.platform=$PLATFORM
19ro.addon.open_type=$VARIANT
20ro.addon.open_version=$DATE
21# end addon properties" > "$build/$1"
22 EXTRACTFILES="$EXTRACTFILES $1"
23}
24
25makegappsremovetxt(){
26 gapps_remove=""
27 if [ "$API" -le "21" ] && [ "$GAPPSREMOVEVARIANT" = "super" ]; then
28 get_supported_variants "stock" # On 5.0 and lower the largest package is stock instead of super for the "regular" package-type
29 else
30 get_supported_variants "$GAPPSREMOVEVARIANT" # Retrieve the largest package of the package-type branch
31 fi
32 get_gapps_list "$supported_variants"
33 for gapp in $gapps_list; do
34 get_package_info "$gapp"
35 if [ -n "$packagetarget" ]; then
36 gapps_remove="/system/$packagetarget$REMOVALSUFFIX
37$gapps_remove"
38 fi
39 for lib in $packagelibs; do
40 systemlibpath=""
41 getpathsystemlib "$lib"
42 for libpath in $systemlibpath; do
43 gapps_remove="/system/$libpath
44$gapps_remove"
45 done
46 done
47 for file in $packagefiles; do
48 gapps_remove="/system/$file
49$gapps_remove"
50 done
51 for extraline in $packagegappsremove; do
52 gapps_remove="/system/$extraline
53$gapps_remove"
54 done
55 done
56 printf "%s" "$gapps_remove" | sort -u > "$build/$1" # make unique for the VRmode entries
57 EXTRACTFILES="$EXTRACTFILES $1"
58}
59
60makeupdatebinary(){
61 echo '#!/sbin/sh
62#This file is part of The Open GApps script of @mfonville.
63#
64# The Open GApps scripts are free software: you can redistribute it and/or modify
65# it under the terms of the GNU General Public License as published by
66# the Free Software Foundation, either version 3 of the License, or
67# (at your option) any later version, w/Open GApps installable zip exception.
68#
69# These scripts are distributed in the hope that it will be useful,
70# but WITHOUT ANY WARRANTY; without even the implied warranty of
71# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
72# GNU General Public License for more details.
73#
74# This Open GApps installer-runtime is because of the Open GApps installable
75# zip exception de-facto LGPLv3 licensed.
76#
77export OPENGAZIP="$3"
78export OUTFD="/proc/self/fd/$2"
79export TMP="/tmp"
80case "$(uname -m)" in
81 *86*) export BINARCH="x86";; # e.g. Zenfone is i686
82 *ar*) export BINARCH="arm";; # i.e. armv7l and aarch64
83esac
84bb="$TMP/'"$2"'-$BINARCH"
85l="$TMP/bin"
86setenforce 0
87for f in '"$4"'; do
88 unzip -o "$OPENGAZIP" "$f" -d "$TMP";
89done
90for f in '"$5"'; do
91 chmod +x "$TMP/$f";
92done
93if [ -e "$bb" ]; then
94 install -d "$l"
95 for i in $($bb --list); do
96 if ! ln -sf "$bb" "$l/$i" && ! $bb ln -sf "$bb" "$l/$i" && ! $bb ln -f "$bb" "$l/$i" ; then
97 # create script wrapper if symlinking and hardlinking failed because of restrictive selinux policy
98 if ! echo "#!$bb" > "$l/$i" || ! chmod +x "$l/$i" ; then
99 echo "ui_print ERROR 10: Failed to set-up Open GApps'"'"' pre-bundled '"$2"'" > "$OUTFD"
100 echo "ui_print" > "$OUTFD"
101 echo "ui_print Please use TWRP as recovery instead" > "$OUTFD"
102 echo "ui_print" > "$OUTFD"
103 exit 1
104 fi
105 fi
106 done
107 PATH="$l:$PATH" $bb ash "$TMP/'"$3"'" "$@"
108 exit "$?"
109else
110 echo "ui_print ERROR 64: Wrong architecture to set-up Open GApps'"'"' pre-bundled '"$2"'" > "$OUTFD"
111 echo "ui_print" > "$OUTFD"
112 exit 1
113fi'> "$build/$1"
114}
115
116makeinstallersh(){
117EXTRACTFILES="$EXTRACTFILES $1"
118echo '#!/sbin/ash
119#This file is part of The Open GApps script of @mfonville.
120#
121# The Open GApps scripts are free software: you can redistribute it and/or modify
122# it under the terms of the GNU General Public License as published by
123# the Free Software Foundation, either version 3 of the License, or
124# (at your option) any later version, w/Open GApps installable zip exception.
125#
126# These scripts are distributed in the hope that it will be useful,
127# but WITHOUT ANY WARRANTY; without even the implied warranty of
128# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
129# GNU General Public License for more details.
130#
131# This Open GApps installer-runtime is because of the Open GApps installable
132# zip exception de-facto LGPLv3 licensed.
133#
134# This script of the Open GApps Installer is contains work from the PA GApps of @TKruzze and @osm0sis,
135# PA GApps source is used with permission, under the license that it may be re-used to continue GApps packages.
136#
137# Last Updated: '"$DATE"'
138# _____________________________________________________________________________________________________________________
139# Define Current Package Variables
140# List of GApps packages that can be installed with this installer
141pkg_names="'"$SUPPORTEDVARIANTS"'";
142
143# Installer Name (32 chars Total, excluding "")
144installer_name="Open GApps '"$VARIANT"' '"$PLATFORM"' - ";
145
146req_android_arch="'"$ARCH"'";
147req_android_sdk="'"$API"'";
148req_android_version="'"$PLATFORM"'";
149
150'"$KEYBDLIBS"'
151faceLock_lib_filename="'"$FACELOCKLIB"'";
152atvremote_lib_filename="libatv_uinputbridge.so"
153WebView_lib_filename="libwebviewchromium.so"
154markup_lib_filename="libsketchology_native.so"
155
156# Buffer of extra system space to require for GApps install (9216=9MB)
157# This will allow for some ROM size expansion when GApps are restored
158buffer_size_kb=9216; small_buffer_size=2048;
159
160# List of GApps files that should NOT be automatically removed as they are also included in (many) ROMs
161removal_bypass_list="'"$REMOVALBYPASS"'
162";
163
164# Define exit codes (returned upon exit due to an error)
165E_ROMVER=20; # Wrong ROM version
166E_NOBUILDPROP=25; #No build.prop or equivalent
167E_RECCOMPR=30; # Recovery without transparent compression
168E_NOSPACE=70; # Insufficient Space Available in System Partition
169E_NONOPEN=40; # NON Open GApps Currently Installed
170E_ARCH=64; # Wrong Architecture Detected
171#_________________________________________________________________________________________________________________
172# GApps List (Applications user can Select/Deselect)
173core_gapps_list="
174'"$gappscore"'
175";
176
177super_gapps_list="
178'"$gappssuper"'
179";
180
181stock_gapps_list="
182'"$gappsstock"'
183";
184
185full_gapps_list="
186'"$gappsfull"'
187";
188
189mini_gapps_list="
190'"$gappsmini"'
191";
192
193micro_gapps_list="
194'"$gappsmicro"'
195";
196
197nano_gapps_list="
198'"$gappsnano"'
199";
200
201pico_gapps_list="
202'"$gappspico"'
203";
204
205tvcore_gapps_list="
206'"$gappstvcore"'
207";
208
209tvstock_gapps_list="
210'"$gappstvstock"'
211";
212
213# _____________________________________________________________________________________________________________________
214# Default Stock/AOSP Removal List (Stock GApps Only)
215default_stock_remove_list="
216'"$stockremove"'
217";
218# _____________________________________________________________________________________________________________________
219# Optional Stock/AOSP/ROM Removal List
220optional_aosp_remove_list="
221boxer
222basicdreams
223calculatorstock
224calendarstock
225clockstock
226cmaudiofx
227cmaccount
228cmbugreport
229cmfilemanager
230cmmusic
231cmscreencast
232cmsetupwizard
233cmupdater
234cmwallpapers
235cmweatherprovider
236dashclock
237exchangestock
238extservicesstock
239extsharedstock
240fmradio
241galaxy
242hexo
243holospiral
244keyboardstock
245lbr0zip
246livewallpapers
247lockclock
248logcat
249lrecorder
250lsetupwizard
251lupdater
252mms
253mzfilemanager
254mzpay
255mzsetupwizard
256mzupdater
257mzweather
258noisefield
259omniswitch
260phasebeam
261photophase
262phototable
263printservicestock
264provision
265simtoolkit
266soundrecorder
267storagemanagerstock
268studio
269sykopath
270tagstock
271terminal
272themes
273visualizationwallpapers
274wallpapersstock
275whisperpush
276";
277# _____________________________________________________________________________________________________________________
278# Stock/AOSP/ROM File Removal Lists
279boxer_list="
280vendor/bundled-app/Boxer'"$REMOVALSUFFIX"'"
281
282browser_list="
283app/Bolt'"$REMOVALSUFFIX"'
284app/Browser'"$REMOVALSUFFIX"'
285app/Browser2'"$REMOVALSUFFIX"'
286app/BrowserIntl'"$REMOVALSUFFIX"'
287app/BrowserProviderProxy'"$REMOVALSUFFIX"'
288app/Chromium'"$REMOVALSUFFIX"'
289app/Fluxion'"$REMOVALSUFFIX"'
290app/Gello'"$REMOVALSUFFIX"'
291app/Jelly'"$REMOVALSUFFIX"'
292app/PA_Browser'"$REMOVALSUFFIX"'
293app/PABrowser'"$REMOVALSUFFIX"'
294app/YuBrowser'"$REMOVALSUFFIX"'
295priv-app/BLUOpera'"$REMOVALSUFFIX"'
296priv-app/BLUOperaPreinstall'"$REMOVALSUFFIX"'
297priv-app/Browser'"$REMOVALSUFFIX"'
298priv-app/BrowserIntl'"$REMOVALSUFFIX"'"
299
300basicdreams_list="
301app/BasicDreams'"$REMOVALSUFFIX"'"
302
303# Must be used when GoogleCalculator is installed
304calculatorstock_list="
305app/Calculator'"$REMOVALSUFFIX"'
306app/ExactCalculator'"$REMOVALSUFFIX"'
307app/FineOSCalculator'"$REMOVALSUFFIX"'"
308
309# Must be used when GoogleCalendar is installed
310calendarstock_list="
311app/Calendar'"$REMOVALSUFFIX"'
312app/MonthCalendarWidget'"$REMOVALSUFFIX"'
313priv-app/Calendar'"$REMOVALSUFFIX"'
314app/FineOSCalendar'"$REMOVALSUFFIX"'"
315
316# Must be used when GoogleCamera is installed
317camerastock_list="
318app/Camera'"$REMOVALSUFFIX"'
319app/Camera2'"$REMOVALSUFFIX"'
320priv-app/Camera'"$REMOVALSUFFIX"'
321priv-app/Camera2'"$REMOVALSUFFIX"'
322priv-app/CameraX'"$REMOVALSUFFIX"'
323app/MotCamera'"$REMOVALSUFFIX"'
324app/MtkCamera'"$REMOVALSUFFIX"'
325app/MTKCamera'"$REMOVALSUFFIX"'
326priv-app/MotCamera'"$REMOVALSUFFIX"'
327priv-app/MiuiCamera'"$REMOVALSUFFIX"'
328priv-app/MtkCamera'"$REMOVALSUFFIX"'
329priv-app/MTKCamera'"$REMOVALSUFFIX"'
330app/Snap'"$REMOVALSUFFIX"'
331priv-app/Snap'"$REMOVALSUFFIX"'
332app/SnapdragonCamera'"$REMOVALSUFFIX"'
333priv-app/SnapdragonCamera'"$REMOVALSUFFIX"'
334app/FineOSCamera'"$REMOVALSUFFIX"'"
335
336clockstock_list="
337app/DeskClock'"$REMOVALSUFFIX"'
338app/DeskClock2'"$REMOVALSUFFIX"'
339app/FineOSDeskClock'"$REMOVALSUFFIX"'
340app/OmniClockOSS'"$REMOVALSUFFIX"'"
341
342cmaccount_list="
343priv-app/CMAccount'"$REMOVALSUFFIX"'"
344
345cmaudiofx_list="
346priv-app/AudioFX'"$REMOVALSUFFIX"'"
347
348cmbugreport_list="
349priv-app/CMBugReport'"$REMOVALSUFFIX"'"
350
351cmfilemanager_list="
352app/CMFileManager'"$REMOVALSUFFIX"'"
353
354cmmusic_list="
355app/Apollo'"$REMOVALSUFFIX"'
356app/Eleven'"$REMOVALSUFFIX"'
357priv-app/Eleven'"$REMOVALSUFFIX"'
358app/Music'"$REMOVALSUFFIX"'
359app/MusicX'"$REMOVALSUFFIX"'
360app/Phonograph'"$REMOVALSUFFIX"'
361app/SnapdragonMusic'"$REMOVALSUFFIX"'"
362
363cmscreencast_list="
364priv-app/Screencast'"$REMOVALSUFFIX"'"
365
366cmsetupwizard_list="
367app/CyanogenSetupWizard'"$REMOVALSUFFIX"'
368priv-app/CyanogenSetupWizard'"$REMOVALSUFFIX"'"
369
370cmupdater_list="
371priv-app/CMUpdater'"$REMOVALSUFFIX"'"
372
373cmwallpapers_list="
374app/CMWallpapers'"$REMOVALSUFFIX"'"
375
376cmweatherprovider_list="
377priv-app/WeatherProvider'"$REMOVALSUFFIX"'"
378
379# Must be used when Google Contacts is installed
380contactsstock_list="
381priv-app/Contacts'"$REMOVALSUFFIX"'
382priv-app/FineOSContacts'"$REMOVALSUFFIX"'"
383
384dashclock_list="
385app/DashClock'"$REMOVALSUFFIX"'"
386
387# Must be used when Google Dialer is installed
388# For now, prevent stock AOSP Dialer (priv-app/Dialer) from being removed, no matter the configuration, on all ROMs
389dialerstock_list="
390priv-app/FineOSDialer'"$REMOVALSUFFIX"'
391priv-app/OPInCallUI'"$REMOVALSUFFIX"'"
392
393email_list="
394app/Email'"$REMOVALSUFFIX"'
395app/PrebuiltEmailGoogle'"$REMOVALSUFFIX"'
396priv-app/Email'"$REMOVALSUFFIX"'"
397
398exchangestock_list="
399app/Exchange2'"$REMOVALSUFFIX"'
400priv-app/Exchange2'"$REMOVALSUFFIX"'"
401
402extservicesstock_list="
403priv-app/ExtServices'"$REMOVALSUFFIX"'"
404
405extsharedstock_list="
406app/ExtShared'"$REMOVALSUFFIX"'"
407
408fmradio_list="
409app/FM'"$REMOVALSUFFIX"'
410app/FM2'"$REMOVALSUFFIX"'
411app/FMRecord'"$REMOVALSUFFIX"'
412priv-app/FMRadio'"$REMOVALSUFFIX"'
413priv-app/MiuiRadio'"$REMOVALSUFFIX"'"
414
415galaxy_list="
416app/Galaxy4'"$REMOVALSUFFIX"'"
417
418gallery_list="
419app/Gallery'"$REMOVALSUFFIX"'
420priv-app/Gallery'"$REMOVALSUFFIX"'
421priv-app/GalleryX'"$REMOVALSUFFIX"'
422app/Gallery2'"$REMOVALSUFFIX"'
423priv-app/Gallery2'"$REMOVALSUFFIX"'
424app/MotGallery'"$REMOVALSUFFIX"'
425priv-app/MotGallery'"$REMOVALSUFFIX"'
426app/MediaShortcuts'"$REMOVALSUFFIX"'
427priv-app/MediaShortcuts'"$REMOVALSUFFIX"'
428priv-app/MiuiGallery'"$REMOVALSUFFIX"'
429priv-app/FineOSGallery'"$REMOVALSUFFIX"'
430priv-app/SnapdragonGallery'"$REMOVALSUFFIX"'"
431
432hexo_list="
433app/HexoLibre'"$REMOVALSUFFIX"'"
434
435holospiral_list="
436app/HoloSpiralWallpaper'"$REMOVALSUFFIX"'"
437
438# Must be used when GoogleKeyboard is installed
439keyboardstock_list="
440app/LatinIME'"$REMOVALSUFFIX"'
441app/MzInput'"$REMOVALSUFFIX"'
442app/OpenWnn'"$REMOVALSUFFIX"'
443priv-app/BLUTouchPal'"$REMOVALSUFFIX"'
444priv-app/BLUTouchPalPortuguesebrPack'"$REMOVALSUFFIX"'
445priv-app/BLUTouchPalSpanishLatinPack'"$REMOVALSUFFIX"'
446priv-app/MzInput'"$REMOVALSUFFIX"'"
447
448launcher_list="
449app/CMHome'"$REMOVALSUFFIX"'
450app/CustomLauncher3'"$REMOVALSUFFIX"'
451app/EasyLauncher'"$REMOVALSUFFIX"'
452app/Fluctuation'"$REMOVALSUFFIX"'
453app/FlymeLauncher'"$REMOVALSUFFIX"'
454app/FlymeLauncherIntl'"$REMOVALSUFFIX"'
455app/Launcher2'"$REMOVALSUFFIX"'
456app/Launcher3'"$REMOVALSUFFIX"'
457app/LiquidLauncher'"$REMOVALSUFFIX"'
458app/Paclauncher'"$REMOVALSUFFIX"'
459app/SlimLauncher'"$REMOVALSUFFIX"'
460app/Trebuchet'"$REMOVALSUFFIX"'
461app/FineOSHome'"$REMOVALSUFFIX"'
462priv-app/CMHome'"$REMOVALSUFFIX"'
463priv-app/CustomLauncher3'"$REMOVALSUFFIX"'
464priv-app/EasyLauncher'"$REMOVALSUFFIX"'
465priv-app/Fluctuation'"$REMOVALSUFFIX"'
466priv-app/FlymeLauncher'"$REMOVALSUFFIX"'
467priv-app/FlymeLauncherIntl'"$REMOVALSUFFIX"'
468priv-app/Launcher2'"$REMOVALSUFFIX"'
469priv-app/Launcher3'"$REMOVALSUFFIX"'
470priv-app/LiquidLauncher'"$REMOVALSUFFIX"'
471priv-app/MiuiHome'"$REMOVALSUFFIX"'
472priv-app/Paclauncher'"$REMOVALSUFFIX"'
473priv-app/SlimLauncher'"$REMOVALSUFFIX"'
474priv-app/Trebuchet'"$REMOVALSUFFIX"'
475priv-app/Nox'"$REMOVALSUFFIX"'"
476
477lbr0zip_list="
478app/Br0Zip'"$REMOVALSUFFIX"'"
479
480livewallpapers_list="
481app/LiveWallpapers'"$REMOVALSUFFIX"'"
482
483lockclock_list="
484app/LockClock'"$REMOVALSUFFIX"'"
485
486logcat_list="
487priv-app/MatLog'"$REMOVALSUFFIX"'"
488
489lrecorder_list="
490priv-app/Recorder'"$REMOVALSUFFIX"'"
491
492lsetupwizard_list="
493app/LineageSetupWizard'"$REMOVALSUFFIX"'
494priv-app/LineageSetupWizard'"$REMOVALSUFFIX"'"
495
496lupdater_list="
497priv-app/Updater'"$REMOVALSUFFIX"'"
498
499mms_list="
500app/messaging'"$REMOVALSUFFIX"'
501priv-app/Mms'"$REMOVALSUFFIX"'
502priv-app/FineOSMms'"$REMOVALSUFFIX"'"
503
504mzfilemanager_list="
505app/FileManager'"$REMOVALSUFFIX"'"
506
507mzpay_list="
508app/MzMPay'"$REMOVALSUFFIX"'
509app/MzPay'"$REMOVALSUFFIX"'"
510
511mzsetupwizard_list="
512app/MzSetupWizard'"$REMOVALSUFFIX"'"
513
514mzupdater_list="
515app/MzUpdate'"$REMOVALSUFFIX"'
516app/SystemUpdate'"$REMOVALSUFFIX"'
517app/SystemUpdateAssistant'"$REMOVALSUFFIX"'"
518
519mzweather_list="
520app/Weather'"$REMOVALSUFFIX"'"
521
522noisefield_list="
523app/NoiseField'"$REMOVALSUFFIX"'"
524
525omniswitch_list="
526priv-app/OmniSwitch'"$REMOVALSUFFIX"'"
527
528# Must be used when Google PackageInstaller is installed; non-capitalized spelling on Lenovo K3 Note
529packageinstallerstock_list="
530app/PackageInstaller'"$REMOVALSUFFIX"'
531priv-app/PackageInstaller'"$REMOVALSUFFIX"'
532priv-app/packageinstaller'"$REMOVALSUFFIX"'"
533
534phasebeam_list="
535app/PhaseBeam'"$REMOVALSUFFIX"'"
536
537photophase_list="
538app/PhotoPhase'"$REMOVALSUFFIX"'"
539
540phototable_list="
541app/PhotoTable'"$REMOVALSUFFIX"'"
542
543picotts_list="
544app/PicoTts'"$REMOVALSUFFIX"'
545priv-app/PicoTts'"$REMOVALSUFFIX"'
546lib/libttscompat.so
547lib/libttspico.so
548tts"
549
550printservicestock_list="
551app/BuiltInPrintService'"$REMOVALSUFFIX"'
552app/PrintRecommendationService'"$REMOVALSUFFIX"'"
553
554provision_list="
555app/Provision'"$REMOVALSUFFIX"'
556priv-app/Provision'"$REMOVALSUFFIX"'"
557
558simtoolkit_list="
559app/Stk'"$REMOVALSUFFIX"'"
560
561soundrecorder_list="
562app/SoundRecorder'"$REMOVALSUFFIX"'"
563
564storagemanagerstock_list="
565priv-app/StorageManager'"$REMOVALSUFFIX"'"
566
567studio_list="
568app/VideoEditor'"$REMOVALSUFFIX"'"
569
570sykopath_list="
571app/Layers'"$REMOVALSUFFIX"'"
572
573tagstock_list="
574priv-app/Tag'"$REMOVALSUFFIX"'"
575
576terminal_list="
577app/Terminal'"$REMOVALSUFFIX"'"
578
579themes_list="
580priv-app/CustomizeCenter'"$REMOVALSUFFIX"'
581priv-app/ThemeChooser'"$REMOVALSUFFIX"'
582priv-app/ThemesProvider'"$REMOVALSUFFIX"'"
583
584visualizationwallpapers_list="
585app/VisualizationWallpapers'"$REMOVALSUFFIX"'"
586
587wallpapersstock_list="
588app/WallpaperPicker'"$REMOVALSUFFIX"'"
589
590webviewstock_list="
591app/webview'"$REMOVALSUFFIX"'
592app/WebView'"$REMOVALSUFFIX"'
593'"$webviewstocklibs"'"
594
595whisperpush_list="
596app/WhisperPush'"$REMOVALSUFFIX"'"
597# _____________________________________________________________________________________________________________________
598# Permanently Removed Folders
599# Pieces that may be left over from AIO ROMs that can/will interfere with these GApps
600other_list="
601app/BooksStub'"$REMOVALSUFFIX"'
602app/BookmarkProvider'"$REMOVALSUFFIX"'
603app/CalendarGoogle'"$REMOVALSUFFIX"'
604app/CloudPrint'"$REMOVALSUFFIX"'
605app/DeskClockGoogle'"$REMOVALSUFFIX"'
606app/EditorsDocsStub'"$REMOVALSUFFIX"'
607app/EditorsSheetsStub'"$REMOVALSUFFIX"'
608app/EditorsSlidesStub'"$REMOVALSUFFIX"'
609app/Gmail'"$REMOVALSUFFIX"'
610app/Gmail2'"$REMOVALSUFFIX"'
611app/GoogleCalendar'"$REMOVALSUFFIX"'
612app/GoogleCloudPrint'"$REMOVALSUFFIX"'
613app/GoogleHangouts'"$REMOVALSUFFIX"'
614app/GoogleKeep'"$REMOVALSUFFIX"'
615app/GoogleLatinIme'"$REMOVALSUFFIX"'
616app/Keep'"$REMOVALSUFFIX"'
617app/NewsstandStub'"$REMOVALSUFFIX"'
618app/PartnerBookmarksProvider'"$REMOVALSUFFIX"'
619app/PrebuiltBugleStub'"$REMOVALSUFFIX"'
620app/PrebuiltKeepStub'"$REMOVALSUFFIX"'
621app/QuickSearchBox'"$REMOVALSUFFIX"'
622app/Vending'"$REMOVALSUFFIX"'
623priv-app/GmsCore'"$REMOVALSUFFIX"'
624priv-app/GoogleNow'"$REMOVALSUFFIX"'
625priv-app/GoogleSearch'"$REMOVALSUFFIX"'
626priv-app/GoogleHangouts'"$REMOVALSUFFIX"'
627priv-app/OneTimeInitializer'"$REMOVALSUFFIX"'
628priv-app/QuickSearchBox'"$REMOVALSUFFIX"'
629priv-app/Vending'"$REMOVALSUFFIX"'
630priv-app/Velvet_update'"$REMOVALSUFFIX"'
631priv-app/GmsCore_update'"$REMOVALSUFFIX"'
632";
633
634# Apps from app that need to be installed in priv-app
635privapp_list="
636app/CanvasPackageInstaller'"$REMOVALSUFFIX"'
637app/ConfigUpdater'"$REMOVALSUFFIX"'
638app/GoogleBackupTransport'"$REMOVALSUFFIX"'
639app/GoogleFeedback'"$REMOVALSUFFIX"'
640app/GoogleLoginService'"$REMOVALSUFFIX"'
641app/GoogleOneTimeInitializer'"$REMOVALSUFFIX"'
642app/GooglePartnerSetup'"$REMOVALSUFFIX"'
643app/GoogleServicesFramework'"$REMOVALSUFFIX"'
644app/OneTimeInitializer'"$REMOVALSUFFIX"'
645app/Phonesky'"$REMOVALSUFFIX"'
646app/PrebuiltGmsCore'"$REMOVALSUFFIX"'
647app/SetupWizard'"$REMOVALSUFFIX"'
648app/Velvet'"$REMOVALSUFFIX"'
649";
650
651# Stock/AOSP Keyboard lib (and symlink) that are always removed since they are always replaced
652reqd_list="
653'"$REQDLIST"'
654";
655
656# Remove from priv-app since it was moved to app and vice-versa or other path changes
657obsolete_list="
658app/CalculatorGoogle
659priv-app/GoogleHome'"$REMOVALSUFFIX"'
660priv-app/Hangouts'"$REMOVALSUFFIX"'
661priv-app/PrebuiltExchange3Google'"$REMOVALSUFFIX"'
662priv-app/talkback'"$REMOVALSUFFIX"'
663priv-app/Wallet'"$REMOVALSUFFIX"'
664";
665
666# Old addon.d backup scripts as we will be replacing with updated version during install
667oldscript_list="
668etc/g.prop
669addon.d/70-gapps.sh
670";' >> "$build/$1"
671tee -a "$build/$1" > /dev/null <<'EOFILE'
672
673remove_list="${other_list}${privapp_list}${reqd_list}${obsolete_list}${oldscript_list}";
674# _____________________________________________________________________________________________________________________
675# Installer Error Messages
676arch_compat_msg="INSTALLATION FAILURE: This Open GApps package cannot be installed on this\ndevice's architecture. Please download the correct version for your device.\n";
677camera_sys_msg="WARNING: Google Camera has/will not be installed as requested. Google Camera\ncan only be installed during a Clean Install or as an update to an existing\nGApps Installation.\n";
678camera_compat_msg="WARNING: Google Camera has/will not be installed as requested. Google Camera\nis NOT compatible with your device if installed on the system partition. Try\ninstalling from the Play Store instead.\n";
679cmcompatibility_msg="WARNING: PackageInstallerGoogle is not installed. Cyanogenmod is NOT\ncompatible with some Google Applications and Open GApps\n will skip their installation.\n";
680dialergoogle_msg="WARNING: Google Dialer has/will not be installed as requested. Dialer Framework\nmust be added to the GApps installation if you want to install the\nGoogle Dialer.\n";
681faceunlock_msg="NOTE: FaceUnlock can only be installed on devices with a front facing camera.\n";
682googlenow_msg="WARNING: Google Now Launcher has/will not be installed as requested. Google Search\nmust be added to the GApps installation if you want to install the\nGoogle Now Launcher.\n";
683messenger_msg="WARNING: Google Messages has/will not be installed as requested. Carrier Services\nmust be added to the GApps installation on Android 6.0+ if you want to install\nGoogle Messages.\n";
684pixellauncher_msg="WARNING: Pixel Launcher has/will not be installed as requested. Wallpapers and\nGoogle Search must be added to the GApps installation if you want to install\nthe Pixel Launcher.\n";
685projectfi_msg="WARNING: Project Fi has/will not be installed as requested. GCS must be\nadded to the GApps installation if you want to install the Project Fi app.\n";
686nobuildprop="INSTALLATION FAILURE: The installed ROM has no build.prop or equivalent\n";
687nokeyboard_msg="NOTE: The Stock/AOSP keyboard was NOT removed as requested to ensure your device\nwas not accidentally left with no keyboard installed. If this was intentional,\nyou can add 'Override' to your gapps-config to override this protection.\n";
688nolauncher_msg="NOTE: The Stock/AOSP Launcher was NOT removed as requested to ensure your device\nwas not accidentally left with no Launcher. If this was your intention, you can\nadd 'Override' to your gapps-config to override this protection.\n";
689nomms_msg="NOTE: The Stock/AOSP MMS app was NOT removed as requested to ensure your device\nwas not accidentally left with no way to receive text messages. If this WAS\nintentional, add 'Override' to your gapps-config to override this protection.\n";
690nowebview_msg="NOTE: The Stock/AOSP WebView was NOT removed as requested to ensure your device\nwas not accidentally left with no WebViewProvider installed. If this was intentional,\nyou can add 'Override' to your gapps-config to override this protection.\n";
691non_open_gapps_msg="INSTALLATION FAILURE: Open GApps can only be installed on top of an existing\nOpen GApps installation. Since you are currently using another GApps package, you\nwill need to wipe (format) your system partition before installing Open GApps.\n";
692fornexus_open_gapps_msg="NOTE: The installer detected that you already have Stock ROM GApps installed.\nThe installer will now continue, but please be aware that there could be problems.\n";
693recovery_compression_msg="INSTALLATION FAILURE: Your ROM uses transparent compression, but your recovery\ndoes not support this feature, resulting in corrupt files.\nPlease update your recovery before flashing ANY package to prevent corruption.\n";
694rom_android_version_msg="INSTALLATION FAILURE: This GApps package can only be installed on a $req_android_version.x ROM.\n";
695simulation_msg="TEST INSTALL: This was only a simulated install. NO CHANGES WERE MADE TO YOUR\nDEVICE. To complete the installation remove 'Test' from your gapps-config.\n";
696stubwebview_msg="NOTE: Stub WebView was installed instead of Google WebView because your device\nhas already Chrome installed as WebViewProvider. If you still want Google WebView,\nyou can add 'Override' to your gapps-config to override this redundancy protection.\n";
697system_space_msg="INSTALLATION FAILURE: Your device does not have sufficient space available in\nthe system partition to install this GApps package as currently configured.\nYou will need to switch to a smaller GApps package or use gapps-config to\nreduce the installed size.\n";
698user_multiplefound_msg="NOTE: All User Application Removals included in gapps-config were unable to be\nprocessed as requested because multiple versions of the app were found on your\ndevice. See the log portion below for the name(s) of the application(s).\n";
699user_notfound_msg="NOTE: All User Application Removals included in gapps-config were unable to be\nremoved as requested because the files were not found on your device. See the\nlog portion below for the name(s) of the application(s).\n";
700vrservice_compat_msg="WARNING: Google VR Services has/will not be installed as requested.\nGoogle VR Services is NOT compatible with your device.\n";
701del_conflict_msg="!!! WARNING !!! - Duplicate files were found between your ROM and this GApps\npackage. This is likely due to your ROM's dev including Google proprietary\nfiles in the ROM. The duplicate files are shown in the log portion below.\n";
702
703nogooglecontacts_removal_msg="NOTE: The Stock/AOSP Contacts is not available on your\nROM (anymore), the Google equivalent will not be removed."
704nogoogledialer_removal_msg="NOTE: The Stock/AOSP Dialer is not available on your\nROM (anymore), the Google equivalent will not be removed."
705nogooglekeyboard_removal_msg="NOTE: The Stock/AOSP Keyboard is not available on your\nROM (anymore), the Google equivalent will not be removed."
706nogooglepackageinstaller_removal_msg="NOTE: The Stock/AOSP Package Installer is not\navailable on your ROM (anymore), the Google equivalent will not be removed."
707nogoogletag_removal_msg="NOTE: The Stock/AOSP NFC Tag is not available on your\nROM (anymore), the Google equivalent will not be removed."
708nogooglewebview_removal_msg="NOTE: The Stock/AOSP WebView is not available on your\nROM (anymore), not all Google WebViewProviders will be removed."
709
710# _____________________________________________________________________________________________________________________
711# Detect A/B partition layout https://source.android.com/devices/tech/ota/ab_updates
712# and system-as-root https://source.android.com/devices/bootloader/system-as-root
713system_as_root=`getprop ro.build.system_root_image`
714if [ "$system_as_root" == "true" ]; then
715 active_slot=`getprop ro.boot.slot_suffix`
716 if [ ! -z "$active_slot" ]; then
717 device_abpartition=true
718 block=/dev/block/bootdevice/by-name/system$active_slot
719 else
720 device_abpartition=false
721 block=/dev/block/bootdevice/by-name/system
722 fi
723 mkdir -p /system_root
724 SYSTEM_MOUNT=/system_root
725 SYSTEM=$SYSTEM_MOUNT/system
726else
727 # Try to get the block from /etc/recovery.fstab
728 block=`cat /etc/recovery.fstab | cut -d '#' -f 1 | grep /system | grep -o '/dev/[^ ]*' | head -1`
729
730 device_abpartition=false
731 SYSTEM_MOUNT=/system
732 SYSTEM=$SYSTEM_MOUNT
733fi
734
735# _____________________________________________________________________________________________________________________
736# Declare Variables
737zip_folder="$(dirname "$OPENGAZIP")";
738g_prop=$SYSTEM/etc/g.prop
739PROPFILES="$g_prop $SYSTEM/default.prop $SYSTEM/build.prop /vendor/build.prop /data/local.prop /default.prop /build.prop"
740bkup_tail=$TMP/bkup_tail.sh;
741gapps_removal_list=$TMP/gapps-remove.txt;
742g_log=$TMP/g.log;
743calc_log=$TMP/calc.log;
744conflicts_log=$TMP/conflicts.log;
745rec_cache_log=/cache/recovery/log;
746rec_tmp_log=$TMP/recovery.log;
747user_remove_notfound_log=$TMP/user_remove_notfound.log;
748user_remove_multiplefound_log=$TMP/user_remove_multiplefound.log;
749
750log_close="# End Open GApps Install Log\n";
751
752reclaimed_gapps_space_kb=0;
753reclaimed_removal_space_kb=0;
754reclaimed_aosp_space_kb=0;
755total_install_size_kb=0;
756# _____________________________________________________________________________________________________________________
757# Define Functions
758abort() {
759 quit;
760 ui_print "- NO changes were made to your device";
761 ui_print " ";
762 ui_print "Installer will now exit...";
763 ui_print " ";
764 ui_print "Error Code: $1";
765 sleep 5;
766 exxit "$1";
767}
768
769ch_con() {
770 chcon -h u:object_r:system_file:s0 "$1";
771}
772
773checkmanifest() {
774 if [ -f "$1" ] && ("$TMP/unzip-$BINARCH" -ql "$1" | grep -q "META-INF/MANIFEST.MF"); then # strict, only files
775 "$TMP/unzip-$BINARCH" -p "$1" "META-INF/MANIFEST.MF" | grep -q "$2"
776 return "$?"
777 else
778 return 0
779 fi
780}
781
782complete_gapps_list() {
783 cat <<EOF
784$full_removal_list
785EOF
786}
787
788contains() {
789 case "$1" in
790 *"$2"*) return 0;;
791 *) return 1;;
792 esac;
793}
794
795clean_inst() {
796 if [ -f /data/system/packages.xml ] && [ "$forceclean" != "true" ]; then
797 return 1;
798 fi;
799 return 0;
800}
801
802exists_in_zip(){
803 "$TMP/unzip-$BINARCH" -l "$OPENGAZIP" "$1" | grep -q "$1"
804 return $?
805}
806
807extract_app() {
808 tarpath="$TMP/$1.tar" # NB no suffix specified here
809 if "$TMP/unzip-$BINARCH" -o "$OPENGAZIP" "$1.tar*" -d "$TMP"; then # wildcard for suffix
810 app_name="$(basename "$1")"
811 which_dpi "$app_name"
812 echo "Found $1 DPI path: $dpiapkpath"
813 folder_extract "$tarpath" "$dpiapkpath" "$app_name/common"
814 else
815 echo "Failed to extract $1.tar* from $OPENGAZIP"
816 fi
817}
818
819exxit() {
820 set_progress 0.98
821 if [ "$skipvendorlibs" = "true" ]; then
822 umount $SYSTEM_MOUNT/vendor # unmount tmpfs
823 fi
824 if ( ! grep -qiE '^ *nodebug *($|#)+' "$g_conf" ); then
825 if [ "$g_conf" ]; then # copy gapps-config files to debug logs folder
826 cp -f "$g_conf_orig" "$TMP/logs/gapps-config_original.txt"
827 cp -f "$g_conf" "$TMP/logs/gapps-config_processed.txt"
828 fi
829 ls -alZR $SYSTEM > "$TMP/logs/System_Files_After.txt"
830 df -k > "$TMP/logs/Device_Space_After.txt"
831 cp -f "$log_folder/open_gapps_log.txt" "$TMP/logs"
832 for f in $PROPFILES; do
833 cp -f "$f" "$TMP/logs"
834 done
835 cp -f "$SYSTEM/addon.d/70-gapps.sh" "$TMP/logs"
836 cp -f "$gapps_removal_list" "$TMP/logs/gapps-remove_revised.txt"
837 cp -f "$rec_cache_log" "$TMP/logs/Recovery_cache.log"
838 cp -f "$rec_tmp_log" "$TMP/logs/Recovery_tmp.log"
839 curLD="$LD_LIBRARY_PATH"
840 unset LD_LIBRARY_PATH
841 logcat -d -f "$TMP/logs/logcat"
842 export LD_LIBRARY_PATH="$curLD"
843 cd "$TMP"
844 tar -cz -f "$log_folder/open_gapps_debug_logs.tar.gz" logs/*
845 cd /
846 fi
847 find $TMP/* -maxdepth 0 ! -path "$rec_tmp_log" -exec rm -rf {} +
848 set_progress 1.0
849 ui_print "- Unmounting $mounts"
850 ui_print " "
851 for m in $mounts; do
852 case $m in
853 $SYSTEM_MOUNT)
854 if [ "$device_abpartition" = "true" ]; then
855 mount -o ro $SYSTEM_MOUNT
856 else
857 umount $SYSTEM_MOUNT
858 fi;;
859 *) umount "$m";;
860 esac
861 done
862 exit "$1"
863}
864
865folder_extract() {
866 archive="$1"
867 shift
868 if [ -e "$archive.xz" ]; then
869 for f in "$@"; do
870 if [ "$f" != "unknown" ]; then
871 "$TMP/xzdec-$BINARCH" "$archive.xz" | "$TMP/tar-$BINARCH" -x -C "$TMP" -f - "$f" && install_extracted "$f"
872 fi
873 done
874 rm -f "$archive.xz"
875 elif [ -e "$archive.lz" ]; then
876 for f in "$@"; do
877 if [ "$f" != "unknown" ]; then
878 "$TMP/tar-$BINARCH" -xf "$archive.lz" -C "$TMP" "$f" && install_extracted "$f"
879 fi
880 done
881 rm -f "$archive.lz"
882 elif [ -e "$archive" ]; then
883 for f in "$@"; do
884 if [ "$f" != "unknown" ]; then
885 "$TMP/tar-$BINARCH" -xf "$archive" -C "$TMP" "$f" && install_extracted "$f"
886 fi
887 done
888 rm -f "$archive"
889 fi
890}
891
892get_apparch() {
893 if [ -z "$2" ]; then # no arch given
894 apparch="$arch"
895 else
896 apparch="$2"
897 fi
898 if exists_in_zip "$1-$apparch.*"; then # add the . to make sure it is not a substring being matched
899 return 0
900 else
901 get_fallback_arch "$apparch"
902 if [ "$apparch" != "$fallback_arch" ]; then
903 get_apparch "$1" "$fallback_arch"
904 return $?
905 else
906 apparch="" # No arch-specific package
907 return 1
908 fi
909 fi
910}
911
912get_apparchives(){
913 apparchives=""
914 if get_apparch "$1"; then
915 apparchives="$1-$apparch"
916 fi
917 if exists_in_zip "$1-common.*"; then
918 apparchives="$1-common $apparchives"
919 fi
920 if exists_in_zip "$1-lib-$arch.*"; then
921 apparchives="$1-lib-$arch $apparchives"
922 fi
923 if [ -n "$fbarch" ] && exists_in_zip "$1-lib-$fbarch.*"; then
924 apparchives="$1-lib-$fbarch $apparchives"
925 fi
926}
927
928get_appsize() {
929 app_name="$(basename "$1")"
930 which_dpi "$app_name"
931 app_density="$(basename "$dpiapkpath")"
932 case $preodex in
933 true*) odexsize="|odex";;
934 *) odexsize="";;
935 esac
936 appsize="$(cat $TMP/app_sizes.txt | grep -E "$app_name.*[[:blank:]]($app_density|common$odexsize)[[:blank:]]" | awk 'BEGIN { app_size=0; } { folder_size=$3; app_size=app_size+folder_size; } END { printf app_size; }')"
937}
938
939get_fallback_arch(){
940 case "$1" in
941 arm) fallback_arch="all";;
942 arm64) fallback_arch="arm";;
943 x86) fallback_arch="arm";; #by using libhoudini
944 x86_64) fallback_arch="x86";; #e.g. chain: x86_64->x86->arm->all
945 *) fallback_arch="$1";; #return original arch if no fallback available
946 esac
947}
948
949get_file_prop() {
950 grep -m1 "^$2=" "$1" | cut -d= -f2
951}
952
953get_prop() {
954 #check known .prop files using get_file_prop
955 for f in $PROPFILES; do
956 if [ -e "$f" ]; then
957 prop="$(get_file_prop "$f" "$1")"
958 if [ -n "$prop" ]; then
959 break #if an entry has been found, break out of the loop
960 fi
961 fi
962 done
963 #if prop is still empty; try to use recovery's built-in getprop method; otherwise output current result
964 if [ -z "$prop" ]; then
965 getprop "$1" | cut -c1-
966 else
967 printf "$prop"
968 fi
969}
970
971install_extracted() {
972 file_list="$(find "$TMP/$1/" -mindepth 1 -type f | cut -d/ -f5-)"
973 dir_list="$(find "$TMP/$1/" -mindepth 1 -type d | cut -d/ -f5-)"
974 for file in $file_list; do
975 install -D "$TMP/$1/${file}" "$SYSTEM/${file}"
976 ch_con "$SYSTEM/${file}"
977 set_perm 0 0 644 "$SYSTEM/${file}";
978 done
979 for dir in $dir_list; do
980 ch_con "$SYSTEM/${dir}"
981 set_perm 0 0 755 "$SYSTEM/${dir}";
982 done
983 case $preodex in
984 true*)
985 installedapkpaths="$(find "$TMP/$1/" -name "*.apk" -type f | cut -d/ -f5-)"
986 for installedapkpath in $installedapkpaths; do # TODO fix spaces-handling
987 if ! checkmanifest "$SYSTEM/$installedapkpath" "classes.dex"; then
988 ui_print "- pre-ODEX-ing $gapp_name";
989 log "pre-ODEX-ing" "$gapp_name";
990 odexapk "$SYSTEM/$installedapkpath"
991 fi
992 done
993 ;;
994 esac
995 bkup_list=$'\n'"${file_list}${bkup_list}"
996 rm -rf "$TMP/$1"
997}
998
999log() {
1000 printf "%31s | %s\n" "$1" "$2" >> $g_log;
1001}
1002
1003log_add() {
1004 printf "%7s | %26s | + %7d | %7d\n" "$1" "$2" "$3" "$4">> $calc_log;
1005}
1006
1007log_sub() {
1008 printf "%7s | %26s | - %7d | %7d\n" "$1" "$2" "$3" "$4">> $calc_log;
1009}
1010
1011obsolete_gapps_list() {
1012 cat <<EOF
1013$remove_list
1014EOF
1015}
1016
1017odexapk() {
1018 if [ -f "$1" ]; then # strict, only files
1019 apkdir="$(dirname "$1")"
1020 apkname="$(basename "$1" ".apk")" # Take note not to use -s, it is not supported in busybox
1021 install -d "$TMP/classesdex"
1022 "$TMP/unzip-$BINARCH" -q -o "$1" "classes*.dex" -d "$TMP/classesdex/" # extract to temporary location first, to avoid potential disk space shortage
1023 eval '$TMP/zip-$BINARCH -d "$1" "classes*.dex"'
1024 cp "$TMP/classesdex/"* "$apkdir"
1025 rm -rf "$TMP/classesdex/"
1026 dexfiles="$(find "$apkdir" -name "classes*.dex")"
1027 if [ -n "$dexfiles" ]; then
1028 dex="LD_LIBRARY_PATH='$SYSTEM/lib:$SYSTEM/lib64' $SYSTEM/bin/dex2oat"
1029 for d in $dexfiles; do
1030 dex="$dex --dex-file=\"$d\""
1031 bkup_list=$'\n'"${d#\$SYSTEM\/}${bkup_list}" # Backup the dex for re-generating oat in the future
1032 done
1033 dex="install -d \"$apkdir/oat/$req_android_arch\" && $dex --instruction-set=\"$req_android_arch\" --oat-file=\"$apkdir/oat/$req_android_arch/$apkname.odex\""
1034 eval "$dex"
1035 # Add the dex2oat command to addon.d for re-running during a restore
1036 sed -i "\:# Re-pre-ODEX APKs (from GApps Installer):a \ $dex" $bkup_tail
1037 fi
1038 fi
1039}
1040
1041quit() {
1042 set_progress 0.94;
1043 install_note=$(echo "${install_note}" | sort -r | sed '/^$/d'); # sort Installation Notes & remove empty lines
1044 echo ------------------------------------------------------------------ >> $g_log;
1045 echo -e "$log_close" >> $g_log;
1046
1047 # Add Installation Notes to log to help user better understand conflicts/errors
1048 for note in $install_note; do
1049 eval "error_msg=\$${note}";
1050 echo -e "$error_msg" >> $g_log;
1051 done;
1052
1053 # Add User App Removals NotFound Log if it exists
1054 if [ -r $user_remove_notfound_log ]; then
1055 echo -e "$user_notfound_msg" >> $g_log;
1056 echo "# Begin User App Removals NOT Found (from gapps-config)" >> $g_log;
1057 cat $user_remove_notfound_log >> $g_log;
1058 rm -f $user_remove_notfound_log;
1059 echo -e "# End User App Removals NOT Found (from gapps-config)\n" >> $g_log;
1060 fi;
1061 # Add User App Removals MultipleFound Log if it exists
1062 if [ -r $user_remove_multiplefound_log ]; then
1063 echo -e "$user_multiplefound_msg" >> $g_log;
1064 echo "# Begin User App Removals MULTIPLE Found (from gapps-config)" >> $g_log;
1065 cat $user_remove_multiplefound_log >> $g_log;
1066 rm -f $user_remove_multiplefound_log;
1067 echo -e "# End User App Removals MULTIPLE Found (from gapps-config)\n" >> $g_log;
1068 fi;
1069
1070 # Add Duplicate Files Log if it exists
1071 if [ -r $conflicts_log ]; then
1072 echo -e "$del_conflict_msg" >> $g_log;
1073 echo "# Begin GApps <> ROM Duplicate File List" >> $g_log;
1074 cat $conflicts_log >> $g_log;
1075 rm -f $conflicts_log;
1076 echo -e "# End GApps <> ROM Duplicate File List\n" >> $g_log;
1077 fi;
1078
1079 # Add Installation Calculations to the log if they were performed
1080 if [ -r $calc_log ]; then
1081 echo "# Begin GApps Size Calculations" >> $g_log;
1082 cat $calc_log >> $g_log;
1083 rm -f $calc_log;
1084 echo -e "\n# End GApps Size Calculations" >> $g_log;
1085 fi;
1086
1087 # Add list of Raw User Application Removals back to end of processed gapps-config for display in gapps log
1088 if [ -n "$user_remove_list" ]; then
1089 for user_remove_app_raw in $user_remove_list; do
1090 echo "(${user_remove_app_raw})" >> "$g_conf";
1091 done;
1092 fi;
1093
1094 set_progress 0.96;
1095 # Add gapps-config information to the log
1096 echo -e "\n# Begin User's gapps-config" >> $g_log;
1097 if [ "$g_conf" ]; then
1098 cat "$g_conf" >> $g_log;
1099 else
1100 echo -n " *** NOT USED ***" >> $g_log;
1101 fi;
1102 echo -e "\n# End User's gapps-config" >> $g_log;
1103
1104 # Copy logs to proper folder (Same as gapps-config or same as Zip)
1105 ui_print "- Copying Log to $log_folder";
1106 ui_print " ";
1107 cp -f $g_log "$log_folder/open_gapps_log.txt";
1108 rm -f $g_log;
1109 set_progress 0.97;
1110}
1111
1112set_perm() {
1113 chown "$1:$2" "$4";
1114 chmod "$3" "$4";
1115}
1116
1117set_progress() { echo "set_progress $1" > "$OUTFD"; }
1118
1119sys_app() {
1120 if ( grep -q "codePath=\"$SYSTEM/app/$1" /data/system/packages.xml ); then
1121 return 0;
1122 fi;
1123 return 1;
1124}
1125
1126ui_print() {
1127 echo "ui_print $1" > "$OUTFD";
1128 echo "ui_print" > "$OUTFD";
1129}
1130
1131which_dpi() {
1132 # Calculate available densities
1133 app_densities="";
1134 app_densities="$(cat $TMP/app_densities.txt | grep -E "$1/([0-9-]+|nodpi)/" | sed -r 's#.*/([0-9-]+|nodpi)/.*#\1#' | sort)";
1135 dpiapkpath="unknown"
1136 # Check if in the package there is a version for our density, or a universal one.
1137 for densities in $app_densities; do
1138 case "$densities" in
1139 *"$density"*) dpiapkpath="$1/$densities"; break;;
1140 *nodpi*) dpiapkpath="$1/nodpi"; break;;
1141 esac;
1142 done;
1143 # Check if density is unknown or set to nopdi and there is not a universal package and select the package with higher density.
1144 if { [ "$density" = "unknown" ] || [ "$density" = "nopdi" ]; } && [ "$dpiapkpath" = "unknown" ] && [ -n "$app_densities" ]; then
1145 app_densities="$(echo "$app_densities" | sort -r)"
1146 for densities in $app_densities; do
1147 dpiapkpath="$1/$densities";
1148 break;
1149 done;
1150 fi;
1151 # If there is no package for our density nor a universal one, we will look for the one with closer, but higher density.
1152 if [ "$dpiapkpath" = "unknown" ] && [ -n "$app_densities" ]; then
1153 app_densities="$(echo "$app_densities" | sort)"
1154 for densities in $app_densities; do
1155 all_densities="$(echo "$densities" | sed 's/-/ /g' | tr ' ' '\n' | sort | tr '\n' ' ')";
1156 for d in $all_densities; do
1157 if [ "$d" -ge "$density" ]; then
1158 dpiapkpath="$1/$densities";
1159 break 2;
1160 fi;
1161 done;
1162 done;
1163 fi;
1164 # If there is no package for our density nor a universal one or one for higher density, we will use the one with closer, but lower density.
1165 if [ "$dpiapkpath" = "unknown" ] && [ -n "$app_densities" ]; then
1166 app_densities="$(echo "$app_densities" | sort -r)"
1167 for densities in $app_densities; do
1168 all_densities="$(echo "$densities" | sed 's/-/ /g' | tr ' ' '\n' | sort -r | tr '\n' ' ')";
1169 for d in $all_densities; do
1170 if [ "$d" -le "$density" ]; then
1171 dpiapkpath="$1/$densities";
1172 break 2;
1173 fi;
1174 done;
1175 done;
1176 fi;
1177}
1178# _____________________________________________________________________________________________________________________
1179# Gather Pre-Install Info
1180# Are we on an Android device is or is a really stupid person running this script on their computer?
1181if [ -e "/etc/lsb-release" ] || [ -n "$OSTYPE" ]; then
1182 echo "Don't run this on your computer! You need to flash the Open GApps zip on an Android Recovery!"
1183 exit 1
1184fi
1185# Get GApps Version and GApps Type from g.prop extracted at top of script
1186gapps_version=$(get_file_prop "$TMP/g.prop" "ro.addon.open_version")
1187gapps_type=$(get_file_prop "$TMP/g.prop" "ro.addon.open_type")
1188# _____________________________________________________________________________________________________________________
1189# Begin GApps Installation
1190ui_print " ";
1191ui_print '##############################';
1192ui_print ' _____ _____ ___ ____ ';
1193ui_print ' / _ \ | __ \ / _ \ | _ \ ';
1194ui_print '| / \ || |__) | |_| || | \ \';
1195ui_print '| | | || ___/| __/ | | | |';
1196ui_print '| \ / || | \ |__ | | | |';
1197ui_print ' \_/ \_/ |_| \___| |_| |_|';
1198ui_print ' ___ _ ___ ___ ___ ';
1199ui_print ' / __| /_\ | _ \ _ \/ __|';
1200ui_print ' | (_ |/ _ \| _/ _/\__ \';
1201ui_print ' \___/_/ \_\_| |_| |___/';
1202ui_print '##############################';
1203ui_print " ";
1204ui_print "$installer_name$gapps_version";
1205ui_print " ";
1206mounts=""
1207for p in "/cache" "/data" "/persist" "/vendor"; do
1208 if [ -d "$p" ] && grep -q "$p" "/etc/fstab" && ! mountpoint -q "$p"; then
1209 mounts="$mounts $p"
1210 fi
1211done
1212ui_print "- Mounting $mounts";
1213ui_print " ";
1214set_progress 0.01;
1215for m in $mounts; do
1216 mount "$m"
1217done
1218
1219if ! mount "$SYSTEM_MOUNT"; then
1220 mount -o rw "$block" "$SYSTEM_MOUNT"
1221fi
1222
1223# _____________________________________________________________________________________________________________________
1224# Gather Device & GApps Package Information
1225if [ -z "$(get_prop "ro.build.id")" ]; then
1226 ui_print "*** No ro.build.id ***"
1227 ui_print " "
1228 ui_print "Your ROM has no valid build.prop or equivalent"
1229 ui_print " "
1230 ui_print "******* GApps Installation failed *******"
1231 ui_print " "
1232 install_note="${install_note}nobuildprop"$'\n'
1233 abort "$E_NOBUILDPROP"
1234fi
1235
1236testcomprfile="$(find $SYSTEM -maxdepth 1 -type f | head -n 1)" #often this should return the build.prop, but it can be any file for this test
1237# Check if $testcomprfile if it is exists is not compressed and thus unprocessable
1238if [ -e "$testcomprfile" ] && [ "$(head -c 4 "$testcomprfile")" = "zzzz" ]; then
1239 ui_print "*** Recovery does not support transparent compression ***"
1240 ui_print " "
1241 ui_print "Your ROM uses transparent compression, but your recovery"
1242 ui_print "does not support this feature, resulting in corrupt files."
1243 ui_print " "
1244 ui_print "BEFORE INSTALLING ANYTHING ANYMORE YOU SHOULD UPDATE YOUR"
1245 ui_print "RECOVERY AS SOON AS POSSIBLE, TO PREVENT FILE CORRUPTION."
1246 ui_print " "
1247 ui_print "******* GApps Installation failed *******"
1248 ui_print " "
1249 install_note="${install_note}recovery_compression_msg"$'\n'
1250 abort "$E_RECCOMPR"
1251fi
1252
1253# Get device name any which way we can
1254for field in ro.product.device ro.build.product ro.product.name; do
1255 device_name="$(get_prop "$field")"
1256 if [ "${#device_name}" -ge "2" ]; then
1257 break
1258 fi
1259 device_name="Bad ROM/Recovery"
1260done
1261
1262# Locate gapps-config (if used)
1263for i in "$TMP/aroma/.gapps-config"\
1264 "$zip_folder/.gapps-config"\
1265 "$zip_folder/.gapps-config-$device_name"\
1266 "$zip_folder/.gapps-config-$device_name.txt"\
1267 "$zip_folder/.gapps-config.txt"\
1268 "$zip_folder/gapps-config-$device_name.txt"\
1269 "$zip_folder/gapps-config.txt"\
1270 "/data/.gapps-config"\
1271 "/data/.gapps-config-$device_name"\
1272 "/data/.gapps-config-$device_name.txt"\
1273 "/data/.gapps-config.txt"\
1274 "/data/gapps-config-$device_name.txt"\
1275 "/data/gapps-config.txt"\
1276 "/persist/.gapps-config"\
1277 "/persist/.gapps-config-$device_name"\
1278 "/persist/.gapps-config-$device_name.txt"\
1279 "/persist/.gapps-config.txt"\
1280 "/persist/gapps-config-$device_name.txt"\
1281 "/persist/gapps-config.txt"\
1282 "/sdcard/.gapps-config"\
1283 "/sdcard/.gapps-config-$device_name"\
1284 "/sdcard/.gapps-config-$device_name.txt"\
1285 "/sdcard/.gapps-config.txt"\
1286 "/sdcard/gapps-config-$device_name.txt"\
1287 "/sdcard/gapps-config.txt"\
1288 "/sdcard/Open-GApps/.gapps-config"\
1289 "/sdcard/Open-GApps/.gapps-config-$device_name"\
1290 "/sdcard/Open-GApps/.gapps-config-$device_name.txt"\
1291 "/sdcard/Open-GApps/.gapps-config.txt"\
1292 "/sdcard/Open-GApps/gapps-config-$device_name.txt"\
1293 "/sdcard/Open-GApps/gapps-config.txt"\
1294 "/tmp/install/.gapps-config"\
1295 "/tmp/install/.gapps-config-$device_name"\
1296 "/tmp/install/.gapps-config-$device_name.txt"\
1297 "/tmp/install/.gapps-config.txt"\
1298 "/tmp/install/gapps-config-$device_name.txt"\
1299 "/tmp/install/gapps-config.txt"; do
1300 if [ -r "$i" ]; then
1301 g_conf="$i";
1302 break;
1303 fi;
1304done;
1305
1306# We log in the same directory as the gapps-config file, unless it is aroma
1307if [ -n "$g_conf" ] && [ "$g_conf" != "$TMP/aroma/.gapps-config" ]; then
1308 log_folder="$(dirname "$g_conf")";
1309else
1310 log_folder="$zip_folder";
1311fi
1312
1313if [ "$g_conf" ]; then
1314 config_file="$g_conf";
1315 g_conf_orig="$g_conf";
1316 g_conf="$TMP/proc_gconf";
1317
1318 sed -r -e 's/\r//g' -e 's|#.*||g' -e 's/^[ \t ]*//g' -e 's/[ \t ]*$//g' -e '/^$/d' "$g_conf_orig" > "$g_conf"; # UNIX line-endings, strip comments+emptylines+spaces+tabs
1319
1320 # include mentioned as a *whole word* (surrounded by space/tabs or start/end or directly followed by a comment) and is itself NOT a comment (should not be possible because of sed above)
1321 if ( grep -qiE '^([^#]*[[:blank:]]+)?include($|#|[[:blank:]])' "$g_conf" ); then
1322 config_type="include"
1323 else
1324 config_type="exclude"
1325 fi
1326 sed -i -r -e 's/\<(in|ex)clude\>//gI' "$g_conf" # drop in/exclude from the config
1327
1328 user_remove_list=$(awk -F "[()]" '{ for (i=2; i<NF; i+=2) print $i }' "$g_conf"); # Get users list of apk's to remove from gapps-config
1329 sed -i -e s/'([^)]*)'/''/g -e '/^$/d' "$g_conf"; # Remove all instances of user app removals (stuff between parentheses) and empty lines we might have created
1330else
1331 config_file="Not Used";
1332 g_conf="$TMP/proc_gconf";
1333 touch "$g_conf";
1334fi;
1335
1336# Unless this is a NoDebug install - create folder and take 'Before' snapshots
1337if ( ! grep -qiE '^nodebug$' "$g_conf" ); then
1338 install -d $TMP/logs;
1339 ls -alZR $SYSTEM > $TMP/logs/System_Files_Before.txt;
1340 df -k > $TMP/logs/Device_Space_Before.txt;
1341fi;
1342
1343# Get ROM Android version
1344ui_print "- Gathering device & ROM information"
1345ui_print " "
1346
1347# Get ROM SDK version
1348rom_build_sdk="$(get_prop "ro.build.version.sdk")"
1349
1350# Get Device Type
1351if echo "$(get_prop "ro.build.characteristics")" | grep -qi "tablet"; then
1352 device_type=tablet
1353elif echo "$(get_prop "ro.build.characteristics")" | grep -qi "tv"; then
1354 device_type=tv
1355 core_gapps_list="$tvcore_gapps_list" # use the TV core apps instead of the regular core apps
1356else
1357 device_type=phone
1358fi
1359
1360echo "# Begin Open GApps Install Log" > $g_log;
1361echo ------------------------------------------------------------------ >> $g_log;
1362
1363# Check to make certain user has proper version ROM Installed
1364if [ ! "$rom_build_sdk" = "$req_android_sdk" ]; then
1365 ui_print "*** Incompatible Android ROM detected ***";
1366 ui_print " ";
1367 ui_print "This GApps pkg is for Android $req_android_version.x ONLY";
1368 ui_print "Please download the correct version for"
1369 ui_print "your ROM: $(get_prop "ro.build.version.release") (SDK $rom_build_sdk)"
1370 ui_print " ";
1371 ui_print "******* GApps Installation failed *******";
1372 ui_print " ";
1373 install_note="${install_note}rom_android_version_msg"$'\n'; # make note that ROM Version is not compatible with these GApps
1374 abort "$E_ROMVER";
1375fi;
1376
1377# Check to make certain that user device matches the architecture
1378device_architecture="$(get_prop "ro.product.cpu.abilist")"
1379# If the recommended field is empty, fall back to the deprecated one
1380if [ -z "$device_architecture" ]; then
1381 device_architecture="$(get_prop "ro.product.cpu.abi")"
1382fi
1383
1384case "$device_architecture" in
1385 *x86_64*) arch="x86_64"; libfolder="lib64";;
1386 *x86*) arch="x86"; libfolder="lib";;
1387 *arm64*) arch="arm64"; libfolder="lib64";;
1388 *armeabi*) arch="arm"; libfolder="lib";;
1389 *) arch="unknown";;
1390esac
1391
1392EOFILE
1393echo "for targetarch in $ARCH abort; do" >> "$build/$1" # we add abort as latest entry to detect if there is no match
1394tee -a "$build/$1" > /dev/null <<'EOFILE'
1395 if [ "$arch" = "$targetarch" ]; then
1396 if [ "$libfolder" = "lib64" ]; then #on 64bit we also need to install 32 bit libs from the fbarch
1397 get_fallback_arch "$arch"
1398 fbarch="$fallback_arch"
1399 else
1400 fbarch=""
1401 fi
1402 break
1403 elif [ "abort" = "$targetarch" ]; then
1404 ui_print "***** Incompatible Device Detected *****"
1405 ui_print " "
1406 ui_print "This Open GApps package cannot be"
1407 ui_print "installed on this device's architecture."
1408 ui_print "Please download the correct version for"
1409 ui_print "your device: $arch"
1410 ui_print " "
1411 ui_print "******* GApps Installation failed *******"
1412 ui_print " "
1413 install_note="${install_note}arch_compat_msg"$'\n' # make note that Open GApps are not compatible with architecture
1414 abort "$E_ARCH"
1415 fi
1416done
1417
1418# Determine Recovery Type and Version
1419for rec_log in $rec_tmp_log $rec_cache_log; do
1420 recovery=$(grep -m 2 -E " Recovery v|Starting TWRP|Welcome to|PhilZ|Starting recovery \(" $rec_log);
1421 case "$recovery" in
1422 *Welcome*) recovery="$(grep -m 1 "Welcome to" $rec_log | awk '{ print substr($0, index($0,$3)) }')$(grep -m 1 "^ext.version" $rec_log | cut -d\" -f2)"; break;;
1423 *Recovery*) recovery=$(grep -m 1 "Recovery v" $rec_log); recovery=${recovery/Recovery v/Recovery }; break;;
1424 *PhilZ*) recovery=$(grep -m 2 -E "PhilZ|ClockworkMod" $rec_log); recovery="${recovery/ClockworkMod v/(ClockworkMod })"; break;;
1425 *Starting\ recovery\ \(*) recovery=$(grep -m 1 "ro.cm.version=" $rec_log| sed -e 's/.*ro.cm.version=/CM Recovery /gI'); break;;
1426 Starting*) recovery=$(echo "$recovery" | awk -F"Starting " '{ print $2 }' | awk -F" on " '{ print $1 }'); break;;
1427 esac;
1428done;
1429
1430# Get device model
1431device_model="$(get_prop "ro.product.model")"
1432
1433# Get display density
1434density="$(get_prop "ro.sf.lcd_density")"
1435
1436# Check for DPI Override in gapps-config
1437if ( grep -qiE '^forcedpi(120|160|213|240|260|280|300|320|340|360|400|420|480|560|640|nodpi)$' "$g_conf" ); then # user wants to override the DPI selection
1438 density=$( grep -iEo '^forcedpi(120|160|213|240|260|280|300|320|340|360|400|420|480|560|640|nodpi)$' "$g_conf" | tr '[:upper:]' '[:lower:]' )
1439 density=${density#forcedpi}
1440fi
1441
1442# Set density to unknown if it's still empty
1443test -z "$density" && density="unknown"
1444
1445# Check for Camera API v2 availability
1446cameraapi="$(get_prop "camera2.portability.force_api")"
1447camerahal="$(get_prop "persist.camera.HAL3.enabled")"
1448if ( grep -qiE '^forcenewcamera$' "$g_conf" ); then # takes precedence over any detection
1449 newcamera_compat="true[forcenewcamera]"
1450else
1451 if [ -n "$cameraapi" ]; then # we check first for the existence of this key, it takes precedence if set to any value
1452 if [ "$cameraapi" -ge "2" ]; then
1453 newcamera_compat="true[force_api]"
1454 else
1455 newcamera_compat="false[force_api]"
1456 fi
1457 elif [ -n "$camerahal" ] && [ "$camerahal" -ge "1" ]; then
1458 newcamera_compat="true"
1459 else
1460 # If not explictly defined, check whitelist
1461 case $device_name in
1462 ryu|angler|bullhead|shamu|volantis*|flounder*|hammerhead*|sprout*) newcamera_compat="true[whitelist]";;
1463 *) newcamera_compat="false";;
1464 esac
1465 fi
1466fi
1467
1468cmcompatibilityhacks="false" # test for CM/Lineage since they do weird AOSP-breaking changes to their code, breaking some GApps
1469case "$(get_prop "ro.build.flavor")" in
1470 cm_*|lineage_*)
1471 if [ "$rom_build_sdk" -lt "27" ]; then
1472 cmcompatibilityhacks="true";
1473 fi
1474 if [ "$rom_build_sdk" -ge "24" ]; then # CMSetupWizard is broken in LineageOS 14+ and can be safely removed on CM14+ as well
1475 aosp_remove_list="${aosp_remove_list}cmsetupwizard"$'\n';
1476 fi;;
1477esac
1478
1479# Check for Clean Override in gapps-config
1480if ( grep -qiE '^forceclean$' "$g_conf" ); then
1481 forceclean="true"
1482else
1483 forceclean="false"
1484fi
1485
1486# Check for Pre-Odex support or NoPreODEX Override in gapps-config
1487if [ "$rom_build_sdk" -lt "23" ]; then
1488 preodex="false [Only 6.0+]"
1489elif [ "$(get_prop "persist.sys.dalvik.vm.lib.2")" != "libart.so" ] && [ "$(get_prop "persist.sys.dalvik.vm.lib.2")" != "libart" ]; then
1490 preodex="false [No ART]"
1491elif ! command -v "$TMP/zip-$BINARCH" >/dev/null 2>&1; then
1492 preodex="false [No Info-Zip]"
1493elif ! command -v "dex2oat" >/dev/null 2>&1; then
1494 preodex="false [No dex2oat]"
1495elif ( grep -qiE '^nopreodex$' "$g_conf" ); then
1496 preodex="false [nopreodex]"
1497elif ( grep -qiE '^preodex$' "$g_conf" ); then
1498 preodex="true [preodex]"
1499else
1500 preodex="false" #temporarily changed to false by default until we sort the issues out
1501fi
1502
1503# Check for skipswypelibs in gapps-config
1504if ( grep -qiE '^skipswypelibs$' $g_conf ); then
1505 skipswypelibs="true"
1506else
1507 skipswypelibs="false"
1508fi
1509
1510# Check for substituteswypelibs in gapps-config
1511if ( grep -qiE '^substituteswypelibs$' $g_conf ); then
1512 substituteswypelibs="true"
1513else
1514 substituteswypelibs="false"
1515fi
1516
1517# Check for skipvendorlibs in gapps-config
1518if ( grep -qiE '^skipvendorlibs$' $g_conf ); then
1519 skipvendorlibs="true"
1520 mount -t tmpfs tmpfs $SYSTEM/vendor # by mounting a tmpfs on this location, we hide the existing files from any operations
1521else
1522 skipvendorlibs="false"
1523fi
1524
1525# Remove any files from gapps-remove.txt that should not be processed for automatic removal
1526for bypass_file in $removal_bypass_list; do
1527 sed -i "\:${bypass_file}:d" $gapps_removal_list
1528done
1529
1530# Is this a 'Clean' or 'Dirty' install
1531if ( clean_inst ); then
1532 install_type="Clean[Data Wiped]"
1533 cameragoogle_inst=Clean
1534else
1535 install_type="Dirty[Data NOT Wiped]"
1536
1537 # Was Google Camera previously installed (in /system)
1538 if ( sys_app GoogleCamera ); then
1539 cameragoogle_inst=true
1540 else
1541 cameragoogle_inst=false
1542 fi
1543fi
1544
1545# Is device FaceUnlock compatible
1546if ( ! grep -qE "Victory|herring|sun4i" /proc/cpuinfo ); then
1547 for xml in $SYSTEM/etc/permissions/android.hardware.camera.front.xml $SYSTEM/etc/permissions/android.hardware.camera.xml $SYSTEM/vendor/etc/permissions/android.hardware.camera.front.xml $SYSTEM/vendor/etc/permissions/android.hardware.camera.xml; do
1548 if ( awk -vRS='-->' '{ gsub(/<!--.*/,"")}1' $xml | grep -qr "feature name=\"android.hardware.camera.front" ); then
1549 faceunlock_compat=true
1550 break
1551 fi
1552 faceunlock_compat=false
1553 done
1554else
1555 faceunlock_compat=false
1556fi
1557
1558# Is device VRMode compatible
1559vrmode_compat=false
1560for xml in $(grep -rl '<feature name="android.software.vr.mode" />' $SYSTEM/etc/ $SYSTEM/vendor/etc/); do
1561 if ( awk -vRS='-->' '{ gsub(/<!--.*/,"")}1' $xml | grep -qr '<feature name="android.software.vr.mode" />' $SYSTEM/etc/ $SYSTEM/vendor/etc/ ); then
1562 vrmode_compat=true
1563 break
1564 fi
1565done
1566
1567# Check device name for devices that are incompatible with Google Camera
1568case $device_name in
1569EOFILE
1570cameracompatibilityhack "$build/$1" #in kitkat we don't have google camera compatibility with some phones
1571tee -a "$build/$1" > /dev/null <<'EOFILE'
1572 *) cameragoogle_compat=true;;
1573esac;
1574
1575# Check if Google Pixel
1576case $device_name in
1577 marlin|sailfish|walleye|taimen|crosshatch|blueline) googlepixel_compat="true";;
1578 *) googlepixel_compat="false";;
1579esac
1580
1581log "ROM Android version" "$(get_prop "ro.build.version.release")"
1582log "ROM Build ID" "$(get_prop "ro.build.display.id")"
1583log "ROM Version increment" "$(get_prop "ro.build.version.incremental")"
1584log "ROM SDK version" "$rom_build_sdk"
1585log "ROM/Recovery modversion" "$(get_prop "ro.modversion")"
1586log "Device Recovery" "$recovery"
1587log "Device Name" "$device_name"
1588log "Device Model" "$device_model"
1589log "Device Type" "$device_type"
1590log "Device CPU" "$device_architecture"
1591log "Device A/B-partitions" "$device_abpartition"
1592log "Installer Platform" "$BINARCH"
1593log "ROM Platform" "$arch"
1594log "Display Density Used" "$density"
1595log "Install Type" "$install_type"
1596log "Smart ART Pre-ODEX" "$preodex"
1597log "Google Camera already installed" "$cameragoogle_inst"
1598log "FaceUnlock Compatible" "$faceunlock_compat"
1599log "VRMode Compatible" "$vrmode_compat"
1600log "Google Camera Compatible" "$cameragoogle_compat"
1601log "New Camera API Compatible" "$newcamera_compat"
1602log "Google Pixel Features" "$googlepixel_compat"
1603
1604# Determine if a GApps package is installed and
1605# the version, type, and whether it's an Open GApps package
1606if [ -e "$SYSTEM/priv-app/GoogleServicesFramework/GoogleServicesFramework.apk" ] || [ -e "$SYSTEM/priv-app/GoogleServicesFramework.apk" ]; then
1607 openversion="$(get_prop "ro.addon.open_version")"
1608 if [ -n "$openversion" ]; then
1609 log "Current GApps Version" "$openversion"
1610 opentype="$(get_prop "ro.addon.open_type")"
1611 if [ -z "$opentype" ]; then
1612 opentype="unknown"
1613 fi
1614 log "Current Open GApps Package" "$opentype"
1615 elif [ -e "$SYSTEM/etc/g.prop" ]; then
1616 log "Current GApps Version" "NON Open GApps Package Currently Installed (FAILURE)"
1617 ui_print "* Incompatible GApps Currently Installed *"
1618 ui_print " "
1619 ui_print "This Open GApps package can ONLY be installed"
1620 ui_print "on top of an existing installation of Open GApps"
1621 ui_print "or a clean AOSP/CyanogenMod ROM installation,"
1622 ui_print "or a Stock ROM that conforms to Nexus standards."
1623 ui_print "You must wipe (format) your system partition"
1624 ui_print "and flash your ROM BEFORE installing Open GApps."
1625 ui_print " "
1626 ui_print "******* GApps Installation failed *******"
1627 ui_print " "
1628 install_note="${install_note}non_open_gapps_msg"$'\n'
1629 abort "$E_NONOPEN"
1630 else
1631 log "Current GApps Version" "Stock ROM GApps Currently Installed (NOTICE)"
1632 ui_print "* Stock ROM GApps Currently Installed *"
1633 ui_print " "
1634 ui_print "The installer detected that Stock ROM GApps are"
1635 ui_print "already installed. If you are flashing over a"
1636 ui_print "Nexus-compatible ROM there is no problem, but if"
1637 ui_print "you are flashing over a custom ROM, you may want"
1638 ui_print "to contact the developer to request the removal of"
1639 ui_print "the included GApps. The installation will now"
1640 ui_print "continue, but please be aware that any problems"
1641 ui_print "that may occur depend on your ROM."
1642 ui_print " "
1643 install_note="${install_note}fornexus_open_gapps_msg"$'\n'
1644 fi
1645else
1646 # User does NOT have a GApps package installed on their device
1647 log "Current GApps Version" "No GApps Installed"
1648
1649 # Did this 6.0+ system already boot and generated runtime permissions
1650 if [ -e /data/system/users/0/runtime-permissions.xml ]; then
1651 # Check if permissions were granted to Google Setupwizard, this permissions should always be set in the file if GApps were installed before
1652 if ! grep -q "com.google.android.setupwizard" /data/system/users/*/runtime-permissions.xml; then
1653 # Purge the runtime permissions to prevent issues if flashing GApps for the first time on a dirty install
1654 rm -f /data/system/users/*/runtime-permissions.xml
1655 log "Runtime Permissions" "Reset"
1656 fi
1657 fi
1658
1659 # Use the opportunity of No GApps installed to check for potential ROM conflicts when deleting existing GApps files
1660 while read gapps_file; do
1661 if [ -e "$gapps_file" ] && [ "$gapps_file" != "$SYSTEM/lib/$WebView_lib_filename" ] && [ "$gapps_file" != "$SYSTEM/lib64/$WebView_lib_filename" ]; then
1662 echo "$gapps_file" >> $conflicts_log
1663 fi
1664 done < $gapps_removal_list
1665fi
1666# _____________________________________________________________________________________________________________________
1667# Prepare the list of GApps being installed and AOSP/Stock apps being removed
1668# Build list of available GApps that can be installed (and check for a user package preset)
1669for pkg in $pkg_names; do
1670 eval "addto=\$${pkg}_gapps_list"; # Look for method to combine this with line below
1671 all_gapps_list=${all_gapps_list}${addto}; # Look for method to combine this with line above
1672 if ( grep -qiE "^${pkg}gapps\$" "$g_conf" ); then # user has selected a 'preset' install
1673 gapps_type=$pkg;
1674 sed -i "/ro.addon.open_type/c\ro.addon.open_type=$pkg" "$TMP/g.prop"; # modify g.prop to new package type
1675 break;
1676 fi;
1677done;
1678
1679# Prepare list of User specified GApps that will be installed
1680if [ "$g_conf" ]; then
1681 if [ "$config_type" = "include" ]; then # User is indicating the apps they WANT installed
1682 for gapp_name in $all_gapps_list; do
1683 if ( grep -qiE "^$gapp_name\$" "$g_conf" ); then
1684 gapps_list="$gapps_list$gapp_name"$'\n';
1685 fi;
1686 done;
1687 else # User is indicating the apps they DO NOT WANT installed
1688 for gapp_name in $all_gapps_list; do
1689 if ( ! grep -qiE "^$gapp_name\$" "$g_conf" ); then
1690 gapps_list="$gapps_list$gapp_name"$'\n';
1691 fi;
1692 done;
1693 fi;
1694else # User is not using a gapps-config and we're doing the 'full monty'
1695 config_type="[Default]";
1696 gapps_list=$all_gapps_list;
1697fi;
1698
1699# Configure default removal of Stock/AOSP apps - if we're installing Stock GApps or larger
1700if [ "$gapps_type" = "super" ] || [ "$gapps_type" = "stock" ] || [ "$gapps_type" = "aroma" ]; then
1701 for default_name in $default_stock_remove_list; do
1702 eval "remove_${default_name}=true[default]";
1703 done;
1704else
1705 # Do not perform any default removals - but make them optional
1706 for default_name in $default_stock_remove_list; do
1707 eval "remove_${default_name}=false[default]";
1708 done;
1709fi;
1710
1711# Prepare list of AOSP/ROM files that will be deleted using gapps-config
1712# We will look for +Browser, +CameraStock, +DialerStock, +Email, +Gallery, +Launcher, +MMS, +PicoTTS and more to prevent their removal
1713set_progress 0.03;
1714if [ "$g_conf" ]; then
1715 for default_name in $default_stock_remove_list; do
1716 if ( grep -qiE "^\+$default_name\$" "$g_conf" ); then
1717 eval "remove_${default_name}=false[gapps-config]";
1718 elif [ "$gapps_type" = "super" ] || [ "$gapps_type" = "stock" ] || [ "$gapps_type" = "aroma" ]; then
1719 aosp_remove_list="$aosp_remove_list$default_name"$'\n';
1720 if ( grep -qiE "^$default_name\$" "$g_conf" ); then
1721 eval "remove_${default_name}=true[gapps-config]";
1722 fi;
1723 else
1724 if ( grep -qiE "^$default_name\$" "$g_conf" ); then
1725 eval "remove_${default_name}=true[gapps-config]";
1726 aosp_remove_list="$aosp_remove_list$default_name"$'\n';
1727 fi;
1728 fi;
1729 done;
1730 # Check gapps-config for other optional AOSP/ROM files that will be deleted
1731 for opt_name in $optional_aosp_remove_list; do
1732 if ( grep -qiE "^$opt_name\$" "$g_conf" ); then
1733 aosp_remove_list="$aosp_remove_list$opt_name"$'\n';
1734 fi;
1735 done;
1736else
1737 if [ "$gapps_type" = "super" ] || [ "$gapps_type" = "stock" ] || [ "$gapps_type" = "aroma" ]; then
1738 aosp_remove_list=$default_stock_remove_list;
1739 fi;
1740fi;
1741
1742# Provision folder always has to be removed (it conflicts with SetupWizard)
1743aosp_remove_list="${aosp_remove_list}provision"$'\n';
1744# Remove AOSP Android Shared Services in favour of our Google versions of it
1745aosp_remove_list="${aosp_remove_list}extsharedstock"$'\n'"extservicesstock"$'\n';
1746
1747EOFILE
1748webviewcheckhack "$build/$1" # WebViewProvider rules differ Pre-Nougat and Nougat+
1749tee -a "$build/$1" > /dev/null <<'EOFILE'
1750# Cyanogenmod breaks Google's PackageInstaller don't install it on CM
1751if ( contains "$gapps_list" "packageinstallergoogle" ) && [ $cmcompatibilityhacks = "true" ]; then
1752 gapps_list=${gapps_list/packageinstallergoogle};
1753 install_note="${install_note}cmcompatibility_msg"$'\n'; # make note that CM compatibility hacks are applied
1754fi;
1755
1756# Verify device is FaceUnlock compatible BEFORE we allow it in $gapps_list
1757if ( contains "$gapps_list" "faceunlock" ) && [ $faceunlock_compat = "false" ]; then
1758 gapps_list=${gapps_list/faceunlock};
1759 install_note="${install_note}faceunlock_msg"$'\n'; # make note that FaceUnlock will NOT be installed as user requested
1760fi;
1761
1762# Add Google Pixel config if this is a Pixel device (and remove if it is not)
1763if ( ! contains "$gapps_list" "googlepixelconfig" ) && [ $googlepixel_compat = "true" ]; then
1764 gapps_list="${gapps_list}googlepixelconfig"$'\n'
1765fi;
1766if ( contains "$gapps_list" "googlepixelconfig" ) && [ $googlepixel_compat = "false" ]; then
1767 gapps_list=${gapps_list/googlepixelconfig};
1768fi;
1769
1770# If we're NOT installing chrome make certain 'browser' is NOT in $aosp_remove_list UNLESS 'browser' is in $g_conf
1771if ( ! contains "$gapps_list" "chrome" ) && ( ! grep -qiE '^browser$' "$g_conf" ); then
1772 aosp_remove_list=${aosp_remove_list/browser};
1773 remove_browser="false[NO_Chrome]";
1774fi;
1775
1776# If we're NOT installing gmail make certain 'email' is NOT in $aosp_remove_list UNLESS 'email' is in $g_conf
1777if ( ! contains "$gapps_list" "gmail" ) && ( ! grep -qiE '^email$' "$g_conf" ); then
1778 aosp_remove_list=${aosp_remove_list/email};
1779 remove_email="false[NO_Gmail]";
1780fi;
1781
1782# If we're NOT installing photos make certain 'gallery' is NOT in $aosp_remove_list UNLESS 'gallery' is in $g_conf
1783if ( ! contains "$gapps_list" "photos" ) && ( ! grep -qiE '^gallery$' "$g_conf" ); then
1784 aosp_remove_list=${aosp_remove_list/gallery};
1785 remove_gallery="false[NO_Photos]";
1786fi;
1787
1788# If $device_type is not a 'phone' make certain we're not installing messenger
1789if ( contains "$gapps_list" "messenger" ) && [ $device_type != "phone" ]; then
1790 gapps_list=${gapps_list/messenger}; # we'll prevent messenger from being installed since this isn't a phone
1791fi;
1792
1793# If $device_type is not a 'phone' make certain we're not installing carrierservices (this is essential for messenger)
1794if ( contains "$gapps_list" "carrierservices" ) && [ $device_type != "phone" ]; then
1795 gapps_list=${gapps_list/carrierservices}; # we'll prevent carrierservices from being installed since this isn't a phone
1796fi;
1797
1798# If $device_type is not a 'phone' make certain we're not installing dialerframework (implies no dialergoogle)
1799if ( contains "$gapps_list" "dialerframework" ) && [ $device_type != "phone" ]; then
1800 gapps_list=${gapps_list/dialerframework}; # we'll prevent dialerframework from being installed since this isn't a phone
1801fi;
1802
1803# If we're NOT installing dialerframework then we MUST REMOVE dialergoogle from $gapps_list (if it's currently there)
1804if ( ! contains "$gapps_list" "dialerframework" ) && ( contains "$gapps_list" "dialergoogle" ); then
1805 gapps_list=${gapps_list/dialergoogle};
1806 install_note="${install_note}dialergoogle_msg"$'\n'; # make note that Google Dialer will NOT be installed as user requested
1807fi;
1808
1809# If we're NOT installing dialergoogle make certain 'dialerstock' is NOT in $aosp_remove_list UNLESS 'dialerstock' is in $g_conf
1810if ( ! contains "$gapps_list" "dialergoogle" ) && ( ! grep -qiE '^dialerstock$' "$g_conf" ); then
1811 aosp_remove_list=${aosp_remove_list/dialerstock};
1812 remove_dialerstock="false[NO_DialerGoogle]";
1813fi;
1814
1815# If we're NOT installing carrier services then we MUST REMOVE messenger from $gapps_list (if it's currently there)
1816if [ "$API" -ge "23" ] && ( ! contains "$gapps_list" "carrierservices" ) && ( contains "$gapps_list" "messenger" ); then
1817 gapps_list=${gapps_list/messenger};
1818 install_note="${install_note}messenger_msg"$'\n'; # make note that Google Messages will NOT be installed as user requested
1819fi;
1820
1821# If we're NOT installing messenger make certain 'mms' is NOT in $aosp_remove_list UNLESS 'mms' is in $g_conf
1822if ( ! contains "$gapps_list" "messenger" ) && ( ! grep -qiE '^mms$' "$g_conf" ); then
1823 aosp_remove_list=${aosp_remove_list/mms};
1824 remove_mms="false[NO_Messenger]";
1825fi;
1826
1827# If we're NOT installing messenger and mms is in $aosp_remove_list then user must override removal protection
1828if ( ! contains "$gapps_list" "messenger" ) && ( contains "$aosp_remove_list" "mms" ) && ( ! grep -qiE '^override$' "$g_conf" ); then
1829 aosp_remove_list=${aosp_remove_list/mms}; # we'll prevent mms from being removed so user isn't left with no way to receive text messages
1830 remove_mms="false[NO_Override]";
1831 install_note="${install_note}nomms_msg"$'\n'; # make note that MMS can't be removed unless user Overrides
1832fi;
1833
1834# If we're NOT installing googletts make certain 'picotts' is NOT in $aosp_remove_list UNLESS 'picotts' is in $g_conf
1835if ( ! contains "$gapps_list" "googletts" ) && ( ! grep -qiE '^picotts$' "$g_conf" ); then
1836 aosp_remove_list=${aosp_remove_list/picotts};
1837 remove_picotts="false[NO_GoogleTTS]";
1838fi;
1839
1840# If we're NOT installing wallpapers then we MUST REMOVE pixellauncher from $gapps_list (if it's currently there)
1841if ( ! contains "$gapps_list" "wallpapers" ) && ( contains "$gapps_list" "pixellauncher" ); then
1842 gapps_list=${gapps_list/pixellauncher};
1843 install_note="${install_note}pixellauncher_msg"$'\n'; # make note that Google Now Launcher will NOT be installed as user requested
1844fi;
1845
1846# If we're NOT installing search then we MUST REMOVE pixellauncher from $gapps_list (if it's currently there)
1847if ( ! contains "$gapps_list" "search" ) && ( contains "$gapps_list" "pixellauncher" ); then
1848 gapps_list=${gapps_list/pixellauncher};
1849 install_note="${install_note}pixellauncher_msg"$'\n'; # make note that Pixel Launcher will NOT be installed as user requested
1850fi;
1851
1852# If we're NOT installing search then we MUST REMOVE googlenow from $gapps_list (if it's currently there)
1853if ( ! contains "$gapps_list" "search" ) && ( contains "$gapps_list" "googlenow" ); then
1854 gapps_list=${gapps_list/googlenow};
1855 install_note="${install_note}googlenow_msg"$'\n'; # make note that Google Now Launcher will NOT be installed as user requested
1856fi;
1857
1858# If we're NOT installing googlenow or pixellauncher make certain 'launcher' is NOT in $aosp_remove_list UNLESS 'launcher' is in $g_conf
1859if ( ! contains "$gapps_list" "googlenow" ) && ( ! contains "$gapps_list" "pixellauncher" ) && ( ! grep -qiE '^launcher$' "$g_conf" ); then
1860 aosp_remove_list=${aosp_remove_list/launcher};
1861 remove_launcher="false[NO_GoogleNow/PixelLauncher]";
1862fi;
1863
1864# If we're NOT installing googlenow or pixellauncher and launcher is in $aosp_remove_list then user must override removal protection
1865if ( ! contains "$gapps_list" "googlenow" ) && ( ! contains "$gapps_list" "pixellauncher" ) && ( contains "$aosp_remove_list" "launcher" ) && ( ! grep -qiE '^override$' "$g_conf" ); then
1866 aosp_remove_list=${aosp_remove_list/launcher}; # we'll prevent launcher from being removed so user isn't left with no Launcher
1867 remove_launcher="false[NO_Override]";
1868 install_note="${install_note}nolauncher_msg"$'\n'; # make note that Launcher can't be removed unless user Overrides
1869fi;
1870
1871# If we're installing calendargoogle we must ADD calendarstock to $aosp_remove_list (if it's not already there)
1872if ( contains "$gapps_list" "calendargoogle" ) && ( ! contains "$aosp_remove_list" "calendarstock" ); then
1873 aosp_remove_list="${aosp_remove_list}calendarstock"$'\n';
1874fi;
1875
1876# If we're installing calendargoogle we must NOT install calsync
1877if ( contains "$gapps_list" "calendargoogle" ); then
1878 gapps_list=${gapps_list/calsync};
1879fi;
1880
1881# If we're installing keyboardgoogle we must ADD keyboardstock to $aosp_remove_list (if it's not already there)
1882if ( contains "$gapps_list" "keyboardgoogle" ) && ( ! contains "$aosp_remove_list" "keyboardstock" ); then
1883 aosp_remove_list="${aosp_remove_list}keyboardstock"$'\n';
1884fi;
1885
1886# If we're NOT installing keyboardgoogle and keyboardstock is in $aosp_remove_list then user must override removal protection
1887if ( ! contains "$gapps_list" "keyboardgoogle" ) && ( contains "$aosp_remove_list" "keyboardstock" ) && ( ! grep -qi "override" "$g_conf" ); then
1888 aosp_remove_list=${aosp_remove_list/keyboardstock}; # we'll prevent keyboardstock from being removed so user isn't left with no keyboard
1889 install_note="${install_note}nokeyboard_msg"$'\n'; # make note that Stock Keyboard can't be removed unless user Overrides
1890fi;
1891
1892# Verify device is Google Camera compatible BEFORE we allow it in $gapps_list
1893if ( contains "$gapps_list" "cameragoogle" ) && [ $cameragoogle_compat = "false" ]; then
1894 gapps_list=${gapps_list/cameragoogle}; # we must DISALLOW cameragoogle from being installed
1895 install_note="${install_note}camera_compat_msg"$'\n'; # make note that Google Camera will NOT be installed as user requested
1896fi;
1897
1898# If user wants to install cameragoogle then it MUST be a Clean Install OR cameragoogle was previously installed in system partition
1899if ( contains "$gapps_list" "cameragoogle" ) && ( ! clean_inst ) && [ $cameragoogle_inst = "false" ]; then
1900 gapps_list=${gapps_list/cameragoogle}; # we must DISALLOW cameragoogle from being installed
1901 aosp_remove_list=${aosp_remove_list/camerastock}; # and we'll prevent camerastock from being removed so user isn't left with no camera
1902 install_note="${install_note}camera_sys_msg"$'\n'; # make note that Google Camera will NOT be installed as user requested
1903fi;
1904
1905# If we're NOT installing cameragoogle make certain 'camerastock' is NOT in $aosp_remove_list UNLESS 'camerastock' is in $g_conf
1906if ( ! contains "$gapps_list" "cameragoogle" ) && ( ! grep -qiE '^camerastock$' "$g_conf" ); then
1907 aosp_remove_list=${aosp_remove_list/camerastock};
1908 remove_camerastock="false[NO_CameraGoogle]";
1909fi;
1910
1911# Verify device is VRMode compatible, BEFORE we allow vrservice in $gapps_list
1912if ( contains "$gapps_list" "vrservice" ) && [ "$vrmode_compat" = "false" ]; then
1913 gapps_list=${gapps_list/vrservice}; # we must DISALLOW vrservice from being installed
1914 install_note="${install_note}vrservice_compat_msg"$'\n'; # make note that VRService will NOT be installed as user requested
1915fi
1916
1917# If we're installing clockgoogle we must ADD clockstock to $aosp_remove_list (if it's not already there)
1918if ( contains "$gapps_list" "clockgoogle" ) && ( ! contains "$aosp_remove_list" "clockstock" ); then
1919 aosp_remove_list="${aosp_remove_list}clockstock"$'\n';
1920fi;
1921
1922# If we're installing exchangegoogle we must ADD exchangestock to $aosp_remove_list (if it's not already there)
1923if ( contains "$gapps_list" "exchangegoogle" ) && ( ! contains "$aosp_remove_list" "exchangestock" ); then
1924 aosp_remove_list="${aosp_remove_list}exchangestock"$'\n';
1925fi;
1926
1927# If we're installing printservicegoogle we must ADD printservicestock to $aosp_remove_list (if it's not already there)
1928if ( contains "$gapps_list" "printservicegoogle" ) && ( ! contains "$aosp_remove_list" "printservicestock" ); then
1929 aosp_remove_list="${aosp_remove_list}printservicestock"$'\n';
1930fi;
1931
1932# If we're installing storagemanagergoogle we must ADD storagemanagerstock to $aosp_remove_list (if it's not already there)
1933if ( contains "$gapps_list" "storagemanagergoogle" ) && ( ! contains "$aosp_remove_list" "storagemanagerstock" ); then
1934 aosp_remove_list="${aosp_remove_list}storagemanagerstock"$'\n';
1935fi;
1936
1937# If we're installing taggoogle we must ADD tagstock to $aosp_remove_list (if it's not already there)
1938if ( contains "$gapps_list" "taggoogle" ) && ( ! contains "$aosp_remove_list" "tagstock" ); then
1939 aosp_remove_list="${aosp_remove_list}tagstock"$'\n';
1940fi;
1941
1942# If we're installing calculatorgoogle we MUST ADD calculatorstock to $aosp_remove_list (if it's not already there)
1943if ( contains "$gapps_list" "calculatorgoogle" ) && ( ! contains "$aosp_remove_list" "calculatorstock" ); then
1944 aosp_remove_list="${aosp_remove_list}calculatorstock"$'\n';
1945fi;
1946
1947# If we're installing contactsgoogle we MUST ADD contactsstock to $aosp_remove_list (if it's not already there)
1948if ( contains "$gapps_list" "contactsgoogle" ) && ( ! contains "$aosp_remove_list" "contactsstock" ); then
1949 aosp_remove_list="${aosp_remove_list}contactsstock"$'\n';
1950fi;
1951
1952# If we're installing packageinstallergoogle we MUST ADD packageinstallerstock to $aosp_remove_list (if it's not already there)
1953if ( contains "$gapps_list" "packageinstallergoogle" ) && ( ! contains "$aosp_remove_list" "packageinstallerstock" ); then
1954 aosp_remove_list="${aosp_remove_list}packageinstallerstock"$'\n';
1955fi;
1956
1957# If we're NOT installing gcs then we MUST REMOVE projectfi from $gapps_list (if it's currently there)
1958if ( ! contains "$gapps_list" "gcs" ) && ( contains "$gapps_list" "projectfi" ); then
1959 gapps_list=${gapps_list/projectfi};
1960 install_note="${install_note}projectfi_msg"$'\n'; # make note that Project Fi will NOT be installed as user requested
1961fi;
1962
1963# If we're installing wallpapers we must ADD wallpapersstock to $aosp_remove_list (if it's not already there)
1964if ( contains "$gapps_list" "wallpapers" ) && ( ! contains "$aosp_remove_list" "wallpapersstock" ); then
1965 aosp_remove_list="${aosp_remove_list}wallpapersstock"$'\n';
1966fi;
1967
1968# Some ROMs bundle Google Apps or the user might have installed a Google replacement app during an earlier install
1969# Some of these apps are crucial to a functioning system and should NOT be removed if no AOSP/Stock equivalent is available
1970# Unless override keyword is used, make sure they are not removed
1971# NOTICE: Only for Google Keyboard we need to take KitKat support into account, others are only Lollipop+
1972ignoregooglecontacts="true"
1973for f in $contactsstock_list; do
1974 if [ -e "$SYSTEM/$f" ]; then
1975 ignoregooglecontacts="false"
1976 break; #at least 1 aosp stock file is present
1977 fi
1978done;
1979if [ "$ignoregooglecontacts" = "true" ]; then
1980 if ( ! contains "$gapps_list" "contactsgoogle" ) && ( ! grep -qiE '^override$' "$g_conf" ); then
1981 sed -i "\:$SYSTEM/priv-app/GoogleContacts:d" $gapps_removal_list;
1982 ignoregooglecontacts="true[NoRemove]"
1983 install_note="${install_note}nogooglecontacts_removal"$'\n'; # make note that Google Contacts will not be removed
1984 else
1985 ignoregooglecontacts="false[ContactsGoogle]"
1986 fi
1987fi
1988
1989ignoregoogledialer="true"
1990for f in $dialerstock_list; do
1991 if [ -e "$SYSTEM/$f" ]; then
1992 ignoregoogledialer="false"
1993 break; #at least 1 aosp stock file is present
1994 fi
1995done;
1996if [ "$ignoregoogledialer" = "true" ]; then
1997 if ( ! contains "$gapps_list" "dialergoogle" ) && ( ! grep -qiE '^override$' "$g_conf" ); then
1998 sed -i "\:$SYSTEM/priv-app/GoogleDialer:d" $gapps_removal_list;
1999 ignoregoogledialer="true[NoRemove]"
2000 install_note="${install_note}nogoogledialer_removal"$'\n'; # make note that Google Dialer will not be removed
2001 else
2002 ignoregoogledialer="false[DialerGoogle]"
2003 fi
2004fi
2005
2006ignoregooglekeyboard="true"
2007for f in $keyboardstock_list; do
2008 if [ -e "$SYSTEM/$f" ]; then
2009 ignoregooglekeyboard="false"
2010 break; #at least 1 aosp stock file is present
2011 fi
2012done;
2013if [ "$ignoregooglekeyboard" = "true" ]; then
2014 if ( ! contains "$gapps_list" "keyboardgoogle" ) && ( ! grep -qiE '^override$' "$g_conf" ); then
2015EOFILE
2016keyboardgooglenotremovehack "$build/$1"
2017tee -a "$build/$1" > /dev/null <<'EOFILE'
2018 ignoregooglekeyboard="true[NoRemove]"
2019 install_note="${install_note}nogooglekeyboard_removal"$'\n'; # make note that Google Keyboard will not be removed
2020 else
2021 ignoregooglekeyboard="false[KeyboardGoogle]"
2022 fi
2023fi
2024
2025ignoregooglepackageinstaller="true"
2026for f in $packageinstallerstock_list; do
2027 if [ -e "$SYSTEM/$f" ]; then
2028 ignoregooglepackageinstaller="false"
2029 break; #at least 1 aosp stock file is present
2030 fi
2031done;
2032if [ "$ignoregooglepackageinstaller" = "true" ]; then
2033 if ( ! contains "$gapps_list" "packageinstallergoogle" ) && ( ! grep -qiE '^override$' "$g_conf" ); then
2034 sed -i "\:$SYSTEM/priv-app/GooglePackageInstaller:d" $gapps_removal_list;
2035 ignoregooglepackageinstaller="true[NoRemove]"
2036 install_note="${install_note}nogooglepackageinstaller_removal"$'\n'; # make note that Google Package Installer will not be removed
2037 else
2038 ignoregooglepackageinstaller="false[PackageInstallerGoogle]"
2039 fi
2040fi
2041
2042ignoregoogletag="true"
2043for f in $tagstock_list; do
2044 if [ -e "$SYSTEM/$f" ]; then
2045 ignoregoogletag="false"
2046 break; #at least 1 aosp stock file is present
2047 fi
2048done;
2049if [ "$ignoregoogletag" = "true" ]; then
2050 if ( ! contains "$gapps_list" "taggoogle" ) && ( ! grep -qiE '^override$' "$g_conf" ); then
2051 sed -i "\:$SYSTEM/priv-app/TagGoogle:d" $gapps_removal_list;
2052 ignoregoogletag="true[NoRemove]"
2053 install_note="${install_note}nogoogletag_removal"$'\n'; # make note that Google Tag will not be removed
2054 else
2055 ignoregoogletag="false[TagGoogle]"
2056 fi
2057fi
2058
2059ignoregooglewebview="true"
2060for f in $webviewstock_list; do
2061 if [ -e "$SYSTEM/$f" ]; then
2062 ignoregooglewebview="false"
2063 break; #at least 1 aosp stock file is present
2064 fi
2065done;
2066EOFILE
2067webviewignorehack "$build/$1" # in Nougat Chrome and WebViewStub can also be used as WebViewProvider
2068camerav3compatibilityhack "$build/$1" # in Marshmallow we need to use the legacy camera that uses the older api
2069tee -a "$build/$1" > /dev/null <<'EOFILE'
2070
2071# Process User Application Removals for calculations and subsequent removal
2072if [ -n "$user_remove_list" ]; then
2073 for remove_apk in $user_remove_list; do
2074 testapk=$( echo "$remove_apk" | tr '[:upper:]' '[:lower:]' );
2075 # Add apk extension if user didn't include it
2076 case $testapk in
2077 *".apk" ) ;;
2078 * ) testapk="${testapk}.apk" ;;
2079 esac;
2080 # Create user_remove_folder_list if this is a system/ROM application
2081 for folder in $SYSTEM/app $SYSTEM/priv-app; do # Check all subfolders in /system/app /system/priv-app for the apk
2082 file_count=0; # Reset Counter
2083 file_count=$(find $folder -iname "$testapk" | wc -l);
2084 case $file_count in
2085 0) continue;;
2086EOFILE
2087universalremoverhack "$build/$1" #on kitkat the paths for the universalremover are different
2088tee -a "$build/$1" > /dev/null <<'EOFILE'
2089 break;;
2090 *) echo "$remove_apk" >> $user_remove_multiplefound_log; # Add app to user_remove_multiplefound_log since we found more than 1 instance
2091 break;;
2092 esac;
2093 done;
2094 if [ "$file_count" -eq 0 ]; then
2095 echo "$remove_apk" >> $user_remove_notfound_log;
2096 fi; # Add 'not found' app to user_remove_notfound_log
2097 done;
2098fi;
2099
2100# Removing old Chrome libraries
2101obsolete_libs_list="";
2102for f in $(find $SYSTEM/lib $SYSTEM/lib64 -name 'libchrome.*.so' 2>/dev/null); do
2103 obsolete_libs_list="${obsolete_libs_list}$f"$'\n';
2104done;
2105
2106# Read in gapps removal list from file and append old Chrome libs
2107full_removal_list="$(cat $gapps_removal_list)"$'\n'"${obsolete_libs_list}";
2108
2109# Read in old user removal list from addon.d to allow for persistence
2110addond_remove_folder_list=$(sed -e "1,/# Remove 'user requested' apps (from gapps-config)/d" -e '/;;/,$d' -e 's/ rm -rf //' $SYSTEM/addon.d/70-gapps.sh)
2111
2112# Clean up and sort our lists for space calculations and installation
2113set_progress 0.04;
2114gapps_list=$(echo "${gapps_list}" | sort | sed '/^$/d'); # sort GApps list & remove empty lines
2115aosp_remove_list=$(echo "${aosp_remove_list}" | sort | sed '/^$/d'); # sort AOSP Remove list & remove empty lines
2116full_removal_list=$(echo "${full_removal_list}" | sed '/^$/d'); # Remove empty lines from FINAL GApps Removal list
2117remove_list=$(echo "${remove_list}" | sed '/^$/d'); # Remove empty lines from remove_list
2118user_remove_folder_list=$(echo "${user_remove_folder_list}" | sed '/^$/d'); # Remove empty lines from User Application Removal list
2119
2120log "Installing GApps Zipfile" "$OPENGAZIP"
2121log "Installing GApps Version" "$gapps_version";
2122log "Installing GApps Type" "$gapps_type";
2123log "Config Type" "$config_type";
2124log "Using gapps-config" "$config_file";
2125log "Remove Stock/AOSP Browser" "$remove_browser";
2126log "Remove Stock/AOSP Camera" "$remove_camerastock";
2127log "Remove Stock/AOSP Dialer" "$remove_dialerstock";
2128log "Remove Stock/AOSP Email" "$remove_email";
2129log "Remove Stock/AOSP Gallery" "$remove_gallery";
2130log "Remove Stock/AOSP Launcher" "$remove_launcher";
2131log "Remove Stock/AOSP MMS App" "$remove_mms";
2132log "Remove Stock/AOSP Pico TTS" "$remove_picotts";
2133log "Ignore Google Contacts" "$ignoregooglecontacts";
2134log "Ignore Google Dialer" "$ignoregoogledialer";
2135log "Ignore Google Keyboard" "$ignoregooglekeyboard";
2136log "Ignore Google Package Installer" "$ignoregooglepackageinstaller";
2137log "Ignore Google NFC Tag" "$ignoregoogletag";
2138log "Ignore Google WebView" "$ignoregooglewebview";
2139# _____________________________________________________________________________________________________________________
2140# Perform space calculations
2141ui_print "- Performing system space calculations";
2142ui_print " ";
2143
2144# Perform calculations of core applications
2145core_size=0;
2146for gapp_name in $core_gapps_list; do
2147 get_apparchives "Core/$gapp_name"
2148 for archive in $apparchives; do
2149 case $gapp_name in
2150 setupwizarddefault) if [ "$device_type" != "tablet" ]; then get_appsize "$archive"; fi;;
2151 setupwizardtablet) if [ "$device_type" = "tablet" ]; then get_appsize "$archive"; fi;;
2152 *) get_appsize "$archive";;
2153 esac
2154 core_size=$((core_size + appsize))
2155 done
2156done;
2157
2158# Add swypelibs size to core, if it will be installed
2159if ( ! contains "$gapps_list" "keyboardgoogle" ) || [ "$skipswypelibs" = "false" ]; then
2160 get_appsize "Optional/swypelibs-lib-$arch" # Keep it simple, swypelibs is only lib-$arch
2161 core_size=$((core_size + keybd_lib_size)) # Add Keyboard Lib size to core, if it exists
2162fi
2163
2164# Read and save system partition size details
2165df=$(df -k $SYSTEM | tail -n 1);
2166case $df in
2167 /dev/block/*) df=$(echo "$df" | awk '{ print substr($0, index($0,$2)) }');;
2168esac;
2169total_system_size_kb=$(echo "$df" | awk '{ print $1 }');
2170used_system_size_kb=$(echo "$df" | awk '{ print $2 }');
2171free_system_size_kb=$(echo "$df" | awk '{ print $3 }');
2172log "Total System Size (KB)" "$total_system_size_kb";
2173log "Used System Space (KB)" "$used_system_size_kb";
2174log "Current Free Space (KB)" "$free_system_size_kb";
2175
2176# Perform storage space calculations of existing GApps that will be deleted/replaced
2177reclaimed_gapps_space_kb=$(du -ck $(complete_gapps_list) | tail -n 1 | awk '{ print $1 }');
2178
2179# Perform storage space calculations of other Removals that need to be deleted (Obsolete and Conflicting Apps)
2180set_progress 0.05;
2181reclaimed_removal_space_kb=$(du -ck $(obsolete_gapps_list) | tail -n 1 | awk '{ print $1 }');
2182
2183# Add information to calc.log that will later be added to open_gapps.log to assist user with app removals
2184post_install_size_kb=$((free_system_size_kb + reclaimed_gapps_space_kb)); # Add opening calculations
2185echo ------------------------------------------------------------------ > $calc_log;
2186printf "%7s | %26s | %7s | %7s\n" "TYPE " "DESCRIPTION " "SIZE" " TOTAL" >> $calc_log;
2187printf "%7s | %26s | %7d | %7d\n" "" "Current Free Space" "$free_system_size_kb" "$free_system_size_kb" >> $calc_log;
2188printf "%7s | %26s | + %7d | %7d\n" "Remove" "Existing GApps" "$reclaimed_gapps_space_kb" $post_install_size_kb >> $calc_log;
2189post_install_size_kb=$((post_install_size_kb + reclaimed_removal_space_kb)); # Add reclaimed_removal_space_kb
2190printf "%7s | %26s | + %7d | %7d\n" "Remove" "Obsolete Files" "$reclaimed_removal_space_kb" $post_install_size_kb >> $calc_log;
2191
2192# Perform calculations of AOSP/ROM files that will be deleted
2193set_progress 0.07;
2194for aosp_name in $aosp_remove_list; do
2195 eval "list_name=\$${aosp_name}_list";
2196 aosp_size_kb=0; # Reset counter
2197 for file_name in $list_name; do
2198 if [ -e "$SYSTEM/$file_name" ]; then
2199 file_size_kb=$(du -ck "$SYSTEM/$file_name" | tail -n 1 | awk '{ print $1 }');
2200 aosp_size_kb=$((file_size_kb + aosp_size_kb));
2201 post_install_size_kb=$((post_install_size_kb + file_size_kb));
2202 fi;
2203 done;
2204 log_add "Remove" "$aosp_name" $aosp_size_kb $post_install_size_kb;
2205done;
2206
2207# Perform calculations of User App Removals that will be deleted
2208for remove_folder in $user_remove_folder_list; do
2209 if [ -e "$remove_folder" ]; then
2210 folder_size_kb=$(du -ck "$remove_folder" | tail -n 1 | awk '{ print $1 }');
2211 post_install_size_kb=$((post_install_size_kb + folder_size_kb));
2212 log_add "Remove" "$(basename "$remove_folder")*" "$folder_size_kb" $post_install_size_kb;
2213 fi;
2214done;
2215
2216# Perform calculations of GApps files that will be installed
2217set_progress 0.09
2218post_install_size_kb=$((post_install_size_kb - core_size)) # Add Core GApps
2219log_sub "Install" "Core" $core_size $post_install_size_kb
2220
2221for gapp_name in $gapps_list; do
2222 case $gapp_name in
2223 photos) if [ "$vrmode_compat" = "true" ] && [ "$arch" = "arm64" ] && [ "$rom_build_sdk" -ge "24" ]; then gapp_name="photosvrmode"; fi;; # for now only available on Nougat arm64
2224 movies) if [ "$vrmode_compat" = "true" ] && ( [ "$arch" = "arm" ] || [ "$arch" = "arm64" ] ) && [ "$rom_build_sdk" -ge "24" ]; then gapp_name="moviesvrmode"; fi;; # for now only available on Nougat arm & arm64
2225 *) ;;
2226 esac
2227 get_apparchives "GApps/$gapp_name"
2228 total_appsize=0
2229 for archive in $apparchives; do
2230 get_appsize "$archive"
2231 total_appsize=$((total_appsize + $appsize))
2232 done
2233EOFILE
2234echo "$DATASIZESCODE" >> "$build/$1"
2235tee -a "$build/$1" > /dev/null <<'EOFILE'
2236 post_install_size_kb=$((post_install_size_kb - total_appsize))
2237 log_sub "Install" "$gapp_name" "$total_appsize" "$post_install_size_kb"
2238done;
2239
2240# Perform calculations of required Buffer Size
2241set_progress 0.11
2242if ( grep -qiE '^smallbuffer$' "$g_conf" ); then
2243 buffer_size_kb=$small_buffer_size
2244fi
2245
2246post_install_size_kb=$((post_install_size_kb - buffer_size_kb));
2247log_sub "" "Buffer Space" "$buffer_size_kb" $post_install_size_kb;
2248echo ------------------------------------------------------------------ >> $calc_log;
2249
2250if [ "$post_install_size_kb" -ge 0 ]; then
2251 printf "%47s | %7d\n" " Post Install Free Space" $post_install_size_kb >> $calc_log;
2252 log "Post Install Free Space (KB)" "$post_install_size_kb << See Calculations Below";
2253else
2254 additional_size_kb=$((post_install_size_kb * -1));
2255 printf "%47s | %7d\n" "Additional Space Required" $additional_size_kb >> $calc_log;
2256 log "Additional Space Required (KB)" "$additional_size_kb << See Calculations Below";
2257fi;
2258
2259# Finish up Calculation Log
2260echo ------------------------------------------------------------------ >> $calc_log;
2261if [ -n "$user_remove_folder_list" ]; then
2262 echo " * User Requested Removal" >> $calc_log;
2263fi;
2264
2265# Check whether there's enough free space to complete this installation
2266if [ "$post_install_size_kb" -lt 0 ]; then
2267 # We don't have enough system space to install everything user requested
2268 ui_print "Insufficient storage space available in";
2269 ui_print "System partition. You may want to use a";
2270 ui_print "smaller Open GApps package or consider";
2271 ui_print "removing some apps using gapps-config.";
2272 ui_print "See:'$log_folder/open_gapps_log.txt'";
2273 ui_print "for complete details and information.";
2274 ui_print " ";
2275 install_note="${install_note}system_space_msg"$'\n'; # make note that there is insufficient space in system to install
2276 abort "$E_NOSPACE";
2277fi;
2278
2279# Check to see if this is the 'real thing' or only a test
2280if ( grep -qiE '^test$' "$g_conf" ); then # user has selected a 'test' install ONLY
2281 ui_print "- Exiting Simulated Install";
2282 ui_print " ";
2283 install_note="${install_note}simulation_msg"$'\n'; # make note that this is only a test installation
2284 quit;
2285 exxit 0;
2286fi;
2287# _____________________________________________________________________________________________________________________
2288# Perform Removals
2289# Remove ALL Existing GApps files
2290set_progress 0.13;
2291ui_print "- Removing existing/obsolete Apps";
2292ui_print " ";
2293rm -rf $(complete_gapps_list);
2294
2295# Remove Obsolete and Conflicting Apps
2296rm -rf $(obsolete_gapps_list);
2297
2298# Remove Stock/AOSP Apps and add Removals to addon.d script
2299aosp_remove_list=$(echo "${aosp_remove_list}" | sort -r); # reverse sort list for more readable output
2300for aosp_name in $aosp_remove_list; do
2301 eval "list_name=\$${aosp_name}_list";
2302 list_name=$(echo "${list_name}" | sort -r); # reverse sort list for more readable output
2303 for file_name in $list_name; do
2304 rm -rf "$SYSTEM/$file_name";
2305 sed -i "\:# Remove Stock/AOSP apps (from GApps Installer):a \ rm -rf \$SYS/$file_name" $bkup_tail;
2306 done;
2307done;
2308
2309# Add saved addon.d User App Removals to make them persistent through repeat dirty GApps installs though the app may have already been removed
2310user_remove_folder_list=$(echo -e "${user_remove_folder_list}\n${addond_remove_folder_list}" | sort -u | sed '/^$/d') # remove duplicates and empty lines
2311
2312# Perform User App Removals and add Removals to addon.d script
2313user_remove_folder_list=$(echo "${user_remove_folder_list}" | sort -r); # reverse sort list for more readable output
2314for user_app in $user_remove_folder_list; do
2315 rm -rf "$user_app";
2316 sed -i "\:# Remove 'user requested' apps (from gapps-config):a \ rm -rf $user_app" $bkup_tail;
2317done;
2318
2319# Remove any empty folders we may have created during the removal process
2320for i in $SYSTEM/app $SYSTEM/priv-app $SYSTEM/vendor/pittpatt $SYSTEM/usr/srec $SYSTEM/etc/preferred-apps; do
2321 find "$i" -type d | xargs -r rmdir -p --ignore-fail-on-non-empty;
2322done;
2323# _____________________________________________________________________________________________________________________
2324# Perform Installs
2325ui_print "- Installing core GApps";
2326set_progress 0.15;
2327for gapp_name in $core_gapps_list; do
2328 get_apparchives "Core/$gapp_name"
2329 for archive in $apparchives; do
2330 case $gapp_name in
2331 setupwizarddefault) if [ "$device_type" != "tablet" ]; then extract_app "$archive"; fi;;
2332 setupwizardtablet) if [ "$device_type" = "tablet" ]; then extract_app "$archive"; fi;;
2333 *) extract_app "$archive";;
2334 esac
2335 done
2336done;
2337ui_print " ";
2338set_progress 0.25;
2339
2340EOFILE
2341echo "$KEYBDINSTALLCODE" >> "$build/$1"
2342echo "$DATAINSTALLCODE" >> "$build/$1"
2343tee -a "$build/$1" > /dev/null <<'EOFILE'
2344# Progress Bar increment calculations for GApps Install process
2345set_progress 0.30;
2346gapps_count=$(echo "${gapps_list}" | wc -w); # Count number of GApps left to be installed
2347if [ "$gapps_count" -lt 1 ]; then gapps_count=1; fi; # Prevent division by zero
2348incr_amt=$(( 5000 / gapps_count )); # Determine increment factor of progress bar during GApps installation
2349prog_bar=3000; # Set Progress Bar start point (0.3000) for below
2350
2351# Install the rest of GApps still in $gapps_list
2352for gapp_name in $gapps_list; do
2353 case $gapp_name in
2354 photos) if [ "$vrmode_compat" = "true" ] && [ "$arch" = "arm64" ] && [ "$rom_build_sdk" -ge "24" ]; then gapp_name="photosvrmode"; fi;; # for now only available on Nougat arm64
2355 movies) if [ "$vrmode_compat" = "true" ] && ( [ "$arch" = "arm" ] || [ "$arch" = "arm64" ] ) && [ "$rom_build_sdk" -ge "24" ]; then gapp_name="moviesvrmode"; fi;; # for now only available on Nougat arm & arm64
2356 *) ;;
2357 esac
2358 ui_print "- Installing $gapp_name"
2359 get_apparchives "GApps/$gapp_name"
2360 for archive in $apparchives; do
2361 extract_app "$archive" # Installing User Selected GApps
2362 done
2363 prog_bar=$((prog_bar + incr_amt))
2364 set_progress 0.$prog_bar
2365done;
2366
2367ui_print " ";
2368ui_print "- Miscellaneous tasks";
2369ui_print " ";
2370
2371# Use Gms (Google Play services) for feedback/bug reporting (instead of org.cyanogenmod.bugreport or others)
2372sed -i "s/ro.error.receiver.system.apps=.*/ro.error.receiver.system.apps=com.google.android.gms/g" $SYSTEM/build.prop
2373sed -i "\:# Apply build.prop changes (from GApps Installer):a \ sed -i \"s/ro.error.receiver.system.apps=.*/ro.error.receiver.system.apps=com.google.android.gms/g\" \$SYS/build.prop" $bkup_tail
2374
2375# Enable Google Assistant
2376if ( grep -qiE '^googleassistant$' "$g_conf" ); then #TODO this is not enabled by default atm; because Assistant still has various regressions compared to Google Now
2377 if ! grep -q "ro.opa.eligible_device=" $SYSTEM/build.prop; then
2378 echo "ro.opa.eligible_device=true" >> $SYSTEM/build.prop
2379 fi
2380 sed -i "\:# Apply build.prop changes (from GApps Installer):a \ if ! grep -q \"ro.opa.eligible_device=\" $SYSTEM/build.prop; then echo \"ro.opa.eligible_device=true\" >> \$SYS/build.prop; fi" $bkup_tail
2381fi
2382
2383# Create FaceLock lib symlink if installed
2384if ( contains "$gapps_list" "faceunlock" ); then
2385 install -d "$SYSTEM/app/FaceLock/lib/$arch"
2386 ln -sfn "$SYSTEM/$libfolder/$faceLock_lib_filename" "$SYSTEM/app/FaceLock/lib/$arch/$faceLock_lib_filename"
2387 # Add same code to backup script to ensure symlinks are recreated on addon.d restore
2388 sed -i "\:# Recreate required symlinks (from GApps Installer):a \ ln -sfn \"\$SYS/$libfolder/$faceLock_lib_filename\" \"\$SYS/app/FaceLock/lib/$arch/$faceLock_lib_filename\"" $bkup_tail
2389 sed -i "\:# Recreate required symlinks (from GApps Installer):a \ install -d \"\$SYS/app/FaceLock/lib/$arch\"" $bkup_tail
2390fi
2391
2392# Create Markup lib symlink if installed
2393if ( contains "$gapps_list" "markup" ); then
2394 install -d "$SYSTEM/app/MarkupGoogle/lib/$arch"
2395 ln -sfn "$SYSTEM/$libfolder/$markup_lib_filename" "$SYSTEM/app/MarkupGoogle/lib/$arch/$markup_lib_filename"
2396 # Add same code to backup script to ensure symlinks are recreated on addon.d restore
2397 sed -i "\:# Recreate required symlinks (from GApps Installer):a \ ln -sfn \"$SYSTEM/$libfolder/$markup_lib_filename\" \"$SYSTEM/app/MarkupGoogle/lib/$arch/$markup_lib_filename\"" $bkup_tail
2398 sed -i "\:# Recreate required symlinks (from GApps Installer):a \ install -d \"$SYSTEM/app/MarkupGoogle/lib/$arch\"" $bkup_tail
2399fi
2400
2401EOFILE
2402if [ "$API" -lt "24" ]; then # Only 5.1 and 6.0
2403 echo '# Create TVRemote lib symlink if installed
2404if ( contains "$gapps_list" "tvremote" ); then
2405 install -d "$SYSTEM/app/AtvRemoteService/lib/$arch"
2406 ln -sfn "$SYSTEM/$libfolder/$atvremote_lib_filename" "$SYSTEM/app/AtvRemoteService/lib/$arch/$atvremote_lib_filename"
2407 # Add same code to backup script to ensure symlinks are recreated on addon.d restore
2408 sed -i "\:# Recreate required symlinks (from GApps Installer):a \ ln -sfn \"\$SYS/$libfolder/$atvremote_lib_filename\" \"\$SYS/app/AtvRemoteService/lib/$arch/$atvremote_lib_filename\"" $bkup_tail
2409 sed -i "\:# Recreate required symlinks (from GApps Installer):a \ install -d \"\$SYS/app/AtvRemoteService/lib/$arch\"" $bkup_tail
2410fi
2411' >> "$build/$1"
2412fi
2413
2414if [ "$API" -lt "23" ]; then
2415 echo '# Create WebView lib symlink if WebView was installed
2416if ( contains "$gapps_list" "webviewgoogle" ); then
2417 install -d "$SYSTEM/app/WebViewGoogle/lib/$arch"
2418 ln -sfn "$SYSTEM/$libfolder/$WebView_lib_filename" "$SYSTEM/app/WebViewGoogle/lib/$arch/$WebView_lib_filename"
2419 # Add same code to backup script to ensure symlinks are recreated on addon.d restore
2420 sed -i "\:# Recreate required symlinks (from GApps Installer):a \ ln -sfn \"$SYSTEM/$libfolder/$WebView_lib_filename\" \"$SYSTEM/app/WebViewGoogle/lib/$arch/$WebView_lib_filename\"" $bkup_tail
2421 sed -i "\:# Recreate required symlinks (from GApps Installer):a \ install -d \"$SYSTEM/app/WebViewGoogle/lib/$arch\"" $bkup_tail
2422 if [ -n "$fbarch" ]; then # on 64bit we also need to add 32 bit libs
2423 install -d "$SYSTEM/app/WebViewGoogle/lib/$fbarch"
2424 ln -sfn "$SYSTEM/lib/$WebView_lib_filename" "$SYSTEM/app/WebViewGoogle/lib/$fbarch/$WebView_lib_filename"
2425 # Add same code to backup script to ensure symlinks are recreated on addon.d restore
2426 sed -i "\:# Recreate required symlinks (from GApps Installer):a \ ln -sfn \"\$SYS/lib/$WebView_lib_filename\" \"$SYSTEM/app/WebViewGoogle/lib/$fbarch/$WebView_lib_filename\"" $bkup_tail
2427 sed -i "\:# Recreate required symlinks (from GApps Installer):a \ install -d \"\$SYS/app/WebViewGoogle/lib/$fbarch\"" $bkup_tail
2428 fi
2429fi
2430' >> "$build/$1"
2431fi
2432tee -a "$build/$1" > /dev/null <<'EOFILE'
2433
2434# Copy g.prop over to /system/etc
2435cp -f "$TMP/g.prop" "$g_prop"
2436# _____________________________________________________________________________________________________________________
2437# Build and Install Addon.d Backup Script
2438# Add 'other' Removals to addon.d script
2439set_progress 0.80;
2440other_list=$(echo "${other_list}" | sort -r); # reverse sort list for more readable output
2441for other_name in $other_list; do
2442 sed -i "\:# Remove 'other' apps (per installer.data):a \ rm -rf \$SYS/$other_name" $bkup_tail;
2443done;
2444
2445# Add 'priv-app' Removals to addon.d script
2446privapp_list=$(echo "${privapp_list}" | sort -r); # reverse sort list for more readable output
2447for privapp_name in $privapp_list; do
2448 sed -i "\:# Remove 'priv-app' apps from 'app' (per installer.data):a \ rm -rf \$SYS/$privapp_name" $bkup_tail;
2449done;
2450
2451# Add 'required' Removals to addon.d script
2452reqd_list=$(echo "${reqd_list}" | sort -r); # reverse sort list for more readable output
2453for reqdapp_name in $reqd_list; do
2454 reqdapp_name=$(echo ${reqdapp_name/\/system/\$SYS})
2455 sed -i "\:# Remove 'required' apps (per installer.data):a \ rm -rf $reqdapp_name" $bkup_tail;
2456done;
2457
2458# Create final addon.d script in system
2459bkup_header="#!/sbin/sh\n# \n# ADDOND_VERSION=2\n# \n# $SYSTEM/addon.d/70-gapps.sh\n#\n. /tmp/backuptool.functions\n\nif [ -z \$backuptool_ab ]; then\n SYS=\$S\n TMP="/tmp"\nelse\n SYS="/postinstall/system"\n TMP="/postinstall/tmp"\nfi\n\nlist_files() {\ncat <<EOF"
2460bkup_list="$bkup_list"$'\n'"etc/g.prop"; # add g.prop to backup list
2461bkup_list=$(echo "${bkup_list}" | sort -u| sed '/^$/d'); # sort list & remove duplicates and empty lines
2462install -d $SYSTEM/addon.d;
2463echo -e "$bkup_header" > $SYSTEM/addon.d/70-gapps.sh;
2464echo -e "$bkup_list" >> $SYSTEM/addon.d/70-gapps.sh;
2465cat $bkup_tail >> $SYSTEM/addon.d/70-gapps.sh;
2466# _____________________________________________________________________________________________________________________
2467# Fix Permissions
2468
2469set_progress 0.85
2470find $SYSTEM/vendor/pittpatt -type d -exec chown 0:2000 '{}' \; # Change pittpatt folders to root:shell per Google Factory Settings
2471
2472set_perm 0 0 755 "$SYSTEM/addon.d/70-gapps.sh"
2473ch_con "$SYSTEM/addon.d/70-gapps.sh"
2474
2475set_perm 0 0 644 "$g_prop"
2476ch_con "$g_prop"
2477
2478set_progress 0.92
2479quit
2480
2481ui_print "- Installation complete!"
2482ui_print " "
2483
2484if ( contains "$gapps_list" "dialergoogle" ); then
2485 ui_print "You installed Google Dialer."
2486 ui_print "Please set it as default Phone"
2487 ui_print "application to prevent calls"
2488 ui_print "from rebooting your device."
2489 ui_print "See https://goo.gl/LTIJ0o"
2490
2491 # set Google Dialer as default; based on the work of osm0sis @ xda-developers
2492 setver="122" # lowest version in MM, tagged at 6.0.0
2493 setsec="/data/system/users/0/settings_secure.xml"
2494 if [ -f "$setsec" ]; then
2495 if grep -q 'dialer_default_application' "$setsec"; then
2496 if ! grep -q 'dialer_default_application" value="com.google.android.dialer' "$setsec"; then
2497 curentry="$(grep -o 'dialer_default_application" value=.*$' "$setsec")"
2498 newentry='dialer_default_application" value="com.google.android.dialer" package="android" />\r'
2499 sed -i "s;${curentry};${newentry};" "$setsec"
2500 fi
2501 else
2502 max="0"
2503 for i in $(grep -o 'id=.*$' "$setsec" | cut -d '"' -f 2); do
2504 test "$i" -gt "$max" && max="$i"
2505 done
2506 entry='<setting id="'"$((max + 1))"'" name="dialer_default_application" value="com.google.android.dialer" package="android" />\r'
2507 sed -i "/<settings version=\"/a\ \ ${entry}" "$setsec"
2508 fi
2509 else
2510 if [ ! -d "/data/system/users/0" ]; then
2511 install -d "/data/system/users/0"
2512 chown -R 1000:1000 "/data/system"
2513 chmod -R 775 "/data/system"
2514 chmod 700 "/data/system/users/0"
2515 fi
2516 { echo -e "<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>\r";
2517 echo -e '<settings version="'$setver'">\r';
2518 echo -e ' <setting id="1" name="dialer_default_application" value="com.google.android.dialer" package="android" />\r';
2519 echo -e '</settings>'; } > "$setsec"
2520 fi
2521 chown 1000:1000 "$setsec"
2522 chmod 600 "$setsec"
2523fi
2524
2525exxit 0
2526EOFILE
2527}