1616package com .android .server .blob ;
1717
1818import static android .app .blob .BlobStoreManager .COMMIT_RESULT_ERROR ;
19+ import static android .app .blob .XmlTags .ATTR_CREATION_TIME_MS ;
1920import static android .app .blob .XmlTags .ATTR_ID ;
2021import static android .app .blob .XmlTags .ATTR_PACKAGE ;
2122import static android .app .blob .XmlTags .ATTR_UID ;
2930
3031import static com .android .server .blob .BlobStoreConfig .LOGV ;
3132import static com .android .server .blob .BlobStoreConfig .TAG ;
33+ import static com .android .server .blob .BlobStoreConfig .XML_VERSION_ADD_SESSION_CREATION_TIME ;
34+ import static com .android .server .blob .BlobStoreConfig .hasSessionExpired ;
3235
3336import android .annotation .BytesLong ;
3437import android .annotation .NonNull ;
@@ -89,6 +92,7 @@ class BlobStoreSession extends IBlobStoreSession.Stub {
8992 private final long mSessionId ;
9093 private final int mOwnerUid ;
9194 private final String mOwnerPackageName ;
95+ private final long mCreationTimeMs ;
9296
9397 // Do not access this directly, instead use getSessionFile().
9498 private File mSessionFile ;
@@ -109,16 +113,24 @@ class BlobStoreSession extends IBlobStoreSession.Stub {
109113 @ GuardedBy ("mSessionLock" )
110114 private IBlobCommitCallback mBlobCommitCallback ;
111115
112- BlobStoreSession (Context context , long sessionId , BlobHandle blobHandle ,
113- int ownerUid , String ownerPackageName , SessionStateChangeListener listener ) {
116+ private BlobStoreSession (Context context , long sessionId , BlobHandle blobHandle ,
117+ int ownerUid , String ownerPackageName , long creationTimeMs ,
118+ SessionStateChangeListener listener ) {
114119 this .mContext = context ;
115120 this .mBlobHandle = blobHandle ;
116121 this .mSessionId = sessionId ;
117122 this .mOwnerUid = ownerUid ;
118123 this .mOwnerPackageName = ownerPackageName ;
124+ this .mCreationTimeMs = creationTimeMs ;
119125 this .mListener = listener ;
120126 }
121127
128+ BlobStoreSession (Context context , long sessionId , BlobHandle blobHandle ,
129+ int ownerUid , String ownerPackageName , SessionStateChangeListener listener ) {
130+ this (context , sessionId , blobHandle , ownerUid , ownerPackageName ,
131+ System .currentTimeMillis (), listener );
132+ }
133+
122134 public BlobHandle getBlobHandle () {
123135 return mBlobHandle ;
124136 }
@@ -178,6 +190,12 @@ boolean isFinalized() {
178190 }
179191 }
180192
193+ boolean isExpired () {
194+ final long lastModifiedTimeMs = getSessionFile ().lastModified ();
195+ return hasSessionExpired (lastModifiedTimeMs == 0
196+ ? mCreationTimeMs : lastModifiedTimeMs );
197+ }
198+
181199 @ Override
182200 @ NonNull
183201 public ParcelFileDescriptor openWrite (@ BytesLong long offsetBytes ,
@@ -491,6 +509,7 @@ void dump(IndentingPrintWriter fout, DumpArgs dumpArgs) {
491509 fout .println ("state: " + stateToString (mState ));
492510 fout .println ("ownerUid: " + mOwnerUid );
493511 fout .println ("ownerPkg: " + mOwnerPackageName );
512+ fout .println ("creation time: " + BlobStoreUtils .formatTime (mCreationTimeMs ));
494513
495514 fout .println ("blobHandle:" );
496515 fout .increaseIndent ();
@@ -511,6 +530,7 @@ void writeToXml(@NonNull XmlSerializer out) throws IOException {
511530 XmlUtils .writeLongAttribute (out , ATTR_ID , mSessionId );
512531 XmlUtils .writeStringAttribute (out , ATTR_PACKAGE , mOwnerPackageName );
513532 XmlUtils .writeIntAttribute (out , ATTR_UID , mOwnerUid );
533+ XmlUtils .writeLongAttribute (out , ATTR_CREATION_TIME_MS , mCreationTimeMs );
514534
515535 out .startTag (null , TAG_BLOB_HANDLE );
516536 mBlobHandle .writeToXml (out );
@@ -529,6 +549,9 @@ static BlobStoreSession createFromXml(@NonNull XmlPullParser in, int version,
529549 final long sessionId = XmlUtils .readLongAttribute (in , ATTR_ID );
530550 final String ownerPackageName = XmlUtils .readStringAttribute (in , ATTR_PACKAGE );
531551 final int ownerUid = XmlUtils .readIntAttribute (in , ATTR_UID );
552+ final long creationTimeMs = version >= XML_VERSION_ADD_SESSION_CREATION_TIME
553+ ? XmlUtils .readLongAttribute (in , ATTR_CREATION_TIME_MS )
554+ : System .currentTimeMillis ();
532555
533556 final int depth = in .getDepth ();
534557 BlobHandle blobHandle = null ;
@@ -551,7 +574,7 @@ static BlobStoreSession createFromXml(@NonNull XmlPullParser in, int version,
551574 }
552575
553576 final BlobStoreSession blobStoreSession = new BlobStoreSession (context , sessionId ,
554- blobHandle , ownerUid , ownerPackageName , stateChangeListener );
577+ blobHandle , ownerUid , ownerPackageName , creationTimeMs , stateChangeListener );
555578 blobStoreSession .mBlobAccessMode .allow (blobAccessMode );
556579 return blobStoreSession ;
557580 }
0 commit comments