blob: 47ff6afbb5dcbbb4ead0121f0de7981b5a97aa8a [file] [log] [blame]
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001/**
2 * Copyright (C) 2007 Google Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy
6 * 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, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations
14 * under the License.
15 */
16
17package com.android.settings;
18
Alexandra Gherghina7d748c02014-06-27 12:33:42 +010019import static android.content.Intent.EXTRA_USER;
20
21import android.annotation.Nullable;
Amith Yamasaniae697552011-09-27 11:33:17 -070022import android.app.ActivityManager;
Alexandra Gherghina7d748c02014-06-27 12:33:42 +010023import android.app.ActivityManagerNative;
Amith Yamasani9627a8e2012-09-23 12:54:14 -070024import android.app.AlertDialog;
25import android.app.Dialog;
Fabrice Di Meglio769630c2014-04-24 14:48:48 -070026import android.app.Fragment;
Alexandra Gherghina1eb3f312014-06-10 14:01:10 +010027import android.app.IActivityManager;
Amith Yamasani8d40fac2012-10-23 15:36:16 -070028import android.content.ContentResolver;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080029import android.content.Context;
Amith Yamasani9627a8e2012-09-23 12:54:14 -070030import android.content.DialogInterface;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080031import android.content.Intent;
32import android.content.pm.ApplicationInfo;
Dan Sandlerb58b5122014-09-02 18:31:49 +020033import android.content.pm.PackageInfo;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080034import android.content.pm.PackageManager;
Amith Yamasani02cf71a2010-09-21 15:48:52 -070035import android.content.pm.PackageManager.NameNotFoundException;
Jeff Sharkeyb654cbb2011-08-18 11:59:19 -070036import android.content.pm.ResolveInfo;
Dan Sandlerb58b5122014-09-02 18:31:49 +020037import android.content.pm.Signature;
Amith Yamasaniae47ef42012-09-16 17:53:35 -070038import android.content.pm.UserInfo;
Anders Hammar1b2dd9032010-04-08 10:03:50 +020039import android.content.res.Resources;
40import android.content.res.Resources.NotFoundException;
Amith Yamasaniae47ef42012-09-16 17:53:35 -070041import android.database.Cursor;
Amith Yamasanif34a85d2012-09-17 18:31:45 -070042import android.graphics.Bitmap;
43import android.graphics.BitmapFactory;
Anders Hammar1b2dd9032010-04-08 10:03:50 +020044import android.graphics.drawable.Drawable;
Amith Yamasanic06d4c42011-02-25 14:35:20 -080045import android.net.ConnectivityManager;
46import android.net.LinkProperties;
Amith Yamasaniae47ef42012-09-16 17:53:35 -070047import android.net.Uri;
Amith Yamasania4379d62011-07-22 10:34:58 -070048import android.os.BatteryManager;
Anders Hammar1b2dd9032010-04-08 10:03:50 +020049import android.os.Bundle;
Alexandra Gherghina1eb3f312014-06-10 14:01:10 +010050import android.os.IBinder;
51import android.os.RemoteException;
Amith Yamasaniae47ef42012-09-16 17:53:35 -070052import android.os.UserHandle;
53import android.os.UserManager;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080054import android.preference.Preference;
Jeff Sharkeyb654cbb2011-08-18 11:59:19 -070055import android.preference.PreferenceFrameLayout;
56import android.preference.PreferenceGroup;
Amith Yamasani8d40fac2012-10-23 15:36:16 -070057import android.provider.ContactsContract.CommonDataKinds;
Amith Yamasaniae47ef42012-09-16 17:53:35 -070058import android.provider.ContactsContract.Contacts;
Amith Yamasani8d40fac2012-10-23 15:36:16 -070059import android.provider.ContactsContract.Data;
Amith Yamasaniae47ef42012-09-16 17:53:35 -070060import android.provider.ContactsContract.Profile;
Amith Yamasani8d40fac2012-10-23 15:36:16 -070061import android.provider.ContactsContract.RawContacts;
Andres Moralesce249fe2014-07-07 16:58:16 -070062import android.service.persistentdata.PersistentDataBlockManager;
Amith Yamasani60133dd2010-09-11 14:17:31 -070063import android.telephony.TelephonyManager;
Anders Hammar1b2dd9032010-04-08 10:03:50 +020064import android.text.TextUtils;
Alexandra Gherghina1eb3f312014-06-10 14:01:10 +010065import android.util.Log;
Jeff Sharkeyb654cbb2011-08-18 11:59:19 -070066import android.view.View;
67import android.view.ViewGroup;
68import android.widget.ListView;
69import android.widget.TabWidget;
Alexandra Gherghina7d748c02014-06-27 12:33:42 +010070
Alexandra Gherghina80e1f1b2014-07-31 14:56:33 +010071import com.android.settings.UserSpinnerAdapter.UserDetails;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -070072import com.android.settings.dashboard.DashboardCategory;
73import com.android.settings.dashboard.DashboardTile;
Alexandra Gherghinafe47a8d2014-07-18 17:23:37 +010074import com.android.settings.drawable.CircleFramedDrawable;
Daisuke Miyakawaa2633d02010-09-15 20:09:12 -070075
Amith Yamasaniae47ef42012-09-16 17:53:35 -070076import java.io.IOException;
77import java.io.InputStream;
Amith Yamasanic06d4c42011-02-25 14:35:20 -080078import java.net.InetAddress;
Alexandra Gherghina80e1f1b2014-07-31 14:56:33 +010079import java.util.ArrayList;
Amith Yamasanic06d4c42011-02-25 14:35:20 -080080import java.util.Iterator;
Daisuke Miyakawaa2633d02010-09-15 20:09:12 -070081import java.util.List;
Jean Chalard71ad1f42011-05-12 15:06:16 +090082import java.util.Locale;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080083
Fabrice Di Meglioc9711be2014-06-17 12:30:18 -070084public final class Utils {
Alexandra Gherghina1eb3f312014-06-10 14:01:10 +010085 private static final String TAG = "Settings";
Alexandra Gherghina7d748c02014-06-27 12:33:42 +010086
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080087 /**
88 * Set the preference's title to the matching activity's label.
89 */
90 public static final int UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY = 1;
91
92 /**
Shuhrat Dehkanov96577682012-10-03 12:24:07 +090093 * The opacity level of a disabled icon.
94 */
95 public static final float DISABLED_ALPHA = 0.4f;
96
97 /**
Dianne Hackborn68f005f2014-06-18 18:29:12 -070098 * Color spectrum to use to indicate badness. 0 is completely transparent (no data),
99 * 1 is most bad (red), the last value is least bad (green).
100 */
101 public static final int[] BADNESS_COLORS = new int[] {
102 0x00000000, 0xffc43828, 0xffe54918, 0xfff47b00,
103 0xfffabf2c, 0xff679e37, 0xff0a7f42
104 };
105
106 /**
Anders Hammar1b2dd9032010-04-08 10:03:50 +0200107 * Name of the meta-data item that should be set in the AndroidManifest.xml
108 * to specify the icon that should be displayed for the preference.
109 */
110 private static final String META_DATA_PREFERENCE_ICON = "com.android.settings.icon";
111
112 /**
113 * Name of the meta-data item that should be set in the AndroidManifest.xml
114 * to specify the title that should be displayed for the preference.
115 */
116 private static final String META_DATA_PREFERENCE_TITLE = "com.android.settings.title";
117
118 /**
119 * Name of the meta-data item that should be set in the AndroidManifest.xml
120 * to specify the summary text that should be displayed for the preference.
121 */
122 private static final String META_DATA_PREFERENCE_SUMMARY = "com.android.settings.summary";
123
Alexandra Gherghina7d748c02014-06-27 12:33:42 +0100124 private static final String SETTINGS_PACKAGE_NAME = "com.android.settings";
125
Anders Hammar1b2dd9032010-04-08 10:03:50 +0200126 /**
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800127 * Finds a matching activity for a preference's intent. If a matching
128 * activity is not found, it will remove the preference.
Ying Wanga7188322010-01-04 18:45:10 -0800129 *
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800130 * @param context The context.
131 * @param parentPreferenceGroup The preference group that contains the
132 * preference whose intent is being resolved.
133 * @param preferenceKey The key of the preference whose intent is being
134 * resolved.
135 * @param flags 0 or one or more of
136 * {@link #UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY}
137 * .
138 * @return Whether an activity was found. If false, the preference was
139 * removed.
140 */
141 public static boolean updatePreferenceToSpecificActivityOrRemove(Context context,
142 PreferenceGroup parentPreferenceGroup, String preferenceKey, int flags) {
Ying Wanga7188322010-01-04 18:45:10 -0800143
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800144 Preference preference = parentPreferenceGroup.findPreference(preferenceKey);
145 if (preference == null) {
146 return false;
147 }
Ying Wanga7188322010-01-04 18:45:10 -0800148
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800149 Intent intent = preference.getIntent();
150 if (intent != null) {
151 // Find the activity that is in the system image
152 PackageManager pm = context.getPackageManager();
153 List<ResolveInfo> list = pm.queryIntentActivities(intent, 0);
154 int listSize = list.size();
155 for (int i = 0; i < listSize; i++) {
156 ResolveInfo resolveInfo = list.get(i);
157 if ((resolveInfo.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM)
158 != 0) {
Ying Wanga7188322010-01-04 18:45:10 -0800159
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800160 // Replace the intent with this specific activity
161 preference.setIntent(new Intent().setClassName(
162 resolveInfo.activityInfo.packageName,
163 resolveInfo.activityInfo.name));
164
165 if ((flags & UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY) != 0) {
166 // Set the preference title to the activity's label
167 preference.setTitle(resolveInfo.loadLabel(pm));
168 }
Ying Wanga7188322010-01-04 18:45:10 -0800169
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800170 return true;
171 }
172 }
173 }
174
175 // Did not find a matching activity, so remove the preference
176 parentPreferenceGroup.removePreference(preference);
Ying Wanga7188322010-01-04 18:45:10 -0800177
Shuhrat Dehkanov7dc567a2012-04-23 01:59:56 +0900178 return false;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800179 }
Ying Wanga7188322010-01-04 18:45:10 -0800180
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700181 public static boolean updateTileToSpecificActivityFromMetaDataOrRemove(Context context,
Amith Yamasani57fd5fd2014-08-06 15:48:10 -0700182 DashboardTile tile) {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700183
184 Intent intent = tile.intent;
185 if (intent != null) {
186 // Find the activity that is in the system image
187 PackageManager pm = context.getPackageManager();
188 List<ResolveInfo> list = pm.queryIntentActivities(intent, PackageManager.GET_META_DATA);
189 int listSize = list.size();
190 for (int i = 0; i < listSize; i++) {
191 ResolveInfo resolveInfo = list.get(i);
192 if ((resolveInfo.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM)
193 != 0) {
194 Drawable icon = null;
195 String title = null;
196 String summary = null;
197
198 // Get the activity's meta-data
199 try {
200 Resources res = pm.getResourcesForApplication(
201 resolveInfo.activityInfo.packageName);
202 Bundle metaData = resolveInfo.activityInfo.metaData;
203
204 if (res != null && metaData != null) {
205 icon = res.getDrawable(metaData.getInt(META_DATA_PREFERENCE_ICON));
206 title = res.getString(metaData.getInt(META_DATA_PREFERENCE_TITLE));
207 summary = res.getString(metaData.getInt(META_DATA_PREFERENCE_SUMMARY));
208 }
209 } catch (NameNotFoundException e) {
210 // Ignore
211 } catch (NotFoundException e) {
212 // Ignore
213 }
214
215 // Set the preference title to the activity's label if no
216 // meta-data is found
217 if (TextUtils.isEmpty(title)) {
218 title = resolveInfo.loadLabel(pm).toString();
219 }
220
221 // Set icon, title and summary for the preference
222 // TODO:
223 //tile.icon = icon;
224 tile.title = title;
225 tile.summary = summary;
226 // Replace the intent with this specific activity
227 tile.intent = new Intent().setClassName(resolveInfo.activityInfo.packageName,
228 resolveInfo.activityInfo.name);
229
230 return true;
231 }
232 }
233 }
234
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700235 return false;
236 }
237
Anders Hammar1b2dd9032010-04-08 10:03:50 +0200238 /**
Ying Wanga7188322010-01-04 18:45:10 -0800239 * Returns true if Monkey is running.
240 */
241 public static boolean isMonkeyRunning() {
Amith Yamasaniae697552011-09-27 11:33:17 -0700242 return ActivityManager.isUserAMonkey();
Ying Wanga7188322010-01-04 18:45:10 -0800243 }
Amith Yamasani60133dd2010-09-11 14:17:31 -0700244
245 /**
246 * Returns whether the device is voice-capable (meaning, it is also a phone).
247 */
248 public static boolean isVoiceCapable(Context context) {
249 TelephonyManager telephony =
250 (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
251 return telephony != null && telephony.isVoiceCapable();
252 }
Amith Yamasani0f85c482011-02-23 17:19:11 -0800253
Robert Greenwalt8af88fb2011-08-31 11:17:47 -0700254 public static boolean isWifiOnly(Context context) {
255 ConnectivityManager cm = (ConnectivityManager)context.getSystemService(
256 Context.CONNECTIVITY_SERVICE);
257 return (cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE) == false);
Amith Yamasani0f85c482011-02-23 17:19:11 -0800258 }
Amith Yamasanic06d4c42011-02-25 14:35:20 -0800259
260 /**
261 * Returns the WIFI IP Addresses, if any, taking into account IPv4 and IPv6 style addresses.
262 * @param context the application context
Lorenzo Colitti769f0692013-08-01 17:30:07 +0900263 * @return the formatted and newline-separated IP addresses, or null if none.
Amith Yamasanic06d4c42011-02-25 14:35:20 -0800264 */
265 public static String getWifiIpAddresses(Context context) {
266 ConnectivityManager cm = (ConnectivityManager)
267 context.getSystemService(Context.CONNECTIVITY_SERVICE);
268 LinkProperties prop = cm.getLinkProperties(ConnectivityManager.TYPE_WIFI);
Amith Yamasani6822b742011-10-17 16:41:00 -0700269 return formatIpAddresses(prop);
270 }
271
272 /**
273 * Returns the default link's IP addresses, if any, taking into account IPv4 and IPv6 style
274 * addresses.
275 * @param context the application context
Lorenzo Colitti769f0692013-08-01 17:30:07 +0900276 * @return the formatted and newline-separated IP addresses, or null if none.
Amith Yamasani6822b742011-10-17 16:41:00 -0700277 */
Lorenzo Colitti6eb6a902013-11-08 03:53:29 +0900278 public static String getDefaultIpAddresses(ConnectivityManager cm) {
Amith Yamasani6822b742011-10-17 16:41:00 -0700279 LinkProperties prop = cm.getActiveLinkProperties();
280 return formatIpAddresses(prop);
281 }
282
283 private static String formatIpAddresses(LinkProperties prop) {
Amith Yamasanic06d4c42011-02-25 14:35:20 -0800284 if (prop == null) return null;
Lorenzo Colitti769f0692013-08-01 17:30:07 +0900285 Iterator<InetAddress> iter = prop.getAllAddresses().iterator();
Amith Yamasanic06d4c42011-02-25 14:35:20 -0800286 // If there are no entries, return null
287 if (!iter.hasNext()) return null;
288 // Concatenate all available addresses, comma separated
289 String addresses = "";
290 while (iter.hasNext()) {
291 addresses += iter.next().getHostAddress();
Lorenzo Colitti769f0692013-08-01 17:30:07 +0900292 if (iter.hasNext()) addresses += "\n";
Amith Yamasanic06d4c42011-02-25 14:35:20 -0800293 }
294 return addresses;
295 }
Jean Chalard71ad1f42011-05-12 15:06:16 +0900296
297 public static Locale createLocaleFromString(String localeStr) {
298 // TODO: is there a better way to actually construct a locale that will match?
299 // The main problem is, on top of Java specs, locale.toString() and
300 // new Locale(locale.toString()).toString() do not return equal() strings in
301 // many cases, because the constructor takes the only string as the language
302 // code. So : new Locale("en", "US").toString() => "en_US"
303 // And : new Locale("en_US").toString() => "en_us"
304 if (null == localeStr)
305 return Locale.getDefault();
306 String[] brokenDownLocale = localeStr.split("_", 3);
307 // split may not return a 0-length array.
308 if (1 == brokenDownLocale.length) {
309 return new Locale(brokenDownLocale[0]);
310 } else if (2 == brokenDownLocale.length) {
311 return new Locale(brokenDownLocale[0], brokenDownLocale[1]);
312 } else {
313 return new Locale(brokenDownLocale[0], brokenDownLocale[1], brokenDownLocale[2]);
314 }
315 }
Amith Yamasania4379d62011-07-22 10:34:58 -0700316
Jaewan Kima3fe77b2013-06-04 21:17:40 +0900317 public static boolean isBatteryPresent(Intent batteryChangedIntent) {
318 return batteryChangedIntent.getBooleanExtra(BatteryManager.EXTRA_PRESENT, true);
319 }
320
Amith Yamasania4379d62011-07-22 10:34:58 -0700321 public static String getBatteryPercentage(Intent batteryChangedIntent) {
Dianne Hackborn525f2bd2014-04-29 11:24:06 -0700322 return String.valueOf(getBatteryLevel(batteryChangedIntent)) + "%";
323 }
324
325 public static int getBatteryLevel(Intent batteryChangedIntent) {
Jaewan Kima3fe77b2013-06-04 21:17:40 +0900326 int level = batteryChangedIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
327 int scale = batteryChangedIntent.getIntExtra(BatteryManager.EXTRA_SCALE, 100);
Dianne Hackborn525f2bd2014-04-29 11:24:06 -0700328 return (level * 100) / scale;
Amith Yamasania4379d62011-07-22 10:34:58 -0700329 }
330
331 public static String getBatteryStatus(Resources res, Intent batteryChangedIntent) {
332 final Intent intent = batteryChangedIntent;
333
Jaewan Kima3fe77b2013-06-04 21:17:40 +0900334 int plugType = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0);
335 int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS,
336 BatteryManager.BATTERY_STATUS_UNKNOWN);
Amith Yamasania4379d62011-07-22 10:34:58 -0700337 String statusString;
338 if (status == BatteryManager.BATTERY_STATUS_CHARGING) {
Dianne Hackborn5a9ace32014-05-15 17:04:42 -0700339 int resId;
340 if (plugType == BatteryManager.BATTERY_PLUGGED_AC) {
341 resId = R.string.battery_info_status_charging_ac;
342 } else if (plugType == BatteryManager.BATTERY_PLUGGED_USB) {
343 resId = R.string.battery_info_status_charging_usb;
344 } else if (plugType == BatteryManager.BATTERY_PLUGGED_WIRELESS) {
345 resId = R.string.battery_info_status_charging_wireless;
346 } else {
347 resId = R.string.battery_info_status_charging;
Amith Yamasania4379d62011-07-22 10:34:58 -0700348 }
Dianne Hackborn5a9ace32014-05-15 17:04:42 -0700349 statusString = res.getString(resId);
Amith Yamasania4379d62011-07-22 10:34:58 -0700350 } else if (status == BatteryManager.BATTERY_STATUS_DISCHARGING) {
351 statusString = res.getString(R.string.battery_info_status_discharging);
352 } else if (status == BatteryManager.BATTERY_STATUS_NOT_CHARGING) {
353 statusString = res.getString(R.string.battery_info_status_not_charging);
354 } else if (status == BatteryManager.BATTERY_STATUS_FULL) {
355 statusString = res.getString(R.string.battery_info_status_full);
356 } else {
357 statusString = res.getString(R.string.battery_info_status_unknown);
358 }
359
360 return statusString;
361 }
Jeff Sharkeyb654cbb2011-08-18 11:59:19 -0700362
Jeff Sharkey97d07fa2012-11-30 12:36:53 -0800363 public static void forcePrepareCustomPreferencesList(
364 ViewGroup parent, View child, ListView list, boolean ignoreSidePadding) {
365 list.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
366 list.setClipToPadding(false);
367 prepareCustomPreferencesList(parent, child, list, ignoreSidePadding);
368 }
369
Jeff Sharkeyb654cbb2011-08-18 11:59:19 -0700370 /**
371 * Prepare a custom preferences layout, moving padding to {@link ListView}
372 * when outside scrollbars are requested. Usually used to display
373 * {@link ListView} and {@link TabWidget} with correct padding.
374 */
Jeff Sharkey5d706792011-09-08 18:57:17 -0700375 public static void prepareCustomPreferencesList(
Jeff Sharkey97d07fa2012-11-30 12:36:53 -0800376 ViewGroup parent, View child, View list, boolean ignoreSidePadding) {
Jeff Sharkeyb654cbb2011-08-18 11:59:19 -0700377 final boolean movePadding = list.getScrollBarStyle() == View.SCROLLBARS_OUTSIDE_OVERLAY;
Fabrice Di Meglio97a18c82014-07-18 19:12:36 -0700378 if (movePadding) {
Jeff Sharkeyb654cbb2011-08-18 11:59:19 -0700379 final Resources res = list.getResources();
Amith Yamasani56f51a82013-08-05 10:07:23 -0700380 final int paddingSide = res.getDimensionPixelSize(R.dimen.settings_side_margin);
Jeff Sharkeyb654cbb2011-08-18 11:59:19 -0700381 final int paddingBottom = res.getDimensionPixelSize(
382 com.android.internal.R.dimen.preference_fragment_padding_bottom);
Jeff Sharkey5d706792011-09-08 18:57:17 -0700383
Fabrice Di Meglio97a18c82014-07-18 19:12:36 -0700384 if (parent instanceof PreferenceFrameLayout) {
385 ((PreferenceFrameLayout.LayoutParams) child.getLayoutParams()).removeBorders = true;
386
387 final int effectivePaddingSide = ignoreSidePadding ? 0 : paddingSide;
388 list.setPaddingRelative(effectivePaddingSide, 0, effectivePaddingSide, paddingBottom);
389 } else {
390 list.setPaddingRelative(paddingSide, 0, paddingSide, paddingBottom);
391 }
Jeff Sharkeyb654cbb2011-08-18 11:59:19 -0700392 }
393 }
Jeff Sharkeya83a24f2011-09-16 01:52:39 -0700394
Fabrice Di Meglio0f4a7792014-07-28 18:25:14 -0700395 public static void forceCustomPadding(View view, boolean additive) {
Fabrice Di Meglio38ba9a22014-07-18 19:58:50 -0700396 final Resources res = view.getResources();
397 final int paddingSide = res.getDimensionPixelSize(R.dimen.settings_side_margin);
Fabrice Di Meglio0f4a7792014-07-28 18:25:14 -0700398
399 final int paddingStart = paddingSide + (additive ? view.getPaddingStart() : 0);
400 final int paddingEnd = paddingSide + (additive ? view.getPaddingEnd() : 0);
Fabrice Di Meglio38ba9a22014-07-18 19:58:50 -0700401 final int paddingBottom = res.getDimensionPixelSize(
402 com.android.internal.R.dimen.preference_fragment_padding_bottom);
403
Fabrice Di Meglio0f4a7792014-07-28 18:25:14 -0700404 view.setPaddingRelative(paddingStart, 0, paddingEnd, paddingBottom);
Fabrice Di Meglio38ba9a22014-07-18 19:58:50 -0700405 }
406
Jeff Sharkeya83a24f2011-09-16 01:52:39 -0700407 /**
408 * Return string resource that best describes combination of tethering
409 * options available on this device.
410 */
411 public static int getTetheringLabel(ConnectivityManager cm) {
412 String[] usbRegexs = cm.getTetherableUsbRegexs();
413 String[] wifiRegexs = cm.getTetherableWifiRegexs();
414 String[] bluetoothRegexs = cm.getTetherableBluetoothRegexs();
415
416 boolean usbAvailable = usbRegexs.length != 0;
417 boolean wifiAvailable = wifiRegexs.length != 0;
418 boolean bluetoothAvailable = bluetoothRegexs.length != 0;
419
420 if (wifiAvailable && usbAvailable && bluetoothAvailable) {
421 return R.string.tether_settings_title_all;
422 } else if (wifiAvailable && usbAvailable) {
423 return R.string.tether_settings_title_all;
424 } else if (wifiAvailable && bluetoothAvailable) {
425 return R.string.tether_settings_title_all;
426 } else if (wifiAvailable) {
427 return R.string.tether_settings_title_wifi;
428 } else if (usbAvailable && bluetoothAvailable) {
429 return R.string.tether_settings_title_usb_bluetooth;
430 } else if (usbAvailable) {
431 return R.string.tether_settings_title_usb;
432 } else {
433 return R.string.tether_settings_title_bluetooth;
434 }
435 }
Amith Yamasaniae47ef42012-09-16 17:53:35 -0700436
437 /* Used by UserSettings as well. Call this on a non-ui thread. */
438 public static boolean copyMeProfilePhoto(Context context, UserInfo user) {
439 Uri contactUri = Profile.CONTENT_URI;
440
441 InputStream avatarDataStream = Contacts.openContactPhotoInputStream(
442 context.getContentResolver(),
443 contactUri, true);
444 // If there's no profile photo, assign a default avatar
445 if (avatarDataStream == null) {
446 return false;
447 }
448 int userId = user != null ? user.id : UserHandle.myUserId();
449 UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
Amith Yamasanif34a85d2012-09-17 18:31:45 -0700450 Bitmap icon = BitmapFactory.decodeStream(avatarDataStream);
451 um.setUserIcon(userId, icon);
Amith Yamasaniae47ef42012-09-16 17:53:35 -0700452 try {
Amith Yamasanif34a85d2012-09-17 18:31:45 -0700453 avatarDataStream.close();
454 } catch (IOException ioe) { }
455 return true;
Amith Yamasaniae47ef42012-09-16 17:53:35 -0700456 }
457
Amith Yamasani8d40fac2012-10-23 15:36:16 -0700458 public static String getMeProfileName(Context context, boolean full) {
459 if (full) {
460 return getProfileDisplayName(context);
461 } else {
462 return getShorterNameIfPossible(context);
Amith Yamasaniae47ef42012-09-16 17:53:35 -0700463 }
Amith Yamasani8d40fac2012-10-23 15:36:16 -0700464 }
465
466 private static String getShorterNameIfPossible(Context context) {
467 final String given = getLocalProfileGivenName(context);
468 return !TextUtils.isEmpty(given) ? given : getProfileDisplayName(context);
469 }
470
471 private static String getLocalProfileGivenName(Context context) {
472 final ContentResolver cr = context.getContentResolver();
473
474 // Find the raw contact ID for the local ME profile raw contact.
475 final long localRowProfileId;
476 final Cursor localRawProfile = cr.query(
477 Profile.CONTENT_RAW_CONTACTS_URI,
478 new String[] {RawContacts._ID},
479 RawContacts.ACCOUNT_TYPE + " IS NULL AND " +
480 RawContacts.ACCOUNT_NAME + " IS NULL",
481 null, null);
482 if (localRawProfile == null) return null;
Amith Yamasaniae47ef42012-09-16 17:53:35 -0700483
484 try {
Amith Yamasani8d40fac2012-10-23 15:36:16 -0700485 if (!localRawProfile.moveToFirst()) {
486 return null;
Amith Yamasaniae47ef42012-09-16 17:53:35 -0700487 }
Amith Yamasani8d40fac2012-10-23 15:36:16 -0700488 localRowProfileId = localRawProfile.getLong(0);
Amith Yamasaniae47ef42012-09-16 17:53:35 -0700489 } finally {
Amith Yamasani8d40fac2012-10-23 15:36:16 -0700490 localRawProfile.close();
Amith Yamasaniae47ef42012-09-16 17:53:35 -0700491 }
Amith Yamasani8d40fac2012-10-23 15:36:16 -0700492
493 // Find the structured name for the raw contact.
494 final Cursor structuredName = cr.query(
495 Profile.CONTENT_URI.buildUpon().appendPath(Contacts.Data.CONTENT_DIRECTORY).build(),
496 new String[] {CommonDataKinds.StructuredName.GIVEN_NAME,
497 CommonDataKinds.StructuredName.FAMILY_NAME},
498 Data.RAW_CONTACT_ID + "=" + localRowProfileId,
499 null, null);
500 if (structuredName == null) return null;
501
502 try {
503 if (!structuredName.moveToFirst()) {
504 return null;
505 }
506 String partialName = structuredName.getString(0);
507 if (TextUtils.isEmpty(partialName)) {
508 partialName = structuredName.getString(1);
509 }
510 return partialName;
511 } finally {
512 structuredName.close();
513 }
514 }
515
516 private static final String getProfileDisplayName(Context context) {
517 final ContentResolver cr = context.getContentResolver();
518 final Cursor profile = cr.query(Profile.CONTENT_URI,
519 new String[] {Profile.DISPLAY_NAME}, null, null, null);
520 if (profile == null) return null;
521
522 try {
523 if (!profile.moveToFirst()) {
524 return null;
525 }
526 return profile.getString(0);
527 } finally {
528 profile.close();
529 }
Amith Yamasaniae47ef42012-09-16 17:53:35 -0700530 }
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700531
532 /** Not global warming, it's global change warning. */
533 public static Dialog buildGlobalChangeWarningDialog(final Context context, int titleResId,
534 final Runnable positiveAction) {
535 final AlertDialog.Builder builder = new AlertDialog.Builder(context);
536 builder.setTitle(titleResId);
537 builder.setMessage(R.string.global_change_warning);
538 builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
539 @Override
540 public void onClick(DialogInterface dialog, int which) {
541 positiveAction.run();
542 }
543 });
544 builder.setNegativeButton(android.R.string.cancel, null);
545
546 return builder.create();
547 }
548
549 public static boolean hasMultipleUsers(Context context) {
550 return ((UserManager) context.getSystemService(Context.USER_SERVICE))
551 .getUsers().size() > 1;
552 }
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700553
554 /**
555 * Start a new instance of the activity, showing only the given fragment.
556 * When launched in this mode, the given preference fragment will be instantiated and fill the
557 * entire activity.
558 *
559 * @param context The context.
Fabrice Di Meglio93b77b72014-05-17 00:01:07 +0000560 * @param fragmentName The name of the fragment to display.
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700561 * @param args Optional arguments to supply to the fragment.
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700562 * @param resultTo Option fragment that should receive the result of the activity launch.
563 * @param resultRequestCode If resultTo is non-null, this is the request code in which
564 * to report the result.
565 * @param titleResId resource id for the String to display for the title of this set
566 * of preferences.
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700567 * @param title String to display for the title of this set of preferences.
568 */
Fabrice Di Meglio93b77b72014-05-17 00:01:07 +0000569 public static void startWithFragment(Context context, String fragmentName, Bundle args,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700570 Fragment resultTo, int resultRequestCode, int titleResId, CharSequence title) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700571 startWithFragment(context, fragmentName, args, resultTo, resultRequestCode,
572 titleResId, title, false /* not a shortcut */);
573 }
574
575 public static void startWithFragment(Context context, String fragmentName, Bundle args,
576 Fragment resultTo, int resultRequestCode, int titleResId, CharSequence title,
577 boolean isShortcut) {
578 Intent intent = onBuildStartFragmentIntent(context, fragmentName, args, titleResId,
579 title, isShortcut);
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700580 if (resultTo == null) {
581 context.startActivity(intent);
582 } else {
583 resultTo.startActivityForResult(intent, resultRequestCode);
584 }
585 }
586
587 /**
588 * Build an Intent to launch a new activity showing the selected fragment.
589 * The implementation constructs an Intent that re-launches the current activity with the
590 * appropriate arguments to display the fragment.
591 *
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700592 *
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700593 * @param context The Context.
Fabrice Di Meglio93b77b72014-05-17 00:01:07 +0000594 * @param fragmentName The name of the fragment to display.
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700595 * @param args Optional arguments to supply to the fragment.
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700596 * @param titleResId Optional title resource id to show for this item.
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700597 * @param title Optional title to show for this item.
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700598 * @param isShortcut tell if this is a Launcher Shortcut or not
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700599 * @return Returns an Intent that can be launched to display the given
600 * fragment.
601 */
Fabrice Di Meglio93b77b72014-05-17 00:01:07 +0000602 public static Intent onBuildStartFragmentIntent(Context context, String fragmentName,
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700603 Bundle args, int titleResId, CharSequence title, boolean isShortcut) {
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700604 Intent intent = new Intent(Intent.ACTION_MAIN);
605 intent.setClass(context, SubSettings.class);
Fabrice Di Meglio93b77b72014-05-17 00:01:07 +0000606 intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT, fragmentName);
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700607 intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700608 intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RESID, titleResId);
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700609 intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE, title);
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700610 intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, isShortcut);
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700611 return intent;
612 }
Alexandra Gherghina3939cd72014-06-04 10:02:55 +0100613
614 /**
615 * Returns the managed profile of the current user or null if none found.
616 */
617 public static UserHandle getManagedProfile(UserManager userManager) {
618 List<UserHandle> userProfiles = userManager.getUserProfiles();
619 final int count = userProfiles.size();
620 for (int i = 0; i < count; i++) {
621 final UserHandle profile = userProfiles.get(i);
622 if (profile.getIdentifier() == userManager.getUserHandle()) {
623 continue;
624 }
625 final UserInfo userInfo = userManager.getUserInfo(profile.getIdentifier());
626 if (userInfo.isManagedProfile()) {
627 return profile;
628 }
629 }
630 return null;
631 }
632
633 /**
634 * Returns true if the current profile is a managed one.
635 */
636 public static boolean isManagedProfile(UserManager userManager) {
637 UserInfo currentUser = userManager.getUserInfo(userManager.getUserHandle());
638 return currentUser.isManagedProfile();
639 }
Alexandra Gherghina1eb3f312014-06-10 14:01:10 +0100640
641 /**
Alexandra Gherghina80e1f1b2014-07-31 14:56:33 +0100642 * Creates a {@link UserSpinnerAdapter} if there is more than one profile on the device.
643 *
644 * <p> The adapter can be used to populate a spinner that switches between the Settings
645 * app on the different profiles.
646 *
647 * @return a {@link UserSpinnerAdapter} or null if there is only one profile.
648 */
649 public static UserSpinnerAdapter createUserSpinnerAdapter(UserManager userManager,
650 Context context) {
651 List<UserHandle> userProfiles = userManager.getUserProfiles();
652 if (userProfiles.size() < 2) {
653 return null;
654 }
655
656 UserHandle myUserHandle = new UserHandle(UserHandle.myUserId());
657 // The first option should be the current profile
658 userProfiles.remove(myUserHandle);
659 userProfiles.add(0, myUserHandle);
660
661 ArrayList<UserDetails> userDetails = new ArrayList<UserDetails>(userProfiles.size());
662 final int count = userProfiles.size();
663 for (int i = 0; i < count; i++) {
664 userDetails.add(new UserDetails(userProfiles.get(i), userManager, context));
665 }
666 return new UserSpinnerAdapter(context, userDetails);
667 }
668
669 /**
Alexandra Gherghina7d748c02014-06-27 12:33:42 +0100670 * Returns the target user for a Settings activity.
Alexandra Gherghina1eb3f312014-06-10 14:01:10 +0100671 *
Alexandra Gherghina7d748c02014-06-27 12:33:42 +0100672 * The target user can be either the current user, the user that launched this activity or
673 * the user contained as an extra in the arguments or intent extras.
674 *
675 * Note: This is secure in the sense that it only returns a target user different to the current
676 * one if the app launching this activity is the Settings app itself, running in the same user
677 * or in one that is in the same profile group, or if the user id is provided by the system.
Alexandra Gherghina1eb3f312014-06-10 14:01:10 +0100678 */
Alexandra Gherghina7d748c02014-06-27 12:33:42 +0100679 public static UserHandle getSecureTargetUser(IBinder activityToken,
680 UserManager um, @Nullable Bundle arguments, @Nullable Bundle intentExtras) {
681 UserHandle currentUser = new UserHandle(UserHandle.myUserId());
682 IActivityManager am = ActivityManagerNative.getDefault();
683 try {
684 String launchedFromPackage = am.getLaunchedFromPackage(activityToken);
685 boolean launchedFromSettingsApp = SETTINGS_PACKAGE_NAME.equals(launchedFromPackage);
686
687 UserHandle launchedFromUser = new UserHandle(UserHandle.getUserId(
688 am.getLaunchedFromUid(activityToken)));
689 if (launchedFromUser != null && !launchedFromUser.equals(currentUser)) {
690 // Check it's secure
691 if (isProfileOf(um, launchedFromUser)) {
692 return launchedFromUser;
693 }
694 }
695 UserHandle extrasUser = intentExtras != null
696 ? (UserHandle) intentExtras.getParcelable(EXTRA_USER) : null;
697 if (extrasUser != null && !extrasUser.equals(currentUser)) {
698 // Check it's secure
699 if (launchedFromSettingsApp && isProfileOf(um, extrasUser)) {
700 return extrasUser;
701 }
702 }
703 UserHandle argumentsUser = arguments != null
704 ? (UserHandle) arguments.getParcelable(EXTRA_USER) : null;
705 if (argumentsUser != null && !argumentsUser.equals(currentUser)) {
706 // Check it's secure
707 if (launchedFromSettingsApp && isProfileOf(um, argumentsUser)) {
708 return argumentsUser;
709 }
710 }
711 } catch (RemoteException e) {
712 // Should not happen
713 Log.v(TAG, "Could not talk to activity manager.", e);
714 }
715 return currentUser;
716 }
717
718 /**
719 * Returns the target user for a Settings activity.
720 *
721 * The target user can be either the current user, the user that launched this activity or
722 * the user contained as an extra in the arguments or intent extras.
723 *
724 * You should use {@link #getSecureTargetUser(IBinder, UserManager, Bundle, Bundle)} if
725 * possible.
726 *
727 * @see #getInsecureTargetUser(IBinder, Bundle, Bundle)
728 */
729 public static UserHandle getInsecureTargetUser(IBinder activityToken, @Nullable Bundle arguments,
730 @Nullable Bundle intentExtras) {
731 UserHandle currentUser = new UserHandle(UserHandle.myUserId());
732 IActivityManager am = ActivityManagerNative.getDefault();
Alexandra Gherghina1eb3f312014-06-10 14:01:10 +0100733 try {
Alexandra Gherghina7d748c02014-06-27 12:33:42 +0100734 UserHandle launchedFromUser = new UserHandle(UserHandle.getUserId(
735 am.getLaunchedFromUid(activityToken)));
736 if (launchedFromUser != null && !launchedFromUser.equals(currentUser)) {
737 return launchedFromUser;
738 }
739 UserHandle extrasUser = intentExtras != null
740 ? (UserHandle) intentExtras.getParcelable(EXTRA_USER) : null;
741 if (extrasUser != null && !extrasUser.equals(currentUser)) {
742 return extrasUser;
743 }
744 UserHandle argumentsUser = arguments != null
745 ? (UserHandle) arguments.getParcelable(EXTRA_USER) : null;
746 if (argumentsUser != null && !argumentsUser.equals(currentUser)) {
747 return argumentsUser;
Alexandra Gherghina1eb3f312014-06-10 14:01:10 +0100748 }
749 } catch (RemoteException e) {
750 // Should not happen
Alexandra Gherghina7d748c02014-06-27 12:33:42 +0100751 Log.v(TAG, "Could not talk to activity manager.", e);
752 return null;
Alexandra Gherghina1eb3f312014-06-10 14:01:10 +0100753 }
Alexandra Gherghina7d748c02014-06-27 12:33:42 +0100754 return currentUser;
755 }
Alexandra Gherghina1eb3f312014-06-10 14:01:10 +0100756
Alexandra Gherghina7d748c02014-06-27 12:33:42 +0100757 /**
758 * Returns true if the user provided is in the same profiles group as the current user.
759 */
760 private static boolean isProfileOf(UserManager um, UserHandle otherUser) {
761 if (um == null || otherUser == null) return false;
762 return (UserHandle.myUserId() == otherUser.getIdentifier())
763 || um.getUserProfiles().contains(otherUser);
Alexandra Gherghina1eb3f312014-06-10 14:01:10 +0100764 }
Amith Yamasani51c6dac2014-07-02 00:06:37 +0530765
766 /**
767 * Creates a dialog to confirm with the user if it's ok to remove the user
768 * and delete all the data.
769 *
770 * @param context a Context object
771 * @param removingUserId The userId of the user to remove
772 * @param onConfirmListener Callback object for positive action
773 * @return the created Dialog
774 */
775 public static Dialog createRemoveConfirmationDialog(Context context, int removingUserId,
776 DialogInterface.OnClickListener onConfirmListener) {
777 UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
778 UserInfo userInfo = um.getUserInfo(removingUserId);
Alexandra Gherghina4c962672014-08-22 11:17:29 +0100779 int titleResId;
780 int messageResId;
781 if (UserHandle.myUserId() == removingUserId) {
782 titleResId = R.string.user_confirm_remove_self_title;
783 messageResId = R.string.user_confirm_remove_self_message;
784 } else if (userInfo.isRestricted()) {
785 titleResId = R.string.user_profile_confirm_remove_title;
786 messageResId = R.string.user_profile_confirm_remove_message;
787 } else if (userInfo.isManagedProfile()) {
788 titleResId = R.string.work_profile_confirm_remove_title;
789 messageResId = R.string.work_profile_confirm_remove_message;
790 } else {
791 titleResId = R.string.user_confirm_remove_title;
792 messageResId = R.string.user_confirm_remove_message;
793 }
Amith Yamasani51c6dac2014-07-02 00:06:37 +0530794 Dialog dlg = new AlertDialog.Builder(context)
Alexandra Gherghina4c962672014-08-22 11:17:29 +0100795 .setTitle(titleResId)
796 .setMessage(messageResId)
Amith Yamasani51c6dac2014-07-02 00:06:37 +0530797 .setPositiveButton(R.string.user_delete_button,
798 onConfirmListener)
799 .setNegativeButton(android.R.string.cancel, null)
800 .create();
801 return dlg;
802 }
Andres Moralesce249fe2014-07-07 16:58:16 -0700803
804 /**
805 * Returns whether or not this device is able to be OEM unlocked.
806 */
807 static boolean isOemUnlockEnabled(Context context) {
808 PersistentDataBlockManager manager =(PersistentDataBlockManager)
809 context.getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
810 return manager.getOemUnlockEnabled();
811 }
812
813 /**
814 * Allows enabling or disabling OEM unlock on this device. OEM unlocked
815 * devices allow users to flash other OSes to them.
816 */
817 static void setOemUnlockEnabled(Context context, boolean enabled) {
818 PersistentDataBlockManager manager =(PersistentDataBlockManager)
819 context.getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
820 manager.setOemUnlockEnabled(enabled);
821 }
Alexandra Gherghina95b86a52014-07-24 19:13:25 +0100822
823 /**
824 * Returns a circular icon for a user.
825 */
826 public static Drawable getUserIcon(Context context, UserManager um, UserInfo user) {
827 if (user.iconPath == null) return null;
828 Bitmap icon = um.getUserIcon(user.id);
829 if (icon == null) return null;
830 return CircleFramedDrawable.getInstance(context, icon);
831 }
Fabrice Di Meglio22a2a492014-08-08 12:27:57 -0700832
833 /**
834 * Return whether or not the user should have a SIM Cards option in Settings.
835 * TODO: Change back to returning true if count is greater than one after testing.
836 * TODO: See bug 16533525.
837 */
838 public static boolean showSimCardTile(Context context) {
839 final TelephonyManager tm =
840 (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
841
842 return tm.getSimCount() > 0;
843 }
Dan Sandlerb58b5122014-09-02 18:31:49 +0200844
845 /**
846 * Determine whether a package is a "system package", in which case certain things (like
847 * disabling notifications or disabling the package altogether) should be disallowed.
848 */
849 public static boolean isSystemPackage(PackageManager pm, PackageInfo pkg) {
850 if (sSystemSignature == null) {
851 sSystemSignature = new Signature[]{ getSystemSignature(pm) };
852 }
853 return sSystemSignature[0] != null && sSystemSignature[0].equals(getFirstSignature(pkg));
854 }
855
856 private static Signature[] sSystemSignature;
857
858 private static Signature getFirstSignature(PackageInfo pkg) {
859 if (pkg != null && pkg.signatures != null && pkg.signatures.length > 0) {
860 return pkg.signatures[0];
861 }
862 return null;
863 }
864
865 private static Signature getSystemSignature(PackageManager pm) {
866 try {
867 final PackageInfo sys = pm.getPackageInfo("android", PackageManager.GET_SIGNATURES);
868 return getFirstSignature(sys);
869 } catch (NameNotFoundException e) {
870 }
871 return null;
872 }
873
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800874}