Java Code Examples for android.os.Parcel#recycle()

The following examples show how to use android.os.Parcel#recycle() .
Example 1
Project: TelePlus-Android   File: ICustomTabsCallback.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void onMessageChannelReady(Bundle extras) throws RemoteException {
    Parcel _data = Parcel.obtain();
    Parcel _reply = Parcel.obtain();

    try {
        _data.writeInterfaceToken("android.support.customtabs.ICustomTabsCallback");
        if(extras != null) {
            _data.writeInt(1);
            extras.writeToParcel(_data, 0);
        } else {
            _data.writeInt(0);
        }

        this.mRemote.transact(4, _data, _reply, 0);
        _reply.readException();
    } finally {
        _reply.recycle();
        _data.recycle();
    }

}
 
Example 2
Project: Indic-Keyboard   File: RichInputConnectionAndTextRangeTests.java    License: Apache License 2.0 6 votes vote down vote up
public MockConnection(final CharSequence text, final int cursorPosition) {
    super(null, false);
    // Interaction of spans with Parcels is completely non-trivial, but in the actual case
    // the CharSequences do go through Parcels because they go through IPC. There
    // are some significant differences between the behavior of Spanned objects that
    // have and that have not gone through parceling, so it's much easier to simulate
    // the environment with Parcels than try to emulate things by hand.
    final Parcel p = Parcel.obtain();
    TextUtils.writeToParcel(text.subSequence(0, cursorPosition), p, 0 /* flags */);
    TextUtils.writeToParcel(text.subSequence(cursorPosition, text.length()), p,
            0 /* flags */);
    final byte[] marshalled = p.marshall();
    p.unmarshall(marshalled, 0, marshalled.length);
    p.setDataPosition(0);
    mTextBefore = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(p);
    mTextAfter = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(p);
    mExtractedText = null;
    p.recycle();
}
 
Example 3
Project: commcare-android   File: AndroidSharedKeyRecord.java    License: Apache License 2.0 6 votes vote down vote up
public Bundle getIncomingCallout(Intent incoming) {
    byte[] incomingCallout = incoming.getByteArrayExtra(EXTRA_KEY_CALLOUT);
    byte[] incomingKey = incoming.getByteArrayExtra(EXTRA_KEY_CALLOUT_SYMETRIC_KEY);
    Parcel p = Parcel.obtain();
    byte[] decoded;
    try {
        byte[] aesKey = CryptUtil.decrypt(incomingKey, CryptUtil.getPrivateKeyCipher(this.privateKey));
        decoded = CryptUtil.decrypt(incomingCallout, CryptUtil.getAesKeyCipher(aesKey));
    } catch (GeneralSecurityException gse) {
        Logger.exception("Error getting incoming callout", gse);
        return null;
    }

    p.unmarshall(decoded, 0, decoded.length);
    p.setDataPosition(0);

    Bundle result = p.readBundle();
    p.recycle();
    return result;
}
 
Example 4
Project: arca-android   File: ServiceErrorTest.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void testServiceErrorParcelableCreator() {
	final int code = 1;
	final String type = "type";
	final String message = "message";
	final ServiceError error = new ServiceError(code, type, message);

	final Parcel parcel = Parcel.obtain();
	error.writeToParcel(parcel, 0);
	parcel.setDataPosition(0);

	final ServiceError parceled = ServiceError.CREATOR.createFromParcel(parcel);
	assertEquals(code, parceled.getCode());
	assertEquals(type, parceled.getType());
	assertEquals(message, parceled.getMessage());

	parcel.recycle();
}
 
Example 5
Project: VirtualAPK   File: BookManagerImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void addBook(Book book) throws RemoteException {
    Parcel data = Parcel.obtain();
    Parcel reply = Parcel.obtain();
    try {
        data.writeInterfaceToken(DESCRIPTOR);
        if ((book != null)) {
            data.writeInt(1);
            book.writeToParcel(data, 0);
        } else {
            data.writeInt(0);
        }
        mRemote.transact(TRANSACTION_addBook, data, reply, 0);
        reply.readException();
    } finally {
        reply.recycle();
        data.recycle();
    }
}
 
Example 6
Project: Telegram-FOSS   File: ICustomTabsService.java    License: GNU General Public License v2.0 6 votes vote down vote up
public int postMessage(ICustomTabsCallback callback, String message, Bundle extras) throws RemoteException {
    Parcel _data = Parcel.obtain();
    Parcel _reply = Parcel.obtain();

    int _result;
    try {
        _data.writeInterfaceToken("android.support.customtabs.ICustomTabsService");
        _data.writeStrongBinder(callback != null?callback.asBinder():null);
        _data.writeString(message);
        if(extras != null) {
            _data.writeInt(1);
            extras.writeToParcel(_data, 0);
        } else {
            _data.writeInt(0);
        }

        this.mRemote.transact(8, _data, _reply, 0);
        _reply.readException();
        _result = _reply.readInt();
    } finally {
        _reply.recycle();
        _data.recycle();
    }

    return _result;
}
 
Example 7
Project: android_9.0.0_r45   File: ContentProviderNative.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public AssetFileDescriptor openAssetFile(
        String callingPkg, Uri url, String mode, ICancellationSignal signal)
        throws RemoteException, FileNotFoundException {
    Parcel data = Parcel.obtain();
    Parcel reply = Parcel.obtain();
    try {
        data.writeInterfaceToken(IContentProvider.descriptor);

        data.writeString(callingPkg);
        url.writeToParcel(data, 0);
        data.writeString(mode);
        data.writeStrongBinder(signal != null ? signal.asBinder() : null);

        mRemote.transact(IContentProvider.OPEN_ASSET_FILE_TRANSACTION, data, reply, 0);

        DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(reply);
        int has = reply.readInt();
        AssetFileDescriptor fd = has != 0
                ? AssetFileDescriptor.CREATOR.createFromParcel(reply) : null;
        return fd;
    } finally {
        data.recycle();
        reply.recycle();
    }
}
 
Example 8
Project: VirtualAPK   File: BookManagerImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public List<Book> getBookList() throws RemoteException {
    Parcel data = Parcel.obtain();
    Parcel reply = Parcel.obtain();
    List<Book> result;
    try {
        data.writeInterfaceToken(DESCRIPTOR);
        mRemote.transact(TRANSACTION_getBookList, data, reply, 0);
        reply.readException();
        result = reply.createTypedArrayList(Book.CREATOR);
    } finally {
        reply.recycle();
        data.recycle();
    }
    return result;
}
 
Example 9
Project: Telegram   File: ICustomTabsCallback.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void onPostMessage(String message, Bundle extras) throws RemoteException {
    Parcel _data = Parcel.obtain();
    Parcel _reply = Parcel.obtain();

    try {
        _data.writeInterfaceToken("android.support.customtabs.ICustomTabsCallback");
        _data.writeString(message);
        if(extras != null) {
            _data.writeInt(1);
            extras.writeToParcel(_data, 0);
        } else {
            _data.writeInt(0);
        }

        this.mRemote.transact(5, _data, _reply, 0);
        _reply.readException();
    } finally {
        _reply.recycle();
        _data.recycle();
    }

}
 
Example 10
Project: CSipSimple   File: SipCallSession.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Constructor by copy
 * @param callInfo
 */
public SipCallSession(SipCallSession callInfo) {
     Parcel p = Parcel.obtain();
     callInfo.writeToParcel(p, 0);
     p.setDataPosition(0);
     initFromParcel(p);
     p.recycle();
}
 
Example 11
Project: letv   File: ICdeBinder.java    License: Apache License 2.0 5 votes vote down vote up
public void setChannelSeekPosition(String url, double pos) throws RemoteException {
    Parcel _data = Parcel.obtain();
    Parcel _reply = Parcel.obtain();
    try {
        _data.writeInterfaceToken(Stub.DESCRIPTOR);
        _data.writeString(url);
        _data.writeDouble(pos);
        this.mRemote.transact(10, _data, _reply, 0);
        _reply.readException();
    } finally {
        _reply.recycle();
        _data.recycle();
    }
}
 
Example 12
Project: letv   File: EncryptListenerProxy.java    License: Apache License 2.0 5 votes vote down vote up
public void onEncryptStartedError(int errorCode) throws RemoteException {
    Parcel data = Parcel.obtain();
    Parcel reply = Parcel.obtain();
    try {
        data.writeInt(errorCode);
        this.mRemote.transact(2, data, reply, 0);
        reply.readException();
    } finally {
        data.recycle();
        reply.recycle();
    }
}
 
Example 13
Project: letv   File: INotificationSideChannel.java    License: Apache License 2.0 5 votes vote down vote up
public void cancel(String packageName, int id, String tag) throws RemoteException {
    Parcel _data = Parcel.obtain();
    try {
        _data.writeInterfaceToken(Stub.DESCRIPTOR);
        _data.writeString(packageName);
        _data.writeInt(id);
        _data.writeString(tag);
        this.mRemote.transact(2, _data, null, 1);
    } finally {
        _data.recycle();
    }
}
 
Example 14
Project: letv   File: IMediaSession.java    License: Apache License 2.0 5 votes vote down vote up
public void skipToQueueItem(long id) throws RemoteException {
    Parcel _data = Parcel.obtain();
    Parcel _reply = Parcel.obtain();
    try {
        _data.writeInterfaceToken(Stub.DESCRIPTOR);
        _data.writeLong(id);
        this.mRemote.transact(17, _data, _reply, 0);
        _reply.readException();
    } finally {
        _reply.recycle();
        _data.recycle();
    }
}
 
Example 15
Project: letv   File: IMediaSession.java    License: Apache License 2.0 5 votes vote down vote up
public void seekTo(long pos) throws RemoteException {
    Parcel _data = Parcel.obtain();
    Parcel _reply = Parcel.obtain();
    try {
        _data.writeInterfaceToken(Stub.DESCRIPTOR);
        _data.writeLong(pos);
        this.mRemote.transact(24, _data, _reply, 0);
        _reply.readException();
    } finally {
        _reply.recycle();
        _data.recycle();
    }
}
 
Example 16
Project: deltachat-android   File: ParcelUtil.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static byte[] serialize(Parcelable parceable) {
  Parcel parcel = Parcel.obtain();
  parceable.writeToParcel(parcel, 0);
  byte[] bytes = parcel.marshall();
  parcel.recycle();
  return bytes;
}
 
Example 17
Project: android_9.0.0_r45   File: ProcessStatsService.java    License: Apache License 2.0 5 votes vote down vote up
void performWriteState(long initialTime) {
    if (DEBUG) Slog.d(TAG, "Performing write to " + mFile.getBaseFile());
    Parcel data;
    AtomicFile file;
    synchronized (mPendingWriteLock) {
        data = mPendingWrite;
        file = mPendingWriteFile;
        mPendingWriteCommitted = false;
        if (data == null) {
            return;
        }
        mPendingWrite = null;
        mPendingWriteFile = null;
        mWriteLock.lock();
    }

    final long startTime = SystemClock.uptimeMillis();
    FileOutputStream stream = null;
    try {
        stream = file.startWrite();
        stream.write(data.marshall());
        stream.flush();
        file.finishWrite(stream);
        com.android.internal.logging.EventLogTags.writeCommitSysConfigFile(
                "procstats", SystemClock.uptimeMillis() - startTime + initialTime);
        if (DEBUG) Slog.d(TAG, "Write completed successfully!");
    } catch (IOException e) {
        Slog.w(TAG, "Error writing process statistics", e);
        file.failWrite(stream);
    } finally {
        data.recycle();
        trimHistoricStatesWriteLocked();
        mWriteLock.unlock();
    }
}
 
Example 18
Project: letv   File: IMediaSession.java    License: Apache License 2.0 5 votes vote down vote up
public void pause() throws RemoteException {
    Parcel _data = Parcel.obtain();
    Parcel _reply = Parcel.obtain();
    try {
        _data.writeInterfaceToken(Stub.DESCRIPTOR);
        this.mRemote.transact(18, _data, _reply, 0);
        _reply.readException();
    } finally {
        _reply.recycle();
        _data.recycle();
    }
}
 
Example 19
Project: android-test   File: SpeakEasyProtocol.java    License: Apache License 2.0 5 votes vote down vote up
/** Strips the custom subclass out of the ResultReceiver so you can ship between packages. */
private static ResultReceiver marshableReceiver(ResultReceiver r) {
  if (r.getClass().equals(ResultReceiver.class)) {
    return r;
  }
  Parcel p = Parcel.obtain();
  try {
    r.writeToParcel(p, 0);
    p.setDataPosition(0);
    return ResultReceiver.CREATOR.createFromParcel(p);
  } finally {
    p.recycle();
  }
}
 
Example 20
Project: sdl_java_suite   File: LocalRouterServiceTests.java    License: BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void corruptParcel(int testWith){
	Parcel p =  Parcel.obtain();
	p.writeInt(4);
	p.writeLong(System.currentTimeMillis());
	p.writeParcelable(new ComponentName(mContext, "test"), 0);
	p.writeParcelable(new Intent(), 0);
	p.setDataPosition(0);
	
	SdlRouterService.LocalRouterService local = getLocalRouterService(testWith, p);

	assertNotNull(local);
	assertNull(local.launchIntent);
	assertNull(local.name);
	
	p.recycle();
	//---------------------------------------------------------------------------
	
	p =  Parcel.obtain();
	p.writeInt(4);
	p.writeLong(System.currentTimeMillis());
	p.writeParcelable(null,0);
	p.writeParcelable(null,0);
	p.setDataPosition(0);
	
	local = getLocalRouterService(testWith, p);

	assertNotNull(local);
	assertNull(local.launchIntent);
	assertNull(local.name);
	
	p.recycle();
	//---------------------------------------------------------------------------
	
	p =  Parcel.obtain();
	p.writeInt(4);
	p.writeLong(System.currentTimeMillis());
	p.setDataPosition(0);
	
	local = getLocalRouterService(testWith, p);

	assertNotNull(local);
	assertNull(local.launchIntent);
	assertNull(local.name);
	
	p.recycle();
	
	//---------------------------------------------------------------------------
	local = null;
	p = null;
	
	p =  Parcel.obtain();
	p.writeInt(4);
	p.writeLong(System.currentTimeMillis());
	int space = p.dataSize();
	p.writeParcelable(new Intent(), 0);
	p.writeParcelable(new ComponentName(mContext, "test"), 0);
	p.setDataPosition(0);
	
	byte[] raw = p.marshall();
	for(;space<raw.length;space++){
		raw[space] = 0x00;
	}
	p.recycle();
	p = Parcel.obtain();
	p.unmarshall(raw, 0, raw.length);
	p.setDataPosition(0);
	
	
	local = getLocalRouterService(testWith, p);

	assertNotNull(local);
	assertNull(local.launchIntent);
	assertNull(local.name);
	
	p.recycle();
	
}