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

Commit 3fb8581f authored by Jacky Wang's avatar Jacky Wang
Browse files

[Catalyst] Provide pid for permission check

The pid is actually optional but provoide it for consistency.

Bug: 374115149
Flag: com.android.settings.flags.catalyst
Test: manual
Change-Id: I89daec8a60e961a6e98c769d0dbdbcffc1a6fcb4
parent ffdfbbda
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -38,11 +38,11 @@ abstract class GetPreferenceGraphApiHandler(

    override suspend fun invoke(
        application: Application,
        myUid: Int,
        callingPid: Int,
        callingUid: Int,
        request: GetPreferenceGraphRequest,
    ): PreferenceGraphProto {
        val builder = PreferenceGraphBuilder.of(application, myUid, callingUid, request)
        val builder = PreferenceGraphBuilder.of(application, callingPid, callingUid, request)
        if (request.screenKeys.isEmpty()) {
            for (key in PreferenceScreenRegistry.preferenceScreens.keys) {
                builder.addPreferenceScreenFromRegistry(key)
+4 −4
Original line number Diff line number Diff line
@@ -83,14 +83,14 @@ class PreferenceGetterApiHandler(

    override fun hasPermission(
        application: Application,
        myUid: Int,
        callingPid: Int,
        callingUid: Int,
        request: PreferenceGetterRequest,
    ) = permissionChecker.hasPermission(application, myUid, callingUid, request)
    ) = permissionChecker.hasPermission(application, callingPid, callingUid, request)

    override suspend fun invoke(
        application: Application,
        myUid: Int,
        callingPid: Int,
        callingUid: Int,
        request: PreferenceGetterRequest,
    ): PreferenceGetterResponse {
@@ -123,7 +123,7 @@ class PreferenceGetterApiHandler(
                    val preferenceProto =
                        metadata.toProto(
                            application,
                            myUid,
                            callingPid,
                            callingUid,
                            screenMetadata,
                            metadata.key == screenMetadata.key,
+16 −14
Original line number Diff line number Diff line
@@ -65,7 +65,7 @@ private const val TAG = "PreferenceGraphBuilder"
class PreferenceGraphBuilder
private constructor(
    private val context: Context,
    private val myUid: Int,
    private val callingPid: Int,
    private val callingUid: Int,
    private val request: GetPreferenceGraphRequest,
) {
@@ -81,7 +81,7 @@ private constructor(
        }
    }

    fun build() = builder.build()
    fun build(): PreferenceGraphProto = builder.build()

    /**
     * Adds an activity to the graph.
@@ -268,7 +268,9 @@ private constructor(
        metadata: PreferenceMetadata,
        isRoot: Boolean,
    ) =
        metadata.toProto(context, myUid, callingUid, screenMetadata, isRoot, request.flags).also {
        metadata
            .toProto(context, callingPid, callingUid, screenMetadata, isRoot, request.flags)
            .also {
                if (metadata is PreferenceScreenMetadata) {
                    @Suppress("CheckReturnValue") addPreferenceScreenMetadata(metadata)
                }
@@ -343,16 +345,16 @@ private constructor(
    companion object {
        suspend fun of(
            context: Context,
            myUid: Int,
            callingPid: Int,
            callingUid: Int,
            request: GetPreferenceGraphRequest,
        ) = PreferenceGraphBuilder(context, myUid, callingUid, request).also { it.init() }
        ) = PreferenceGraphBuilder(context, callingPid, callingUid, request).also { it.init() }
    }
}

fun PreferenceMetadata.toProto(
    context: Context,
    myUid: Int,
    callingPid: Int,
    callingUid: Int,
    screenMetadata: PreferenceScreenMetadata,
    isRoot: Boolean,
@@ -394,7 +396,7 @@ fun PreferenceMetadata.toProto(
                (!hasAvailable() || available) &&
                (!hasRestricted() || !restricted) &&
                metadata is PersistentPreference<*> &&
                metadata.getReadPermit(context, myUid, callingUid) == ReadWritePermit.ALLOW
                metadata.getReadPermit(context, callingPid, callingUid) == ReadWritePermit.ALLOW
        ) {
            value = preferenceValueProto {
                when (metadata) {
+4 −4
Original line number Diff line number Diff line
@@ -99,14 +99,14 @@ class PreferenceSetterApiHandler(

    override fun hasPermission(
        application: Application,
        myUid: Int,
        callingPid: Int,
        callingUid: Int,
        request: PreferenceSetterRequest,
    ) = permissionChecker.hasPermission(application, myUid, callingUid, request)
    ) = permissionChecker.hasPermission(application, callingPid, callingUid, request)

    override suspend fun invoke(
        application: Application,
        myUid: Int,
        callingPid: Int,
        callingUid: Int,
        request: PreferenceSetterRequest,
    ): Int {
@@ -127,7 +127,7 @@ class PreferenceSetterApiHandler(

        fun <T> PreferenceMetadata.checkWritePermit(value: T): Int {
            @Suppress("UNCHECKED_CAST") val preference = (this as PersistentPreference<T>)
            return when (preference.getWritePermit(application, value, myUid, callingUid)) {
            return when (preference.getWritePermit(application, value, callingPid, callingUid)) {
                ReadWritePermit.ALLOW -> PreferenceSetterResult.OK
                ReadWritePermit.DISALLOW -> PreferenceSetterResult.DISALLOW
                ReadWritePermit.REQUIRE_APP_PERMISSION ->
+2 −2
Original line number Diff line number Diff line
@@ -101,14 +101,14 @@ object EchoApiImpl : ApiHandler<String?, String?>,
                     ApiDescriptor<String?, String?> by EchoApi {
  override suspend fun invoke(
    application: Application,
    myUid: Int,
    callingPid: Int,
    callingUid: Int,
    request: String?,
  ): String? = request

  override fun hasPermission(
    application: Application,
    myUid: Int,
    callingPid: Int,
    callingUid: Int,
    request: String?,
  ): Boolean = (request?.length ?: 0) <= 5
Loading