1 /* 2 * Copyright (C) 2018 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 com.android.server.wm.flicker.testapp; 18 19 import static android.os.SystemClock.sleep; 20 21 import static com.android.server.wm.flicker.testapp.ActivityOptions.EXTRA_STARVE_UI_THREAD; 22 23 import android.app.Activity; 24 import android.os.Bundle; 25 import android.os.Handler; 26 import android.os.Looper; 27 import android.os.Message; 28 import android.view.Window; 29 import android.view.WindowManager; 30 31 import java.util.Timer; 32 import java.util.TimerTask; 33 34 public class SeamlessRotationActivity extends Activity { 35 36 @Override onCreate(Bundle savedInstanceState)37 public void onCreate(Bundle savedInstanceState) { 38 super.onCreate(savedInstanceState); 39 enableSeamlessRotation(); 40 setContentView(R.layout.activity_simple); 41 boolean starveUiThread = getIntent().getExtras() != null 42 && getIntent().getExtras().getBoolean(EXTRA_STARVE_UI_THREAD); 43 if (starveUiThread) { 44 starveUiThread(); 45 } 46 } 47 starveUiThread()48 private void starveUiThread() { 49 Handler handler = new Handler(Looper.getMainLooper(), (Message unused) -> { 50 sleep(20); 51 return true; 52 }); 53 new Timer().schedule(new TimerTask() { 54 @Override 55 public void run() { 56 handler.sendEmptyMessage(0); 57 } 58 }, 0, 21); 59 } 60 enableSeamlessRotation()61 private void enableSeamlessRotation() { 62 WindowManager.LayoutParams p = getWindow().getAttributes(); 63 p.rotationAnimation = WindowManager.LayoutParams.ROTATION_ANIMATION_SEAMLESS; 64 p.layoutInDisplayCutoutMode = WindowManager.LayoutParams 65 .LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; 66 requestWindowFeature(Window.FEATURE_NO_TITLE); 67 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 68 WindowManager.LayoutParams.FLAG_FULLSCREEN); 69 getWindow().setAttributes(p); 70 } 71 } 72