1 /*
2  * Copyright (C) 2008 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.tests.getinfo;
18 
19 import android.app.Activity;
20 import android.app.ActivityManager;
21 import android.content.Context;
22 import android.content.pm.ConfigurationInfo;
23 import android.content.res.Configuration;
24 import android.os.Bundle;
25 import android.view.Window;
26 import android.view.WindowManager;
27 
28 import java.util.HashSet;
29 import java.util.Locale;
30 import java.util.concurrent.CountDownLatch;
31 
32 /**
33  * Collect device information on target device.
34  */
35 public class DeviceInfoActivity extends Activity {
36 
37     // work done should be reported in GLES..View
38     private CountDownLatch mDone = new CountDownLatch(1);
39     private HashSet<String> mOpenGlExtensions = new HashSet<String>();
40     private HashSet<String> mFormats = new HashSet<String>();
41     private String mGraphicsVendor;
42     private String mGraphicsRenderer;
43 
44     /**
45      * Other classes can call this function to wait for this activity
46      * to finish. */
waitForAcitityToFinish()47     public void waitForAcitityToFinish() {
48         try {
49             mDone.await();
50         } catch (InterruptedException e) {
51             // just move on
52         }
53     }
54 
runIterations(int glVersion)55     private void runIterations(int glVersion) {
56         for (int i = 1; i <= glVersion; i++) {
57             final CountDownLatch done = new CountDownLatch(1);
58             final int version = i;
59             DeviceInfoActivity.this.runOnUiThread(new Runnable() {
60                 @Override
61                 public void run() {
62                     setContentView(new GLESSurfaceView(DeviceInfoActivity.this, version, done));
63                 }
64             });
65             try {
66                 done.await();
67             } catch (InterruptedException e) {
68                 // just move on
69             }
70         }
71 
72         StringBuilder textureBuilder = new StringBuilder();
73         for (String format: mFormats) {
74             textureBuilder.append(format).append(";");
75         }
76         StringBuilder extensionBuilder = new StringBuilder();
77         for (String extension : mOpenGlExtensions) {
78             extensionBuilder.append(extension).append(";");
79         }
80         DeviceInfoInstrument.addResult(
81                 DeviceInfoConstants.OPEN_GL_EXTENSIONS,
82                 extensionBuilder.toString());
83         DeviceInfoInstrument.addResult(
84                 DeviceInfoConstants.OPEN_GL_COMPRESSED_TEXTURE_FORMATS,
85                 textureBuilder.toString());
86         DeviceInfoInstrument.addResult(
87                 DeviceInfoConstants.GRAPHICS_VENDOR,
88                 mGraphicsVendor);
89         DeviceInfoInstrument.addResult(
90                 DeviceInfoConstants.GRAPHICS_RENDERER,
91                 mGraphicsRenderer);
92         mDone.countDown();
93     }
94 
addOpenGlExtension(String openGlExtension)95     public void addOpenGlExtension(String openGlExtension) {
96         mOpenGlExtensions.add(openGlExtension);
97     }
98 
addCompressedTextureFormat(String format)99     public void addCompressedTextureFormat(String format) {
100         mFormats.add(format);
101     }
102 
setGraphicsInfo(String vendor, String renderer)103     public void setGraphicsInfo(String vendor, String renderer) {
104         mGraphicsVendor = vendor;
105         mGraphicsRenderer = renderer;
106     }
107 
108     @Override
onCreate(Bundle savedInstanceState)109     public void onCreate(Bundle savedInstanceState) {
110         // Dismiss keyguard and keep screen on while this test is on.
111         getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
112                 WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
113                 WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
114 
115         super.onCreate(savedInstanceState);
116         Window w = getWindow();
117         w.setFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED,
118                 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
119 
120         ActivityManager am =
121                 (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
122         ConfigurationInfo info = am.getDeviceConfigurationInfo();
123         final int glVersion = (info.reqGlEsVersion & 0xffff0000) >> 16;
124         new Thread() {
125             @Override
126             public void run() {
127                 runIterations(glVersion);
128             }
129         }.start();
130 
131         Configuration con = getResources().getConfiguration();
132         String touchScreen = null;
133         if (con.touchscreen == Configuration.TOUCHSCREEN_UNDEFINED) {
134             touchScreen = "undefined";
135         } else if (con.touchscreen == Configuration.TOUCHSCREEN_NOTOUCH) {
136             touchScreen = "notouch";
137         } else if (con.touchscreen == Configuration.TOUCHSCREEN_STYLUS) {
138             touchScreen = "stylus";
139         } else if (con.touchscreen == Configuration.TOUCHSCREEN_FINGER) {
140             touchScreen = "finger";
141         }
142         if (touchScreen != null) {
143             DeviceInfoInstrument.addResult(DeviceInfoConstants.TOUCH_SCREEN,
144                     touchScreen);
145         }
146 
147         String navigation = null;
148         if (con.navigation == Configuration.NAVIGATION_UNDEFINED) {
149             navigation = "undefined";
150         } else if (con.navigation == Configuration.NAVIGATION_NONAV) {
151             navigation = "nonav";
152         } else if (con.navigation == Configuration.NAVIGATION_DPAD) {
153             navigation = "drap";
154         } else if (con.navigation == Configuration.NAVIGATION_TRACKBALL) {
155             navigation = "trackball";
156         } else if (con.navigation == Configuration.NAVIGATION_WHEEL) {
157             navigation = "wheel";
158         }
159 
160         if (navigation != null) {
161             DeviceInfoInstrument.addResult(DeviceInfoConstants.NAVIGATION,
162                     navigation);
163         }
164 
165         String keypad = null;
166         if (con.keyboard == Configuration.KEYBOARD_UNDEFINED) {
167             keypad = "undefined";
168         } else if (con.keyboard == Configuration.KEYBOARD_NOKEYS) {
169             keypad = "nokeys";
170         } else if (con.keyboard == Configuration.KEYBOARD_QWERTY) {
171             keypad = "qwerty";
172         } else if (con.keyboard == Configuration.KEYBOARD_12KEY) {
173             keypad = "12key";
174         }
175         if (keypad != null) {
176             DeviceInfoInstrument.addResult(DeviceInfoConstants.KEYPAD, keypad);
177         }
178 
179         String[] locales = getAssets().getLocales();
180         StringBuilder localeList = new StringBuilder();
181         for (String s : locales) {
182             if (s.length() == 0) { // default locale
183                 localeList.append(new Locale("en", "US").toString());
184             } else {
185                 localeList.append(s);
186             }
187             localeList.append(";");
188         }
189         DeviceInfoInstrument.addResult(DeviceInfoConstants.LOCALES,
190                 localeList.toString());
191     }
192 }
193