blob: 5d72afcacdf1fb578354a5851ba4573ef6f7cdc6 [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";
The Android Open Source Projectabc48f82008-12-17 18:06:01 -080049 private static final String KEY_SYSTEM_UPDATE_SETTINGS = "system_update_settings";
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070050
51 @Override
52 protected void onCreate(Bundle icicle) {
53 super.onCreate(icicle);
54
55 addPreferencesFromResource(R.xml.device_info_settings);
56
57 setSummary("firmware_version", "ro.build.version.release");
58 setSummary("baseband_version", "gsm.version.baseband");
59 setSummary("device_model", "ro.product.model");
The Android Open Source Projectabc48f82008-12-17 18:06:01 -080060 setSummary("build_number", "ro.build.version.incremental");
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070061 findPreference("kernel_version").setSummary(getFormattedKernelVersion());
62
63 /*
64 * Settings is a generic app and should not contain any device-specific
65 * info.
66 */
67 PreferenceGroup parentPreference = (PreferenceGroup) findPreference(KEY_CONTAINER);
68 Utils.updatePreferenceToSpecificActivityOrRemove(this, parentPreference, KEY_TERMS,
69 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
70 Utils.updatePreferenceToSpecificActivityOrRemove(this, parentPreference, KEY_LICENSE,
71 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
72 Utils.updatePreferenceToSpecificActivityOrRemove(this, parentPreference, KEY_CONTRIBUTORS,
73 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
74 Utils.updatePreferenceToSpecificActivityOrRemove(this, parentPreference, KEY_COPYRIGHT,
75 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
76 Utils.updatePreferenceToSpecificActivityOrRemove(this, parentPreference, KEY_TEAM,
77 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
The Android Open Source Projectabc48f82008-12-17 18:06:01 -080078 Utils.updatePreferenceToSpecificActivityOrRemove(this, parentPreference, KEY_SYSTEM_UPDATE_SETTINGS,
79 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070080 }
81
82 private void setSummary(String preference, String property) {
83 try {
84 findPreference(preference).setSummary(
85 SystemProperties.get(property,
86 getResources().getString(R.string.device_info_default)));
87 } catch (RuntimeException e) {
88
89 }
90 }
91
92 private String getFormattedKernelVersion() {
93 String procVersionStr;
94
95 try {
96 BufferedReader reader = new BufferedReader(new FileReader("/proc/version"), 256);
97 try {
98 procVersionStr = reader.readLine();
99 } finally {
100 reader.close();
101 }
102
103 final String PROC_VERSION_REGEX =
104 "\\w+\\s+" + /* ignore: Linux */
105 "\\w+\\s+" + /* ignore: version */
106 "([^\\s]+)\\s+" + /* group 1: 2.6.22-omap1 */
107 "\\(([^\\s@]+(?:@[^\\s.]+)?)[^)]*\\)\\s+" + /* group 2: (xxxxxx@xxxxx.constant) */
108 "\\([^)]+\\)\\s+" + /* ignore: (gcc ..) */
109 "([^\\s]+)\\s+" + /* group 3: #26 */
110 "(?:PREEMPT\\s+)?" + /* ignore: PREEMPT (optional) */
111 "(.+)"; /* group 4: date */
112
113 Pattern p = Pattern.compile(PROC_VERSION_REGEX);
114 Matcher m = p.matcher(procVersionStr);
115
116 if (!m.matches()) {
117 Log.e(TAG, "Regex did not match on /proc/version: " + procVersionStr);
118 return "Unavailable";
119 } else if (m.groupCount() < 4) {
120 Log.e(TAG, "Regex match on /proc/version only returned " + m.groupCount()
121 + " groups");
122 return "Unavailable";
123 } else {
124 return (new StringBuilder(m.group(1)).append("\n").append(
125 m.group(2)).append(" ").append(m.group(3)).append("\n")
126 .append(m.group(4))).toString();
127 }
128 } catch (IOException e) {
129 Log.e(TAG,
130 "IO Exception when getting kernel version for Device Info screen",
131 e);
132
133 return "Unavailable";
134 }
135 }
136
137}