Snap for 7514518 from 8749dd1a0dd6ed090f3bba40b8906a578794c3f2 to sc-release

Change-Id: Ibba072023023238957786b6b18e3b5cb6d71b57a
diff --git a/apex/Android.bp b/apex/Android.bp
index 3c9f13e..e018565 100644
--- a/apex/Android.bp
+++ b/apex/Android.bp
@@ -28,6 +28,7 @@
     manifest: "apex_manifest.json",
     key: "com.android.adbd.key",
     certificate: ":com.android.adbd.certificate",
+    compressible: true,
 }
 
 soong_config_module_type_import {
diff --git a/daemon/file_sync_service.cpp b/daemon/file_sync_service.cpp
index 513b8dd..b59da97 100644
--- a/daemon/file_sync_service.cpp
+++ b/daemon/file_sync_service.cpp
@@ -65,6 +65,7 @@
 
 using android::base::borrowed_fd;
 using android::base::Dirname;
+using android::base::Realpath;
 using android::base::StringPrintf;
 
 static bool should_use_fs_config(const std::string& path) {
@@ -369,8 +370,16 @@
             goto fail;
         } else {
             if (fchown(fd.get(), uid, gid) == -1) {
-                SendSyncFailErrno(s, "fchown failed");
-                goto fail;
+                struct stat st;
+                std::string real_path;
+
+                // Only return failure if parent directory does not have S_ISGID bit set,
+                // if S_ISGID is set then file will inherit groupid from directory
+                if (!Realpath(path, &real_path) || lstat(Dirname(real_path).c_str(), &st) == -1 ||
+                    (S_ISDIR(st.st_mode) && (st.st_mode & S_ISGID) == 0)) {
+                    SendSyncFailErrno(s, "fchown failed");
+                    goto fail;
+                }
             }
 
 #if defined(__ANDROID__)