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

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

Merge "Re-enable BlobStorePerfTests."

parents c43a9482 285848d8
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */
package com.android.perftests.blob;

import android.app.blob.BlobHandle;
import android.app.blob.BlobStoreManager;
import android.content.Context;
import android.perftests.utils.ManualBenchmarkState;
@@ -30,7 +31,6 @@ import com.android.utils.blob.DummyBlobData;

import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -39,6 +39,7 @@ import org.junit.runners.Parameterized;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Base64;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.CompletableFuture;
@@ -90,7 +91,6 @@ public class BlobStorePerfTests {
        runShellCommand("cmd jobscheduler run -f android 191934935");
    }

    @Ignore
    @Test
    public void testComputeDigest() throws Exception {
        mAtraceUtils.startTrace(ATRACE_CATEGORY_SYSTEM_SERVER);
@@ -104,7 +104,8 @@ public class BlobStorePerfTests {

                durations.clear();
                collectDigestDurationsFromTrace(parser, durations);
                // TODO: get and delete blobId before next iteration.

                deleteBlob(blobData.getBlobHandle());
            }
        } finally {
            mAtraceUtils.stopTrace();
@@ -137,6 +138,16 @@ public class BlobStorePerfTests {
        }
    }

    private void deleteBlob(BlobHandle blobHandle) throws Exception {
        runShellCommand(String.format(
                "cmd blob_store delete-blob --algo %s --digest %s --label %s --expiry %d --tag %s",
                blobHandle.algorithm,
                Base64.getEncoder().encode(blobHandle.digest),
                blobHandle.label,
                blobHandle.expiryTimeMillis,
                blobHandle.tag));
    }

    private String runShellCommand(String cmd) {
        try {
            return UiDevice.getInstance(
+2 −1
Original line number Diff line number Diff line
@@ -43,7 +43,8 @@ import java.util.Objects;
 */
// TODO: use datagen tool?
public final class BlobHandle implements Parcelable {
    private static final String ALGO_SHA_256 = "SHA-256";
    /** @hide */
    public static final String ALGO_SHA_256 = "SHA-256";

    private static final String[] SUPPORTED_ALGOS = {
            ALGO_SHA_256
+14 −0
Original line number Diff line number Diff line
@@ -874,6 +874,20 @@ public class BlobStoreManagerService extends SystemService {
        }
    }

    void deleteBlob(@NonNull BlobHandle blobHandle, @UserIdInt int userId) {
        synchronized (mBlobsLock) {
            final ArrayMap<BlobHandle, BlobMetadata> userBlobs = getUserBlobsLocked(userId);
            final BlobMetadata blobMetadata = userBlobs.get(blobHandle);
            if (blobMetadata == null) {
                return;
            }
            blobMetadata.getBlobFile().delete();
            userBlobs.remove(blobHandle);
            mKnownBlobIds.remove(blobMetadata.getBlobId());
            writeBlobsInfoAsync();
        }
    }

    @GuardedBy("mBlobsLock")
    private void dumpSessionsLocked(IndentingPrintWriter fout, DumpArgs dumpArgs) {
        for (int i = 0, userCount = mSessions.size(); i < userCount; ++i) {
+56 −2
Original line number Diff line number Diff line
@@ -15,10 +15,13 @@
 */
package com.android.server.blob;

import android.app.ActivityManager;
import android.app.blob.BlobHandle;
import android.os.ShellCommand;
import android.os.UserHandle;

import java.io.PrintWriter;
import java.util.Base64;

class BlobStoreManagerShellCommand extends ShellCommand {

@@ -39,6 +42,8 @@ class BlobStoreManagerShellCommand extends ShellCommand {
                return runClearAllSessions(pw);
            case "clear-all-blobs":
                return runClearAllBlobs(pw);
            case "delete-blob":
                return runDeleteBlob(pw);
            default:
                return handleDefaultCommands(cmd);
        }
@@ -68,6 +73,17 @@ class BlobStoreManagerShellCommand extends ShellCommand {
        return 0;
    }

    private int runDeleteBlob(PrintWriter pw) {
        final ParsedArgs args = new ParsedArgs();

        if (parseOptions(pw, args) < 0) {
            return -1;
        }

        mService.deleteBlob(args.getBlobHandle(), args.userId);
        return 0;
    }

    @Override
    public void onHelp() {
        final PrintWriter pw = getOutPrintWriter();
@@ -78,14 +94,24 @@ class BlobStoreManagerShellCommand extends ShellCommand {
        pw.println("clear-all-sessions [-u | --user USER_ID]");
        pw.println("    Remove all sessions.");
        pw.println("    Options:");
        pw.println("      -u or --user: specify which user's sessions to be removed;");
        pw.println("      -u or --user: specify which user's sessions to be removed.");
        pw.println("                    If not specified, sessions in all users are removed.");
        pw.println();
        pw.println("clear-all-blobs [-u | --user USER_ID]");
        pw.println("    Remove all blobs.");
        pw.println("    Options:");
        pw.println("      -u or --user: specify which user's blobs to be removed.");
        pw.println("                    If not specified, blobs in all users are removed.");
        pw.println("delete-blob [-u | --user USER_ID] [--digest DIGEST] [--expiry EXPIRY_TIME] "
                + "[--label LABEL] [--tag TAG]");
        pw.println("    Delete a blob.");
        pw.println("    Options:");
        pw.println("      -u or --user: specify which user's blobs to be removed;");
        pw.println("                    If not specified, blobs in all users are removed.");
        pw.println("      --digest: Base64 encoded digest of the blob to delete.");
        pw.println("      --expiry: Expiry time of the blob to delete, in milliseconds.");
        pw.println("      --label: Label of the blob to delete.");
        pw.println("      --tag: Tag of the blob to delete.");
        pw.println();
    }

@@ -97,15 +123,43 @@ class BlobStoreManagerShellCommand extends ShellCommand {
                case "--user":
                    args.userId = Integer.parseInt(getNextArgRequired());
                    break;
                case "--algo":
                    args.algorithm = getNextArgRequired();
                    break;
                case "--digest":
                    args.digest = Base64.getDecoder().decode(getNextArgRequired());
                    break;
                case "--label":
                    args.label = getNextArgRequired();
                    break;
                case "--expiry":
                    args.expiryTimeMillis = Long.parseLong(getNextArgRequired());
                    break;
                case "--tag":
                    args.tag = getNextArgRequired();
                    break;
                default:
                    pw.println("Error: unknown option '" + opt + "'");
                    return -1;
            }
        }
        if (args.userId == UserHandle.USER_CURRENT) {
            args.userId = ActivityManager.getCurrentUser();
        }
        return 0;
    }

    private static class ParsedArgs {
        public int userId;
        public int userId = UserHandle.USER_CURRENT;

        public String algorithm = BlobHandle.ALGO_SHA_256;
        public byte[] digest;
        public long expiryTimeMillis;
        public CharSequence label;
        public String tag;

        public BlobHandle getBlobHandle() {
            return BlobHandle.create(algorithm, digest, label, expiryTimeMillis, tag);
        }
    }
}