Merge cherrypicks of ['googleplex-android-review.googlesource.com/39515976', 'googleplex-android-review.googlesource.com/39537230'] into 26Q2-release.

Change-Id: Ic7e5996dfb1170f9433dbaaf18a2bebd59e0718f
diff --git a/cmds/installd/InstalldNativeService.cpp b/cmds/installd/InstalldNativeService.cpp
index c289b60..21dbf89 100644
--- a/cmds/installd/InstalldNativeService.cpp
+++ b/cmds/installd/InstalldNativeService.cpp
@@ -930,12 +930,14 @@
             chown_app_profile_dir(packageName, appId, userId);
         }
 
-        if (flags::enable_set_inode_quotas()) {
+        #if APPLY_HARD_QUOTAS
+        if (flags::enable_set_inode_quotas() && appId >= FIRST_APPLICATION_UID) {
             ScopedTrace tracer_quota("prepare_app_inode_quota");
             if (!PrepareAppInodeQuota(uuid ? uuid->c_str() : "", uid)) {
                 PLOG(ERROR) << "Failed to set hard quota " + path;
             }
         }
+        #endif
 
         {
             ScopedTrace tracer_profile("prepare_app_profile_dir");
diff --git a/cmds/installd/QuotaUtils.cpp b/cmds/installd/QuotaUtils.cpp
index 28bfea6..54ff0e9 100644
--- a/cmds/installd/QuotaUtils.cpp
+++ b/cmds/installd/QuotaUtils.cpp
@@ -151,7 +151,6 @@
         return true;
     }
 
-#if APPLY_HARD_QUOTAS
     struct dqblk dq;
     if (quotactl(QCMD(Q_GETQUOTA, USRQUOTA), device.c_str(), uid, reinterpret_cast<char*>(&dq)) !=
         0) {
@@ -184,10 +183,6 @@
         // Hard quota already set; assume it's reasonable
         return true;
     }
-#else
-    // Hard quotas disabled
-    return true;
-#endif
 }
 
 int64_t GetInodesQuotaHardLimitsForUid(const std::string& uuid, uid_t uid) {
diff --git a/cmds/installd/tests/installd_service_test.cpp b/cmds/installd/tests/installd_service_test.cpp
index 402057a..1a47419 100644
--- a/cmds/installd/tests/installd_service_test.cpp
+++ b/cmds/installd/tests/installd_service_test.cpp
@@ -279,6 +279,7 @@
     if (!flags::enable_set_inode_quotas()) {
         return;
     }
+    #if APPLY_HARD_QUOTAS
     android::os::CreateAppDataResult result;
     android::os::CreateAppDataArgs args;
     args.uuid = std::nullopt;
@@ -293,6 +294,7 @@
     ASSERT_BINDER_SUCCESS(service->createAppData(args, &result));
 
     EXPECT_LT(0, GetInodesQuotaHardLimitsForUid("", kTestAppId));
+    #endif
 }
 
 TEST_F(ServiceTest, FixupAppData_Upgrade) {
diff --git a/cmds/installd/utils.h b/cmds/installd/utils.h
index 28ca84f..227fa7f 100644
--- a/cmds/installd/utils.h
+++ b/cmds/installd/utils.h
@@ -39,7 +39,7 @@
 #define BYPASS_QUOTA 0
 #define BYPASS_SDCARDFS 0
 
-#define APPLY_HARD_QUOTAS 1
+#define APPLY_HARD_QUOTAS 0
 
 namespace android {
 namespace installd {