1/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * 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, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16
17package com.android.frameworks.perftests.am.tests;
18
19import android.content.Intent;
20import android.support.test.filters.LargeTest;
21import android.support.test.runner.AndroidJUnit4;
22
23import com.android.frameworks.perftests.am.util.Constants;
24
25import org.junit.Test;
26import org.junit.runner.RunWith;
27
28@RunWith(AndroidJUnit4.class)
29@LargeTest
30public class BroadcastPerfTest extends BasePerfTest {
31    @Test
32    public void manifestBroadcastRunning() {
33        runPerfFunction(() -> {
34            startTargetPackage();
35
36            final Intent intent = createBroadcastIntent(
37                    Constants.ACTION_BROADCAST_MANIFEST_RECEIVE);
38
39            final long startTime = System.nanoTime();
40
41            mContext.sendBroadcast(intent);
42
43            final long endTime = getReceivedTimeNs(Constants.TYPE_BROADCAST_RECEIVE);
44
45            return endTime - startTime;
46        });
47    }
48
49    @Test
50    public void manifestBroadcastNotRunning() {
51        runPerfFunction(() -> {
52            final Intent intent = createBroadcastIntent(
53                    Constants.ACTION_BROADCAST_MANIFEST_RECEIVE);
54
55            final long startTime = System.nanoTime();
56
57            mContext.sendBroadcast(intent);
58
59            final long endTime = getReceivedTimeNs(Constants.TYPE_BROADCAST_RECEIVE);
60
61            return endTime - startTime;
62        });
63    }
64
65    @Test
66    public void registeredBroadcast() {
67        runPerfFunction(() -> {
68            startTargetPackage();
69
70            final Intent intent = createBroadcastIntent(
71                    Constants.ACTION_BROADCAST_REGISTERED_RECEIVE);
72
73            final long startTime = System.nanoTime();
74
75            mContext.sendBroadcast(intent);
76
77            final long endTime = getReceivedTimeNs(Constants.TYPE_BROADCAST_RECEIVE);
78
79            return endTime - startTime;
80        });
81    }
82}
83