[Catalyst] Fix calling pid/uid in PreferenceService
Bug: 379750656 Bug: 374115149 Flag: com.android.settingslib.flags.settings_catalyst Test: N/A Change-Id: Ia33141549faa68f3a9fca4648a88687974fab2e8
This commit is contained in:
@@ -19,7 +19,6 @@ package com.android.settings.service
|
|||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.os.Binder
|
import android.os.Binder
|
||||||
import android.os.OutcomeReceiver
|
import android.os.OutcomeReceiver
|
||||||
import android.os.Process
|
|
||||||
import android.service.settings.preferences.GetValueRequest
|
import android.service.settings.preferences.GetValueRequest
|
||||||
import android.service.settings.preferences.GetValueResult
|
import android.service.settings.preferences.GetValueResult
|
||||||
import android.service.settings.preferences.MetadataRequest
|
import android.service.settings.preferences.MetadataRequest
|
||||||
@@ -37,7 +36,6 @@ import kotlinx.coroutines.CoroutineScope
|
|||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.SupervisorJob
|
import kotlinx.coroutines.SupervisorJob
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import java.lang.Exception
|
|
||||||
|
|
||||||
class PreferenceService : SettingsPreferenceService() {
|
class PreferenceService : SettingsPreferenceService() {
|
||||||
|
|
||||||
@@ -49,14 +47,22 @@ class PreferenceService : SettingsPreferenceService() {
|
|||||||
|
|
||||||
override fun onGetAllPreferenceMetadata(
|
override fun onGetAllPreferenceMetadata(
|
||||||
request: MetadataRequest,
|
request: MetadataRequest,
|
||||||
callback: OutcomeReceiver<MetadataResult, Exception>
|
callback: OutcomeReceiver<MetadataResult, Exception>,
|
||||||
) {
|
) {
|
||||||
|
// MUST get pid/uid in binder thread
|
||||||
|
val callingPid = Binder.getCallingPid()
|
||||||
|
val callingUid = Binder.getCallingUid()
|
||||||
scope.launch {
|
scope.launch {
|
||||||
val graphProto = graphApi.invoke(application, Process.myUid(), Binder.getCallingUid(),
|
val graphProto =
|
||||||
GetPreferenceGraphRequest(
|
graphApi.invoke(
|
||||||
includeValue = false,
|
application,
|
||||||
flags = PreferenceGetterFlags.METADATA
|
callingPid,
|
||||||
))
|
callingUid,
|
||||||
|
GetPreferenceGraphRequest(
|
||||||
|
includeValue = false,
|
||||||
|
flags = PreferenceGetterFlags.METADATA,
|
||||||
|
),
|
||||||
|
)
|
||||||
val result = transformCatalystGetMetadataResponse(this@PreferenceService, graphProto)
|
val result = transformCatalystGetMetadataResponse(this@PreferenceService, graphProto)
|
||||||
callback.onResult(result)
|
callback.onResult(result)
|
||||||
}
|
}
|
||||||
@@ -64,17 +70,16 @@ class PreferenceService : SettingsPreferenceService() {
|
|||||||
|
|
||||||
override fun onGetPreferenceValue(
|
override fun onGetPreferenceValue(
|
||||||
request: GetValueRequest,
|
request: GetValueRequest,
|
||||||
callback: OutcomeReceiver<GetValueResult, Exception>
|
callback: OutcomeReceiver<GetValueResult, Exception>,
|
||||||
) {
|
) {
|
||||||
|
// MUST get pid/uid in binder thread
|
||||||
|
val callingPid = Binder.getCallingPid()
|
||||||
|
val callingUid = Binder.getCallingUid()
|
||||||
scope.launch {
|
scope.launch {
|
||||||
val apiRequest = transformFrameworkGetValueRequest(request)
|
val apiRequest = transformFrameworkGetValueRequest(request)
|
||||||
val response = getApiHandler.invoke(application, Process.myUid(),
|
val response = getApiHandler.invoke(application, callingPid, callingUid, apiRequest)
|
||||||
Binder.getCallingUid(), apiRequest)
|
val result =
|
||||||
val result = transformCatalystGetValueResponse(
|
transformCatalystGetValueResponse(this@PreferenceService, request, response)
|
||||||
this@PreferenceService,
|
|
||||||
request,
|
|
||||||
response
|
|
||||||
)
|
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
callback.onError(IllegalStateException("No response"))
|
callback.onError(IllegalStateException("No response"))
|
||||||
} else {
|
} else {
|
||||||
@@ -85,8 +90,11 @@ class PreferenceService : SettingsPreferenceService() {
|
|||||||
|
|
||||||
override fun onSetPreferenceValue(
|
override fun onSetPreferenceValue(
|
||||||
request: SetValueRequest,
|
request: SetValueRequest,
|
||||||
callback: OutcomeReceiver<SetValueResult, Exception>
|
callback: OutcomeReceiver<SetValueResult, Exception>,
|
||||||
) {
|
) {
|
||||||
|
// MUST get pid/uid in binder thread
|
||||||
|
val callingPid = Binder.getCallingPid()
|
||||||
|
val callingUid = Binder.getCallingUid()
|
||||||
scope.launch {
|
scope.launch {
|
||||||
val apiRequest = transformFrameworkSetValueRequest(request)
|
val apiRequest = transformFrameworkSetValueRequest(request)
|
||||||
if (apiRequest == null) {
|
if (apiRequest == null) {
|
||||||
@@ -94,8 +102,7 @@ class PreferenceService : SettingsPreferenceService() {
|
|||||||
SetValueResult.Builder(SetValueResult.RESULT_INVALID_REQUEST).build()
|
SetValueResult.Builder(SetValueResult.RESULT_INVALID_REQUEST).build()
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
val response = setApiHandler.invoke(application, Process.myUid(),
|
val response = setApiHandler.invoke(application, callingPid, callingUid, apiRequest)
|
||||||
Binder.getCallingUid(), apiRequest)
|
|
||||||
|
|
||||||
callback.onResult(transformCatalystSetValueResponse(response))
|
callback.onResult(transformCatalystSetValueResponse(response))
|
||||||
}
|
}
|
||||||
@@ -106,9 +113,9 @@ class PreferenceService : SettingsPreferenceService() {
|
|||||||
private class GraphProvider(override val id: Int) : GetPreferenceGraphApiHandler(emptySet()) {
|
private class GraphProvider(override val id: Int) : GetPreferenceGraphApiHandler(emptySet()) {
|
||||||
override fun hasPermission(
|
override fun hasPermission(
|
||||||
application: Application,
|
application: Application,
|
||||||
myUid: Int,
|
callingPid: Int,
|
||||||
callingUid: Int,
|
callingUid: Int,
|
||||||
request: GetPreferenceGraphRequest
|
request: GetPreferenceGraphRequest,
|
||||||
) = true
|
) = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user