Search in sources :

Example 56 with RemoteException

use of android.os.RemoteException in project android_frameworks_base by ParanoidAndroid.

the class BroadcastReceiver method peekService.

/**
     * Provide a binder to an already-running service.  This method is synchronous
     * and will not start the target service if it is not present, so it is safe
     * to call from {@link #onReceive}.
     * 
     * @param myContext The Context that had been passed to {@link #onReceive(Context, Intent)}
     * @param service The Intent indicating the service you wish to use.  See {@link
     * Context#startService(Intent)} for more information.
     */
public IBinder peekService(Context myContext, Intent service) {
    IActivityManager am = ActivityManagerNative.getDefault();
    IBinder binder = null;
    try {
        service.prepareToLeaveProcess();
        binder = am.peekService(service, service.resolveTypeIfNeeded(myContext.getContentResolver()));
    } catch (RemoteException e) {
    }
    return binder;
}
Also used : IBinder(android.os.IBinder) RemoteException(android.os.RemoteException) IActivityManager(android.app.IActivityManager)

Example 57 with RemoteException

use of android.os.RemoteException in project android_frameworks_base by ParanoidAndroid.

the class ContentProviderProxy method query.

public Cursor query(String callingPkg, Uri url, String[] projection, String selection, String[] selectionArgs, String sortOrder, ICancellationSignal cancellationSignal) throws RemoteException {
    BulkCursorToCursorAdaptor adaptor = new BulkCursorToCursorAdaptor();
    Parcel data = Parcel.obtain();
    Parcel reply = Parcel.obtain();
    try {
        data.writeInterfaceToken(IContentProvider.descriptor);
        data.writeString(callingPkg);
        url.writeToParcel(data, 0);
        int length = 0;
        if (projection != null) {
            length = projection.length;
        }
        data.writeInt(length);
        for (int i = 0; i < length; i++) {
            data.writeString(projection[i]);
        }
        data.writeString(selection);
        if (selectionArgs != null) {
            length = selectionArgs.length;
        } else {
            length = 0;
        }
        data.writeInt(length);
        for (int i = 0; i < length; i++) {
            data.writeString(selectionArgs[i]);
        }
        data.writeString(sortOrder);
        data.writeStrongBinder(adaptor.getObserver().asBinder());
        data.writeStrongBinder(cancellationSignal != null ? cancellationSignal.asBinder() : null);
        mRemote.transact(IContentProvider.QUERY_TRANSACTION, data, reply, 0);
        DatabaseUtils.readExceptionFromParcel(reply);
        if (reply.readInt() != 0) {
            BulkCursorDescriptor d = BulkCursorDescriptor.CREATOR.createFromParcel(reply);
            adaptor.initialize(d);
        } else {
            adaptor.close();
            adaptor = null;
        }
        return adaptor;
    } catch (RemoteException ex) {
        adaptor.close();
        throw ex;
    } catch (RuntimeException ex) {
        adaptor.close();
        throw ex;
    } finally {
        data.recycle();
        reply.recycle();
    }
}
Also used : Parcel(android.os.Parcel) BulkCursorDescriptor(android.database.BulkCursorDescriptor) BulkCursorToCursorAdaptor(android.database.BulkCursorToCursorAdaptor) RemoteException(android.os.RemoteException)

Example 58 with RemoteException

use of android.os.RemoteException in project android_frameworks_base by ParanoidAndroid.

the class BluetoothGatt method writeDescriptor.

/**
     * Write the value of a given descriptor to the associated remote device.
     *
     * <p>A {@link BluetoothGattCallback#onDescriptorWrite} callback is
     * triggered to report the result of the write operation.
     *
     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
     *
     * @param descriptor Descriptor to write to the associated remote device
     * @return true, if the write operation was initiated successfully
     */
public boolean writeDescriptor(BluetoothGattDescriptor descriptor) {
    if (DBG)
        Log.d(TAG, "writeDescriptor() - uuid: " + descriptor.getUuid());
    if (mService == null || mClientIf == 0)
        return false;
    BluetoothGattCharacteristic characteristic = descriptor.getCharacteristic();
    if (characteristic == null)
        return false;
    BluetoothGattService service = characteristic.getService();
    if (service == null)
        return false;
    BluetoothDevice device = service.getDevice();
    if (device == null)
        return false;
    try {
        mService.writeDescriptor(mClientIf, device.getAddress(), service.getType(), service.getInstanceId(), new ParcelUuid(service.getUuid()), characteristic.getInstanceId(), new ParcelUuid(characteristic.getUuid()), new ParcelUuid(descriptor.getUuid()), characteristic.getWriteType(), AUTHENTICATION_NONE, descriptor.getValue());
    } catch (RemoteException e) {
        Log.e(TAG, "", e);
        return false;
    }
    return true;
}
Also used : ParcelUuid(android.os.ParcelUuid) BluetoothDevice(android.bluetooth.BluetoothDevice) RemoteException(android.os.RemoteException)

Example 59 with RemoteException

use of android.os.RemoteException in project android_frameworks_base by ParanoidAndroid.

the class BluetoothGatt method readCharacteristic.

/**
     * Reads the requested characteristic from the associated remote device.
     *
     * <p>This is an asynchronous operation. The result of the read operation
     * is reported by the {@link BluetoothGattCallback#onCharacteristicRead}
     * callback.
     *
     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
     *
     * @param characteristic Characteristic to read from the remote device
     * @return true, if the read operation was initiated successfully
     */
public boolean readCharacteristic(BluetoothGattCharacteristic characteristic) {
    if ((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_READ) == 0)
        return false;
    if (DBG)
        Log.d(TAG, "readCharacteristic() - uuid: " + characteristic.getUuid());
    if (mService == null || mClientIf == 0)
        return false;
    BluetoothGattService service = characteristic.getService();
    if (service == null)
        return false;
    BluetoothDevice device = service.getDevice();
    if (device == null)
        return false;
    try {
        mService.readCharacteristic(mClientIf, device.getAddress(), service.getType(), service.getInstanceId(), new ParcelUuid(service.getUuid()), characteristic.getInstanceId(), new ParcelUuid(characteristic.getUuid()), AUTHENTICATION_NONE);
    } catch (RemoteException e) {
        Log.e(TAG, "", e);
        return false;
    }
    return true;
}
Also used : ParcelUuid(android.os.ParcelUuid) BluetoothDevice(android.bluetooth.BluetoothDevice) RemoteException(android.os.RemoteException)

Example 60 with RemoteException

use of android.os.RemoteException in project android_frameworks_base by ParanoidAndroid.

the class BluetoothGattServer method addService.

/**
     * Add a service to the list of services to be hosted.
     *
     * <p>Once a service has been addded to the the list, the service and it's
     * included characteristics will be provided by the local device.
     *
     * <p>If the local device has already exposed services when this function
     * is called, a service update notification will be sent to all clients.
     *
     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
     *
     * @param service Service to be added to the list of services provided
     *                by this device.
     * @return true, if the service has been added successfully
     */
public boolean addService(BluetoothGattService service) {
    if (DBG)
        Log.d(TAG, "addService() - service: " + service.getUuid());
    if (mService == null || mServerIf == 0)
        return false;
    mServices.add(service);
    try {
        mService.beginServiceDeclaration(mServerIf, service.getType(), service.getInstanceId(), service.getHandles(), new ParcelUuid(service.getUuid()));
        List<BluetoothGattService> includedServices = service.getIncludedServices();
        for (BluetoothGattService includedService : includedServices) {
            mService.addIncludedService(mServerIf, includedService.getType(), includedService.getInstanceId(), new ParcelUuid(includedService.getUuid()));
        }
        List<BluetoothGattCharacteristic> characteristics = service.getCharacteristics();
        for (BluetoothGattCharacteristic characteristic : characteristics) {
            int permission = ((characteristic.getKeySize() - 7) << 12) + characteristic.getPermissions();
            mService.addCharacteristic(mServerIf, new ParcelUuid(characteristic.getUuid()), characteristic.getProperties(), permission);
            List<BluetoothGattDescriptor> descriptors = characteristic.getDescriptors();
            for (BluetoothGattDescriptor descriptor : descriptors) {
                permission = ((characteristic.getKeySize() - 7) << 12) + descriptor.getPermissions();
                mService.addDescriptor(mServerIf, new ParcelUuid(descriptor.getUuid()), permission);
            }
        }
        mService.endServiceDeclaration(mServerIf);
    } catch (RemoteException e) {
        Log.e(TAG, "", e);
        return false;
    }
    return true;
}
Also used : ParcelUuid(android.os.ParcelUuid) RemoteException(android.os.RemoteException)

Aggregations

RemoteException (android.os.RemoteException)4527 Intent (android.content.Intent)595 IBinder (android.os.IBinder)480 Bundle (android.os.Bundle)461 Point (android.graphics.Point)423 IOException (java.io.IOException)381 PendingIntent (android.app.PendingIntent)274 ComponentName (android.content.ComponentName)265 ArrayList (java.util.ArrayList)248 ApplicationInfo (android.content.pm.ApplicationInfo)190 IPackageManager (android.content.pm.IPackageManager)190 Message (android.os.Message)184 Uri (android.net.Uri)157 UserHandle (android.os.UserHandle)154 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)151 Cursor (android.database.Cursor)150 Configuration (android.content.res.Configuration)133 UserInfo (android.content.pm.UserInfo)129 AndroidRuntimeException (android.util.AndroidRuntimeException)128 ParcelFileDescriptor (android.os.ParcelFileDescriptor)126