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

Commit b7e49a41 authored by Alex Buynytskyy's avatar Alex Buynytskyy
Browse files

FileIntegrity API improvements.

1. Reimplement per-file API via same API, but using FD. This extends the API test coverage to both methods.
2. Document the behavior in case of power failures.

Bug: 253568736
Test: atest SettingsTest
Change-Id: Iaeee2cc849f477d1cf379c353e1ec1925115ac02
parent 9d248e51
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.server.security;

import static android.os.ParcelFileDescriptor.MODE_READ_ONLY;

import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.os.ParcelFileDescriptor;
@@ -36,18 +38,25 @@ public final class FileIntegrity {
    private FileIntegrity() {}

    /**
     * Enables fs-verity, if supported by the filesystem.
     * Enables fs-verity, if supported by the filesystem. This operation is atomic, i.e. it's either
     * enabled or not, even in case of power failure during or after the call.
     * @see <a href="https://www.kernel.org/doc/html/latest/filesystems/fsverity.html">
     *
     * @hide
     */
    @SystemApi(client = SystemApi.Client.SYSTEM_SERVER)
    public static void setUpFsVerity(@NonNull File file) throws IOException {
        VerityUtils.setUpFsverity(file.getAbsolutePath());
        ParcelFileDescriptor pfd = ParcelFileDescriptor.open(file, MODE_READ_ONLY);
        setUpFsVerity(pfd);
    }

    /**
     * Enables fs-verity, if supported by the filesystem.
     * Enables fs-verity, if supported by the filesystem. This operation is atomic, i.e. it's either
     * enabled or not, even in case of power failure during or after the call.
     * @see <a href="https://www.kernel.org/doc/html/latest/filesystems/fsverity.html">
     *
     * @param parcelFileDescriptor an FD opened in {@link ParcelFileDescriptor#MODE_READ_ONLY}.
     *
     * @hide
     */
    @SystemApi(client = SystemApi.Client.SYSTEM_SERVER)