/** * Base class for Binder interfaces. When defining a new interface, * you must derive it from IInterface. */ publicinterfaceIInterface { /** * Retrieve the Binder object associated with this interface. * You must use this instead of a plain cast, so that proxy objects * can return the correct result. */ public IBinder asBinder(); }
/** * Add the calling thread to the IPC thread pool. This function does * not return until the current process is exiting. * 这里涉及到Binder线程池,后面分析 */ publicstaticfinalvoidjoinThreadPool(){ BinderInternal.joinThreadPool(); }
if (FIND_POTENTIAL_LEAKS) { final Class<? extends Binder> klass = getClass(); if ((klass.isAnonymousClass() || klass.isMemberClass() || klass.isLocalClass()) && (klass.getModifiers() & Modifier.STATIC) == 0) { Log.w(TAG, "The following Binder class should be static or leaks might occur: " + klass.getCanonicalName()); } } mDescriptor = descriptor; }
/** * 检索一个本地接口——在代理的情况下始终为空 */ public IInterface queryLocalInterface(String descriptor){ returnnull; }
/** * Perform a binder transaction on a proxy. * * @param code The action to perform. This should * be a number between {@link #FIRST_CALL_TRANSACTION} and * {@link #LAST_CALL_TRANSACTION}. * @param data Marshalled data to send to the target. Must not be null. * If you are not sending any data, you must create an empty Parcel * that is given here. * @param reply Marshalled data to be received from the target. May be * null if you are not interested in the return value. * @param flags Additional operation flags. Either 0 for a normal * RPC, or {@link #FLAG_ONEWAY} for a one-way RPC. * * @return * @throws RemoteException */ publicbooleantransact(int code, Parcel data, Parcel reply, int flags)throws RemoteException { Binder.checkParcel(this, code, data, "Unreasonably large binder buffer");
// For now, avoid spamming the log by disabling after we've logged // about this interface at least once mWarnOnBlocking = false;
if (Build.IS_USERDEBUG) { // Log this as a WTF on userdebug builds. Log.wtf(Binder.TAG, "Outgoing transactions from this process must be FLAG_ONEWAY", new Throwable()); } else { Log.w(Binder.TAG, "Outgoing transactions from this process must be FLAG_ONEWAY", new Throwable()); } }
finalboolean tracingEnabled = Binder.isTracingEnabled(); if (tracingEnabled) { final Throwable tr = new Throwable(); Binder.getTransactionTracker().addTrace(tr); StackTraceElement stackTraceElement = tr.getStackTrace()[1]; Trace.traceBegin(Trace.TRACE_TAG_ALWAYS, stackTraceElement.getClassName() + "." + stackTraceElement.getMethodName()); }
// Make sure the listener won't change while processing a transaction. final Binder.ProxyTransactListener transactListener = sTransactListener; Object session = null;
// Allow the listener to update the work source uid. We need to update the request // header if the uid is updated. finalint updatedWorkSourceUid = Binder.getCallingWorkSourceUid(); if (origWorkSourceUid != updatedWorkSourceUid) { data.replaceCallingWorkSourceUid(updatedWorkSourceUid); } }
final AppOpsManager.PausedNotedAppOpsCollection prevCollection = AppOpsManager.pauseNotedAppOpsCollection();
publicstaticbooleansetDefaultImpl(com.tufusi.aidl.IBookManager impl){ // Only one user of this interface can use this function // at a time. This is a heuristic to detect if two different // users in the same process use this function. if (Stub.Proxy.sDefaultImpl != null) { thrownew IllegalStateException("setDefaultImpl() called twice"); } if (impl != null) { Stub.Proxy.sDefaultImpl = impl; returntrue; } returnfalse; }