类android.os.BadParcelableException源码实例Demo

下面列出了怎么用android.os.BadParcelableException的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: OpenYOLO-Android   文件: IntentUtil.java
/**
 * 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;
}
 
源代码2 项目: sms-ticket   文件: TicketAlarmReceiver.java
@Override
public void onReceive(Context c, Intent intent) {
    try {
        final Ticket t = intent.getParcelableExtra(EXTRA_TICKET);

        if (t == null) {
            DebugLog.w("Scheduled ticket is null");
        } else {
            if (INTENT_TICKET_ALARM_EXPIRING.equals(intent.getAction())) {
                NotificationUtil.notifyTicket(c, t, Preferences.getBoolean(c, Preferences.KEEP_NOTIFICATIONS,
                    true));
                DebugLog.i("Receiving alarm for expiring ticket " + t);
            }
            if (INTENT_TICKET_ALARM_EXPIRED.equals(intent.getAction())) {
                NotificationUtil.notifyTicket(c, t, false);
                DebugLog.i("Receiving alarm for expired ticket " + t);
            }
        }
    } catch (BadParcelableException e) {
        DebugLog.i("ticket was bought in the old version and alarm received in the new version, ignoring");
    }
}
 
源代码3 项目: android_9.0.0_r45   文件: KeyChainSnapshot.java
/**
 * CertPath containing the public key used to encrypt {@code encryptedRecoveryKeyBlob}.
 */
public @NonNull CertPath getTrustedHardwareCertPath() {
    try {
        return mCertPath.getCertPath();
    } catch (CertificateException e) {
        // Rethrow an unchecked exception as it should not happen. If such an issue exists,
        // an exception should have been thrown during service initialization.
        throw new BadParcelableException(e);
    }
}
 
源代码4 项目: android_9.0.0_r45   文件: AssistStructure.java
Parcel readParcel(int validateToken, int level) {
    if (DEBUG_PARCEL) Log.d(TAG, "readParcel: at " + mCurParcel.dataPosition()
            + ", avail=" + mCurParcel.dataAvail() + ", windows=" + mNumReadWindows
            + ", views=" + mNumReadViews + ", level=" + level);
    int token = mCurParcel.readInt();
    if (token != 0) {
        if (token != validateToken) {
            throw new BadParcelableException("Got token " + Integer.toHexString(token)
                    + ", expected token " + Integer.toHexString(validateToken));
        }
        return mCurParcel;
    }
    // We have run out of partial data, need to read another batch.
    mTransferToken = mCurParcel.readStrongBinder();
    if (mTransferToken == null) {
        throw new IllegalStateException(
                "Reached end of partial data without transfer token");
    }
    if (DEBUG_PARCEL) Log.d(TAG, "Ran out of partial data at "
            + mCurParcel.dataPosition() + ", token " + mTransferToken);
    fetchData();
    if (DEBUG_PARCEL) Log.d(TAG, "Creating PooledStringReader @ "
            + mCurParcel.dataPosition());
    mStringReader = new PooledStringReader(mCurParcel);
    if (DEBUG_PARCEL) Log.d(TAG, "PooledStringReader size = "
            + mStringReader.getStringCount());
    if (DEBUG_PARCEL) Log.d(TAG, "readParcel: at " + mCurParcel.dataPosition()
            + ", avail=" + mCurParcel.dataAvail() + ", windows=" + mNumReadWindows
            + ", views=" + mNumReadViews);
    mCurParcel.readInt();
    return mCurParcel;
}
 
源代码5 项目: FairEmail   文件: Log.java
static List<String> getExtras(Bundle data) {
    List<String> result = new ArrayList<>();
    if (data == null)
        return result;

    try {
        Set<String> keys = data.keySet();
        for (String key : keys) {
            Object v = data.get(key);

            Object value = v;
            if (v != null && v.getClass().isArray()) {
                int length = Array.getLength(v);
                if (length <= 10) {
                    String[] elements = new String[length];
                    for (int i = 0; i < length; i++) {
                        Object element = Array.get(v, i);
                        if (element instanceof Long)
                            elements[i] = element.toString() + " (0x" + Long.toHexString((Long) element) + ")";
                        else
                            elements[i] = (element == null ? null : element.toString());
                    }
                    value = TextUtils.join(",", elements);
                } else
                    value = "[" + length + "]";
            } else if (v instanceof Long)
                value = v.toString() + " (0x" + Long.toHexString((Long) v) + ")";

            result.add(key + "=" + value + (value == null ? "" : " (" + v.getClass().getSimpleName() + ")"));
        }
    } catch (BadParcelableException ex) {
        // android.os.BadParcelableException: ClassNotFoundException when unmarshalling: ...
        Log.e(ex);
    }

    return result;
}
 
源代码6 项目: OpenYOLO-Android   文件: IntentUtilTest.java
@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);
}
 
源代码7 项目: OpenYOLO-Android   文件: IntentUtilTest.java
@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);
}
 
源代码8 项目: FireFiles   文件: DurableUtils.java
public static <D extends Durable> void writeToParcel(Parcel parcel, D d) {
    try {
        parcel.writeByteArray(writeToArray(d));
    } catch (IOException e) {
        throw new BadParcelableException(e);
    }
}
 
源代码9 项目: FireFiles   文件: DurableUtils.java
public static <D extends Durable> D readFromParcel(Parcel parcel, D d) {
    try {
        return readFromArray(parcel.createByteArray(), d);
    } catch (IOException e) {
        throw new BadParcelableException(e);
    }
}
 
源代码10 项目: FireFiles   文件: DurableUtils.java
public static <D extends Durable> void writeToParcel(Parcel parcel, D d) {
    try {
        parcel.writeByteArray(writeToArray(d));
    } catch (IOException e) {
        throw new BadParcelableException(e);
    }
}
 
源代码11 项目: FireFiles   文件: DurableUtils.java
public static <D extends Durable> D readFromParcel(Parcel parcel, D d) {
    try {
        return readFromArray(parcel.createByteArray(), d);
    } catch (IOException e) {
        throw new BadParcelableException(e);
    }
}
 
源代码12 项目: FireFiles   文件: DurableUtils.java
public static <D extends Durable> void writeToParcel(Parcel parcel, D d) {
    try {
        parcel.writeByteArray(writeToArray(d));
    } catch (IOException e) {
        throw new BadParcelableException(e);
    }
}
 
源代码13 项目: FireFiles   文件: DurableUtils.java
public static <D extends Durable> D readFromParcel(Parcel parcel, D d) {
    try {
        return readFromArray(parcel.createByteArray(), d);
    } catch (IOException e) {
        throw new BadParcelableException(e);
    }
}
 
源代码14 项目: AndroidChromium   文件: IntentUtils.java
/**
 * 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);
    }
}
 
源代码15 项目: sdk   文件: NevoDecoratorService.java
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);
}
 
源代码16 项目: 365browser   文件: IntentUtils.java
/**
 * 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);
    }
}
 
源代码17 项目: commcare-android   文件: IntentCallout.java
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;
}
 
源代码18 项目: MapsMeasure   文件: Map.java
@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();
}
 
 类所在包
 同包方法