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