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 17 package com.android.frameworks.perftests.am.tests; 18 19 import android.content.Intent; 20 21 import androidx.test.filters.LargeTest; 22 import androidx.test.runner.AndroidJUnit4; 23 24 import com.android.frameworks.perftests.am.util.Constants; 25 26 import org.junit.Test; 27 import org.junit.runner.RunWith; 28 29 @RunWith(AndroidJUnit4.class) 30 @LargeTest 31 public class BroadcastPerfTest extends BasePerfTest { 32 @Test manifestBroadcastRunning()33 public void manifestBroadcastRunning() { 34 runPerfFunction(() -> { 35 startTargetPackage(); 36 37 final Intent intent = createBroadcastIntent( 38 Constants.ACTION_BROADCAST_MANIFEST_RECEIVE); 39 40 final long startTime = System.nanoTime(); 41 42 mContext.sendBroadcast(intent); 43 44 final long endTime = getReceivedTimeNs(Constants.TYPE_BROADCAST_RECEIVE); 45 46 return endTime - startTime; 47 }); 48 } 49 50 @Test manifestBroadcastNotRunning()51 public void manifestBroadcastNotRunning() { 52 runPerfFunction(() -> { 53 final Intent intent = createBroadcastIntent( 54 Constants.ACTION_BROADCAST_MANIFEST_RECEIVE); 55 56 final long startTime = System.nanoTime(); 57 58 mContext.sendBroadcast(intent); 59 60 final long endTime = getReceivedTimeNs(Constants.TYPE_BROADCAST_RECEIVE); 61 62 return endTime - startTime; 63 }); 64 } 65 66 @Test registeredBroadcast()67 public void registeredBroadcast() { 68 runPerfFunction(() -> { 69 startTargetPackage(); 70 71 final Intent intent = createBroadcastIntent( 72 Constants.ACTION_BROADCAST_REGISTERED_RECEIVE); 73 74 final long startTime = System.nanoTime(); 75 76 mContext.sendBroadcast(intent); 77 78 final long endTime = getReceivedTimeNs(Constants.TYPE_BROADCAST_RECEIVE); 79 80 return endTime - startTime; 81 }); 82 } 83 } 84