From ee7ab99e8e8521ec59b2a8a0eb2f3e0f2c77509c Mon Sep 17 00:00:00 2001 From: shifujun Date: Mon, 22 Apr 2024 15:35:16 +0800 Subject: [PATCH] =?UTF-8?q?fix(core.runtime):=20getDatabasePath=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E4=BC=A0=E7=BB=9D=E5=AF=B9=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 对齐ContextImpl的逻辑。 https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/core/java/android/app/ContextImpl.java;l=1018;drc=88bbe8206f93272a610e9d24182c6e80b94d8548?hl=zh-cn fix #1049 --- .../shadow/core/runtime/SubDirContextThemeWrapper.java | 3 ++- .../cases/plugin_main/SubDirContextThemeWrapperTest.java | 4 ++++ .../context/SubDirContextThemeWrapperTestActivity.java | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/projects/sdk/core/runtime/src/main/java/com/tencent/shadow/core/runtime/SubDirContextThemeWrapper.java b/projects/sdk/core/runtime/src/main/java/com/tencent/shadow/core/runtime/SubDirContextThemeWrapper.java index 9a275e711..cd5bbb40b 100644 --- a/projects/sdk/core/runtime/src/main/java/com/tencent/shadow/core/runtime/SubDirContextThemeWrapper.java +++ b/projects/sdk/core/runtime/src/main/java/com/tencent/shadow/core/runtime/SubDirContextThemeWrapper.java @@ -301,7 +301,8 @@ public boolean deleteDatabase(String name) { @Override public File getDatabasePath(String name) { - if (getSubDirName() == null) { + if (getSubDirName() == null + || name.charAt(0) == File.separatorChar) { return super.getDatabasePath(name); } else { return super.getDatabasePath(makeSubName(name)); diff --git a/projects/test/dynamic/host/test-dynamic-host/src/androidTest/java/com/tencent/shadow/test/cases/plugin_main/SubDirContextThemeWrapperTest.java b/projects/test/dynamic/host/test-dynamic-host/src/androidTest/java/com/tencent/shadow/test/cases/plugin_main/SubDirContextThemeWrapperTest.java index 2222890e1..e0c14a5b8 100644 --- a/projects/test/dynamic/host/test-dynamic-host/src/androidTest/java/com/tencent/shadow/test/cases/plugin_main/SubDirContextThemeWrapperTest.java +++ b/projects/test/dynamic/host/test-dynamic-host/src/androidTest/java/com/tencent/shadow/test/cases/plugin_main/SubDirContextThemeWrapperTest.java @@ -317,6 +317,10 @@ public void testGetDatabasePath() { "TAG_GET_DATABASE_PATH_BAR", hostDatabasePath + "/" + EXPECT_NAME + "_bar" ); + matchTextWithViewTag( + "TAG_GET_DATABASE_ABSOLUTE_PATH_FOO_BAR", + "/foo/bar" + ); } @Test diff --git a/projects/test/plugin/general-cases/test-plugin-general-cases/src/main/java/com/tencent/shadow/test/plugin/general_cases/lib/usecases/context/SubDirContextThemeWrapperTestActivity.java b/projects/test/plugin/general-cases/test-plugin-general-cases/src/main/java/com/tencent/shadow/test/plugin/general_cases/lib/usecases/context/SubDirContextThemeWrapperTestActivity.java index 77e541d1c..04331625a 100644 --- a/projects/test/plugin/general-cases/test-plugin-general-cases/src/main/java/com/tencent/shadow/test/plugin/general_cases/lib/usecases/context/SubDirContextThemeWrapperTestActivity.java +++ b/projects/test/plugin/general-cases/test-plugin-general-cases/src/main/java/com/tencent/shadow/test/plugin/general_cases/lib/usecases/context/SubDirContextThemeWrapperTestActivity.java @@ -237,6 +237,11 @@ protected void fillTestValues(Context testContext) { testContext.getDatabasePath("bar").getAbsolutePath() ); + // 传绝对路径给getDatabasePath应该返回路径不变的文件 + makeItem("getDatabasePath(\"/foo/bar\")", "TAG_GET_DATABASE_ABSOLUTE_PATH_FOO_BAR", + testContext.getDatabasePath("/foo/bar").getAbsolutePath() + ); + Context hostContext = getApplication().getBaseContext(); hostContext.openOrCreateDatabase("foo", MODE_PRIVATE, null);