下面列出了android.os.TransactionTooLargeException#android.app.IServiceConnection 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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);
}
}
}
}
}
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;
}
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);
}
}
/**
* 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);
}
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();
}
}
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();
}
}
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;
}
@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);
}
@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);
}
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);
}
}
public boolean unbindService(IServiceConnection connection) {
try {
return getService().unbindService(connection, VUserHandle.myUserId());
} catch (RemoteException e) {
return VirtualRuntime.crash(e);
}
}
private ServiceRecord findRecordLocked(IServiceConnection connection) {
synchronized (mHistory) {
for (ServiceRecord r : mHistory) {
if (r.containConnection(connection)) {
return r;
}
}
return null;
}
}
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();
}
}
public boolean containConnection(IServiceConnection connection) {
for (IntentBindRecord record : bindings) {
if (record.containConnection(connection)) {
return true;
}
}
return false;
}
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);
}
public boolean containConnection(IServiceConnection connection) {
for (IServiceConnection con : connections) {
if (con.asBinder() == connection.asBinder()) {
return true;
}
}
return false;
}
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();
}
}
}
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();
}
}
}
}
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;
}
/**
* @hide
*/
@Override
public IServiceConnection getServiceDispatcher(ServiceConnection conn, Handler handler,
int flags) {
return mBase.getServiceDispatcher(conn, handler, flags);
}
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);
}
public boolean unbindService(IServiceConnection connection) {
return mTarget.unbindService(connection);
}
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();
}
public int bindService$Pr(IApplicationThread caller, IBinder token,
Intent service, String resolvedType,
IServiceConnection connection, int flags, int userId) {
throw new UnsupportedOperationException();
}
private ServiceConnectionDelegate(IServiceConnection mConn) {
this.mConn = mConn;
}
public static ServiceConnectionDelegate removeDelegate(IServiceConnection conn) {
return DELEGATE_MAP.remove(conn.asBinder());
}
private DeathRecipient(IntentBindRecord bindRecord, IServiceConnection connection) {
this.bindRecord = bindRecord;
this.connection = connection;
}
/**
* 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();
}
}