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

Commit 3023aab5 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add ContentProvider perf tests"

parents ac98b13e 433770fa
Loading
Loading
Loading
Loading
+7 −3
Original line number Original line Diff line number Diff line
@@ -17,6 +17,10 @@
        package="com.android.frameworks.perftests.amteststestapp">
        package="com.android.frameworks.perftests.amteststestapp">
    <application android:name=".TestApplication">
    <application android:name=".TestApplication">
        <activity android:name=".TestActivity" android:exported="true"/>
        <activity android:name=".TestActivity" android:exported="true"/>
        <provider
                android:authorities="com.android.frameworks.perftests.amteststestapp"
                android:name=".TestContentProvider"
                android:exported="true" />
        <receiver
        <receiver
                android:name=".TestBroadcastReceiver"
                android:name=".TestBroadcastReceiver"
                android:exported="true">
                android:exported="true">
+55 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.android.frameworks.perftests.amteststestapp;

import android.content.ContentProvider;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;

public class TestContentProvider extends ContentProvider {
    @Override
    public Uri insert(Uri uri, ContentValues values) {
        return null;
    }

    @Override
    public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
            String sortOrder) {
        return null;
    }

    @Override
    public String getType(Uri uri) {
        return null;
    }

    @Override
    public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
        return 0;
    }

    @Override
    public boolean onCreate() {
        return false;
    }

    @Override
    public int delete(Uri uri, String selection, String[] selectionArgs) {
        return 0;
    }
}
+70 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.android.frameworks.perftests.am.tests;

import android.content.ContentProviderClient;
import android.support.test.filters.LargeTest;
import android.support.test.runner.AndroidJUnit4;

import com.android.frameworks.perftests.am.util.TargetPackageUtils;

import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
@LargeTest
public class ContentProviderPerfTest extends BasePerfTest {
    /**
     * Benchmark time to call ContentResolver.acquireContentProviderClient() when target package is
     * running.
     */
    @Test
    public void contentProviderRunning() {
        runPerfFunction(() -> {
            startTargetPackage();

            long startTimeNs = System.nanoTime();
            final ContentProviderClient contentProviderClient =
                    mContext.getContentResolver()
                            .acquireContentProviderClient(TargetPackageUtils.PACKAGE_NAME);
            final long endTimeNs = System.nanoTime();

            contentProviderClient.close();

            return endTimeNs - startTimeNs;
        });
    }

    /**
     * Benchmark time to call ContentResolver.acquireContentProviderClient() when target package is
     * not running.
     */
    @Test
    public void contentProviderNotRunning() {
        runPerfFunction(() -> {
            final long startTimeNs = System.nanoTime();
            final ContentProviderClient contentProviderClient =
                    mContext.getContentResolver().acquireContentProviderClient(
                            TargetPackageUtils.PACKAGE_NAME);
            final long endTimeNs = System.nanoTime();

            contentProviderClient.close();

            return endTimeNs - startTimeNs;
        });
    }
}