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 static android.server.am.Components.TestActivity.TEST_ACTIVITY_ACTION_FINISH_SELF; 20 import static android.server.am.Components.TestActivity.EXTRA_FIXED_ORIENTATION; 21 22 import android.content.BroadcastReceiver; 23 import android.content.Context; 24 import android.content.Intent; 25 import android.content.IntentFilter; 26 import android.content.res.Configuration; 27 import android.os.Bundle; 28 29 public class TestActivity extends AbstractLifecycleLogActivity { 30 31 private BroadcastReceiver mReceiver = new BroadcastReceiver() { 32 @Override 33 public void onReceive(Context context, Intent intent) { 34 if (intent != null && TEST_ACTIVITY_ACTION_FINISH_SELF.equals(intent.getAction())) { 35 finish(); 36 } 37 } 38 }; 39 40 @Override 41 protected void onCreate(Bundle icicle) { 42 super.onCreate(icicle); 43 44 // Set the fixed orientation if requested 45 if (getIntent().hasExtra(EXTRA_FIXED_ORIENTATION)) { 46 final int ori = Integer.parseInt(getIntent().getStringExtra(EXTRA_FIXED_ORIENTATION)); 47 setRequestedOrientation(ori); 48 } 49 } 50 51 @Override 52 protected void onStart() { 53 super.onStart(); 54 registerReceiver(mReceiver, new IntentFilter(TEST_ACTIVITY_ACTION_FINISH_SELF)); 55 } 56 57 @Override 58 protected void onResume() { 59 super.onResume(); 60 final Configuration config = getResources().getConfiguration(); 61 dumpDisplaySize(config); 62 dumpConfiguration(config); 63 } 64 65 @Override 66 protected void onStop() { 67 super.onStop(); 68 unregisterReceiver(mReceiver); 69 } 70 71 @Override 72 public void onConfigurationChanged(Configuration newConfig) { 73 super.onConfigurationChanged(newConfig); 74 dumpDisplaySize(newConfig); 75 dumpConfiguration(newConfig); 76 } 77 } 78