blob: be01f7dc57e6dbe474adf1decce6db1fefa245c0 [file] [log] [blame]
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
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 com.android.settings;
18
19import android.content.Intent;
20import android.content.pm.ApplicationInfo;
21import android.content.pm.PackageManager;
22import android.content.pm.ResolveInfo;
The Android Open Source Project1feaa852009-02-10 15:44:05 -080023import android.os.Build;
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070024import android.os.Bundle;
25import android.os.SystemProperties;
26import android.preference.Preference;
27import android.preference.PreferenceActivity;
28import android.preference.PreferenceGroup;
29import android.util.Config;
30import android.util.Log;
31
32import java.io.BufferedReader;
33import java.io.FileReader;
34import java.io.IOException;
35import java.util.List;
36import java.util.regex.Matcher;
37import java.util.regex.Pattern;
38
39public class DeviceInfoSettings extends PreferenceActivity {
40
41 private static final String TAG = "DeviceInfoSettings";
42 private static final boolean LOGD = false || Config.LOGD;
43
44 private static final String KEY_CONTAINER = "container";
45 private static final String KEY_TEAM = "team";
46 private static final String KEY_CONTRIBUTORS = "contributors";
47 private static final String KEY_TERMS = "terms";
48 private static final String KEY_LICENSE = "license";
49 private static final String KEY_COPYRIGHT = "copyright";
The Android Open Source Projectabc48f82008-12-17 18:06:01 -080050 private static final String KEY_SYSTEM_UPDATE_SETTINGS = "system_update_settings";
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070051
52 @Override
53 protected void onCreate(Bundle icicle) {
54 super.onCreate(icicle);
55
56 addPreferencesFromResource(R.xml.device_info_settings);
57
The Android Open Source Project1feaa852009-02-10 15:44:05 -080058 setStringSummary("firmware_version", Build.VERSION.RELEASE);
59 setValueSummary("baseband_version", "gsm.version.baseband");
60 setStringSummary("device_model", Build.MODEL);
61 setStringSummary("build_number", Build.DISPLAY);
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070062 findPreference("kernel_version").setSummary(getFormattedKernelVersion());
63
64 /*
65 * Settings is a generic app and should not contain any device-specific
66 * info.
67 */
The Android Open Source Projectb9f58512009-02-13 12:57:53 -080068
69 // These are contained in the "container" preference group
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070070 PreferenceGroup parentPreference = (PreferenceGroup) findPreference(KEY_CONTAINER);
71 Utils.updatePreferenceToSpecificActivityOrRemove(this, parentPreference, KEY_TERMS,
72 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
73 Utils.updatePreferenceToSpecificActivityOrRemove(this, parentPreference, KEY_LICENSE,
74 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070075 Utils.updatePreferenceToSpecificActivityOrRemove(this, parentPreference, KEY_COPYRIGHT,
76 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
77 Utils.updatePreferenceToSpecificActivityOrRemove(this, parentPreference, KEY_TEAM,
78 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
The Android Open Source Projectb9f58512009-02-13 12:57:53 -080079
80 // These are contained by the root preference screen
81 parentPreference = getPreferenceScreen();
82 Utils.updatePreferenceToSpecificActivityOrRemove(this, parentPreference,
83 KEY_SYSTEM_UPDATE_SETTINGS,
84 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
85 Utils.updatePreferenceToSpecificActivityOrRemove(this, parentPreference, KEY_CONTRIBUTORS,
The Android Open Source Projectabc48f82008-12-17 18:06:01 -080086 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070087 }
88
The Android Open Source Project1feaa852009-02-10 15:44:05 -080089 private void setStringSummary(String preference, String value) {
90 try {
91 findPreference(preference).setSummary(value);
92 } catch (RuntimeException e) {
93 findPreference(preference).setSummary(
94 getResources().getString(R.string.device_info_default));
95 }
96 }
97
98 private void setValueSummary(String preference, String property) {
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070099 try {
100 findPreference(preference).setSummary(
101 SystemProperties.get(property,
102 getResources().getString(R.string.device_info_default)));
103 } catch (RuntimeException e) {
The Android Open Source Project1feaa852009-02-10 15:44:05 -0800104
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -0700105 }
106 }
107
108 private String getFormattedKernelVersion() {
109 String procVersionStr;
110
111 try {
112 BufferedReader reader = new BufferedReader(new FileReader("/proc/version"), 256);
113 try {
114 procVersionStr = reader.readLine();
115 } finally {
116 reader.close();
117 }
118
119 final String PROC_VERSION_REGEX =
120 "\\w+\\s+" + /* ignore: Linux */
121 "\\w+\\s+" + /* ignore: version */
122 "([^\\s]+)\\s+" + /* group 1: 2.6.22-omap1 */
123 "\\(([^\\s@]+(?:@[^\\s.]+)?)[^)]*\\)\\s+" + /* group 2: (xxxxxx@xxxxx.constant) */
124 "\\([^)]+\\)\\s+" + /* ignore: (gcc ..) */
125 "([^\\s]+)\\s+" + /* group 3: #26 */
126 "(?:PREEMPT\\s+)?" + /* ignore: PREEMPT (optional) */
127 "(.+)"; /* group 4: date */
128
129 Pattern p = Pattern.compile(PROC_VERSION_REGEX);
130 Matcher m = p.matcher(procVersionStr);
131
132 if (!m.matches()) {
133 Log.e(TAG, "Regex did not match on /proc/version: " + procVersionStr);
134 return "Unavailable";
135 } else if (m.groupCount() < 4) {
136 Log.e(TAG, "Regex match on /proc/version only returned " + m.groupCount()
137 + " groups");
138 return "Unavailable";
139 } else {
140 return (new StringBuilder(m.group(1)).append("\n").append(
141 m.group(2)).append(" ").append(m.group(3)).append("\n")
142 .append(m.group(4))).toString();
143 }
144 } catch (IOException e) {
145 Log.e(TAG,
146 "IO Exception when getting kernel version for Device Info screen",
147 e);
148
149 return "Unavailable";
150 }
151 }
152
153}