Home | History | Annotate | Download | only in getinfo
      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 
     26 import java.util.HashSet;
     27 import java.util.Locale;
     28 import java.util.concurrent.CountDownLatch;
     29 
     30 /**
     31  * Collect device information on target device.
     32  */
     33 public class DeviceInfoActivity extends Activity {
     34 
     35     // work done should be reported in GLES..View
     36     private CountDownLatch mDone = new CountDownLatch(1);
     37     private HashSet<String> mFormats = new HashSet<String>();
     38 
     39     /**
     40      * Other classes can call this function to wait for this activity
     41      * to finish. */
     42     public void waitForAcitityToFinish() {
     43         try {
     44             mDone.await();
     45         } catch (InterruptedException e) {
     46             // just move on
     47         }
     48     }
     49 
     50     private void runIterations(int glVersion) {
     51         for (int i = 1; i <= glVersion; i++) {
     52             final CountDownLatch done = new CountDownLatch(1);
     53             final int version = i;
     54             DeviceInfoActivity.this.runOnUiThread(new Runnable() {
     55               public void run() {
     56                 setContentView(new GLESSurfaceView(DeviceInfoActivity.this, version, done));
     57               }
     58             });
     59             try {
     60                 done.await();
     61             } catch (InterruptedException e) {
     62                 // just move on
     63             }
     64         }
     65 
     66         StringBuilder builder = new StringBuilder();
     67         for (String format: mFormats) {
     68             builder.append(format);
     69             builder.append(";");
     70         }
     71         DeviceInfoInstrument.addResult(
     72                 DeviceInfoConstants.OPEN_GL_COMPRESSED_TEXTURE_FORMATS,
     73                 builder.toString());
     74         mDone.countDown();
     75     }
     76 
     77     public void addCompressedTextureFormat(String format) {
     78         mFormats.add(format);
     79     }
     80 
     81     @Override
     82     public void onCreate(Bundle savedInstanceState) {
     83         super.onCreate(savedInstanceState);
     84 
     85         ActivityManager am =
     86                 (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
     87         ConfigurationInfo info = am.getDeviceConfigurationInfo();
     88         final int glVersion = (info.reqGlEsVersion & 0xffff0000) >> 16;
     89         new Thread() {
     90           public void run() {
     91             runIterations(glVersion);
     92           }
     93         }.start();
     94 
     95         Configuration con = getResources().getConfiguration();
     96         String touchScreen = null;
     97         if (con.touchscreen == Configuration.TOUCHSCREEN_UNDEFINED) {
     98             touchScreen = "undefined";
     99         } else if (con.touchscreen == Configuration.TOUCHSCREEN_NOTOUCH) {
    100             touchScreen = "notouch";
    101         } else if (con.touchscreen == Configuration.TOUCHSCREEN_STYLUS) {
    102             touchScreen = "stylus";
    103         } else if (con.touchscreen == Configuration.TOUCHSCREEN_FINGER) {
    104             touchScreen = "finger";
    105         }
    106         if (touchScreen != null) {
    107             DeviceInfoInstrument.addResult(DeviceInfoConstants.TOUCH_SCREEN,
    108                     touchScreen);
    109         }
    110 
    111         String navigation = null;
    112         if (con.navigation == Configuration.NAVIGATION_UNDEFINED) {
    113             navigation = "undefined";
    114         } else if (con.navigation == Configuration.NAVIGATION_NONAV) {
    115             navigation = "nonav";
    116         } else if (con.navigation == Configuration.NAVIGATION_DPAD) {
    117             navigation = "drap";
    118         } else if (con.navigation == Configuration.NAVIGATION_TRACKBALL) {
    119             navigation = "trackball";
    120         } else if (con.navigation == Configuration.NAVIGATION_WHEEL) {
    121             navigation = "wheel";
    122         }
    123 
    124         if (navigation != null) {
    125             DeviceInfoInstrument.addResult(DeviceInfoConstants.NAVIGATION,
    126                     navigation);
    127         }
    128 
    129         String keypad = null;
    130         if (con.keyboard == Configuration.KEYBOARD_UNDEFINED) {
    131             keypad = "undefined";
    132         } else if (con.keyboard == Configuration.KEYBOARD_NOKEYS) {
    133             keypad = "nokeys";
    134         } else if (con.keyboard == Configuration.KEYBOARD_QWERTY) {
    135             keypad = "qwerty";
    136         } else if (con.keyboard == Configuration.KEYBOARD_12KEY) {
    137             keypad = "12key";
    138         }
    139         if (keypad != null) {
    140             DeviceInfoInstrument.addResult(DeviceInfoConstants.KEYPAD, keypad);
    141         }
    142 
    143         String[] locales = getAssets().getLocales();
    144         StringBuilder localeList = new StringBuilder();
    145         for (String s : locales) {
    146             if (s.length() == 0) { // default locale
    147                 localeList.append(new Locale("en", "US").toString());
    148             } else {
    149                 localeList.append(s);
    150             }
    151             localeList.append(";");
    152         }
    153         DeviceInfoInstrument.addResult(DeviceInfoConstants.LOCALES,
    154                 localeList.toString());
    155     }
    156 }
    157