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

Commit db483fab authored by Sudheer Shanka's avatar Sudheer Shanka
Browse files

Add BlobStoreManager.Session.openRead().

Bug: 143559646
Test: atest cts/tests/BlobStore/src/com/android/cts/blob/BlobStoreManagerTest.java
Change-Id: I0188b4197da57644753507f5c7729eeddfec96b9
parent c6cf3a4d
Loading
Loading
Loading
Loading
+22 −0
Original line number Original line Diff line number Diff line
@@ -322,6 +322,28 @@ public class BlobStoreManager {
            }
            }
        }
        }


        /**
         * Opens a file descriptor to read the blob content already written into this session.
         *
         * @return a {@link ParcelFileDescriptor} for reading from the blob file.
         *
         * @throws IOException when there is an I/O error while opening the file to read.
         * @throws SecurityException when the caller is not the owner of the session.
         * @throws IllegalStateException when the caller tries to read the file after it is
         *                               abandoned (using {@link #abandon()})
         *                               or closed (using {@link #close()}).
         */
        public @NonNull ParcelFileDescriptor openRead() throws IOException {
            try {
                return mSession.openRead();
            } catch (ParcelableException e) {
                e.maybeRethrow(IOException.class);
                throw new RuntimeException(e);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
        }

        /**
        /**
         * Gets the size of the blob file that was written to the session so far.
         * Gets the size of the blob file that was written to the session so far.
         *
         *
+1 −0
Original line number Original line Diff line number Diff line
@@ -21,6 +21,7 @@ import android.os.ParcelFileDescriptor;
/** {@hide} */
/** {@hide} */
interface IBlobStoreSession {
interface IBlobStoreSession {
    ParcelFileDescriptor openWrite(long offsetBytes, long lengthBytes);
    ParcelFileDescriptor openWrite(long offsetBytes, long lengthBytes);
    ParcelFileDescriptor openRead();


    void allowPackageAccess(in String packageName, in byte[] certificate);
    void allowPackageAccess(in String packageName, in byte[] certificate);
    void allowSameSignatureAccess();
    void allowSameSignatureAccess();
+35 −0
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@ package com.android.server.blob;


import static android.app.blob.BlobStoreManager.COMMIT_RESULT_ERROR;
import static android.app.blob.BlobStoreManager.COMMIT_RESULT_ERROR;
import static android.system.OsConstants.O_CREAT;
import static android.system.OsConstants.O_CREAT;
import static android.system.OsConstants.O_RDONLY;
import static android.system.OsConstants.O_RDWR;
import static android.system.OsConstants.O_RDWR;
import static android.system.OsConstants.SEEK_SET;
import static android.system.OsConstants.SEEK_SET;


@@ -186,6 +187,40 @@ public class BlobStoreSession extends IBlobStoreSession.Stub {
        return createRevocableFdLocked(fd);
        return createRevocableFdLocked(fd);
    }
    }


    @Override
    @NonNull
    public ParcelFileDescriptor openRead() {
        assertCallerIsOwner();
        synchronized (mSessionLock) {
            if (mState != STATE_OPENED) {
                throw new IllegalStateException("Not allowed to read in state: "
                        + stateToString(mState));
            }

            try {
                return openReadLocked();
            } catch (IOException e) {
                throw ExceptionUtils.wrap(e);
            }
        }
    }

    @GuardedBy("mSessionLock")
    @NonNull
    private ParcelFileDescriptor openReadLocked() throws IOException {
        FileDescriptor fd = null;
        try {
            final File sessionFile = getSessionFile();
            if (sessionFile == null) {
                throw new IllegalStateException("Couldn't get the file for this session");
            }
            fd = Os.open(sessionFile.getPath(), O_RDONLY, 0);
        } catch (ErrnoException e) {
            e.rethrowAsIOException();
        }
        return createRevocableFdLocked(fd);
    }

    @Override
    @Override
    @BytesLong
    @BytesLong
    public long getSize() {
    public long getSize() {
+1 −0
Original line number Original line Diff line number Diff line
@@ -7538,6 +7538,7 @@ package android.app.blob {
    method public boolean isPackageAccessAllowed(@NonNull String, @NonNull byte[]) throws java.io.IOException;
    method public boolean isPackageAccessAllowed(@NonNull String, @NonNull byte[]) throws java.io.IOException;
    method public boolean isPublicAccessAllowed() throws java.io.IOException;
    method public boolean isPublicAccessAllowed() throws java.io.IOException;
    method public boolean isSameSignatureAccessAllowed() throws java.io.IOException;
    method public boolean isSameSignatureAccessAllowed() throws java.io.IOException;
    method @NonNull public android.os.ParcelFileDescriptor openRead() throws java.io.IOException;
    method @NonNull public android.os.ParcelFileDescriptor openWrite(long, long) throws java.io.IOException;
    method @NonNull public android.os.ParcelFileDescriptor openWrite(long, long) throws java.io.IOException;
  }
  }