blob: 36973197c253971fe3d1889c09d9061ff5c8f0d4 [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 */
68 PreferenceGroup parentPreference = (PreferenceGroup) findPreference(KEY_CONTAINER);
69 Utils.updatePreferenceToSpecificActivityOrRemove(this, parentPreference, KEY_TERMS,
70 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
71 Utils.updatePreferenceToSpecificActivityOrRemove(this, parentPreference, KEY_LICENSE,
72 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
73 Utils.updatePreferenceToSpecificActivityOrRemove(this, parentPreference, KEY_CONTRIBUTORS,
74 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
75 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 Projectabc48f82008-12-17 18:06:01 -080079 Utils.updatePreferenceToSpecificActivityOrRemove(this, parentPreference, KEY_SYSTEM_UPDATE_SETTINGS,
80 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070081 }
82
The Android Open Source Project1feaa852009-02-10 15:44:05 -080083 private void setStringSummary(String preference, String value) {
84 try {
85 findPreference(preference).setSummary(value);
86 } catch (RuntimeException e) {
87 findPreference(preference).setSummary(
88 getResources().getString(R.string.device_info_default));
89 }
90 }
91
92 private void setValueSummary(String preference, String property) {
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070093 try {
94 findPreference(preference).setSummary(
95 SystemProperties.get(property,
96 getResources().getString(R.string.device_info_default)));
97 } catch (RuntimeException e) {
The Android Open Source Project1feaa852009-02-10 15:44:05 -080098
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070099 }
100 }
101
102 private String getFormattedKernelVersion() {
103 String procVersionStr;
104
105 try {
106 BufferedReader reader = new BufferedReader(new FileReader("/proc/version"), 256);
107 try {
108 procVersionStr = reader.readLine();
109 } finally {
110 reader.close();
111 }
112
113 final String PROC_VERSION_REGEX =
114 "\\w+\\s+" + /* ignore: Linux */
115 "\\w+\\s+" + /* ignore: version */
116 "([^\\s]+)\\s+" + /* group 1: 2.6.22-omap1 */
117 "\\(([^\\s@]+(?:@[^\\s.]+)?)[^)]*\\)\\s+" + /* group 2: (xxxxxx@xxxxx.constant) */
118 "\\([^)]+\\)\\s+" + /* ignore: (gcc ..) */
119 "([^\\s]+)\\s+" + /* group 3: #26 */
120 "(?:PREEMPT\\s+)?" + /* ignore: PREEMPT (optional) */
121 "(.+)"; /* group 4: date */
122
123 Pattern p = Pattern.compile(PROC_VERSION_REGEX);
124 Matcher m = p.matcher(procVersionStr);
125
126 if (!m.matches()) {
127 Log.e(TAG, "Regex did not match on /proc/version: " + procVersionStr);
128 return "Unavailable";
129 } else if (m.groupCount() < 4) {
130 Log.e(TAG, "Regex match on /proc/version only returned " + m.groupCount()
131 + " groups");
132 return "Unavailable";
133 } else {
134 return (new StringBuilder(m.group(1)).append("\n").append(
135 m.group(2)).append(" ").append(m.group(3)).append("\n")
136 .append(m.group(4))).toString();
137 }
138 } catch (IOException e) {
139 Log.e(TAG,
140 "IO Exception when getting kernel version for Device Info screen",
141 e);
142
143 return "Unavailable";
144 }
145 }
146
147}