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

Commit 732be857 authored by Sudheer Shanka's avatar Sudheer Shanka Committed by Automerger Merge Worker
Browse files

Merge "Persist blobstore session creation time." into rvc-dev am: d78ac6b9

Change-Id: I0678b4aac52c29216a5c0f5c5da9cdc2cbfa5b72
parents c291e76a d78ac6b9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ public final class XmlTags {
    public static final String ATTR_ID = "id";
    public static final String ATTR_PACKAGE = "p";
    public static final String ATTR_UID = "u";
    public static final String ATTR_CREATION_TIME_MS = "crt";

    // For BlobMetadata
    public static final String TAG_BLOB = "b";
+2 −1
Original line number Diff line number Diff line
@@ -45,8 +45,9 @@ class BlobStoreConfig {
    public static final int XML_VERSION_ADD_STRING_DESC = 2;
    public static final int XML_VERSION_ADD_DESC_RES_NAME = 3;
    public static final int XML_VERSION_ADD_COMMIT_TIME = 4;
    public static final int XML_VERSION_ADD_SESSION_CREATION_TIME = 5;

    public static final int XML_VERSION_CURRENT = XML_VERSION_ADD_COMMIT_TIME;
    public static final int XML_VERSION_CURRENT = XML_VERSION_ADD_SESSION_CREATION_TIME;

    private static final String ROOT_DIR_NAME = "blobstore";
    private static final String BLOBS_DIR_NAME = "blobs";
+1 −3
Original line number Diff line number Diff line
@@ -32,7 +32,6 @@ import static com.android.server.blob.BlobStoreConfig.LOGV;
import static com.android.server.blob.BlobStoreConfig.TAG;
import static com.android.server.blob.BlobStoreConfig.XML_VERSION_CURRENT;
import static com.android.server.blob.BlobStoreConfig.getAdjustedCommitTimeMs;
import static com.android.server.blob.BlobStoreConfig.hasSessionExpired;
import static com.android.server.blob.BlobStoreSession.STATE_ABANDONED;
import static com.android.server.blob.BlobStoreSession.STATE_COMMITTED;
import static com.android.server.blob.BlobStoreSession.STATE_VERIFIED_INVALID;
@@ -986,9 +985,8 @@ public class BlobStoreManagerService extends SystemService {
            userSessions.removeIf((sessionId, blobStoreSession) -> {
                boolean shouldRemove = false;

                // TODO: handle the case where no content has been written to session yet.
                // Cleanup sessions which haven't been modified in a while.
                if (hasSessionExpired(blobStoreSession.getSessionFile().lastModified())) {
                if (blobStoreSession.isExpired()) {
                    shouldRemove = true;
                }

+26 −3
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
package com.android.server.blob;

import static android.app.blob.BlobStoreManager.COMMIT_RESULT_ERROR;
import static android.app.blob.XmlTags.ATTR_CREATION_TIME_MS;
import static android.app.blob.XmlTags.ATTR_ID;
import static android.app.blob.XmlTags.ATTR_PACKAGE;
import static android.app.blob.XmlTags.ATTR_UID;
@@ -29,6 +30,8 @@ import static android.system.OsConstants.SEEK_SET;

import static com.android.server.blob.BlobStoreConfig.LOGV;
import static com.android.server.blob.BlobStoreConfig.TAG;
import static com.android.server.blob.BlobStoreConfig.XML_VERSION_ADD_SESSION_CREATION_TIME;
import static com.android.server.blob.BlobStoreConfig.hasSessionExpired;

import android.annotation.BytesLong;
import android.annotation.NonNull;
@@ -89,6 +92,7 @@ class BlobStoreSession extends IBlobStoreSession.Stub {
    private final long mSessionId;
    private final int mOwnerUid;
    private final String mOwnerPackageName;
    private final long mCreationTimeMs;

    // Do not access this directly, instead use getSessionFile().
    private File mSessionFile;
@@ -109,16 +113,24 @@ class BlobStoreSession extends IBlobStoreSession.Stub {
    @GuardedBy("mSessionLock")
    private IBlobCommitCallback mBlobCommitCallback;

    BlobStoreSession(Context context, long sessionId, BlobHandle blobHandle,
            int ownerUid, String ownerPackageName, SessionStateChangeListener listener) {
    private BlobStoreSession(Context context, long sessionId, BlobHandle blobHandle,
            int ownerUid, String ownerPackageName, long creationTimeMs,
            SessionStateChangeListener listener) {
        this.mContext = context;
        this.mBlobHandle = blobHandle;
        this.mSessionId = sessionId;
        this.mOwnerUid = ownerUid;
        this.mOwnerPackageName = ownerPackageName;
        this.mCreationTimeMs = creationTimeMs;
        this.mListener = listener;
    }

    BlobStoreSession(Context context, long sessionId, BlobHandle blobHandle,
            int ownerUid, String ownerPackageName, SessionStateChangeListener listener) {
        this(context, sessionId, blobHandle, ownerUid, ownerPackageName,
                System.currentTimeMillis(), listener);
    }

    public BlobHandle getBlobHandle() {
        return mBlobHandle;
    }
@@ -178,6 +190,12 @@ class BlobStoreSession extends IBlobStoreSession.Stub {
        }
    }

    boolean isExpired() {
        final long lastModifiedTimeMs = getSessionFile().lastModified();
        return hasSessionExpired(lastModifiedTimeMs == 0
                ? mCreationTimeMs : lastModifiedTimeMs);
    }

    @Override
    @NonNull
    public ParcelFileDescriptor openWrite(@BytesLong long offsetBytes,
@@ -491,6 +509,7 @@ class BlobStoreSession extends IBlobStoreSession.Stub {
            fout.println("state: " + stateToString(mState));
            fout.println("ownerUid: " + mOwnerUid);
            fout.println("ownerPkg: " + mOwnerPackageName);
            fout.println("creation time: " + BlobStoreUtils.formatTime(mCreationTimeMs));

            fout.println("blobHandle:");
            fout.increaseIndent();
@@ -511,6 +530,7 @@ class BlobStoreSession extends IBlobStoreSession.Stub {
            XmlUtils.writeLongAttribute(out, ATTR_ID, mSessionId);
            XmlUtils.writeStringAttribute(out, ATTR_PACKAGE, mOwnerPackageName);
            XmlUtils.writeIntAttribute(out, ATTR_UID, mOwnerUid);
            XmlUtils.writeLongAttribute(out, ATTR_CREATION_TIME_MS, mCreationTimeMs);

            out.startTag(null, TAG_BLOB_HANDLE);
            mBlobHandle.writeToXml(out);
@@ -529,6 +549,9 @@ class BlobStoreSession extends IBlobStoreSession.Stub {
        final long sessionId = XmlUtils.readLongAttribute(in, ATTR_ID);
        final String ownerPackageName = XmlUtils.readStringAttribute(in, ATTR_PACKAGE);
        final int ownerUid = XmlUtils.readIntAttribute(in, ATTR_UID);
        final long creationTimeMs = version >= XML_VERSION_ADD_SESSION_CREATION_TIME
                ? XmlUtils.readLongAttribute(in, ATTR_CREATION_TIME_MS)
                : System.currentTimeMillis();

        final int depth = in.getDepth();
        BlobHandle blobHandle = null;
@@ -551,7 +574,7 @@ class BlobStoreSession extends IBlobStoreSession.Stub {
        }

        final BlobStoreSession blobStoreSession = new BlobStoreSession(context, sessionId,
                blobHandle, ownerUid, ownerPackageName, stateChangeListener);
                blobHandle, ownerUid, ownerPackageName, creationTimeMs, stateChangeListener);
        blobStoreSession.mBlobAccessMode.allow(blobAccessMode);
        return blobStoreSession;
    }
+1 −0
Original line number Diff line number Diff line
@@ -372,6 +372,7 @@ public class BlobStoreManagerServiceTest {
        doReturn(sessionId).when(session).getSessionId();
        doReturn(sessionFile).when(session).getSessionFile();
        doReturn(blobHandle).when(session).getBlobHandle();
        doCallRealMethod().when(session).isExpired();
        return session;
    }