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

Commit 61926875 authored by Yabin Cui's avatar Yabin Cui
Browse files

run-as: allow running cmds for apps profileable from shell.

So we can run simpleperf on released apps with profileableFromShell flag.

Bug: 118835348
Test: build and test manually on marlin.
Test: run CtsSimpleperfTestCases.

Change-Id: I58e208391f7ef1a9871e6e772947ce5c99ecb9b8
parent aa53461e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ struct pkg_info {
    char *seinfo;
    gid_list gids;
    void *private_data;
    bool profileable_from_shell;
};

/**
+17 −0
Original line number Diff line number Diff line
@@ -223,6 +223,23 @@ extern bool packagelist_parse(pfn_on_package callback, void *userdata)
            }
        }

        cur = strsep(&next, " \t\r\n");
        if (cur) {
            tmp = strtoul(cur, &endptr, 10);
            if (*endptr != '\0') {
                errmsg = "Could not convert field \"profileable_from_shell\" to integer value";
                goto err;
            }

            /* should be a valid boolean of 1 or 0 */
            if (!(tmp == 0 || tmp == 1)) {
                errmsg = "Field \"profileable_from_shell\" is not 0 or 1 boolean value";
                goto err;
            }

            pkg_info->profileable_from_shell = (bool)tmp;
        }

        rc = callback(pkg_info, userdata);
        if (rc == false) {
            /*
+5 −4
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@
//
//  - that the ro.boot.disable_runas property is not set
//  - that it is invoked from the 'shell' or 'root' user (abort otherwise)
//  - that '<package-name>' is the name of an installed and debuggable package
//  - that '<package-name>' is the name of an installed and debuggable/profileableFromShell package
//  - that the package's data directory is well-formed
//
//  If so, it will drop to the application's user id / group id, cd to the
@@ -57,6 +57,7 @@
//    during development.
//
//  - Run the 'gdbserver' binary executable to allow native debugging
//  - Run simpleperf to allow native profiling
//

static bool packagelist_parse_callback(pkg_info* this_package, void* userdata) {
@@ -196,9 +197,9 @@ int main(int argc, char* argv[]) {
    error(1, 0, "package not an application: %s", pkgname);
  }

  // Reject any non-debuggable package.
  if (!info.debuggable) {
    error(1, 0, "package not debuggable: %s", pkgname);
  // Reject packages that are neither debuggable nor profileable from shell.
  if (!info.debuggable && !info.profileable_from_shell) {
    error(1, 0, "package is neither debuggable nor profileable from shell: %s", pkgname);
  }

  // Check that the data directory path is valid.