OSDN Git Service

Fix sharing bugreports from lockscreen
authorJorim Jaggi <jjaggi@google.com>
Fri, 24 Feb 2017 12:49:47 +0000 (13:49 +0100)
committerJorim Jaggi <jjaggi@google.com>
Fri, 24 Feb 2017 17:37:08 +0000 (17:37 +0000)
When launching ChooserActivity from lockscreen, we will start it
in stopped state because lockscreen is still showing, meaning that
the activity goes through start -> resume -> pause -> stop
immediately after it was launched, and will be later resumed once
Keyguard actually goes away.

However, ResolverActivity finished itself in onStop. We add a
private extra to change this behavior for sharing bugreports.

Test: Take bugreport, double tap on it on lockscreen
Test: com.android.shell.BugreportReceiverTest$1
Bug: 33009364
Change-Id: I973b2c71587950499b7c88b16af9cf1387795e17

core/java/com/android/internal/app/ChooserActivity.java
core/java/com/android/internal/app/ResolverActivity.java
packages/Shell/src/com/android/shell/BugreportProgressService.java

index 84c8f7a..df65659 100644 (file)
@@ -84,6 +84,14 @@ import java.util.List;
 public class ChooserActivity extends ResolverActivity {
     private static final String TAG = "ChooserActivity";
 
+    /**
+     * Boolean extra to change the following behavior: Normally, ChooserActivity finishes itself
+     * in onStop when launched in a new task. If this extra is set to true, we do not finish
+     * ourselves when onStop gets called.
+     */
+    public static final String EXTRA_PRIVATE_RETAIN_IN_ON_STOP
+            = "com.android.internal.app.ChooserActivity.EXTRA_PRIVATE_RETAIN_IN_ON_STOP";
+
     private static final boolean DEBUG = false;
 
     private static final int QUERY_TARGET_SERVICE_LIMIT = 5;
@@ -260,6 +268,7 @@ public class ChooserActivity extends ResolverActivity {
         }
 
         mPinnedSharedPrefs = getPinnedSharedPrefs(this);
+        setRetainInOnStop(intent.getBooleanExtra(EXTRA_PRIVATE_RETAIN_IN_ON_STOP, false));
         super.onCreate(savedInstanceState, target, title, defaultTitleRes, initialIntents,
                 null, false);
 
index 0b1f0aa..9fb9cb6 100644 (file)
@@ -116,6 +116,10 @@ public class ResolverActivity extends Activity {
     private Runnable mPostListReadyRunnable;
 
     private boolean mRegistered;
+
+    /** See {@link #setRetainInOnStop}. */
+    private boolean mRetainInOnStop;
+
     private final PackageMonitor mPackageMonitor = new PackageMonitor() {
         @Override public void onSomePackagesChanged() {
             mAdapter.handlePackagesChanged();
@@ -502,7 +506,7 @@ public class ResolverActivity extends Activity {
         }
         final Intent intent = getIntent();
         if ((intent.getFlags() & FLAG_ACTIVITY_NEW_TASK) != 0 && !isVoiceInteraction()
-                && !mResolvingHome) {
+                && !mResolvingHome && !mRetainInOnStop) {
             // This resolver is in the unusual situation where it has been
             // launched at the top of a new task.  We don't let it be added
             // to the recent tasks shown to the user, and we need to make sure
@@ -1029,6 +1033,14 @@ public class ResolverActivity extends Activity {
     }
 
     /**
+     * If {@code retainInOnStop} is set to true, we will not finish ourselves when onStop gets
+     * called and we are launched in a new task.
+     */
+    protected void setRetainInOnStop(boolean retainInOnStop) {
+        mRetainInOnStop = retainInOnStop;
+    }
+
+    /**
      * Check a simple match for the component of two ResolveInfos.
      */
     static boolean resolveInfoMatch(ResolveInfo lhs, ResolveInfo rhs) {
index 12d0c03..1df626f 100644 (file)
@@ -44,6 +44,7 @@ import java.util.zip.ZipOutputStream;
 import libcore.io.Streams;
 
 import com.android.internal.annotations.VisibleForTesting;
+import com.android.internal.app.ChooserActivity;
 import com.android.internal.logging.MetricsLogger;
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.internal.util.FastPrintWriter;
@@ -943,8 +944,13 @@ public class BugreportProgressService extends Service {
     }
 
     static void sendShareIntent(Context context, Intent intent) {
-        context.startActivity(Intent.createChooser(intent,
-                context.getResources().getText(R.string.bugreport_intent_chooser_title)));
+        final Intent chooserIntent = Intent.createChooser(intent,
+                context.getResources().getText(R.string.bugreport_intent_chooser_title));
+
+        // Since we may be launched behind lockscreen, make sure that ChooserActivity doesn't finish
+        // itself in onStop.
+        chooserIntent.putExtra(ChooserActivity.EXTRA_PRIVATE_RETAIN_IN_ON_STOP, true);
+        context.startActivity(chooserIntent);
     }
 
     /**