Search in sources :

Example 1 with IBinder

use of android.os.IBinder in project AndroidTraining by mixi-inc.

the class SampleServiceTestCase method testBinding.

public void testBinding() throws Exception {
    // 開始するサービスの場合で、バインドをサポートしない場合は、bindService の返り値が null となるので、それをチェック
    IBinder binder = bindService(new Intent(getContext(), TestTargetService.class));
    assertNull(binder);
}
Also used : IBinder(android.os.IBinder) Intent(android.content.Intent) TestTargetService(jp.mixi.sample.test.TestTargetService)

Example 2 with IBinder

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

the class UsbPermissionActivity method onDestroy.

@Override
public void onDestroy() {
    IBinder b = ServiceManager.getService(USB_SERVICE);
    IUsbManager service = IUsbManager.Stub.asInterface(b);
    // send response via pending intent
    Intent intent = new Intent();
    try {
        if (mDevice != null) {
            intent.putExtra(UsbManager.EXTRA_DEVICE, mDevice);
            if (mPermissionGranted) {
                service.grantDevicePermission(mDevice, mUid);
                if (mAlwaysUse.isChecked()) {
                    final int userId = UserHandle.getUserId(mUid);
                    service.setDevicePackage(mDevice, mPackageName, userId);
                }
            }
        }
        if (mAccessory != null) {
            intent.putExtra(UsbManager.EXTRA_ACCESSORY, mAccessory);
            if (mPermissionGranted) {
                service.grantAccessoryPermission(mAccessory, mUid);
                if (mAlwaysUse.isChecked()) {
                    final int userId = UserHandle.getUserId(mUid);
                    service.setAccessoryPackage(mAccessory, mPackageName, userId);
                }
            }
        }
        intent.putExtra(UsbManager.EXTRA_PERMISSION_GRANTED, mPermissionGranted);
        mPendingIntent.send(this, 0, intent);
    } catch (PendingIntent.CanceledException e) {
        Log.w(TAG, "PendingIntent was cancelled");
    } catch (RemoteException e) {
        Log.e(TAG, "IUsbService connection failed", e);
    }
    if (mDisconnectedReceiver != null) {
        unregisterReceiver(mDisconnectedReceiver);
    }
    super.onDestroy();
}
Also used : IBinder(android.os.IBinder) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) RemoteException(android.os.RemoteException) IUsbManager(android.hardware.usb.IUsbManager)

Example 3 with IBinder

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

the class UsbConfirmActivity method onClick.

public void onClick(DialogInterface dialog, int which) {
    if (which == AlertDialog.BUTTON_POSITIVE) {
        try {
            IBinder b = ServiceManager.getService(USB_SERVICE);
            IUsbManager service = IUsbManager.Stub.asInterface(b);
            final int uid = mResolveInfo.activityInfo.applicationInfo.uid;
            final int userId = UserHandle.myUserId();
            boolean alwaysUse = mAlwaysUse.isChecked();
            Intent intent = null;
            if (mDevice != null) {
                intent = new Intent(UsbManager.ACTION_USB_DEVICE_ATTACHED);
                intent.putExtra(UsbManager.EXTRA_DEVICE, mDevice);
                // grant permission for the device
                service.grantDevicePermission(mDevice, uid);
                // set or clear default setting
                if (alwaysUse) {
                    service.setDevicePackage(mDevice, mResolveInfo.activityInfo.packageName, userId);
                } else {
                    service.setDevicePackage(mDevice, null, userId);
                }
            } else if (mAccessory != null) {
                intent = new Intent(UsbManager.ACTION_USB_ACCESSORY_ATTACHED);
                intent.putExtra(UsbManager.EXTRA_ACCESSORY, mAccessory);
                // grant permission for the accessory
                service.grantAccessoryPermission(mAccessory, uid);
                // set or clear default setting
                if (alwaysUse) {
                    service.setAccessoryPackage(mAccessory, mResolveInfo.activityInfo.packageName, userId);
                } else {
                    service.setAccessoryPackage(mAccessory, null, userId);
                }
            }
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.setComponent(new ComponentName(mResolveInfo.activityInfo.packageName, mResolveInfo.activityInfo.name));
            startActivityAsUser(intent, new UserHandle(userId));
        } catch (Exception e) {
            Log.e(TAG, "Unable to start activity", e);
        }
    }
    finish();
}
Also used : IBinder(android.os.IBinder) UserHandle(android.os.UserHandle) Intent(android.content.Intent) ComponentName(android.content.ComponentName) IUsbManager(android.hardware.usb.IUsbManager)

Example 4 with IBinder

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

the class PhoneWindowManager method takeScreenshot.

// Assume this is called from the Handler thread.
private void takeScreenshot() {
    synchronized (mScreenshotLock) {
        if (mScreenshotConnection != null) {
            return;
        }
        ComponentName cn = new ComponentName("com.android.systemui", "com.android.systemui.screenshot.TakeScreenshotService");
        Intent intent = new Intent();
        intent.setComponent(cn);
        ServiceConnection conn = new ServiceConnection() {

            @Override
            public void onServiceConnected(ComponentName name, IBinder service) {
                synchronized (mScreenshotLock) {
                    if (mScreenshotConnection != this) {
                        return;
                    }
                    Messenger messenger = new Messenger(service);
                    Message msg = Message.obtain(null, 1);
                    final ServiceConnection myConn = this;
                    Handler h = new Handler(mHandler.getLooper()) {

                        @Override
                        public void handleMessage(Message msg) {
                            synchronized (mScreenshotLock) {
                                if (mScreenshotConnection == myConn) {
                                    mContext.unbindService(mScreenshotConnection);
                                    mScreenshotConnection = null;
                                    mHandler.removeCallbacks(mScreenshotTimeout);
                                }
                            }
                        }
                    };
                    msg.replyTo = new Messenger(h);
                    msg.arg1 = msg.arg2 = 0;
                    if (mStatusBar != null && mStatusBar.isVisibleLw())
                        msg.arg1 = 1;
                    if (mNavigationBar != null && mNavigationBar.isVisibleLw())
                        msg.arg2 = 1;
                    try {
                        messenger.send(msg);
                    } catch (RemoteException e) {
                    }
                }
            }

            @Override
            public void onServiceDisconnected(ComponentName name) {
            }
        };
        if (mContext.bindServiceAsUser(intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
            mScreenshotConnection = conn;
            mHandler.postDelayed(mScreenshotTimeout, 10000);
        }
    }
}
Also used : ServiceConnection(android.content.ServiceConnection) IBinder(android.os.IBinder) Message(android.os.Message) Handler(android.os.Handler) DeviceKeyHandler(com.android.internal.os.DeviceKeyHandler) ComponentName(android.content.ComponentName) Intent(android.content.Intent) Messenger(android.os.Messenger) RemoteException(android.os.RemoteException)

Example 5 with IBinder

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

the class FaceUnlock method handleServiceConnected.

/**
     * Tells the service to start its UI via an AIDL interface.  Called when the
     * onServiceConnected() callback is received.
     */
void handleServiceConnected() {
    Log.d(TAG, "handleServiceConnected()");
    // onServiceConnected() rather than using a handler.
    if (!mBoundToService) {
        Log.d(TAG, "Dropping startUi() in handleServiceConnected() because no longer bound");
        return;
    }
    try {
        mService.registerCallback(mFaceUnlockCallback);
    } catch (RemoteException e) {
        Log.e(TAG, "Caught exception connecting to Face Unlock: " + e.toString());
        mService = null;
        mBoundToService = false;
        mIsRunning = false;
        return;
    }
    if (mFaceUnlockView != null) {
        IBinder windowToken = mFaceUnlockView.getWindowToken();
        if (windowToken != null) {
            // When switching between portrait and landscape view while Face Unlock is running,
            // the screen will eventually go dark unless we poke the wakelock when Face Unlock
            // is restarted.
            mKeyguardScreenCallback.userActivity(0);
            int[] position;
            position = new int[2];
            mFaceUnlockView.getLocationInWindow(position);
            startUi(windowToken, position[0], position[1], mFaceUnlockView.getWidth(), mFaceUnlockView.getHeight());
        } else {
            Log.e(TAG, "windowToken is null in handleServiceConnected()");
        }
    }
}
Also used : IBinder(android.os.IBinder) RemoteException(android.os.RemoteException)

Aggregations

IBinder (android.os.IBinder)1139 RemoteException (android.os.RemoteException)553 Intent (android.content.Intent)186 ComponentName (android.content.ComponentName)166 ServiceConnection (android.content.ServiceConnection)127 Parcel (android.os.Parcel)112 PendingIntent (android.app.PendingIntent)69 Point (android.graphics.Point)67 Bundle (android.os.Bundle)56 IOException (java.io.IOException)53 UserHandle (android.os.UserHandle)50 Binder (android.os.Binder)47 Message (android.os.Message)37 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)35 Handler (android.os.Handler)33 AndroidRuntimeException (android.util.AndroidRuntimeException)33 ArrayList (java.util.ArrayList)30 IUsbManager (android.hardware.usb.IUsbManager)29 Context (android.content.Context)28 Messenger (android.os.Messenger)26