Java Code Examples for android.os.Parcel.obtain()

The following are Jave code examples for showing how to use obtain() of the android.os.Parcel class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: DroidIPC   File: ServiceManagerImpl.java   View Source Code Vote up 6 votes
private IBinder findService(String name){
	Parcel data = Parcel.obtain();
	data.writeString(name);
	Parcel reply = Parcel.obtain();
	try {
		mRemoteServiceManager.transact(ServiceContext.GET_SERVICE, data, reply, 0);
		IBinder service = reply.readStrongBinder();
		log("getService result binder = " + service);
		return service;
	} catch (RemoteException e) {
		e.printStackTrace();
		log("getService exception");
		return null;
	} finally {
		data.recycle();
		reply.recycle();
	}
}
 
Example 2
Project: airgram   File: ICustomTabsService.java   View Source Code Vote up 6 votes
public boolean newSession(ICustomTabsCallback callback) throws RemoteException {
    Parcel _data = Parcel.obtain();
    Parcel _reply = Parcel.obtain();

    boolean _result;
    try {
        _data.writeInterfaceToken("android.support.customtabs.ICustomTabsService");
        _data.writeStrongBinder(callback != null ? callback.asBinder() : null);
        this.mRemote.transact(3, _data, _reply, 0);
        _reply.readException();
        _result = 0 != _reply.readInt();
    } finally {
        _reply.recycle();
        _data.recycle();
    }

    return _result;
}
 
Example 3
Project: letv   File: IMediaSession.java   View Source Code Vote up 6 votes
public void playFromUri(Uri uri, Bundle extras) throws RemoteException {
    Parcel _data = Parcel.obtain();
    Parcel _reply = Parcel.obtain();
    try {
        _data.writeInterfaceToken(Stub.DESCRIPTOR);
        if (uri != null) {
            _data.writeInt(1);
            uri.writeToParcel(_data, 0);
        } else {
            _data.writeInt(0);
        }
        if (extras != null) {
            _data.writeInt(1);
            extras.writeToParcel(_data, 0);
        } else {
            _data.writeInt(0);
        }
        this.mRemote.transact(16, _data, _reply, 0);
        _reply.readException();
    } finally {
        _reply.recycle();
        _data.recycle();
    }
}
 
Example 4
Project: letv   File: IMediaSession.java   View Source Code Vote up 6 votes
public PlaybackStateCompat getPlaybackState() throws RemoteException {
    Parcel _data = Parcel.obtain();
    Parcel _reply = Parcel.obtain();
    try {
        PlaybackStateCompat _result;
        _data.writeInterfaceToken(Stub.DESCRIPTOR);
        this.mRemote.transact(28, _data, _reply, 0);
        _reply.readException();
        if (_reply.readInt() != 0) {
            _result = (PlaybackStateCompat) PlaybackStateCompat.CREATOR.createFromParcel(_reply);
        } else {
            _result = null;
        }
        _reply.recycle();
        _data.recycle();
        return _result;
    } catch (Throwable th) {
        _reply.recycle();
        _data.recycle();
    }
}
 
Example 5
Project: letv   File: RemoteDeviceManager.java   View Source Code Vote up 6 votes
public DeviceInfo getDeviceInfo(String deviceId) throws RemoteException {
    Parcel _data = Parcel.obtain();
    Parcel _reply = Parcel.obtain();
    try {
        DeviceInfo _result;
        _data.writeInterfaceToken(Stub.DESCRIPTOR);
        _data.writeString(deviceId);
        this.mRemote.transact(3, _data, _reply, 0);
        ExceptionUtils.readExceptionFromParcel(_reply);
        if (_reply.readInt() != 0) {
            _result = (DeviceInfo) DeviceInfo.CREATOR.createFromParcel(_reply);
        } else {
            _result = null;
        }
        _reply.recycle();
        _data.recycle();
        return _result;
    } catch (Throwable th) {
        _reply.recycle();
        _data.recycle();
    }
}
 
Example 6
Project: letv   File: IMediaSession.java   View Source Code Vote up 6 votes
public void sendCustomAction(String action, Bundle args) throws RemoteException {
    Parcel _data = Parcel.obtain();
    Parcel _reply = Parcel.obtain();
    try {
        _data.writeInterfaceToken(Stub.DESCRIPTOR);
        _data.writeString(action);
        if (args != null) {
            _data.writeInt(1);
            args.writeToParcel(_data, 0);
        } else {
            _data.writeInt(0);
        }
        this.mRemote.transact(26, _data, _reply, 0);
        _reply.readException();
    } finally {
        _reply.recycle();
        _data.recycle();
    }
}
 
Example 7
Project: PlusGram   File: ICustomTabsService.java   View Source Code Vote up 6 votes
public boolean warmup(long flags) throws RemoteException {
    Parcel _data = Parcel.obtain();
    Parcel _reply = Parcel.obtain();

    boolean _result;
    try {
        _data.writeInterfaceToken("android.support.customtabs.ICustomTabsService");
        _data.writeLong(flags);
        this.mRemote.transact(2, _data, _reply, 0);
        _reply.readException();
        _result = 0 != _reply.readInt();
    } finally {
        _reply.recycle();
        _data.recycle();
    }

    return _result;
}
 
Example 8
Project: OpenYOLO-Android   File: QueryResponseTest.java   View Source Code Vote up 5 votes
@Test
public void testWriteAndReadParcel() throws Exception {
    Parcel p = Parcel.obtain();
    p.writeParcelable(QUERY_RESPONSE, 0);
    p.setDataPosition(0);
    QueryResponse read = p.readParcelable(QueryResponse.class.getClassLoader());

    assertThat(read.responderPackage).isEqualTo(QUERY_RESPONSE.responderPackage);
    assertThat(read.responseId).isEqualTo(QUERY_RESPONSE.responseId);
    assertThat(read.responseMessage).isEqualTo(QUERY_RESPONSE.responseMessage);
}
 
Example 9
Project: LJFramework   File: CacheUtils.java   View Source Code Vote up 5 votes
private static byte[] parcelable2Bytes(final Parcelable parcelable) {
    if (parcelable == null) {
        return null;
    }
    Parcel parcel = Parcel.obtain();
    parcelable.writeToParcel(parcel, 0);
    byte[] bytes = parcel.marshall();
    parcel.recycle();
    return bytes;
}
 
Example 10
Project: TPlayer   File: PersistenceLayer.java   View Source Code Vote up 5 votes
public void save() {
    Parcel p = Parcel.obtain();
    try {
        writeMagic(p);
        p.writeInt(getCurrentVersion());
        writePersistenceData(p);
        FileOutputStream fos = new FileOutputStream(mPersistenceFile);
        fos.write(p.marshall());
        fos.close();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        p.recycle();
    }
}
 
Example 11
Project: AndroidUtilCode-master   File: CacheUtils.java   View Source Code Vote up 5 votes
private static byte[] parcelable2Bytes(Parcelable parcelable) {
    if (parcelable == null) return null;
    Parcel parcel = Parcel.obtain();
    parcelable.writeToParcel(parcel, 0);
    byte[] bytes = parcel.marshall();
    parcel.recycle();
    return bytes;
}
 
Example 12
Project: toolargetool   File: TooLargeTool.java   View Source Code Vote up 5 votes
/**
 * Measure the size of a typed {@link Bundle} when written to a {@link Parcel}.
 *
 * @param bundle to measure
 * @return size when written to parcel in bytes
 */
public static int sizeAsParcel(@NonNull Bundle bundle) {
    Parcel parcel = Parcel.obtain();
    try {
        parcel.writeBundle(bundle);
        return parcel.dataSize();
    } finally {
        parcel.recycle();
    }
}
 
Example 13
Project: GitHub   File: ParcelFn.java   View Source Code Vote up 5 votes
static byte[] marshall(Object o) {
    Parcel parcel = Parcel.obtain();
    parcel.writeValue(o);
    byte[] result = parcel.marshall();
    parcel.recycle();
    return result;
}
 
Example 14
Project: letv   File: IMediaSession.java   View Source Code Vote up 5 votes
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: boohee_v5.6   File: IMediaSession.java   View Source Code Vote up 5 votes
public void registerCallbackListener(IMediaControllerCallback cb) throws RemoteException {
    Parcel _data = Parcel.obtain();
    Parcel _reply = Parcel.obtain();
    try {
        _data.writeInterfaceToken(Stub.DESCRIPTOR);
        _data.writeStrongBinder(cb != null ? cb.asBinder() : null);
        this.mRemote.transact(3, _data, _reply, 0);
        _reply.readException();
    } finally {
        _reply.recycle();
        _data.recycle();
    }
}
 
Example 16
Project: tenor-android-core   File: AaidClient.java   View Source Code Vote up 5 votes
public String getId() throws RemoteException {
    Parcel data = Parcel.obtain();
    Parcel reply = Parcel.obtain();
    String id;
    try {
        data.writeInterfaceToken("com.google.android.gms.ads.identifier.internal.IAdvertisingIdService");
        mBinder.transact(1, data, reply, 0);
        reply.readException();
        id = reply.readString();
    } finally {
        reply.recycle();
        data.recycle();
    }
    return id;
}
 
Example 17
Project: boohee_v5.6   File: IMediaSession.java   View Source Code Vote up 5 votes
public void rewind() throws RemoteException {
    Parcel _data = Parcel.obtain();
    Parcel _reply = Parcel.obtain();
    try {
        _data.writeInterfaceToken(Stub.DESCRIPTOR);
        this.mRemote.transact(23, _data, _reply, 0);
        _reply.readException();
    } finally {
        _reply.recycle();
        _data.recycle();
    }
}
 
Example 18
Project: letv   File: RemoteDeviceManager.java   View Source Code Vote up 5 votes
public List<PackageInfo> getInstalledPackages(String deviceId) throws RemoteException {
    Parcel _data = Parcel.obtain();
    Parcel _reply = Parcel.obtain();
    try {
        _data.writeInterfaceToken(Stub.DESCRIPTOR);
        _data.writeString(deviceId);
        this.mRemote.transact(16, _data, _reply, 0);
        ExceptionUtils.readExceptionFromParcel(_reply);
        List<PackageInfo> _result = _reply.createTypedArrayList(PackageInfo.CREATOR);
        return _result;
    } finally {
        _reply.recycle();
        _data.recycle();
    }
}
 
Example 19
Project: boohee_v5.6   File: IMediaSession.java   View Source Code Vote up 5 votes
public void adjustVolume(int direction, int flags, String packageName) throws RemoteException {
    Parcel _data = Parcel.obtain();
    Parcel _reply = Parcel.obtain();
    try {
        _data.writeInterfaceToken(Stub.DESCRIPTOR);
        _data.writeInt(direction);
        _data.writeInt(flags);
        _data.writeString(packageName);
        this.mRemote.transact(11, _data, _reply, 0);
        _reply.readException();
    } finally {
        _reply.recycle();
        _data.recycle();
    }
}
 
Example 20
Project: nifi-android-s2s   File: SiteToSiteDB.java   View Source Code Vote up 4 votes
/**
 * Gets the peer status for a given url set and proxy
 *
 * @param siteToSiteClientConfig the config to get peer status for
 */
public void updatePeerStatusOnConfig(SiteToSiteClientConfig siteToSiteClientConfig) throws SQLiteIOException {
    SQLiteDatabase readableDatabase = sqLiteOpenHelper.getReadableDatabase();
    try {
        for (SiteToSiteRemoteCluster siteToSiteRemoteCluster : siteToSiteClientConfig.getRemoteClusters()) {
            PeerStatus origPeerStatus = siteToSiteRemoteCluster.getPeerStatus();

            List<String> parameters = new ArrayList<>();

            String peerUrlsString = getPeerUrlsString(siteToSiteRemoteCluster.getUrls());
            StringBuilder queryString = new StringBuilder(PEER_STATUS_URLS_COLUMN).append(" = ? AND ").append(PEER_STATUS_PROXY_HOST_COLUMN);
            parameters.add(peerUrlsString);

            String proxyHost = siteToSiteRemoteCluster.getProxyHost();
            if (proxyHost == null || proxyHost.isEmpty()) {
                queryString.append(" IS NULL AND ").append(PEER_STATUS_PROXY_PORT_COLUMN).append(" IS NULL");
            } else {
                queryString.append(" = ? AND ").append(PEER_STATUS_PROXY_PORT_COLUMN).append(" = ?");
                parameters.add(proxyHost);
                parameters.add(Integer.toString(siteToSiteRemoteCluster.getProxyPort()));
            }
            Cursor cursor;
            cursor = readableDatabase.query(false, PEER_STATUSES_TABLE_NAME, new String[]{CONTENT_COLUMN}, queryString.toString(),
                    parameters.toArray(new String[parameters.size()]), null, null, null, null);
            try {
                int contentIndex = cursor.getColumnIndexOrThrow(CONTENT_COLUMN);
                while (cursor.moveToNext()) {
                    byte[] bytes = cursor.getBlob(contentIndex);
                    Parcel parcel = Parcel.obtain();
                    parcel.unmarshall(bytes, 0, bytes.length);
                    parcel.setDataPosition(0);
                    PeerStatus dbPeerStatus = PeerStatus.CREATOR.createFromParcel(parcel);
                    if (dbPeerStatus != null && (origPeerStatus == null || origPeerStatus.getLastPeerUpdate() < dbPeerStatus.getLastPeerUpdate())) {
                        siteToSiteRemoteCluster.setPeerStatus(dbPeerStatus);
                        origPeerStatus = dbPeerStatus;
                    }
                }
            } finally {
                cursor.close();
            }
        }
    } catch (SQLiteException e) {
        throw new SQLiteIOException("Unable to read peer status from database.", e);
    } finally {
        readableDatabase.close();
    }
}