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.game.qualification.tests;
18 
19 import android.app.Activity;
20 import android.content.Context;
21 import android.os.Bundle;
22 import android.view.SurfaceView;
23 import android.util.AttributeSet;
24 import android.view.SurfaceHolder;
25 import android.view.Surface;
26 
27 import java.util.ArrayList;
28 
29 public class ChoreoTestActivity extends TestActivity {
30     @Override
onCreate(Bundle savedInstanceState)31     protected void onCreate(Bundle savedInstanceState) {
32         super.onCreate(savedInstanceState);
33         ChoreoTestView sv = new ChoreoTestView(this);
34         setContentView(sv);
35     }
36 
37     @Override
onStart()38     protected void onStart() {
39         super.onStart();
40     }
41 
42     private class ChoreoTestView extends SurfaceView implements Runnable {
43         private Thread mThread;
44 
ChoreoTestView(Context context)45         public ChoreoTestView(Context context) {
46             super(context);
47 
48             getHolder().addCallback(new SurfaceHolder.Callback() {
49                 @Override
50                 public void surfaceCreated(SurfaceHolder holder) {
51                     startTheTest();
52                     mThread = new Thread(ChoreoTestView.this);
53                     mThread.start();
54                 }
55 
56                 @Override
57                 public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {}
58 
59                 @Override
60                 public void surfaceDestroyed(SurfaceHolder holder) {
61                     stopTheTest();
62                     try {
63                         if(mThread != null) {
64                             mThread.join();
65                         }
66                     } catch (InterruptedException e) {
67                         throw new RuntimeException(e);
68                     }
69                 }
70             });
71         }
72 
ChoreoTestView(Context context, AttributeSet attrs)73         public ChoreoTestView(Context context, AttributeSet attrs) {
74             super(context, attrs);
75         }
76 
ChoreoTestView(Context context, AttributeSet attrs, int defStyleAttr)77         public ChoreoTestView(Context context, AttributeSet attrs, int defStyleAttr) {
78             super(context, attrs, defStyleAttr);
79         }
80 
ChoreoTestView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)81         public ChoreoTestView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
82             super(context, attrs, defStyleAttr, defStyleRes);
83         }
84 
85         @Override
run()86         public void run() {
87             runTheTest(getHolder().getSurface());
88         }
89     }
90 
startTheTest()91     public native boolean startTheTest();
runTheTest(Object theSurface)92     public native boolean runTheTest(Object theSurface);
stopTheTest()93     public native void stopTheTest();
getFrameIntervals()94     public native ArrayList<Long> getFrameIntervals();
95 }
96