blob: 283605d7d3ad29e9dda3aa1114acb83b646b2ea5 [file] [log] [blame]
The Android Open Source Projectf8057102009-03-15 16:47:16 -07001/*
2 * Copyright (C) 2008 Google Inc.
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
17package android.tests.getinfo;
18
19import android.app.Activity;
20import android.app.Instrumentation;
21import android.content.Context;
22import android.content.Intent;
Brian Muramatsua61d3232010-06-08 12:29:36 -070023import android.content.pm.PackageManager;
The Android Open Source Projectf8057102009-03-15 16:47:16 -070024import android.os.Build;
25import android.os.Bundle;
Brett Chabot62a17ce2009-11-12 13:35:13 -080026import android.telephony.TelephonyManager;
The Android Open Source Projectf8057102009-03-15 16:47:16 -070027import android.util.DisplayMetrics;
28import android.view.Display;
29import android.view.WindowManager;
30
31public class DeviceInfoInstrument extends Instrumentation {
Brian Muramatsua61d3232010-06-08 12:29:36 -070032
33 // Should use XML files in frameworks/base/data/etc to generate dynamically.
34 private static final String[] FEATURES_TO_CHECK = {
35 PackageManager.FEATURE_CAMERA,
36 PackageManager.FEATURE_CAMERA_AUTOFOCUS,
37 PackageManager.FEATURE_CAMERA_FLASH,
38 PackageManager.FEATURE_SENSOR_LIGHT,
39 PackageManager.FEATURE_SENSOR_PROXIMITY,
40 PackageManager.FEATURE_TELEPHONY,
41 PackageManager.FEATURE_TELEPHONY_CDMA,
42 PackageManager.FEATURE_TELEPHONY_GSM,
43 PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH,
44 PackageManager.FEATURE_LIVE_WALLPAPER,
45 };
46
47 private static final String FEATURES = "features";
The Android Open Source Projectf8057102009-03-15 16:47:16 -070048 private static final String PHONE_NUMBER = "phoneNumber";
49 public static final String LOCALES = "locales";
50 private static final String IMSI = "imsi";
51 private static final String IMEI = "imei";
52 private static final String NETWORK = "network";
53 public static final String KEYPAD = "keypad";
54 public static final String NAVIGATION = "navigation";
55 public static final String TOUCH_SCREEN = "touch_screen";
56 private static final String SCREEN_Y_DENSITY = "screen_Y_density";
57 private static final String SCREEN_X_DENSITY = "screen_X_density";
58 private static final String SCREEN_DENSITY = "screen_density";
59 private static final String SCREEN_HEIGHT = "screen_height";
60 private static final String SCREEN_WIDTH = "screen_width";
61 private static final String VERSION_SDK = "version_sdk";
62 private static final String VERSION_RELEASE = "version_release";
63 private static final String VERSION_INCREMENTAL = "version_incremental";
64 private static final String BUILD_FINGERPRINT = "build_fingerprint";
65 private static final String BUILD_TAGS = "build_tags";
66 private static final String BUILD_TYPE = "build_type";
67 private static final String BUILD_MODEL = "build_model";
68 private static final String BUILD_BRAND = "build_brand";
69 private static final String BUILD_BOARD = "build_board";
70 private static final String BUILD_DEVICE = "build_device";
71 private static final String PRODUCT_NAME = "product_name";
72 private static final String BUILD_ID = "build_id";
73 private static Bundle mResults = new Bundle();
74
The Android Open Source Projectf8057102009-03-15 16:47:16 -070075 public DeviceInfoInstrument() {
76 super();
77 }
78
79 @Override
80 public void onCreate(Bundle arguments) {
81 start();
82 }
83
84 @Override
85 public void onStart() {
86
87 addResult(BUILD_ID, Build.ID);
88 addResult(PRODUCT_NAME, Build.PRODUCT);
89 addResult(BUILD_DEVICE, Build.DEVICE);
90 addResult(BUILD_BOARD, Build.BOARD);
91 addResult(BUILD_BRAND, Build.BRAND);
92 addResult(BUILD_MODEL, Build.MODEL);
93 addResult(BUILD_TYPE, Build.TYPE);
94 addResult(BUILD_TAGS, Build.TAGS);
95 addResult(BUILD_FINGERPRINT, Build.FINGERPRINT);
96
97 addResult(VERSION_INCREMENTAL, Build.VERSION.INCREMENTAL);
98 addResult(VERSION_RELEASE, Build.VERSION.RELEASE);
99 addResult(VERSION_SDK, Build.VERSION.SDK);
100
101 DisplayMetrics metrics = new DisplayMetrics();
102 WindowManager wm = (WindowManager) getContext().getSystemService(
103 Context.WINDOW_SERVICE);
104 Display d = wm.getDefaultDisplay();
105 d.getMetrics(metrics);
106 addResult(SCREEN_WIDTH, metrics.widthPixels);
107 addResult(SCREEN_HEIGHT, metrics.heightPixels);
108 addResult(SCREEN_DENSITY, metrics.density);
109 addResult(SCREEN_X_DENSITY, metrics.xdpi);
110 addResult(SCREEN_Y_DENSITY, metrics.ydpi);
111
112 Intent intent = new Intent();
113 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
114 intent.setClass(this.getContext(), DeviceInfoActivity.class);
115
Bill Napier6c12b462009-05-14 11:07:39 -0700116 DeviceInfoActivity activity = (DeviceInfoActivity) startActivitySync(intent);
117 waitForIdleSync();
118 activity.waitForAcitityToFinish();
The Android Open Source Projectf8057102009-03-15 16:47:16 -0700119
Brett Chabot62a17ce2009-11-12 13:35:13 -0800120 TelephonyManager tm = (TelephonyManager) getContext().getSystemService(
121 Context.TELEPHONY_SERVICE);
The Android Open Source Projectf8057102009-03-15 16:47:16 -0700122 // network
Brett Chabot62a17ce2009-11-12 13:35:13 -0800123 String network = tm.getNetworkOperatorName();
The Android Open Source Projectf8057102009-03-15 16:47:16 -0700124 addResult(NETWORK, network);
125
126 // imei
Brett Chabot62a17ce2009-11-12 13:35:13 -0800127 String imei = tm.getDeviceId();
The Android Open Source Projectf8057102009-03-15 16:47:16 -0700128 addResult(IMEI, imei);
129
130 // imsi
Brett Chabot62a17ce2009-11-12 13:35:13 -0800131 String imsi = tm.getSubscriberId();
The Android Open Source Projectf8057102009-03-15 16:47:16 -0700132 addResult(IMSI, imsi);
133
134 // phone number
Brett Chabot62a17ce2009-11-12 13:35:13 -0800135 String phoneNumber = tm.getLine1Number();
The Android Open Source Projectf8057102009-03-15 16:47:16 -0700136 addResult(PHONE_NUMBER, phoneNumber);
137
Brian Muramatsua61d3232010-06-08 12:29:36 -0700138 // features
139 String features = getFeatures();
140 addResult(FEATURES, features);
141
The Android Open Source Projectf8057102009-03-15 16:47:16 -0700142 finish(Activity.RESULT_OK, mResults);
143 }
144
145 /**
146 * Add string result.
147 *
148 * @param key the string of the key name.
149 * @param value string value.
150 */
151 static void addResult(final String key, final String value){
152 mResults.putString(key, value);
153 }
154
155 /**
156 * Add integer result.
157 *
158 * @param key the string of the key name.
159 * @param value integer value.
160 */
161 private void addResult(final String key, final int value){
162 mResults.putInt(key, value);
163 }
164
165 /**
166 * Add float result.
167 *
168 * @param key the string of the key name.
169 * @param value float value.
170 */
171 private void addResult(final String key, final float value){
172 mResults.putFloat(key, value);
173 }
Brian Muramatsua61d3232010-06-08 12:29:36 -0700174
175 /**
176 * Return a summary of the device's feature as a semi-colon-delimited list of colon separated
177 * name and availability pairs like "feature1:true;feature2:false;feature3;true".
178 */
179 private String getFeatures() {
180 StringBuilder builder = new StringBuilder();
181
182 PackageManager packageManager = getContext().getPackageManager();
183 for (String feature : FEATURES_TO_CHECK) {
184 boolean hasFeature = packageManager.hasSystemFeature(feature);
185 builder.append(feature).append(':').append(hasFeature).append(';');
186 }
187
188 return builder.toString();
189 }
The Android Open Source Projectf8057102009-03-15 16:47:16 -0700190}