diff --git a/keystore/java/android/security/KeyStore.java b/keystore/java/android/security/KeyStore.java index 11b827117aa3..46fbb5f86f83 100644 --- a/keystore/java/android/security/KeyStore.java +++ b/keystore/java/android/security/KeyStore.java @@ -16,7 +16,10 @@ package android.security; +import android.app.ActivityThread; +import android.app.Application; import android.compat.annotation.UnsupportedAppUsage; +import android.content.Context; import android.os.Build; import android.os.StrictMode; @@ -37,6 +40,17 @@ public class KeyStore { private static final KeyStore KEY_STORE = new KeyStore(); + /** @hide */ + @UnsupportedAppUsage + public static Context getApplicationContext() { + Application application = ActivityThread.currentApplication(); + if (application == null) { + throw new IllegalStateException( + "Failed to obtain application Context from ActivityThread"); + } + return application; + } + @UnsupportedAppUsage public static KeyStore getInstance() { return KEY_STORE;