android.app.IServiceConnection Java Examples

The following examples show how to use android.app.IServiceConnection. 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: VActivityManagerService.java    From container with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void publishService(IBinder token, Intent intent, IBinder service, int userId) {
    synchronized (this) {
        ServiceRecord r = (ServiceRecord) token;
        if (r != null) {
            ServiceRecord.IntentBindRecord boundRecord = r.peekBinding(intent);
            if (boundRecord != null) {
                boundRecord.binder = service;
                for (IServiceConnection conn : boundRecord.connections) {
                    ComponentName component = ComponentUtils.toComponentName(r.serviceInfo);
                    connectService(conn, component, boundRecord);
                }
            }
        }
    }
}
 
Example #2
Source File: ServiceRecord.java    From container with GNU General Public License v3.0 5 votes vote down vote up
void addToBoundIntent(Intent intent, IServiceConnection connection) {
	IntentBindRecord record = peekBinding(intent);
	if (record == null) {
		record = new IntentBindRecord();
		record.intent = intent;
		synchronized (bindings) {
			bindings.add(record);
		}
	}
	record.addConnection(connection);
}
 
Example #3
Source File: VActivityManagerService.java    From container with GNU General Public License v3.0 5 votes vote down vote up
private ServiceRecord findRecordLocked(IServiceConnection connection) {
    synchronized (mHistory) {
        for (ServiceRecord r : mHistory) {
            if (r.containConnection(connection)) {
                return r;
            }
        }
        return null;
    }
}
 
Example #4
Source File: VActivityManager.java    From container with GNU General Public License v3.0 5 votes vote down vote up
public boolean unbindService(IServiceConnection connection) {
    try {
        return getService().unbindService(connection, VUserHandle.myUserId());
    } catch (RemoteException e) {
        return VirtualRuntime.crash(e);
    }
}
 
Example #5
Source File: VActivityManager.java    From container with GNU General Public License v3.0 5 votes vote down vote up
public int bindService(IBinder caller, IBinder token, Intent service, String resolvedType, IServiceConnection connection, int flags, int userId) {
    try {
        return getService().bindService(caller, token, service, resolvedType, connection, flags, userId);
    } catch (RemoteException e) {
        return VirtualRuntime.crash(e);
    }
}
 
Example #6
Source File: BindService.java    From container with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Object call(Object who, Method method, Object... args) throws Throwable {
	IInterface caller = (IInterface) args[0];
	IBinder token = (IBinder) args[1];
	Intent service = (Intent) args[2];
	String resolvedType = (String) args[3];
	IServiceConnection conn = (IServiceConnection) args[4];
	if (!VirtualCore.get().getComponentDelegate().onStartService(service)) return 0;
	int flags = (int) args[5];
	int userId = VUserHandle.myUserId();
	if (isServerProcess()) {
		userId = service.getIntExtra("_VA_|_user_id_", VUserHandle.USER_NULL);
	}
	if (userId == VUserHandle.USER_NULL) {
		return method.invoke(who, args);
	}
	ServiceInfo serviceInfo = VirtualCore.get().resolveServiceInfo(service, userId);
	if (serviceInfo != null) {
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
			service.setComponent(new ComponentName(serviceInfo.packageName, serviceInfo.name));
		}
		conn = ServiceConnectionDelegate.getDelegate(conn);
		return VActivityManager.get().bindService(caller.asBinder(), token, service, resolvedType,
                   conn, flags, userId);
	}
	return method.invoke(who, args);
}
 
Example #7
Source File: UnbindService.java    From container with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Object call(Object who, Method method, Object... args) throws Throwable {
	IServiceConnection conn = (IServiceConnection) args[0];
	ServiceConnectionDelegate delegate = ServiceConnectionDelegate.removeDelegate(conn);
	if (delegate == null) {
		return method.invoke(who, args);
	}
	return VActivityManager.get().unbindService(delegate);
}
 
Example #8
Source File: ServiceConnectionDelegate.java    From container with GNU General Public License v3.0 5 votes vote down vote up
public static ServiceConnectionDelegate getDelegate(IServiceConnection conn) {
    if(conn instanceof ServiceConnectionDelegate){
        return (ServiceConnectionDelegate)conn;
    }
    IBinder binder = conn.asBinder();
    ServiceConnectionDelegate delegate = DELEGATE_MAP.get(binder);
    if (delegate == null) {
        delegate = new ServiceConnectionDelegate(conn);
        DELEGATE_MAP.put(binder, delegate);
    }
    return delegate;
}
 
Example #9
Source File: VActivityManagerService.java    From container with GNU General Public License v3.0 5 votes vote down vote up
private void connectService(IServiceConnection conn, ComponentName component, ServiceRecord.IntentBindRecord r) {
    try {
        BinderDelegateService delegateService = new BinderDelegateService(component, r.binder);
        conn.connected(component, delegateService);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}
 
Example #10
Source File: ServiceRecord.java    From container with GNU General Public License v3.0 5 votes vote down vote up
public boolean containConnection(IServiceConnection connection) {
	for (IntentBindRecord record : bindings) {
		if (record.containConnection(connection)) {
			return true;
		}
	}
	return false;
}
 
Example #11
Source File: ActivityManagerService.java    From prevent with Do What The F*ck You Want To Public License 5 votes vote down vote up
public int bindService(IApplicationThread caller, IBinder token,
                       Intent service, String resolvedType,
                       IServiceConnection connection, int flags, int userId) {
    try {
        PreventRunningUtils.setSender(caller);
        if (PreventRunningUtils.hookBindService(caller, token, service)) {
            return bindService$Pr(caller, token, service,
                    resolvedType, connection, flags, userId);
        } else {
            return 0;
        }
    } finally {
        PreventRunningUtils.clearSender();
    }
}
 
Example #12
Source File: ActivityManagerService.java    From prevent with Do What The F*ck You Want To Public License 5 votes vote down vote up
public int bindService(IApplicationThread caller, IBinder token, Intent service,
                       String resolvedType, IServiceConnection connection, int flags, String callingPackage,
                       int userId) throws TransactionTooLargeException {
    try {
        PreventRunningUtils.setSender(caller);
        if (PreventRunningUtils.hookBindService(caller, token, service)) {
            return bindService$Pr(caller, token, service,
                    resolvedType, connection, flags, callingPackage, userId);
        } else {
            return 0;
        }
    } finally {
        PreventRunningUtils.clearSender();
    }
}
 
Example #13
Source File: ServiceRecord.java    From container with GNU General Public License v3.0 5 votes vote down vote up
public boolean containConnection(IServiceConnection connection) {
	for (IServiceConnection con : connections) {
		if (con.asBinder() == connection.asBinder()) {
			return true;
		}
	}
	return false;
}
 
Example #14
Source File: ActivityManagerNativeWorker.java    From GPT with Apache License 2.0 5 votes vote down vote up
/**
 * android 6.0
 */
public int bindService(IApplicationThread caller, IBinder token, Intent service,
                       String resolvedType, IServiceConnection connection, int flags,
                       String callingPackage, int userId) {

    RemapingUtil.remapServiceIntent(mHostContext, service);

    return mTarget.bindService(caller, token, service, resolvedType, connection, flags, callingPackage, userId);
}
 
Example #15
Source File: ActivityManagerNativeWorker.java    From GPT with Apache License 2.0 5 votes vote down vote up
public int bindService(IApplicationThread caller, IBinder token,
                       Intent service, String resolvedType,
                       IServiceConnection connection, int flags, int userId) {

    token = getActivityToken(token);

    RemapingUtil.remapServiceIntent(mHostContext, service);

    if (userId == INVALID_USER_ID) {
        return mTarget.bindService(caller, token, service, resolvedType, connection, flags);
    } else {
        return mTarget.bindService(caller, token, service, resolvedType, connection, flags, userId);
    }
}
 
Example #16
Source File: ServiceRecord.java    From container with GNU General Public License v3.0 5 votes vote down vote up
public void addConnection(IServiceConnection connection) {
	if (!containConnection(connection)) {
		connections.add(connection);
		try {
			connection.asBinder().linkToDeath(new DeathRecipient(this, connection), 0);
		} catch (RemoteException e) {
			e.printStackTrace();
		}
	}
}
 
Example #17
Source File: ServiceRecord.java    From container with GNU General Public License v3.0 5 votes vote down vote up
public void removeConnection(IServiceConnection connection) {
	synchronized (connections) {
		Iterator<IServiceConnection> iterator = connections.iterator();
		while (iterator.hasNext()) {
			IServiceConnection conn = iterator.next();
			if (conn.asBinder() == connection.asBinder()) {
				iterator.remove();
			}
		}
	}
}
 
Example #18
Source File: ConnectionRecord.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
ConnectionRecord(AppBindRecord _binding, ActivityRecord _activity,
           IServiceConnection _conn, int _flags,
           int _clientLabel, PendingIntent _clientIntent) {
    binding = _binding;
    activity = _activity;
    conn = _conn;
    flags = _flags;
    clientLabel = _clientLabel;
    clientIntent = _clientIntent;
}
 
Example #19
Source File: ServiceRecord.java    From container with GNU General Public License v3.0 4 votes vote down vote up
private DeathRecipient(IntentBindRecord bindRecord, IServiceConnection connection) {
	this.bindRecord = bindRecord;
	this.connection = connection;
}
 
Example #20
Source File: ActiveServices.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
boolean unbindServiceLocked(IServiceConnection connection) {
    IBinder binder = connection.asBinder();
    if (DEBUG_SERVICE) Slog.v(TAG_SERVICE, "unbindService: conn=" + binder);
    ArrayList<ConnectionRecord> clist = mServiceConnections.get(binder);
    if (clist == null) {
        Slog.w(TAG, "Unbind failed: could not find connection for "
              + connection.asBinder());
        return false;
    }

    final long origId = Binder.clearCallingIdentity();
    try {
        while (clist.size() > 0) {
            ConnectionRecord r = clist.get(0);
            removeConnectionLocked(r, null, null);
            if (clist.size() > 0 && clist.get(0) == r) {
                // In case it didn't get removed above, do it now.
                Slog.wtf(TAG, "Connection " + r + " not removed for binder " + binder);
                clist.remove(0);
            }

            if (r.binding.service.app != null) {
                if (r.binding.service.app.whitelistManager) {
                    updateWhitelistManagerLocked(r.binding.service.app);
                }
                // This could have made the service less important.
                if ((r.flags&Context.BIND_TREAT_LIKE_ACTIVITY) != 0) {
                    r.binding.service.app.treatLikeActivity = true;
                    mAm.updateLruProcessLocked(r.binding.service.app,
                            r.binding.service.app.hasClientActivities
                            || r.binding.service.app.treatLikeActivity, null);
                }
                mAm.updateOomAdjLocked(r.binding.service.app, false);
            }
        }

        mAm.updateOomAdjLocked();

    } finally {
        Binder.restoreCallingIdentity(origId);
    }

    return true;
}
 
Example #21
Source File: ServiceConnectionDelegate.java    From container with GNU General Public License v3.0 4 votes vote down vote up
public static ServiceConnectionDelegate removeDelegate(IServiceConnection conn) {
    return DELEGATE_MAP.remove(conn.asBinder());
}
 
Example #22
Source File: ServiceConnectionDelegate.java    From container with GNU General Public License v3.0 4 votes vote down vote up
private ServiceConnectionDelegate(IServiceConnection mConn) {
    this.mConn = mConn;
}
 
Example #23
Source File: ActivityManagerService.java    From prevent with Do What The F*ck You Want To Public License 4 votes vote down vote up
public int bindService$Pr(IApplicationThread caller, IBinder token,
                          Intent service, String resolvedType,
                          IServiceConnection connection, int flags, int userId) {
    throw new UnsupportedOperationException();
}
 
Example #24
Source File: ActivityManagerService.java    From prevent with Do What The F*ck You Want To Public License 4 votes vote down vote up
public int bindService$Pr(IApplicationThread caller, IBinder token, Intent service,
                          String resolvedType, IServiceConnection connection, int flags, String callingPackage,
                          int userId) throws TransactionTooLargeException {
    throw new UnsupportedOperationException();
}
 
Example #25
Source File: ActivityManagerNativeWorker.java    From GPT with Apache License 2.0 4 votes vote down vote up
public boolean unbindService(IServiceConnection connection) {
    return mTarget.unbindService(connection);
}
 
Example #26
Source File: ActivityManagerNativeWorker.java    From GPT with Apache License 2.0 4 votes vote down vote up
public int bindService(IApplicationThread caller, IBinder token,
                       Intent service, String resolvedType,
                       IServiceConnection connection, int flags) {

    return bindService(caller, token, service, resolvedType, connection, flags, INVALID_USER_ID);
}
 
Example #27
Source File: ContextWrapper.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * @hide
 */
@Override
public IServiceConnection getServiceDispatcher(ServiceConnection conn, Handler handler,
        int flags) {
    return mBase.getServiceDispatcher(conn, handler, flags);
}
 
Example #28
Source File: AppWidgetManager.java    From android_9.0.0_r45 with Apache License 2.0 3 votes vote down vote up
/**
 * Binds the RemoteViewsService for a given appWidgetId and intent.
 *
 * The appWidgetId specified must already be bound to the calling AppWidgetHost via
 * {@link android.appwidget.AppWidgetManager#bindAppWidgetId AppWidgetManager.bindAppWidgetId()}.
 *
 * @param appWidgetId   The AppWidget instance for which to bind the RemoteViewsService.
 * @param intent        The intent of the service which will be providing the data to the
 *                      RemoteViewsAdapter.
 * @param connection    The callback interface to be notified when a connection is made or lost.
 * @param flags         Flags used for binding to the service
 *
 * @see Context#getServiceDispatcher(ServiceConnection, Handler, int)
 * @hide
 */
public boolean bindRemoteViewsService(Context context, int appWidgetId, Intent intent,
        IServiceConnection connection, @Context.BindServiceFlags int flags) {
    if (mService == null) {
        return false;
    }
    try {
        return mService.bindRemoteViewsService(context.getOpPackageName(), appWidgetId, intent,
                context.getIApplicationThread(), context.getActivityToken(), connection, flags);
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}