Check for any permissions before holding any sf locks

Also fixes an incorrect permissions check in setClientState to
check a cached value since it is now called on the main thread.

Test: presubmit tests
Fixes: 180180131

Change-Id: I87f2dc0683780166fec8738265c74d8d706a8575
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index 21cd2a5..3f21f77 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -344,7 +344,8 @@
 
     virtual uint32_t setClientStateLocked(
             const FrameTimelineInfo& info, const ComposerState& composerState,
-            int64_t desiredPresentTime, bool isAutoTimestamp, int64_t postTime, bool privileged,
+            int64_t desiredPresentTime, bool isAutoTimestamp, int64_t postTime,
+            uint32_t permissions,
             std::unordered_set<ListenerCallbacks, ListenerCallbacksHash>& listenerCallbacks)
             REQUIRES(mStateLock);
     virtual void commitTransactionLocked();
@@ -441,7 +442,7 @@
                          const sp<IBinder>& applyToken,
                          const InputWindowCommands& inputWindowCommands, int64_t desiredPresentTime,
                          bool isAutoTimestamp, const client_cache_t& uncacheBuffer,
-                         int64_t postTime, bool privileged, bool hasListenerCallbacks,
+                         int64_t postTime, uint32_t permissions, bool hasListenerCallbacks,
                          std::vector<ListenerCallbacks> listenerCallbacks, int originPid,
                          int originUid, uint64_t transactionId)
               : frameTimelineInfo(frameTimelineInfo),
@@ -454,7 +455,7 @@
                 isAutoTimestamp(isAutoTimestamp),
                 buffer(uncacheBuffer),
                 postTime(postTime),
-                privileged(privileged),
+                permissions(permissions),
                 hasListenerCallbacks(hasListenerCallbacks),
                 listenerCallbacks(listenerCallbacks),
                 originPid(originPid),
@@ -471,7 +472,7 @@
         const bool isAutoTimestamp;
         client_cache_t buffer;
         const int64_t postTime;
-        bool privileged;
+        uint32_t permissions;
         bool hasListenerCallbacks;
         std::vector<ListenerCallbacks> listenerCallbacks;
         int originPid;
@@ -740,7 +741,7 @@
                                const InputWindowCommands& inputWindowCommands,
                                const int64_t desiredPresentTime, bool isAutoTimestamp,
                                const client_cache_t& uncacheBuffer, const int64_t postTime,
-                               bool privileged, bool hasListenerCallbacks,
+                               uint32_t permissions, bool hasListenerCallbacks,
                                const std::vector<ListenerCallbacks>& listenerCallbacks,
                                int originPid, int originUid, uint64_t transactionId)
             REQUIRES(mStateLock);