1 /* 2 * Copyright (C) 2024 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.app.jank.tests; 18 19 import android.app.jank.AppJankStats; 20 import android.app.jank.JankTracker; 21 import android.content.Context; 22 import android.util.AttributeSet; 23 import android.view.View; 24 25 public class TestWidget extends View { 26 27 private JankTracker mJankTracker; 28 29 /** 30 * Create JankTrackerView 31 */ TestWidget(Context context)32 public TestWidget(Context context) { 33 super(context); 34 } 35 36 /** 37 * Create JankTrackerView, needed by system when inflating views defined in a layout file. 38 */ TestWidget(Context context, AttributeSet attributeSet)39 public TestWidget(Context context, AttributeSet attributeSet) { 40 super(context, attributeSet); 41 } 42 43 /** 44 * Mock starting an animation. 45 */ simulateAnimationStarting()46 public void simulateAnimationStarting() { 47 if (jankTrackerCreated()) { 48 mJankTracker.addUiState(AppJankStats.WIDGET_CATEGORY_ANIMATION, 49 Integer.toString(this.getId()), AppJankStats.WIDGET_STATE_ANIMATING); 50 } 51 } 52 53 /** 54 * Mock ending an animation. 55 */ simulateAnimationEnding()56 public void simulateAnimationEnding() { 57 if (jankTrackerCreated()) { 58 mJankTracker.removeUiState(AppJankStats.WIDGET_CATEGORY_ANIMATION, 59 Integer.toString(this.getId()), AppJankStats.WIDGET_STATE_ANIMATING); 60 } 61 } 62 jankTrackerCreated()63 private boolean jankTrackerCreated() { 64 if (mJankTracker == null) { 65 mJankTracker = getJankTracker(); 66 } 67 return mJankTracker != null; 68 } 69 } 70