The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 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; |
Brian Muramatsu | 4af6c4e | 2010-06-21 16:57:12 -0700 | [diff] [blame^] | 23 | import android.content.pm.FeatureInfo; |
Brian Muramatsu | a61d323 | 2010-06-08 12:29:36 -0700 | [diff] [blame] | 24 | import android.content.pm.PackageManager; |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 25 | import android.os.Build; |
| 26 | import android.os.Bundle; |
Brett Chabot | 62a17ce | 2009-11-12 13:35:13 -0800 | [diff] [blame] | 27 | import android.telephony.TelephonyManager; |
Brian Muramatsu | 5579039 | 2010-06-14 14:45:42 -0700 | [diff] [blame] | 28 | import android.tests.getinfo.RootProcessScanner.MalformedStatMException; |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 29 | import android.util.DisplayMetrics; |
| 30 | import android.view.Display; |
| 31 | import android.view.WindowManager; |
| 32 | |
Brian Muramatsu | 5579039 | 2010-06-14 14:45:42 -0700 | [diff] [blame] | 33 | import java.io.FileNotFoundException; |
Brian Muramatsu | 4af6c4e | 2010-06-21 16:57:12 -0700 | [diff] [blame^] | 34 | import java.util.HashSet; |
| 35 | import java.util.Set; |
Brian Muramatsu | 5579039 | 2010-06-14 14:45:42 -0700 | [diff] [blame] | 36 | |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 37 | public class DeviceInfoInstrument extends Instrumentation { |
Brian Muramatsu | a61d323 | 2010-06-08 12:29:36 -0700 | [diff] [blame] | 38 | |
| 39 | // Should use XML files in frameworks/base/data/etc to generate dynamically. |
| 40 | private static final String[] FEATURES_TO_CHECK = { |
| 41 | PackageManager.FEATURE_CAMERA, |
| 42 | PackageManager.FEATURE_CAMERA_AUTOFOCUS, |
| 43 | PackageManager.FEATURE_CAMERA_FLASH, |
| 44 | PackageManager.FEATURE_SENSOR_LIGHT, |
| 45 | PackageManager.FEATURE_SENSOR_PROXIMITY, |
| 46 | PackageManager.FEATURE_TELEPHONY, |
| 47 | PackageManager.FEATURE_TELEPHONY_CDMA, |
| 48 | PackageManager.FEATURE_TELEPHONY_GSM, |
| 49 | PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH, |
| 50 | PackageManager.FEATURE_LIVE_WALLPAPER, |
| 51 | }; |
| 52 | |
Brian Muramatsu | 5579039 | 2010-06-14 14:45:42 -0700 | [diff] [blame] | 53 | private static final String PROCESSES = "processes"; |
Brian Muramatsu | a61d323 | 2010-06-08 12:29:36 -0700 | [diff] [blame] | 54 | private static final String FEATURES = "features"; |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 55 | private static final String PHONE_NUMBER = "phoneNumber"; |
| 56 | public static final String LOCALES = "locales"; |
| 57 | private static final String IMSI = "imsi"; |
| 58 | private static final String IMEI = "imei"; |
| 59 | private static final String NETWORK = "network"; |
| 60 | public static final String KEYPAD = "keypad"; |
| 61 | public static final String NAVIGATION = "navigation"; |
| 62 | public static final String TOUCH_SCREEN = "touch_screen"; |
| 63 | private static final String SCREEN_Y_DENSITY = "screen_Y_density"; |
| 64 | private static final String SCREEN_X_DENSITY = "screen_X_density"; |
| 65 | private static final String SCREEN_DENSITY = "screen_density"; |
| 66 | private static final String SCREEN_HEIGHT = "screen_height"; |
| 67 | private static final String SCREEN_WIDTH = "screen_width"; |
| 68 | private static final String VERSION_SDK = "version_sdk"; |
| 69 | private static final String VERSION_RELEASE = "version_release"; |
| 70 | private static final String VERSION_INCREMENTAL = "version_incremental"; |
| 71 | private static final String BUILD_FINGERPRINT = "build_fingerprint"; |
| 72 | private static final String BUILD_TAGS = "build_tags"; |
| 73 | private static final String BUILD_TYPE = "build_type"; |
| 74 | private static final String BUILD_MODEL = "build_model"; |
| 75 | private static final String BUILD_BRAND = "build_brand"; |
| 76 | private static final String BUILD_BOARD = "build_board"; |
| 77 | private static final String BUILD_DEVICE = "build_device"; |
| 78 | private static final String PRODUCT_NAME = "product_name"; |
| 79 | private static final String BUILD_ID = "build_id"; |
| 80 | private static Bundle mResults = new Bundle(); |
| 81 | |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 82 | public DeviceInfoInstrument() { |
| 83 | super(); |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public void onCreate(Bundle arguments) { |
| 88 | start(); |
| 89 | } |
| 90 | |
| 91 | @Override |
| 92 | public void onStart() { |
| 93 | |
| 94 | addResult(BUILD_ID, Build.ID); |
| 95 | addResult(PRODUCT_NAME, Build.PRODUCT); |
| 96 | addResult(BUILD_DEVICE, Build.DEVICE); |
| 97 | addResult(BUILD_BOARD, Build.BOARD); |
| 98 | addResult(BUILD_BRAND, Build.BRAND); |
| 99 | addResult(BUILD_MODEL, Build.MODEL); |
| 100 | addResult(BUILD_TYPE, Build.TYPE); |
| 101 | addResult(BUILD_TAGS, Build.TAGS); |
| 102 | addResult(BUILD_FINGERPRINT, Build.FINGERPRINT); |
| 103 | |
| 104 | addResult(VERSION_INCREMENTAL, Build.VERSION.INCREMENTAL); |
| 105 | addResult(VERSION_RELEASE, Build.VERSION.RELEASE); |
| 106 | addResult(VERSION_SDK, Build.VERSION.SDK); |
| 107 | |
| 108 | DisplayMetrics metrics = new DisplayMetrics(); |
| 109 | WindowManager wm = (WindowManager) getContext().getSystemService( |
| 110 | Context.WINDOW_SERVICE); |
| 111 | Display d = wm.getDefaultDisplay(); |
| 112 | d.getMetrics(metrics); |
| 113 | addResult(SCREEN_WIDTH, metrics.widthPixels); |
| 114 | addResult(SCREEN_HEIGHT, metrics.heightPixels); |
| 115 | addResult(SCREEN_DENSITY, metrics.density); |
| 116 | addResult(SCREEN_X_DENSITY, metrics.xdpi); |
| 117 | addResult(SCREEN_Y_DENSITY, metrics.ydpi); |
| 118 | |
| 119 | Intent intent = new Intent(); |
| 120 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 121 | intent.setClass(this.getContext(), DeviceInfoActivity.class); |
| 122 | |
Bill Napier | 6c12b46 | 2009-05-14 11:07:39 -0700 | [diff] [blame] | 123 | DeviceInfoActivity activity = (DeviceInfoActivity) startActivitySync(intent); |
| 124 | waitForIdleSync(); |
| 125 | activity.waitForAcitityToFinish(); |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 126 | |
Brett Chabot | 62a17ce | 2009-11-12 13:35:13 -0800 | [diff] [blame] | 127 | TelephonyManager tm = (TelephonyManager) getContext().getSystemService( |
| 128 | Context.TELEPHONY_SERVICE); |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 129 | // network |
Brett Chabot | 62a17ce | 2009-11-12 13:35:13 -0800 | [diff] [blame] | 130 | String network = tm.getNetworkOperatorName(); |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 131 | addResult(NETWORK, network); |
| 132 | |
| 133 | // imei |
Brett Chabot | 62a17ce | 2009-11-12 13:35:13 -0800 | [diff] [blame] | 134 | String imei = tm.getDeviceId(); |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 135 | addResult(IMEI, imei); |
| 136 | |
| 137 | // imsi |
Brett Chabot | 62a17ce | 2009-11-12 13:35:13 -0800 | [diff] [blame] | 138 | String imsi = tm.getSubscriberId(); |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 139 | addResult(IMSI, imsi); |
| 140 | |
| 141 | // phone number |
Brett Chabot | 62a17ce | 2009-11-12 13:35:13 -0800 | [diff] [blame] | 142 | String phoneNumber = tm.getLine1Number(); |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 143 | addResult(PHONE_NUMBER, phoneNumber); |
| 144 | |
Brian Muramatsu | a61d323 | 2010-06-08 12:29:36 -0700 | [diff] [blame] | 145 | // features |
| 146 | String features = getFeatures(); |
| 147 | addResult(FEATURES, features); |
| 148 | |
Brian Muramatsu | 5579039 | 2010-06-14 14:45:42 -0700 | [diff] [blame] | 149 | // processes |
| 150 | String processes = getProcesses(); |
| 151 | addResult(PROCESSES, processes); |
| 152 | |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 153 | finish(Activity.RESULT_OK, mResults); |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * Add string result. |
| 158 | * |
| 159 | * @param key the string of the key name. |
| 160 | * @param value string value. |
| 161 | */ |
| 162 | static void addResult(final String key, final String value){ |
| 163 | mResults.putString(key, value); |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Add integer result. |
| 168 | * |
| 169 | * @param key the string of the key name. |
| 170 | * @param value integer value. |
| 171 | */ |
| 172 | private void addResult(final String key, final int value){ |
| 173 | mResults.putInt(key, value); |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * Add float result. |
| 178 | * |
| 179 | * @param key the string of the key name. |
| 180 | * @param value float value. |
| 181 | */ |
| 182 | private void addResult(final String key, final float value){ |
| 183 | mResults.putFloat(key, value); |
| 184 | } |
Brian Muramatsu | a61d323 | 2010-06-08 12:29:36 -0700 | [diff] [blame] | 185 | |
| 186 | /** |
| 187 | * Return a summary of the device's feature as a semi-colon-delimited list of colon separated |
Brian Muramatsu | 4af6c4e | 2010-06-21 16:57:12 -0700 | [diff] [blame^] | 188 | * name and availability pairs like "feature1:sdk:true;feature2:sdk:false;feature3:other:true;". |
Brian Muramatsu | a61d323 | 2010-06-08 12:29:36 -0700 | [diff] [blame] | 189 | */ |
| 190 | private String getFeatures() { |
Brian Muramatsu | 4af6c4e | 2010-06-21 16:57:12 -0700 | [diff] [blame^] | 191 | StringBuilder features = new StringBuilder(); |
| 192 | |
| 193 | Set<String> checkedFeatures = new HashSet<String>(); |
Brian Muramatsu | a61d323 | 2010-06-08 12:29:36 -0700 | [diff] [blame] | 194 | |
| 195 | PackageManager packageManager = getContext().getPackageManager(); |
Brian Muramatsu | 4af6c4e | 2010-06-21 16:57:12 -0700 | [diff] [blame^] | 196 | for (String featureName : FEATURES_TO_CHECK) { |
| 197 | checkedFeatures.add(featureName); |
| 198 | boolean hasFeature = packageManager.hasSystemFeature(featureName); |
| 199 | addFeature(features, featureName, "sdk", hasFeature); |
Brian Muramatsu | a61d323 | 2010-06-08 12:29:36 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Brian Muramatsu | 4af6c4e | 2010-06-21 16:57:12 -0700 | [diff] [blame^] | 202 | FeatureInfo[] featureInfos = packageManager.getSystemAvailableFeatures(); |
| 203 | for (FeatureInfo featureInfo : featureInfos) { |
| 204 | if (featureInfo.name != null && !checkedFeatures.contains(featureInfo.name)) { |
| 205 | addFeature(features, featureInfo.name, "other", true); |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | return features.toString(); |
| 210 | } |
| 211 | |
| 212 | private static void addFeature(StringBuilder features, String name, String type, |
| 213 | boolean available) { |
| 214 | features.append(name).append(':').append(type).append(':').append(available).append(';'); |
Brian Muramatsu | a61d323 | 2010-06-08 12:29:36 -0700 | [diff] [blame] | 215 | } |
Brian Muramatsu | 5579039 | 2010-06-14 14:45:42 -0700 | [diff] [blame] | 216 | |
| 217 | /** |
| 218 | * Return a semi-colon-delimited list of the root processes that were running on the phone |
| 219 | * or an error message. |
| 220 | */ |
| 221 | private static String getProcesses() { |
| 222 | StringBuilder builder = new StringBuilder(); |
| 223 | |
| 224 | try { |
| 225 | String[] rootProcesses = RootProcessScanner.getRootProcesses(); |
| 226 | for (String rootProcess : rootProcesses) { |
| 227 | builder.append(rootProcess).append(';'); |
| 228 | } |
| 229 | } catch (FileNotFoundException notFound) { |
| 230 | builder.append(notFound.getMessage()); |
| 231 | } catch (MalformedStatMException malformedStatM) { |
| 232 | builder.append(malformedStatM.getMessage()); |
| 233 | } |
| 234 | |
| 235 | return builder.toString(); |
| 236 | } |
The Android Open Source Project | f805710 | 2009-03-15 16:47:16 -0700 | [diff] [blame] | 237 | } |