Skip to content

Commit

Permalink
KeyStore: Add getApplicationContext method required for Asus Devices
Browse files Browse the repository at this point in the history
- 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.<init>(Unknown Source:29)

Change-Id: I9c95000a8f3d26022bad4a5db85eb8de48f8aa49
Signed-off-by: Jackeagle <[email protected]>
  • Loading branch information
Jackeagle committed May 10, 2024
1 parent 710b69c commit f88b2a4
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions keystore/java/android/security/KeyStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down

0 comments on commit f88b2a4

Please sign in to comment.