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

Commit da208016 authored by Yurii Zubrytskyi's avatar Yurii Zubrytskyi
Browse files

[incfs] Make native library extraction async

IncrementalService can create the library files beforehand, but
delay filling in their data. As it takes quite a while in
general (over a second in cases when the phone is busy), it's
better to run the unzipping and filling in a separate thread
and only make sure it finishes before the whole installation
process is complete.
This speeds up the megacity.apk installation by ~250-300ms,
1000-1100ms -> 750-800ms

Bug: 153513507
Test: adb install megacity.apk

Change-Id: Ia44f7e45b9e0abaebdfb6fe5352f9dcf29ab4ece
parent b78a0f46
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -109,4 +109,9 @@ interface IIncrementalService {
     * Setting up native library directories and extract native libs onto a storage.
     */
    boolean configureNativeBinaries(int storageId, in @utf8InCpp String apkFullPath, in @utf8InCpp String libDirRelativePath, in @utf8InCpp String abi);

    /**
     * Waits until all native library extraction is done for the storage
     */
    boolean waitForNativeBinariesExtraction(int storageId);
}
+14 −0
Original line number Diff line number Diff line
@@ -480,4 +480,18 @@ public final class IncrementalStorage {
            return false;
        }
    }

    /**
     * Waits for all native binary extraction operations to complete on the storage.
     *
     * @return Success of not.
     */
    public boolean waitForNativeBinariesExtraction() {
        try {
            return mService.waitForNativeBinariesExtraction(mId);
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
            return false;
        }
    }
}
+15 −1
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ import static android.system.OsConstants.S_IXGRP;
import static android.system.OsConstants.S_IXOTH;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageParser;
import android.content.pm.PackageParser.PackageLite;
@@ -40,6 +39,7 @@ import android.os.incremental.IncrementalManager;
import android.os.incremental.IncrementalStorage;
import android.system.ErrnoException;
import android.system.Os;
import android.util.ArraySet;
import android.util.Slog;

import dalvik.system.CloseGuard;
@@ -545,4 +545,18 @@ public class NativeLibraryHelper {
        }
        return false;
    }

    /**
     * Wait for all native library extraction to complete for the passed storages.
     *
     * @param incrementalStorages A list of the storages to wait for.
     */
    public static void waitForNativeBinariesExtraction(
            ArraySet<IncrementalStorage> incrementalStorages) {
        for (int i = 0; i < incrementalStorages.size(); ++i) {
            IncrementalStorage storage = incrementalStorages.valueAtUnchecked(i);
            storage.waitForNativeBinariesExtraction();
        }
    }

}
+11 −0
Original line number Diff line number Diff line
@@ -263,6 +263,7 @@ import android.os.UserHandle;
import android.os.UserManager;
import android.os.UserManagerInternal;
import android.os.incremental.IncrementalManager;
import android.os.incremental.IncrementalStorage;
import android.os.storage.DiskInfo;
import android.os.storage.IStorageManager;
import android.os.storage.StorageEventListener;
@@ -16596,6 +16597,7 @@ public class PackageManagerService extends IPackageManager.Stub
     * locks on {@link #mLock}.
     */
    private void executePostCommitSteps(CommitRequest commitRequest) {
        final ArraySet<IncrementalStorage> incrementalStorages = new ArraySet<>();
        for (ReconciledPackage reconciledPkg : commitRequest.reconciledPackages.values()) {
            final boolean instantApp = ((reconciledPkg.scanResult.request.scanFlags
                            & PackageManagerService.SCAN_AS_INSTANT_APP) != 0);
@@ -16603,6 +16605,14 @@ public class PackageManagerService extends IPackageManager.Stub
            final String packageName = pkg.getPackageName();
            final boolean onIncremental = mIncrementalManager != null
                    && isIncrementalPath(pkg.getCodePath());
            if (onIncremental) {
                IncrementalStorage storage = mIncrementalManager.openStorage(pkg.getCodePath());
                if (storage == null) {
                    throw new IllegalArgumentException(
                            "Install: null storage for incremental package " + packageName);
                }
                incrementalStorages.add(storage);
            }
            prepareAppDataAfterInstallLIF(pkg);
            if (reconciledPkg.prepareResult.clearCodeCache) {
                clearAppDataLIF(pkg, UserHandle.USER_ALL, FLAG_STORAGE_DE | FLAG_STORAGE_CE
@@ -16700,6 +16710,7 @@ public class PackageManagerService extends IPackageManager.Stub
            notifyPackageChangeObserversOnUpdate(reconciledPkg);
        }
        NativeLibraryHelper.waitForNativeBinariesExtraction(incrementalStorages);
    }
    private void notifyPackageChangeObserversOnUpdate(ReconciledPackage reconciledPkg) {
+16 −6
Original line number Diff line number Diff line
@@ -116,11 +116,14 @@ binder::Status BinderIncrementalService::openStorage(const std::string& path,
    return ok();
}

binder::Status BinderIncrementalService::createStorage(const std::string& path,
                                                       const DataLoaderParamsParcel& params,
binder::Status BinderIncrementalService::createStorage(
        const std::string& path, const DataLoaderParamsParcel& params,
        const ::android::sp<::android::content::pm::IDataLoaderStatusListener>& listener,
        int32_t createMode, int32_t* _aidl_return) {
    *_aidl_return = mImpl.createStorage(path, const_cast<DataLoaderParamsParcel&&>(params), listener, android::incremental::IncrementalService::CreateOptions(createMode));
    *_aidl_return =
            mImpl.createStorage(path, const_cast<DataLoaderParamsParcel&&>(params), listener,
                                android::incremental::IncrementalService::CreateOptions(
                                        createMode));
    return ok();
}

@@ -181,7 +184,8 @@ static std::tuple<int, incfs::FileId, incfs::NewFileParams> toMakeFileParams(
    if (!params.signature) {
        nfp.signature = {};
    } else {
        nfp.signature = {(const char*)params.signature->data(), (IncFsSize)params.signature->size()};
        nfp.signature = {(const char*)params.signature->data(),
                         (IncFsSize)params.signature->size()};
    }
    return {0, id, nfp};
}
@@ -278,6 +282,12 @@ binder::Status BinderIncrementalService::configureNativeBinaries(
    return ok();
}

binder::Status BinderIncrementalService::waitForNativeBinariesExtraction(int storageId,
                                                                         bool* _aidl_return) {
    *_aidl_return = mImpl.waitForNativeBinariesExtraction(storageId);
    return ok();
}

} // namespace android::os::incremental

jlong Incremental_IncrementalService_Start() {
Loading