1 /* 2 * Copyright 2022 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 package android.media.codec.cts; 17 18 import android.app.Activity; 19 import android.content.BroadcastReceiver; 20 import android.content.Context; 21 import android.content.Intent; 22 import android.content.IntentFilter; 23 import android.os.Process; 24 25 public class MediaCodecResourceTestHighPriorityActivity extends Activity { 26 public static final String ACTION_HIGH_PRIORITY_ACTIVITY_READY = 27 "android.media.codec.cts.HIGH_PRIORITY_TEST_ACTIVITY_READY"; 28 29 public static final String ACTION_HIGH_PRIORITY_ACTIVITY_FINISH = 30 "android.media.codec.cts.HIGH_PRIORITY_TEST_ACTIVITY_FINISH"; 31 32 private FinishBroadcastReceiver mFinishBroadcastReceiver = null; 33 34 @Override onStart()35 protected void onStart() { 36 super.onStart(); 37 38 mFinishBroadcastReceiver = new FinishBroadcastReceiver(); 39 registerReceiver(mFinishBroadcastReceiver, 40 new IntentFilter(ACTION_HIGH_PRIORITY_ACTIVITY_FINISH)); 41 42 Intent intent = new Intent(); 43 intent.setAction(ACTION_HIGH_PRIORITY_ACTIVITY_READY); 44 intent.putExtra("pid", Process.myPid()); 45 intent.putExtra("uid", Process.myUid()); 46 sendBroadcast(intent); 47 } 48 49 @Override onStop()50 protected void onStop() { 51 if (mFinishBroadcastReceiver != null) { 52 unregisterReceiver(mFinishBroadcastReceiver); 53 mFinishBroadcastReceiver = null; 54 } 55 super.onStop(); 56 } 57 58 private class FinishBroadcastReceiver extends BroadcastReceiver { 59 @Override onReceive(Context context, Intent intent)60 public void onReceive(Context context, Intent intent) { 61 finish(); 62 } 63 } 64 } 65