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

The following are Jave code examples for showing how to use recycle() 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: airgram   File: ICustomTabsCallback.java   View Source Code Vote up 6 votes
public void onNavigationEvent(int navigationEvent, Bundle extras) throws RemoteException {
    Parcel _data = Parcel.obtain();

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

        this.mRemote.transact(2, _data, null, 1);
    } finally {
        _data.recycle();
    }

}
 
Example 2
Project: airgram   File: ICustomTabsCallback.java   View Source Code Vote up 6 votes
public void extraCallback(String callbackName, Bundle args) throws RemoteException {
    Parcel _data = Parcel.obtain();

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

        this.mRemote.transact(3, _data, null, 1);
    } finally {
        _data.recycle();
    }

}
 
Example 3
Project: boohee_v5.6   File: br.java   View Source Code Vote up 6 votes
public boolean a(boolean z) throws RemoteException {
    boolean z2 = true;
    Parcel obtain = Parcel.obtain();
    Parcel obtain2 = Parcel.obtain();
    try {
        obtain.writeInterfaceToken("com.google.android.gms.ads.identifier.internal.IAdvertisingIdService");
        obtain.writeInt(z ? 1 : 0);
        this.a.transact(2, obtain, obtain2, 0);
        obtain2.readException();
        if (obtain2.readInt() == 0) {
            z2 = false;
        }
        obtain2.recycle();
        obtain.recycle();
        return z2;
    } catch (Throwable th) {
        obtain2.recycle();
        obtain.recycle();
    }
}
 
Example 4
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 5
Project: Cable-Android   File: MasterSecret.java   View Source Code Vote up 6 votes
public MasterSecret parcelClone() {
  Parcel thisParcel = Parcel.obtain();
  Parcel thatParcel = Parcel.obtain();
  byte[] bytes      = null;

  thisParcel.writeValue(this);
  bytes = thisParcel.marshall();

  thatParcel.unmarshall(bytes, 0, bytes.length);
  thatParcel.setDataPosition(0);

  MasterSecret that = (MasterSecret)thatParcel.readValue(MasterSecret.class.getClassLoader());

  thisParcel.recycle();
  thatParcel.recycle();

  return that;
}
 
Example 6
Project: boohee_v5.6   File: IMediaControllerCallback.java   View Source Code Vote up 6 votes
public void onEvent(String event, Bundle extras) throws RemoteException {
    Parcel _data = Parcel.obtain();
    try {
        _data.writeInterfaceToken(Stub.DESCRIPTOR);
        _data.writeString(event);
        if (extras != null) {
            _data.writeInt(1);
            extras.writeToParcel(_data, 0);
        } else {
            _data.writeInt(0);
        }
        this.mRemote.transact(1, _data, null, 1);
    } finally {
        _data.recycle();
    }
}
 
Example 7
Project: JobSchedulerCompat   File: GcmIntentParser.java   View Source Code Vote up 6 votes
/**
 * Checks whether {@link Parcel#readString()} or {@link Parcel#readValue(ClassLoader)} should be used to access
 * Bundle keys from a serialized Parcel. Commit https://android.googlesource.com/platform/frameworks/base/+
 * /9c3e74fI57bda9eb79ceaaa9c1b94ad49d9e462b52102149 (which only officially landed in Lollipop) changed from using
 * writeValue to writeString for Bundle keys. Some OEMs have pulled this change into their KitKat fork, so we can't
 * trust the SDK version check. Instead, we'll write a dummy Bundle to a Parcel and figure it out using that.
 *
 * The check is cached because the result doesn't change during runtime.
 */
private static synchronized boolean shouldReadKeysAsStrings() {
    // readString() should always be used on L+, but if the check is short-circuited there'd be no evidence that
    // this code is functioning correctly on KitKat devices that have the corresponding writeString() change.
    if (shouldReadKeysAsStrings == null) {
        Bundle testBundle = new Bundle();
        testBundle.putString("key", "value");
        Parcel testParcel = toParcel(testBundle);
        try {
            int entries = checkNonEmptyBundleHeader(testParcel);
            shouldReadKeysAsStrings = entries == 1 && "key".equals(testParcel.readString());
        } catch (RuntimeException e) {
            shouldReadKeysAsStrings = false;
        } finally {
            testParcel.recycle();
        }
    }

    return shouldReadKeysAsStrings;
}
 
Example 8
Project: letv   File: RemoteDeviceManager.java   View Source Code Vote up 6 votes
public int playMedia(String deviceId, Uri uri, int start) throws RemoteException {
    Parcel _data = Parcel.obtain();
    Parcel _reply = Parcel.obtain();
    int _result = 1;
    try {
        _data.writeInterfaceToken(Stub.DESCRIPTOR);
        _data.writeString(deviceId);
        if (uri != null) {
            _data.writeInt(1);
            uri.writeToParcel(_data, 0);
        } else {
            _data.writeInt(0);
        }
        _data.writeInt(start);
        this.mRemote.transact(13, _data, _reply, 0);
        ExceptionUtils.readExceptionFromParcel(_reply);
        _result = _reply.readInt();
        return _result;
    } finally {
        _reply.recycle();
        _data.recycle();
    }
}
 
Example 9
Project: airgram   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 10
Project: boohee_v5.6   File: IMediaSession.java   View Source Code Vote up 6 votes
public boolean isTransportControlEnabled() throws RemoteException {
    boolean _result = false;
    Parcel _data = Parcel.obtain();
    Parcel _reply = Parcel.obtain();
    try {
        _data.writeInterfaceToken(Stub.DESCRIPTOR);
        this.mRemote.transact(5, _data, _reply, 0);
        _reply.readException();
        if (_reply.readInt() != 0) {
            _result = true;
        }
        _reply.recycle();
        _data.recycle();
        return _result;
    } catch (Throwable th) {
        _reply.recycle();
        _data.recycle();
    }
}
 
Example 11
Project: HeadlineNews   File: CacheUtils.java   View Source Code Vote up 5 votes
private static <T> T bytes2Parcelable(final byte[] bytes, final Parcelable.Creator<T> creator) {
    if (bytes == null) return null;
    Parcel parcel = Parcel.obtain();
    parcel.unmarshall(bytes, 0, bytes.length);
    parcel.setDataPosition(0);
    T result = creator.createFromParcel(parcel);
    parcel.recycle();
    return result;
}
 
Example 12
Project: letv   File: EncryptListenerProxy.java   View Source Code Vote up 5 votes
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   View Source Code Vote up 5 votes
public void cancelAll(String packageName) throws RemoteException {
    Parcel _data = Parcel.obtain();
    try {
        _data.writeInterfaceToken(Stub.DESCRIPTOR);
        _data.writeString(packageName);
        this.mRemote.transact(3, _data, null, 1);
    } finally {
        _data.recycle();
    }
}
 
Example 14
Project: container   File: PendingIntentData.java   View Source Code Vote up 5 votes
public static PendingIntent readPendingIntent(IBinder binder) {
    Parcel parcel = Parcel.obtain();
    parcel.writeStrongBinder(binder);
    parcel.setDataPosition(0);
    try {
        return PendingIntent.readPendingIntentOrNullFromParcel(parcel);
    } finally {
        parcel.recycle();
    }
}
 
Example 15
Project: Nird2   File: AndroidSecureRandomProvider.java   View Source Code Vote up 5 votes
@Override
protected void writeToEntropyPool(DataOutputStream out) throws IOException {
	super.writeToEntropyPool(out);
	out.writeInt(android.os.Process.myPid());
	out.writeInt(android.os.Process.myTid());
	out.writeInt(android.os.Process.myUid());
	if (Build.FINGERPRINT != null) out.writeUTF(Build.FINGERPRINT);
	if (Build.SERIAL != null) out.writeUTF(Build.SERIAL);
	ContentResolver contentResolver = appContext.getContentResolver();
	String id = Settings.Secure.getString(contentResolver, ANDROID_ID);
	if (id != null) out.writeUTF(id);
	Parcel parcel = Parcel.obtain();
	WifiManager wm =
			(WifiManager) appContext.getSystemService(WIFI_SERVICE);
	List<WifiConfiguration> configs = wm.getConfiguredNetworks();
	if (configs != null) {
		for (WifiConfiguration config : configs)
			parcel.writeParcelable(config, 0);
	}
	BluetoothAdapter bt = BluetoothAdapter.getDefaultAdapter();
	if (bt != null) {
		for (BluetoothDevice device : bt.getBondedDevices())
			parcel.writeParcelable(device, 0);
	}
	out.write(parcel.marshall());
	parcel.recycle();
}
 
Example 16
Project: JobSchedulerCompat   File: GcmJobServiceTest.java   View Source Code Vote up 5 votes
private void executeService(int jobId) {
    Intent intent = new Intent(GcmJobService.ACTION_EXECUTE);
    intent.putExtra(GcmIntentParser.BUNDLE_KEY_TAG, String.valueOf(jobId));
    intent.putExtra(GcmIntentParser.BUNDLE_KEY_EXTRAS, Bundle.EMPTY);
    Parcel parcel = Parcel.obtain();
    try {
        parcel.writeStrongBinder(new Binder());
        parcel.setDataPosition(0);
        intent.putExtra(GcmIntentParser.BUNDLE_KEY_CALLBACK, new PendingCallback(parcel));
    } finally {
        parcel.recycle();
    }
    service.onStartCommand(intent, 0, 0);
}
 
Example 17
Project: letv   File: ICdeBinder.java   View Source Code Vote up 5 votes
public long getStateLastReceiveSpeed(String url) throws RemoteException {
    Parcel _data = Parcel.obtain();
    Parcel _reply = Parcel.obtain();
    try {
        _data.writeInterfaceToken(Stub.DESCRIPTOR);
        _data.writeString(url);
        this.mRemote.transact(5, _data, _reply, 0);
        _reply.readException();
        long _result = _reply.readLong();
        return _result;
    } finally {
        _reply.recycle();
        _data.recycle();
    }
}
 
Example 18
Project: AndroidUtilCode-master   File: CacheUtils.java   View Source Code Vote up 5 votes
private static <T> T bytes2Parcelable(byte[] bytes, Parcelable.Creator<T> creator) {
    if (bytes == null) return null;
    Parcel parcel = Parcel.obtain();
    parcel.unmarshall(bytes, 0, bytes.length);
    parcel.setDataPosition(0);
    T result = creator.createFromParcel(parcel);
    parcel.recycle();
    return result;
}
 
Example 19
Project: GravityBox   File: ProgressBarController.java   View Source Code Vote up 4 votes
private ProgressInfo getProgressInfo(String id, Notification n) {
    if (id == null || n == null) return null;

    ProgressInfo pInfo = new ProgressInfo(id, false, 0, 0);

    // We have to extract the information from the content view
    RemoteViews views = n.bigContentView;
    if (views == null) views = n.contentView;
    if (views == null) return pInfo;

    try {
        @SuppressWarnings("unchecked")
        List<Parcelable> actions = (List<Parcelable>) 
            XposedHelpers.getObjectField(views, "mActions");
        if (actions == null) return pInfo;

        for (Parcelable p : actions) {
            Parcel parcel = Parcel.obtain();
            p.writeToParcel(parcel, 0);
            parcel.setDataPosition(0);

            // The tag tells which type of action it is (2 is ReflectionAction)
            int tag = parcel.readInt();
            if (tag != 2)  {
                parcel.recycle();
                continue;
            }

            parcel.readInt(); // skip View ID
            String methodName = parcel.readString();
            if ("setMax".equals(methodName)) {
                parcel.readInt(); // skip type value
                pInfo.max = parcel.readInt();
                if (DEBUG) log("getProgressInfo: total=" + pInfo.max);
            } else if ("setProgress".equals(methodName)) {
                parcel.readInt(); // skip type value
                pInfo.progress = parcel.readInt();
                pInfo.hasProgressBar = true;
                if (DEBUG) log("getProgressInfo: current=" + pInfo.progress);
            }

            parcel.recycle();
        }
    } catch (Throwable  t) {
        XposedBridge.log(t);
    }

    return pInfo;
}
 
Example 20
Project: VirtualHook   File: VAccountManagerService.java   View Source Code Vote up 4 votes
/**
 * Read all accounts from file.
 */
private void readAllAccounts() {
	File accountFile = VEnvironment.getAccountConfigFile();
	refreshAuthenticatorCache(null);
	if (accountFile.exists()) {
		accountsByUserId.clear();
		Parcel dest = Parcel.obtain();
		try {
			FileInputStream is = new FileInputStream(accountFile);
			byte[] bytes = new byte[(int) accountFile.length()];
			int readLength = is.read(bytes);
			is.close();
			if (readLength != bytes.length) {
				throw new IOException(String.format(Locale.ENGLISH, "Expect length %d, but got %d.", bytes.length, readLength));
			}
			dest.unmarshall(bytes, 0, bytes.length);
			dest.setDataPosition(0);
			dest.readInt(); // skip the magic
			int size = dest.readInt(); // the VAccount's size we need to read
			boolean invalid = false;
			while (size-- > 0) {
				VAccount account = new VAccount(dest);
				VLog.d(TAG, "Reading account : " + account.type);
				AuthenticatorInfo info = cache.authenticators.get(account.type);
				if (info != null) {
					List<VAccount> accounts = accountsByUserId.get(account.userId);
					if (accounts == null) {
						accounts = new ArrayList<>();
						accountsByUserId.put(account.userId, accounts);
					}
					accounts.add(account);
				} else {
					invalid = true;
				}
			}
			lastAccountChangeTime = dest.readLong();
			if (invalid) {
				saveAllAccounts();
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			dest.recycle();
		}
	}
}