1 /* 2 * Copyright (C) 2015 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 17 package android.server.am; 18 19 import android.app.PictureInPictureParams; 20 import android.content.ComponentName; 21 import android.content.Intent; 22 import android.os.Bundle; 23 24 public class TestActivityWithSameAffinity extends TestActivity { 25 26 // Calls enterPictureInPicture() on creation 27 private static final String EXTRA_ENTER_PIP = "enter_pip"; 28 // Starts the activity (component name) provided by the value at the end of onCreate 29 private static final String EXTRA_START_ACTIVITY = "start_activity"; 30 // Finishes the activity at the end of onResume (after EXTRA_START_ACTIVITY is handled) 31 private static final String EXTRA_FINISH_SELF_ON_RESUME = "finish_self_on_resume"; 32 33 @Override 34 protected void onCreate(Bundle icicle) { 35 super.onCreate(icicle); 36 37 // Enter picture in picture if requested 38 if (getIntent().hasExtra(EXTRA_ENTER_PIP)) { 39 enterPictureInPictureMode(new PictureInPictureParams.Builder().build()); 40 } 41 42 // Launch a new activity if requested 43 String launchActivityComponent = getIntent().getStringExtra(EXTRA_START_ACTIVITY); 44 if (launchActivityComponent != null) { 45 Intent launchIntent = new Intent(); 46 launchIntent.setComponent(ComponentName.unflattenFromString(launchActivityComponent)); 47 startActivity(launchIntent); 48 } 49 } 50 51 @Override 52 protected void onResume() { 53 super.onResume(); 54 55 // Finish self if requested 56 if (getIntent().hasExtra(EXTRA_FINISH_SELF_ON_RESUME)) { 57 finish(); 58 } 59 } 60 } 61