OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.util; | 5 package org.chromium.chrome.browser.util; |
6 | 6 |
7 import android.content.ComponentName; | 7 import android.content.ComponentName; |
8 import android.content.Context; | 8 import android.content.Context; |
9 import android.content.Intent; | 9 import android.content.Intent; |
10 import android.content.pm.ResolveInfo; | 10 import android.content.pm.ResolveInfo; |
11 import android.os.Build; | 11 import android.os.Build; |
12 import android.os.Bundle; | 12 import android.os.Bundle; |
13 import android.os.IBinder; | 13 import android.os.IBinder; |
14 import android.os.Parcel; | 14 import android.os.Parcel; |
15 import android.os.Parcelable; | 15 import android.os.Parcelable; |
16 | 16 |
17 import org.chromium.base.Log; | 17 import org.chromium.base.Log; |
18 import org.chromium.base.VisibleForTesting; | 18 import org.chromium.base.VisibleForTesting; |
19 | 19 |
20 import java.lang.reflect.Method; | 20 import java.lang.reflect.Method; |
21 import java.util.ArrayList; | 21 import java.util.ArrayList; |
22 import java.util.List; | 22 import java.util.List; |
23 | 23 |
24 /** | 24 /** |
25 * Utilities dealing with extracting information from intents. | 25 * Utilities dealing with extracting information from intents. |
26 */ | 26 */ |
27 public class IntentUtils { | 27 public class IntentUtils { |
28 private static final String TAG = "IntentUtils"; | 28 private static final String TAG = "cr_IntentUtils"; |
29 | 29 |
30 /** See {@link #isIntentTooLarge(Intent)}. */ | 30 /** See {@link #isIntentTooLarge(Intent)}. */ |
31 private static final int MAX_INTENT_SIZE_THRESHOLD = 750000; | 31 private static final int MAX_INTENT_SIZE_THRESHOLD = 750000; |
32 | 32 |
33 /** | 33 /** |
34 * Retrieves a list of components that would handle the given intent. | 34 * Retrieves a list of components that would handle the given intent. |
35 * @param context The application context. | 35 * @param context The application context. |
36 * @param intent The intent which we are interested in. | 36 * @param intent The intent which we are interested in. |
37 * @return The list of component names. | 37 * @return The list of component names. |
38 */ | 38 */ |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 try { | 117 try { |
118 return intent.getBundleExtra(name); | 118 return intent.getBundleExtra(name); |
119 } catch (Throwable t) { | 119 } catch (Throwable t) { |
120 // Catches un-parceling exceptions. | 120 // Catches un-parceling exceptions. |
121 Log.e(TAG, "getBundleExtra failed on intent " + intent); | 121 Log.e(TAG, "getBundleExtra failed on intent " + intent); |
122 return null; | 122 return null; |
123 } | 123 } |
124 } | 124 } |
125 | 125 |
126 /** | 126 /** |
| 127 * Just like {@link Bundle#getBundle(String)} but doesn't throw exceptions. |
| 128 */ |
| 129 public static Bundle safeGetBundle(Bundle bundle, String name) { |
| 130 try { |
| 131 return bundle.getBundle(name); |
| 132 } catch (Throwable t) { |
| 133 // Catches un-parceling exceptions. |
| 134 Log.e(TAG, "getBundle failed on bundle " + bundle); |
| 135 return null; |
| 136 } |
| 137 } |
| 138 |
| 139 /** |
127 * Just like {@link Bundle#getParcelable(String)} but doesn't throw exceptio
ns. | 140 * Just like {@link Bundle#getParcelable(String)} but doesn't throw exceptio
ns. |
128 */ | 141 */ |
129 public static <T extends Parcelable> T safeGetParcelable(Bundle bundle, Stri
ng name) { | 142 public static <T extends Parcelable> T safeGetParcelable(Bundle bundle, Stri
ng name) { |
130 try { | 143 try { |
131 return bundle.getParcelable(name); | 144 return bundle.getParcelable(name); |
132 } catch (Throwable t) { | 145 } catch (Throwable t) { |
133 // Catches un-parceling exceptions. | 146 // Catches un-parceling exceptions. |
134 Log.e(TAG, "getParcelable failed on bundle " + bundle); | 147 Log.e(TAG, "getParcelable failed on bundle " + bundle); |
135 return null; | 148 return null; |
136 } | 149 } |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 * Determines if an Intent's size is bigger than a reasonable threshold. Ha
ving too many large | 277 * Determines if an Intent's size is bigger than a reasonable threshold. Ha
ving too many large |
265 * transactions in flight simultaneously (including Intents) causes Android
to throw a | 278 * transactions in flight simultaneously (including Intents) causes Android
to throw a |
266 * {@link TransactionTooLargeException}. According to that class, the limit
across all | 279 * {@link TransactionTooLargeException}. According to that class, the limit
across all |
267 * transactions combined is one megabyte. Best practice is to keep each ind
ividual Intent well | 280 * transactions combined is one megabyte. Best practice is to keep each ind
ividual Intent well |
268 * under the limit to avoid this situation. | 281 * under the limit to avoid this situation. |
269 */ | 282 */ |
270 public static boolean isIntentTooLarge(Intent intent) { | 283 public static boolean isIntentTooLarge(Intent intent) { |
271 return getParceledIntentSize(intent) > MAX_INTENT_SIZE_THRESHOLD; | 284 return getParceledIntentSize(intent) > MAX_INTENT_SIZE_THRESHOLD; |
272 } | 285 } |
273 } | 286 } |
OLD | NEW |