This method checks if the interface is the same between the client and server.
Detailed process:
- calling the IPC method on the client side, before calling
mRemote.transact this method is _data.writeInterfaceToken(DESCRIPTOR); I will call first. - will be called
onTransact server side, and then call data.enforceInterface(descriptor); to check if the interface matches, if they do not match, the error message "Binder invocation to an incorrect interface" .
Package Source Code:
static void android_os_Parcel_enforceInterface(JNIEnv* env, jclass clazz, jlong nativePtr, jstring name) { Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr); if (parcel != NULL) { const jchar* str = env->GetStringCritical(name, 0); if (str) { IPCThreadState* threadState = IPCThreadState::self(); const int32_t oldPolicy = threadState->getStrictModePolicy(); const bool isValid = parcel->enforceInterface( String16(reinterpret_cast<const char16_t*>(str), env->GetStringLength(name)), threadState); env->ReleaseStringCritical(name, str); if (isValid) { const int32_t newPolicy = threadState->getStrictModePolicy(); if (oldPolicy != newPolicy) {
source share