• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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                 public void run() {
61                     setContentView(new GLESSurfaceView(DeviceInfoActivity.this, version, done));
62                 }
63             });
64             try {
65                 done.await();
66             } catch (InterruptedException e) {
67                 // just move on
68             }
69         }
70 
71         StringBuilder textureBuilder = new StringBuilder();
72         for (String format: mFormats) {
73             textureBuilder.append(format).append(";");
74         }
75         StringBuilder extensionBuilder = new StringBuilder();
76         for (String extension : mOpenGlExtensions) {
77             extensionBuilder.append(extension).append(";");
78         }
79         DeviceInfoInstrument.addResult(
80                 DeviceInfoConstants.OPEN_GL_EXTENSIONS,
81                 extensionBuilder.toString());
82         DeviceInfoInstrument.addResult(
83                 DeviceInfoConstants.OPEN_GL_COMPRESSED_TEXTURE_FORMATS,
84                 textureBuilder.toString());
85         DeviceInfoInstrument.addResult(
86                 DeviceInfoConstants.GRAPHICS_VENDOR,
87                 mGraphicsVendor);
88         DeviceInfoInstrument.addResult(
89                 DeviceInfoConstants.GRAPHICS_RENDERER,
90                 mGraphicsRenderer);
91         mDone.countDown();
92     }
93 
addOpenGlExtension(String openGlExtension)94     public void addOpenGlExtension(String openGlExtension) {
95         mOpenGlExtensions.add(openGlExtension);
96     }
97 
addCompressedTextureFormat(String format)98     public void addCompressedTextureFormat(String format) {
99         mFormats.add(format);
100     }
101 
setGraphicsInfo(String vendor, String renderer)102     public void setGraphicsInfo(String vendor, String renderer) {
103         mGraphicsVendor = vendor;
104         mGraphicsRenderer = renderer;
105     }
106 
107     @Override
onCreate(Bundle savedInstanceState)108     public void onCreate(Bundle savedInstanceState) {
109         super.onCreate(savedInstanceState);
110         Window w = getWindow();
111         w.setFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED,
112                 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
113 
114         ActivityManager am =
115                 (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
116         ConfigurationInfo info = am.getDeviceConfigurationInfo();
117         final int glVersion = (info.reqGlEsVersion & 0xffff0000) >> 16;
118         new Thread() {
119             public void run() {
120                 runIterations(glVersion);
121             }
122         }.start();
123 
124         Configuration con = getResources().getConfiguration();
125         String touchScreen = null;
126         if (con.touchscreen == Configuration.TOUCHSCREEN_UNDEFINED) {
127             touchScreen = "undefined";
128         } else if (con.touchscreen == Configuration.TOUCHSCREEN_NOTOUCH) {
129             touchScreen = "notouch";
130         } else if (con.touchscreen == Configuration.TOUCHSCREEN_STYLUS) {
131             touchScreen = "stylus";
132         } else if (con.touchscreen == Configuration.TOUCHSCREEN_FINGER) {
133             touchScreen = "finger";
134         }
135         if (touchScreen != null) {
136             DeviceInfoInstrument.addResult(DeviceInfoConstants.TOUCH_SCREEN,
137                     touchScreen);
138         }
139 
140         String navigation = null;
141         if (con.navigation == Configuration.NAVIGATION_UNDEFINED) {
142             navigation = "undefined";
143         } else if (con.navigation == Configuration.NAVIGATION_NONAV) {
144             navigation = "nonav";
145         } else if (con.navigation == Configuration.NAVIGATION_DPAD) {
146             navigation = "drap";
147         } else if (con.navigation == Configuration.NAVIGATION_TRACKBALL) {
148             navigation = "trackball";
149         } else if (con.navigation == Configuration.NAVIGATION_WHEEL) {
150             navigation = "wheel";
151         }
152 
153         if (navigation != null) {
154             DeviceInfoInstrument.addResult(DeviceInfoConstants.NAVIGATION,
155                     navigation);
156         }
157 
158         String keypad = null;
159         if (con.keyboard == Configuration.KEYBOARD_UNDEFINED) {
160             keypad = "undefined";
161         } else if (con.keyboard == Configuration.KEYBOARD_NOKEYS) {
162             keypad = "nokeys";
163         } else if (con.keyboard == Configuration.KEYBOARD_QWERTY) {
164             keypad = "qwerty";
165         } else if (con.keyboard == Configuration.KEYBOARD_12KEY) {
166             keypad = "12key";
167         }
168         if (keypad != null) {
169             DeviceInfoInstrument.addResult(DeviceInfoConstants.KEYPAD, keypad);
170         }
171 
172         String[] locales = getAssets().getLocales();
173         StringBuilder localeList = new StringBuilder();
174         for (String s : locales) {
175             if (s.length() == 0) { // default locale
176                 localeList.append(new Locale("en", "US").toString());
177             } else {
178                 localeList.append(s);
179             }
180             localeList.append(";");
181         }
182         DeviceInfoInstrument.addResult(DeviceInfoConstants.LOCALES,
183                 localeList.toString());
184     }
185 }
186