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() + ) + ); + } } }