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.am; 18 19 import android.app.Activity; 20 import android.content.res.Configuration; 21 import android.graphics.Point; 22 import android.os.Bundle; 23 import android.util.DisplayMetrics; 24 import android.util.Log; 25 import android.view.Display; 26 import android.view.WindowManager; 27 28 public abstract class AbstractLifecycleLogActivity extends Activity { 29 30 @Override 31 protected void onCreate(Bundle icicle) { 32 super.onCreate(icicle); 33 Log.i(getTag(), "onCreate"); 34 } 35 36 @Override 37 protected void onStart() { 38 super.onResume(); 39 Log.i(getTag(), "onStart"); 40 } 41 42 @Override 43 protected void onResume() { 44 super.onResume(); 45 Log.i(getTag(), "onResume"); 46 } 47 48 @Override 49 public void onConfigurationChanged(Configuration newConfig) { 50 super.onConfigurationChanged(newConfig); 51 Log.i(getTag(), "onConfigurationChanged"); 52 } 53 54 @Override 55 public void onMultiWindowModeChanged(boolean isInMultiWindowMode, Configuration newConfig) { 56 super.onMultiWindowModeChanged(isInMultiWindowMode, newConfig); 57 Log.i(getTag(), "onMultiWindowModeChanged"); 58 } 59 60 @Override 61 public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, 62 Configuration newConfig) { 63 super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig); 64 Log.i(getTag(), "onPictureInPictureModeChanged"); 65 } 66 67 @Override 68 protected void onPause() { 69 super.onPause(); 70 Log.i(getTag(), "onPause"); 71 } 72 73 @Override 74 protected void onStop() { 75 super.onStop(); 76 Log.i(getTag(), "onStop"); 77 } 78 79 @Override 80 protected void onDestroy() { 81 super.onDestroy(); 82 Log.i(getTag(), "onDestroy"); 83 } 84 85 @Override 86 protected void onUserLeaveHint() { 87 super.onUserLeaveHint(); 88 Log.i(getTag(), "onUserLeaveHint"); 89 } 90 91 protected final String getTag() { 92 return getClass().getSimpleName(); 93 } 94 95 protected void dumpConfiguration(Configuration config) { 96 Log.i(getTag(), "Configuration: " + config); 97 } 98 99 protected void dumpDisplaySize(Configuration config) { 100 // Dump the display size as seen by this Activity. 101 final WindowManager wm = getSystemService(WindowManager.class); 102 final Display display = wm.getDefaultDisplay(); 103 final Point point = new Point(); 104 display.getSize(point); 105 final DisplayMetrics metrics = getResources().getDisplayMetrics(); 106 107 final String line = "config" 108 + " size=" + buildCoordString(config.screenWidthDp, config.screenHeightDp) 109 + " displaySize=" + buildCoordString(point.x, point.y) 110 + " metricsSize=" + buildCoordString(metrics.widthPixels, metrics.heightPixels) 111 + " smallestScreenWidth=" + config.smallestScreenWidthDp 112 + " densityDpi=" + config.densityDpi 113 + " orientation=" + config.orientation; 114 115 Log.i(getTag(), line); 116 } 117 118 protected static String buildCoordString(int x, int y) { 119 return "(" + x + "," + y + ")"; 120 } 121 } 122