Java Code Examples for android.os.IBinder.pingBinder()

The following are Jave code examples for showing how to use pingBinder() of the android.os.IBinder class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: springreplugin   File: RePluginServiceManager.java   Source Code and License Vote up 6 votes
/**
 * 获取已注册的IBinder
 *
 * @param name
 * @return
 */
public IBinder getService(final String name) {
    if (LogDebug.LOG) {
        LogDebug.d(TAG, "get service for IPlugin.query, name = " + name);
    }

    if (TextUtils.isEmpty(name)) {
        throw new IllegalArgumentException("service name can not value null");
    }

    IBinder ret = mServices.get(name);

    if (ret == null) {
        return null;
    }

    if (!ret.isBinderAlive() || !ret.pingBinder()) {
        mServices.remove(name);
        return null;
    }

    return ret;
}
 
Example 2
Project: springreplugin   File: ServiceChannelImpl.java   Source Code and License Vote up 5 votes
@Override
public IBinder getService(String serviceName) throws RemoteException {
    if (DEBUG) {
        Log.d(TAG, "[getService] --> serviceName = " + serviceName);
    }

    if (TextUtils.isEmpty(serviceName)) {
        throw new IllegalArgumentException();
    }

    IBinder service = sServices.get(serviceName);

    // 若没有注册此服务,则尝试从“延迟IBinder”中获取
    // Added by Jiongxuan Zhang
    if (service == null) {
        return fetchFromDelayedMap(serviceName);
    }

    // 判断Binder是否挂掉
    if (!service.isBinderAlive() || !service.pingBinder()) {
        if (DEBUG) {
            Log.d(TAG, "[getService] --> service died:" + serviceName);
        }

        sServices.remove(serviceName);
        return null;
    } else {
        return service;
    }
}
 
Example 3
Project: springreplugin   File: QihooServiceManager.java   Source Code and License Vote up 4 votes
/**
 * 获取已注册服务的IBinder对象,前提是该服务是静态服务,即默认一直存在,或者自己已经启动并且向我们注册过;
 * 注意不能通过此借口获取一个插件的服务,除非明确知道该插件的服务已经主动注册过,否则使用getPluginService()
 *
 * @param context
 * @param serviceName 请求获取的service名称
 * @return 所请求的service实现对象
 */
public static IBinder getService(Context context, String serviceName) {
    if (DEBUG) {
        Log.d(TAG, "[getService] begin = " + SystemClock.elapsedRealtime());
    }

    IBinder service = null;

    /**
     * 先考虑本地缓存
     */
    SoftReference<IBinder> ref = sCache.get(serviceName);
    if (ref != null) {
        service = ref.get();
        if (service != null) {
            if (service.isBinderAlive() && service.pingBinder()) {
                if (DEBUG) {
                    Log.d(TAG, "[getService] Found service from cache: " + serviceName);
                    Log.d(TAG, "[getService] end = " + SystemClock.elapsedRealtime());
                }
                return service;
            } else {
                sCache.remove(serviceName);
            }
        }
    }

    IServiceChannel serviceChannel = getServerChannel(context);
    if (serviceChannel == null) {
        return null;
    }

    try {
        service = serviceChannel.getService(serviceName);

        if (service != null) {
            if (DEBUG) {
                Log.d(TAG, "[getService] Found service from remote service channel: " + serviceName);
            }
            service = ServiceWrapper.factory(context, serviceName, service);
            sCache.put(serviceName, new SoftReference<IBinder>(service));
        }
    } catch (RemoteException e) {
        if (DEBUG) {
            Log.e(TAG, "[getService] Error when getting service from service channel...", e);
        }
    }

    if (DEBUG) {
        Log.d(TAG, "[getService] end = " + SystemClock.elapsedRealtime());
    }

    return service;
}
 
Example 4
Project: IPCServiceManager   File: Utils.java   Source Code and License Vote up 4 votes
public static boolean isAlive(IBinder binder){
    return (binder!=null && binder.isBinderAlive() && binder.pingBinder());
}