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

Commit f4fae628 authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 6630229 from a2ed294a to rvc-release

Change-Id: I803af2a3cd02c7dc2f88d2936381d44e6cbc7854
parents 9225be4b a2ed294a
Loading
Loading
Loading
Loading
+58 −18
Original line number Diff line number Diff line
@@ -154,10 +154,10 @@ class BlobMetadata {
        }
    }

    void removeInvalidCommitters(SparseArray<String> packages) {
    void removeCommittersFromUnknownPkgs(SparseArray<String> knownPackages) {
        synchronized (mMetadataLock) {
            mCommitters.removeIf(committer ->
                    !committer.packageName.equals(packages.get(committer.uid)));
                    !committer.packageName.equals(knownPackages.get(committer.uid)));
        }
    }

@@ -200,16 +200,27 @@ class BlobMetadata {
        }
    }

    void removeInvalidLeasees(SparseArray<String> packages) {
    void removeLeaseesFromUnknownPkgs(SparseArray<String> knownPackages) {
        synchronized (mMetadataLock) {
            mLeasees.removeIf(leasee ->
                    !leasee.packageName.equals(packages.get(leasee.uid)));
                    !leasee.packageName.equals(knownPackages.get(leasee.uid)));
        }
    }

    boolean hasLeases() {
    void removeExpiredLeases() {
        synchronized (mMetadataLock) {
            return !mLeasees.isEmpty();
            mLeasees.removeIf(leasee -> !leasee.isStillValid());
        }
    }

    boolean hasValidLeases() {
        synchronized (mMetadataLock) {
            for (int i = 0, size = mLeasees.size(); i < size; ++i) {
                if (mLeasees.valueAt(i).isStillValid()) {
                    return true;
                }
            }
            return false;
        }
    }

@@ -226,8 +237,7 @@ class BlobMetadata {
            // Check if packageName already holds a lease on the blob.
            for (int i = 0, size = mLeasees.size(); i < size; ++i) {
                final Leasee leasee = mLeasees.valueAt(i);
                if (leasee.equals(callingPackage, callingUid)
                        && leasee.isStillValid()) {
                if (leasee.isStillValid() && leasee.equals(callingPackage, callingUid)) {
                    return true;
                }
            }
@@ -259,25 +269,32 @@ class BlobMetadata {

    boolean isALeasee(@Nullable String packageName, int uid) {
        synchronized (mMetadataLock) {
            return isAnAccessor(mLeasees, packageName, uid);
            final Leasee leasee = getAccessor(mLeasees, packageName, uid);
            return leasee != null && leasee.isStillValid();
        }
    }

    private static <T extends Accessor> boolean isAnAccessor(@NonNull ArraySet<T> accessors,
            @Nullable String packageName, int uid) {
        // Check if the package is an accessor of the data blob.
        return getAccessor(accessors, packageName, uid) != null;
    }

    private static <T extends Accessor> T getAccessor(@NonNull ArraySet<T> accessors,
            @Nullable String packageName, int uid) {
        // Check if the package is an accessor of the data blob.
        for (int i = 0, size = accessors.size(); i < size; ++i) {
            final Accessor accessor = accessors.valueAt(i);
            if (packageName != null && uid != INVALID_UID
                    && accessor.equals(packageName, uid)) {
                return true;
                return (T) accessor;
            } else if (packageName != null && accessor.packageName.equals(packageName)) {
                return true;
                return (T) accessor;
            } else if (uid != INVALID_UID && accessor.uid == uid) {
                return true;
                return (T) accessor;
            }
        }
        return false;
        return null;
    }

    boolean isALeasee(@NonNull String packageName) {
@@ -298,11 +315,11 @@ class BlobMetadata {

    private boolean hasOtherLeasees(@Nullable String packageName, int uid) {
        synchronized (mMetadataLock) {
            if (mCommitters.size() > 1 || mLeasees.size() > 1) {
                return true;
            }
            for (int i = 0, size = mLeasees.size(); i < size; ++i) {
                final Leasee leasee = mLeasees.valueAt(i);
                if (!leasee.isStillValid()) {
                    continue;
                }
                // TODO: Also exclude packages which are signed with same cert?
                if (packageName != null && uid != INVALID_UID
                        && !leasee.equals(packageName, uid)) {
@@ -322,6 +339,9 @@ class BlobMetadata {
        synchronized (mMetadataLock) {
            for (int i = 0, size = mLeasees.size(); i < size; ++i) {
                final Leasee leasee = mLeasees.valueAt(i);
                if (!leasee.isStillValid()) {
                    continue;
                }
                if (leasee.uid == uid && leasee.packageName.equals(packageName)) {
                    final int descriptionResId = leasee.descriptionResEntryName == null
                            ? Resources.ID_NULL
@@ -398,6 +418,26 @@ class BlobMetadata {
        return revocableFd.getRevocableFileDescriptor();
    }

    void destroy() {
        revokeAllFds();
        getBlobFile().delete();
    }

    private void revokeAllFds() {
        synchronized (mRevocableFds) {
            for (int i = 0, pkgCount = mRevocableFds.size(); i < pkgCount; ++i) {
                final ArraySet<RevocableFileDescriptor> packageFds =
                        mRevocableFds.valueAt(i);
                if (packageFds == null) {
                    continue;
                }
                for (int j = 0, fdCount = packageFds.size(); j < fdCount; ++j) {
                    packageFds.valueAt(j).revoke();
                }
            }
        }
    }

    boolean shouldBeDeleted(boolean respectLeaseWaitTime) {
        // Expired data blobs
        if (getBlobHandle().isExpired()) {
@@ -406,7 +446,7 @@ class BlobMetadata {

        // Blobs with no active leases
        if ((!respectLeaseWaitTime || hasLeaseWaitTimeElapsedForAll())
                && !hasLeases()) {
                && !hasValidLeases()) {
            return true;
        }

@@ -695,7 +735,7 @@ class BlobMetadata {
        }

        boolean isStillValid() {
            return expiryTimeMillis == 0 || expiryTimeMillis <= System.currentTimeMillis();
            return expiryTimeMillis == 0 || expiryTimeMillis >= System.currentTimeMillis();
        }

        void dump(@NonNull Context context, @NonNull IndentingPrintWriter fout) {
+27 −17
Original line number Diff line number Diff line
@@ -539,7 +539,7 @@ public class BlobStoreManagerService extends SystemService {
                Slog.v(TAG, "Released lease on " + blobHandle
                        + "; callingUid=" + callingUid + ", callingPackage=" + callingPackage);
            }
            if (!blobMetadata.hasLeases()) {
            if (!blobMetadata.hasValidLeases()) {
                mHandler.postDelayed(() -> {
                    synchronized (mBlobsLock) {
                        // Check if blobMetadata object is still valid. If it is not, then
@@ -583,6 +583,9 @@ public class BlobStoreManagerService extends SystemService {
            getUserBlobsLocked(userId).forEach((blobHandle, blobMetadata) -> {
                final ArrayList<LeaseInfo> leaseInfos = new ArrayList<>();
                blobMetadata.forEachLeasee(leasee -> {
                    if (!leasee.isStillValid()) {
                        return;
                    }
                    final int descriptionResId = leasee.descriptionResEntryName == null
                            ? Resources.ID_NULL
                            : getDescriptionResourceId(resourcesGetter.apply(leasee.packageName),
@@ -606,7 +609,11 @@ public class BlobStoreManagerService extends SystemService {
                    UserHandle.getUserId(callingUid));
            userBlobs.entrySet().removeIf(entry -> {
                final BlobMetadata blobMetadata = entry.getValue();
                return blobMetadata.getBlobId() == blobId;
                if (blobMetadata.getBlobId() == blobId) {
                    deleteBlobLocked(blobMetadata);
                    return true;
                }
                return false;
            });
            writeBlobsInfoAsync();
        }
@@ -657,11 +664,10 @@ public class BlobStoreManagerService extends SystemService {
        switch (session.getState()) {
            case STATE_ABANDONED:
            case STATE_VERIFIED_INVALID:
                session.getSessionFile().delete();
                synchronized (mBlobsLock) {
                    deleteSessionLocked(session);
                    getUserSessionsLocked(UserHandle.getUserId(session.getOwnerUid()))
                            .remove(session.getSessionId());
                    mActiveBlobIds.remove(session.getSessionId());
                    if (LOGV) {
                        Slog.v(TAG, "Session is invalid; deleted " + session);
                    }
@@ -682,8 +688,7 @@ public class BlobStoreManagerService extends SystemService {
                        Slog.d(TAG, "Failed to commit: too many committed blobs. count: "
                                + committedBlobsCount + "; blob: " + session);
                        session.sendCommitCallbackResult(COMMIT_RESULT_ERROR);
                        session.getSessionFile().delete();
                        mActiveBlobIds.remove(session.getSessionId());
                        deleteSessionLocked(session);
                        getUserSessionsLocked(UserHandle.getUserId(session.getOwnerUid()))
                                .remove(session.getSessionId());
                        break;
@@ -732,8 +737,7 @@ public class BlobStoreManagerService extends SystemService {
                    }
                    // Delete redundant data from recommits.
                    if (session.getSessionId() != blob.getBlobId()) {
                        session.getSessionFile().delete();
                        mActiveBlobIds.remove(session.getSessionId());
                        deleteSessionLocked(session);
                    }
                    getUserSessionsLocked(UserHandle.getUserId(session.getOwnerUid()))
                            .remove(session.getSessionId());
@@ -921,8 +925,8 @@ public class BlobStoreManagerService extends SystemService {
                        blobMetadata.getBlobFile().delete();
                    } else {
                        addBlobForUserLocked(blobMetadata, blobMetadata.getUserId());
                        blobMetadata.removeInvalidCommitters(userPackages);
                        blobMetadata.removeInvalidLeasees(userPackages);
                        blobMetadata.removeCommittersFromUnknownPkgs(userPackages);
                        blobMetadata.removeLeaseesFromUnknownPkgs(userPackages);
                    }
                    mCurrentMaxSessionId = Math.max(mCurrentMaxSessionId, blobMetadata.getBlobId());
                }
@@ -1019,8 +1023,7 @@ public class BlobStoreManagerService extends SystemService {
            userSessions.removeIf((sessionId, blobStoreSession) -> {
                if (blobStoreSession.getOwnerUid() == uid
                        && blobStoreSession.getOwnerPackageName().equals(packageName)) {
                    blobStoreSession.getSessionFile().delete();
                    mActiveBlobIds.remove(blobStoreSession.getSessionId());
                    deleteSessionLocked(blobStoreSession);
                    return true;
                }
                return false;
@@ -1061,8 +1064,7 @@ public class BlobStoreManagerService extends SystemService {
            if (userSessions != null) {
                for (int i = 0, count = userSessions.size(); i < count; ++i) {
                    final BlobStoreSession session = userSessions.valueAt(i);
                    session.getSessionFile().delete();
                    mActiveBlobIds.remove(session.getSessionId());
                    deleteSessionLocked(session);
                }
            }

@@ -1111,6 +1113,9 @@ public class BlobStoreManagerService extends SystemService {
            userBlobs.entrySet().removeIf(entry -> {
                final BlobMetadata blobMetadata = entry.getValue();

                // Remove expired leases
                blobMetadata.removeExpiredLeases();

                if (blobMetadata.shouldBeDeleted(true /* respectLeaseWaitTime */)) {
                    deleteBlobLocked(blobMetadata);
                    deletedBlobIds.add(blobMetadata.getBlobId());
@@ -1138,8 +1143,7 @@ public class BlobStoreManagerService extends SystemService {
                }

                if (shouldRemove) {
                    blobStoreSession.getSessionFile().delete();
                    mActiveBlobIds.remove(blobStoreSession.getSessionId());
                    deleteSessionLocked(blobStoreSession);
                    deletedBlobIds.add(blobStoreSession.getSessionId());
                }
                return shouldRemove;
@@ -1150,9 +1154,15 @@ public class BlobStoreManagerService extends SystemService {
        writeBlobSessionsAsync();
    }

    @GuardedBy("mBlobsLock")
    private void deleteSessionLocked(BlobStoreSession blobStoreSession) {
        blobStoreSession.destroy();
        mActiveBlobIds.remove(blobStoreSession.getSessionId());
    }

    @GuardedBy("mBlobsLock")
    private void deleteBlobLocked(BlobMetadata blobMetadata) {
        blobMetadata.getBlobFile().delete();
        blobMetadata.destroy();
        mActiveBlobIds.remove(blobMetadata.getBlobId());
    }

+5 −0
Original line number Diff line number Diff line
@@ -479,6 +479,11 @@ class BlobStoreSession extends IBlobStoreSession.Stub {
        }
    }

    void destroy() {
        revokeAllFds();
        getSessionFile().delete();
    }

    private void revokeAllFds() {
        synchronized (mRevocableFds) {
            for (int i = mRevocableFds.size() - 1; i >= 0; --i) {
+0 −1
Original line number Diff line number Diff line
@@ -33,7 +33,6 @@ import com.android.internal.os.StatsdConfigProto.PullAtomPackages;
import com.android.internal.os.StatsdConfigProto.SimpleAtomMatcher;
import com.android.internal.os.StatsdConfigProto.StatsdConfig;
import com.android.internal.os.StatsdConfigProto.TimeUnit;
import com.android.internal.os.statsd.StatsConfigUtils;
import com.android.internal.os.statsd.protos.TestAtoms;
import com.android.os.AtomsProto.Atom;

+1 −1
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.internal.os.statsd;
package com.android.internal.os.statsd.libstats;

import static com.google.common.truth.Truth.assertThat;

Loading