From c8e5ad4c8a09da074a8b5e6b739879a104accf8b Mon Sep 17 00:00:00 2001 From: shifujun Date: Fri, 10 Sep 2021 15:54:38 +0800 Subject: [PATCH] =?UTF-8?q?fix(core.runtime):=20=E6=94=AF=E6=8C=81Applicat?= =?UTF-8?q?ion.getProcessName()=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix #606 (cherry picked from commit a75c81cd644114b22832ab6f411658a9ef5ffd22) --- .../shadow/core/runtime/ShadowApplication.java | 6 ++++++ .../test/cases/plugin_main/ApplicationTest.java | 8 ++++++++ .../application/TestApplicationActivity.java | 13 +++++++++++++ 3 files changed, 27 insertions(+) diff --git a/projects/sdk/core/runtime/src/main/java/com/tencent/shadow/core/runtime/ShadowApplication.java b/projects/sdk/core/runtime/src/main/java/com/tencent/shadow/core/runtime/ShadowApplication.java index ad3c9e145..7e7b7ce7b 100644 --- a/projects/sdk/core/runtime/src/main/java/com/tencent/shadow/core/runtime/ShadowApplication.java +++ b/projects/sdk/core/runtime/src/main/java/com/tencent/shadow/core/runtime/ShadowApplication.java @@ -18,6 +18,7 @@ package com.tencent.shadow.core.runtime; +import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.app.Application; import android.content.BroadcastReceiver; @@ -158,4 +159,9 @@ public void attachBaseContext(Context base) { public void setAppComponentFactory(ShadowAppComponentFactory factory) { mAppComponentFactory = factory; } + + @SuppressLint("NewApi") + public static String getProcessName() { + return Application.getProcessName(); + } } diff --git a/projects/test/dynamic/host/test-dynamic-host/src/androidTest/java/com/tencent/shadow/test/cases/plugin_main/ApplicationTest.java b/projects/test/dynamic/host/test-dynamic-host/src/androidTest/java/com/tencent/shadow/test/cases/plugin_main/ApplicationTest.java index 29b688768..bf31c50fe 100644 --- a/projects/test/dynamic/host/test-dynamic-host/src/androidTest/java/com/tencent/shadow/test/cases/plugin_main/ApplicationTest.java +++ b/projects/test/dynamic/host/test-dynamic-host/src/androidTest/java/com/tencent/shadow/test/cases/plugin_main/ApplicationTest.java @@ -19,11 +19,13 @@ package com.tencent.shadow.test.cases.plugin_main; import android.content.Intent; +import android.os.Build; import androidx.test.core.app.ApplicationProvider; import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.LargeTest; +import org.junit.Assume; import org.junit.Test; import org.junit.runner.RunWith; @@ -48,4 +50,10 @@ public void testApplication() { matchTextWithViewTag("TAG_IS_ON_CREATE", Boolean.toString(true)); } + @Test + public void testApplicationGetProcessName() { + Assume.assumeTrue(Build.VERSION.SDK_INT >= Build.VERSION_CODES.P); + matchTextWithViewTag("Application.getProcessName()", + ApplicationProvider.getApplicationContext().getPackageName()); + } } diff --git a/projects/test/plugin/general-cases/general-cases-lib/src/main/java/com/tencent/shadow/test/plugin/general_cases/lib/usecases/application/TestApplicationActivity.java b/projects/test/plugin/general-cases/general-cases-lib/src/main/java/com/tencent/shadow/test/plugin/general_cases/lib/usecases/application/TestApplicationActivity.java index 5805fa3ff..27f442107 100644 --- a/projects/test/plugin/general-cases/general-cases-lib/src/main/java/com/tencent/shadow/test/plugin/general_cases/lib/usecases/application/TestApplicationActivity.java +++ b/projects/test/plugin/general-cases/general-cases-lib/src/main/java/com/tencent/shadow/test/plugin/general_cases/lib/usecases/application/TestApplicationActivity.java @@ -19,6 +19,8 @@ package com.tencent.shadow.test.plugin.general_cases.lib.usecases.application; import android.app.Activity; +import android.app.Application; +import android.os.Build; import android.os.Bundle; import android.support.annotation.Nullable; import android.view.ViewGroup; @@ -43,5 +45,16 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { Boolean.toString(TestApplication.getInstance().isOnCreate) ) ); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + mItemViewGroup.addView( + UiUtil.makeItem( + this, + "Application.getProcessName()", + "Application.getProcessName()", + Application.getProcessName() + ) + ); + } } }