• 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.content.res.Configuration;
21 import android.os.Bundle;
22 import android.widget.TextView;
23 
24 import java.util.Locale;
25 
26 
27 /**
28  * Collect device information on target device.
29  */
30 public class DeviceInfoActivity extends Activity {
31     private boolean isActivityFinished = false;
32     private Object sync = new Object();
33 
34     /**
35      * Other classes can call this function to wait for this activity
36      * to finish. */
waitForAcitityToFinish()37     public void waitForAcitityToFinish() {
38         synchronized (sync) {
39             while (!isActivityFinished) {
40                 try {
41                     sync.wait();
42                 } catch (InterruptedException e) {
43                 }
44             }
45         }
46     }
47 
48     @Override
onCreate(Bundle savedInstanceState)49     public void onCreate(Bundle savedInstanceState) {
50         super.onCreate(savedInstanceState);
51 
52         TextView view = new TextView(this);
53         view.setText("hello");
54         setContentView(view);
55         Configuration con = getResources().getConfiguration();
56         String touchScreen = null;
57         if (con.touchscreen == Configuration.TOUCHSCREEN_UNDEFINED) {
58             touchScreen = "undefined";
59         } else if (con.touchscreen == Configuration.TOUCHSCREEN_NOTOUCH) {
60             touchScreen = "notouch";
61         } else if (con.touchscreen == Configuration.TOUCHSCREEN_STYLUS) {
62             touchScreen = "stylus";
63         } else if (con.touchscreen == Configuration.TOUCHSCREEN_FINGER) {
64             touchScreen = "finger";
65         }
66         if (touchScreen != null) {
67             DeviceInfoInstrument.addResult(DeviceInfoInstrument.TOUCH_SCREEN,
68                     touchScreen);
69         }
70 
71         String navigation = null;
72         if (con.navigation == Configuration.NAVIGATION_UNDEFINED) {
73             navigation = "undefined";
74         } else if (con.navigation == Configuration.NAVIGATION_NONAV) {
75             navigation = "nonav";
76         } else if (con.navigation == Configuration.NAVIGATION_DPAD) {
77             navigation = "drap";
78         } else if (con.navigation == Configuration.NAVIGATION_TRACKBALL) {
79             navigation = "trackball";
80         } else if (con.navigation == Configuration.NAVIGATION_WHEEL) {
81             navigation = "wheel";
82         }
83 
84         if (navigation != null) {
85             DeviceInfoInstrument.addResult(DeviceInfoInstrument.NAVIGATION,
86                     navigation);
87         }
88 
89         String keypad = null;
90         if (con.keyboard == Configuration.KEYBOARD_UNDEFINED) {
91             keypad = "undefined";
92         } else if (con.keyboard == Configuration.KEYBOARD_NOKEYS) {
93             keypad = "nokeys";
94         } else if (con.keyboard == Configuration.KEYBOARD_QWERTY) {
95             keypad = "qwerty";
96         } else if (con.keyboard == Configuration.KEYBOARD_12KEY) {
97             keypad = "12key";
98         }
99         if (keypad != null) {
100             DeviceInfoInstrument.addResult(DeviceInfoInstrument.KEYPAD, keypad);
101         }
102 
103         String[] locales = getAssets().getLocales();
104         StringBuilder localeList = new StringBuilder();
105         for (String s : locales) {
106             if (s.length() == 0) { // default locale
107                 localeList.append(new Locale("en", "US").toString());
108             } else {
109                 localeList.append(s);
110             }
111             localeList.append(";");
112         }
113         DeviceInfoInstrument.addResult(DeviceInfoInstrument.LOCALES,
114                 localeList.toString());
115 
116         synchronized (sync) {
117             sync.notify();
118             isActivityFinished = true;
119         }
120     }
121 }
122