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

The following are Jave code examples for showing how to use linkToDeath() 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.
+ Save this method
Example 1
Project: VirtualHook   File: PendingIntents.java   View Source Code Vote up 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 2
Project: springreplugin   File: PluginProviderStub.java   View Source Code Vote up 6 votes
/**
 * @param context
 * @return
 * @throws RemoteException
 */
public static final IPref getPref(Context context) throws RemoteException {
    if (sPref == null) {
        if (IPC.isPersistentProcess()) {
            // 需要枷锁否?
            initPref();
        } else {
            IBinder b = PluginProviderStub.proxyFetchHostPref(context);
            b.linkToDeath(new DeathRecipient() {

                @Override
                public void binderDied() {
                    sPref = null;
                }
            }, 0);
            sPref = IPref.Stub.asInterface(b);
        }
    }
    return sPref;
}
 
Example 3
Project: IPCServiceManager   File: ServiceManagerServer.java   View Source Code Vote up 6 votes
@Override
public void addService(String serviceName, IBinder service)
		throws RemoteException {

	LogControler.info("ServiceManagerServer", "[svcmgr server] addService name = " + serviceName + " , service = " + service+ " , callingpid = " + Binder.getCallingPid());

	service.linkToDeath(new BinderServiceDeathRecipient(serviceName),0);
	clientServiceContainer.put(serviceName, service);

	//查看是否有listen这个服务的
	IServiceCallbackProxy serviceCallback = asyncClientServiceContainer.get(serviceName);

	if(serviceCallback!=null){
		try {
			LogControler.info("ServiceManagerServer", "[svcmgr server] addService onReady");
			serviceCallback.callback(service);
		} catch(Exception e){
			e.printStackTrace();
		}
	} else {
		LogControler.info("ServiceManagerServer", "[svcmgr server] addService serviceCallback not found");
	}
}
 
Example 4
Project: IPCServiceManager   File: ServiceManager.java   View Source Code Vote up 6 votes
IServiceManager getServiceManager(){
	if(serviceManager == null || !Utils.isAlive(serviceManager.asBinder())) {

		LogControler.info("ServiceManager", "[svcmgr proxy] recreate svcmgr object");

		IBinder svcmgr = BinderQuerier.query(sContext,IPC.SERVICE_MANAGER_URI,"server");

		try {
			svcmgr.linkToDeath(this,0);
		} catch(Exception e){
			e.printStackTrace();
		}

		serviceManager = IServiceManager.Stub.asInterface(svcmgr);
	}

	return serviceManager;
}
 
Example 5
Project: TPlayer   File: PendingIntents.java   View Source Code Vote up 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 6
Project: container   File: PendingIntents.java   View Source Code Vote up 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 7
Project: serviceconnector   File: AbstractServiceHandler.java   View Source Code Vote up 6 votes
public void onServiceConnected(ComponentName className, IBinder serviceBinder) {
    try {
        synchronized (AbstractServiceHandler.this) {
            AbstractServiceHandler.this.service = initService(serviceBinder);
            if (AbstractServiceHandler.this.service != null) {
                connected = true;
                AbstractServiceHandler.this.notifyAll();
            }
        }
        serviceBinder.linkToDeath(new IBinder.DeathRecipient() {
            @Override
            public void binderDied() {
                connectToService();
            }
        }, 0);
        AbstractServiceHandler.this.onServiceConnected();
    } catch (Exception ex) {
        Log.w(TAG, ex);
    }
}
 
Example 8
Project: VirtualHook   File: MethodProxies.java   View Source Code Vote up 5 votes
@Override
public Object call(Object who, Method method, Object... args) throws Throwable {
    MethodParameterUtils.replaceFirstAppPkg(args);
    args[IDX_RequiredPermission] = null;
    IntentFilter filter = (IntentFilter) args[IDX_IntentFilter];
    SpecialComponentList.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;
                }
            }
        }
    }
    return method.invoke(who, args);
}
 
Example 9
Project: VirtualHook   File: ServiceManagerNative.java   View Source Code Vote up 5 votes
private static void linkBinderDied(final IBinder binder) {
	IBinder.DeathRecipient deathRecipient = new IBinder.DeathRecipient() {
		@Override
		public void binderDied() {
			binder.unlinkToDeath(this, 0);
		}
	};
	try {
		binder.linkToDeath(deathRecipient, 0);
	} catch (RemoteException e) {
		e.printStackTrace();
	}
}
 
Example 10
Project: DroidIPC   File: ServiceManagerImpl.java   View Source Code Vote up 5 votes
static ServiceManagerImpl createLocalServiceManager(Context context,IBinder remoteServiceManager){
	ServiceManagerImpl serviceManager = new ServiceManagerImpl(context,remoteServiceManager);
	
	try {
		remoteServiceManager.linkToDeath(serviceManager, 0);
	} catch (RemoteException e) {
		e.printStackTrace(); //ignore
	}
	
	serviceManager.managedSelf(context.getPackageName());
	
	return serviceManager;
}
 
Example 11
Project: springreplugin   File: PluginServiceRecord.java   View Source Code Vote up 5 votes
private ProcessRecord(int pid, IBinder deathMonitor) {
    this.pid = pid;
    this.deathMonitor = deathMonitor;
    try {
        deathMonitor.linkToDeath(this, 0);
    } catch (RemoteException e) {
        if (DEBUG) {
            Log.d(TAG, "Error when linkToDeath: ");
        }
    }
    refCount = 1;
}
 
Example 12
Project: springreplugin   File: PmHostSvc.java   View Source Code Vote up 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 13
Project: IPCServiceManager   File: ServiceManager.java   View Source Code Vote up 5 votes
static IServiceManager create(Context context) {

			sContext = context;

			IBinder svcmgr = BinderQuerier.query(context,IPC.SERVICE_MANAGER_URI,"server");

			RemoteServiceManagerProxy proxy = new RemoteServiceManagerProxy(svcmgr);
			try {
				svcmgr.linkToDeath(proxy,0);
			} catch(Exception e){
				e.printStackTrace();
			}
			return proxy;
		}
 
Example 14
Project: IPCServiceManager   File: BinderProxy.java   View Source Code Vote up 5 votes
public static IBinder proxy(String serviceName,IBinder target) {
	BinderProxy binderProxy = new BinderProxy(serviceName,target);
	try {
		target.linkToDeath(binderProxy, 0);
	} catch (RemoteException e) {
		e.printStackTrace();
	}
	return binderProxy;
}
 
Example 15
Project: TPlayer   File: MethodProxies.java   View Source Code Vote up 5 votes
@Override
public Object call(Object who, Method method, Object... args) throws Throwable {
    MethodParameterUtils.replaceFirstAppPkg(args);
    args[IDX_RequiredPermission] = null;
    IntentFilter filter = (IntentFilter) args[IDX_IntentFilter];
    SpecialComponentList.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;
                }
            }
        }
    }
    return method.invoke(who, args);
}
 
Example 16
Project: TPlayer   File: ServiceManagerNative.java   View Source Code Vote up 5 votes
private static void linkBinderDied(final IBinder binder) {
    IBinder.DeathRecipient deathRecipient = new IBinder.DeathRecipient() {
        @Override
        public void binderDied() {
            binder.unlinkToDeath(this, 0);
        }
    };
    try {
        binder.linkToDeath(deathRecipient, 0);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}
 
Example 17
Project: container   File: RegisterReceiver.java   View Source Code Vote up 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 18
Project: container   File: ServiceManagerNative.java   View Source Code Vote up 5 votes
private static void linkBinderDied(final IBinder binder) {
	IBinder.DeathRecipient deathRecipient = new IBinder.DeathRecipient() {
		@Override
		public void binderDied() {
			binder.unlinkToDeath(this, 0);
		}
	};
	try {
		binder.linkToDeath(deathRecipient, 0);
	} catch (RemoteException e) {
		e.printStackTrace();
	}
}
 
Example 19
Project: springreplugin   File: ServiceDispatcher.java   View Source Code Vote up 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);
        }
    }