• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.adpf.atom.app2;
18 
19 import static android.adpf.atom.common.ADPFAtomTestConstants.ACTION_CREATE_REGULAR_HINT_SESSIONS;
20 import static android.adpf.atom.common.ADPFAtomTestConstants.ACTION_CREATE_REGULAR_HINT_SESSIONS_MULTIPLE;
21 import static android.adpf.atom.common.ADPFAtomTestConstants.INTENT_ACTION_KEY;
22 
23 import static org.junit.Assert.assertNotNull;
24 import static org.junit.Assume.assumeNotNull;
25 
26 import android.app.Activity;
27 import android.content.Intent;
28 import android.os.Build;
29 import android.os.Bundle;
30 import android.os.PerformanceHintManager;
31 import android.util.Log;
32 import android.widget.RelativeLayout;
33 
34 import com.android.compatibility.common.util.PropertyUtil;
35 
36 /** An activity which performs ADPF actions. */
37 public class ADPFAtomTestActivity extends Activity {
38     private static final String TAG = ADPFAtomTestActivity.class.getSimpleName();
39     private static final int FIRST_API_LEVEL = PropertyUtil.getFirstApiLevel();
40 
41     private RelativeLayout mRelativeLayout;
42 
43     @Override
onCreate(Bundle bundle)44     public void onCreate(Bundle bundle) {
45         super.onCreate(bundle);
46 
47         final Intent intent = this.getIntent();
48         assertNotNull(intent);
49         final String action = intent.getStringExtra(INTENT_ACTION_KEY);
50         assertNotNull(action);
51         switch (action) {
52             case ACTION_CREATE_REGULAR_HINT_SESSIONS:
53                 PerformanceHintManager.Session session = createPerformanceHintSession();
54                 if (FIRST_API_LEVEL < Build.VERSION_CODES.S) {
55                     assumeNotNull(session);
56                 } else {
57                     assertNotNull(session);
58                 }
59                 drawText();
60                 Log.i(TAG, "Created hint session.");
61                 break;
62             case ACTION_CREATE_REGULAR_HINT_SESSIONS_MULTIPLE:
63                 PerformanceHintManager.Session session1 = createPerformanceHintSession();
64                 PerformanceHintManager.Session session2 = createPerformanceHintSession();
65                 PerformanceHintManager.Session session3 = createPerformanceHintSession();
66                 if (FIRST_API_LEVEL < Build.VERSION_CODES.S) {
67                     assumeNotNull(session1);
68                     assumeNotNull(session2);
69                     assumeNotNull(session3);
70                 } else {
71                     assertNotNull(session1);
72                     assertNotNull(session2);
73                     assertNotNull(session3);
74                 }
75                 drawText();
76                 Log.i(TAG, "Created multiple hint sessions.");
77                 break;
78         }
79     }
80 
drawText()81     private void drawText() {
82         setContentView(R.layout.activity_main);
83 
84         mRelativeLayout = findViewById(R.id.idRLView);
85 
86         ADPFAtomTestPaintView paintView = new ADPFAtomTestPaintView(this);
87         mRelativeLayout.addView(paintView);
88     }
89 
createPerformanceHintSession()90     private PerformanceHintManager.Session createPerformanceHintSession() {
91         final long testTargetDuration = 12345678L;
92         PerformanceHintManager hintManager = getApplicationContext().getSystemService(
93                 PerformanceHintManager.class);
94         assertNotNull(hintManager);
95         return hintManager.createHintSession(
96                 new int[]{android.os.Process.myTid()}, testTargetDuration);
97     }
98 }
99