The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.settings; |
| 18 | |
| 19 | import android.content.Intent; |
| 20 | import android.content.pm.ApplicationInfo; |
| 21 | import android.content.pm.PackageManager; |
| 22 | import android.content.pm.ResolveInfo; |
The Android Open Source Project | 1feaa85 | 2009-02-10 15:44:05 -0800 | [diff] [blame] | 23 | import android.os.Build; |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 24 | import android.os.Bundle; |
| 25 | import android.os.SystemProperties; |
| 26 | import android.preference.Preference; |
| 27 | import android.preference.PreferenceActivity; |
| 28 | import android.preference.PreferenceGroup; |
| 29 | import android.util.Config; |
| 30 | import android.util.Log; |
| 31 | |
| 32 | import java.io.BufferedReader; |
| 33 | import java.io.FileReader; |
| 34 | import java.io.IOException; |
| 35 | import java.util.List; |
| 36 | import java.util.regex.Matcher; |
| 37 | import java.util.regex.Pattern; |
| 38 | |
| 39 | public 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 Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 50 | private static final String KEY_SYSTEM_UPDATE_SETTINGS = "system_update_settings"; |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 51 | |
| 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 Project | 1feaa85 | 2009-02-10 15:44:05 -0800 | [diff] [blame] | 58 | 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 Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 62 | 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 Project | b9f5851 | 2009-02-13 12:57:53 -0800 | [diff] [blame] | 68 | |
| 69 | // These are contained in the "container" preference group |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 70 | 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 Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 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 Project | b9f5851 | 2009-02-13 12:57:53 -0800 | [diff] [blame] | 79 | |
| 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 Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 86 | Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY); |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 87 | } |
| 88 | |
The Android Open Source Project | 1feaa85 | 2009-02-10 15:44:05 -0800 | [diff] [blame] | 89 | 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 Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 99 | 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 Project | 1feaa85 | 2009-02-10 15:44:05 -0800 | [diff] [blame] | 104 | |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 105 | } |
| 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 | } |