1 /* 2 * Copyright (C) 2022 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.activity.lifecycle; 18 19 import static android.server.wm.activity.lifecycle.LifecycleConstants.EXTRA_SKIP_TOP_RESUMED_STATE; 20 import static android.server.wm.activity.lifecycle.LifecycleConstants.ON_ACTIVITY_RESULT; 21 import static android.server.wm.activity.lifecycle.LifecycleConstants.ON_MULTI_WINDOW_MODE_CHANGED; 22 import static android.server.wm.activity.lifecycle.LifecycleConstants.ON_NEW_INTENT; 23 import static android.server.wm.activity.lifecycle.LifecycleConstants.ON_POST_CREATE; 24 import static android.server.wm.activity.lifecycle.LifecycleConstants.ON_TOP_POSITION_GAINED; 25 import static android.server.wm.activity.lifecycle.LifecycleConstants.ON_TOP_POSITION_LOST; 26 27 import android.content.Intent; 28 import android.content.res.Configuration; 29 import android.os.Bundle; 30 31 /** 32 * Base activity that records callbacks in addition to main lifecycle transitions. 33 */ 34 public class CallbackTrackingActivity extends LifecycleTrackingActivity { 35 36 @Override onActivityResult(int requestCode, int resultCode, Intent data)37 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 38 super.onActivityResult(requestCode, resultCode, data); 39 mEventLogClient.onCallback(ON_ACTIVITY_RESULT); 40 } 41 42 @Override onPostCreate(Bundle savedInstanceState)43 protected void onPostCreate(Bundle savedInstanceState) { 44 super.onPostCreate(savedInstanceState); 45 mEventLogClient.onCallback(ON_POST_CREATE); 46 } 47 48 @Override onNewIntent(Intent intent)49 protected void onNewIntent(Intent intent) { 50 super.onNewIntent(intent); 51 mEventLogClient.onCallback(ON_NEW_INTENT); 52 setIntent(intent); 53 } 54 55 @Override onTopResumedActivityChanged(boolean isTopResumedActivity)56 public void onTopResumedActivityChanged(boolean isTopResumedActivity) { 57 if (!getIntent().getBooleanExtra(EXTRA_SKIP_TOP_RESUMED_STATE, false)) { 58 mEventLogClient.onCallback( 59 isTopResumedActivity ? ON_TOP_POSITION_GAINED : ON_TOP_POSITION_LOST); 60 } 61 } 62 63 @Override onMultiWindowModeChanged(boolean isInMultiWindowMode, Configuration newConfig)64 public void onMultiWindowModeChanged(boolean isInMultiWindowMode, Configuration newConfig) { 65 mEventLogClient.onCallback(ON_MULTI_WINDOW_MODE_CHANGED); 66 } 67 } 68