2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.settings;
19 import android.app.Activity;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.content.pm.ApplicationInfo;
23 import android.content.pm.PackageManager;
24 import android.content.pm.ResolveInfo;
25 import android.opengl.GLES20;
26 import android.os.Binder;
27 import android.os.Build;
28 import android.os.Bundle;
29 import android.os.Parcel;
30 import android.os.RemoteException;
31 import android.os.SELinux;
32 import android.os.SystemClock;
33 import android.os.SystemProperties;
34 import android.os.UserHandle;
35 import android.os.UserManager;
36 import android.preference.Preference;
37 import android.preference.PreferenceGroup;
38 import android.preference.PreferenceScreen;
39 import android.provider.SearchIndexableResource;
40 import android.provider.Settings;
41 import android.text.TextUtils;
42 import android.util.Log;
43 import android.widget.Toast;
44 import com.android.settings.search.BaseSearchIndexProvider;
45 import com.android.settings.search.Index;
46 import com.android.settings.search.Indexable;
48 import java.io.BufferedReader;
49 import java.io.FileReader;
50 import java.io.IOException;
51 import java.util.ArrayList;
52 import java.util.Arrays;
53 import java.util.List;
54 import java.util.regex.Matcher;
55 import java.util.regex.Pattern;
57 public class DeviceInfoSettings extends SettingsPreferenceFragment implements Indexable {
59 private static final String LOG_TAG = "DeviceInfoSettings";
60 private static final String FILENAME_PROC_VERSION = "/proc/version";
61 private static final String FILENAME_MSV = "/sys/board_properties/soc/msv";
63 private static final String KEY_CONTAINER = "container";
64 private static final String KEY_REGULATORY_INFO = "regulatory_info";
65 private static final String KEY_TERMS = "terms";
66 private static final String KEY_LICENSE = "license";
67 private static final String KEY_COPYRIGHT = "copyright";
68 private static final String KEY_WEBVIEW_LICENSE = "webview_license";
69 private static final String KEY_SYSTEM_UPDATE_SETTINGS = "system_update_settings";
70 private static final String PROPERTY_URL_SAFETYLEGAL = "ro.url.safetylegal";
71 private static final String PROPERTY_SELINUX_STATUS = "ro.build.selinux";
72 private static final String KEY_KERNEL_VERSION = "kernel_version";
73 private static final String KEY_OPENGL_VERSION = "opengl_version";
74 private static final String KEY_BUILD_NUMBER = "build_number";
75 private static final String KEY_DEVICE_MODEL = "device_model";
76 private static final String KEY_SELINUX_STATUS = "selinux_status";
77 private static final String KEY_BASEBAND_VERSION = "baseband_version";
78 private static final String KEY_FIRMWARE_VERSION = "firmware_version";
79 private static final String KEY_SECURITY_PATCH = "security_patch";
80 private static final String KEY_UPDATE_SETTING = "additional_system_update_settings";
81 private static final String KEY_EQUIPMENT_ID = "fcc_equipment_id";
82 private static final String PROPERTY_EQUIPMENT_ID = "ro.ril.fccid";
83 private static final String KEY_DEVICE_FEEDBACK = "device_feedback";
84 private static final String KEY_SAFETY_LEGAL = "safetylegal";
85 private static final String KEY_DEVICE_MANUFACTURER = "device_manufacturer";
87 static final int TAPS_TO_BE_A_DEVELOPER = 7;
89 long[] mHits = new long[3];
94 public void onCreate(Bundle icicle) {
95 super.onCreate(icicle);
97 addPreferencesFromResource(R.xml.device_info_settings);
99 String opengl_version = "GL Vendor: " + GLES20.glGetString(GLES20.GL_VENDOR) + "\n" +
100 "GL Renderer: " + GLES20.glGetString(GLES20.GL_RENDERER) + "\n" +
101 "GL Version: " + GLES20.glGetString(GLES20.GL_VERSION);
103 setStringSummary(KEY_FIRMWARE_VERSION, Build.VERSION.RELEASE);
104 findPreference(KEY_FIRMWARE_VERSION).setEnabled(true);
105 String patch = Build.VERSION.SECURITY_PATCH;
106 if (!"".equals(patch)) {
107 setStringSummary(KEY_SECURITY_PATCH, patch);
109 getPreferenceScreen().removePreference(findPreference(KEY_SECURITY_PATCH));
112 setValueSummary(KEY_BASEBAND_VERSION, "gsm.version.baseband");
113 setStringSummary(KEY_DEVICE_MODEL, Build.MODEL + getMsvSuffix());
114 setValueSummary(KEY_EQUIPMENT_ID, PROPERTY_EQUIPMENT_ID);
115 setStringSummary(KEY_DEVICE_MODEL, Build.MODEL);
116 setStringSummary(KEY_BUILD_NUMBER, Build.DISPLAY);
117 findPreference(KEY_BUILD_NUMBER).setEnabled(true);
118 findPreference(KEY_KERNEL_VERSION).setSummary(getFormattedKernelVersion());
119 findPreference(KEY_OPENGL_VERSION).setSummary(opengl_version);
120 setStringSummary(KEY_DEVICE_MANUFACTURER, Build.MANUFACTURER);
122 if (!SELinux.isSELinuxEnabled()) {
123 String status = getResources().getString(R.string.selinux_status_disabled);
124 setStringSummary(KEY_SELINUX_STATUS, status);
125 } else if (!SELinux.isSELinuxEnforced()) {
126 String status = getResources().getString(R.string.selinux_status_permissive);
127 setStringSummary(KEY_SELINUX_STATUS, status);
130 // Remove selinux information if property is not present
131 removePreferenceIfPropertyMissing(getPreferenceScreen(), KEY_SELINUX_STATUS,
132 PROPERTY_SELINUX_STATUS);
134 // Remove Safety information preference if PROPERTY_URL_SAFETYLEGAL is not set
135 removePreferenceIfPropertyMissing(getPreferenceScreen(), KEY_SAFETY_LEGAL,
136 PROPERTY_URL_SAFETYLEGAL);
138 // Remove Equipment id preference if FCC ID is not set by RIL
139 removePreferenceIfPropertyMissing(getPreferenceScreen(), KEY_EQUIPMENT_ID,
140 PROPERTY_EQUIPMENT_ID);
142 // Remove Baseband version if wifi-only device
143 if (Utils.isWifiOnly(getActivity())) {
144 getPreferenceScreen().removePreference(findPreference(KEY_BASEBAND_VERSION));
147 // Dont show feedback option if there is no reporter.
148 if (TextUtils.isEmpty(getFeedbackReporterPackage(getActivity()))) {
149 getPreferenceScreen().removePreference(findPreference(KEY_DEVICE_FEEDBACK));
153 * Settings is a generic app and should not contain any device-specific
156 final Activity act = getActivity();
157 // These are contained in the "container" preference group
158 PreferenceGroup parentPreference = (PreferenceGroup) findPreference(KEY_CONTAINER);
159 Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_TERMS,
160 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
161 Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_LICENSE,
162 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
163 Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_COPYRIGHT,
164 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
165 Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_WEBVIEW_LICENSE,
166 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
168 // These are contained by the root preference screen
169 parentPreference = getPreferenceScreen();
170 if (UserHandle.myUserId() == UserHandle.USER_OWNER) {
171 Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference,
172 KEY_SYSTEM_UPDATE_SETTINGS,
173 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
175 // Remove for secondary users
176 removePreference(KEY_SYSTEM_UPDATE_SETTINGS);
179 // Read platform settings for additional system update setting
180 removePreferenceIfBoolFalse(KEY_UPDATE_SETTING,
181 R.bool.config_additional_system_update_setting_enable);
183 // Remove regulatory information if none present.
184 final Intent intent = new Intent(Settings.ACTION_SHOW_REGULATORY_INFO);
185 if (getPackageManager().queryIntentActivities(intent, 0).isEmpty()) {
186 Preference pref = findPreference(KEY_REGULATORY_INFO);
188 getPreferenceScreen().removePreference(pref);
194 public void onResume() {
196 mDevHitCountdown = getActivity().getSharedPreferences(DevelopmentSettings.PREF_FILE,
197 Context.MODE_PRIVATE).getBoolean(DevelopmentSettings.PREF_SHOW,
198 android.os.Build.TYPE.equals("eng")) ? -1 : TAPS_TO_BE_A_DEVELOPER;
203 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
204 if (preference.getKey().equals(KEY_FIRMWARE_VERSION)) {
205 System.arraycopy(mHits, 1, mHits, 0, mHits.length-1);
206 mHits[mHits.length-1] = SystemClock.uptimeMillis();
207 if (mHits[0] >= (SystemClock.uptimeMillis()-500)) {
208 Intent intent = new Intent(Intent.ACTION_MAIN);
209 intent.setClassName("android",
210 com.android.internal.app.PlatLogoActivity.class.getName());
212 startActivity(intent);
213 } catch (Exception e) {
214 Log.e(LOG_TAG, "Unable to start activity " + intent.toString());
217 } else if (preference.getKey().equals(KEY_BUILD_NUMBER)) {
218 // Don't enable developer options for secondary users.
219 if (UserHandle.myUserId() != UserHandle.USER_OWNER) return true;
221 final UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
222 if (um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES)) return true;
224 if (mDevHitCountdown > 0) {
226 if (mDevHitCountdown == 0) {
227 getActivity().getSharedPreferences(DevelopmentSettings.PREF_FILE,
228 Context.MODE_PRIVATE).edit().putBoolean(
229 DevelopmentSettings.PREF_SHOW, true).apply();
230 if (mDevHitToast != null) {
231 mDevHitToast.cancel();
233 mDevHitToast = Toast.makeText(getActivity(), R.string.show_dev_on,
236 // This is good time to index the Developer Options
238 getActivity().getApplicationContext()).updateFromClassNameResource(
239 DevelopmentSettings.class.getName(), true, true);
241 } else if (mDevHitCountdown > 0
242 && mDevHitCountdown < (TAPS_TO_BE_A_DEVELOPER-2)) {
243 if (mDevHitToast != null) {
244 mDevHitToast.cancel();
246 mDevHitToast = Toast.makeText(getActivity(), getResources().getQuantityString(
247 R.plurals.show_dev_countdown, mDevHitCountdown, mDevHitCountdown),
251 } else if (mDevHitCountdown < 0) {
252 if (mDevHitToast != null) {
253 mDevHitToast.cancel();
255 mDevHitToast = Toast.makeText(getActivity(), R.string.show_dev_already,
259 } else if (preference.getKey().equals(KEY_DEVICE_FEEDBACK)) {
262 return super.onPreferenceTreeClick(preferenceScreen, preference);
265 private void removePreferenceIfPropertyMissing(PreferenceGroup preferenceGroup,
266 String preference, String property ) {
267 if (SystemProperties.get(property).equals("")) {
268 // Property is missing so remove preference from group
270 preferenceGroup.removePreference(findPreference(preference));
271 } catch (RuntimeException e) {
272 Log.d(LOG_TAG, "Property '" + property + "' missing and no '"
273 + preference + "' preference");
278 private void removePreferenceIfBoolFalse(String preference, int resId) {
279 if (!getResources().getBoolean(resId)) {
280 Preference pref = findPreference(preference);
282 getPreferenceScreen().removePreference(pref);
287 private void setStringSummary(String preference, String value) {
289 findPreference(preference).setSummary(value);
290 } catch (RuntimeException e) {
291 findPreference(preference).setSummary(
292 getResources().getString(R.string.device_info_default));
296 private void setValueSummary(String preference, String property) {
298 findPreference(preference).setSummary(
299 SystemProperties.get(property,
300 getResources().getString(R.string.device_info_default)));
301 } catch (RuntimeException e) {
306 private void sendFeedback() {
307 String reporterPackage = getFeedbackReporterPackage(getActivity());
308 if (TextUtils.isEmpty(reporterPackage)) {
311 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
312 intent.setPackage(reporterPackage);
313 startActivityForResult(intent, 0);
317 * Reads a line from the specified file.
318 * @param filename the file to read from
319 * @return the first line, if any.
320 * @throws IOException if the file couldn't be read
322 private static String readLine(String filename) throws IOException {
323 BufferedReader reader = new BufferedReader(new FileReader(filename), 256);
325 return reader.readLine();
331 public static String getFormattedKernelVersion() {
333 return formatKernelVersion(readLine(FILENAME_PROC_VERSION));
335 } catch (IOException e) {
337 "IO Exception when getting kernel version for Device Info screen",
340 return "Unavailable";
344 public static String formatKernelVersion(String rawKernelVersion) {
345 // Example (see tests for more):
346 // Linux version 3.0.31-g6fb96c9 (android-build@xxx.xxx.xxx.xxx.com) \
347 // (gcc version 4.6.x-xxx 20120106 (prerelease) (GCC) ) #1 SMP PREEMPT \
348 // Thu Jun 28 11:02:39 PDT 2012
350 final String PROC_VERSION_REGEX =
351 "Linux version (\\S+) " + /* group 1: "3.0.31-g6fb96c9" */
352 "\\((\\S+?)\\) " + /* group 2: "x@y.com" (kernel builder) */
353 "(?:\\(gcc.+? \\)) " + /* ignore: GCC version information */
354 "(#\\d+) " + /* group 3: "#1" */
355 "(?:.*?)?" + /* ignore: optional SMP, PREEMPT, and any CONFIG_FLAGS */
356 "((Sun|Mon|Tue|Wed|Thu|Fri|Sat).+)"; /* group 4: "Thu Jun 28 11:02:39 PDT 2012" */
358 Matcher m = Pattern.compile(PROC_VERSION_REGEX).matcher(rawKernelVersion);
360 Log.e(LOG_TAG, "Regex did not match on /proc/version: " + rawKernelVersion);
361 return "Unavailable";
362 } else if (m.groupCount() < 4) {
363 Log.e(LOG_TAG, "Regex match on /proc/version only returned " + m.groupCount()
365 return "Unavailable";
367 return m.group(1) + "\n" + // 3.0.31-g6fb96c9
368 m.group(2) + " " + m.group(3) + "\n" + // x@y.com #1
369 m.group(4); // Thu Jun 28 11:02:39 PDT 2012
373 * Returns " (ENGINEERING)" if the msv file has a zero value, else returns "".
374 * @return a string to append to the model number description.
376 private String getMsvSuffix() {
377 // Production devices should have a non-zero value. If we can't read it, assume it's a
378 // production device so that we don't accidentally show that it's an ENGINEERING device.
380 String msv = readLine(FILENAME_MSV);
381 // Parse as a hex number. If it evaluates to a zero, then it's an engineering build.
382 if (Long.parseLong(msv, 16) == 0) {
383 return " (ENGINEERING)";
385 } catch (IOException ioe) {
386 // Fail quietly, as the file may not exist on some devices.
387 } catch (NumberFormatException nfe) {
388 // Fail quietly, returning empty string should be sufficient
393 private static String getFeedbackReporterPackage(Context context) {
394 final String feedbackReporter =
395 context.getResources().getString(R.string.oem_preferred_feedback_reporter);
396 if (TextUtils.isEmpty(feedbackReporter)) {
397 // Reporter not configured. Return.
398 return feedbackReporter;
400 // Additional checks to ensure the reporter is on system image, and reporter is
401 // configured to listen to the intent. Otherwise, dont show the "send feedback" option.
402 final Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
404 PackageManager pm = context.getPackageManager();
405 List<ResolveInfo> resolvedPackages =
406 pm.queryIntentActivities(intent, PackageManager.GET_RESOLVED_FILTER);
407 for (ResolveInfo info : resolvedPackages) {
408 if (info.activityInfo != null) {
409 if (!TextUtils.isEmpty(info.activityInfo.packageName)) {
411 ApplicationInfo ai = pm.getApplicationInfo(info.activityInfo.packageName, 0);
412 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
413 // Package is on the system image
414 if (TextUtils.equals(
415 info.activityInfo.packageName, feedbackReporter)) {
416 return feedbackReporter;
419 } catch (PackageManager.NameNotFoundException e) {
420 // No need to do anything here.
431 public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
432 new BaseSearchIndexProvider() {
435 public List<SearchIndexableResource> getXmlResourcesToIndex(
436 Context context, boolean enabled) {
437 final SearchIndexableResource sir = new SearchIndexableResource(context);
438 sir.xmlResId = R.xml.device_info_settings;
439 return Arrays.asList(sir);
443 public List<String> getNonIndexableKeys(Context context) {
444 final List<String> keys = new ArrayList<String>();
445 if (isPropertyMissing(PROPERTY_SELINUX_STATUS)) {
446 keys.add(KEY_SELINUX_STATUS);
448 if (isPropertyMissing(PROPERTY_URL_SAFETYLEGAL)) {
449 keys.add(KEY_SAFETY_LEGAL);
451 if (isPropertyMissing(PROPERTY_EQUIPMENT_ID)) {
452 keys.add(KEY_EQUIPMENT_ID);
454 // Remove Baseband version if wifi-only device
455 if (Utils.isWifiOnly(context)) {
456 keys.add((KEY_BASEBAND_VERSION));
458 // Dont show feedback option if there is no reporter.
459 if (TextUtils.isEmpty(getFeedbackReporterPackage(context))) {
460 keys.add(KEY_DEVICE_FEEDBACK);
462 if (!checkIntentAction(context, "android.settings.TERMS")) {
465 if (!checkIntentAction(context, "android.settings.LICENSE")) {
466 keys.add(KEY_LICENSE);
468 if (!checkIntentAction(context, "android.settings.COPYRIGHT")) {
469 keys.add(KEY_COPYRIGHT);
471 if (!checkIntentAction(context, "android.settings.WEBVIEW_LICENSE")) {
472 keys.add(KEY_WEBVIEW_LICENSE);
474 if (UserHandle.myUserId() != UserHandle.USER_OWNER) {
475 keys.add(KEY_SYSTEM_UPDATE_SETTINGS);
477 if (!context.getResources().getBoolean(
478 R.bool.config_additional_system_update_setting_enable)) {
479 keys.add(KEY_UPDATE_SETTING);
484 private boolean isPropertyMissing(String property) {
485 return SystemProperties.get(property).equals("");
488 private boolean checkIntentAction(Context context, String action) {
489 final Intent intent = new Intent(action);
491 // Find the activity that is in the system image
492 final PackageManager pm = context.getPackageManager();
493 final List<ResolveInfo> list = pm.queryIntentActivities(intent, 0);
494 final int listSize = list.size();
496 for (int i = 0; i < listSize; i++) {
497 ResolveInfo resolveInfo = list.get(i);
498 if ((resolveInfo.activityInfo.applicationInfo.flags &
499 ApplicationInfo.FLAG_SYSTEM) != 0) {