Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 54769abe authored by Aaron Okano's avatar Aaron Okano Committed by Android (Google) Code Review
Browse files

Merge changes from topic "ado/java-inherit-rt" into main

* changes:
  Allow enabling RT inheritance for system_server binders
  binder: Add Java bindings for setInheritRt
  Declare flag for enabling RT inheritance within system_server
parents 8f749f45 0f9843fa
Loading
Loading
Loading
Loading
+20 −0
Original line number Original line Diff line number Diff line
@@ -1259,6 +1259,26 @@ public class Binder implements IBinder {


    private final native void setExtensionNative(@Nullable IBinder extension);
    private final native void setExtensionNative(@Nullable IBinder extension);


    /**
     * Set whether or not this binder node will inherit real-time priority.
     * This should be called immediately when the object is created.
     *
     * @hide
     */
    public final native void setInheritRt(boolean inheritRt);

    /**
     * Set default RT inheritance for Binders in this process
     *
     * Any binder objects sent out of the process before this is called will
     * not use the updated value. Can be overridden by setInheritRt. Defaults
     * to false if this function is not called.
     *
     * @hide
     */
    @CriticalNative
    public static final native void setGlobalInheritRt(boolean enabled);

    /**
    /**
     * Default implementation rewinds the parcels and calls onTransact. On
     * Default implementation rewinds the parcels and calls onTransact. On
     * the remote side, transact calls into the binder to do the IPC.
     * the remote side, transact calls into the binder to do the IPC.
+25 −0
Original line number Original line Diff line number Diff line
@@ -496,6 +496,9 @@ public:
                    b.get()->setExtension(extensionFromJava);
                    b.get()->setExtension(extensionFromJava);
                }
                }
            }
            }
            if (mInheritRt) {
                b.get()->setInheritRt(mInheritRt);
            }
            mBinder = b;
            mBinder = b;
            ALOGV("Creating JavaBinder %p (refs %p) for Object %p, weakCount=%" PRId32 "\n",
            ALOGV("Creating JavaBinder %p (refs %p) for Object %p, weakCount=%" PRId32 "\n",
                 b.get(), b->getWeakRefs(), obj, b->getWeakRefs()->getWeakCount());
                 b.get(), b->getWeakRefs(), obj, b->getWeakRefs()->getWeakCount());
@@ -529,6 +532,15 @@ public:
        }
        }
    }
    }


    void setInheritRt(bool inheritRt) {
        AutoMutex _l(mLock);
        mInheritRt = inheritRt;
        sp<JavaBBinder> b = mBinder.promote();
        if (b != nullptr) {
            b.get()->setInheritRt(inheritRt);
        }
    }

private:
private:
    Mutex           mLock;
    Mutex           mLock;
    wp<JavaBBinder> mBinder;
    wp<JavaBBinder> mBinder;
@@ -538,6 +550,7 @@ private:
    // sp here (avoid recreating it)
    // sp here (avoid recreating it)
    bool            mVintf = false;
    bool            mVintf = false;
    bool            mSetExtensionCalled = false;
    bool            mSetExtensionCalled = false;
    bool            mInheritRt = false;
};
};


// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
@@ -1262,6 +1275,15 @@ static void android_os_Binder_setExtension(JNIEnv* env, jobject obj, jobject ext
    jbh->setExtension(extension);
    jbh->setExtension(extension);
}
}


static void android_os_Binder_setInheritRt(JNIEnv* env, jobject obj, jboolean inheritRt) {
    JavaBBinderHolder* jbh = (JavaBBinderHolder*) env->GetLongField(obj, gBinderOffsets.mObject);
    jbh->setInheritRt(inheritRt);
}

static void android_os_Binder_setGlobalInheritRt(CRITICAL_JNI_PARAMS_COMMA jboolean enabled) {
    BBinder::setGlobalInheritRt(enabled);
}

// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------


// clang-format off
// clang-format off
@@ -1290,6 +1312,8 @@ static const JNINativeMethod gBinderMethods[] = {
    { "getCallingWorkSourceUid", "()I", (void*)android_os_Binder_getCallingWorkSourceUid },
    { "getCallingWorkSourceUid", "()I", (void*)android_os_Binder_getCallingWorkSourceUid },
    // @CriticalNative
    // @CriticalNative
    { "clearCallingWorkSource", "()J", (void*)android_os_Binder_clearCallingWorkSource },
    { "clearCallingWorkSource", "()J", (void*)android_os_Binder_clearCallingWorkSource },
    // @CriticalNative
    { "setGlobalInheritRt", "(Z)V", (void*)android_os_Binder_setGlobalInheritRt },
    { "restoreCallingWorkSource", "(J)V", (void*)android_os_Binder_restoreCallingWorkSource },
    { "restoreCallingWorkSource", "(J)V", (void*)android_os_Binder_restoreCallingWorkSource },
    { "markVintfStability", "()V", (void*)android_os_Binder_markVintfStability},
    { "markVintfStability", "()V", (void*)android_os_Binder_markVintfStability},
    { "forceDowngradeToSystemStability", "()V", (void*)android_os_Binder_forceDowngradeToSystemStability},
    { "forceDowngradeToSystemStability", "()V", (void*)android_os_Binder_forceDowngradeToSystemStability},
@@ -1298,6 +1322,7 @@ static const JNINativeMethod gBinderMethods[] = {
    { "getNativeFinalizer", "()J", (void*)android_os_Binder_getNativeFinalizer },
    { "getNativeFinalizer", "()J", (void*)android_os_Binder_getNativeFinalizer },
    { "blockUntilThreadAvailable", "()V", (void*)android_os_Binder_blockUntilThreadAvailable },
    { "blockUntilThreadAvailable", "()V", (void*)android_os_Binder_blockUntilThreadAvailable },
    { "setExtensionNative", "(Landroid/os/IBinder;)V", (void*)android_os_Binder_setExtension },
    { "setExtensionNative", "(Landroid/os/IBinder;)V", (void*)android_os_Binder_setExtension },
    { "setInheritRt", "(Z)V", (void*)android_os_Binder_setInheritRt },
};
};
// clang-format on
// clang-format on


+4 −0
Original line number Original line Diff line number Diff line
@@ -1021,6 +1021,10 @@ public final class SystemServer implements Dumpable {
        // Start services.
        // Start services.
        try {
        try {
            t.traceBegin("StartServices");
            t.traceBegin("StartServices");
            if (android.server.Flags.allowSystemServerInheritRt()
                    && SystemProperties.getBoolean("sys.system_server_inherit_rt", false)) {
                Binder.setGlobalInheritRt(true);
            }
            startBootstrapServices(t);
            startBootstrapServices(t);
            startCoreServices(t);
            startCoreServices(t);
            startOtherServices(t);
            startOtherServices(t);
+7 −0
Original line number Original line Diff line number Diff line
@@ -95,3 +95,10 @@ flag {
     description: "Remove AdServicesManagerService from Wear"
     description: "Remove AdServicesManagerService from Wear"
     bug: "340928611"
     bug: "340928611"
}
}

flag {
    namespace: "wear_system_health"
    name: "allow_system_server_inherit_rt"
    description: "Allow enabling real-time priority inheritance for binder services within system_server"
    bug: "379851024"
}