com.google.protobuf.nano.InvalidProtocolBufferNanoException Java Examples

The following examples show how to use com.google.protobuf.nano.InvalidProtocolBufferNanoException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LauncherBackupHelper.java    From TurboLauncher with Apache License 2.0 6 votes vote down vote up
/**
 * Read a favorite from the stream.
 *
 * <P>Keys arrive in any order, so screens and containers may not exist yet.
 *
 * @param key identifier for the row
 * @param buffer the serialized proto from the stream, may be larger than dataSize
 * @param dataSize the size of the proto from the stream
 * @param keys keys to mark as clean in the notes for next backup
 */
private void restoreFavorite(Key key, byte[] buffer, int dataSize, ArrayList<Key> keys) {
    if (VERBOSE) Log.v(TAG, "unpacking favorite " + key.id);
    if (DEBUG) Log.d(TAG, "read (" + buffer.length + "): " +
            Base64.encodeToString(buffer, 0, dataSize, Base64.NO_WRAP));

    if (!mRestoreEnabled) {
        if (VERBOSE) Log.v(TAG, "restore not enabled: skipping database mutation");
        return;
    }

    try {
        ContentResolver cr = mContext.getContentResolver();
        ContentValues values = unpackFavorite(buffer, 0, dataSize);
        cr.insert(Favorites.CONTENT_URI, values);
    } catch (InvalidProtocolBufferNanoException e) {
        Log.e(TAG, "failed to decode favorite", e);
    }
}
 
Example #2
Source File: LauncherBackupHelper.java    From TurboLauncher with Apache License 2.0 6 votes vote down vote up
/**
 * Read a screen from the stream.
 *
 * <P>Keys arrive in any order, so children of this screen may already exist.
 *
 * @param key identifier for the row
 * @param buffer the serialized proto from the stream, may be larger than dataSize
 * @param dataSize the size of the proto from the stream
 * @param keys keys to mark as clean in the notes for next backup
 */
private void restoreScreen(Key key, byte[] buffer, int dataSize, ArrayList<Key> keys) {
    if (VERBOSE) Log.v(TAG, "unpacking screen " + key.id);
    if (DEBUG) Log.d(TAG, "read (" + buffer.length + "): " +
            Base64.encodeToString(buffer, 0, dataSize, Base64.NO_WRAP));

    if (!mRestoreEnabled) {
        if (VERBOSE) Log.v(TAG, "restore not enabled: skipping database mutation");
        return;
    }

    try {
        ContentResolver cr = mContext.getContentResolver();
        ContentValues values = unpackScreen(buffer, 0, dataSize);
        cr.insert(WorkspaceScreens.CONTENT_URI, values);

    } catch (InvalidProtocolBufferNanoException e) {
        Log.e(TAG, "failed to decode screen", e);
    }
}
 
Example #3
Source File: NanoUtilsTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@Test
public void parseInvalid() throws Exception {
  InputStream is = new ByteArrayInputStream(new byte[] {-127});
  try {
    marshaller.parse(is);
    fail("Expected exception");
  } catch (StatusRuntimeException ex) {
    assertEquals(Status.Code.INTERNAL, ex.getStatus().getCode());
    assertTrue(ex.getCause() instanceof InvalidProtocolBufferNanoException);
  }
}
 
Example #4
Source File: LauncherBackupHelper.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
/** Deserialize a Screen from persistence, after verifying checksum wrapper. */
private ContentValues unpackScreen(byte[] buffer, int dataSize)
        throws InvalidProtocolBufferNanoException {
    Screen screen = unpackProto(new Screen(), buffer, dataSize);
    ContentValues values = new ContentValues();
    values.put(WorkspaceScreens._ID, screen.id);
    values.put(WorkspaceScreens.SCREEN_RANK, screen.rank);
    return values;
}
 
Example #5
Source File: LauncherBackupHelper.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Deserialize a proto after verifying checksum wrapper.
 */
private <T extends MessageNano> T unpackProto(T proto, byte[] buffer, int dataSize)
        throws InvalidProtocolBufferNanoException {
    MessageNano.mergeFrom(proto, readCheckedBytes(buffer, dataSize));
    if (DEBUG) Log.d(TAG, "unpacked proto " + proto);
    return proto;
}
 
Example #6
Source File: LauncherBackupHelper.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
/** Unwrap a proto message from a CheckedMessage, verifying the checksum. */
private static byte[] readCheckedBytes(byte[] buffer, int dataSize)
        throws InvalidProtocolBufferNanoException {
    CheckedMessage wrapper = new CheckedMessage();
    MessageNano.mergeFrom(wrapper, buffer, 0, dataSize);
    CRC32 checksum = new CRC32();
    checksum.update(wrapper.payload);
    if (wrapper.checksum != checksum.getValue()) {
        throw new InvalidProtocolBufferNanoException("checksum does not match");
    }
    return wrapper.payload;
}
 
Example #7
Source File: LauncherBackupHelper.java    From TurboLauncher with Apache License 2.0 5 votes vote down vote up
/** Deserialize a Screen from persistence, after verifying checksum wrapper. */
private ContentValues unpackScreen(byte[] buffer, int offset, int dataSize)
        throws InvalidProtocolBufferNanoException {
    Screen screen = new Screen();
    MessageNano.mergeFrom(screen, readCheckedBytes(buffer, offset, dataSize));
    if (VERBOSE) Log.v(TAG, "unpacked screen " + screen.id + "/" + screen.rank);
    ContentValues values = new ContentValues();
    values.put(WorkspaceScreens._ID, screen.id);
    values.put(WorkspaceScreens.SCREEN_RANK, screen.rank);
    return values;
}
 
Example #8
Source File: LauncherBackupHelper.java    From TurboLauncher with Apache License 2.0 5 votes vote down vote up
/** Deserialize an icon resource from persistence, after verifying checksum wrapper. */
private static Resource unpackIcon(byte[] buffer, int offset, int dataSize)
        throws InvalidProtocolBufferNanoException {
    Resource res = new Resource();
    MessageNano.mergeFrom(res, readCheckedBytes(buffer, offset, dataSize));
    if (VERBOSE) Log.v(TAG, "unpacked icon " + res.dpi + "/" + res.data.length);
    return res;
}
 
Example #9
Source File: LauncherBackupHelper.java    From TurboLauncher with Apache License 2.0 5 votes vote down vote up
/** Deserialize a widget from persistence, after verifying checksum wrapper. */
private Widget unpackWidget(byte[] buffer, int offset, int dataSize)
        throws InvalidProtocolBufferNanoException {
    Widget widget = new Widget();
    MessageNano.mergeFrom(widget, readCheckedBytes(buffer, offset, dataSize));
    if (VERBOSE) Log.v(TAG, "unpacked widget " + widget.provider);
    return widget;
}
 
Example #10
Source File: LauncherBackupHelper.java    From TurboLauncher with Apache License 2.0 5 votes vote down vote up
/** Unwrap a proto message from a CheckedMessage, verifying the checksum. */
private static byte[] readCheckedBytes(byte[] buffer, int offset, int dataSize)
        throws InvalidProtocolBufferNanoException {
    CheckedMessage wrapper = new CheckedMessage();
    MessageNano.mergeFrom(wrapper, buffer, offset, dataSize);
    CRC32 checksum = new CRC32();
    checksum.update(wrapper.payload);
    if (wrapper.checksum != checksum.getValue()) {
        throw new InvalidProtocolBufferNanoException("checksum does not match");
    }
    return wrapper.payload;
}
 
Example #11
Source File: LauncherBackupHelper.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
/** Deserialize a Screen from persistence, after verifying checksum wrapper. */
private ContentValues unpackScreen(byte[] buffer, int dataSize)
        throws InvalidProtocolBufferNanoException {
    Screen screen = unpackProto(new Screen(), buffer, dataSize);
    ContentValues values = new ContentValues();
    values.put(WorkspaceScreens._ID, screen.id);
    values.put(WorkspaceScreens.SCREEN_RANK, screen.rank);
    return values;
}
 
Example #12
Source File: LauncherBackupHelper.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
/**
 * Deserialize a proto after verifying checksum wrapper.
 */
private <T extends MessageNano> T unpackProto(T proto, byte[] buffer, int dataSize)
        throws InvalidProtocolBufferNanoException {
    MessageNano.mergeFrom(proto, readCheckedBytes(buffer, dataSize));
    if (DEBUG) Log.d(TAG, "unpacked proto " + proto);
    return proto;
}
 
Example #13
Source File: LauncherBackupHelper.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
/** Unwrap a proto message from a CheckedMessage, verifying the checksum. */
private static byte[] readCheckedBytes(byte[] buffer, int dataSize)
        throws InvalidProtocolBufferNanoException {
    CheckedMessage wrapper = new CheckedMessage();
    MessageNano.mergeFrom(wrapper, buffer, 0, dataSize);
    CRC32 checksum = new CRC32();
    checksum.update(wrapper.payload);
    if (wrapper.checksum != checksum.getValue()) {
        throw new InvalidProtocolBufferNanoException("checksum does not match");
    }
    return wrapper.payload;
}
 
Example #14
Source File: LauncherBackupHelper.java    From TurboLauncher with Apache License 2.0 4 votes vote down vote up
/** Deserialize a Favorite from persistence, after verifying checksum wrapper. */
private ContentValues unpackFavorite(byte[] buffer, int offset, int dataSize)
        throws InvalidProtocolBufferNanoException {
    Favorite favorite = new Favorite();
    MessageNano.mergeFrom(favorite, readCheckedBytes(buffer, offset, dataSize));
    if (VERBOSE) Log.v(TAG, "unpacked favorite " + favorite.itemType + ", " +
            (TextUtils.isEmpty(favorite.title) ? favorite.id : favorite.title));
    ContentValues values = new ContentValues();
    values.put(Favorites._ID, favorite.id);
    values.put(Favorites.SCREEN, favorite.screen);
    values.put(Favorites.CONTAINER, favorite.container);
    values.put(Favorites.CELLX, favorite.cellX);
    values.put(Favorites.CELLY, favorite.cellY);
    values.put(Favorites.SPANX, favorite.spanX);
    values.put(Favorites.SPANY, favorite.spanY);
    values.put(Favorites.ICON_TYPE, favorite.iconType);
    if (favorite.iconType == Favorites.ICON_TYPE_RESOURCE) {
        values.put(Favorites.ICON_PACKAGE, favorite.iconPackage);
        values.put(Favorites.ICON_RESOURCE, favorite.iconResource);
    }
    if (favorite.iconType == Favorites.ICON_TYPE_BITMAP) {
        values.put(Favorites.ICON, favorite.icon);
    }
    if (!TextUtils.isEmpty(favorite.title)) {
        values.put(Favorites.TITLE, favorite.title);
    } else {
        values.put(Favorites.TITLE, "");
    }
    if (!TextUtils.isEmpty(favorite.intent)) {
        values.put(Favorites.INTENT, favorite.intent);
    }
    values.put(Favorites.ITEM_TYPE, favorite.itemType);
    if (favorite.itemType == Favorites.ITEM_TYPE_APPWIDGET) {
        if (!TextUtils.isEmpty(favorite.appWidgetProvider)) {
            values.put(Favorites.APPWIDGET_PROVIDER, favorite.appWidgetProvider);
        }
        values.put(Favorites.APPWIDGET_ID, favorite.appWidgetId);
    }

    // Let LauncherModel know we've been here.
    values.put(LauncherSettings.Favorites.RESTORED, 1);

    return values;
}