blob: 58fc91e98927c19f12d290ae774a28b63d7817ca [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;
23import android.os.Bundle;
24import android.os.SystemProperties;
25import android.preference.Preference;
26import android.preference.PreferenceActivity;
27import android.preference.PreferenceGroup;
28import android.util.Config;
29import android.util.Log;
30
31import java.io.BufferedReader;
32import java.io.FileReader;
33import java.io.IOException;
34import java.util.List;
35import java.util.regex.Matcher;
36import java.util.regex.Pattern;
37
38public class DeviceInfoSettings extends PreferenceActivity {
39
40 private static final String TAG = "DeviceInfoSettings";
41 private static final boolean LOGD = false || Config.LOGD;
42
43 private static final String KEY_CONTAINER = "container";
44 private static final String KEY_TEAM = "team";
45 private static final String KEY_CONTRIBUTORS = "contributors";
46 private static final String KEY_TERMS = "terms";
47 private static final String KEY_LICENSE = "license";
48 private static final String KEY_COPYRIGHT = "copyright";
49
50 @Override
51 protected void onCreate(Bundle icicle) {
52 super.onCreate(icicle);
53
54 addPreferencesFromResource(R.xml.device_info_settings);
55
56 setSummary("firmware_version", "ro.build.version.release");
57 setSummary("baseband_version", "gsm.version.baseband");
58 setSummary("device_model", "ro.product.model");
59 setSummary("build_number", "ro.build.description");
60 findPreference("kernel_version").setSummary(getFormattedKernelVersion());
61
62 /*
63 * Settings is a generic app and should not contain any device-specific
64 * info.
65 */
66 PreferenceGroup parentPreference = (PreferenceGroup) findPreference(KEY_CONTAINER);
67 Utils.updatePreferenceToSpecificActivityOrRemove(this, parentPreference, KEY_TERMS,
68 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
69 Utils.updatePreferenceToSpecificActivityOrRemove(this, parentPreference, KEY_LICENSE,
70 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
71 Utils.updatePreferenceToSpecificActivityOrRemove(this, parentPreference, KEY_CONTRIBUTORS,
72 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
73 Utils.updatePreferenceToSpecificActivityOrRemove(this, parentPreference, KEY_COPYRIGHT,
74 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
75 Utils.updatePreferenceToSpecificActivityOrRemove(this, parentPreference, KEY_TEAM,
76 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
77 }
78
79 private void setSummary(String preference, String property) {
80 try {
81 findPreference(preference).setSummary(
82 SystemProperties.get(property,
83 getResources().getString(R.string.device_info_default)));
84 } catch (RuntimeException e) {
85
86 }
87 }
88
89 private String getFormattedKernelVersion() {
90 String procVersionStr;
91
92 try {
93 BufferedReader reader = new BufferedReader(new FileReader("/proc/version"), 256);
94 try {
95 procVersionStr = reader.readLine();
96 } finally {
97 reader.close();
98 }
99
100 final String PROC_VERSION_REGEX =
101 "\\w+\\s+" + /* ignore: Linux */
102 "\\w+\\s+" + /* ignore: version */
103 "([^\\s]+)\\s+" + /* group 1: 2.6.22-omap1 */
104 "\\(([^\\s@]+(?:@[^\\s.]+)?)[^)]*\\)\\s+" + /* group 2: (xxxxxx@xxxxx.constant) */
105 "\\([^)]+\\)\\s+" + /* ignore: (gcc ..) */
106 "([^\\s]+)\\s+" + /* group 3: #26 */
107 "(?:PREEMPT\\s+)?" + /* ignore: PREEMPT (optional) */
108 "(.+)"; /* group 4: date */
109
110 Pattern p = Pattern.compile(PROC_VERSION_REGEX);
111 Matcher m = p.matcher(procVersionStr);
112
113 if (!m.matches()) {
114 Log.e(TAG, "Regex did not match on /proc/version: " + procVersionStr);
115 return "Unavailable";
116 } else if (m.groupCount() < 4) {
117 Log.e(TAG, "Regex match on /proc/version only returned " + m.groupCount()
118 + " groups");
119 return "Unavailable";
120 } else {
121 return (new StringBuilder(m.group(1)).append("\n").append(
122 m.group(2)).append(" ").append(m.group(3)).append("\n")
123 .append(m.group(4))).toString();
124 }
125 } catch (IOException e) {
126 Log.e(TAG,
127 "IO Exception when getting kernel version for Device Info screen",
128 e);
129
130 return "Unavailable";
131 }
132 }
133
134}