微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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,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);
        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,flags);
    }});
    if (result) mCondom.logIfOutboundPass(TAG,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(),serviceConnection);

  assertTelemetryReceiverRegistered(boundService);
}
项目:mapBox-events-android    文件TelemetryServiceTest.java   
@Test
public void checksLocationReceiverIsDownWhenServiceStopped() throws Exception {
  Intent serviceIntent = new Intent(InstrumentationRegistry.getTargetContext(),latchConnected);
  startService(serviceIntent);
  waitUntilServiceIsBound(serviceIntent,serviceConnection);

  stopService(serviceIntent,boundService);
  waitUntilServiceIsDestroyed();

  assertLocationReceiverNotRegistered(boundService);
}
项目:mapBox-events-android    文件TelemetryServiceTest.java   
@Test
public void checksTelemetryReceiverIsDownWhenServiceStopped() throws Exception {
  Intent serviceIntent = new Intent(InstrumentationRegistry.getTargetContext(),boundService);
  waitUntilServiceIsDestroyed();

  assertTelemetryReceiverNotRegistered(boundService);
}
项目:mapBox-events-android    文件TelemetryServiceTest.java   
@Test
public void checksLocationReceiverIsDownWhenOnBackgroundCalled() throws Exception {
  Intent serviceIntent = new Intent(InstrumentationRegistry.getTargetContext(),serviceConnection);

  backgroundService(boundService);

  assertLocationReceiverNotRegistered(boundService);
}
项目:mapBox-events-android    文件TelemetryServiceTest.java   
@Test
public void checksTelemetryReceiverIsUpWhenOnForegroundCalled() throws Exception {
  Intent serviceIntent = new Intent(InstrumentationRegistry.getTargetContext(),serviceConnection);
  backgroundService(boundService);

  foregroundService(boundService);

  assertLocationReceiverRegistered(boundService);
}
项目:mapBox-events-android    文件TelemetryServiceTest.java   
@Test
public void checksOnTaskRemovedCallbackWhenOnTaskRemovedCalled() throws Exception {
  Intent serviceIntent = new Intent(InstrumentationRegistry.getTargetContext(),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,CondomCore.CondomEvent.BIND_PASS);
    return result;
}
项目:condom    文件CondomApplication.java   
@Override public boolean bindService(final Intent intent,new CondomCore.WrappedValueProcedure<Boolean>() { @Override public Boolean proceed() {
        return mApplication.bindService(intent,CondomCore.CondomEvent.BIND_PASS);
    return result;
}
项目:springreplugin    文件Servicedispatcher.java   
Servicedispatcher(ServiceConnection conn,Handler activityThread,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,flags);
    }
    try {
        return PluginServiceClient.bindService(this,service,true);
    } catch (PluginClientHelper.ShouldCallSystem e) {
        // 若打开插件出错,则直接走系统逻辑
        return super.bindService(service,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,"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,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,int flags) {
    try {
        IServiceConnection conn = ServiceConnectionDelegate.getDelegate(context,flags);
        return getService().bindService(null,null,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,int flags) {
    if (isApkLoaded()) {
        service.putExtra(ApkConstant.EXTRA_APK_PATH,loaded.getApkPath());
        service = HookService_Component.modify(service);
    }
    return super.bindService(service,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,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,Service.BIND_AUTO_CREATE);
}
项目:Orin    文件MusicPlayerRemote.java   
public ServiceBinder(final ServiceConnection callback) {
    mCallback = callback;
}
项目:MiPushFramework    文件PseudoContextwrapper.java   
@Override public boolean bindService(Intent service,int flags) {
    return mBase.bindService(service,flags);
}
项目:MiPushFramework    文件PseudoContextwrapper.java   
@Override public void unbindService(ServiceConnection conn) {
    mBase.unbindService(conn);
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。