Skip screenshots when user storage is locked.

Screenshots are written to shared storage, which isn't available
until after the user unlocks their device for the first time.  So
instead of showing a misleading animation and then the "failed to
persist" notification, skip the screenshot completely when storage
is locked.

Bug: 27208608
Change-Id: I654c6688f68b2395f6e6065aa716551948f302b3
diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/TakeScreenshotService.java b/packages/SystemUI/src/com/android/systemui/screenshot/TakeScreenshotService.java
index 4badc42..f3bae20 100644
--- a/packages/SystemUI/src/com/android/systemui/screenshot/TakeScreenshotService.java
+++ b/packages/SystemUI/src/com/android/systemui/screenshot/TakeScreenshotService.java
@@ -23,6 +23,8 @@
 import android.os.Message;
 import android.os.Messenger;
 import android.os.RemoteException;
+import android.os.UserManager;
+import android.util.Log;
 import android.view.WindowManager;
 
 public class TakeScreenshotService extends Service {
@@ -44,6 +46,16 @@
                     }
                 }
             };
+
+            // If the storage for this user is locked, we have no place to store
+            // the screenshot, so skip taking it instead of showing a misleading
+            // animation and error notification.
+            if (!getSystemService(UserManager.class).isUserUnlocked()) {
+                Log.w(TAG, "Skipping screenshot because storage is locked!");
+                post(finisher);
+                return;
+            }
+
             if (mScreenshot == null) {
                 mScreenshot = new GlobalScreenshot(TakeScreenshotService.this);
             }