| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.app; |
| 18 |
|
| 19 |
import android.content.Context; |
| 20 |
import android.content.Intent; |
| 21 |
import android.perftests.utils.BenchmarkState; |
| 22 |
import android.perftests.utils.PerfStatusReporter; |
| 23 |
import android.perftests.utils.PerfTestActivity; |
| 24 |
|
| 25 |
import androidx.test.InstrumentationRegistry; |
| 26 |
import androidx.test.filters.LargeTest; |
| 27 |
import androidx.test.runner.AndroidJUnit4; |
| 28 |
|
| 29 |
import org.junit.Before; |
| 30 |
import org.junit.Rule; |
| 31 |
import org.junit.Test; |
| 32 |
import org.junit.runner.RunWith; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
@RunWith(AndroidJUnit4.class) |
| 38 |
@LargeTest |
| 39 |
public class PendingIntentPerfTest { |
| 40 |
|
| 41 |
private Context mContext; |
| 42 |
|
| 43 |
@Rule |
| 44 |
public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter(); |
| 45 |
|
| 46 |
private Intent mIntent; |
| 47 |
|
| 48 |
@Before |
| 49 |
public void setUp() { |
| 50 |
mContext = InstrumentationRegistry.getTargetContext(); |
| 51 |
mIntent = PerfTestActivity.createLaunchIntent(mContext); |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
@Test |
| 58 |
public void create() { |
| 59 |
final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); |
| 60 |
while (state.keepRunning()) { |
| 61 |
state.pauseTiming(); |
| 62 |
state.resumeTiming(); |
| 63 |
|
| 64 |
final PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, mIntent, |
| 65 |
PendingIntent.FLAG_MUTABLE_UNAUDITED); |
| 66 |
|
| 67 |
state.pauseTiming(); |
| 68 |
pendingIntent.cancel(); |
| 69 |
state.resumeTiming(); |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
@Test |
| 78 |
public void createWithCancelFlag() { |
| 79 |
final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); |
| 80 |
while (state.keepRunning()) { |
| 81 |
state.pauseTiming(); |
| 82 |
final PendingIntent previousPendingIntent = PendingIntent.getActivity(mContext, 0, |
| 83 |
mIntent, PendingIntent.FLAG_MUTABLE_UNAUDITED); |
| 84 |
state.resumeTiming(); |
| 85 |
|
| 86 |
final PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, mIntent, |
| 87 |
PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_MUTABLE_UNAUDITED); |
| 88 |
|
| 89 |
state.pauseTiming(); |
| 90 |
pendingIntent.cancel(); |
| 91 |
state.resumeTiming(); |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
@Test |
| 100 |
public void createWithUpdateFlag() { |
| 101 |
final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); |
| 102 |
while (state.keepRunning()) { |
| 103 |
state.pauseTiming(); |
| 104 |
final PendingIntent previousPendingIntent = PendingIntent.getActivity(mContext, 0, |
| 105 |
mIntent, PendingIntent.FLAG_MUTABLE_UNAUDITED); |
| 106 |
state.resumeTiming(); |
| 107 |
|
| 108 |
final PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, mIntent, |
| 109 |
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE_UNAUDITED); |
| 110 |
|
| 111 |
state.pauseTiming(); |
| 112 |
previousPendingIntent.cancel(); |
| 113 |
pendingIntent.cancel(); |
| 114 |
state.resumeTiming(); |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
@Test |
| 122 |
public void cancel() { |
| 123 |
final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); |
| 124 |
while (state.keepRunning()) { |
| 125 |
state.pauseTiming(); |
| 126 |
final PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, |
| 127 |
mIntent, PendingIntent.FLAG_MUTABLE_UNAUDITED); |
| 128 |
state.resumeTiming(); |
| 129 |
|
| 130 |
pendingIntent.cancel(); |
| 131 |
} |
| 132 |
} |
| 133 |
} |
| 134 |
|