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