Search in sources :

Example 31 with ServiceConnection

use of android.content.ServiceConnection in project android_frameworks_base by ResurrectionRemix.

the class PhoneWindowManager method takeScreenrecord.

// Assume this is called from the Handler thread.
private void takeScreenrecord() {
    synchronized (mScreenrecordLock) {
        if (mScreenrecordConnection != null) {
            return;
        }
        ComponentName cn = new ComponentName("com.android.systemui", "com.android.systemui.omni.screenrecord.TakeScreenrecordService");
        Intent intent = new Intent();
        intent.setComponent(cn);
        ServiceConnection conn = new ServiceConnection() {

            @Override
            public void onServiceConnected(ComponentName name, IBinder service) {
                synchronized (mScreenrecordLock) {
                    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 (mScreenrecordLock) {
                                if (mScreenrecordConnection == myConn) {
                                    mContext.unbindService(mScreenrecordConnection);
                                    mScreenrecordConnection = null;
                                    mHandler.removeCallbacks(mScreenrecordTimeout);
                                }
                            }
                        }
                    };
                    msg.replyTo = new Messenger(h);
                    msg.arg1 = msg.arg2 = 0;
                    try {
                        messenger.send(msg);
                    } catch (RemoteException e) {
                    }
                }
            }

            @Override
            public void onServiceDisconnected(ComponentName name) {
            }
        };
        if (mContext.bindServiceAsUser(intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
            mScreenrecordConnection = conn;
            // Screenrecord max duration is 30 minutes. Allow 31 minutes before killing
            // the service.
            mHandler.postDelayed(mScreenrecordTimeout, 31 * 60 * 1000);
        }
    }
}
Also used : ServiceConnection(android.content.ServiceConnection) IBinder(android.os.IBinder) Message(android.os.Message) ActionHandler(com.android.internal.utils.du.ActionHandler) Handler(android.os.Handler) DeviceKeyHandler(com.android.internal.os.DeviceKeyHandler) ComponentName(android.content.ComponentName) Intent(android.content.Intent) RecognizerIntent(android.speech.RecognizerIntent) Messenger(android.os.Messenger) RemoteException(android.os.RemoteException)

Example 32 with ServiceConnection

use of android.content.ServiceConnection in project android_frameworks_base by ResurrectionRemix.

the class GlobalActions method takeScreenrecord.

private void takeScreenrecord() {
    synchronized (mScreenrecordLock) {
        if (mScreenrecordConnection != null) {
            return;
        }
        ComponentName cn = new ComponentName("com.android.systemui", "com.android.systemui.omni.screenrecord.TakeScreenrecordService");
        Intent intent = new Intent();
        intent.setComponent(cn);
        ServiceConnection conn = new ServiceConnection() {

            @Override
            public void onServiceConnected(ComponentName name, IBinder service) {
                synchronized (mScreenrecordLock) {
                    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 (mScreenrecordLock) {
                                if (mScreenrecordConnection == myConn) {
                                    mContext.unbindService(mScreenrecordConnection);
                                    mScreenrecordConnection = null;
                                    mHandler.removeCallbacks(mScreenrecordTimeout);
                                }
                            }
                        }
                    };
                    msg.replyTo = new Messenger(h);
                    msg.arg1 = msg.arg2 = 0;
                    try {
                        messenger.send(msg);
                    } catch (RemoteException e) {
                    }
                }
            }

            @Override
            public void onServiceDisconnected(ComponentName name) {
            }
        };
        if (mContext.bindServiceAsUser(intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
            mScreenrecordConnection = conn;
            mHandler.postDelayed(mScreenrecordTimeout, 31 * 60 * 1000);
        }
    }
}
Also used : ServiceConnection(android.content.ServiceConnection) IBinder(android.os.IBinder) Message(android.os.Message) Handler(android.os.Handler) ComponentName(android.content.ComponentName) Intent(android.content.Intent) Messenger(android.os.Messenger) RemoteException(android.os.RemoteException)

Example 33 with ServiceConnection

use of android.content.ServiceConnection in project android_frameworks_base by ResurrectionRemix.

the class ScreenshotTile method takeScreenshot.

private void takeScreenshot(final int screenshotType) {
    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, screenshotType);
                    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;
                    // Take the screenshot
                    try {
                        messenger.send(msg);
                    } catch (RemoteException e) {
                    // Do nothing here
                    }
                }
            }

            @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) ComponentName(android.content.ComponentName) Intent(android.content.Intent) Messenger(android.os.Messenger) RemoteException(android.os.RemoteException)

Example 34 with ServiceConnection

use of android.content.ServiceConnection in project RSAndroidApp by RailwayStations.

the class MainActivity method bindToStatus.

private void bindToStatus() {
    Intent intent = new Intent(this, NearbyNotificationService.class);
    intent.setAction(NearbyNotificationService.STATUS_INTERFACE);
    if (!this.getApplicationContext().bindService(intent, new ServiceConnection() {

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            Log.d(TAG, "Bound to status service of NearbyNotificationService");
            statusBinder = (NearbyNotificationService.StatusBinder) service;
            invalidateOptionsMenu();
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
            Log.d(TAG, "Unbound from status service of NearbyNotificationService");
            statusBinder = null;
        }
    }, 0))
        Log.e(TAG, "Bind request to statistics interface failed");
}
Also used : ServiceConnection(android.content.ServiceConnection) IBinder(android.os.IBinder) Intent(android.content.Intent) ComponentName(android.content.ComponentName)

Example 35 with ServiceConnection

use of android.content.ServiceConnection in project android_frameworks_base by ResurrectionRemix.

the class PacManager method bind.

private void bind() {
    if (mContext == null) {
        Log.e(TAG, "No context for binding");
        return;
    }
    Intent intent = new Intent();
    intent.setClassName(PAC_PACKAGE, PAC_SERVICE);
    if ((mProxyConnection != null) && (mConnection != null)) {
        // Already bound no need to bind again, just download the new file.
        mNetThreadHandler.post(mPacDownloader);
        return;
    }
    mConnection = new ServiceConnection() {

        @Override
        public void onServiceDisconnected(ComponentName component) {
            synchronized (mProxyLock) {
                mProxyService = null;
            }
        }

        @Override
        public void onServiceConnected(ComponentName component, IBinder binder) {
            synchronized (mProxyLock) {
                try {
                    Log.d(TAG, "Adding service " + PAC_SERVICE_NAME + " " + binder.getInterfaceDescriptor());
                } catch (RemoteException e1) {
                    Log.e(TAG, "Remote Exception", e1);
                }
                ServiceManager.addService(PAC_SERVICE_NAME, binder);
                mProxyService = IProxyService.Stub.asInterface(binder);
                if (mProxyService == null) {
                    Log.e(TAG, "No proxy service");
                } else {
                    try {
                        mProxyService.startPacSystem();
                    } catch (RemoteException e) {
                        Log.e(TAG, "Unable to reach ProxyService - PAC will not be started", e);
                    }
                    mNetThreadHandler.post(mPacDownloader);
                }
            }
        }
    };
    mContext.bindService(intent, mConnection, Context.BIND_AUTO_CREATE | Context.BIND_NOT_FOREGROUND | Context.BIND_NOT_VISIBLE);
    intent = new Intent();
    intent.setClassName(PROXY_PACKAGE, PROXY_SERVICE);
    mProxyConnection = new ServiceConnection() {

        @Override
        public void onServiceDisconnected(ComponentName component) {
        }

        @Override
        public void onServiceConnected(ComponentName component, IBinder binder) {
            IProxyCallback callbackService = IProxyCallback.Stub.asInterface(binder);
            if (callbackService != null) {
                try {
                    callbackService.getProxyPort(new IProxyPortListener.Stub() {

                        @Override
                        public void setProxyPort(int port) throws RemoteException {
                            if (mLastPort != -1) {
                                // Always need to send if port changed
                                mHasSentBroadcast = false;
                            }
                            mLastPort = port;
                            if (port != -1) {
                                Log.d(TAG, "Local proxy is bound on " + port);
                                sendProxyIfNeeded();
                            } else {
                                Log.e(TAG, "Received invalid port from Local Proxy," + " PAC will not be operational");
                            }
                        }
                    });
                } catch (RemoteException e) {
                    e.printStackTrace();
                }
            }
        }
    };
    mContext.bindService(intent, mProxyConnection, Context.BIND_AUTO_CREATE | Context.BIND_NOT_FOREGROUND | Context.BIND_NOT_VISIBLE);
}
Also used : ServiceConnection(android.content.ServiceConnection) IBinder(android.os.IBinder) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) ComponentName(android.content.ComponentName) IProxyCallback(com.android.net.IProxyCallback) RemoteException(android.os.RemoteException)

Aggregations

ServiceConnection (android.content.ServiceConnection)122 ComponentName (android.content.ComponentName)95 Intent (android.content.Intent)95 IBinder (android.os.IBinder)94 RemoteException (android.os.RemoteException)75 PendingIntent (android.app.PendingIntent)46 UserHandle (android.os.UserHandle)23 Handler (android.os.Handler)20 Message (android.os.Message)19 Messenger (android.os.Messenger)19 IRemoteViewsFactory (com.android.internal.widget.IRemoteViewsFactory)12 IInterface (android.os.IInterface)9 ResolveInfo (android.content.pm.ResolveInfo)8 IntentFilter (android.content.IntentFilter)7 Point (android.graphics.Point)7 AndroidRuntimeException (android.util.AndroidRuntimeException)7 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)7 Test (org.junit.Test)7 FilterComparison (android.content.Intent.FilterComparison)6 ReceiverCallNotAllowedException (android.content.ReceiverCallNotAllowedException)6