summaryrefslogtreecommitdiff
path: root/keystore/java/android/security/KeyChain.java
diff options
context:
space:
mode:
authorRobin Lee <rgl@google.com>2016-08-12 12:46:28 +0100
committerRobin Lee <rgl@google.com>2016-08-23 12:47:54 +0000
commitda23618043667e9cee680688b7413f65b400516e (patch)
treefb234ca3e4f157ba5d46e4b73dd36ba445fadd09 /keystore/java/android/security/KeyChain.java
parentab6e7c3502e191abb956f9f17959b627e230b0db (diff)
Documentation warning against short-lived Contexts
It's better to use an Application Context rather than hoping the activity won't be destroyed in another thread (because it will). Change-Id: I9bf842d0d7dbedcc509a4a314d23a9a6cfca4d48 Fix: 29873669
Diffstat (limited to 'keystore/java/android/security/KeyChain.java')
-rw-r--r--keystore/java/android/security/KeyChain.java7
1 files changed, 7 insertions, 0 deletions
diff --git a/keystore/java/android/security/KeyChain.java b/keystore/java/android/security/KeyChain.java
index cce58c2096f3..be9ebb58675e 100644
--- a/keystore/java/android/security/KeyChain.java
+++ b/keystore/java/android/security/KeyChain.java
@@ -20,6 +20,7 @@ import android.annotation.Nullable;
import android.annotation.WorkerThread;
import android.app.Activity;
import android.app.PendingIntent;
+import android.app.Service;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -356,6 +357,9 @@ public final class KeyChain {
*
* <p> This method may block while waiting for a connection to another process, and must never
* be called from the main thread.
+ * <p> As {@link Activity} and {@link Service} contexts are short-lived and can be destroyed
+ * at any time from the main thread, it is safer to rely on a long-lived context such as one
+ * returned from {@link Context#getApplicationContext()}.
*
* @param alias The alias of the desired private key, typically returned via
* {@link KeyChainAliasCallback#alias}.
@@ -400,6 +404,9 @@ public final class KeyChain {
*
* <p> This method may block while waiting for a connection to another process, and must never
* be called from the main thread.
+ * <p> As {@link Activity} and {@link Service} contexts are short-lived and can be destroyed
+ * at any time from the main thread, it is safer to rely on a long-lived context such as one
+ * returned from {@link Context#getApplicationContext()}.
*
* @param alias The alias of the desired certificate chain, typically
* returned via {@link KeyChainAliasCallback#alias}.