Java Code Examples for android.os.IBinder#linkToDeath()
The following examples show how to use
android.os.IBinder#linkToDeath() .
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: InputManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override public void vibrate(int deviceId, long[] pattern, int repeat, IBinder token) { if (repeat >= pattern.length) { throw new ArrayIndexOutOfBoundsException(); } VibratorToken v; synchronized (mVibratorLock) { v = mVibratorTokens.get(token); if (v == null) { v = new VibratorToken(deviceId, token, mNextVibratorTokenValue++); try { token.linkToDeath(v, 0); } catch (RemoteException ex) { // give up throw new RuntimeException(ex); } mVibratorTokens.put(token, v); } } synchronized (v) { v.mVibrating = true; nativeVibrate(mPtr, deviceId, pattern, repeat, v.mTokenValue); } }
Example 2
Source File: PendingIntents.java From container with GNU General Public License v3.0 | 6 votes |
final void addPendingIntent(final IBinder binder, String creator) { synchronized (mLruHistory) { try { binder.linkToDeath(new IBinder.DeathRecipient() { @Override public void binderDied() { binder.unlinkToDeath(this, 0); mLruHistory.remove(binder); } }, 0); } catch (RemoteException e) { e.printStackTrace(); } PendingIntentData pendingIntentData = mLruHistory.get(binder); if (pendingIntentData == null) { mLruHistory.put(binder, new PendingIntentData(creator, binder)); } else { pendingIntentData.creator = creator; } } }
Example 3
Source File: InstantAppResolverConnection.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override public void onServiceConnected(ComponentName name, IBinder service) { if (DEBUG_INSTANT) { Slog.d(TAG, "Connected to instant app resolver"); } synchronized (mLock) { mRemoteInstance = IInstantAppResolver.Stub.asInterface(service); if (mBindState == STATE_PENDING) { mBindState = STATE_IDLE; } try { service.linkToDeath(InstantAppResolverConnection.this, 0 /*flags*/); } catch (RemoteException e) { handleBinderDiedLocked(); } mLock.notifyAll(); } }
Example 4
Source File: TelephonyRegistry.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private Record add(IBinder binder) { Record r; synchronized (mRecords) { final int N = mRecords.size(); for (int i = 0; i < N; i++) { r = mRecords.get(i); if (binder == r.binder) { // Already existed. return r; } } r = new Record(); r.binder = binder; r.deathRecipient = new TelephonyRegistryDeathRecipient(binder); try { binder.linkToDeath(r.deathRecipient, 0); } catch (RemoteException e) { if (VDBG) log("LinkToDeath remote exception sending to r=" + r + " e=" + e); // Binder already died. Return null. return null; } mRecords.add(r); if (DBG) log("add new record"); } return r; }
Example 5
Source File: ServiceBoundService.java From ShadowsocksRR with Apache License 2.0 | 5 votes |
@Override public void onServiceConnected(ComponentName name, IBinder service) { try { binder = service; service.linkToDeath(ServiceBoundService.this, 0); bgService = IShadowsocksService.Stub.asInterface(service); registerCallback(); ServiceBoundService.this.onServiceConnected(); } catch (RemoteException e) { VayLog.e(TAG, "onServiceConnected", e); } }
Example 6
Source File: RegisterReceiver.java From container with GNU General Public License v3.0 | 5 votes |
@Override public Object call(Object who, Method method, Object... args) throws Throwable { HookUtils.replaceFirstAppPkg(args); args[IDX_RequiredPermission] = null; IntentFilter filter = (IntentFilter) args[IDX_IntentFilter]; IntentFilter backupFilter = new IntentFilter(filter); protectIntentFilter(filter); if (args.length > IDX_IIntentReceiver && IIntentReceiver.class.isInstance(args[IDX_IIntentReceiver])) { final IInterface old = (IInterface) args[IDX_IIntentReceiver]; if (!IIntentReceiverProxy.class.isInstance(old)) { final IBinder token = old.asBinder(); if (token != null) { token.linkToDeath(new IBinder.DeathRecipient() { @Override public void binderDied() { token.unlinkToDeath(this, 0); mProxyIIntentReceivers.remove(token); } }, 0); IIntentReceiver proxyIIntentReceiver = mProxyIIntentReceivers.get(token); if (proxyIIntentReceiver == null) { proxyIIntentReceiver = new IIntentReceiverProxy(old); mProxyIIntentReceivers.put(token, proxyIIntentReceiver); } WeakReference mDispatcher = LoadedApk.ReceiverDispatcher.InnerReceiver.mDispatcher.get(old); if (mDispatcher != null) { LoadedApk.ReceiverDispatcher.mIIntentReceiver.set(mDispatcher.get(), proxyIIntentReceiver); args[IDX_IIntentReceiver] = proxyIIntentReceiver; } } } } Object res = method.invoke(who, args); Intent intent = VActivityManager.get().dispatchStickyBroadcast(backupFilter); if (intent != null) { return intent; } return res; }
Example 7
Source File: CameraDeviceImpl.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Set remote device, which triggers initial onOpened/onUnconfigured callbacks * * <p>This function may post onDisconnected and throw CAMERA_DISCONNECTED if remoteDevice dies * during setup.</p> * */ public void setRemoteDevice(ICameraDeviceUser remoteDevice) throws CameraAccessException { synchronized(mInterfaceLock) { // TODO: Move from decorator to direct binder-mediated exceptions // If setRemoteFailure already called, do nothing if (mInError) return; mRemoteDevice = new ICameraDeviceUserWrapper(remoteDevice); IBinder remoteDeviceBinder = remoteDevice.asBinder(); // For legacy camera device, remoteDevice is in the same process, and // asBinder returns NULL. if (remoteDeviceBinder != null) { try { remoteDeviceBinder.linkToDeath(this, /*flag*/ 0); } catch (RemoteException e) { CameraDeviceImpl.this.mDeviceExecutor.execute(mCallOnDisconnected); throw new CameraAccessException(CameraAccessException.CAMERA_DISCONNECTED, "The camera device has encountered a serious error"); } } mDeviceExecutor.execute(mCallOnOpened); mDeviceExecutor.execute(mCallOnUnconfigured); } }
Example 8
Source File: ABridgeService.java From DoraemonKit with Apache License 2.0 | 5 votes |
@Override public void join(IBinder token) throws RemoteException { int idx = findClient(token); if (idx >= 0) { Log.d(TAG, token + " already joined , client size " + mClients.size()); return; } Client client = new Client(token); // 注册客户端死掉的通知 token.linkToDeath(client, 0); mClients.add(client); Log.d(TAG, token + " join , client size " + mClients.size()); }
Example 9
Source File: ContentProviderRecord.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
public ExternalProcessHandle(IBinder token) { mToken = token; try { token.linkToDeath(this, 0); } catch (RemoteException re) { Slog.e(LOG_TAG, "Couldn't register for death for token: " + mToken, re); } }
Example 10
Source File: SyncManager.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private void runBoundToAdapterH(final ActiveSyncContext activeSyncContext, IBinder syncAdapter) { final SyncOperation syncOperation = activeSyncContext.mSyncOperation; try { activeSyncContext.mIsLinkedToDeath = true; syncAdapter.linkToDeath(activeSyncContext, 0); mLogger.log("Sync start: account=" + syncOperation.target.account, " authority=", syncOperation.target.provider, " reason=", SyncOperation.reasonToString(null, syncOperation.reason), " extras=", SyncOperation.extrasToString(syncOperation.extras), " adapter=", activeSyncContext.mSyncAdapter); activeSyncContext.mSyncAdapter = ISyncAdapter.Stub.asInterface(syncAdapter); activeSyncContext.mSyncAdapter .startSync(activeSyncContext, syncOperation.target.provider, syncOperation.target.account, syncOperation.extras); mLogger.log("Sync is running now..."); } catch (RemoteException remoteExc) { mLogger.log("Sync failed with RemoteException: ", remoteExc.toString()); Log.d(TAG, "maybeStartNextSync: caught a RemoteException, rescheduling", remoteExc); closeActiveSyncContext(activeSyncContext); increaseBackoffSetting(syncOperation.target); scheduleSyncOperationH(syncOperation); } catch (RuntimeException exc) { mLogger.log("Sync failed with RuntimeException: ", exc.toString()); closeActiveSyncContext(activeSyncContext); Slog.e(TAG, "Caught RuntimeException while starting the sync " + logSafe(syncOperation), exc); } }
Example 11
Source File: PinnedSliceState.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
public void pin(String pkg, SliceSpec[] specs, IBinder token) { synchronized (mLock) { mListeners.put(token, new ListenerInfo(token, pkg, true, Binder.getCallingUid(), Binder.getCallingPid())); try { token.linkToDeath(mDeathRecipient, 0); } catch (RemoteException e) { } mergeSpecs(specs); setSlicePinned(true); } }
Example 12
Source File: ServiceBoundContext.java From Maying with Apache License 2.0 | 5 votes |
@Override public void onServiceConnected(ComponentName name, IBinder service) { try { binder = service; service.linkToDeath(ServiceBoundContext.this, 0); bgService = IShadowsocksService.Stub.asInterface(service); registerCallback(); ServiceBoundContext.this.onServiceConnected(); } catch (RemoteException e) { VayLog.e(TAG, "onServiceConnected", e); } }
Example 13
Source File: StatusBarManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
public DisableRecord(int userId, IBinder token) { this.userId = userId; this.token = token; try { token.linkToDeath(this, 0); } catch (RemoteException re) { // Give up } }
Example 14
Source File: PmHostSvc.java From springreplugin with Apache License 2.0 | 5 votes |
@Override public void installBinder(String name, IBinder binder) throws RemoteException { if (LOG) { LogDebug.d(PLUGIN_TAG, "install binder: n=" + name + " b=" + binder); } synchronized (PluginProcessMain.sBinders) { if (binder != null) { PluginProcessMain.sBinders.put(name, binder); binder.linkToDeath(new BinderDied(name, binder), 0); } else { PluginProcessMain.sBinders.remove(name); } } }
Example 15
Source File: BluetoothManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
public int updateBleAppCount(IBinder token, boolean enable, String packageName) { ClientDeathRecipient r = mBleApps.get(token); if (r == null && enable) { ClientDeathRecipient deathRec = new ClientDeathRecipient(packageName); try { token.linkToDeath(deathRec, 0); } catch (RemoteException ex) { throw new IllegalArgumentException("BLE app (" + packageName + ") already dead!"); } mBleApps.put(token, deathRec); if (DBG) { Slog.d(TAG, "Registered for death of " + packageName); } } else if (!enable && r != null) { // Unregister death recipient as the app goes away. token.unlinkToDeath(r, 0); mBleApps.remove(token); if (DBG) { Slog.d(TAG, "Unregistered for death of " + packageName); } } int appCount = mBleApps.size(); if (DBG) { Slog.d(TAG, appCount + " registered Ble Apps"); } if (appCount == 0 && mEnable) { disableBleScanMode(); } if (appCount == 0 && !mEnableExternal) { sendBrEdrDownCallback(); } return appCount; }
Example 16
Source File: TrackRecordingServiceConnection.java From mytracks with Apache License 2.0 | 5 votes |
@Override public void onServiceConnected(ComponentName className, IBinder service) { Log.i(TAG, "Connected to the service."); try { service.linkToDeath(deathRecipient, 0); } catch (RemoteException e) { Log.e(TAG, "Failed to bind a death recipient.", e); } setTrackRecordingService(ITrackRecordingService.Stub.asInterface(service)); }
Example 17
Source File: LoadedApk.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
public void doConnected(ComponentName name, IBinder service, boolean dead) { ServiceDispatcher.ConnectionInfo old; ServiceDispatcher.ConnectionInfo info; synchronized (this) { if (mForgotten) { // We unbound before receiving the connection; ignore // any connection received. return; } old = mActiveConnections.get(name); if (old != null && old.binder == service) { // Huh, already have this one. Oh well! return; } if (service != null) { // A new service is being connected... set it all up. info = new ConnectionInfo(); info.binder = service; info.deathMonitor = new DeathMonitor(name, service); try { service.linkToDeath(info.deathMonitor, 0); mActiveConnections.put(name, info); } catch (RemoteException e) { // This service was dead before we got it... just // don't do anything with it. mActiveConnections.remove(name); return; } } else { // The named service is being disconnected... clean up. mActiveConnections.remove(name); } if (old != null) { old.binder.unlinkToDeath(old.deathMonitor, 0); } } // If there was an old service, it is now disconnected. if (old != null) { mConnection.onServiceDisconnected(name); } if (dead) { mConnection.onBindingDied(name); } // If there is a new viable service, it is now connected. if (service != null) { mConnection.onServiceConnected(name, service); } else { // The binding machinery worked, but the remote returned null from onBind(). mConnection.onNullBinding(name); } }
Example 18
Source File: RemoteListenerHelper.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
public boolean addListener(@NonNull TListener listener) { Preconditions.checkNotNull(listener, "Attempted to register a 'null' listener."); IBinder binder = listener.asBinder(); LinkedListener deathListener = new LinkedListener(listener); synchronized (mListenerMap) { if (mListenerMap.containsKey(binder)) { // listener already added return true; } try { binder.linkToDeath(deathListener, 0 /* flags */); } catch (RemoteException e) { // if the remote process registering the listener is already death, just swallow the // exception and return Log.v(mTag, "Remote listener already died.", e); return false; } mListenerMap.put(binder, deathListener); // update statuses we already know about, starting from the ones that will never change int result; if (!isAvailableInPlatform()) { result = RESULT_NOT_AVAILABLE; } else if (mHasIsSupported && !mIsSupported) { result = RESULT_NOT_SUPPORTED; } else if (!isGpsEnabled()) { // only attempt to register if GPS is enabled, otherwise we will register once GPS // becomes available result = RESULT_GPS_LOCATION_DISABLED; } else if (mHasIsSupported && mIsSupported) { tryRegister(); // initially presume success, possible internal error could follow asynchornously result = RESULT_SUCCESS; } else { // at this point if the supported flag is not set, the notification will be sent // asynchronously in the future return true; } post(listener, getHandlerOperation(result)); } return true; }
Example 19
Source File: ServiceDispatcher.java From springreplugin with Apache License 2.0 | 4 votes |
public void doConnected(ComponentName name, IBinder service) { ServiceDispatcher.ConnectionInfo old; ServiceDispatcher.ConnectionInfo info; synchronized (this) { if (mForgotten) { // We unbound before receiving the connection; ignore // any connection received. return; } old = mActiveConnections.get(name); if (old != null && old.binder == service) { // Huh, already have this one. Oh well! return; } if (service != null) { // A new service is being connected... set it all up. // mDied = false; info = new ConnectionInfo(); info.binder = service; info.deathMonitor = new DeathMonitor(name, service); try { service.linkToDeath(info.deathMonitor, 0); mActiveConnections.put(name, info); } catch (RemoteException e) { // This service was dead before we got it... just // don't do anything with it. mActiveConnections.remove(name); return; } } else { // The named service is being disconnected... clean up. mActiveConnections.remove(name); } if (old != null) { old.binder.unlinkToDeath(old.deathMonitor, 0); } } // If there was an old service, it is not disconnected. if (old != null) { mConnection.onServiceDisconnected(name); } // If there is a new service, it is now connected. if (service != null) { mConnection.onServiceConnected(name, service); } }
Example 20
Source File: AppOpsService.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
public ClientRestrictionState(IBinder token) throws RemoteException { token.linkToDeath(this, 0); this.token = token; }