add system permission for float window in demos and tdd

Signed-off-by: 17342015572 <hujunjian1@huawei.com>
Change-Id: Id3f976fdd096d202dd63bfe830566dd311deabfb
This commit is contained in:
17342015572 2024-10-09 01:51:44 +00:00
parent 0d78a55f05
commit bb7f2f2c9e
15 changed files with 109 additions and 39 deletions

View File

@ -29,6 +29,7 @@ public:
static void SetAceessTokenPermission(const std::string processName);
static void SetAceessTokenPermission(const std::string processName,
const char** perms, const int permCount);
static void GuaranteeFloatWindowPermission(const std::string processName);
};
} // namespace OHOS::Rosen
#endif // TEST_UTILS_H

View File

@ -12,6 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <iostream>
#include "common_test_utils.h"
#include <access_token.h>
@ -105,4 +106,26 @@ void CommonTestUtils::SetAceessTokenPermission(const std::string processName,
SetSelfTokenID(tokenId);
OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
}
void CommonTestUtils::GuaranteeFloatWindowPermission(const std::string processName)
{
const char **perms = new const char *[1];
perms[0] = "ohos.permission.SYSTEM_FLOAT_WINDOW";
NativeTokenInfoParams infoInstance = {
.dcapsNum = 0,
.permsNum = 1,
.aclsNum = 0,
.dcaps = nullptr,
.perms = perms,
.acls = nullptr,
.processName = processName.c_str(),
.aplStr = "system_core",
};
uint64_t tokenId = GetAccessTokenId(&infoInstance);
auto ret = SetSelfTokenID(tokenId);
auto ret1 = OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
std::cout << "Guarantee float window permission, processName: " << processName << ", tokenId: " <<
tokenId << ", set selfTokenId return: " << ret << ", reload native tokenInfo return: " << ret1 << std::endl;
delete[] perms;
}
} // namespace OHOS::Rosen

View File

@ -101,7 +101,10 @@ ohos_executable("demo_system_sub_window") {
"../common/utils/include",
]
deps = [ "${window_base_path}/wm:libwm" ]
deps = [
"${window_base_path}/test/common/utils:libtestutil",
"${window_base_path}/wm:libwm",
]
external_deps = [
"c_utils:utils",

View File

@ -20,7 +20,7 @@
#include "wm_common.h"
#include "window_option.h"
#include "window_manager.h"
#include "common_test_utils.h"
#include "future.h"
namespace OHOS {
@ -63,6 +63,7 @@ int main(int argc, char* argv[])
std::cout << "before add window " << std::endl;
OutputWindowInfos(infos);
CommonTestUtils::GuaranteeFloatWindowPermission("demo_system_sub_window");
Rect baseWindowRect = { 150, 150, 400, 600 };
sptr<WindowOption> baseOp = new WindowOption();
baseOp->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);

View File

@ -66,6 +66,7 @@ ohos_systemtest("wms_window_layout_test") {
deps = [
":wms_systemtest_common",
"${window_base_path}/test/common/utils:libtestutil",
"${window_base_path}/window_scene/common:window_scene_common",
"${window_base_path}/window_scene/interfaces/innerkits:libwsutils",
"${window_base_path}/window_scene/session:scene_session",
@ -83,7 +84,10 @@ ohos_systemtest("wms_window_effect_test") {
sources = [ "window_effect_test.cpp" ]
deps = [ ":wms_systemtest_common" ]
deps = [
":wms_systemtest_common",
"${window_base_path}/test/common/utils:libtestutil",
]
external_deps = [
"c_utils:utils",
@ -125,7 +129,10 @@ ohos_systemtest("wms_window_systemsubwindow_test") {
sources = [ "window_systemsubwindow_test.cpp" ]
deps = [ ":wms_systemtest_common" ]
deps = [
":wms_systemtest_common",
"${window_base_path}/test/common/utils:libtestutil",
]
external_deps = [
"bundle_framework:appexecfwk_base",
@ -346,7 +353,10 @@ ohos_systemtest("wms_window_raisetoapptop_test") {
sources = [ "window_raisetoapptop_test.cpp" ]
deps = [ ":wms_systemtest_common" ]
deps = [
":wms_systemtest_common",
"${window_base_path}/test/common/utils:libtestutil",
]
external_deps = [
"c_utils:utils",
@ -416,7 +426,10 @@ ohos_systemtest("wms_window_app_floating_window_test") {
sources = [ "window_app_floating_window_test.cpp" ]
deps = [ ":wms_systemtest_common" ]
deps = [
":wms_systemtest_common",
"${window_base_path}/test/common/utils:libtestutil",
]
external_deps = [
"c_utils:utils",
@ -446,7 +459,10 @@ ohos_systemtest("wms_window_animation_transition_test") {
sources = [ "window_animation_transition_test.cpp" ]
deps = [ ":wms_systemtest_common" ]
deps = [
":wms_systemtest_common",
"${window_base_path}/test/common/utils:libtestutil",
]
external_deps = [
"c_utils:utils",
@ -492,6 +508,7 @@ config("wms_systemtest_common_public_config") {
"${window_base_path}/wmserver/include",
"${window_base_path}/interfaces/innerkits/wm",
"${window_base_path}/utils/include",
"${window_base_path}/test/common/utils/include",
"//commonlibrary/c_utils/base/include",
"//foundation/communication/ipc/interfaces/innerkits/ipc_core/include",
"//base/hiviewdfx/hilog/interfaces/native/innerkits/include",

View File

@ -17,6 +17,7 @@
#include <gtest/gtest.h>
#include "window.h"
#include "wm_common.h"
#include "common_test_utils.h"
#include "window_test_utils.h"
using namespace testing;
using namespace testing::ext;
@ -76,6 +77,7 @@ void WindowAnimationTransitionTest::TearDownTestCase()
void WindowAnimationTransitionTest::SetUp()
{
CommonTestUtils::GuaranteeFloatWindowPermission("wms_window_animation_transition_test");
windowInfo_ = {
.name = "AnimationTestWindow",
.rect = {0, 0, 200, 200},

View File

@ -21,6 +21,7 @@
#include "window_manager.h"
#include "window_option.h"
#include "window_scene.h"
#include "common_test_utils.h"
#include "window_test_utils.h"
#include "wm_common.h"
@ -79,6 +80,7 @@ void WindowAppFloatingWindowTest::TearDownTestCase()
void WindowAppFloatingWindowTest::SetUp()
{
CommonTestUtils::GuaranteeFloatWindowPermission("wms_window_app_floating_window_test");
}
void WindowAppFloatingWindowTest::TearDown()

View File

@ -16,6 +16,7 @@
// gtest
#include <gtest/gtest.h>
#include "display_manager_proxy.h"
#include "common_test_utils.h"
#include "window_test_utils.h"
#include "window_accessibility_controller.h"
#include "wm_common.h"
@ -46,6 +47,7 @@ void WindowEffectTest::TearDownTestCase()
void WindowEffectTest::SetUp()
{
CommonTestUtils::GuaranteeFloatWindowPermission("wms_window_effect_test");
windowInfo_ = {
.name = "TestWindow",
.rect = {0, 0, 100, 200},

View File

@ -15,6 +15,7 @@
// gtest
#include <gtest/gtest.h>
#include "common_test_utils.h"
#include "window_test_utils.h"
#include "wm_common.h"
#include "window_adapter.h"
@ -23,6 +24,7 @@
#include "mock_session.h"
#include "session/host/include/scene_session.h"
using namespace testing;
using namespace testing::ext;
@ -115,6 +117,7 @@ void WindowLayoutTest::SetUp()
{
activeWindows_.clear();
abilityContext_ = std::make_shared<AbilityRuntime::AbilityContextImpl>();
CommonTestUtils::GuaranteeFloatWindowPermission("wms_window_app_floating_window_test");
}
void WindowLayoutTest::TearDown()

View File

@ -15,8 +15,8 @@
// gtest
#include <gtest/gtest.h>
#include "common_test_utils.h"
#include "window_test_utils.h"
#include "window_impl.h"
#include "wm_common.h"
@ -214,6 +214,7 @@ HWTEST_F(WindowRaiseToAppTopTest, RaiseWhenHide, Function | MediumTest | Level3)
*/
HWTEST_F(WindowRaiseToAppTopTest, NotAppSubWindow, Function | MediumTest | Level3)
{
CommonTestUtils::GuaranteeFloatWindowPermission("window_raisetoapptop_test");
fullInfo_.name = "mainWindow.1";
fullInfo_.type = WindowType::WINDOW_TYPE_FLOAT;
sptr<Window> mainWindow = Utils::CreateTestWindow(fullInfo_);

View File

@ -16,7 +16,7 @@
// gtest
#include <gtest/gtest.h>
#include <ability_context.h>
#include "common_test_utils.h"
#include "window_test_utils.h"
#include "window.h"
#include "window_option.h"
@ -34,6 +34,32 @@ public:
static void TearDownTestCase();
virtual void SetUp() override;
virtual void TearDown() override;
// define windowTypes_ for SystemSubWindow02
std::vector<WindowType> windowTypes_ = {
WindowType::WINDOW_TYPE_APP_LAUNCHING,
WindowType::WINDOW_TYPE_DOCK_SLICE,
WindowType::WINDOW_TYPE_INCOMING_CALL,
WindowType::WINDOW_TYPE_SEARCHING_BAR,
WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW,
WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT,
WindowType::WINDOW_TYPE_FLOAT,
WindowType::WINDOW_TYPE_TOAST,
WindowType::WINDOW_TYPE_STATUS_BAR,
WindowType::WINDOW_TYPE_PANEL,
WindowType::WINDOW_TYPE_VOLUME_OVERLAY,
WindowType::WINDOW_TYPE_NAVIGATION_BAR,
WindowType::WINDOW_TYPE_DRAGGING_EFFECT,
WindowType::WINDOW_TYPE_POINTER,
WindowType::WINDOW_TYPE_LAUNCHER_RECENT,
WindowType::WINDOW_TYPE_LAUNCHER_DOCK,
WindowType::WINDOW_TYPE_BOOT_ANIMATION,
WindowType::WINDOW_TYPE_FREEZE_DISPLAY,
WindowType::WINDOW_TYPE_VOICE_INTERACTION,
WindowType::WINDOW_TYPE_FLOAT_CAMERA,
WindowType::WINDOW_TYPE_PLACEHOLDER,
WindowType::WINDOW_TYPE_SCREENSHOT,
WindowType::WINDOW_TYPE_GLOBAL_SEARCH,
};
};
void WindowSystemSubWindowTest::SetUpTestCase()
@ -143,32 +169,10 @@ HWTEST_F(WindowSystemSubWindowTest, SystemSubWindow01, Function | MediumTest | L
*/
HWTEST_F(WindowSystemSubWindowTest, SystemSubWindow02, Function | MediumTest | Level2)
{
std::vector<WindowType> windowTypes = {
WindowType::WINDOW_TYPE_APP_LAUNCHING,
WindowType::WINDOW_TYPE_DOCK_SLICE,
WindowType::WINDOW_TYPE_INCOMING_CALL,
WindowType::WINDOW_TYPE_SEARCHING_BAR,
WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW,
WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT,
WindowType::WINDOW_TYPE_FLOAT,
WindowType::WINDOW_TYPE_TOAST,
WindowType::WINDOW_TYPE_STATUS_BAR,
WindowType::WINDOW_TYPE_PANEL,
WindowType::WINDOW_TYPE_VOLUME_OVERLAY,
WindowType::WINDOW_TYPE_NAVIGATION_BAR,
WindowType::WINDOW_TYPE_DRAGGING_EFFECT,
WindowType::WINDOW_TYPE_POINTER,
WindowType::WINDOW_TYPE_LAUNCHER_RECENT,
WindowType::WINDOW_TYPE_LAUNCHER_DOCK,
WindowType::WINDOW_TYPE_BOOT_ANIMATION,
WindowType::WINDOW_TYPE_FREEZE_DISPLAY,
WindowType::WINDOW_TYPE_VOICE_INTERACTION,
WindowType::WINDOW_TYPE_FLOAT_CAMERA,
WindowType::WINDOW_TYPE_PLACEHOLDER,
WindowType::WINDOW_TYPE_SCREENSHOT,
WindowType::WINDOW_TYPE_GLOBAL_SEARCH,
};
for (auto itor = windowTypes.begin(); itor != windowTypes.end(); itor++) {
for (auto itor = windowTypes_.begin(); itor != windowTypes_.end(); itor++) {
if (static_cast<WindowType>(*itor) == WindowType::WINDOW_TYPE_FLOAT) {
CommonTestUtils::GuaranteeFloatWindowPermission("wms_window_systemsubwindow_test");
}
struct Rect baseRect = {0, 0, 100, 200};
uint32_t baseFlags = 0;
sptr<Window> baseWindow = CreateBaseWindow(static_cast<WindowType>(*itor), baseRect, baseFlags);

View File

@ -617,10 +617,13 @@ ohos_unittest("ws_scene_session_manager_test4") {
ohos_unittest("ws_scene_session_manager_test5") {
module_out_path = module_out_path
include_dirs = [ "${window_base_path}/test/common/utils/include/" ]
sources = [ "scene_session_manager_test5.cpp" ]
deps = [ ":ws_unittest_common" ]
deps = [
":ws_unittest_common",
"${window_base_path}/test/common/utils:libtestutil",
]
external_deps = [
"ability_base:configuration",

View File

@ -29,10 +29,12 @@
#include "window_manager_agent.h"
#include "session_manager.h"
#include "zidl/window_manager_agent_interface.h"
#include "common_test_utils.h"
#include "mock/mock_session_stage.h"
#include "mock/mock_window_event_channel.h"
#include "context.h"
using namespace testing;
using namespace testing::ext;
@ -1205,6 +1207,7 @@ HWTEST_F(SceneSessionManagerTest5, CreateAndConnectSpecificSession02, Function |
info.bundleName_ = "test2";
sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
ASSERT_NE(property, nullptr);
CommonTestUtils::GuaranteeFloatWindowPermission("ws_scene_session_manager_test5");
property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
property->SetWindowFlags(123);
ssm_->CreateAndConnectSpecificSession(sessionStage, eventChannel, node, property, id, session,

View File

@ -477,10 +477,13 @@ ohos_unittest("wm_window_scene_session_impl_test3") {
ohos_unittest("wm_window_scene_session_impl_test4") {
module_out_path = module_out_path
include_dirs = [ "${window_base_path}/test/common/utils/include/" ]
sources = [ "window_scene_session_impl_test4.cpp" ]
deps = [ ":wm_unittest_common" ]
deps = [
":wm_unittest_common",
"${window_base_path}/test/common/utils:libtestutil",
]
external_deps = [
"c_utils:utils",

View File

@ -17,6 +17,7 @@
#include <parameters.h>
#include "ability_context_impl.h"
#include "display_info.h"
#include "common_test_utils.h"
#include "mock_session.h"
#include "mock_uicontent.h"
#include "mock_window_adapter.h"
@ -53,6 +54,7 @@ void WindowSceneSessionImplTest4::TearDownTestCase() {}
void WindowSceneSessionImplTest4::SetUp()
{
abilityContext_ = std::make_shared<AbilityRuntime::AbilityContextImpl>();
CommonTestUtils::GuaranteeFloatWindowPermission("wm_window_scene_session_impl_test4");
}
void WindowSceneSessionImplTest4::TearDown()