# AOSPA GApps Installation Script - Updated: 2013-11-25

ui_print(" ");
ui_print("#############################################");
ui_print("#  ___   _      ___    _                    #");
ui_print("# | _ \ /_\    / __|  /_\   _ __  _ __  ___ #");
ui_print("# |  _// _ \  | (_ | / _ \ | '_ \| '_ \(_-< #");
ui_print("# |_| /_/ \_\  \___|/_/ \_\| .__/| .__//__/ #");
ui_print("#                          |_|   |_|        #");
ui_print("#############################################");
ui_print(" ");
ui_print("Paranoid Android GApps Full 4.4 - 20131126");
ui_print(" ");
sleep(3);
ui_print("Mounting system...");
run_program("/sbin/busybox", "mount", "/system");
ui_print(" ");

# Checking to make certain user has a 4.4.x ROM Installed - If not, we abort
ifelse(
    is_substring("4.4", file_getprop("/system/build.prop","ro.build.version.release")),
    (
        ui_print("Android 4.4 ROM detected");
        ui_print(" ");
    ),
    (
        ui_print("**** Incompatible Android ROM detected ****");
        ui_print(" ");
        ui_print("This GApps package is for Android 4.4.x ONLY");
        ui_print(" ");
        ui_print("******** GApps Installation failed *******");
        ui_print(" ");
        ui_print("Unmounting system...");
        run_program("/sbin/busybox", "umount", "/system");
        ui_print(" ");
        sleep(7);
        abort("Aborting...");
    )
);

show_progress(0.8,25);

# Removing pieces that may be left over from other GApps or ROM's
delete(
    "/system/app/BrowserProviderProxy.apk",
    "/system/app/Calendar.apk",
    "/system/app/Gmail.apk",
    "/system/app/GmsCore.apk",
    "/system/app/GoogleCalendar.apk",
    "/system/app/GoogleCalendarSyncAdapter.apk",
    "/system/app/GoogleCloudPrint.apk",
    "/system/app/GoogleHangouts.apk",
    "/system/app/GoogleKeep.apk",
    "/system/app/GoogleOneTimeInitializer.apk",
    "/system/app/GooglePlus.apk",
    "/system/app/PartnerBookmarksProvider.apk",
    "/system/app/QuickSearchBox.apk",
    "/system/app/Talk.apk",
    "/system/app/Vending.apk",
    "/system/app/Youtube.apk",
    "/system/priv-app/Calendar.apk",
    "/system/priv-app/GmsCore.apk",
    "/system/priv-app/GoogleNow.apk",
    "/system/priv-app/QuickSearchBox.apk",
    "/system/priv-app/Vending.apk"
);

# Remove apps from 'app' that need to be installed in 'priv-app'
delete(
    "/system/app/CalendarProvider.apk",
    "/system/app/GoogleBackupTransport.apk",
    "/system/app/GoogleFeedback.apk",
    "/system/app/GoogleLoginService.apk",
    "/system/app/GooglePartnerSetup.apk",
    "/system/app/GoogleServicesFramework.apk",
    "/system/app/OneTimeInitializer.apk",
    "/system/app/Phonesky.apk",
    "/system/app/PrebuiltGmsCore.apk",
    "/system/app/SetupWizard.apk",
    "/system/app/talkback.apk",
    "/system/app/Velvet.apk",
    "/system/app/Wallet.apk"
);

# Remove .odex files since they're no longer needed
delete(
    "/system/app/CalendarGoogle.odex",
    "/system/app/GenieWidget.odex",
    "/system/app/Gmail2.odex",
    "/system/app/GoogleContactsSyncAdapter.odex",
    "/system/app/GoogleEars.odex",
    "/system/app/GoogleTTS.odex",
    "/system/app/Keep.odex",
    "/system/app/MediaUploader.odex",
    "/system/framework/com.google.android.maps.odex",
    "/system/framework/com.google.android.media.effects.odex",
    "/system/framework/com.google.widevine.software.drm.odex",
    "/system/priv-app/CalendarProvider.odex",
    "/system/priv-app/GoogleBackupTransport.odex",
    "/system/priv-app/GoogleFeedback.odex",
    "/system/priv-app/GoogleLoginService.odex",
    "/system/priv-app/GooglePartnerSetup.odex",
    "/system/priv-app/GoogleServicesFramework.odex",
    "/system/priv-app/OneTimeInitializer.odex",
    "/system/priv-app/SetupWizard.odex"
);

# Removing lib that is no longer included with Google+ (check to make certain it doesn't show up in another app)
delete("/system/lib/libstlport_shared.so");

# Removing the stock AOSP launcher for the new GoogleHome version with more features
delete("/system/priv-app/Launcher2.apk","/system/priv-app/Launcher3.apk","/system/app/Launcher2.apk","/system/app/Launcher3.apk");

# Removing AOSP Keyboard and library (since we're adding Google Keyboard)
delete("/system/app/LatinIME.apk","/system/lib/libjni_latinime.so");

# Removing Keyboard odex and Factory Image libs (to replace with updated version from Play Store)
delete("/system/app/LatinImeGoogle.odex","/system/lib/libjni_latinimegoogle.so");

# Removing the Pico TTS app due to crashing problems with early 4.4 builds.
delete("/system/app/PicoTts.apk");

ui_print("Copying files...");
ui_print(" ");
package_extract_dir("system", "/system");

package_extract_dir("optional", "/tmp");
package_extract_file("install-optional.sh", "/tmp/install-optional.sh");
set_perm(0, 0, 0777, "/tmp/install-optional.sh");
run_program("/tmp/install-optional.sh", "");

show_progress(0.2, 6);
ui_print("Fixing Permissions...");
ui_print(" ");
set_perm(0, 0, 0755, "/system/addon.d/70-gapps.sh");
set_perm_recursive(0, 0, 0755, 0644, "/system/app");
set_perm_recursive(0, 0, 0755, 0644, "/system/priv-app");

ui_print("Unmounting system...");
ui_print(" ");
run_program("/sbin/busybox", "umount", "/system");
ui_print("GApps Installation Complete!");
ui_print(" ");
sleep(3);
