Java Code Examples for android.os.IBinder#isBinderAlive()

The following examples show how to use android.os.IBinder#isBinderAlive() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RePluginServiceManager.java    From springreplugin with Apache License 2.0 6 votes vote down vote up
/**
 * 获取已注册的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
Source File: ServiceChannelImpl.java    From springreplugin with Apache License 2.0 5 votes vote down vote up
@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
Source File: XulRemoteDataService.java    From starcor.xul with GNU Lesser General Public License v3.0 5 votes vote down vote up
private boolean checkRemoteService() {
	if (_remoteDataService == null) {
		return false;
	}
	IBinder iBinder = _remoteDataService.asBinder();
	if (iBinder == null) {
		return false;
	}
	if (!iBinder.isBinderAlive()) {
		return false;
	}
	return true;
}
 
Example 4
Source File: StatusBarManagerService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 5
Source File: QihooServiceManager.java    From springreplugin with Apache License 2.0 4 votes vote down vote up
/**
 * 获取已注册服务的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;
}