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

Commit 0800858b authored by Nikita Ioffe's avatar Nikita Ioffe Committed by Android (Google) Code Review
Browse files

Merge "Add Binder.getCallingUidOrThrow method"

parents 6948154e a929cf01
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -33707,6 +33707,7 @@ package android.os {
    method public static final void flushPendingCommands();
    method public static final int getCallingPid();
    method public static final int getCallingUid();
    method public static final int getCallingUidOrThrow();
    method public static final android.os.UserHandle getCallingUserHandle();
    method public java.lang.String getInterfaceDescriptor();
    method public boolean isBinderAlive();
+24 −0
Original line number Diff line number Diff line
@@ -272,6 +272,30 @@ public class Binder implements IBinder {
    @CriticalNative
    public static final native int getCallingUid();

    /**
     * Returns {@code true} if the current thread is currently executing an
     * incoming transaction.
     *
     * @hide
     */
    @CriticalNative
    public static final native boolean isHandlingTransaction();

    /**
     * Return the Linux uid assigned to the process that sent the transaction
     * currently being processed.
     *
     * @throws IllegalStateException if the current thread is not currently
     *        executing an incoming transaction.
     */
    public static final int getCallingUidOrThrow() {
        if (!isHandlingTransaction()) {
            throw new IllegalStateException(
                  "Thread is not in a binder transcation");
        }
        return getCallingUid();
    }

    /**
     * Return the UserHandle assigned to the process that sent you the
     * current transaction that is being processed.  This is the user
+7 −0
Original line number Diff line number Diff line
@@ -875,6 +875,11 @@ static jint android_os_Binder_getCallingUid()
    return IPCThreadState::self()->getCallingUid();
}

static jboolean android_os_Binder_isHandlingTransaction()
{
    return IPCThreadState::self()->isServingCall();
}

static jlong android_os_Binder_clearCallingIdentity()
{
    return IPCThreadState::self()->clearCallingIdentity();
@@ -960,6 +965,8 @@ static const JNINativeMethod gBinderMethods[] = {
    // @CriticalNative
    { "getCallingUid", "()I", (void*)android_os_Binder_getCallingUid },
    // @CriticalNative
    { "isHandlingTransaction", "()Z", (void*)android_os_Binder_isHandlingTransaction },
    // @CriticalNative
    { "clearCallingIdentity", "()J", (void*)android_os_Binder_clearCallingIdentity },
    { "restoreCallingIdentity", "(J)V", (void*)android_os_Binder_restoreCallingIdentity },
    // @CriticalNative
+9 −0
Original line number Diff line number Diff line
@@ -43,4 +43,13 @@ public class BinderTest extends TestCase {
        Binder.restoreCallingWorkSource(token);
        assertEquals(UID, Binder.getCallingWorkSourceUid());
    }

    @SmallTest
    public void testGetCallingUidOrThrow() throws Exception {
        try {
            Binder.getCallingUidOrThrow();
            throw new AssertionError("IllegalStateException expected");
        } catch (IllegalStateException expected) {
        }
    }
}