/** * Return information about who launched this activity. If the launching Intent * contains an {@link android.content.Intent#EXTRA_REFERRER Intent.EXTRA_REFERRER}, * that will be returned as-is; otherwise, if known, an * {@link Intent#URI_ANDROID_APP_SCHEME android-app:} referrer URI containing the * package name that started the Intent will be returned. This may return null if no * referrer can be identified -- it is neither explicitly specified, nor is it known which * application package was involved. * * <p>If called while inside the handling of {@link #onNewIntent}, this function will * return the referrer that submitted that new intent to the activity. Otherwise, it * always returns the referrer of the original Intent.</p> * * <p>Note that this is <em>not</em> a security feature -- you can not trust the * referrer information, applications can spoof it.</p> */ @Nullable public Uri getReferrer() { Intent intent = getIntent(); try { Uri referrer = intent.getParcelableExtra(Intent.EXTRA_REFERRER); if (referrer != null) { return referrer; } String referrerName = intent.getStringExtra(Intent.EXTRA_REFERRER_NAME); if (referrerName != null) { return Uri.parse(referrerName); } } catch (BadParcelableException e) { Log.w(TAG, "Cannot read referrer from intent;" + " intent extras contain unknown custom Parcelable objects"); } if (mReferrer != null) { return new Uri.Builder().scheme("android-app").authority(mReferrer).build(); } return null; }
/** * Unmarshalls a parcelable's byte array into the object * * @param bytes the byte array * @param clazz the class * @param <T> the type * @return the object */ @SuppressWarnings("unchecked") public static <T extends Parcelable> T unmarshallParcelable(byte[] bytes, Class<T> clazz) { if (bytes == null) { return null; } Parcel parcel = Parcel.obtain(); parcel.unmarshall(bytes, 0, bytes.length); parcel.setDataPosition(0); try { Parcelable.Creator<? extends Parcelable> creator = (Parcelable.Creator<? extends Parcelable>) clazz.getField("CREATOR").get(null); return (T) creator.createFromParcel(parcel); } catch (Exception e) { throw new BadParcelableException(e); } finally { parcel.recycle(); } }
/** * Unmarshalls a serializable's byte array into the object * * @param bytes the bytes * @param <T> the type * @return the object */ @SuppressWarnings("unchecked") public static <T extends Serializable> T unmarshallSerializable(byte[] bytes) { if (bytes == null) { return null; } Parcel parcel = Parcel.obtain(); parcel.unmarshall(bytes, 0, bytes.length); parcel.setDataPosition(0); try { return (T) parcel.readSerializable(); } catch (Exception e) { throw new BadParcelableException(e); } finally { parcel.recycle(); } }
/** * Gets a parcelable from an intent * * @param intent the intent * @param name the name * @param <T> the type * @return the parcelable */ @SuppressWarnings("unchecked") public static <T extends Parcelable> T getParcelable(Intent intent, String name) { byte[] bytes = intent.getByteArrayExtra(name); if (bytes == null) { return null; } try { ClassLoader intentClassLoader = intent.getExtras().getClassLoader(); String classname = intent.getStringExtra(name + "_CLASSNAME"); Class<T> parcelable; if (intentClassLoader == null) { parcelable = (Class<T>) Class.forName(classname); } else { parcelable = (Class<T>) Class.forName(classname, true, intentClassLoader); } return unmarshallParcelable(bytes, parcelable); } catch (Exception e) { throw new BadParcelableException(e); } }
@Test public void fromBytes_withNullIntent_throwsBadParcelableException() { final byte[] intentBytes = toBytesUnchecked(null); assertThatThrownBy(new ThrowableAssert.ThrowingCallable() { @Override public void call() throws Throwable { IntentUtil.fromBytes(intentBytes); } }).isInstanceOf(BadParcelableException.class); }
private void updateKeySet() { // Try to unpack bundle without sandbox if (!mUseSandbox) { try { if (mBundle.keySet() != null) { mKeys = mBundle.keySet().toArray(mKeys); mKeysCount = mBundle.size(); } else { mKeys = new String[0]; mKeysCount = 0; } return; } catch (BadParcelableException ignored) {} } // If it failed or was disabled sandboxBundle(true, null); }
@SuppressWarnings("unused") @Subscribe public void onChildAdded(GameAddedEvent event) { synchronized (listeners) { for (ServiceListener listener : listeners) { try { listener.gameAdded(event.getGameData()); } catch (RemoteException | BadParcelableException ignore) { } } } }
public static <D extends Durable> void writeToParcel(Parcel parcel, D d) { try { parcel.writeByteArray(writeToArray(d)); } catch (IOException e) { throw new BadParcelableException(e); } }
public static <D extends Durable> D readFromParcel(Parcel parcel, D d) { try { return readFromArray(parcel.createByteArray(), d); } catch (IOException e) { throw new BadParcelableException(e); } }
/** * Sanitizes an intent. In case the intent cannot be unparcelled, all extras will be removed to * make it safe to use. * @return A safe to use version of this intent. */ public static Intent sanitizeIntent(final Intent incomingIntent) { if (incomingIntent == null) return null; try { incomingIntent.getBooleanExtra("TriggerUnparcel", false); return incomingIntent; } catch (BadParcelableException e) { Log.e(TAG, "Invalid incoming intent.", e); return incomingIntent.replaceExtras((Bundle) null); } }
private RuntimeException asParcelableException(final Throwable e) { if (e instanceof SecurityException || e instanceof BadParcelableException || e instanceof IllegalArgumentException || e instanceof NullPointerException || e instanceof IllegalStateException || e instanceof NetworkOnMainThreadException || e instanceof UnsupportedOperationException) return (RuntimeException) e; return new IllegalStateException(e); }
/** * Constructor for loading from parcel */ SandboxedObject(Parcel source) { try { mType = Type.values()[source.readInt()]; mHelper = mType.mHelperClass.getDeclaredConstructor(Parcel.class).newInstance(source); } catch (Exception e) { throw new BadParcelableException(e); } }
@Override public Object unwrap(ClassLoader classLoader) { try { return Utils.deepCastArray( (Object[]) super.unwrap(classLoader), Class.forName(mArrayClassName, true, classLoader) ); } catch (ClassNotFoundException e) { throw new BadParcelableException(e); } }
Accessors(String fieldName) throws RemoteException { mFieldName = fieldName; // Get value final SandboxedObject wrappedValue = mSandboxedObject.getFieldValue(mFieldName); try { // Try to unwrap, if successful use that value mCachedValue = wrappedValue.unwrap(null); } catch (BadParcelableException e) { // Unwrap failed, use sandbox mValueIsSandboxed = true; mCachedStringValue = mSandboxedObject.getFieldValueAsString(mFieldName); mCachedValue = wrappedValue; } }
private static boolean intentInvalid(Intent intent) { if (intent == null) { return true; } try { // force unparcelling to check if we are missing classes to // correctly process callout response intent.hasExtra(INTENT_RESULT_VALUE); } catch (BadParcelableException e) { Log.w(TAG, "unable to unparcel intent: " + e.getMessage()); return true; } return false; }
private boolean isConnectedIntent(Intent intent) { NetworkInfo networkInfo = null; try { networkInfo = (NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO); } catch (BadParcelableException ignored) {} return (networkInfo != null && networkInfo.isConnected() && networkInfo.getType() == ConnectivityManager.TYPE_WIFI); }
@SuppressLint("NewApi") @Override public void onCreate(final Bundle savedInstanceState) { if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= 23 && PermissionChecker .checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PermissionChecker.PERMISSION_GRANTED) { requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0); } try { super.onCreate(savedInstanceState); } catch (final BadParcelableException bpe) { if (BuildConfig.DEBUG) Logger.log(bpe); } init(); }
public static boolean hasExtras(Bundle extras) { try { return (extras != null && !extras.isEmpty()); } catch (BadParcelableException e) { Log.w("IntentLogger", "Extra contains unknown class instance: ", e); return true; } }
@Test public void fromBytes_withIntentNotPresent_throwsBadParcelableException() { final byte[] intentBytes = new byte[10]; assertThatThrownBy(new ThrowableAssert.ThrowingCallable() { @Override public void call() throws Throwable { IntentUtil.fromBytes(intentBytes); } }).isInstanceOf(BadParcelableException.class); }
private final Intent c(Intent paramIntent) { try { gya localgya = this.c.r_(); if (localgya != null) { paramIntent.putExtra("com.google.plus.analytics.intent.extra.START_VIEW", localgya.ordinal()); paramIntent.putExtra("com.google.plus.analytics.intent.extra.START_TIME", System.currentTimeMillis()); Bundle localBundle = new Bundle(); this.c.b(localBundle); if (!localBundle.isEmpty()) { paramIntent.putExtras(localBundle); } } return paramIntent; } catch (BadParcelableException localBadParcelableException) {} return paramIntent; }
@SuppressWarnings("unchecked") @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public static <T extends Parcelable> T getParcelable(ClassLoader classLoader, PersistableBundle persistableBundle, String name) { PersistableBundle bundle = persistableBundle.getPersistableBundle(name); if (bundle == null) { return null; } try { return unmarshallParcelable(Base64.decode(bundle.getString("data"), 0), (Class<T>) Class.forName(bundle.getString("class"), true, classLoader)); } catch (ClassNotFoundException e) { throw new BadParcelableException(e); } }
/** * Deserializes an intent from the provided bytes array. * @throws BadParcelableException if the intent is null, not present, or malformed. */ @NonNull public static Intent fromBytes(@NonNull byte[] intentBytes) throws BadParcelableException { require(intentBytes, notNullValue()); Intent intent; try { Parcel parcel = Parcel.obtain(); parcel.unmarshall(intentBytes, 0, intentBytes.length); parcel.setDataPosition(0); intent = parcel.readParcelable(IntentUtil.class.getClassLoader()); parcel.recycle(); } catch (Exception ex) { throw new BadParcelableException(ex); } validate(intent, notNullValue(), BadParcelableException.class); return intent; }
@SuppressWarnings("unchecked") private HistoryStore(Parcel in) { mMaxSize = in.readInt(); int count = in.readInt(); for (int i = 0; i < count; i++) try { mHistoryList.add((A) in.readParcelable(null)); // this (maybe sometimes) crashes with a BadParcelableException } catch (BadParcelableException e1) { Log.e("afc_HistoryStore", "BadParcelableException: " + e1.getMessage()); BugSenseHandler.sendExceptionMessage("afc_HistoryStore", "readParcelable_1: " + e1.getMessage(), e1); try { mHistoryList.add((A) in.readParcelable(HistoryStore.class.getClassLoader())); } catch (BadParcelableException e2) { Log.e("afc_HistoryStore", "BadParcelableException: " + e2.getMessage()); BugSenseHandler.sendExceptionMessage("afc_HistoryStore", "readParcelable_2: " + e2.getMessage(), e2); try { mHistoryList.add((A) in.readParcelable(getClass().getClassLoader())); } catch (BadParcelableException e3) { Log.e("afc_HistoryStore", "BadParcelableException: " + e3.getMessage()); BugSenseHandler.sendExceptionMessage("afc_HistoryStore", "readParcelable_3: " + e3.getMessage(), e3); } } } }