Java 类android.content.ServiceConnection 实例源码

项目:boohee_v5.6    文件:br.java   
private static a b(Context context) throws Exception {
    try {
        context.getPackageManager().getPackageInfo("com.android.vending", 0);
        ServiceConnection bVar = new b();
        Intent intent = new Intent("com.google.android.gms.ads.identifier.service.START");
        intent.setPackage("com.google.android.gms");
        if (context.bindService(intent, bVar, 1)) {
            try {
                c cVar = new c(bVar.a());
                a aVar = new a(cVar.a(), cVar.a(true));
                context.unbindService(bVar);
                return aVar;
            } catch (Exception e) {
                throw e;
            } catch (Throwable th) {
                context.unbindService(bVar);
            }
        } else {
            throw new IOException("Google Play connection failed");
        }
    } catch (Exception e2) {
        throw e2;
    }
}
项目:springreplugin    文件:PluginServiceDispatcherManager.java   
public ServiceDispatcher get(ServiceConnection c, Context context, Handler handler, int flags, int process) {
    synchronized (SERVICES_LOCKER) {
        ServiceDispatcher sd = null;
        ArrayMap<ServiceConnection, ServiceDispatcher> map = mServices.get(context);
        if (map != null) {
            sd = map.get(c);
        }
        if (sd == null) {
            sd = new ServiceDispatcher(c, context, handler, flags, process);
            if (map == null) {
                map = new ArrayMap<>();
                mServices.put(context, map);
            }
            map.put(c, sd);
        } else {
            sd.validate(context, handler);
        }
        return sd;
    }
}
项目:springreplugin    文件:PluginContext.java   
@Override
public void unbindService(ServiceConnection conn) {
    if (mLoader.mPluginObj.mInfo.getFrameworkVersion() <= 2) {
        // 仅框架版本为3及以上的才支持
        super.unbindService(conn);
        return;
    }
    // 先走一遍系统的逻辑
    try {
        super.unbindService(conn);
    } catch (Throwable e) {
        // Ignore
    }
    // 再走插件的unbindService
    // NOTE 由于不应重新调用context.unbind命令,故传进去的是false
    PluginServiceClient.unbindService(this, conn, false);
}
项目:DroidPlugin    文件:PluginManager.java   
@Override
public void onServiceDisconnected(ComponentName componentName) {
    Log.i(TAG, "onServiceDisconnected disconnected!");
    mPluginManager = null;

    Iterator<WeakReference<ServiceConnection>> iterator = sServiceConnection.iterator();
    while (iterator.hasNext()) {
        WeakReference<ServiceConnection> wsc = iterator.next();
        ServiceConnection sc = wsc != null ? wsc.get() : null;
        if (sc != null) {
            sc.onServiceDisconnected(componentName);
        } else {
            iterator.remove();
        }
    }
    //服务连接断开,需要重新连接。
    connectToService();
}
项目:boohee_v5.6    文件:ServiceChecker.java   
public static boolean isServiceSupport(Context context) {
    Intent intent = ServiceTalker.getAuthServiceIntent();
    ServiceConnection serviceConnection = new EmptyServiceConnection();
    boolean binded = context.bindService(intent, serviceConnection, 1);
    context.unbindService(serviceConnection);
    return binded;
}
项目:TPlayer    文件:ServiceConnectionDelegate.java   
public static IServiceConnection getDelegate(Context context, ServiceConnection connection,int flags) {
    IServiceConnection sd = null;
    if (connection == null) {
        throw new IllegalArgumentException("connection is null");
    }
    try {
        Object activityThread = ActivityThread.currentActivityThread.call();
        Object loadApk = ContextImpl.mPackageInfo.get(VirtualCore.get().getContext());
        Handler handler = ActivityThread.getHandler.call(activityThread);
        sd = LoadedApk.getServiceDispatcher.call(loadApk, connection, context, handler, flags);
    } catch (Exception e) {
        Log.e("ConnectionDelegate", "getServiceDispatcher", e);
    }
    if (sd == null) {
        throw new RuntimeException("Not supported in system context");
    }
    return getDelegate(sd);
}
项目:ThunderMusic    文件:MusicUtils.java   
public static ServiceToken bindToService(Activity context,
                                         ServiceConnection callback) {
    Activity realActivity = context.getParent();
    if (realActivity == null) {
        realActivity = context;
    }
    ContextWrapper cw = new ContextWrapper(realActivity);
    cw.startService(new Intent(cw, MediaPlaybackService.class));
    ServiceBinder sb = new ServiceBinder(callback);
    if (cw.bindService(
            (new Intent()).setClass(cw, MediaPlaybackService.class), sb, 0)) {
        sConnectionMap.put(cw, sb);
        return new ServiceToken(cw);
    }
    return null;
}
项目:Phoenix-for-VK    文件:UploadUtils.java   
/**
 * @param context  The {@link Context} to use
 * @param callback The {@link ServiceConnection} to use
 * @return The new instance of {@link ServiceToken}
 */
public static ServiceToken bindToService(final Context context, final ServiceConnection callback) {
    ContextWrapper contextWrapper = new ContextWrapper(context);
    ServiceBinder binder = new ServiceBinder(callback);
    Intent intent = new Intent().setClass(contextWrapper, UploadService.class);

    if (contextWrapper.bindService(intent, binder, 0)) {
        mConnectionMap.put(contextWrapper, binder);
        return new ServiceToken(contextWrapper);
    }

    Logger.d(TAG, "bindToService, count: " + mConnectionMap.size());
    return null;
}
项目:Phoenix-for-VK    文件:MusicUtils.java   
public static ServiceToken bindToServiceWithoutStart(final Activity realActivity, final ServiceConnection callback) {
    final ContextWrapper contextWrapper = new ContextWrapper(realActivity);
    final ServiceBinder binder = new ServiceBinder(callback);

    if (contextWrapper.bindService(new Intent().setClass(contextWrapper, MusicPlaybackService.class), binder, 0)) {
        mConnectionMap.put(contextWrapper, binder);
        return new ServiceToken(contextWrapper);
    }

    return null;
}
项目:MiPushFramework    文件:CondomContext.java   
@Override public boolean bindService(final Intent intent, final ServiceConnection conn, final int flags) {
    final boolean result = mCondom.proceed(OutboundType.BIND_SERVICE, intent, Boolean.FALSE, new CondomCore.WrappedValueProcedure<Boolean>() { @Override public Boolean proceed() {
        return CondomContext.super.bindService(intent, conn, flags);
    }});
    if (result) mCondom.logIfOutboundPass(TAG, intent, CondomCore.getTargetPackage(intent), CondomCore.CondomEvent.BIND_PASS);
    return result;
}
项目:Chidori    文件:ChidoriClient.java   
private void disconnect(final ServiceConnection serviceConnection) {
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            synchronized (ChidoriClient.this) {
                try {
                    if (ApplicationHolder.getAppContext() != null && serviceConnection != null) {
                        ApplicationHolder.getAppContext().unbindService(serviceConnection);
                    }
                } catch (Exception e) {
                }
            }
        }
    }, FIVE_MINUTES);
}
项目:mapbox-events-android    文件:TelemetryServiceTest.java   
@Test
public void checksLocationReceiverIsUpWhenServiceStarted() throws Exception {
  Intent serviceIntent = new Intent(InstrumentationRegistry.getTargetContext(), TelemetryService.class);
  final TelemetryService[] boundService = new TelemetryService[1];
  final CountDownLatch latchConnected = new CountDownLatch(1);
  ServiceConnection serviceConnection = setupServiceConnection(boundService, latchConnected);

  startService(serviceIntent);
  waitUntilServiceIsBound(serviceIntent, latchConnected, serviceConnection);

  assertLocationReceiverRegistered(boundService);
}
项目:mapbox-events-android    文件:TelemetryServiceTest.java   
@Test
public void checksTelemetryReceiverIsUpWhenServiceStarted() throws Exception {
  Intent serviceIntent = new Intent(InstrumentationRegistry.getTargetContext(), TelemetryService.class);
  final TelemetryService[] boundService = new TelemetryService[1];
  final CountDownLatch latchConnected = new CountDownLatch(1);
  ServiceConnection serviceConnection = setupServiceConnection(boundService, latchConnected);

  startService(serviceIntent);
  waitUntilServiceIsBound(serviceIntent, latchConnected, serviceConnection);

  assertTelemetryReceiverRegistered(boundService);
}
项目:mapbox-events-android    文件:TelemetryServiceTest.java   
@Test
public void checksLocationReceiverIsDownWhenServiceStopped() throws Exception {
  Intent serviceIntent = new Intent(InstrumentationRegistry.getTargetContext(), TelemetryService.class);
  final TelemetryService[] boundService = new TelemetryService[1];
  final CountDownLatch latchConnected = new CountDownLatch(1);
  ServiceConnection serviceConnection = setupServiceConnection(boundService, latchConnected);
  startService(serviceIntent);
  waitUntilServiceIsBound(serviceIntent, latchConnected, serviceConnection);

  stopService(serviceIntent, boundService);
  waitUntilServiceIsDestroyed();

  assertLocationReceiverNotRegistered(boundService);
}
项目:mapbox-events-android    文件:TelemetryServiceTest.java   
@Test
public void checksTelemetryReceiverIsDownWhenServiceStopped() throws Exception {
  Intent serviceIntent = new Intent(InstrumentationRegistry.getTargetContext(), TelemetryService.class);
  final TelemetryService[] boundService = new TelemetryService[1];
  final CountDownLatch latchConnected = new CountDownLatch(1);
  ServiceConnection serviceConnection = setupServiceConnection(boundService, latchConnected);
  startService(serviceIntent);
  waitUntilServiceIsBound(serviceIntent, latchConnected, serviceConnection);

  stopService(serviceIntent, boundService);
  waitUntilServiceIsDestroyed();

  assertTelemetryReceiverNotRegistered(boundService);
}
项目:mapbox-events-android    文件:TelemetryServiceTest.java   
@Test
public void checksLocationReceiverIsDownWhenOnBackgroundCalled() throws Exception {
  Intent serviceIntent = new Intent(InstrumentationRegistry.getTargetContext(), TelemetryService.class);
  final TelemetryService[] boundService = new TelemetryService[1];
  final CountDownLatch latchConnected = new CountDownLatch(1);
  ServiceConnection serviceConnection = setupServiceConnection(boundService, latchConnected);
  startService(serviceIntent);
  waitUntilServiceIsBound(serviceIntent, latchConnected, serviceConnection);

  backgroundService(boundService);

  assertLocationReceiverNotRegistered(boundService);
}
项目:mapbox-events-android    文件:TelemetryServiceTest.java   
@Test
public void checksTelemetryReceiverIsUpWhenOnForegroundCalled() throws Exception {
  Intent serviceIntent = new Intent(InstrumentationRegistry.getTargetContext(), TelemetryService.class);
  final TelemetryService[] boundService = new TelemetryService[1];
  final CountDownLatch latchConnected = new CountDownLatch(1);
  ServiceConnection serviceConnection = setupServiceConnection(boundService, latchConnected);
  startService(serviceIntent);
  waitUntilServiceIsBound(serviceIntent, latchConnected, serviceConnection);
  backgroundService(boundService);

  foregroundService(boundService);

  assertLocationReceiverRegistered(boundService);
}
项目:mapbox-events-android    文件:TelemetryServiceTest.java   
@Test
public void checksOnTaskRemovedCallbackWhenOnTaskRemovedCalled() throws Exception {
  Intent serviceIntent = new Intent(InstrumentationRegistry.getTargetContext(), TelemetryService.class);
  final TelemetryService[] boundService = new TelemetryService[1];
  final CountDownLatch latchConnected = new CountDownLatch(1);
  ServiceConnection serviceConnection = setupServiceConnection(boundService, latchConnected);
  startService(serviceIntent);
  waitUntilServiceIsBound(serviceIntent, latchConnected, serviceConnection);
  ServiceTaskCallback mockedCallback = mock(ServiceTaskCallback.class);
  boundService[0].injectServiceTask(mockedCallback);

  boundService[0].onTaskRemoved(serviceIntent);

  verify(mockedCallback, times(1)).onTaskRemoved();
}
项目:chromium-for-android-56-debug-video    文件:ClientManager.java   
/** Unbind from the KeepAlive service for a client. */
public synchronized void dontKeepAliveForSession(CustomTabsSessionToken session) {
    SessionParams params = mSessionParams.get(session);
    if (params == null || params.getKeepAliveConnection() == null) return;
    ServiceConnection connection = params.getKeepAliveConnection();
    params.setKeepAliveConnection(null);
    mContext.unbindService(connection);
}
项目:letv    文件:ApkManager.java   
public void removeServiceConnection(ServiceConnection sc) {
    Iterator<WeakReference<ServiceConnection>> iterator = this.sServiceConnection.iterator();
    while (iterator.hasNext()) {
        if (((WeakReference) iterator.next()).get() == sc) {
            iterator.remove();
        }
    }
}
项目:letv    文件:MediaBrowserCompat.java   
public void connect() {
    if (this.mState != 0) {
        throw new IllegalStateException("connect() called while not disconnected (state=" + getStateLabel(this.mState) + ")");
    } else if (this.mServiceBinderWrapper != null) {
        throw new RuntimeException("mServiceBinderWrapper should be null. Instead it is " + this.mServiceBinderWrapper);
    } else if (this.mCallbacksMessenger != null) {
        throw new RuntimeException("mCallbacksMessenger should be null. Instead it is " + this.mCallbacksMessenger);
    } else {
        this.mState = 1;
        Intent intent = new Intent(MediaBrowserServiceCompat.SERVICE_INTERFACE);
        intent.setComponent(this.mServiceComponent);
        final ServiceConnection thisConnection = new MediaServiceConnection();
        this.mServiceConnection = thisConnection;
        boolean bound = false;
        try {
            bound = this.mContext.bindService(intent, this.mServiceConnection, 1);
        } catch (Exception e) {
            Log.e(MediaBrowserCompat.TAG, "Failed binding to service " + this.mServiceComponent);
        }
        if (!bound) {
            this.mHandler.post(new Runnable() {
                public void run() {
                    if (thisConnection == MediaBrowserServiceImplBase.this.mServiceConnection) {
                        MediaBrowserServiceImplBase.this.forceCloseConnection();
                        MediaBrowserServiceImplBase.this.mCallback.onConnectionFailed();
                    }
                }
            });
        }
    }
}
项目:Blockly    文件:CodeGeneratorManager.java   
public CodeGeneratorManager(Context context) {
    this.mContext = context;
    this.mStoredRequests = new LinkedList<>();

    this.mCodeGenerationConnection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName className, IBinder binder) {
            try {
                if (!mResumed) {
                    unbind();
                } else {
                    mGeneratorService = ((CodeGeneratorService.CodeGeneratorBinder) binder)
                            .getService();

                    while (!mStoredRequests.isEmpty()) {
                        executeCodeGenerationRequest(mStoredRequests.poll());
                    }
                }
            } finally {
                mIsConnecting = false;
            }
        }

        @Override
        public void onServiceDisconnected(ComponentName arg0) {
            mGeneratorService = null;
        }
    };
}
项目:condom    文件:CondomContext.java   
@Override public boolean bindService(final Intent intent, final ServiceConnection conn, final int flags) {
    final boolean result = mCondom.proceed(OutboundType.BIND_SERVICE, intent, Boolean.FALSE, new CondomCore.WrappedValueProcedure<Boolean>() { @Override public Boolean proceed() {
        return CondomContext.super.bindService(intent, conn, flags);
    }});
    if (result) mCondom.logIfOutboundPass(TAG, intent, CondomCore.getTargetPackage(intent), CondomCore.CondomEvent.BIND_PASS);
    return result;
}
项目:condom    文件:CondomApplication.java   
@Override public boolean bindService(final Intent intent, final ServiceConnection conn, final int flags) {
    final boolean result = mCondom.proceed(OutboundType.BIND_SERVICE, intent, Boolean.FALSE, new CondomCore.WrappedValueProcedure<Boolean>() { @Override public Boolean proceed() {
        return mApplication.bindService(intent, conn, flags);
    }});
    if (result) mCondom.logIfOutboundPass(TAG, intent, CondomCore.getTargetPackage(intent), CondomCore.CondomEvent.BIND_PASS);
    return result;
}
项目:springreplugin    文件:ServiceDispatcher.java   
ServiceDispatcher(ServiceConnection conn,
                  Context context, Handler activityThread, int flags, int process) {
    mIServiceConnection = new InnerConnection(this);
    mConnection = conn;
    mContext = context;
    mActivityThread = activityThread;
    mLocation = new ServiceConnectionLeaked(null);
    mLocation.fillInStackTrace();
    mFlags = flags;
    mProcess = process;
}
项目:springreplugin    文件:PluginContext.java   
@Override
public boolean bindService(Intent service, ServiceConnection conn, int flags) {
    if (mLoader.mPluginObj.mInfo.getFrameworkVersion() <= 2) {
        // 仅框架版本为3及以上的才支持
        return super.bindService(service, conn, flags);
    }
    try {
        return PluginServiceClient.bindService(this, service, conn, flags, true);
    } catch (PluginClientHelper.ShouldCallSystem e) {
        // 若打开插件出错,则直接走系统逻辑
        return super.bindService(service, conn, flags);
    }
}
项目:DroidPlugin    文件:PluginManager.java   
public void removeServiceConnection(ServiceConnection sc) {
    Iterator<WeakReference<ServiceConnection>> iterator = sServiceConnection.iterator();
    while (iterator.hasNext()) {
        WeakReference<ServiceConnection> wsc = iterator.next();
        if (wsc.get() == sc) {
            iterator.remove();
        }
    }
}
项目:boohee_v5.6    文件:MediaBrowserCompat.java   
public void connect() {
    if (this.mState != 0) {
        throw new IllegalStateException("connect() called while not disconnected (state=" + getStateLabel(this.mState) + SocializeConstants.OP_CLOSE_PAREN);
    } else if (this.mServiceBinderWrapper != null) {
        throw new RuntimeException("mServiceBinderWrapper should be null. Instead it is " + this.mServiceBinderWrapper);
    } else if (this.mCallbacksMessenger != null) {
        throw new RuntimeException("mCallbacksMessenger should be null. Instead it is " + this.mCallbacksMessenger);
    } else {
        this.mState = 1;
        Intent intent = new Intent(MediaBrowserServiceCompat.SERVICE_INTERFACE);
        intent.setComponent(this.mServiceComponent);
        final ServiceConnection thisConnection = new MediaServiceConnection();
        this.mServiceConnection = thisConnection;
        boolean bound = false;
        try {
            bound = this.mContext.bindService(intent, this.mServiceConnection, 1);
        } catch (Exception e) {
            Log.e(MediaBrowserCompat.TAG, "Failed binding to service " + this.mServiceComponent);
        }
        if (!bound) {
            this.mHandler.post(new Runnable() {
                public void run() {
                    if (thisConnection == MediaBrowserServiceImplBase.this.mServiceConnection) {
                        MediaBrowserServiceImplBase.this.forceCloseConnection();
                        MediaBrowserServiceImplBase.this.mCallback.onConnectionFailed();
                    }
                }
            });
        }
    }
}
项目:TPlayer    文件:ServiceConnectionDelegate.java   
public static IServiceConnection removeDelegate(Context context, ServiceConnection conn) {
    IServiceConnection connection = null;
    try{
        Object loadApk = ContextImpl.mPackageInfo.get(VirtualCore.get().getContext());
        connection = LoadedApk.forgetServiceDispatcher.call(loadApk, context, conn);
    }catch (Exception e){
        Log.e("ConnectionDelegate", "forgetServiceDispatcher", e);
    }
    if(connection == null){
        return null;
    }
    return ServiceConnectionDelegate.removeDelegate(connection);
}
项目:TPlayer    文件:VActivityManager.java   
public int bindService(Context context, Intent service, ServiceConnection connection, int flags) {
    try {
        IServiceConnection conn = ServiceConnectionDelegate.getDelegate(context, connection, flags);
        return getService().bindService(null, null, service, null, conn, flags, 0);
    } catch (RemoteException e) {
        return VirtualRuntime.crash(e);
    }
}
项目:TPlayer    文件:VActivityManager.java   
public boolean unbindService(Context context, ServiceConnection connection) {
    try {
        IServiceConnection conn = ServiceConnectionDelegate.removeDelegate(context, connection);
        return getService().unbindService(conn, VUserHandle.myUserId());
    } catch (RemoteException e) {
        return VirtualRuntime.crash(e);
    }
}
项目:android-apkbox    文件:ApkContext.java   
@Override
public boolean bindService(Intent service, ServiceConnection conn, int flags) {
    if (isApkLoaded()) {
        service.putExtra(ApkConstant.EXTRA_APK_PATH, loaded.getApkPath());
        service = HookService_Component.modify(service);
    }
    return super.bindService(service, conn, flags);
}
项目:omnicrow-android    文件:ScanFragment.java   
@Override
public void unbindService(ServiceConnection serviceConnection) {
    Log.d("OMNI", "scan fragment unbound from beacon service");
    if (mBeaconManager.isBound(this)) {
        getActivity().unbindService(serviceConnection);
    }
    isReadyForScan = false;
    isScanning = false;
}
项目:android-runas    文件:CliContext.java   
@Override
public boolean bindService(Intent service, ServiceConnection conn, int flags) {
    return false;
}
项目:Phoenix-for-VK    文件:UploadUtils.java   
public ServiceBinder(final ServiceConnection callback) {
    mCallback = callback;
}
项目:Phoenix-for-VK    文件:MusicUtils.java   
public ServiceBinder(final ServiceConnection callback) {
    mCallback = callback;
}
项目:Musicoco    文件:PlayServiceManager.java   
public void bindService(ServiceConnection connection) {
    Intent intent = new Intent(context, PlayService.class);
    context.bindService(intent, connection, Service.BIND_AUTO_CREATE);
}
项目:Orin    文件:MusicPlayerRemote.java   
public ServiceBinder(final ServiceConnection callback) {
    mCallback = callback;
}
项目:MiPushFramework    文件:PseudoContextWrapper.java   
@Override public boolean bindService(Intent service, ServiceConnection conn, int flags) {
    return mBase.bindService(service, conn, flags);
}
项目:MiPushFramework    文件:PseudoContextWrapper.java   
@Override public void unbindService(ServiceConnection conn) {
    mBase.unbindService(conn);
}