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.Locale;
     27 import java.util.concurrent.CountDownLatch;
     28 
     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 GLESSurfaceView mGLView;
     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     @Override
     51     public void onCreate(Bundle savedInstanceState) {
     52         super.onCreate(savedInstanceState);
     53 
     54         ActivityManager am =
     55                 (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
     56         ConfigurationInfo info = am.getDeviceConfigurationInfo();
     57         boolean useGL20 = (info.reqGlEsVersion >= 0x20000);
     58 
     59         mGLView = new GLESSurfaceView(this, useGL20, mDone);
     60         setContentView(mGLView);
     61 
     62         Configuration con = getResources().getConfiguration();
     63         String touchScreen = null;
     64         if (con.touchscreen == Configuration.TOUCHSCREEN_UNDEFINED) {
     65             touchScreen = "undefined";
     66         } else if (con.touchscreen == Configuration.TOUCHSCREEN_NOTOUCH) {
     67             touchScreen = "notouch";
     68         } else if (con.touchscreen == Configuration.TOUCHSCREEN_STYLUS) {
     69             touchScreen = "stylus";
     70         } else if (con.touchscreen == Configuration.TOUCHSCREEN_FINGER) {
     71             touchScreen = "finger";
     72         }
     73         if (touchScreen != null) {
     74             DeviceInfoInstrument.addResult(DeviceInfoConstants.TOUCH_SCREEN,
     75                     touchScreen);
     76         }
     77 
     78         String navigation = null;
     79         if (con.navigation == Configuration.NAVIGATION_UNDEFINED) {
     80             navigation = "undefined";
     81         } else if (con.navigation == Configuration.NAVIGATION_NONAV) {
     82             navigation = "nonav";
     83         } else if (con.navigation == Configuration.NAVIGATION_DPAD) {
     84             navigation = "drap";
     85         } else if (con.navigation == Configuration.NAVIGATION_TRACKBALL) {
     86             navigation = "trackball";
     87         } else if (con.navigation == Configuration.NAVIGATION_WHEEL) {
     88             navigation = "wheel";
     89         }
     90 
     91         if (navigation != null) {
     92             DeviceInfoInstrument.addResult(DeviceInfoConstants.NAVIGATION,
     93                     navigation);
     94         }
     95 
     96         String keypad = null;
     97         if (con.keyboard == Configuration.KEYBOARD_UNDEFINED) {
     98             keypad = "undefined";
     99         } else if (con.keyboard == Configuration.KEYBOARD_NOKEYS) {
    100             keypad = "nokeys";
    101         } else if (con.keyboard == Configuration.KEYBOARD_QWERTY) {
    102             keypad = "qwerty";
    103         } else if (con.keyboard == Configuration.KEYBOARD_12KEY) {
    104             keypad = "12key";
    105         }
    106         if (keypad != null) {
    107             DeviceInfoInstrument.addResult(DeviceInfoConstants.KEYPAD, keypad);
    108         }
    109 
    110         String[] locales = getAssets().getLocales();
    111         StringBuilder localeList = new StringBuilder();
    112         for (String s : locales) {
    113             if (s.length() == 0) { // default locale
    114                 localeList.append(new Locale("en", "US").toString());
    115             } else {
    116                 localeList.append(s);
    117             }
    118             localeList.append(";");
    119         }
    120         DeviceInfoInstrument.addResult(DeviceInfoConstants.LOCALES,
    121                 localeList.toString());
    122     }
    123 }
    124