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

Commit 5e860ba1 authored by Alex Buynytskyy's avatar Alex Buynytskyy
Browse files

Checking LOADER_USAGE_STATS before enabling read logs.

Bug: b/152633648
Test: atest PackageManagerShellCommandTest PackageManagerShellCommandIncrementalTest IncrementalServiceTest
Change-Id: Ic747a51b97b785c627c95bddecc6834ef602ff30
parent 431c3abc
Loading
Loading
Loading
Loading
+7 −0
Original line number Original line Diff line number Diff line
@@ -37,6 +37,13 @@ interface IIncrementalService {
    int createStorage(in @utf8InCpp String path, in DataLoaderParamsParcel params, in IDataLoaderStatusListener listener, int createMode);
    int createStorage(in @utf8InCpp String path, in DataLoaderParamsParcel params, in IDataLoaderStatusListener listener, int createMode);
    int createLinkedStorage(in @utf8InCpp String path, int otherStorageId, int createMode);
    int createLinkedStorage(in @utf8InCpp String path, int otherStorageId, int createMode);


    /**
     * Changes storage params. Returns 0 on success, and -errno on failure.
     * Use enableReadLogs to switch pages read logs reporting on and off.
     * Returns 0 on success, and - errno on failure: permission check or remount.
     */
    int setStorageParams(int storageId, boolean enableReadLogs);

    /**
    /**
     * Bind-mounts a path under a storage to a full path. Can be permanent or temporary.
     * Bind-mounts a path under a storage to a full path. Can be permanent or temporary.
     */
     */
+19 −0
Original line number Original line Diff line number Diff line
@@ -19,11 +19,13 @@ package android.os.incremental;
import android.annotation.IntDef;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SystemService;
import android.annotation.SystemService;
import android.content.Context;
import android.content.Context;
import android.content.pm.DataLoaderParams;
import android.content.pm.DataLoaderParams;
import android.content.pm.IDataLoaderStatusListener;
import android.content.pm.IDataLoaderStatusListener;
import android.os.RemoteException;
import android.os.RemoteException;
import android.system.ErrnoException;
import android.util.SparseArray;
import android.util.SparseArray;


import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.GuardedBy;
@@ -319,6 +321,23 @@ public final class IncrementalManager {
        return nativeUnsafeGetFileSignature(path);
        return nativeUnsafeGetFileSignature(path);
    }
    }


    /**
     * Sets storage parameters.
     *
     * @param enableReadLogs - enables or disables read logs. Caller has to have a permission.
     */
    @RequiresPermission(android.Manifest.permission.LOADER_USAGE_STATS)
    public void setStorageParams(int storageId, boolean enableReadLogs) throws ErrnoException {
        try {
            int res = mService.setStorageParams(storageId, enableReadLogs);
            if (res < 0) {
                throw new ErrnoException("setStorageParams", -res);
            }
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
        }
    }

    /* Native methods */
    /* Native methods */
    private static native boolean nativeIsEnabled();
    private static native boolean nativeIsEnabled();
    private static native boolean nativeIsIncrementalPath(@NonNull String path);
    private static native boolean nativeIsIncrementalPath(@NonNull String path);
+22 −0
Original line number Original line Diff line number Diff line
@@ -21,6 +21,7 @@ import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.annotation.SystemApi;
import android.app.Service;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.content.pm.DataLoaderParams;
import android.content.pm.DataLoaderParams;
import android.content.pm.DataLoaderParamsParcel;
import android.content.pm.DataLoaderParamsParcel;
@@ -31,6 +32,8 @@ import android.content.pm.InstallationFile;
import android.content.pm.InstallationFileParcel;
import android.content.pm.InstallationFileParcel;
import android.os.IBinder;
import android.os.IBinder;
import android.os.ParcelFileDescriptor;
import android.os.ParcelFileDescriptor;
import android.os.incremental.IncrementalManager;
import android.system.ErrnoException;
import android.util.ExceptionUtils;
import android.util.ExceptionUtils;
import android.util.Slog;
import android.util.Slog;


@@ -208,6 +211,25 @@ public abstract class DataLoaderService extends Service {
        private final long mNativeInstance;
        private final long mNativeInstance;
    }
    }


    /* Used by native FileSystemConnector. */
    private boolean setStorageParams(int storageId, boolean enableReadLogs) {
        IncrementalManager incrementalManager = (IncrementalManager) getSystemService(
                Context.INCREMENTAL_SERVICE);
        if (incrementalManager == null) {
            Slog.e(TAG, "Failed to obtain incrementalManager: " + storageId);
            return false;
        }
        try {
            // This has to be done directly in incrementalManager as the storage
            // might be missing still.
            incrementalManager.setStorageParams(storageId, enableReadLogs);
        } catch (ErrnoException e) {
            Slog.e(TAG, "Failed to set params for storage: " + storageId, e);
            return false;
        }
        return true;
    }

    /* Native methods */
    /* Native methods */
    private native boolean nativeCreateDataLoader(int storageId,
    private native boolean nativeCreateDataLoader(int storageId,
            @NonNull FileSystemControlParcel control,
            @NonNull FileSystemControlParcel control,
+1 −0
Original line number Original line Diff line number Diff line
@@ -392,6 +392,7 @@ private:
        mArgs = params.arguments();
        mArgs = params.arguments();
        mIfs = ifs;
        mIfs = ifs;
        mStatusListener = statusListener;
        mStatusListener = statusListener;
        mIfs->setParams({.readLogsEnabled = true});
        return true;
        return true;
    }
    }
    bool onStart() final { return true; }
    bool onStart() final { return true; }
+5 −0
Original line number Original line Diff line number Diff line
@@ -155,6 +155,11 @@ binder::Status BinderIncrementalService::deleteStorage(int32_t storageId) {
    return ok();
    return ok();
}
}


binder::Status BinderIncrementalService::setStorageParams(int32_t storage, bool enableReadLogs, int32_t* _aidl_return) {
    *_aidl_return = mImpl.setStorageParams(storage, enableReadLogs);
    return ok();
}

binder::Status BinderIncrementalService::makeDirectory(int32_t storageId, const std::string& path,
binder::Status BinderIncrementalService::makeDirectory(int32_t storageId, const std::string& path,
                                                       int32_t* _aidl_return) {
                                                       int32_t* _aidl_return) {
    *_aidl_return = mImpl.makeDir(storageId, path);
    *_aidl_return = mImpl.makeDir(storageId, path);
Loading