| 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; |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 try { | 166 try { |
| 167 return intent.getStringArrayListExtra(name); | 167 return intent.getStringArrayListExtra(name); |
| 168 } catch (Throwable t) { | 168 } catch (Throwable t) { |
| 169 // Catches un-parceling exceptions. | 169 // Catches un-parceling exceptions. |
| 170 Log.e(TAG, "getStringArrayListExtra failed on intent " + intent); | 170 Log.e(TAG, "getStringArrayListExtra failed on intent " + intent); |
| 171 return null; | 171 return null; |
| 172 } | 172 } |
| 173 } | 173 } |
| 174 | 174 |
| 175 /** | 175 /** |
| 176 * Just like {@link Intent#getByteArrayExtra(String)} but doesn't throw exce
ptions. |
| 177 */ |
| 178 public static byte[] safeGetByteArrayExtra(Intent intent, String name) { |
| 179 try { |
| 180 return intent.getByteArrayExtra(name); |
| 181 } catch (Throwable t) { |
| 182 // Catches un-parceling exceptions. |
| 183 Log.e(TAG, "getByteArrayExtra failed on intent " + intent); |
| 184 return null; |
| 185 } |
| 186 } |
| 187 |
| 188 /** |
| 176 * @return a Binder from an Intent, or null. | 189 * @return a Binder from an Intent, or null. |
| 177 * | 190 * |
| 178 * Creates a temporary copy of the extra Bundle, which is required as | 191 * Creates a temporary copy of the extra Bundle, which is required as |
| 179 * Intent#getBinderExtra() doesn't exist, but Bundle.getBinder() does. | 192 * Intent#getBinderExtra() doesn't exist, but Bundle.getBinder() does. |
| 180 */ | 193 */ |
| 181 public static IBinder safeGetBinderExtra(Intent intent, String name) { | 194 public static IBinder safeGetBinderExtra(Intent intent, String name) { |
| 182 if (!intent.hasExtra(name)) return null; | 195 if (!intent.hasExtra(name)) return null; |
| 183 try { | 196 try { |
| 184 Bundle extras = intent.getExtras(); | 197 Bundle extras = intent.getExtras(); |
| 185 // Bundle#getBinder() is public starting at API level 18, but exists | 198 // Bundle#getBinder() is public starting at API level 18, but exists |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 Bundle.class.getMethod("putIBinder", String.class, IBind
er.class); | 236 Bundle.class.getMethod("putIBinder", String.class, IBind
er.class); |
| 224 putBinderMethod.invoke(bundle, name, binder); | 237 putBinderMethod.invoke(bundle, name, binder); |
| 225 } | 238 } |
| 226 } catch (Throwable t) { | 239 } catch (Throwable t) { |
| 227 // Catches parceling exceptions. | 240 // Catches parceling exceptions. |
| 228 Log.e(TAG, "putBinder failed on bundle " + bundle); | 241 Log.e(TAG, "putBinder failed on bundle " + bundle); |
| 229 } | 242 } |
| 230 intent.putExtras(bundle); | 243 intent.putExtras(bundle); |
| 231 } | 244 } |
| 232 } | 245 } |
| OLD | NEW |