Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2a5fcbde authored by Hajime Morrita's avatar Hajime Morrita
Browse files

PinnerService Pin split APKs (behind a flag).

This CL lets PinnerService pin the split APKs, in addition to the
base APK. This matters when the APK is built as AAB.

This behavior is hidden behind "pin_split_apks" DeviceConfig flag,
which is false for now: This is becaue AAB-built apps have
broken pinlist for the base APK and is missing the list for
split APKs, ending up pinning too much. The flag should be flipped
once the these APKs get proper pinlists.

Bug: 174698005
Test: Ran following commands and inspected the output:
  $ adb shell device_config put runtime_native_boot pin_camera true && \
    adb shell device_config put runtime_native_boot pin_split_apks true
  $ adb shell cmd pinner repin && adb shell dumpsys pinner
  $ adb shell device_config put runtime_native_boot pin_camera true && \
    adb shell device_config put runtime_native_boot pin_split_apks false
  $ adb shell cmd pinner repin && adb shell dumpsys pinner
Change-Id: Ic9c82b2538095e53daf9c1ef6557f487e8fac0a4
parent 33266b39
Loading
Loading
Loading
Loading
+40 −12
Original line number Diff line number Diff line
@@ -521,6 +521,13 @@ public final class PinnerService extends SystemService {
        return pinKeys;
    }

    private static boolean shouldPinSplitApks() {
        // For now this is disabled by default bcause the pinlist support for split APKs are
        // missing in the toolchain. This flag should be removed once it is ready. b/174697187.
        return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_RUNTIME_NATIVE_BOOT,
                "pin_split_apks", false);
    }

    private synchronized ArraySet<Integer> getPinKeys() {
        return mPinKeys;
    }
@@ -672,14 +679,32 @@ public final class PinnerService extends SystemService {
            mPinnedApps.put(key, pinnedApp);
        }


        // pin APK
        int pinSizeLimit = getSizeLimitForKey(key);
        String apk = appInfo.sourceDir;
        PinnedFile pf = pinFile(apk, pinSizeLimit, /*attemptPinIntrospection=*/true);
        final int pinSizeLimit = getSizeLimitForKey(key);
        List<String> apks = new ArrayList<>();
        apks.add(appInfo.sourceDir);

        if (shouldPinSplitApks() && appInfo.splitSourceDirs != null) {
            for (String splitApk : appInfo.splitSourceDirs) {
                apks.add(splitApk);
            }
        }

        int apkPinSizeLimit = pinSizeLimit;
        for (String apk: apks) {
            if (apkPinSizeLimit <= 0) {
                Slog.w(TAG, "Reached to the pin size limit. Skipping: " + apk);
                // Continue instead of break to print all skipped APK names.
                continue;
            }

            PinnedFile pf = pinFile(apk, apkPinSizeLimit, /*attemptPinIntrospection=*/true);
            if (pf == null) {
                Slog.e(TAG, "Failed to pin " + apk);
            return;
                continue;
            }

            if (DEBUG) {
                Slog.i(TAG, "Pinned " + pf.fileName);
            }
@@ -687,6 +712,9 @@ public final class PinnerService extends SystemService {
                pinnedApp.mFiles.add(pf);
            }

            apkPinSizeLimit -= pf.bytesPinned;
        }

        // determine the ABI from either ApplicationInfo or Build
        String abi = appInfo.primaryCpuAbi != null ? appInfo.primaryCpuAbi :
                Build.SUPPORTED_ABIS[0];
@@ -703,7 +731,7 @@ public final class PinnerService extends SystemService {

        //not pinning the oat/odex is not a fatal error
        for (String file : files) {
            pf = pinFile(file, pinSizeLimit, /*attemptPinIntrospection=*/false);
            PinnedFile pf = pinFile(file, pinSizeLimit, /*attemptPinIntrospection=*/false);
            if (pf != null) {
                synchronized (this) {
                    if (PROP_PIN_ODEX) {