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