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

Commit bb353a6b authored by Sudheer Shanka's avatar Sudheer Shanka Committed by Android (Google) Code Review
Browse files

Merge "Add BlobStoreManager.Session.openRead()."

parents d1e455a4 db483fab
Loading
Loading
Loading
Loading
+22 −0
Original line number 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.
         *
+1 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.os.ParcelFileDescriptor;
/** {@hide} */
interface IBlobStoreSession {
    ParcelFileDescriptor openWrite(long offsetBytes, long lengthBytes);
    ParcelFileDescriptor openRead();

    void allowPackageAccess(in String packageName, in byte[] certificate);
    void allowSameSignatureAccess();
+35 −0
Original line number 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.system.OsConstants.O_CREAT;
import static android.system.OsConstants.O_RDONLY;
import static android.system.OsConstants.O_RDWR;
import static android.system.OsConstants.SEEK_SET;

@@ -186,6 +187,40 @@ public class BlobStoreSession extends IBlobStoreSession.Stub {
        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
    @BytesLong
    public long getSize() {
+1 −0
Original line number Diff line number Diff line
@@ -7547,6 +7547,7 @@ package android.app.blob {
    method public boolean isPackageAccessAllowed(@NonNull String, @NonNull byte[]) throws java.io.IOException;
    method public boolean isPublicAccessAllowed() 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;
  }