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;
}
}
java类android.content.ServiceConnection的实例源码
br.java 文件源码
项目:boohee_v5.6
阅读 39
收藏 0
点赞 0
评论 0
PluginServiceDispatcherManager.java 文件源码
项目:springreplugin
阅读 34
收藏 0
点赞 0
评论 0
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;
}
}
PluginContext.java 文件源码
项目:springreplugin
阅读 52
收藏 0
点赞 0
评论 0
@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);
}
PluginManager.java 文件源码
项目:DroidPlugin
阅读 53
收藏 0
点赞 0
评论 0
@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();
}
ServiceChecker.java 文件源码
项目:boohee_v5.6
阅读 36
收藏 0
点赞 0
评论 0
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;
}
ServiceConnectionDelegate.java 文件源码
项目:TPlayer
阅读 38
收藏 0
点赞 0
评论 0
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);
}
MusicUtils.java 文件源码
项目:ThunderMusic
阅读 45
收藏 0
点赞 0
评论 0
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;
}
UploadUtils.java 文件源码
项目:Phoenix-for-VK
阅读 38
收藏 0
点赞 0
评论 0
/**
* @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;
}
MusicUtils.java 文件源码
项目:Phoenix-for-VK
阅读 44
收藏 0
点赞 0
评论 0
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;
}
CondomContext.java 文件源码
项目:MiPushFramework
阅读 37
收藏 0
点赞 0
评论 0
@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;
}
ChidoriClient.java 文件源码
项目:Chidori
阅读 42
收藏 0
点赞 0
评论 0
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);
}
TelemetryServiceTest.java 文件源码
项目:mapbox-events-android
阅读 34
收藏 0
点赞 0
评论 0
@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);
}
TelemetryServiceTest.java 文件源码
项目:mapbox-events-android
阅读 36
收藏 0
点赞 0
评论 0
@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);
}
TelemetryServiceTest.java 文件源码
项目:mapbox-events-android
阅读 39
收藏 0
点赞 0
评论 0
@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);
}
TelemetryServiceTest.java 文件源码
项目:mapbox-events-android
阅读 35
收藏 0
点赞 0
评论 0
@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);
}
TelemetryServiceTest.java 文件源码
项目:mapbox-events-android
阅读 34
收藏 0
点赞 0
评论 0
@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);
}
TelemetryServiceTest.java 文件源码
项目:mapbox-events-android
阅读 45
收藏 0
点赞 0
评论 0
@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);
}
TelemetryServiceTest.java 文件源码
项目:mapbox-events-android
阅读 35
收藏 0
点赞 0
评论 0
@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();
}
ClientManager.java 文件源码
项目:chromium-for-android-56-debug-video
阅读 33
收藏 0
点赞 0
评论 0
/** 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);
}
ApkManager.java 文件源码
项目:letv
阅读 44
收藏 0
点赞 0
评论 0
public void removeServiceConnection(ServiceConnection sc) {
Iterator<WeakReference<ServiceConnection>> iterator = this.sServiceConnection.iterator();
while (iterator.hasNext()) {
if (((WeakReference) iterator.next()).get() == sc) {
iterator.remove();
}
}
}
MediaBrowserCompat.java 文件源码
项目:letv
阅读 45
收藏 0
点赞 0
评论 0
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();
}
}
});
}
}
}
CodeGeneratorManager.java 文件源码
项目:Blockly
阅读 34
收藏 0
点赞 0
评论 0
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;
}
};
}
CondomContext.java 文件源码
项目:condom
阅读 42
收藏 0
点赞 0
评论 0
@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;
}
CondomApplication.java 文件源码
项目:condom
阅读 49
收藏 0
点赞 0
评论 0
@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;
}
ServiceDispatcher.java 文件源码
项目:springreplugin
阅读 39
收藏 0
点赞 0
评论 0
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;
}
PluginContext.java 文件源码
项目:springreplugin
阅读 37
收藏 0
点赞 0
评论 0
@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);
}
}
PluginManager.java 文件源码
项目:DroidPlugin
阅读 39
收藏 0
点赞 0
评论 0
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();
}
}
}
MediaBrowserCompat.java 文件源码
项目:boohee_v5.6
阅读 40
收藏 0
点赞 0
评论 0
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();
}
}
});
}
}
}
ServiceConnectionDelegate.java 文件源码
项目:TPlayer
阅读 36
收藏 0
点赞 0
评论 0
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);
}
VActivityManager.java 文件源码
项目:TPlayer
阅读 39
收藏 0
点赞 0
评论 0
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);
}
}