1/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.accounts;
18
19import static junit.framework.Assert.fail;
20
21import android.Manifest;
22import android.content.Context;
23import android.content.pm.PackageManager;
24import android.perftests.utils.BenchmarkState;
25import android.perftests.utils.PerfStatusReporter;
26import android.support.test.InstrumentationRegistry;
27import android.support.test.filters.LargeTest;
28import android.support.test.runner.AndroidJUnit4;
29import android.util.Log;
30
31import org.junit.Rule;
32import org.junit.Test;
33import org.junit.runner.RunWith;
34
35@RunWith(AndroidJUnit4.class)
36@LargeTest
37public class AccountManagerPerfTest {
38
39    @Rule
40    public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
41
42    @Test
43    public void testGetAccounts() {
44        BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
45        final Context context = InstrumentationRegistry.getTargetContext();
46        if (context.checkSelfPermission(Manifest.permission.GET_ACCOUNTS)
47                != PackageManager.PERMISSION_GRANTED) {
48            fail("Missing required GET_ACCOUNTS permission");
49        }
50        AccountManager accountManager = AccountManager.get(context);
51        while (state.keepRunning()) {
52            accountManager.getAccounts();
53        }
54    }
55}
56