• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 **
3 ** Copyright 2006, The Android Open Source Project
4 **
5 ** Licensed under the Apache License, Version 2.0 (the "License");
6 ** you may not use this file except in compliance with the License.
7 ** You may obtain a copy of the License at
8 **
9 **     http://www.apache.org/licenses/LICENSE-2.0
10 **
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
16 */
17 
18 package com.android.development;
19 
20 import com.android.development.R;
21 import android.app.Activity;
22 import android.app.ListActivity;
23 import android.content.Context;
24 import android.content.Intent;
25 import android.content.pm.ConfigurationInfo;
26 import android.content.pm.ApplicationInfo;
27 import android.content.pm.PackageInfo;
28 import android.content.pm.PackageManager;
29 import android.content.pm.PackageManager.NameNotFoundException;
30 import android.content.res.Configuration;
31 import android.os.Bundle;
32 import android.util.Log;
33 import android.view.View;
34 import android.view.ViewGroup;
35 import android.view.LayoutInflater;
36 import android.widget.BaseAdapter;
37 import android.widget.LinearLayout;
38 import android.widget.ListView;
39 import android.widget.TextView;
40 import java.text.Collator;
41 import java.util.ArrayList;
42 import java.util.Collections;
43 import java.util.Comparator;
44 import java.util.HashSet;
45 import java.util.List;
46 
47 /* This activity displays the hardware configuration details
48  * of an application as defined in its manifests
49  */
50 public class AppHwPref extends Activity {
51     private static final String TAG = "AppHwPref";
52     PackageManager mPm;
53     private static final int BASE = 0;
54     private static final int TOUCHSCREEN = BASE + 1;
55     private static final int KEYBOARD_TYPE = BASE + 2;
56     private static final int NAVIGATION = BASE + 3;
57     private static final int GLES_VERSION = BASE + 4;
58 
59     @Override
onCreate(Bundle icicle)60     protected void onCreate(Bundle icicle) {
61         super.onCreate(icicle);
62         Intent intent = getIntent();
63         String pkgName = intent.getStringExtra("packageName");
64         if(pkgName == null) {
65            handleError("Null package name", true);
66            return;
67         }
68         mPm = getPackageManager();
69         PackageInfo pInfo;
70         try {
71             pInfo = mPm.getPackageInfo(pkgName, PackageManager.GET_CONFIGURATIONS);
72         } catch (NameNotFoundException e) {
73             pInfo = null;
74         }
75         if(pInfo == null) {
76             handleError("Failed retrieving packageInfo for pkg:"+pkgName, true);
77             return;
78         }
79         ConfigurationInfo appHwPref[] = pInfo.configPreferences;
80 
81         setContentView(R.layout.application_hw_pref);
82         if(appHwPref != null) {
83             displayTextView(R.id.attr_package, pInfo.applicationInfo.loadLabel(mPm));
84             displayTextView(R.id.attr_touchscreen, appHwPref, TOUCHSCREEN);
85             displayTextView(R.id.attr_input_method, appHwPref, KEYBOARD_TYPE);
86             displayTextView(R.id.attr_navigation, appHwPref, NAVIGATION);
87             displayFlag(R.id.attr_hard_keyboard, ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD, appHwPref);
88             displayFlag(R.id.attr_five_way_nav, ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV, appHwPref);
89            displayTextView(R.id.attr_gles_version, appHwPref, GLES_VERSION);
90         }
91     }
92 
displayFlag(int viewId, int flagMask, ConfigurationInfo[] appHwPref)93     void displayFlag(int viewId, int flagMask, ConfigurationInfo[] appHwPref) {
94         if(appHwPref == null) {
95             return;
96         }
97         boolean flag = false;
98         for (int i = 0; i < appHwPref.length; i++) {
99             ConfigurationInfo pref = appHwPref[i];
100             if((pref.reqInputFeatures & flagMask) != 0) {
101                 flag = true;
102                 break;
103             }
104         }
105         if(flag) {
106             displayTextView(viewId, "true");
107         } else {
108             displayTextView(viewId, "false");
109         }
110     }
111 
handleError(String errMsg, boolean finish)112     void handleError(String errMsg, boolean finish) {
113         // TODO display dialog
114         Log.i(TAG, errMsg);
115         if(finish) {
116             finish();
117         }
118     }
119 
displayTextView(int textViewId, CharSequence displayStr)120     void displayTextView(int textViewId, CharSequence displayStr) {
121         TextView tView = (TextView) findViewById(textViewId);
122         if(displayStr != null) {
123             tView.setText(displayStr);
124         }
125     }
126 
displayTextView(int viewId, ConfigurationInfo[] config, int type)127     void displayTextView(int viewId, ConfigurationInfo[] config, int type) {
128         if((config == null) || (config.length < 1)) {
129             return;
130         }
131 
132         HashSet<String> list = new HashSet<String>();
133         for(int i = 0; i < config.length; i++) {
134             String str = null;
135             switch(type) {
136             case TOUCHSCREEN:
137                 str = getTouchScreenStr(config[i]);
138                 break;
139             case KEYBOARD_TYPE:
140                 str =  getKeyboardTypeStr(config[i]);
141                 break;
142             case NAVIGATION:
143                 str = getNavigationStr(config[i]);
144                 break;
145             case GLES_VERSION:
146                 str = config[i].getGlEsVersion();
147                 break;
148             }
149             if(str != null) {
150                 list.add(str);
151             }
152         }
153         String listStr = "";
154         boolean set = false;
155         for(String str : list) {
156             set = true;
157             listStr += str+",";
158         }
159         if(set) {
160             TextView tView = (TextView)findViewById(viewId);
161             CharSequence txt = listStr.subSequence(0, listStr.length()-1);
162             tView.setText(txt);
163         }
164     }
165 
getTouchScreenStr(ConfigurationInfo appHwPref)166     String getTouchScreenStr(ConfigurationInfo appHwPref) {
167         if(appHwPref == null) {
168             handleError("Invalid HardwareConfigurationObject", true);
169             return null;
170         }
171         switch(appHwPref.reqTouchScreen) {
172         case Configuration.TOUCHSCREEN_FINGER:
173             return "finger";
174         case Configuration.TOUCHSCREEN_NOTOUCH:
175             return "notouch";
176         case Configuration.TOUCHSCREEN_STYLUS:
177             return "stylus";
178         case Configuration.TOUCHSCREEN_UNDEFINED:
179             return null;
180         default:
181                 return null;
182         }
183     }
184 
getKeyboardTypeStr(ConfigurationInfo appHwPref)185     String getKeyboardTypeStr(ConfigurationInfo appHwPref) {
186         if(appHwPref == null) {
187             handleError("Invalid HardwareConfigurationObject", true);
188             return null;
189         }
190         switch(appHwPref.reqKeyboardType) {
191         case Configuration.KEYBOARD_12KEY:
192             return "12key";
193         case Configuration.KEYBOARD_NOKEYS:
194             return "nokeys";
195         case Configuration.KEYBOARD_QWERTY:
196             return "querty";
197         case Configuration.KEYBOARD_UNDEFINED:
198             return null;
199         default:
200                 return null;
201         }
202     }
203 
getNavigationStr(ConfigurationInfo appHwPref)204     String getNavigationStr(ConfigurationInfo appHwPref) {
205         if(appHwPref == null) {
206             handleError("Invalid HardwareConfigurationObject", true);
207             return null;
208         }
209         switch(appHwPref.reqNavigation) {
210         case Configuration.NAVIGATION_DPAD:
211             return "dpad";
212         case Configuration.NAVIGATION_TRACKBALL:
213             return "trackball";
214         case Configuration.NAVIGATION_WHEEL:
215             return "wheel";
216         case Configuration.NAVIGATION_UNDEFINED:
217             return null;
218         default:
219                 return null;
220         }
221     }
222 
223     @Override
onResume()224     protected void onResume() {
225         super.onResume();
226     }
227 
228     @Override
onStop()229     protected void onStop() {
230         super.onStop();
231     }
232 }
233 
234