isBinderAlive ( )源码实例Demo

android.os.IBinder#isBinderAlive ( )源码实例Demo

下面列出了android.os.IBinder#isBinderAlive ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: springreplugin   文件: RePluginServiceManager.java
/**
 * 获取已注册的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;
}
 
源代码2 项目: springreplugin   文件: ServiceChannelImpl.java
@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;
    }
}
 
源代码3 项目: starcor.xul   文件: XulRemoteDataService.java
private boolean checkRemoteService() {
	if (_remoteDataService == null) {
		return false;
	}
	IBinder iBinder = _remoteDataService.asBinder();
	if (iBinder == null) {
		return false;
	}
	if (!iBinder.isBinderAlive()) {
		return false;
	}
	return true;
}
 
void manageDisableListLocked(int userId, int what, IBinder token, String pkg, int which) {
    if (SPEW) {
        Slog.d(TAG, "manageDisableList userId=" + userId
                + " what=0x" + Integer.toHexString(what) + " pkg=" + pkg);
    }

    // Find matching record, if any
    final int N = mDisableRecords.size();
    DisableRecord record = null;
    int i;
    for (i = 0; i < N; i++) {
        DisableRecord r = mDisableRecords.get(i);
        if (r.token == token && r.userId == userId) {
            record = r;
            break;
        }
    }

    // Remove record if binder is already dead
    if (!token.isBinderAlive()) {
        if (record != null) {
            mDisableRecords.remove(i);
            record.token.unlinkToDeath(record, 0);
        }
        return;
    }

    // Update existing record
    if (record != null) {
        record.setFlags(what, which, pkg);
        if (record.isEmpty()) {
            mDisableRecords.remove(i);
            record.token.unlinkToDeath(record, 0);
        }
        return;
    }

    // Record doesn't exist, so we create a new one
    record = new DisableRecord(userId, token);
    record.setFlags(what, which, pkg);
    mDisableRecords.add(record);
}
 
源代码5 项目: springreplugin   文件: QihooServiceManager.java
/**
 * 获取已注册服务的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;
}