Search in sources :

Example 1 with IProxyCallback

use of com.android.net.IProxyCallback in project platform_frameworks_base by android.

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)

Example 2 with IProxyCallback

use of com.android.net.IProxyCallback in project android_frameworks_base by DirtyUnicorns.

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)

Example 3 with IProxyCallback

use of com.android.net.IProxyCallback 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)

Example 4 with IProxyCallback

use of com.android.net.IProxyCallback in project android_frameworks_base by AOSPA.

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)

Example 5 with IProxyCallback

use of com.android.net.IProxyCallback in project android_frameworks_base by crdroidandroid.

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

PendingIntent (android.app.PendingIntent)5 ComponentName (android.content.ComponentName)5 Intent (android.content.Intent)5 ServiceConnection (android.content.ServiceConnection)5 IBinder (android.os.IBinder)5 RemoteException (android.os.RemoteException)5 IProxyCallback (com.android.net.IProxyCallback)5