修复相机不传pid切后台不发送回调的问题

Signed-off-by: zhouyan <zhouyan160@h-partners.com>
Change-Id: I6ff1a898b9d438047558fe7fa9cfa2f5684c91c6
This commit is contained in:
zhouyan
2025-07-03 14:55:44 +08:00
parent 3c24810ba9
commit 6fb1bbc835
33 changed files with 25 additions and 1808 deletions
-3
View File
@@ -38,9 +38,6 @@ group("accesstoken_build_module_test") {
"services/privacymanager/test:unittest",
]
}
if (window_manager_enable == true) {
deps += [ "services/common/window_manager/test:unittest" ]
}
}
if (token_sync_enable == true) {
deps += [
-11
View File
@@ -136,10 +136,6 @@ if (!defined(global_parts_info) ||
access_token_background_task_mgr_continuous_task_enable = false
}
declare_args() {
access_token_camera_float_window_enable = true
}
if (!defined(global_parts_info) ||
defined(global_parts_info.appsecurityprivacy_security_privacy_server)) {
access_token_app_security_privacy_service_enable = true
@@ -147,13 +143,6 @@ if (!defined(global_parts_info) ||
access_token_app_security_privacy_service_enable = false
}
if (!defined(global_parts_info) ||
defined(global_parts_info.window_window_manager)) {
window_manager_enable = true
} else {
window_manager_enable = false
}
if (!defined(global_parts_info) ||
defined(global_parts_info.powermgr_power_manager)) {
power_manager_enable = true
@@ -479,7 +479,7 @@ HWTEST_F(AccessTokenInfoManagerTest, InitHapToken003, TestSize.Level0)
.permList = {},
.permStateList = { permissionStateA, permissionStateB }
};
uint64_t fullTokenId;;
uint64_t fullTokenId;
HapInfoCheckResultIdl resultInfoIdl;
HapInfoCheckResult result;
@@ -550,7 +550,7 @@ HWTEST_F(AccessTokenInfoManagerTest, InitHapToken004, TestSize.Level0)
HapPolicyParcel policy;
GetHapParams(info.hapInfoParameter, policy.hapPolicy);
uint64_t fullTokenId;;
uint64_t fullTokenId;
HapInfoCheckResultIdl result;
int32_t ret = atManagerService_->InitHapToken(info, policy, fullTokenId, result);
ASSERT_EQ(RET_SUCCESS, ret);
@@ -1,46 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef PRIVACY_MOCK_SESSION_MANAGER_PROXY_H
#define PRIVACY_MOCK_SESSION_MANAGER_PROXY_H
#include <iremote_proxy.h>
namespace OHOS {
namespace Security {
namespace AccessToken {
class IMockSessionManagerInterface : public IRemoteBroker {
public:
DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.IMockSessionManager");
enum class MockSessionManagerServiceMessage : uint32_t {
TRANS_ID_GET_SESSION_MANAGER_SERVICE = 0,
};
virtual sptr<IRemoteObject> GetSessionManagerService() = 0;
};
class PrivacyMockSessionManagerProxy : public IRemoteProxy<IMockSessionManagerInterface> {
public:
explicit PrivacyMockSessionManagerProxy(const sptr<IRemoteObject>& impl)
: IRemoteProxy<IMockSessionManagerInterface>(impl) {}
~PrivacyMockSessionManagerProxy() {}
sptr<IRemoteObject> GetSessionManagerService() override;
private:
static inline BrokerDelegator<PrivacyMockSessionManagerProxy> delegator_;
};
}
}
}
#endif // PRIVACY_MOCK_SESSION_MANAGER_PROXY_H
@@ -1,57 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef PRIVACY_SCENE_SESSION_MANAGER_LITE_PROXY_H
#define PRIVACY_SCENE_SESSION_MANAGER_LITE_PROXY_H
#include <iremote_proxy.h>
#include "privacy_window_manager_interface.h"
#include "privacy_window_manager_interface_lite.h"
namespace OHOS {
namespace Security {
namespace AccessToken {
class ISceneSessionManagerLite : public IWindowManagerLite {
public:
DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.ISceneSessionManagerLite");
enum class SceneSessionManagerLiteMessage : uint32_t {
TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT = 22,
TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT = 23,
};
virtual int32_t RegisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent) = 0;
virtual int32_t UnregisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent) = 0;
};
class PrivacySceneSessionManagerLiteProxy : public IRemoteProxy<ISceneSessionManagerLite> {
public:
explicit PrivacySceneSessionManagerLiteProxy(const sptr<IRemoteObject>& impl)
: IRemoteProxy<ISceneSessionManagerLite>(impl) {}
virtual ~PrivacySceneSessionManagerLiteProxy() = default;
int32_t RegisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent) override;
int32_t UnregisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent) override;
private:
static inline BrokerDelegator<PrivacySceneSessionManagerLiteProxy> delegator_;
};
}
}
}
#endif // PRIVACY_SCENE_SESSION_MANAGER_LITE_PROXY_H
@@ -1,57 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef PRIVACY_SCENE_SESSION_MANAGER_PROXY_H
#define PRIVACY_SCENE_SESSION_MANAGER_PROXY_H
#include <iremote_proxy.h>
#include "privacy_window_manager_interface.h"
namespace OHOS {
namespace Security {
namespace AccessToken {
class ISceneSessionManager : public IWindowManager {
public:
DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.ISceneSessionManager");
enum class SceneSessionManagerMessage : uint32_t {
TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT = 4,
TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT = 5,
};
virtual int32_t RegisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent) = 0;
virtual int32_t UnregisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent) = 0;
};
class PrivacySceneSessionManagerProxy : public IRemoteProxy<ISceneSessionManager> {
public:
explicit PrivacySceneSessionManagerProxy(const sptr<IRemoteObject>& impl)
: IRemoteProxy<ISceneSessionManager>(impl) {}
virtual ~PrivacySceneSessionManagerProxy() = default;
int32_t RegisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent) override;
int32_t UnregisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent) override;
private:
static inline BrokerDelegator<PrivacySceneSessionManagerProxy> delegator_;
};
}
}
}
#endif // PRIVACY_SCENE_SESSION_MANAGER_PROXY_H
@@ -1,52 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef PRIVACY_SESSION_MANAGER_PROXY_H
#define PRIVACY_SESSION_MANAGER_PROXY_H
#include <iremote_proxy.h>
namespace OHOS {
namespace Security {
namespace AccessToken {
class ISessionManagerService : public IRemoteBroker {
public:
DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.ISessionManagerService");
enum class SessionManagerServiceMessage : uint32_t {
TRANS_ID_GET_SCENE_SESSION_MANAGER = 0,
TRANS_ID_GET_SCENE_SESSION_MANAGER_LITE = 1,
};
virtual sptr<IRemoteObject> GetSceneSessionManager() = 0;
virtual sptr<IRemoteObject> GetSceneSessionManagerLite() = 0;
};
class PrivacySessionManagerProxy : public IRemoteProxy<ISessionManagerService> {
public:
explicit PrivacySessionManagerProxy(const sptr<IRemoteObject>& object)
: IRemoteProxy<ISessionManagerService>(object) {}
virtual ~PrivacySessionManagerProxy() = default;
sptr<IRemoteObject> GetSceneSessionManager() override;
sptr<IRemoteObject> GetSceneSessionManagerLite() override;
private:
static inline BrokerDelegator<PrivacySessionManagerProxy> delegator_;
};
}
}
}
#endif // PRIVACY_SESSION_MANAGER_PROXY_H
@@ -1,43 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef PRIVACY_WINDOW_MANAGER_AGENT_H
#define PRIVACY_WINDOW_MANAGER_AGENT_H
#include "iremote_stub.h"
#include "nocopyable.h"
#include "privacy_window_manager_interface.h"
namespace OHOS {
namespace Security {
namespace AccessToken {
using WindowChangeCallback = void (*)(uint32_t, bool);
class PrivacyWindowManagerAgent : public IRemoteStub<IWindowManagerAgent> {
public:
PrivacyWindowManagerAgent(WindowChangeCallback callback);
~PrivacyWindowManagerAgent() = default;
int OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override;
void UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing) override;
void UpdateCameraWindowStatus(uint32_t accessTokenId, bool isShowing) override;
private:
WindowChangeCallback callback_;
};
} // namespace AccessToken
} // namespace Security
} // namespace OHOS
#endif // PRIVACY_WINDOW_MANAGER_AGENT_H
@@ -1,80 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef PRIVACY_WINDOW_MANAGER_CLIENT_H
#define PRIVACY_WINDOW_MANAGER_CLIENT_H
#include <mutex>
#include <string>
#include "nocopyable.h"
#include "privacy_window_manager_death_recipient.h"
#include "privacy_window_manager_interface.h"
#include "privacy_window_manager_interface_lite.h"
#include "privacy_scene_session_manager_lite_proxy.h"
#include "privacy_scene_session_manager_proxy.h"
#include "privacy_session_manager_proxy.h"
#include "privacy_mock_session_manager_proxy.h"
namespace OHOS {
namespace Security {
namespace AccessToken {
class PrivacyWindowManagerClient final {
public:
static PrivacyWindowManagerClient& GetInstance();
virtual ~PrivacyWindowManagerClient();
int32_t RegisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent);
int32_t UnregisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent);
void AddDeathCallback(void (*callback)());
void OnRemoteDiedHandle();
private:
PrivacyWindowManagerClient();
DISALLOW_COPY_AND_MOVE(PrivacyWindowManagerClient);
sptr<IWindowManager> GetProxy();
sptr<IWindowManagerLite> GetLiteProxy();
int32_t RegisterWindowManagerAgentLite(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent);
int32_t UnregisterWindowManagerAgentLite(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent);
void InitSceneSessionManagerProxy();
void InitSessionManagerServiceProxy();
void InitSceneSessionManagerLiteProxy();
sptr<ISceneSessionManager> GetSSMProxy();
sptr<ISceneSessionManagerLite> GetSSMLiteProxy();
void InitWMSProxy();
sptr<IWindowManager> GetWMSProxy();
void RemoveDeathRecipient();
sptr<PrivacyWindowManagerDeathRecipient> serviceDeathObserver_ = nullptr;
std::mutex proxyMutex_;
std::mutex deathMutex_;
void (*deathCallback_)();
sptr<IMockSessionManagerInterface> mockSessionManagerServiceProxy_ = nullptr;
sptr<ISessionManagerService> sessionManagerServiceProxy_ = nullptr;
sptr<ISceneSessionManager> sceneSessionManagerProxy_ = nullptr;
sptr<ISceneSessionManagerLite> sceneSessionManagerLiteProxy_ = nullptr;
sptr<IWindowManager> wmsProxy_ = nullptr;
};
} // namespace AccessToken
} // namespace Security
} // namespace OHOS
#endif // PRIVACY_WINDOW_MANAGER_CLIENT_H
@@ -1,33 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef PRIVACY_WINDOW_MANAGER_DEATH_RECIPIENT_H
#define PRIVACY_WINDOW_MANAGER_DEATH_RECIPIENT_H
#include "iremote_object.h"
namespace OHOS {
namespace Security {
namespace AccessToken {
class PrivacyWindowManagerDeathRecipient : public IRemoteObject::DeathRecipient {
public:
PrivacyWindowManagerDeathRecipient() {}
virtual ~PrivacyWindowManagerDeathRecipient() override = default;
void OnRemoteDied(const wptr<IRemoteObject>& object) override;
};
} // namespace AccessToken
} // namespace Security
} // namespace OHOS
#endif // PRIVACY_WINDOW_MANAGER_DEATH_RECIPIENT_H
@@ -1,58 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef PRIVACY_WINDOW_MANAGER_NTERFACE_H
#define PRIVACY_WINDOW_MANAGER_NTERFACE_H
#include <iremote_broker.h>
namespace OHOS {
namespace Security {
namespace AccessToken {
enum class WindowManagerAgentType : uint32_t {
WINDOW_MANAGER_AGENT_TYPE_CAMERA_FLOAT = 5,
WINDOW_MANAGER_AGENT_TYPE_CAMERA_WINDOW = 9,
};
enum class PrivacyWindowServiceInterfaceCode {
TRANS_ID_UPDATE_CAMERA_FLOAT = 6,
TRANS_ID_UPDATE_CAMERA_WINDOW_STATUS = 10,
};
class IWindowManagerAgent : public IRemoteBroker {
public:
DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.IWindowManagerAgent");
virtual void UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing) = 0;
virtual void UpdateCameraWindowStatus(uint32_t accessTokenId, bool isShowing) = 0;
};
class IWindowManager : public IRemoteBroker {
public:
DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.IWindowManager");
enum class WindowManagerMessage : uint32_t {
TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT = 7,
TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT = 8,
};
virtual int32_t RegisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent) = 0;
virtual int32_t UnregisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent) = 0;
};
}
}
}
#endif // PRIVACY_WINDOW_MANAGER_NTERFACE_H
@@ -1,35 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef PRIVACY_WINDOW_MANAGER_NTERFACE_LITE_H
#define PRIVACY_WINDOW_MANAGER_NTERFACE_LITE_H
#include <iremote_broker.h>
namespace OHOS {
namespace Security {
namespace AccessToken {
class IWindowManagerLite : public IRemoteBroker {
public:
DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.IWindowManagerLite");
// do not need enum
virtual int32_t RegisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent) = 0;
virtual int32_t UnregisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent) = 0;
};
}
}
}
#endif // PRIVACY_WINDOW_MANAGER_NTERFACE_LITE_H
@@ -1,41 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef PRIVACY_OHOS_WINDOW_MANAGER_PROXY_H
#define PRIVACY_OHOS_WINDOW_MANAGER_PROXY_H
#include <iremote_proxy.h>
#include "privacy_window_manager_interface.h"
namespace OHOS {
namespace Security {
namespace AccessToken {
class PrivacyWindowManagerProxy : public IRemoteProxy<IWindowManager> {
public:
explicit PrivacyWindowManagerProxy(const sptr<IRemoteObject>& impl) : IRemoteProxy<IWindowManager>(impl) {}
~PrivacyWindowManagerProxy() {}
int32_t RegisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent) override;
int32_t UnregisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent) override;
private:
static inline BrokerDelegator<PrivacyWindowManagerProxy> delegator_;
};
}
}
}
#endif // PRIVACY_OHOS_WINDOW_MANAGER_PROXY_H
@@ -1,48 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <cinttypes>
#include "privacy_mock_session_manager_proxy.h"
#include "accesstoken_common_log.h"
namespace OHOS {
namespace Security {
namespace AccessToken {
sptr<IRemoteObject> PrivacyMockSessionManagerProxy::GetSessionManagerService()
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
LOGE(PRI_DOMAIN, PRI_TAG, "WriteInterfaceToken failed");
return nullptr;
}
if (Remote()->SendRequest(static_cast<uint32_t>(
MockSessionManagerServiceMessage::TRANS_ID_GET_SESSION_MANAGER_SERVICE),
data, reply, option) != ERR_NONE) {
LOGE(PRI_DOMAIN, PRI_TAG, "SendRequest failed");
return nullptr;
}
if (reply.ReadInt32() != ERR_NONE) {
LOGE(PRI_DOMAIN, PRI_TAG, "Read result failed");
return nullptr;
}
sptr<IRemoteObject> remoteObject = reply.ReadRemoteObject();
return remoteObject;
}
}
}
}
@@ -1,100 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "privacy_scene_session_manager_lite_proxy.h"
#include "accesstoken_common_log.h"
#include "privacy_error.h"
namespace OHOS {
namespace Security {
namespace AccessToken {
int32_t PrivacySceneSessionManagerLiteProxy::RegisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent)
{
MessageOption option;
MessageParcel reply;
MessageParcel data;
if (!data.WriteInterfaceToken(GetDescriptor())) {
LOGE(PRI_DOMAIN, PRI_TAG, "Write InterfaceToken failed");
return ERR_WRITE_PARCEL_FAILED;
}
if (!data.WriteUint32(static_cast<uint32_t>(type))) {
LOGE(PRI_DOMAIN, PRI_TAG, "Write type failed");
return ERR_WRITE_PARCEL_FAILED;
}
if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) {
LOGE(PRI_DOMAIN, PRI_TAG, "Write IWindowManagerAgent failed");
return ERR_WRITE_PARCEL_FAILED;
}
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
LOGE(PRI_DOMAIN, PRI_TAG, "Remote service is null.");
return ERR_REMOTE_CONNECTION;
}
int32_t error = remote->SendRequest(static_cast<uint32_t>(
SceneSessionManagerLiteMessage::TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT),
data, reply, option);
if (error != ERR_NONE) {
LOGE(PRI_DOMAIN, PRI_TAG, "SendRequest failed, err=%{public}d.", error);
return error;
}
return reply.ReadInt32();
}
int32_t PrivacySceneSessionManagerLiteProxy::UnregisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent)
{
MessageParcel reply;
MessageOption option;
MessageParcel data;
if (!data.WriteInterfaceToken(GetDescriptor())) {
LOGE(PRI_DOMAIN, PRI_TAG, "Write InterfaceToken failed");
return ERR_WRITE_PARCEL_FAILED;
}
if (!data.WriteUint32(static_cast<uint32_t>(type))) {
LOGE(PRI_DOMAIN, PRI_TAG, "Write type failed");
return ERR_WRITE_PARCEL_FAILED;
}
if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) {
LOGE(PRI_DOMAIN, PRI_TAG, "Write IWindowManagerAgent failed");
return ERR_WRITE_PARCEL_FAILED;
}
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
LOGE(PRI_DOMAIN, PRI_TAG, "Remote service is null.");
return ERR_REMOTE_CONNECTION;
}
int32_t error = remote->SendRequest(static_cast<uint32_t>(
SceneSessionManagerLiteMessage::TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT),
data, reply, option);
if (error != ERR_NONE) {
LOGE(PRI_DOMAIN, PRI_TAG, "SendRequest failed, err=%{public}d.", error);
return error;
}
return reply.ReadInt32();
}
}
}
}
@@ -1,90 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "privacy_scene_session_manager_proxy.h"
#include "accesstoken_common_log.h"
#include "privacy_error.h"
namespace OHOS {
namespace Security {
namespace AccessToken {
int32_t PrivacySceneSessionManagerProxy::RegisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent)
{
MessageOption option;
MessageParcel reply;
MessageParcel data;
if (!data.WriteInterfaceToken(GetDescriptor())) {
LOGE(PRI_DOMAIN, PRI_TAG, "Write InterfaceToken failed");
return ERR_WRITE_PARCEL_FAILED;
}
if (!data.WriteUint32(static_cast<uint32_t>(type))) {
LOGE(PRI_DOMAIN, PRI_TAG, "Write type failed");
return ERR_WRITE_PARCEL_FAILED;
}
if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) {
LOGE(PRI_DOMAIN, PRI_TAG, "Write IWindowManagerAgent failed");
return ERR_WRITE_PARCEL_FAILED;
}
int32_t error = Remote()->SendRequest(static_cast<uint32_t>(
SceneSessionManagerMessage::TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT),
data, reply, option);
if (error != ERR_NONE) {
LOGE(PRI_DOMAIN, PRI_TAG, "SendRequest failed, err=%{public}d.", error);
return error;
}
return reply.ReadInt32();
}
int32_t PrivacySceneSessionManagerProxy::UnregisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent)
{
MessageParcel reply;
MessageOption option;
MessageParcel data;
if (!data.WriteInterfaceToken(GetDescriptor())) {
LOGE(PRI_DOMAIN, PRI_TAG, "Write InterfaceToken failed");
return ERR_WRITE_PARCEL_FAILED;
}
if (!data.WriteUint32(static_cast<uint32_t>(type))) {
LOGE(PRI_DOMAIN, PRI_TAG, "Write type failed");
return ERR_WRITE_PARCEL_FAILED;
}
if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) {
LOGE(PRI_DOMAIN, PRI_TAG, "Write IWindowManagerAgent failed");
return ERR_WRITE_PARCEL_FAILED;
}
int32_t error = Remote()->SendRequest(static_cast<uint32_t>(
SceneSessionManagerMessage::TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT),
data, reply, option);
if (error != ERR_NONE) {
LOGE(PRI_DOMAIN, PRI_TAG, "SendRequest failed, err=%{public}d.", error);
return error;
}
return reply.ReadInt32();
}
}
}
}
@@ -1,79 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "privacy_session_manager_proxy.h"
#include "accesstoken_common_log.h"
namespace OHOS {
namespace Security {
namespace AccessToken {
sptr<IRemoteObject> PrivacySessionManagerProxy::GetSceneSessionManager()
{
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
if (!data.WriteInterfaceToken(GetDescriptor())) {
LOGE(PRI_DOMAIN, PRI_TAG, "WriteInterfaceToken failed");
return nullptr;
}
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
LOGE(PRI_DOMAIN, PRI_TAG, "Remote service is null.");
return nullptr;
}
auto ret = remote->SendRequest(
static_cast<uint32_t>(SessionManagerServiceMessage::TRANS_ID_GET_SCENE_SESSION_MANAGER),
data, reply, option);
if (ret != ERR_NONE) {
LOGE(PRI_DOMAIN, PRI_TAG, "SendRequest failed, errorCode %{public}d", ret);
return nullptr;
}
return reply.ReadRemoteObject();
}
sptr<IRemoteObject> PrivacySessionManagerProxy::GetSceneSessionManagerLite()
{
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_SYNC);
if (!data.WriteInterfaceToken(GetDescriptor())) {
LOGE(PRI_DOMAIN, PRI_TAG, "WriteInterfaceToken failed");
return nullptr;
}
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
LOGE(PRI_DOMAIN, PRI_TAG, "Remote service is null.");
return nullptr;
}
auto ret = remote->SendRequest(
static_cast<uint32_t>(SessionManagerServiceMessage::TRANS_ID_GET_SCENE_SESSION_MANAGER_LITE),
data, reply, option);
if (ret != ERR_NONE) {
LOGE(PRI_DOMAIN, PRI_TAG, "SendRequest failed, errorCode %{public}d", ret);
return nullptr;
}
return reply.ReadRemoteObject();
}
}
}
}
@@ -1,70 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "privacy_window_manager_agent.h"
#include "accesstoken_common_log.h"
#include "privacy_error.h"
namespace OHOS {
namespace Security {
namespace AccessToken {
PrivacyWindowManagerAgent::PrivacyWindowManagerAgent(WindowChangeCallback callback)
{
callback_ = callback;
}
int PrivacyWindowManagerAgent::OnRemoteRequest(uint32_t code, MessageParcel& data,
MessageParcel& reply, MessageOption& option)
{
LOGI(PRI_DOMAIN, PRI_TAG, "%{public}s called, code: %{public}u", __func__, code);
if (data.ReadInterfaceToken() != IWindowManagerAgent::GetDescriptor()) {
LOGI(PRI_DOMAIN, PRI_TAG, "%{public}s called, read desciptor error", __func__);
return ERROR_IPC_REQUEST_FAIL;
}
PrivacyWindowServiceInterfaceCode msgId = static_cast<PrivacyWindowServiceInterfaceCode>(code);
switch (msgId) {
case PrivacyWindowServiceInterfaceCode::TRANS_ID_UPDATE_CAMERA_FLOAT: {
uint32_t accessTokenId = data.ReadUint32();
bool isShowing = data.ReadBool();
UpdateCameraFloatWindowStatus(accessTokenId, isShowing);
break;
}
case PrivacyWindowServiceInterfaceCode::TRANS_ID_UPDATE_CAMERA_WINDOW_STATUS: {
uint32_t accessTokenId = data.ReadUint32();
bool isShowing = data.ReadBool();
UpdateCameraWindowStatus(accessTokenId, isShowing);
break;
}
default:
break;
}
return 0;
}
void PrivacyWindowManagerAgent::UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing)
{
LOGI(PRI_DOMAIN, PRI_TAG, "OnChange(tokenId=%{public}d, isShow=%{public}d)", accessTokenId, isShowing);
callback_(accessTokenId, isShowing);
}
void PrivacyWindowManagerAgent::UpdateCameraWindowStatus(uint32_t accessTokenId, bool isShowing)
{
LOGI(PRI_DOMAIN, PRI_TAG, "OnChange(tokenId=%{public}d, isShow=%{public}d)", accessTokenId, isShowing);
callback_(accessTokenId, isShowing);
}
} // namespace AccessToken
} // namespace Security
} // namespace OHOS
@@ -1,337 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "privacy_window_manager_client.h"
#include <thread>
#include "accesstoken_common_log.h"
#include "iservice_registry.h"
#include "privacy_error.h"
#include "privacy_mock_session_manager_proxy.h"
#include "privacy_scene_session_manager_proxy.h"
#include "privacy_scene_session_manager_lite_proxy.h"
#include "privacy_session_manager_proxy.h"
#include "privacy_window_manager_proxy.h"
#include "scene_board_judgement.h"
#include "system_ability_definition.h"
namespace OHOS {
namespace Security {
namespace AccessToken {
namespace {
std::recursive_mutex g_instanceMutex;
static const int MAX_PTHREAD_NAME_LEN = 15; // pthread name max length
} // namespace
PrivacyWindowManagerClient& PrivacyWindowManagerClient::GetInstance()
{
static PrivacyWindowManagerClient* instance = nullptr;
if (instance == nullptr) {
std::lock_guard<std::recursive_mutex> lock(g_instanceMutex);
if (instance == nullptr) {
PrivacyWindowManagerClient* tmp = new (std::nothrow) PrivacyWindowManagerClient();
instance = std::move(tmp);
}
}
return *instance;
}
PrivacyWindowManagerClient::PrivacyWindowManagerClient() : deathCallback_(nullptr)
{
std::lock_guard<std::mutex> lock(proxyMutex_);
serviceDeathObserver_ = sptr<PrivacyWindowManagerDeathRecipient>::MakeSptr();
}
PrivacyWindowManagerClient::~PrivacyWindowManagerClient()
{
LOGI(PRI_DOMAIN, PRI_TAG, "~PrivacyWindowManagerClient().");
std::lock_guard<std::mutex> lock(proxyMutex_);
RemoveDeathRecipient();
}
int32_t PrivacyWindowManagerClient::RegisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent)
{
if (type == WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CAMERA_WINDOW) {
return RegisterWindowManagerAgentLite(type, windowManagerAgent);
}
auto proxy = GetProxy();
if (proxy == nullptr) {
LOGE(PRI_DOMAIN, PRI_TAG, "Proxy is null");
return ERR_SERVICE_ABNORMAL;
}
return proxy->RegisterWindowManagerAgent(type, windowManagerAgent);
}
int32_t PrivacyWindowManagerClient::UnregisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent)
{
if (type == WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CAMERA_WINDOW) {
return UnregisterWindowManagerAgentLite(type, windowManagerAgent);
}
auto proxy = GetProxy();
if (proxy == nullptr) {
LOGE(PRI_DOMAIN, PRI_TAG, "Proxy is null");
return ERR_SERVICE_ABNORMAL;
}
return proxy->UnregisterWindowManagerAgent(type, windowManagerAgent);
}
int32_t PrivacyWindowManagerClient::RegisterWindowManagerAgentLite(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent)
{
auto proxy = GetLiteProxy();
if (proxy == nullptr) {
LOGE(PRI_DOMAIN, PRI_TAG, "Proxy is null");
return ERR_SERVICE_ABNORMAL;
}
return proxy->RegisterWindowManagerAgent(type, windowManagerAgent);
}
int32_t PrivacyWindowManagerClient::UnregisterWindowManagerAgentLite(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent)
{
auto proxy = GetLiteProxy();
if (proxy == nullptr) {
LOGE(PRI_DOMAIN, PRI_TAG, "Proxy is null");
return ERR_SERVICE_ABNORMAL;
}
return proxy->UnregisterWindowManagerAgent(type, windowManagerAgent);
}
void PrivacyWindowManagerClient::AddDeathCallback(void (*callback)())
{
std::lock_guard<std::mutex> lock(deathMutex_);
deathCallback_ = callback;
}
void PrivacyWindowManagerClient::InitSessionManagerServiceProxy()
{
if (sessionManagerServiceProxy_ && sessionManagerServiceProxy_->AsObject() != nullptr &&
(!sessionManagerServiceProxy_->AsObject()->IsObjectDead())) {
return;
}
sptr<ISystemAbilityManager> systemAbilityManager =
SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (!systemAbilityManager) {
LOGE(PRI_DOMAIN, PRI_TAG, "Failed to get system ability mgr.");
return;
}
sptr<IRemoteObject> remoteObject = systemAbilityManager->GetSystemAbility(WINDOW_MANAGER_SERVICE_ID);
if (!remoteObject) {
LOGE(PRI_DOMAIN, PRI_TAG, "Remote object is nullptr");
return;
}
mockSessionManagerServiceProxy_ = new (std::nothrow) PrivacyMockSessionManagerProxy(remoteObject);
if (!mockSessionManagerServiceProxy_ || mockSessionManagerServiceProxy_->AsObject() == nullptr ||
mockSessionManagerServiceProxy_->AsObject()->IsObjectDead()) {
LOGW(PRI_DOMAIN, PRI_TAG, "Get mock session manager service proxy failed, nullptr");
return;
}
sptr<IRemoteObject> remoteObject2 = mockSessionManagerServiceProxy_->GetSessionManagerService();
if (!remoteObject2) {
LOGE(PRI_DOMAIN, PRI_TAG, "Remote object2 is nullptr");
return;
}
sessionManagerServiceProxy_ = new (std::nothrow) PrivacySessionManagerProxy(remoteObject2);
if (!sessionManagerServiceProxy_ || sessionManagerServiceProxy_->AsObject() == nullptr ||
sessionManagerServiceProxy_->AsObject()->IsObjectDead()) {
LOGE(PRI_DOMAIN, PRI_TAG, "SessionManagerServiceProxy_ is nullptr");
}
}
void PrivacyWindowManagerClient::InitSceneSessionManagerProxy()
{
if (sceneSessionManagerProxy_ && sceneSessionManagerProxy_->AsObject() != nullptr &&
(!sceneSessionManagerProxy_->AsObject()->IsObjectDead())) {
return;
}
if (!sessionManagerServiceProxy_ || sessionManagerServiceProxy_->AsObject() == nullptr ||
sessionManagerServiceProxy_->AsObject()->IsObjectDead()) {
LOGE(PRI_DOMAIN, PRI_TAG, "SessionManagerServiceProxy_ is nullptr");
return;
}
sptr<IRemoteObject> remoteObject = sessionManagerServiceProxy_->GetSceneSessionManager();
if (!remoteObject) {
LOGW(PRI_DOMAIN, PRI_TAG, "Get scene session manager proxy failed, scene session manager service is null");
return;
}
sceneSessionManagerProxy_ = new (std::nothrow) PrivacySceneSessionManagerProxy(remoteObject);
if (sceneSessionManagerProxy_ == nullptr || sceneSessionManagerProxy_->AsObject() == nullptr ||
sceneSessionManagerProxy_->AsObject()->IsObjectDead()) {
LOGW(PRI_DOMAIN, PRI_TAG, "SceneSessionManagerProxy_ is null.");
return;
}
if (!serviceDeathObserver_) {
LOGE(PRI_DOMAIN, PRI_TAG, "Failed to create death Recipient ptr WMSDeathRecipient");
return;
}
if (remoteObject->IsProxyObject() && !remoteObject->AddDeathRecipient(serviceDeathObserver_)) {
LOGE(PRI_DOMAIN, PRI_TAG, "Failed to add death recipient");
return;
}
LOGI(PRI_DOMAIN, PRI_TAG, "InitSceneSessionManagerProxy end.");
}
void PrivacyWindowManagerClient::InitSceneSessionManagerLiteProxy()
{
if (sceneSessionManagerLiteProxy_ && sceneSessionManagerLiteProxy_->AsObject() != nullptr &&
(!sceneSessionManagerLiteProxy_->AsObject()->IsObjectDead())) {
return;
}
if (!sessionManagerServiceProxy_) {
LOGE(PRI_DOMAIN, PRI_TAG, "SessionManagerServiceProxy_ is nullptr");
return;
}
sptr<IRemoteObject> remoteObject = sessionManagerServiceProxy_->GetSceneSessionManagerLite();
if (!remoteObject) {
LOGW(PRI_DOMAIN, PRI_TAG, "Get scene session manager proxy failed, scene session manager service is null");
return;
}
sceneSessionManagerLiteProxy_ = new (std::nothrow) PrivacySceneSessionManagerLiteProxy(remoteObject);
if (sceneSessionManagerLiteProxy_ == nullptr || sceneSessionManagerLiteProxy_->AsObject() == nullptr ||
sceneSessionManagerLiteProxy_->AsObject()->IsObjectDead()) {
LOGW(PRI_DOMAIN, PRI_TAG, "SceneSessionManagerLiteProxy_ is null.");
return;
}
if (!serviceDeathObserver_) {
LOGE(PRI_DOMAIN, PRI_TAG, "Failed to create death Recipient ptr WMSDeathRecipient");
return;
}
if (remoteObject->IsProxyObject() && !remoteObject->AddDeathRecipient(serviceDeathObserver_)) {
LOGE(PRI_DOMAIN, PRI_TAG, "Failed to add death recipient");
return;
}
LOGI(PRI_DOMAIN, PRI_TAG, "InitSceneSessionManagerLiteProxy end.");
}
sptr<ISceneSessionManager> PrivacyWindowManagerClient::GetSSMProxy()
{
std::lock_guard<std::mutex> lock(proxyMutex_);
InitSessionManagerServiceProxy();
InitSceneSessionManagerProxy();
return sceneSessionManagerProxy_;
}
sptr<ISceneSessionManagerLite> PrivacyWindowManagerClient::GetSSMLiteProxy()
{
std::lock_guard<std::mutex> lock(proxyMutex_);
InitSessionManagerServiceProxy();
InitSceneSessionManagerLiteProxy();
return sceneSessionManagerLiteProxy_;
}
void PrivacyWindowManagerClient::InitWMSProxy()
{
if (wmsProxy_ && wmsProxy_->AsObject() != nullptr && (!wmsProxy_->AsObject()->IsObjectDead())) {
return;
}
auto sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (sam == nullptr) {
LOGE(PRI_DOMAIN, PRI_TAG, "GetSystemAbilityManager is null");
return;
}
auto windowManagerSa = sam->GetSystemAbility(WINDOW_MANAGER_SERVICE_ID);
if (windowManagerSa == nullptr) {
LOGE(PRI_DOMAIN, PRI_TAG, "GetSystemAbility %{public}d is null",
WINDOW_MANAGER_SERVICE_ID);
return;
}
if (serviceDeathObserver_ != nullptr) {
windowManagerSa->AddDeathRecipient(serviceDeathObserver_);
}
wmsProxy_ = new (std::nothrow) PrivacyWindowManagerProxy(windowManagerSa);
if (wmsProxy_ == nullptr || wmsProxy_->AsObject() == nullptr || wmsProxy_->AsObject()->IsObjectDead()) {
LOGE(PRI_DOMAIN, PRI_TAG, "WmsProxy_ is null.");
return;
}
LOGI(PRI_DOMAIN, PRI_TAG, "InitWMSProxy end.");
}
sptr<IWindowManager> PrivacyWindowManagerClient::GetWMSProxy()
{
std::lock_guard<std::mutex> lock(proxyMutex_);
InitWMSProxy();
return wmsProxy_;
}
void PrivacyWindowManagerClient::OnRemoteDiedHandle()
{
std::lock_guard<std::mutex> lock(proxyMutex_);
LOGI(PRI_DOMAIN, PRI_TAG, "Window manager remote died.");
RemoveDeathRecipient();
std::function<void()> runner = [this]() {
std::string name = "WindowMgrDiedHandler";
pthread_setname_np(pthread_self(), name.substr(0, MAX_PTHREAD_NAME_LEN).c_str());
auto sleepTime = std::chrono::milliseconds(1000);
std::this_thread::sleep_for(sleepTime);
std::lock_guard<std::mutex> lock(deathMutex_);
if (this->deathCallback_) {
this->deathCallback_();
}
};
std::thread initThread(runner);
initThread.detach();
}
sptr<IWindowManagerLite> PrivacyWindowManagerClient::GetLiteProxy()
{
if (!Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
return nullptr;
}
return GetSSMLiteProxy();
}
sptr<IWindowManager> PrivacyWindowManagerClient::GetProxy()
{
if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
return GetSSMProxy();
}
return GetWMSProxy();
}
void PrivacyWindowManagerClient::RemoveDeathRecipient()
{
if (serviceDeathObserver_ == nullptr) {
return;
}
// remove SceneSessionManager
if (sceneSessionManagerProxy_ != nullptr) {
sceneSessionManagerProxy_->AsObject()->RemoveDeathRecipient(serviceDeathObserver_);
}
//remove SceneSessionManagerLite
if (sceneSessionManagerLiteProxy_ != nullptr) {
sceneSessionManagerLiteProxy_->AsObject()->RemoveDeathRecipient(serviceDeathObserver_);
}
// remove WMSProxy
if (wmsProxy_ != nullptr) {
wmsProxy_->AsObject()->RemoveDeathRecipient(serviceDeathObserver_);
}
mockSessionManagerServiceProxy_ = nullptr;
sessionManagerServiceProxy_ = nullptr;
sceneSessionManagerProxy_ = nullptr;
sceneSessionManagerLiteProxy_ = nullptr;
wmsProxy_ = nullptr;
}
} // namespace AccessToken
} // namespace Security
} // namespace OHOS
@@ -1,31 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "privacy_window_manager_death_recipient.h"
#include "accesstoken_common_log.h"
#include "privacy_window_manager_client.h"
namespace OHOS {
namespace Security {
namespace AccessToken {
void PrivacyWindowManagerDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& object)
{
LOGI(PRI_DOMAIN, PRI_TAG, "WindowManger died.");
PrivacyWindowManagerClient::GetInstance().OnRemoteDiedHandle();
}
} // namespace AccessToken
} // namespace Security
} // namespace OHOS
@@ -1,97 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "privacy_window_manager_proxy.h"
#include "accesstoken_common_log.h"
#include "privacy_error.h"
namespace OHOS {
namespace Security {
namespace AccessToken {
int32_t PrivacyWindowManagerProxy::RegisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
LOGE(PRI_DOMAIN, PRI_TAG, "WriteInterfaceToken failed");
return ERR_WRITE_PARCEL_FAILED;
}
if (!data.WriteUint32(static_cast<uint32_t>(type))) {
LOGE(PRI_DOMAIN, PRI_TAG, "Write type failed");
return ERR_WRITE_PARCEL_FAILED;
}
if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) {
LOGE(PRI_DOMAIN, PRI_TAG, "Write IWindowManagerAgent failed");
return ERR_WRITE_PARCEL_FAILED;
}
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
LOGE(PRI_DOMAIN, PRI_TAG, "Remote service is null.");
return ERR_REMOTE_CONNECTION;
}
int32_t error = remote->SendRequest(
static_cast<uint32_t>(IWindowManager::WindowManagerMessage::TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT),
data, reply, option);
if (error != ERR_NONE) {
LOGE(PRI_DOMAIN, PRI_TAG, "SendRequest failed");
return error;
}
return reply.ReadInt32();
}
int32_t PrivacyWindowManagerProxy::UnregisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
LOGE(PRI_DOMAIN, PRI_TAG, "WriteInterfaceToken failed");
return ERR_WRITE_PARCEL_FAILED;
}
if (!data.WriteUint32(static_cast<uint32_t>(type))) {
LOGE(PRI_DOMAIN, PRI_TAG, "Write type failed");
return ERR_WRITE_PARCEL_FAILED;
}
if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) {
LOGE(PRI_DOMAIN, PRI_TAG, "Write IWindowManagerAgent failed");
return ERR_WRITE_PARCEL_FAILED;
}
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
LOGE(PRI_DOMAIN, PRI_TAG, "Remote service is null.");
return ERR_REMOTE_CONNECTION;
}
int32_t error = remote->SendRequest(
static_cast<uint32_t>(IWindowManager::WindowManagerMessage::TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT),
data, reply, option);
if (error != ERR_NONE) {
LOGE(PRI_DOMAIN, PRI_TAG, "SendRequest failed");
return error;
}
return reply.ReadInt32();
}
} // namespace AccessToken
} // namespace Security
} // namespace OHOS
@@ -1,62 +0,0 @@
# Copyright (c) 2024 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/test.gni")
import("../../../../access_token.gni")
ohos_unittest("libwindow_manager_test") {
subsystem_name = "accesscontrol"
module_out_path = module_output_path_unittest_accesstoken
sanitize = {
cfi = true
cfi_cross_dso = true
debug = false
}
branch_protector_ret = "pac_ret"
include_dirs = [
"${access_token_path}/frameworks/common/include",
"${access_token_path}/frameworks/privacy/include",
"${access_token_path}/interfaces/innerkits/accesstoken/include",
"${access_token_path}/interfaces/innerkits/privacy/include",
"${access_token_path}/services/common/window_manager/include",
]
sources = [
"${access_token_path}/services/common/window_manager/src/privacy_mock_session_manager_proxy.cpp",
"${access_token_path}/services/common/window_manager/src/privacy_scene_session_manager_lite_proxy.cpp",
"${access_token_path}/services/common/window_manager/src/privacy_scene_session_manager_proxy.cpp",
"${access_token_path}/services/common/window_manager/src/privacy_session_manager_proxy.cpp",
"${access_token_path}/services/common/window_manager/src/privacy_window_manager_agent.cpp",
"${access_token_path}/services/common/window_manager/src/privacy_window_manager_client.cpp",
"${access_token_path}/services/common/window_manager/src/privacy_window_manager_death_recipient.cpp",
"${access_token_path}/services/common/window_manager/src/privacy_window_manager_proxy.cpp",
"unittest/window_manager_test.cpp",
]
cflags_cc = [ "-DHILOG_ENABLE" ]
configs = [ "${access_token_path}/config:coverage_flags" ]
external_deps = [
"c_utils:utils",
"hilog:libhilog",
"ipc:ipc_core",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
"window_manager:libwsutils",
]
}
group("unittest") {
testonly = true
deps = [ ":libwindow_manager_test" ]
}
@@ -1,65 +0,0 @@
/*
* Copyright (c) 2022-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <gtest/gtest.h>
#include <memory>
#include <string>
#define private public
#include "privacy_window_manager_client.h"
#undef private
using namespace testing::ext;
namespace OHOS {
namespace Security {
namespace AccessToken {
class WindowManagerTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void WindowManagerTest::SetUpTestCase() {}
void WindowManagerTest::TearDownTestCase() {}
void WindowManagerTest::SetUp() {}
void WindowManagerTest::TearDown() {}
/**
* @tc.name: GetWMSProxy001
* @tc.desc: GetWMSProxy.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(WindowManagerTest, GetWMSProxy001, TestSize.Level1) {
PrivacyWindowManagerClient::GetInstance().GetWMSProxy();
EXPECT_NE(nullptr, PrivacyWindowManagerClient::GetInstance().wmsProxy_);
}
/**
* @tc.name: OnRemoteDiedHandle001
* @tc.desc: OnRemoteDiedHandle.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(WindowManagerTest, OnRemoteDiedHandle001, TestSize.Level1) {
PrivacyWindowManagerClient::GetInstance().OnRemoteDiedHandle();
EXPECT_EQ(nullptr, PrivacyWindowManagerClient::GetInstance().wmsProxy_);
}
} // namespace AccessToken
} // namespace Security
} // namespace OHOS
-17
View File
@@ -240,23 +240,6 @@ if (is_standard_system && ability_base_enable == true) {
sources += [ "src/common/privacy_common_event_subscriber.cpp" ]
}
if (window_manager_enable && access_token_camera_float_window_enable) {
cflags_cc += [ "-DCAMERA_FLOAT_WINDOW_ENABLE" ]
include_dirs +=
[ "${access_token_path}/services/common/window_manager/include" ]
sources += [
"${access_token_path}/services/common/window_manager/src/privacy_mock_session_manager_proxy.cpp",
"${access_token_path}/services/common/window_manager/src/privacy_scene_session_manager_lite_proxy.cpp",
"${access_token_path}/services/common/window_manager/src/privacy_scene_session_manager_proxy.cpp",
"${access_token_path}/services/common/window_manager/src/privacy_session_manager_proxy.cpp",
"${access_token_path}/services/common/window_manager/src/privacy_window_manager_agent.cpp",
"${access_token_path}/services/common/window_manager/src/privacy_window_manager_client.cpp",
"${access_token_path}/services/common/window_manager/src/privacy_window_manager_death_recipient.cpp",
"${access_token_path}/services/common/window_manager/src/privacy_window_manager_proxy.cpp",
]
external_deps += [ "window_manager:libwsutils" ]
}
if (access_token_app_security_privacy_service_enable) {
cflags_cc += [ "-DAPP_SECURITY_PRIVACY_SERVICE" ]
} else {
@@ -39,9 +39,6 @@
#include "permission_used_result.h"
#include "permission_used_type_info.h"
#include "privacy_param.h"
#ifdef CAMERA_FLOAT_WINDOW_ENABLE
#include "privacy_window_manager_agent.h"
#endif
#include "rwlock.h"
#include "safe_map.h"
#include "thread_pool.h"
@@ -110,10 +107,6 @@ public:
void SetLockScreenStatus(int32_t lockScreenStatus);
int32_t GetLockScreenStatus(bool isIpc = false);
#ifdef CAMERA_FLOAT_WINDOW_ENABLE
void NotifyCameraWindowChange(bool isPip, AccessTokenID tokenId, bool isShowing);
void OnWindowMgrRemoteDied();
#endif
void OnAppMgrRemoteDiedHandle();
void OnAudioMgrRemoteDiedHandle();
void OnCameraMgrRemoteDiedHandle();
@@ -180,10 +173,6 @@ private:
const PermissionUsedType type);
void AddDataValueToResults(const GenericValues value, std::vector<PermissionUsedTypeInfo>& results);
#ifdef CAMERA_FLOAT_WINDOW_ENABLE
bool HasUsingCamera();
void ClearWindowShowing();
#endif
bool IsCameraWindowShow(AccessTokenID tokenId);
uint64_t GetUniqueId(uint32_t tokenId, int32_t pid) const;
bool RegisterWindowCallback();
@@ -238,22 +227,6 @@ private:
std::mutex foreReminderMutex_;
std::vector<uint32_t> foreTokenIdList_;
#ifdef CAMERA_FLOAT_WINDOW_ENABLE
std::mutex windowMutex_;
bool isWmRegistered = false;
sptr<PrivacyWindowManagerAgent> floatWindowCallback_ = nullptr;
sptr<PrivacyWindowManagerAgent> pipWindowCallback_ = nullptr;
std::mutex windowStatusMutex_;
// camera float window
bool camFloatWindowShowing_ = false;
AccessTokenID floatWindowTokenId_ = 0;
// pip window
bool pipWindowShowing_ = false;
AccessTokenID pipWindowTokenId_ = 0;
#endif
// record config
int32_t recordSizeMaximum_ = 0;
int32_t recordAgingTime_ = 0;
@@ -48,10 +48,6 @@
#include "state_change_callback_proxy.h"
#include "system_ability_definition.h"
#include "time_util.h"
#ifdef CAMERA_FLOAT_WINDOW_ENABLE
#include "privacy_window_manager_client.h"
#include "scene_board_judgement.h"
#endif
namespace OHOS {
namespace Security {
@@ -200,8 +196,8 @@ int32_t PermissionRecordManager::MergeOrInsertRecord(const PermissionRecord& rec
bool mergeFlag = false;
for (auto it = permUsedRecList_.begin(); it != permUsedRecList_.end(); ++it) {
if (RecordMergeCheck(it->record, record)) {
LOGI(PRI_DOMAIN, PRI_TAG, "Merge record, ori timestamp is %{public}" PRId64 ".",
it->record.timestamp);
LOGI(PRI_DOMAIN, PRI_TAG, "Merge record, ori timestamp is %{public}s.",
std::to_string(it->record.timestamp).c_str());
// merge new record to older one if match the merge condition
it->record.accessCount += record.accessCount;
@@ -234,9 +230,9 @@ int32_t PermissionRecordManager::MergeOrInsertRecord(const PermissionRecord& rec
}
LOGI(PRI_DOMAIN, PRI_TAG, "Add record, id %{public}d, op %{public}d, status: %{public}d, sucCnt: %{public}d, "
"failCnt: %{public}d, lockScreenStatus %{public}d, timestamp %{public}" PRId64 ", type %{public}d.",
"failCnt: %{public}d, lockScreenStatus %{public}d, timestamp %{public}s, type %{public}d.",
record.tokenId, record.opCode, record.status, record.accessCount, record.rejectCount, record.lockScreenStatus,
record.timestamp, record.type);
std::to_string(record.timestamp).c_str(), record.type);
return Constant::SUCCESS;
}
@@ -286,8 +282,8 @@ int32_t PermissionRecordManager::AddRecord(const PermissionRecord& record)
whether update database succeed or not, recod remove from cache
*/
if ((it->needUpdateToDb) && (!UpdatePermissionUsedRecordToDb(it->record))) {
LOGE(PRI_DOMAIN, PRI_TAG, "Record with timestamp %{public}" PRId64 "update database failed!",
it->record.timestamp);
LOGE(PRI_DOMAIN, PRI_TAG, "Record with timestamp %{public}s update database failed!",
std::to_string(it->record.timestamp).c_str());
}
it = permUsedRecList_.erase(it);
@@ -966,7 +962,9 @@ void PermissionRecordManager::ExecuteAndUpdateRecord(uint32_t tokenId, int32_t p
std::lock_guard<std::mutex> lock(startRecordListMutex_);
std::set<ContinusPermissionRecord> updateList;
for (auto it = startRecordList_.begin(); it != startRecordList_.end();) {
if ((it->tokenId == tokenId) && (it->pid == pid) && (it->status != PERM_INACTIVE) && (it->status != status)) {
if ((it->tokenId == tokenId) && // tokenId
((it->pid == -1) || (it->pid == pid)) && // pid
((it->status != PERM_INACTIVE) && (it->status != status))) { // status
std::string perm;
Constant::TransferOpcodeToPermission(it->opCode, perm);
if ((GetMuteStatus(perm, EDM)) || (!GetGlobalSwitchStatus(perm))) {
@@ -974,14 +972,7 @@ void PermissionRecordManager::ExecuteAndUpdateRecord(uint32_t tokenId, int32_t p
continue;
}
// app use camera background without float window
bool isShow = IsCameraWindowShow(tokenId);
bool isAllowedBackGround = false;
if (AccessTokenKit::VerifyAccessToken(tokenId, "ohos.permission.CAMERA_BACKGROUND") == PERMISSION_GRANTED) {
isAllowedBackGround = true;
}
if ((perm == CAMERA_PERMISSION_NAME) && (status == PERM_ACTIVE_IN_BACKGROUND) &&
(!isShow) && (!isAllowedBackGround)) {
if ((perm == CAMERA_PERMISSION_NAME) && (status == PERM_ACTIVE_IN_BACKGROUND)) {
LOGI(PRI_DOMAIN, PRI_TAG, "Camera float window is close!");
camPermList.emplace_back(perm);
++it;
@@ -1014,7 +1005,12 @@ void PermissionRecordManager::ExecuteAndUpdateRecord(uint32_t tokenId, int32_t p
void PermissionRecordManager::NotifyAppStateChange(AccessTokenID tokenId, int32_t pid, ActiveChangeType status)
{
LOGI(PRI_DOMAIN, PRI_TAG, "Id %{public}u, pid %{public}d, status %{public}d", tokenId, pid, status);
// find permissions from startRecordList_ by tokenId which status diff from currStatus
// only handle camera turn background now, send callback only when app without process foreground
if (GetAppStatus(tokenId) == PERM_ACTIVE_IN_FOREGROUND) {
return;
}
ExecuteAndUpdateRecord(tokenId, pid, status);
}
@@ -1275,7 +1271,8 @@ void PermissionRecordManager::ExecuteCameraCallbackAsync(AccessTokenID tokenId,
LOGI(PRI_DOMAIN, PRI_TAG, "ExecuteCameraCallbackAsync task called.");
auto it = [&](uint64_t id, sptr<IRemoteObject> cameraCallback) {
auto callback = iface_cast<IStateChangeCallback>(cameraCallback);
if ((uniqueId == id) && (callback != nullptr)) {
int32_t pid = static_cast<int32_t>(id >> 32);
if (((pid == 0) || (uniqueId == id)) && (callback != nullptr)) {
LOGI(PRI_DOMAIN, PRI_TAG, "CameraCallback tokenId(%{public}u) pid( %{public}d) changeType %{public}d",
tokenId, pid, PERM_INACTIVE);
callback->StateChangeNotify(tokenId, false);
@@ -1354,10 +1351,6 @@ int32_t PermissionRecordManager::StartUsingPermission(const PermissionUsedTypeIn
#endif
uint64_t id = GetUniqueId(tokenId, info.pid);
cameraCallbackMap_.EnsureInsert(id, callback);
if (!RegisterWindowCallback()) {
cameraCallbackMap_.Erase(id);
return PrivacyError::ERR_WINDOW_CALLBACK_FAILED;
}
int32_t ret = AddRecordToStartList(info, status, callerPid);
if (ret != RET_SUCCESS) {
cameraCallbackMap_.Erase(id);
@@ -1735,79 +1728,6 @@ bool PermissionRecordManager::Register()
return true;
}
#ifdef CAMERA_FLOAT_WINDOW_ENABLE
bool PermissionRecordManager::HasUsingCamera()
{
std::lock_guard<std::mutex> lock(startRecordListMutex_);
bool hasCamera = std::any_of(startRecordList_.begin(), startRecordList_.end(),
[](const auto& record) { return record.opCode == Constant::OP_CAMERA; });
return hasCamera;
}
void UpdateCameraFloatWindowStatus(AccessTokenID tokenId, bool isShowing)
{
PermissionRecordManager::GetInstance().NotifyCameraWindowChange(false, tokenId, isShowing);
}
void UpdatePipWindowStatus(AccessTokenID tokenId, bool isShowing)
{
PermissionRecordManager::GetInstance().NotifyCameraWindowChange(true, tokenId, isShowing);
}
/* Handle window manager die */
void HandleWindowDied()
{
PermissionRecordManager::GetInstance().OnWindowMgrRemoteDied();
}
#endif
bool PermissionRecordManager::RegisterWindowCallback()
{
#ifdef CAMERA_FLOAT_WINDOW_ENABLE
LOGI(PRI_DOMAIN, PRI_TAG, "Begin to RegisterWindowCallback.");
std::lock_guard<std::mutex> lock(windowMutex_);
WindowChangeCallback floatCallback = UpdateCameraFloatWindowStatus;
if (floatWindowCallback_ == nullptr) {
floatWindowCallback_ = new (std::nothrow) PrivacyWindowManagerAgent(floatCallback);
if (floatWindowCallback_ == nullptr) {
LOGE(PRI_DOMAIN, PRI_TAG, "Failed to new PrivacyWindowManagerAgent.");
return false;
}
}
ErrCode err = PrivacyWindowManagerClient::GetInstance().RegisterWindowManagerAgent(
WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CAMERA_FLOAT, floatWindowCallback_);
if (err != ERR_OK) {
LOGE(PRI_DOMAIN, PRI_TAG, "Failed to register float window listener, err:%{public}d", err);
return false;
}
if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
WindowChangeCallback pipCallback = UpdatePipWindowStatus;
if (pipWindowCallback_ == nullptr) {
pipWindowCallback_ = new (std::nothrow) PrivacyWindowManagerAgent(pipCallback);
if (floatWindowCallback_ == nullptr) {
LOGE(PRI_DOMAIN, PRI_TAG, "Failed to new PrivacyWindowManagerAgent.");
return false;
}
}
err = PrivacyWindowManagerClient::GetInstance().RegisterWindowManagerAgent(
WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CAMERA_WINDOW, pipWindowCallback_);
if (err != ERR_OK) {
LOGE(PRI_DOMAIN, PRI_TAG, "Failed to register pip window listener, err:%{public}d", err);
PrivacyWindowManagerClient::GetInstance().UnregisterWindowManagerAgent(
WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CAMERA_FLOAT, floatWindowCallback_);
return false;
}
}
PrivacyWindowManagerClient::GetInstance().AddDeathCallback(HandleWindowDied);
#endif
return true;
}
void PermissionRecordManager::InitializeMuteState(const std::string& permissionName)
{
if (permissionName == MICROPHONE_PERMISSION_NAME) {
@@ -1893,72 +1813,8 @@ void PermissionRecordManager::OnCameraMgrRemoteDiedHandle()
std::lock_guard<std::mutex> lock(camLoadMutex_);
isCamLoad_ = false;
}
#ifdef CAMERA_FLOAT_WINDOW_ENABLE
ClearWindowShowing();
#endif
}
bool PermissionRecordManager::IsCameraWindowShow(AccessTokenID tokenId)
{
bool isShow = true;
#ifdef CAMERA_FLOAT_WINDOW_ENABLE
std::lock_guard<std::mutex> lock(windowStatusMutex_);
isShow = (((floatWindowTokenId_ == tokenId) && camFloatWindowShowing_) ||
((pipWindowTokenId_ == tokenId) && pipWindowShowing_));
#endif
return isShow;
}
#ifdef CAMERA_FLOAT_WINDOW_ENABLE
/*
* when camera float window is not show, notice camera service to use StopUsingPermission
*/
void PermissionRecordManager::NotifyCameraWindowChange(bool isPip, AccessTokenID tokenId, bool isShowing)
{
LOGI(PRI_DOMAIN, PRI_TAG, "Update window, isPip(%{public}d), id(%{public}u), status(%{public}d)",
isPip, tokenId, isShowing);
{
std::lock_guard<std::mutex> lock(windowStatusMutex_);
if (isPip) {
pipWindowShowing_ = isShowing;
pipWindowTokenId_ = tokenId;
} else {
camFloatWindowShowing_ = isShowing;
floatWindowTokenId_ = tokenId;
}
}
if (isShowing) {
LOGI(PRI_DOMAIN, PRI_TAG, "Camera float window is showing!");
} else {
if ((GetAppStatus(tokenId) == ActiveChangeType::PERM_ACTIVE_IN_BACKGROUND) &&
!IsCameraWindowShow(tokenId)) {
LOGI(PRI_DOMAIN, PRI_TAG, "Token(%{public}d) is background, pip and float window is not show.", tokenId);
ExecuteCameraCallbackAsync(tokenId, -1);
}
}
}
void PermissionRecordManager::ClearWindowShowing()
{
LOGI(PRI_DOMAIN, PRI_TAG, "Clear window show status.");
{
std::lock_guard<std::mutex> lock(windowStatusMutex_);
camFloatWindowShowing_ = false;
floatWindowTokenId_ = 0;
pipWindowShowing_ = false;
pipWindowTokenId_ = 0;
}
}
/* Handle window manager die */
void PermissionRecordManager::OnWindowMgrRemoteDied()
{
LOGI(PRI_DOMAIN, PRI_TAG, "Handle window manager died.");
ClearWindowShowing();
}
#endif
void PermissionRecordManager::SetDefaultConfigValue()
{
recordSizeMaximum_ = DEFAULT_PERMISSION_USED_RECORD_SIZE_MAXIMUM;
@@ -280,9 +280,9 @@ int32_t PrivacyManagerService::GetPermissionUsedRecords(
permissionList.append(perm);
permissionList.append(" ");
}
LOGI(PRI_DOMAIN, PRI_TAG, "id: %{public}d, timestamp: [%{public}" PRId64 "-%{public}" PRId64
"], flag: %{public}d, perm: %{public}s", request.request.tokenId, request.request.beginTimeMillis,
request.request.endTimeMillis, request.request.flag, permissionList.c_str());
LOGI(PRI_DOMAIN, PRI_TAG, "id: %{public}d, timestamp: [%{public}s-%{public}s], flag: %{public}d, perm: %{public}s.",
request.request.tokenId, std::to_string(request.request.beginTimeMillis).c_str(),
std::to_string(request.request.endTimeMillis).c_str(), request.request.flag, permissionList.c_str());
PermissionUsedResult permissionRecord;
int32_t ret = PermissionRecordManager::GetInstance().GetPermissionUsedRecords(request.request, permissionRecord);
@@ -132,22 +132,6 @@ if (is_standard_system && ability_base_enable == true) {
external_deps += [ "screenlock_mgr:screenlock_client" ]
}
if (window_manager_enable && access_token_camera_float_window_enable) {
cflags_cc += [ "-DCAMERA_FLOAT_WINDOW_ENABLE" ]
include_dirs +=
[ "${access_token_path}/services/common/window_manager/include" ]
sources += [
"${access_token_path}/services/common/window_manager/src/privacy_mock_session_manager_proxy.cpp",
"${access_token_path}/services/common/window_manager/src/privacy_scene_session_manager_lite_proxy.cpp",
"${access_token_path}/services/common/window_manager/src/privacy_scene_session_manager_proxy.cpp",
"${access_token_path}/services/common/window_manager/src/privacy_session_manager_proxy.cpp",
"${access_token_path}/services/common/window_manager/src/privacy_window_manager_agent.cpp",
"${access_token_path}/services/common/window_manager/src/privacy_window_manager_client.cpp",
"${access_token_path}/services/common/window_manager/src/privacy_window_manager_death_recipient.cpp",
"${access_token_path}/services/common/window_manager/src/privacy_window_manager_proxy.cpp",
]
external_deps += [ "window_manager:libwsutils" ]
}
if (access_token_app_security_privacy_service_enable) {
cflags_cc += [ "-DAPP_SECURITY_PRIVACY_SERVICE" ]
} else {
@@ -248,7 +248,7 @@ HWTEST_F(PermissionRecordManagerTest, FindRecordsToUpdateAndExecutedTest001, Tes
reqPerm.emplace_back("ohos.permission.MANAGE_CAMERA_CONFIG");
MockHapToken mock("FindRecordsToUpdateAndExecutedTest001", reqPerm, false);
AccessTokenID tokenId = GetSelfTokenID();;
AccessTokenID tokenId = GetSelfTokenID();
ASSERT_NE(INVALID_TOKENID, tokenId);
ActiveChangeType status = PERM_ACTIVE_IN_BACKGROUND;
@@ -256,10 +256,6 @@ HWTEST_F(PermissionRecordManagerTest, FindRecordsToUpdateAndExecutedTest001, Tes
PermissionRecordManager::GetInstance().SetMutePolicy(PolicyType::PRIVACY, CallerType::CAMERA, false,
RANDOM_TOKENID);
PermissionRecordManager::GetInstance().AddRecordToStartList(MakeInfo(tokenId, PID, permission), status, CALLER_PID);
#ifdef CAMERA_FLOAT_WINDOW_ENABLE
PermissionRecordManager::GetInstance().NotifyCameraWindowChange(false, tokenId, false);
PermissionRecordManager::GetInstance().NotifyCameraWindowChange(true, tokenId, false);
#endif
PermissionRecordManager::GetInstance().ExecuteAndUpdateRecord(tokenId, PID, status);
PermissionRecordManager::GetInstance().NotifyAppStateChange(tokenId, PID, status);
@@ -282,10 +278,6 @@ HWTEST_F(PermissionRecordManagerTest, FindRecordsToUpdateAndExecutedTest002, Tes
ActiveChangeType status = PERM_ACTIVE_IN_BACKGROUND;
std::string permission = "ohos.permission.MICROPHONE";
PermissionRecordManager::GetInstance().AddRecordToStartList(MakeInfo(tokenId, PID, permission), status, CALLER_PID);
#ifdef CAMERA_FLOAT_WINDOW_ENABLE
PermissionRecordManager::GetInstance().NotifyCameraWindowChange(false, tokenId, false);
PermissionRecordManager::GetInstance().NotifyCameraWindowChange(true, tokenId, false);
#endif
PermissionRecordManager::GetInstance().ExecuteAndUpdateRecord(tokenId, PID, status);
PermissionRecordManager::GetInstance().NotifyAppStateChange(tokenId, PID, status);
@@ -308,10 +300,6 @@ HWTEST_F(PermissionRecordManagerTest, FindRecordsToUpdateAndExecutedTest003, Tes
ActiveChangeType status = PERM_ACTIVE_IN_FOREGROUND;
std::string permission = "ohos.permission.CAMERA";
PermissionRecordManager::GetInstance().AddRecordToStartList(MakeInfo(tokenId, PID, permission), status, CALLER_PID);
#ifdef CAMERA_FLOAT_WINDOW_ENABLE
PermissionRecordManager::GetInstance().NotifyCameraWindowChange(false, tokenId, false);
PermissionRecordManager::GetInstance().NotifyCameraWindowChange(true, tokenId, false);
#endif
PermissionRecordManager::GetInstance().ExecuteAndUpdateRecord(tokenId, PID, status);
ASSERT_EQ(RET_SUCCESS, PermissionRecordManager::GetInstance().RemoveRecordFromStartList(
@@ -333,10 +321,6 @@ HWTEST_F(PermissionRecordManagerTest, FindRecordsToUpdateAndExecutedTest004, Tes
ActiveChangeType status = PERM_ACTIVE_IN_BACKGROUND;
std::string permission = "ohos.permission.CAMERA";
PermissionRecordManager::GetInstance().AddRecordToStartList(MakeInfo(tokenId, PID, permission), status, CALLER_PID);
#ifdef CAMERA_FLOAT_WINDOW_ENABLE
PermissionRecordManager::GetInstance().NotifyCameraWindowChange(false, tokenId, false);
PermissionRecordManager::GetInstance().NotifyCameraWindowChange(true, tokenId, false);
#endif
PermissionRecordManager::GetInstance().ExecuteAndUpdateRecord(tokenId, PID, status);
ASSERT_EQ(RET_SUCCESS, PermissionRecordManager::GetInstance().RemoveRecordFromStartList(
@@ -1138,7 +1122,7 @@ HWTEST_F(PermissionRecordManagerTest, RemoveRecordFromStartListTest001, TestSize
reqPerm.emplace_back("ohos.permission.MANAGE_CAMERA_CONFIG");
MockHapToken mock("RemoveRecordFromStartListTest001", reqPerm, false);
AccessTokenID tokenId = GetSelfTokenID();;
AccessTokenID tokenId = GetSelfTokenID();
ActiveChangeType status = PERM_ACTIVE_IN_FOREGROUND;
PermissionRecordManager::GetInstance().AddRecordToStartList(
@@ -139,23 +139,6 @@ if (is_standard_system && ability_base_enable == true) {
external_deps += [ "screenlock_mgr:screenlock_client" ]
}
if (window_manager_enable && access_token_camera_float_window_enable) {
cflags_cc += [ "-DCAMERA_FLOAT_WINDOW_ENABLE" ]
include_dirs +=
[ "${access_token_path}/services/common/window_manager/include" ]
sources += [
"${access_token_path}/services/common/window_manager/src/privacy_mock_session_manager_proxy.cpp",
"${access_token_path}/services/common/window_manager/src/privacy_scene_session_manager_lite_proxy.cpp",
"${access_token_path}/services/common/window_manager/src/privacy_scene_session_manager_proxy.cpp",
"${access_token_path}/services/common/window_manager/src/privacy_session_manager_proxy.cpp",
"${access_token_path}/services/common/window_manager/src/privacy_window_manager_agent.cpp",
"${access_token_path}/services/common/window_manager/src/privacy_window_manager_client.cpp",
"${access_token_path}/services/common/window_manager/src/privacy_window_manager_death_recipient.cpp",
"${access_token_path}/services/common/window_manager/src/privacy_window_manager_proxy.cpp",
]
external_deps += [ "window_manager:libwsutils" ]
}
if (access_token_app_security_privacy_service_enable) {
cflags_cc += [ "-DAPP_SECURITY_PRIVACY_SERVICE" ]
} else {
@@ -580,7 +580,6 @@ HWTEST_F(PermissionRecordManagerTest, StartUsingPermissionTest008, TestSize.Leve
ASSERT_EQ(PERM_INACTIVE, callback->type_);
}
#ifdef CAMERA_FLOAT_WINDOW_ENABLE
/*
* @tc.name: StartUsingPermissionTest009
* @tc.desc: Test multiple process start using permission
@@ -609,28 +608,7 @@ HWTEST_F(PermissionRecordManagerTest, StartUsingPermissionTest009, TestSize.Leve
MakeInfo(tokenId, TEST_PID_1, permissionName), callbackWrap1->AsObject(), CALLER_PID));
ASSERT_EQ(RET_SUCCESS, PermissionRecordManager::GetInstance().StartUsingPermission(
MakeInfo(tokenId, TEST_PID_2, permissionName), callbackWrap2->AsObject(), CALLER_PID));
AppStateData appStateData;
appStateData.accessTokenId = tokenId;
appStateData.state = static_cast<int32_t>(ApplicationState::APP_STATE_FOREGROUND);
appStateData.pid = TEST_PID_1;
appStateObserver_->OnAppStateChanged(appStateData);
appStateData.pid = TEST_PID_2;
appStateObserver_->OnAppStateChanged(appStateData);
appStateData.state = static_cast<int32_t>(ApplicationState::APP_STATE_BACKGROUND);
appStateData.pid = TEST_PID_1;
appStateObserver_->OnAppStateChanged(appStateData);
usleep(500000); // 500000us = 0.5s
ASSERT_FALSE(callbackPtr1->isShow_);
ASSERT_TRUE(callbackPtr2->isShow_);
appStateData.pid = TEST_PID_2;
appStateObserver_->OnAppStateChanged(appStateData);
usleep(500000); // 500000us = 0.5s
ASSERT_FALSE(callbackPtr2->isShow_);
}
#endif
/*
* @tc.name: StartUsingPermissionTest010
@@ -217,18 +217,6 @@ HWTEST_F(PrivacyManagerServiceTest, IsAllowedUsingPermission001, TestSize.Level0
tokenId, LOCATION_PERMISSION_NAME, -1));
ASSERT_EQ(false, PermissionRecordManager::GetInstance().IsAllowedUsingPermission(
tokenId, CAMERA_PERMISSION_NAME, -1));
#ifdef CAMERA_FLOAT_WINDOW_ENABLE
// not pip
PermissionRecordManager::GetInstance().NotifyCameraWindowChange(false, tokenId, false);
ASSERT_EQ(false, PermissionRecordManager::GetInstance().IsAllowedUsingPermission(
tokenId, CAMERA_PERMISSION_NAME, -1));
PermissionRecordManager::GetInstance().NotifyCameraWindowChange(false, tokenId, false);
// pip
PermissionRecordManager::GetInstance().NotifyCameraWindowChange(true, tokenId, false);
ASSERT_EQ(false, PermissionRecordManager::GetInstance().IsAllowedUsingPermission(
tokenId, CAMERA_PERMISSION_NAME, -1));
#endif
}
/*
@@ -106,23 +106,6 @@ if (common_event_service_enable) {
privacy_sources += [ "${access_token_path}/services/privacymanager/src/common/privacy_common_event_subscriber.cpp" ]
}
if (window_manager_enable && access_token_camera_float_window_enable) {
privacy_cflags_cc += [ "-DCAMERA_FLOAT_WINDOW_ENABLE" ]
privacy_include_dirs +=
[ "${access_token_path}/services/common/window_manager/include" ]
privacy_sources += [
"${access_token_path}/services/common/window_manager/src/privacy_mock_session_manager_proxy.cpp",
"${access_token_path}/services/common/window_manager/src/privacy_scene_session_manager_lite_proxy.cpp",
"${access_token_path}/services/common/window_manager/src/privacy_scene_session_manager_proxy.cpp",
"${access_token_path}/services/common/window_manager/src/privacy_session_manager_proxy.cpp",
"${access_token_path}/services/common/window_manager/src/privacy_window_manager_agent.cpp",
"${access_token_path}/services/common/window_manager/src/privacy_window_manager_client.cpp",
"${access_token_path}/services/common/window_manager/src/privacy_window_manager_death_recipient.cpp",
"${access_token_path}/services/common/window_manager/src/privacy_window_manager_proxy.cpp",
]
privacy_external_deps += [ "window_manager:libwsutils" ]
}
if (theme_screenlock_mgr_enable) {
privacy_cflags_cc += [ "-DTHEME_SCREENLOCK_MGR_ENABLE" ]
privacy_external_deps += [ "screenlock_mgr:screenlock_client" ]