From f88b2a4acd9f32aa324cce3036573dabd6440b97 Mon Sep 17 00:00:00 2001 From: Jackeagle Date: Mon, 18 Oct 2021 03:31:52 -0400 Subject: [PATCH] KeyStore: Add getApplicationContext method required for Asus Devices - Since Google migrated keystore to v2 they removed getApplicationContext which is required by Asus Flip Camera MotorService app. - This fixes following issue 10-14 08:53:32.136 2491 2491 E AndroidRuntime: FATAL EXCEPTION: main 10-14 08:53:32.136 2491 2491 E AndroidRuntime: Process: com.asus.motorservice, PID: 2491 10-14 08:53:32.136 2491 2491 E AndroidRuntime: java.lang.NoSuchMethodError: No static method getApplicationContext()Landroid/content/Context; in class Landroid/security/KeyStore; or its super classes (declaration of 'android.security.KeyStore' appears in /system/framework/framework.jar!classes2.dex) 10-14 08:53:32.136 2491 2491 E AndroidRuntime: at com.asus.motorservice.t.(Unknown Source:29) Change-Id: I9c95000a8f3d26022bad4a5db85eb8de48f8aa49 Signed-off-by: Jackeagle --- keystore/java/android/security/KeyStore.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/keystore/java/android/security/KeyStore.java b/keystore/java/android/security/KeyStore.java index 11b827117aa37..46fbb5f86f831 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;