1 /* 2 * Copyright (C) 2016 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_CONFIGURATION; 20 21 import android.content.res.Configuration; 22 import android.os.Bundle; 23 import android.server.wm.CommandSession.BasicTestActivity; 24 import android.server.wm.CommandSession.ConfigInfo; 25 import android.util.Log; 26 27 public abstract class AbstractLifecycleLogActivity extends BasicTestActivity { 28 29 @Override onCreate(Bundle icicle)30 protected void onCreate(Bundle icicle) { 31 super.onCreate(icicle); 32 Log.i(getTag(), "onCreate"); 33 } 34 35 @Override onStart()36 protected void onStart() { 37 super.onStart(); 38 Log.i(getTag(), "onStart"); 39 } 40 41 @Override onResume()42 protected void onResume() { 43 super.onResume(); 44 Log.i(getTag(), "onResume"); 45 } 46 47 @Override onTopResumedActivityChanged(boolean isTopResumedActivity)48 public void onTopResumedActivityChanged(boolean isTopResumedActivity) { 49 super.onTopResumedActivityChanged(isTopResumedActivity); 50 Log.i(getTag(), "onTopResumedActivityChanged: " + isTopResumedActivity); 51 } 52 53 @Override onConfigurationChanged(Configuration newConfig)54 public void onConfigurationChanged(Configuration newConfig) { 55 super.onConfigurationChanged(newConfig); 56 Log.i(getTag(), "onConfigurationChanged"); 57 } 58 59 @Override onMultiWindowModeChanged(boolean isInMultiWindowMode, Configuration newConfig)60 public void onMultiWindowModeChanged(boolean isInMultiWindowMode, Configuration newConfig) { 61 super.onMultiWindowModeChanged(isInMultiWindowMode, newConfig); 62 Log.i(getTag(), "onMultiWindowModeChanged"); 63 } 64 65 @Override onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Configuration newConfig)66 public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, 67 Configuration newConfig) { 68 super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig); 69 Log.i(getTag(), "onPictureInPictureModeChanged"); 70 } 71 72 @Override onPause()73 protected void onPause() { 74 super.onPause(); 75 Log.i(getTag(), "onPause"); 76 } 77 78 @Override onStop()79 protected void onStop() { 80 super.onStop(); 81 Log.i(getTag(), "onStop"); 82 } 83 84 @Override onDestroy()85 protected void onDestroy() { 86 super.onDestroy(); 87 Log.i(getTag(), "onDestroy"); 88 } 89 90 @Override onUserLeaveHint()91 protected void onUserLeaveHint() { 92 super.onUserLeaveHint(); 93 Log.i(getTag(), "onUserLeaveHint"); 94 } 95 dumpConfiguration(Configuration config)96 protected void dumpConfiguration(Configuration config) { 97 Log.i(getTag(), "Configuration: " + config); 98 withTestJournalClient(client -> { 99 final Bundle extras = new Bundle(); 100 extras.putParcelable(EXTRA_CONFIGURATION, config); 101 client.putExtras(extras); 102 }); 103 } 104 dumpConfigInfo()105 protected void dumpConfigInfo() { 106 // Here dumps when idle because the {@link ConfigInfo} includes some information (display 107 // related) got from the attached decor view (after resume). Also if there are several 108 // incoming lifecycle callbacks in a short time, it prefers to dump in a stable state. 109 runWhenIdle(() -> withTestJournalClient(client -> { 110 final ConfigInfo configInfo = getConfigInfo(); 111 Log.i(getTag(), configInfo.toString()); 112 client.setLastConfigInfo(configInfo); 113 })); 114 } 115 } 116