mirror of
https://gitee.com/openharmony/multimedia_audio_standard
synced 2024-12-11 14:46:40 +00:00
User access control requirement
Signed-off-by: Geevarghese V K <geevarghese.v.k1@huawei.com>
This commit is contained in:
parent
06ba7986d2
commit
7976fdc097
@ -234,7 +234,7 @@ napi_value AudioCapturerNapi::Construct(napi_env env, napi_callback_info info)
|
||||
capturerNapi->capturerFlags_ = sAudioCapturerOptions_->capturerInfo.capturerFlags;
|
||||
std::shared_ptr<AbilityRuntime::Context> abilityContext = GetAbilityContext(env);
|
||||
if (abilityContext != nullptr) {
|
||||
capturerNapi->audioCapturer_ = AudioCapturer::Create(abilityContext->GetCacheDir(), *sAudioCapturerOptions_);
|
||||
capturerNapi->audioCapturer_ = AudioCapturer::Create(*sAudioCapturerOptions_, abilityContext->GetCacheDir());
|
||||
} else {
|
||||
capturerNapi->audioCapturer_ = AudioCapturer::Create(*sAudioCapturerOptions_);
|
||||
}
|
||||
|
@ -49,10 +49,11 @@ public:
|
||||
std::shared_ptr<AudioStream> audioStream_;
|
||||
AudioCapturerInfo capturerInfo_ = {};
|
||||
|
||||
explicit AudioCapturerPrivate(AudioStreamType audioStreamType);
|
||||
AudioCapturerPrivate(AudioStreamType audioStreamType, const AppInfo &appInfo);
|
||||
virtual ~AudioCapturerPrivate();
|
||||
private:
|
||||
std::shared_ptr<AudioStreamCallback> audioStreamCallback_ = nullptr;
|
||||
AppInfo appInfo_;
|
||||
};
|
||||
|
||||
class AudioStreamCallbackCapturer : public AudioStreamCallback {
|
||||
|
@ -27,16 +27,34 @@ AudioCapturerPrivate::~AudioCapturerPrivate() = default;
|
||||
|
||||
std::unique_ptr<AudioCapturer> AudioCapturer::Create(AudioStreamType audioStreamType)
|
||||
{
|
||||
return std::make_unique<AudioCapturerPrivate>(audioStreamType);
|
||||
AppInfo appInfo = {};
|
||||
return Create(audioStreamType, appInfo);
|
||||
}
|
||||
|
||||
std::unique_ptr<AudioCapturer> AudioCapturer::Create(const AudioCapturerOptions &capturerOptions)
|
||||
std::unique_ptr<AudioCapturer> AudioCapturer::Create(AudioStreamType audioStreamType, const AppInfo &appInfo)
|
||||
{
|
||||
return Create("", capturerOptions);
|
||||
return std::make_unique<AudioCapturerPrivate>(audioStreamType, appInfo);
|
||||
}
|
||||
|
||||
std::unique_ptr<AudioCapturer> AudioCapturer::Create(const std::string cachePath,
|
||||
const AudioCapturerOptions &capturerOptions)
|
||||
std::unique_ptr<AudioCapturer> AudioCapturer::Create(const AudioCapturerOptions &options)
|
||||
{
|
||||
AppInfo appInfo = {};
|
||||
return Create(options, "", appInfo);
|
||||
}
|
||||
|
||||
std::unique_ptr<AudioCapturer> AudioCapturer::Create(const AudioCapturerOptions &options, const AppInfo &appInfo)
|
||||
{
|
||||
return Create(options, "", appInfo);
|
||||
}
|
||||
|
||||
std::unique_ptr<AudioCapturer> AudioCapturer::Create(const AudioCapturerOptions &options, const std::string cachePath)
|
||||
{
|
||||
AppInfo appInfo = {};
|
||||
return Create(options, cachePath, appInfo);
|
||||
}
|
||||
|
||||
std::unique_ptr<AudioCapturer> AudioCapturer::Create(const AudioCapturerOptions &capturerOptions,
|
||||
const std::string cachePath, const AppInfo &appInfo)
|
||||
{
|
||||
auto sourceType = capturerOptions.capturerInfo.sourceType;
|
||||
if (sourceType < SOURCE_TYPE_MIC || sourceType > SOURCE_TYPE_VOICE_CALL) {
|
||||
@ -54,7 +72,7 @@ std::unique_ptr<AudioCapturer> AudioCapturer::Create(const std::string cachePath
|
||||
params.audioChannel = capturerOptions.streamInfo.channels;
|
||||
params.audioEncoding = capturerOptions.streamInfo.encoding;
|
||||
|
||||
auto capturer = std::make_unique<AudioCapturerPrivate>(audioStreamType);
|
||||
auto capturer = std::make_unique<AudioCapturerPrivate>(audioStreamType, appInfo);
|
||||
if (capturer == nullptr) {
|
||||
return capturer;
|
||||
}
|
||||
@ -75,9 +93,10 @@ std::unique_ptr<AudioCapturer> AudioCapturer::Create(const std::string cachePath
|
||||
return capturer;
|
||||
}
|
||||
|
||||
AudioCapturerPrivate::AudioCapturerPrivate(AudioStreamType audioStreamType)
|
||||
AudioCapturerPrivate::AudioCapturerPrivate(AudioStreamType audioStreamType, const AppInfo &appInfo)
|
||||
{
|
||||
audioStream_ = std::make_shared<AudioStream>(audioStreamType, AUDIO_MODE_RECORD);
|
||||
appInfo_ = appInfo;
|
||||
}
|
||||
|
||||
int32_t AudioCapturerPrivate::GetFrameCount(uint32_t &frameCount) const
|
||||
@ -87,6 +106,11 @@ int32_t AudioCapturerPrivate::GetFrameCount(uint32_t &frameCount) const
|
||||
|
||||
int32_t AudioCapturerPrivate::SetParams(const AudioCapturerParams params) const
|
||||
{
|
||||
if (!audioStream_->VerifyClientPermission(MICROPHONE_PERMISSION, appInfo_.appTokenId)) {
|
||||
AUDIO_ERR_LOG("MICROPHONE permission denied for %{public}d", appInfo_.appTokenId);
|
||||
return ERR_PERMISSION_DENIED;
|
||||
}
|
||||
|
||||
AudioStreamParams audioStreamParams;
|
||||
audioStreamParams.format = params.audioSampleFormat;
|
||||
audioStreamParams.samplingRate = params.samplingRate;
|
||||
|
@ -97,9 +97,14 @@ public:
|
||||
|
||||
int32_t GetSessionInfoInFocus(AudioInterrupt &audioInterrupt);
|
||||
|
||||
int32_t SetVolumeKeyEventCallback(const int32_t clientPid,
|
||||
const std::shared_ptr<VolumeKeyEventCallback> &callback);
|
||||
int32_t SetVolumeKeyEventCallback(const int32_t clientPid, const std::shared_ptr<VolumeKeyEventCallback> &callback);
|
||||
|
||||
int32_t UnsetVolumeKeyEventCallback(const int32_t clientPid);
|
||||
|
||||
bool VerifyClientPermission(const std::string &permissionName);
|
||||
|
||||
bool VerifyClientPermission(const std::string &permissionName, uint32_t appTokenId);
|
||||
|
||||
private:
|
||||
AudioPolicyManager()
|
||||
{
|
||||
|
@ -35,6 +35,7 @@ public:
|
||||
|
||||
int32_t SetAudioStreamInfo(const AudioStreamParams info);
|
||||
int32_t GetAudioStreamInfo(AudioStreamParams &info);
|
||||
bool VerifyClientPermission(const std::string &permissionName, uint32_t appTokenId);
|
||||
|
||||
int32_t GetAudioSessionID(uint32_t &sessionID) const;
|
||||
State GetState();
|
||||
|
@ -101,25 +101,64 @@ public:
|
||||
class AudioCapturer {
|
||||
public:
|
||||
/**
|
||||
* @brief creater capturer instance.
|
||||
* @brief create capturer instance.
|
||||
*
|
||||
* @param options The audio capturer configuration to be used while creating capturer instance.
|
||||
* refer AudioCapturerOptions in audio_info.h.
|
||||
* @return Returns unique pointer to the AudioCapturer object
|
||||
*/
|
||||
static std::unique_ptr<AudioCapturer> Create(AudioStreamType audioStreamType);
|
||||
|
||||
/**
|
||||
* @brief creater capturer instance.
|
||||
* @brief create capturer instance.
|
||||
*
|
||||
* @param options The audio capturer configuration to be used while creating capturer instance.
|
||||
* refer AudioCapturerOptions in audio_info.h.
|
||||
* @param appInfo Originating application's uid and token id can be passed here
|
||||
* @return Returns unique pointer to the AudioCapturer object
|
||||
*/
|
||||
static std::unique_ptr<AudioCapturer> Create(const AudioCapturerOptions &capturerOptions);
|
||||
static std::unique_ptr<AudioCapturer> Create(AudioStreamType audioStreamType, const AppInfo &appInfo);
|
||||
|
||||
/**
|
||||
* @brief create capturer instance.
|
||||
*
|
||||
* @param cachePath Application cache path
|
||||
* @param capturerOptions The audio capturer configuration to be used while creating capturer instance.
|
||||
* @param options The audio capturer configuration to be used while creating capturer instance.
|
||||
* refer AudioCapturerOptions in audio_info.h.
|
||||
* @return Returns unique pointer to the AudioCapturer object
|
||||
*/
|
||||
static std::unique_ptr<AudioCapturer> Create(const std::string cachePath,
|
||||
const AudioCapturerOptions &capturerOptions);
|
||||
static std::unique_ptr<AudioCapturer> Create(const AudioCapturerOptions &options);
|
||||
|
||||
/**
|
||||
* @brief create capturer instance.
|
||||
*
|
||||
* @param options The audio capturer configuration to be used while creating capturer instance.
|
||||
* refer AudioCapturerOptions in audio_info.h.
|
||||
* @param appInfo Originating application's uid and token id can be passed here
|
||||
* @return Returns unique pointer to the AudioCapturer object
|
||||
*/
|
||||
static std::unique_ptr<AudioCapturer> Create(const AudioCapturerOptions &options, const AppInfo &appInfo);
|
||||
|
||||
/**
|
||||
* @brief create capturer instance.
|
||||
*
|
||||
* @param options The audio capturer configuration to be used while creating capturer instance.
|
||||
* refer AudioCapturerOptions in audio_info.h.
|
||||
* @param cachePath Application cache path
|
||||
* @return Returns unique pointer to the AudioCapturer object
|
||||
*/
|
||||
static std::unique_ptr<AudioCapturer> Create(const AudioCapturerOptions &options, const std::string cachePath);
|
||||
|
||||
/**
|
||||
* @brief create capturer instance.
|
||||
*
|
||||
* @param capturerOptions The audio capturer configuration to be used while creating capturer instance.
|
||||
* refer AudioCapturerOptions in audio_info.h.
|
||||
* @param cachePath Application cache path
|
||||
* @param appInfo Originating application's uid and token id can be passed here
|
||||
* @return Returns unique pointer to the AudioCapturer object
|
||||
*/
|
||||
static std::unique_ptr<AudioCapturer> Create(const AudioCapturerOptions &options, const std::string cachePath,
|
||||
const AppInfo &appInfo);
|
||||
|
||||
/**
|
||||
* @brief Sets audio capture parameters.
|
||||
|
@ -118,6 +118,9 @@ const int32_t ERR_FOCUS_DENIED = BASE_AUDIO_ERR_OFFSET - 18;
|
||||
/** incorrect render/capture mode */
|
||||
const int32_t ERR_INCORRECT_MODE = BASE_AUDIO_ERR_OFFSET - 19;
|
||||
|
||||
/** incorrect render/capture mode */
|
||||
const int32_t ERR_PERMISSION_DENIED = BASE_AUDIO_ERR_OFFSET - 20;
|
||||
|
||||
/** Unknown error */
|
||||
const int32_t ERR_UNKNOWN = BASE_AUDIO_ERR_OFFSET - 200;
|
||||
} // namespace AudioStandard
|
||||
|
@ -33,6 +33,10 @@ constexpr int32_t MINIMUM_BUFFER_SIZE_MSEC = 5;
|
||||
constexpr int32_t MAXIMUM_BUFFER_SIZE_MSEC = 20;
|
||||
constexpr int32_t MIN_SERVICE_COUNT = 2;
|
||||
|
||||
const std::string MICROPHONE_PERMISSION = "ohos.permission.MICROPHONE";
|
||||
const std::string MODIFY_AUDIO_SETTINGS_PERMISSION = "ohos.permission.MODIFY_AUDIO_SETTINGS";
|
||||
const std::string ACCESS_NOTIFICATION_POLICY_PERMISSION = "ohos.permission.ACCESS_NOTIFICATION_POLICY";
|
||||
|
||||
enum DeviceFlag {
|
||||
/**
|
||||
* Device flag none.
|
||||
@ -451,6 +455,11 @@ struct AudioCapturerOptions {
|
||||
AudioCapturerInfo capturerInfo;
|
||||
};
|
||||
|
||||
struct AppInfo {
|
||||
int32_t appUid { 0 };
|
||||
uint32_t appTokenId { 0 };
|
||||
};
|
||||
|
||||
// Supported audio parameters for both renderer and capturer
|
||||
const std::vector<AudioSampleFormat> AUDIO_SUPPORTED_FORMATS {
|
||||
SAMPLE_U8,
|
||||
|
@ -193,7 +193,7 @@ public:
|
||||
int32_t SetDeviceActive(ActiveDeviceType deviceType, bool flag) const;
|
||||
bool IsDeviceActive(ActiveDeviceType deviceType) const;
|
||||
bool IsStreamActive(AudioSystemManager::AudioVolumeType volumeType) const;
|
||||
bool SetRingerMode(AudioRingerMode ringMode) const;
|
||||
int32_t SetRingerMode(AudioRingerMode ringMode) const;
|
||||
AudioRingerMode GetRingerMode() const;
|
||||
int32_t SetAudioScene(const AudioScene &scene);
|
||||
AudioScene GetAudioScene() const;
|
||||
|
@ -201,6 +201,7 @@ ohos_shared_library("audio_policy_service") {
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"input:libmmi-client",
|
||||
"ipc:ipc_core",
|
||||
|
@ -112,7 +112,7 @@ public:
|
||||
IS_MICROPHONE_MUTE = 6,
|
||||
SET_AUDIO_SCENE = 7,
|
||||
UPDATE_ROUTE_REQ = 8,
|
||||
RETRIEVE_COOKIE = 9,
|
||||
RETRIEVE_COOKIE = 9
|
||||
};
|
||||
|
||||
public:
|
||||
@ -123,7 +123,6 @@ class AudioManagerStub : public IRemoteStub<IStandardAudioService> {
|
||||
public:
|
||||
virtual int OnRemoteRequest(uint32_t code, MessageParcel &data,
|
||||
MessageParcel &reply, MessageOption &option) override;
|
||||
bool IsPermissionValid();
|
||||
};
|
||||
} // namespace AudioStandard
|
||||
} // namespace OHOS
|
||||
|
@ -85,6 +85,8 @@ public:
|
||||
virtual int32_t SetVolumeKeyEventCallback(const int32_t clientPid, const sptr<IRemoteObject> &object) = 0;
|
||||
|
||||
virtual int32_t UnsetVolumeKeyEventCallback(const int32_t clientPid) = 0;
|
||||
|
||||
virtual bool VerifyClientPermission(const std::string &permissionName, uint32_t appTokenId) = 0;
|
||||
public:
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"IAudioPolicy");
|
||||
};
|
||||
|
@ -24,7 +24,6 @@ class AudioPolicyManagerStub : public IRemoteStub<IAudioPolicy> {
|
||||
public:
|
||||
virtual int32_t OnRemoteRequest(uint32_t code, MessageParcel &data,
|
||||
MessageParcel &reply, MessageOption &option) override;
|
||||
bool IsPermissionValid();
|
||||
|
||||
private:
|
||||
void SetStreamVolumeInternal(MessageParcel &data, MessageParcel &reply);
|
||||
@ -58,6 +57,7 @@ private:
|
||||
void GetDevicesInternal(MessageParcel &data, MessageParcel &reply);
|
||||
void SetDeviceChangeCallbackInternal(MessageParcel &data, MessageParcel &reply);
|
||||
void UnsetDeviceChangeCallbackInternal(MessageParcel &data, MessageParcel &reply);
|
||||
void VerifyClientPermissionInternal(MessageParcel &data, MessageParcel &reply);
|
||||
};
|
||||
} // namespace AudioStandard
|
||||
} // namespace OHOS
|
||||
|
@ -81,6 +81,8 @@ public:
|
||||
AudioStreamType GetStreamInFocus() override;
|
||||
|
||||
int32_t GetSessionInfoInFocus(AudioInterrupt &audioInterrupt) override;
|
||||
|
||||
bool VerifyClientPermission(const std::string &permissionName, uint32_t appTokenId) override;
|
||||
private:
|
||||
static inline BrokerDelegator<AudioPolicyProxy> mDdelegator;
|
||||
void WriteAudioInteruptParams(MessageParcel &parcel, const AudioInterrupt &audioInterrupt);
|
||||
|
@ -48,7 +48,8 @@ enum AudioPolicyCommand {
|
||||
UNSET_VOLUME_KEY_EVENT_CALLBACK,
|
||||
GET_DEVICES,
|
||||
SET_DEVICE_CHANGE_CALLBACK,
|
||||
UNSET_DEVICE_CHANGE_CALLBACK
|
||||
UNSET_DEVICE_CHANGE_CALLBACK,
|
||||
QUERY_PERMISSION
|
||||
};
|
||||
} // namespace AudioStandard
|
||||
} // namespace OHOS
|
||||
|
@ -102,6 +102,8 @@ public:
|
||||
void OnSessionRemoved(const uint32_t sessionID) override;
|
||||
|
||||
int32_t Dump(int32_t fd, const std::vector<std::u16string> &args) override;
|
||||
|
||||
bool VerifyClientPermission(const std::string &permissionName, uint32_t appTokenId) override;
|
||||
protected:
|
||||
void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
|
||||
void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
|
||||
@ -148,6 +150,8 @@ private:
|
||||
static constexpr int32_t SECOND_PRIORITY = 2;
|
||||
static constexpr int32_t THIRD_PRIORITY = 3;
|
||||
static constexpr int32_t VOLUME_KEY_DURATION = 0;
|
||||
static constexpr int32_t ROOT_UID = 0;
|
||||
static constexpr int32_t MEDIA_SERVICE_UID = 1013;
|
||||
};
|
||||
} // namespace AudioStandard
|
||||
} // namespace OHOS
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include <audio_timer.h>
|
||||
|
||||
#include "audio_capturer.h"
|
||||
#include "audio_policy_manager.h"
|
||||
#include "audio_renderer.h"
|
||||
#include "audio_system_manager.h"
|
||||
|
||||
@ -486,6 +487,13 @@ public:
|
||||
*/
|
||||
void SetApplicationCachePath(const std::string cachePath);
|
||||
|
||||
/**
|
||||
* @brief Verifies the clients permsiion based on appTokenId
|
||||
*
|
||||
* @return Retruns whether the authentication was success or not
|
||||
*/
|
||||
bool VerifyClientPermission(const std::string &permissionName, uint32_t appTokenId);
|
||||
|
||||
// Audio timer callback
|
||||
virtual void OnTimeOut();
|
||||
|
||||
@ -585,6 +593,7 @@ private:
|
||||
static const int32_t AUDIO_CLIENT_READ_STREAM_ERR = -6;
|
||||
static const int32_t AUDIO_CLIENT_WRITE_STREAM_ERR = -7;
|
||||
static const int32_t AUDIO_CLIENT_PA_ERR = -8;
|
||||
static const int32_t AUDIO_CLIENT_PERMISSION_ERR = -9;
|
||||
|
||||
// Default values
|
||||
static const uint32_t MINIMUM_BUFFER_SIZE = 1024;
|
||||
|
@ -316,5 +316,15 @@ int32_t AudioPolicyManager::UnsetVolumeKeyEventCallback(const int32_t clientPid)
|
||||
{
|
||||
return g_sProxy->UnsetVolumeKeyEventCallback(clientPid);
|
||||
}
|
||||
|
||||
bool AudioPolicyManager::VerifyClientPermission(const std::string &permissionName)
|
||||
{
|
||||
return VerifyClientPermission(permissionName, 0);
|
||||
}
|
||||
|
||||
bool AudioPolicyManager::VerifyClientPermission(const std::string &permissionName, uint32_t appTokenId)
|
||||
{
|
||||
return g_sProxy->VerifyClientPermission(permissionName, appTokenId);
|
||||
}
|
||||
} // namespace AudioStandard
|
||||
} // namespace OHOS
|
||||
|
@ -634,5 +634,30 @@ int32_t AudioPolicyProxy::UnsetVolumeKeyEventCallback(const int32_t clientPid)
|
||||
|
||||
return reply.ReadInt32();
|
||||
}
|
||||
|
||||
bool AudioPolicyProxy::VerifyClientPermission(const std::string &permissionName, uint32_t appTokenId)
|
||||
{
|
||||
AUDIO_ERR_LOG("VerifyClientPermission [permission : %{public}s] | [tid : %{public}d]",
|
||||
permissionName.c_str(), appTokenId);
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
AUDIO_ERR_LOG("VerifyClientPermission: WriteInterfaceToken failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
data.WriteString(permissionName);
|
||||
data.WriteUint32(appTokenId);
|
||||
|
||||
int result = Remote()->SendRequest(QUERY_PERMISSION, data, reply, option);
|
||||
if (result != ERR_NONE) {
|
||||
AUDIO_ERR_LOG("VerifyClientPermission failed, result: %{public}d", result);
|
||||
return false;
|
||||
}
|
||||
|
||||
return reply.ReadBool();
|
||||
}
|
||||
} // namespace AudioStandard
|
||||
} // namespace OHOS
|
||||
|
@ -290,6 +290,14 @@ void AudioPolicyManagerStub::UnsetVolumeKeyEventCallbackInternal(MessageParcel &
|
||||
reply.WriteInt32(ret);
|
||||
}
|
||||
|
||||
void AudioPolicyManagerStub::VerifyClientPermissionInternal(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
std::string permissionName = data.ReadString();
|
||||
uint32_t appTokenId = data.ReadUint32();
|
||||
bool ret = VerifyClientPermission(permissionName, appTokenId);
|
||||
reply.WriteBool(ret);
|
||||
}
|
||||
|
||||
int AudioPolicyManagerStub::OnRemoteRequest(
|
||||
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
@ -410,16 +418,15 @@ int AudioPolicyManagerStub::OnRemoteRequest(
|
||||
GetDevicesInternal(data, reply);
|
||||
break;
|
||||
|
||||
case QUERY_PERMISSION:
|
||||
VerifyClientPermissionInternal(data, reply);
|
||||
break;
|
||||
|
||||
default:
|
||||
AUDIO_ERR_LOG("default case, need check AudioPolicyManagerStub");
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
return AUDIO_OK;
|
||||
}
|
||||
|
||||
bool AudioPolicyManagerStub::IsPermissionValid()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
} // namespace audio_policy
|
||||
} // namespace OHOS
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "key_event.h"
|
||||
#include "key_option.h"
|
||||
|
||||
#include "accesstoken_kit.h"
|
||||
#include "audio_log.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "iservice_registry.h"
|
||||
@ -938,6 +939,38 @@ int32_t AudioPolicyServer::UnsetVolumeKeyEventCallback(const int32_t clientPid)
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
bool AudioPolicyServer::VerifyClientPermission(const std::string &permissionName, uint32_t appTokenId)
|
||||
{
|
||||
auto callerUid = IPCSkeleton::GetCallingUid();
|
||||
AUDIO_INFO_LOG("==[%{public}s] [tid:%{public}d] [uid:%{public}d]==", permissionName.c_str(), appTokenId, callerUid);
|
||||
|
||||
// Root users should be whitelisted
|
||||
if (callerUid == ROOT_UID) {
|
||||
AUDIO_INFO_LOG("Root user. Permission GRANTED!!!");
|
||||
return true;
|
||||
}
|
||||
|
||||
Security::AccessToken::AccessTokenID clientTokenId = 0;
|
||||
// Special handling required for media service
|
||||
if (callerUid == MEDIA_SERVICE_UID) {
|
||||
if (appTokenId == 0) {
|
||||
AUDIO_ERR_LOG("Invalid token received. Permission rejected");
|
||||
return false;
|
||||
}
|
||||
clientTokenId = appTokenId;
|
||||
} else {
|
||||
clientTokenId = IPCSkeleton::GetCallingTokenID();
|
||||
}
|
||||
|
||||
int res = Security::AccessToken::AccessTokenKit::VerifyAccessToken(clientTokenId, permissionName);
|
||||
if (res != Security::AccessToken::PermissionState::PERMISSION_GRANTED) {
|
||||
AUDIO_ERR_LOG("Permission denied [tid:%{public}d]", clientTokenId);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
float AudioPolicyServer::MapVolumeToHDI(int32_t volume)
|
||||
{
|
||||
float value = (float)volume / MAX_VOLUME_LEVEL;
|
||||
|
@ -568,6 +568,16 @@ void AudioServiceClient::SetApplicationCachePath(const std::string cachePath)
|
||||
cachePath_ = cachePath;
|
||||
}
|
||||
|
||||
bool AudioServiceClient::VerifyClientPermission(const std::string &permissionName, uint32_t appTokenId)
|
||||
{ // for capturer check for MICROPHONE PERMISSION
|
||||
if (!AudioPolicyManager::GetInstance().VerifyClientPermission(permissionName, appTokenId)) {
|
||||
AUDIO_DEBUG_LOG("Client doesn't have MICROPHONE permission");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t AudioServiceClient::Initialize(ASClientType eClientType)
|
||||
{
|
||||
int error = PA_ERR_INTERNAL;
|
||||
|
@ -242,6 +242,11 @@ int32_t AudioStream::GetAudioStreamInfo(AudioStreamParams &audioStreamInfo)
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
bool AudioStream::VerifyClientPermission(const std::string &permissionName, uint32_t appTokenId)
|
||||
{
|
||||
return AudioServiceClient::VerifyClientPermission(permissionName, appTokenId);
|
||||
}
|
||||
|
||||
int32_t AudioStream::SetAudioStreamInfo(const AudioStreamParams info)
|
||||
{
|
||||
AUDIO_INFO_LOG("AudioStream: SetAudioParams");
|
||||
|
@ -142,8 +142,15 @@ void AudioSystemManager::init()
|
||||
}
|
||||
}
|
||||
|
||||
bool AudioSystemManager::SetRingerMode(AudioRingerMode ringMode) const
|
||||
int32_t AudioSystemManager::SetRingerMode(AudioRingerMode ringMode) const
|
||||
{
|
||||
if (ringMode == AudioRingerMode::RINGER_MODE_SILENT) {
|
||||
if (!AudioPolicyManager::GetInstance().VerifyClientPermission(ACCESS_NOTIFICATION_POLICY_PERMISSION)) {
|
||||
AUDIO_ERR_LOG("Access policy permission denied for ringerMode : %{public}d", ringMode);
|
||||
return ERR_PERMISSION_DENIED;
|
||||
}
|
||||
}
|
||||
|
||||
/* Call Audio Policy SetRingerMode */
|
||||
return AudioPolicyManager::GetInstance().SetRingerMode(ringMode);
|
||||
}
|
||||
@ -221,6 +228,11 @@ const std::string AudioSystemManager::GetAudioParameter(const std::string key) c
|
||||
void AudioSystemManager::SetAudioParameter(const std::string &key, const std::string &value) const
|
||||
{
|
||||
CHECK_AND_RETURN_LOG(g_sProxy != nullptr, "SetAudioParameter::Audio service unavailable");
|
||||
if (!AudioPolicyManager::GetInstance().VerifyClientPermission(MODIFY_AUDIO_SETTINGS_PERMISSION)) {
|
||||
AUDIO_ERR_LOG("SetAudioParameter: MODIFY_AUDIO_SETTINGS permission denied");
|
||||
return;
|
||||
}
|
||||
|
||||
g_sProxy->SetAudioParameter(key, value);
|
||||
}
|
||||
|
||||
@ -232,6 +244,13 @@ const char *AudioSystemManager::RetrieveCookie(int32_t &size) const
|
||||
|
||||
int32_t AudioSystemManager::SetVolume(AudioSystemManager::AudioVolumeType volumeType, int32_t volume) const
|
||||
{
|
||||
if (volumeType == AudioVolumeType::STREAM_RING) {
|
||||
if (!AudioPolicyManager::GetInstance().VerifyClientPermission(ACCESS_NOTIFICATION_POLICY_PERMISSION)) {
|
||||
AUDIO_ERR_LOG("Access policy permission denied for volume type : %{public}d", volumeType);
|
||||
return ERR_PERMISSION_DENIED;
|
||||
}
|
||||
}
|
||||
|
||||
/* Validate and return INVALID_PARAMS error */
|
||||
if ((volume < MIN_VOLUME_LEVEL) || (volume > MAX_VOLUME_LEVEL)) {
|
||||
AUDIO_ERR_LOG("Invalid Volume Input!");
|
||||
@ -305,6 +324,13 @@ int32_t AudioSystemManager::GetMinVolume(AudioSystemManager::AudioVolumeType vol
|
||||
|
||||
int32_t AudioSystemManager::SetMute(AudioSystemManager::AudioVolumeType volumeType, bool mute) const
|
||||
{
|
||||
if (volumeType == AudioVolumeType::STREAM_RING) {
|
||||
if (!AudioPolicyManager::GetInstance().VerifyClientPermission(ACCESS_NOTIFICATION_POLICY_PERMISSION)) {
|
||||
AUDIO_ERR_LOG("Access policy permission denied for volume type : %{public}d", volumeType);
|
||||
return ERR_PERMISSION_DENIED;
|
||||
}
|
||||
}
|
||||
|
||||
switch (volumeType) {
|
||||
case STREAM_MUSIC:
|
||||
case STREAM_RING:
|
||||
@ -325,6 +351,12 @@ int32_t AudioSystemManager::SetMute(AudioSystemManager::AudioVolumeType volumeTy
|
||||
bool AudioSystemManager::IsStreamMute(AudioSystemManager::AudioVolumeType volumeType) const
|
||||
{
|
||||
AUDIO_DEBUG_LOG("AudioSystemManager::GetMute Client");
|
||||
if (volumeType == AudioVolumeType::STREAM_RING) {
|
||||
if (!AudioPolicyManager::GetInstance().VerifyClientPermission(ACCESS_NOTIFICATION_POLICY_PERMISSION)) {
|
||||
AUDIO_ERR_LOG("Access policy permission denied for volume type : %{public}d", volumeType);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
switch (volumeType) {
|
||||
case STREAM_MUSIC:
|
||||
@ -383,12 +415,22 @@ int32_t AudioSystemManager::UnsetRingerModeCallback(const int32_t clientId) cons
|
||||
int32_t AudioSystemManager::SetMicrophoneMute(bool isMute) const
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(g_sProxy != nullptr, ERR_OPERATION_FAILED, "SetMicrophoneMute::Audio service unavailable");
|
||||
if (!AudioPolicyManager::GetInstance().VerifyClientPermission(MICROPHONE_PERMISSION)) {
|
||||
AUDIO_ERR_LOG("SetMicrophoneMute: MICROPHONE permission denied");
|
||||
return ERR_PERMISSION_DENIED;
|
||||
}
|
||||
|
||||
return g_sProxy->SetMicrophoneMute(isMute);
|
||||
}
|
||||
|
||||
bool AudioSystemManager::IsMicrophoneMute() const
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(g_sProxy != nullptr, ERR_OPERATION_FAILED, "IsMicrophoneMute::Audio service unavailable");
|
||||
if (!AudioPolicyManager::GetInstance().VerifyClientPermission(MICROPHONE_PERMISSION)) {
|
||||
AUDIO_ERR_LOG("IsMicrophoneMute: MICROPHONE permission denied");
|
||||
return false;
|
||||
}
|
||||
|
||||
return g_sProxy->IsMicrophoneMute();
|
||||
}
|
||||
|
||||
|
@ -29,10 +29,6 @@ int AudioManagerStub::OnRemoteRequest(
|
||||
AUDIO_ERR_LOG("AudioManagerStub: ReadInterfaceToken failed");
|
||||
return -1;
|
||||
}
|
||||
if (!IsPermissionValid()) {
|
||||
AUDIO_ERR_LOG("caller app not acquired audio permission");
|
||||
return AUDIO_PERMISSION_DENIED;
|
||||
}
|
||||
|
||||
switch (code) {
|
||||
case GET_MAX_VOLUME: {
|
||||
@ -123,10 +119,5 @@ int AudioManagerStub::OnRemoteRequest(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool AudioManagerStub::IsPermissionValid()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
} // namespace AudioStandard
|
||||
} // namespace OHOS
|
||||
|
Loading…
Reference in New Issue
Block a user