Skip to content

Commit

Permalink
fix(core.runtime): 支持Application.getProcessName()方法
Browse files Browse the repository at this point in the history
fix #606

(cherry picked from commit a75c81c)
  • Loading branch information
shifujun committed May 7, 2022
1 parent 54daf8c commit c8e5ad4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
)
);
}
}
}

0 comments on commit c8e5ad4

Please sign in to comment.