Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a11d9101 authored by Zim's avatar Zim
Browse files

Support Zygote mounting FUSE mount paths while forking

If the persist.sys.fuse flag is true, Zygote will mount
/mnt/user/<userid> on /storage. This will effectively provide
/storage/self/primary symlinked to /storage/emulated/<userid>
This will allow apps access FUSE instead of sdcardfs on /sdcard

If the persist.sys.fuse flag is false (the default). No behavior changes

Bug: 135341433
Test: m && device boots successfully && seems to work ok
Change-Id: If5ee53cc4c18e52481f670be001c581b7f520343
parent 1b902222
Loading
Loading
Loading
Loading
+18 −7
Original line number Diff line number Diff line
@@ -117,7 +117,9 @@ typedef const std::function<void(std::string)>& fail_fn_t;

static pid_t gSystemServerPid = 0;

static constexpr const char* kPropFuse = "persist.sys.fuse";
static constexpr const char* kZygoteClassName = "com/android/internal/os/Zygote";

static jclass gZygoteClass;
static jmethodID gCallPostForkSystemServerHooks;
static jmethodID gCallPostForkChildHooks;
@@ -704,16 +706,25 @@ static void MountEmulatedStorage(uid_t uid, jint mount_mode,
    return;
  }

  const std::string& storage_source = ExternalStorageViews[mount_mode];
  const userid_t user_id = multiuser_get_user_id(uid);
  const std::string user_source = StringPrintf("/mnt/user/%d", user_id);
  bool isFuse = GetBoolProperty(kPropFuse, false);

  CreateDir(user_source, 0751, AID_ROOT, AID_ROOT, fail_fn);

  if (isFuse) {
    // TODO(b/135341433): Bind mount the appropriate storage view for the app given its permissions
    // media and media_location permission access. This should prevent the kernel from incorrectly
    // sharing a cache across permission buckets
    BindMount(user_source, "/storage", fail_fn);
  } else {
    const std::string& storage_source = ExternalStorageViews[mount_mode];
    BindMount(storage_source, "/storage", fail_fn);

    // Mount user-specific symlink helper into place
  userid_t user_id = multiuser_get_user_id(uid);
  const std::string user_source = StringPrintf("/mnt/user/%d", user_id);
  CreateDir(user_source, 0751, AID_ROOT, AID_ROOT, fail_fn);
    BindMount(user_source, "/storage/self", fail_fn);
  }
}

static bool NeedsNoRandomizeWorkaround() {
#if !defined(__arm__)