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

Commit af445713 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix the SYSTEM_UID check in ConfirmSupervisionCredentialsActivity." into main

parents e846e95a 6f080505
Loading
Loading
Loading
Loading
+6 −7
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.os.Binder
import android.os.Bundle
import android.os.CancellationSignal
import android.os.Process
import android.os.UserHandle
import android.util.Log
import androidx.activity.result.contract.ActivityResultContracts
import androidx.annotation.OpenForTesting
@@ -99,7 +100,9 @@ open class ConfirmSupervisionCredentialsActivity : FragmentActivity() {
    public override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        if (!callerHasSupervisionRole() && !callerIsSystemUid()) {
            errorHandler()
            errorHandler(
                "Calling uid ${Binder.getCallingUid()} is not supervision role holder or SYSTEM_UID."
            )
            return
        }

@@ -179,11 +182,7 @@ open class ConfirmSupervisionCredentialsActivity : FragmentActivity() {

    private fun callerIsSystemUid(): Boolean {
        val callingUid = Binder.getCallingUid()
        if (callingUid != Process.SYSTEM_UID) {
            Log.w(TAG, "callingUid: $callingUid is not SYSTEM_UID")
            return false
        }
        return true
        return UserHandle.getAppId(callingUid) == Process.SYSTEM_UID
    }

    @RequiresPermission(anyOf = [INTERACT_ACROSS_USERS_FULL, MANAGE_USERS])
@@ -200,7 +199,7 @@ open class ConfirmSupervisionCredentialsActivity : FragmentActivity() {
    }

    private fun errorHandler(errStr: String? = null) {
        errStr?.let { Log.w(TAG, it) }
        errStr?.let { Log.e(TAG, it) }
        setResult(RESULT_CANCELED)
        finish()
    }
+3 −1
Original line number Diff line number Diff line
@@ -125,7 +125,9 @@ class ConfirmSupervisionCredentialsActivityTest {
    @Test
    @Config(sdk = [Build.VERSION_CODES.BAKLAVA])
    fun onCreate_callerIsSystemUid_doesNotFinish() {
        ShadowBinder.setCallingUid(Process.SYSTEM_UID)
        ShadowBinder.setCallingUid(
            UserHandle.getUid(/* userId= */ 2, /* appId= */ Process.SYSTEM_UID)
        )
        mockUserManager.stub { on { users } doReturn listOf(SUPERVISING_USER_INFO) }
        mockActivityManager.stub { on { startProfile(any()) } doReturn true }
        mockKeyguardManager.stub { on { isDeviceSecure(SUPERVISING_USER_ID) } doReturn true }