OSDN Git Service

am b3f6116e: am fd73824d: Merge "Fix: Text is cut in Edit word edit box when adding...
[android-x86/packages-apps-Settings.git] / src / com / android / settings / DeviceInfoSettings.java
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.app.Activity;
20 import android.content.ComponentName;
21 import android.content.Intent;
22 import android.content.pm.PackageManager;
23 import android.content.pm.ResolveInfo;
24 import android.os.Build;
25 import android.os.Bundle;
26 import android.os.SystemClock;
27 import android.os.SystemProperties;
28 import android.preference.Preference;
29 import android.preference.PreferenceGroup;
30 import android.preference.PreferenceScreen;
31 import android.provider.Settings;
32 import android.util.Log;
33
34 import java.io.BufferedReader;
35 import java.io.FileReader;
36 import java.io.IOException;
37 import java.util.List;
38 import java.util.regex.Matcher;
39 import java.util.regex.Pattern;
40
41 public class DeviceInfoSettings extends SettingsPreferenceFragment {
42
43     private static final String TAG = "DeviceInfoSettings";
44
45     private static final String KEY_CONTAINER = "container";
46     private static final String KEY_TEAM = "team";
47     private static final String KEY_CONTRIBUTORS = "contributors";
48     private static final String KEY_TERMS = "terms";
49     private static final String KEY_LICENSE = "license";
50     private static final String KEY_COPYRIGHT = "copyright";
51     private static final String KEY_SYSTEM_UPDATE_SETTINGS = "system_update_settings";
52     private static final String PROPERTY_URL_SAFETYLEGAL = "ro.url.safetylegal";
53     private static final String KEY_KERNEL_VERSION = "kernel_version";
54     private static final String KEY_BUILD_NUMBER = "build_number";
55     private static final String KEY_DEVICE_MODEL = "device_model";
56     private static final String KEY_BASEBAND_VERSION = "baseband_version";
57     private static final String KEY_FIRMWARE_VERSION = "firmware_version";
58     private static final String KEY_EQUIPMENT_ID = "fcc_equipment_id";
59     private static final String PROPERTY_EQUIPMENT_ID = "ro.ril.fccid";
60
61     long[] mHits = new long[3];
62
63     @Override
64     public void onCreate(Bundle icicle) {
65         super.onCreate(icicle);
66
67         addPreferencesFromResource(R.xml.device_info_settings);
68
69         // If we don't have an IME tutorial, remove that option
70         String currentIme = Settings.Secure.getString(getContentResolver(),
71                 Settings.Secure.DEFAULT_INPUT_METHOD);
72         ComponentName component = ComponentName.unflattenFromString(currentIme);
73         Intent imeIntent = new Intent(component.getPackageName() + ".tutorial");
74         PackageManager pm = getPackageManager();
75         List<ResolveInfo> tutorials = pm.queryIntentActivities(imeIntent, 0);
76         if(tutorials == null || tutorials.isEmpty()) {
77             getPreferenceScreen().removePreference(findPreference("system_tutorial"));
78         }
79
80         setStringSummary(KEY_FIRMWARE_VERSION, Build.VERSION.RELEASE);
81         findPreference(KEY_FIRMWARE_VERSION).setEnabled(true);
82         setValueSummary(KEY_BASEBAND_VERSION, "gsm.version.baseband");
83         setValueSummary(KEY_EQUIPMENT_ID, PROPERTY_EQUIPMENT_ID);
84         setStringSummary(KEY_DEVICE_MODEL, Build.MODEL);
85         setStringSummary(KEY_BUILD_NUMBER, Build.DISPLAY);
86         findPreference(KEY_KERNEL_VERSION).setSummary(getFormattedKernelVersion());
87
88         // Remove Safety information preference if PROPERTY_URL_SAFETYLEGAL is not set
89         removePreferenceIfPropertyMissing(getPreferenceScreen(), "safetylegal",
90                 PROPERTY_URL_SAFETYLEGAL);
91
92         // Remove Equipment id preference if FCC ID is not set by RIL
93         removePreferenceIfPropertyMissing(getPreferenceScreen(), KEY_EQUIPMENT_ID,
94                 PROPERTY_EQUIPMENT_ID);
95
96
97         // Remove Baseband version if wifi-only device
98         if (Utils.isWifiOnly()) {
99             getPreferenceScreen().removePreference(findPreference(KEY_BASEBAND_VERSION));
100         }
101
102         /*
103          * Settings is a generic app and should not contain any device-specific
104          * info.
105          */
106         final Activity act = getActivity();
107         // These are contained in the "container" preference group
108         PreferenceGroup parentPreference = (PreferenceGroup) findPreference(KEY_CONTAINER);
109         Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_TERMS,
110                 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
111         Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_LICENSE,
112                 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
113         Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_COPYRIGHT,
114                 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
115         Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_TEAM,
116                 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
117
118         // These are contained by the root preference screen
119         parentPreference = getPreferenceScreen();
120         Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference,
121                 KEY_SYSTEM_UPDATE_SETTINGS,
122                 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
123         Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_CONTRIBUTORS,
124                 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
125     }
126
127     @Override
128     public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
129         if (preference.getKey().equals(KEY_FIRMWARE_VERSION)) {
130             System.arraycopy(mHits, 1, mHits, 0, mHits.length-1);
131             mHits[mHits.length-1] = SystemClock.uptimeMillis();
132             if (mHits[0] >= (SystemClock.uptimeMillis()-500)) {
133                 Intent intent = new Intent(Intent.ACTION_MAIN);
134                 intent.setClassName("android",
135                         com.android.internal.app.PlatLogoActivity.class.getName());
136                 try {
137                     startActivity(intent);
138                 } catch (Exception e) {
139                 }
140             }
141         }
142         return super.onPreferenceTreeClick(preferenceScreen, preference);
143     }
144
145     private void removePreferenceIfPropertyMissing(PreferenceGroup preferenceGroup,
146             String preference, String property ) {
147         if (SystemProperties.get(property).equals(""))
148         {
149             // Property is missing so remove preference from group
150             try {
151                 preferenceGroup.removePreference(findPreference(preference));
152             } catch (RuntimeException e) {
153                 Log.d(TAG, "Property '" + property + "' missing and no '"
154                         + preference + "' preference");
155             }
156         }
157     }
158
159     private void setStringSummary(String preference, String value) {
160         try {
161             findPreference(preference).setSummary(value);
162         } catch (RuntimeException e) {
163             findPreference(preference).setSummary(
164                 getResources().getString(R.string.device_info_default));
165         }
166     }
167
168     private void setValueSummary(String preference, String property) {
169         try {
170             findPreference(preference).setSummary(
171                     SystemProperties.get(property,
172                             getResources().getString(R.string.device_info_default)));
173         } catch (RuntimeException e) {
174
175         }
176     }
177
178     private String getFormattedKernelVersion() {
179         String procVersionStr;
180
181         try {
182             BufferedReader reader = new BufferedReader(new FileReader("/proc/version"), 256);
183             try {
184                 procVersionStr = reader.readLine();
185             } finally {
186                 reader.close();
187             }
188
189             final String PROC_VERSION_REGEX =
190                 "\\w+\\s+" + /* ignore: Linux */
191                 "\\w+\\s+" + /* ignore: version */
192                 "([^\\s]+)\\s+" + /* group 1: 2.6.22-omap1 */
193                 "\\(([^\\s@]+(?:@[^\\s.]+)?)[^)]*\\)\\s+" + /* group 2: (xxxxxx@xxxxx.constant) */
194                 "\\((?:[^(]*\\([^)]*\\))?[^)]*\\)\\s+" + /* ignore: (gcc ..) */
195                 "([^\\s]+)\\s+" + /* group 3: #26 */
196                 "(?:PREEMPT\\s+)?" + /* ignore: PREEMPT (optional) */
197                 "(.+)"; /* group 4: date */
198
199             Pattern p = Pattern.compile(PROC_VERSION_REGEX);
200             Matcher m = p.matcher(procVersionStr);
201
202             if (!m.matches()) {
203                 Log.e(TAG, "Regex did not match on /proc/version: " + procVersionStr);
204                 return "Unavailable";
205             } else if (m.groupCount() < 4) {
206                 Log.e(TAG, "Regex match on /proc/version only returned " + m.groupCount()
207                         + " groups");
208                 return "Unavailable";
209             } else {
210                 return (new StringBuilder(m.group(1)).append("\n").append(
211                         m.group(2)).append(" ").append(m.group(3)).append("\n")
212                         .append(m.group(4))).toString();
213             }
214         } catch (IOException e) {
215             Log.e(TAG,
216                 "IO Exception when getting kernel version for Device Info screen",
217                 e);
218
219             return "Unavailable";
220         }
221     }
222
223 }