Commit 917b7895 authored by Andrew Grieve's avatar Andrew Grieve Committed by Commit Bot

Android: Remove JellyBean code from ContextUtils.getProcessName()

We no longer support JellyBean.

Change-Id: I5dfd1af42f2336d91fea91bf6d1a953c6e964769
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1814324Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#698944}
parent 0c85a41e
...@@ -10,6 +10,7 @@ import android.content.Context; ...@@ -10,6 +10,7 @@ import android.content.Context;
import android.content.ContextWrapper; import android.content.ContextWrapper;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.AssetManager; import android.content.res.AssetManager;
import android.os.Build;
import android.os.Process; import android.os.Process;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
...@@ -17,6 +18,7 @@ import androidx.annotation.Nullable; ...@@ -17,6 +18,7 @@ import androidx.annotation.Nullable;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.MainDex; import org.chromium.base.annotations.MainDex;
import org.chromium.base.annotations.VerifiesOnP;
/** /**
* This class provides Android application context related utility methods. * This class provides Android application context related utility methods.
...@@ -25,8 +27,6 @@ import org.chromium.base.annotations.MainDex; ...@@ -25,8 +27,6 @@ import org.chromium.base.annotations.MainDex;
public class ContextUtils { public class ContextUtils {
private static final String TAG = "ContextUtils"; private static final String TAG = "ContextUtils";
private static Context sApplicationContext; private static Context sApplicationContext;
// TODO(agrieve): Remove sProcessName caching when we stop supporting JB.
private static String sProcessName;
/** /**
* Initialization-on-demand holder. This exists for thread-safe lazy initialization. * Initialization-on-demand holder. This exists for thread-safe lazy initialization.
...@@ -142,24 +142,15 @@ public class ContextUtils { ...@@ -142,24 +142,15 @@ public class ContextUtils {
} }
/** @return The name of the current process. E.g. "org.chromium.chrome:privileged_process0". */ /** @return The name of the current process. E.g. "org.chromium.chrome:privileged_process0". */
@VerifiesOnP
public static String getProcessName() { public static String getProcessName() {
// Once we drop support JB, this method can be simplified to not cache sProcessName and call if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
// ActivityThread.currentProcessName(). return Application.getProcessName();
if (sProcessName != null) {
return sProcessName;
} }
try { try {
// An even more convenient ActivityThread.currentProcessName() exists, but was not added
// until JB MR2.
Class<?> activityThreadClazz = Class.forName("android.app.ActivityThread"); Class<?> activityThreadClazz = Class.forName("android.app.ActivityThread");
Object activityThread = return (String) activityThreadClazz.getMethod("currentProcessName").invoke(null);
activityThreadClazz.getMethod("currentActivityThread").invoke(null); } catch (Exception e) {
// Before JB MR2, currentActivityThread() returns null when called on a non-UI thread.
// Cache the name to allow other threads to access it.
sProcessName =
(String) activityThreadClazz.getMethod("getProcessName").invoke(activityThread);
return sProcessName;
} catch (Exception e) { // No multi-catch below API level 19 for reflection exceptions.
// If fallback logic is ever needed, refer to: // If fallback logic is ever needed, refer to:
// https://chromium-review.googlesource.com/c/chromium/src/+/905563/1 // https://chromium-review.googlesource.com/c/chromium/src/+/905563/1
throw new RuntimeException(e); throw new RuntimeException(e);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment