blob: c6bc762a35d2f79b75a487ee89dc0506883844cd [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;
23import android.os.Build;
24import android.os.Bundle;
25import android.util.DisplayMetrics;
26import android.view.Display;
27import android.view.WindowManager;
28
29public class DeviceInfoInstrument extends Instrumentation {
30 private static final String PHONE_NUMBER = "phoneNumber";
31 public static final String LOCALES = "locales";
32 private static final String IMSI = "imsi";
33 private static final String IMEI = "imei";
34 private static final String NETWORK = "network";
35 public static final String KEYPAD = "keypad";
36 public static final String NAVIGATION = "navigation";
37 public static final String TOUCH_SCREEN = "touch_screen";
38 private static final String SCREEN_Y_DENSITY = "screen_Y_density";
39 private static final String SCREEN_X_DENSITY = "screen_X_density";
40 private static final String SCREEN_DENSITY = "screen_density";
41 private static final String SCREEN_HEIGHT = "screen_height";
42 private static final String SCREEN_WIDTH = "screen_width";
43 private static final String VERSION_SDK = "version_sdk";
44 private static final String VERSION_RELEASE = "version_release";
45 private static final String VERSION_INCREMENTAL = "version_incremental";
46 private static final String BUILD_FINGERPRINT = "build_fingerprint";
47 private static final String BUILD_TAGS = "build_tags";
48 private static final String BUILD_TYPE = "build_type";
49 private static final String BUILD_MODEL = "build_model";
50 private static final String BUILD_BRAND = "build_brand";
51 private static final String BUILD_BOARD = "build_board";
52 private static final String BUILD_DEVICE = "build_device";
53 private static final String PRODUCT_NAME = "product_name";
54 private static final String BUILD_ID = "build_id";
55 private static Bundle mResults = new Bundle();
56
57 public static boolean sIsFinishActivity = false;
58 public static Object sSync = new Object();
59
60 public DeviceInfoInstrument() {
61 super();
62 }
63
64 @Override
65 public void onCreate(Bundle arguments) {
66 start();
67 }
68
69 @Override
70 public void onStart() {
71
72 addResult(BUILD_ID, Build.ID);
73 addResult(PRODUCT_NAME, Build.PRODUCT);
74 addResult(BUILD_DEVICE, Build.DEVICE);
75 addResult(BUILD_BOARD, Build.BOARD);
76 addResult(BUILD_BRAND, Build.BRAND);
77 addResult(BUILD_MODEL, Build.MODEL);
78 addResult(BUILD_TYPE, Build.TYPE);
79 addResult(BUILD_TAGS, Build.TAGS);
80 addResult(BUILD_FINGERPRINT, Build.FINGERPRINT);
81
82 addResult(VERSION_INCREMENTAL, Build.VERSION.INCREMENTAL);
83 addResult(VERSION_RELEASE, Build.VERSION.RELEASE);
84 addResult(VERSION_SDK, Build.VERSION.SDK);
85
86 DisplayMetrics metrics = new DisplayMetrics();
87 WindowManager wm = (WindowManager) getContext().getSystemService(
88 Context.WINDOW_SERVICE);
89 Display d = wm.getDefaultDisplay();
90 d.getMetrics(metrics);
91 addResult(SCREEN_WIDTH, metrics.widthPixels);
92 addResult(SCREEN_HEIGHT, metrics.heightPixels);
93 addResult(SCREEN_DENSITY, metrics.density);
94 addResult(SCREEN_X_DENSITY, metrics.xdpi);
95 addResult(SCREEN_Y_DENSITY, metrics.ydpi);
96
97 Intent intent = new Intent();
98 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
99 intent.setClass(this.getContext(), DeviceInfoActivity.class);
100
101 startActivitySync(intent);
102 synchronized (sSync) {
103 if (!sIsFinishActivity) {
104 try {
105 sSync.wait();
106 } catch (InterruptedException e) {
107 }
108 }
109 }
110
111 // network
112 String network = android.telephony.TelephonyManager.getDefault().getNetworkOperatorName();
113 addResult(NETWORK, network);
114
115 // imei
116 String imei = android.telephony.TelephonyManager.getDefault().getDeviceId();
117 addResult(IMEI, imei);
118
119 // imsi
120 String imsi = android.telephony.TelephonyManager.getDefault().getSubscriberId();
121 addResult(IMSI, imsi);
122
123 // phone number
124 String phoneNumber = android.telephony.TelephonyManager.getDefault().getLine1Number();
125 addResult(PHONE_NUMBER, phoneNumber);
126
127 finish(Activity.RESULT_OK, mResults);
128 }
129
130 /**
131 * Add string result.
132 *
133 * @param key the string of the key name.
134 * @param value string value.
135 */
136 static void addResult(final String key, final String value){
137 mResults.putString(key, value);
138 }
139
140 /**
141 * Add integer result.
142 *
143 * @param key the string of the key name.
144 * @param value integer value.
145 */
146 private void addResult(final String key, final int value){
147 mResults.putInt(key, value);
148 }
149
150 /**
151 * Add float result.
152 *
153 * @param key the string of the key name.
154 * @param value float value.
155 */
156 private void addResult(final String key, final float value){
157 mResults.putFloat(key, value);
158 }
159}