2012-10-24 17:45:23 +00:00
|
|
|
/*
|
|
|
|
** Copyright 2008, The Android Open Source Project
|
|
|
|
**
|
2014-01-30 22:19:23 +00:00
|
|
|
** Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
** you may not use this file except in compliance with the License.
|
|
|
|
** You may obtain a copy of the License at
|
2012-10-24 17:45:23 +00:00
|
|
|
**
|
2014-01-30 22:19:23 +00:00
|
|
|
** http://www.apache.org/licenses/LICENSE-2.0
|
2012-10-24 17:45:23 +00:00
|
|
|
**
|
2014-01-30 22:19:23 +00:00
|
|
|
** Unless required by applicable law or agreed to in writing, software
|
|
|
|
** distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
** See the License for the specific language governing permissions and
|
2012-10-24 17:45:23 +00:00
|
|
|
** limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2015-04-09 18:34:03 +00:00
|
|
|
#include "installd.h"
|
|
|
|
|
2015-04-09 03:56:42 +00:00
|
|
|
#include <base/stringprintf.h>
|
|
|
|
#include <base/logging.h>
|
2014-08-08 07:52:22 +00:00
|
|
|
#include <cutils/sched_policy.h>
|
2012-10-24 17:45:23 +00:00
|
|
|
#include <diskusage/dirsize.h>
|
2015-04-09 03:56:42 +00:00
|
|
|
#include <logwrap/logwrap.h>
|
2014-11-05 23:21:12 +00:00
|
|
|
#include <system/thread_defs.h>
|
2015-04-09 03:56:42 +00:00
|
|
|
#include <selinux/android.h>
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <sys/capability.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <unistd.h>
|
2015-04-09 18:34:03 +00:00
|
|
|
|
|
|
|
using android::base::StringPrintf;
|
2012-10-24 17:45:23 +00:00
|
|
|
|
|
|
|
/* Directory records that are used in execution of commands. */
|
|
|
|
dir_rec_t android_data_dir;
|
|
|
|
dir_rec_t android_asec_dir;
|
|
|
|
dir_rec_t android_app_dir;
|
|
|
|
dir_rec_t android_app_private_dir;
|
|
|
|
dir_rec_t android_app_lib_dir;
|
|
|
|
dir_rec_t android_media_dir;
|
2015-04-06 23:19:39 +00:00
|
|
|
dir_rec_t android_mnt_expand_dir;
|
2015-11-08 01:52:50 +00:00
|
|
|
dir_rec_t android_prebundled_dir;
|
2012-10-24 17:45:23 +00:00
|
|
|
dir_rec_array_t android_system_dirs;
|
|
|
|
|
2015-04-09 03:56:42 +00:00
|
|
|
static const char* kCpPath = "/system/bin/cp";
|
|
|
|
|
2015-04-08 01:14:05 +00:00
|
|
|
int install(const char *uuid, const char *pkgname, uid_t uid, gid_t gid, const char *seinfo)
|
2012-10-24 17:45:23 +00:00
|
|
|
{
|
|
|
|
if ((uid < AID_SYSTEM) || (gid < AID_SYSTEM)) {
|
|
|
|
ALOGE("invalid uid/gid: %d %d\n", uid, gid);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-04-30 22:58:19 +00:00
|
|
|
std::string _pkgdir(create_data_user_package_path(uuid, 0, pkgname));
|
2015-04-08 01:14:05 +00:00
|
|
|
const char* pkgdir = _pkgdir.c_str();
|
2012-10-24 17:45:23 +00:00
|
|
|
|
2013-01-10 00:00:35 +00:00
|
|
|
if (mkdir(pkgdir, 0751) < 0) {
|
2012-10-24 17:45:23 +00:00
|
|
|
ALOGE("cannot create dir '%s': %s\n", pkgdir, strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
2013-01-10 00:00:35 +00:00
|
|
|
if (chmod(pkgdir, 0751) < 0) {
|
2012-10-24 17:45:23 +00:00
|
|
|
ALOGE("cannot chmod dir '%s': %s\n", pkgdir, strerror(errno));
|
|
|
|
unlink(pkgdir);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-02-07 14:16:46 +00:00
|
|
|
if (selinux_android_setfilecon(pkgdir, pkgname, seinfo, uid) < 0) {
|
2012-10-24 17:45:23 +00:00
|
|
|
ALOGE("cannot setfilecon dir '%s': %s\n", pkgdir, strerror(errno));
|
|
|
|
unlink(pkgdir);
|
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (chown(pkgdir, uid, gid) < 0) {
|
|
|
|
ALOGE("cannot chown dir '%s': %s\n", pkgdir, strerror(errno));
|
|
|
|
unlink(pkgdir);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-08 01:14:05 +00:00
|
|
|
int uninstall(const char *uuid, const char *pkgname, userid_t userid)
|
2012-10-24 17:45:23 +00:00
|
|
|
{
|
2015-04-30 22:58:19 +00:00
|
|
|
std::string _pkgdir(create_data_user_package_path(uuid, userid, pkgname));
|
2015-04-08 01:14:05 +00:00
|
|
|
const char* pkgdir = _pkgdir.c_str();
|
2012-10-24 17:45:23 +00:00
|
|
|
|
2014-01-30 22:19:23 +00:00
|
|
|
remove_profile_file(pkgname);
|
|
|
|
|
2012-10-24 17:45:23 +00:00
|
|
|
/* delete contents AND directory, no exceptions */
|
|
|
|
return delete_dir_contents(pkgdir, 1, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
int renamepkg(const char *oldpkgname, const char *newpkgname)
|
|
|
|
{
|
|
|
|
char oldpkgdir[PKG_PATH_MAX];
|
|
|
|
char newpkgdir[PKG_PATH_MAX];
|
|
|
|
|
|
|
|
if (create_pkg_path(oldpkgdir, oldpkgname, PKG_DIR_POSTFIX, 0))
|
|
|
|
return -1;
|
|
|
|
if (create_pkg_path(newpkgdir, newpkgname, PKG_DIR_POSTFIX, 0))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (rename(oldpkgdir, newpkgdir) < 0) {
|
|
|
|
ALOGE("cannot rename dir '%s' to '%s': %s\n", oldpkgdir, newpkgdir, strerror(errno));
|
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-08 01:14:05 +00:00
|
|
|
int fix_uid(const char *uuid, const char *pkgname, uid_t uid, gid_t gid)
|
2012-10-24 17:45:23 +00:00
|
|
|
{
|
|
|
|
struct stat s;
|
|
|
|
|
|
|
|
if ((uid < AID_SYSTEM) || (gid < AID_SYSTEM)) {
|
|
|
|
ALOGE("invalid uid/gid: %d %d\n", uid, gid);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-04-30 22:58:19 +00:00
|
|
|
std::string _pkgdir(create_data_user_package_path(uuid, 0, pkgname));
|
2015-04-08 01:14:05 +00:00
|
|
|
const char* pkgdir = _pkgdir.c_str();
|
2012-10-24 17:45:23 +00:00
|
|
|
|
|
|
|
if (stat(pkgdir, &s) < 0) return -1;
|
|
|
|
|
|
|
|
if (s.st_uid != 0 || s.st_gid != 0) {
|
2014-03-12 20:12:44 +00:00
|
|
|
ALOGE("fixing uid of non-root pkg: %s %" PRIu32 " %" PRIu32 "\n", pkgdir, s.st_uid, s.st_gid);
|
2012-10-24 17:45:23 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (chmod(pkgdir, 0751) < 0) {
|
|
|
|
ALOGE("cannot chmod dir '%s': %s\n", pkgdir, strerror(errno));
|
|
|
|
unlink(pkgdir);
|
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
if (chown(pkgdir, uid, gid) < 0) {
|
|
|
|
ALOGE("cannot chown dir '%s': %s\n", pkgdir, strerror(errno));
|
|
|
|
unlink(pkgdir);
|
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-08 01:14:05 +00:00
|
|
|
int delete_user_data(const char *uuid, const char *pkgname, userid_t userid)
|
2012-10-24 17:45:23 +00:00
|
|
|
{
|
2015-04-30 22:58:19 +00:00
|
|
|
std::string _pkgdir(create_data_user_package_path(uuid, userid, pkgname));
|
2015-04-08 01:14:05 +00:00
|
|
|
const char* pkgdir = _pkgdir.c_str();
|
2012-10-24 17:45:23 +00:00
|
|
|
|
2014-08-27 17:46:25 +00:00
|
|
|
return delete_dir_contents(pkgdir, 0, NULL);
|
2012-10-24 17:45:23 +00:00
|
|
|
}
|
|
|
|
|
2015-04-08 01:14:05 +00:00
|
|
|
int make_user_data(const char *uuid, const char *pkgname, uid_t uid, userid_t userid, const char* seinfo)
|
2012-10-24 17:45:23 +00:00
|
|
|
{
|
2015-04-30 22:58:19 +00:00
|
|
|
std::string _pkgdir(create_data_user_package_path(uuid, userid, pkgname));
|
2015-04-08 01:14:05 +00:00
|
|
|
const char* pkgdir = _pkgdir.c_str();
|
2012-10-24 17:45:23 +00:00
|
|
|
|
2013-01-10 00:00:35 +00:00
|
|
|
if (mkdir(pkgdir, 0751) < 0) {
|
2012-10-24 17:45:23 +00:00
|
|
|
ALOGE("cannot create dir '%s': %s\n", pkgdir, strerror(errno));
|
|
|
|
return -errno;
|
|
|
|
}
|
2013-01-10 00:00:35 +00:00
|
|
|
if (chmod(pkgdir, 0751) < 0) {
|
2012-10-24 17:45:23 +00:00
|
|
|
ALOGE("cannot chmod dir '%s': %s\n", pkgdir, strerror(errno));
|
|
|
|
unlink(pkgdir);
|
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
|
2014-02-07 14:16:46 +00:00
|
|
|
if (selinux_android_setfilecon(pkgdir, pkgname, seinfo, uid) < 0) {
|
2012-10-24 17:45:23 +00:00
|
|
|
ALOGE("cannot setfilecon dir '%s': %s\n", pkgdir, strerror(errno));
|
|
|
|
unlink(pkgdir);
|
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (chown(pkgdir, uid, uid) < 0) {
|
|
|
|
ALOGE("cannot chown dir '%s': %s\n", pkgdir, strerror(errno));
|
|
|
|
unlink(pkgdir);
|
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-07-07 20:31:37 +00:00
|
|
|
int copy_complete_app(const char *from_uuid, const char *to_uuid,
|
2015-04-30 22:58:19 +00:00
|
|
|
const char *package_name, const char *data_app_name, appid_t appid,
|
|
|
|
const char* seinfo) {
|
2015-04-09 03:56:42 +00:00
|
|
|
std::vector<userid_t> users = get_known_users(from_uuid);
|
|
|
|
|
2015-04-30 22:58:19 +00:00
|
|
|
// Copy app
|
|
|
|
{
|
|
|
|
std::string from(create_data_app_package_path(from_uuid, data_app_name));
|
|
|
|
std::string to(create_data_app_package_path(to_uuid, data_app_name));
|
|
|
|
std::string to_parent(create_data_app_path(to_uuid));
|
|
|
|
|
|
|
|
char *argv[] = {
|
|
|
|
(char*) kCpPath,
|
|
|
|
(char*) "-F", /* delete any existing destination file first (--remove-destination) */
|
|
|
|
(char*) "-p", /* preserve timestamps, ownership, and permissions */
|
|
|
|
(char*) "-R", /* recurse into subdirectories (DEST must be a directory) */
|
|
|
|
(char*) "-P", /* Do not follow symlinks [default] */
|
|
|
|
(char*) "-d", /* don't dereference symlinks */
|
|
|
|
(char*) from.c_str(),
|
|
|
|
(char*) to_parent.c_str()
|
|
|
|
};
|
|
|
|
|
|
|
|
LOG(DEBUG) << "Copying " << from << " to " << to;
|
|
|
|
int rc = android_fork_execvp(ARRAY_SIZE(argv), argv, NULL, false, true);
|
|
|
|
|
|
|
|
if (rc != 0) {
|
|
|
|
LOG(ERROR) << "Failed copying " << from << " to " << to
|
|
|
|
<< ": status " << rc;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selinux_android_restorecon(to.c_str(), SELINUX_ANDROID_RESTORECON_RECURSE) != 0) {
|
|
|
|
LOG(ERROR) << "Failed to restorecon " << to;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy private data for all known users
|
2015-04-09 03:56:42 +00:00
|
|
|
for (auto user : users) {
|
2015-04-30 22:58:19 +00:00
|
|
|
std::string from(create_data_user_package_path(from_uuid, user, package_name));
|
|
|
|
std::string to(create_data_user_package_path(to_uuid, user, package_name));
|
|
|
|
std::string to_parent(create_data_user_path(to_uuid, user));
|
2015-04-09 03:56:42 +00:00
|
|
|
|
|
|
|
// Data source may not exist for all users; that's okay
|
|
|
|
if (access(from.c_str(), F_OK) != 0) {
|
|
|
|
LOG(INFO) << "Missing source " << from;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string user_path(create_data_user_path(to_uuid, user));
|
|
|
|
if (fs_prepare_dir(user_path.c_str(), 0771, AID_SYSTEM, AID_SYSTEM) != 0) {
|
|
|
|
LOG(ERROR) << "Failed to prepare user target " << user_path;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
uid_t uid = multiuser_get_uid(user, appid);
|
|
|
|
if (make_user_data(to_uuid, package_name, uid, user, seinfo) != 0) {
|
|
|
|
LOG(ERROR) << "Failed to create package target " << to;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *argv[] = {
|
|
|
|
(char*) kCpPath,
|
|
|
|
(char*) "-F", /* delete any existing destination file first (--remove-destination) */
|
|
|
|
(char*) "-p", /* preserve timestamps, ownership, and permissions */
|
|
|
|
(char*) "-R", /* recurse into subdirectories (DEST must be a directory) */
|
|
|
|
(char*) "-P", /* Do not follow symlinks [default] */
|
|
|
|
(char*) "-d", /* don't dereference symlinks */
|
|
|
|
(char*) from.c_str(),
|
2015-04-30 22:58:19 +00:00
|
|
|
(char*) to_parent.c_str()
|
2015-04-09 03:56:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
LOG(DEBUG) << "Copying " << from << " to " << to;
|
|
|
|
int rc = android_fork_execvp(ARRAY_SIZE(argv), argv, NULL, false, true);
|
|
|
|
|
|
|
|
if (rc != 0) {
|
|
|
|
LOG(ERROR) << "Failed copying " << from << " to " << to
|
|
|
|
<< ": status " << rc;
|
|
|
|
goto fail;
|
|
|
|
}
|
2015-07-20 23:26:19 +00:00
|
|
|
}
|
2015-04-09 03:56:42 +00:00
|
|
|
|
2015-07-20 23:26:19 +00:00
|
|
|
if (restorecon_data(to_uuid, package_name, seinfo, multiuser_get_uid(0, appid)) != 0) {
|
|
|
|
LOG(ERROR) << "Failed to restorecon";
|
|
|
|
goto fail;
|
2015-04-09 03:56:42 +00:00
|
|
|
}
|
|
|
|
|
2015-07-07 20:31:37 +00:00
|
|
|
// We let the framework scan the new location and persist that before
|
|
|
|
// deleting the data in the old location; this ordering ensures that
|
|
|
|
// we can recover from things like battery pulls.
|
2015-04-09 03:56:42 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
// Nuke everything we might have already copied
|
2015-04-30 22:58:19 +00:00
|
|
|
{
|
|
|
|
std::string to(create_data_app_package_path(to_uuid, data_app_name));
|
|
|
|
if (delete_dir_contents(to.c_str(), 1, NULL) != 0) {
|
|
|
|
LOG(WARNING) << "Failed to rollback " << to;
|
|
|
|
}
|
|
|
|
}
|
2015-04-09 03:56:42 +00:00
|
|
|
for (auto user : users) {
|
2015-04-30 22:58:19 +00:00
|
|
|
std::string to(create_data_user_package_path(to_uuid, user, package_name));
|
2015-04-09 03:56:42 +00:00
|
|
|
if (delete_dir_contents(to.c_str(), 1, NULL) != 0) {
|
|
|
|
LOG(WARNING) << "Failed to rollback " << to;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-06-10 17:46:26 +00:00
|
|
|
int make_user_config(userid_t userid)
|
2012-10-24 17:45:23 +00:00
|
|
|
{
|
2014-04-25 14:05:19 +00:00
|
|
|
if (ensure_config_user_dirs(userid) == -1) {
|
2012-10-24 17:45:23 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2014-04-25 14:05:19 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-09 18:34:03 +00:00
|
|
|
int delete_user(const char *uuid, userid_t userid)
|
2014-04-25 14:05:19 +00:00
|
|
|
{
|
|
|
|
int status = 0;
|
|
|
|
|
2015-04-09 18:34:03 +00:00
|
|
|
std::string data_path(create_data_user_path(uuid, userid));
|
|
|
|
if (delete_dir_contents(data_path.c_str(), 1, NULL) != 0) {
|
2014-04-25 14:05:19 +00:00
|
|
|
status = -1;
|
2012-10-24 17:45:23 +00:00
|
|
|
}
|
|
|
|
|
2015-04-09 18:34:03 +00:00
|
|
|
std::string media_path(create_data_media_path(uuid, userid));
|
|
|
|
if (delete_dir_contents(media_path.c_str(), 1, NULL) != 0) {
|
2014-04-25 14:05:19 +00:00
|
|
|
status = -1;
|
2012-10-24 17:45:23 +00:00
|
|
|
}
|
2014-04-25 14:05:19 +00:00
|
|
|
|
2015-04-09 18:34:03 +00:00
|
|
|
// Config paths only exist on internal storage
|
|
|
|
if (uuid == nullptr) {
|
|
|
|
char config_path[PATH_MAX];
|
|
|
|
if ((create_user_config_path(config_path, userid) != 0)
|
|
|
|
|| (delete_dir_contents(config_path, 1, NULL) != 0)) {
|
|
|
|
status = -1;
|
|
|
|
}
|
2012-10-24 17:45:23 +00:00
|
|
|
}
|
|
|
|
|
2014-04-25 14:05:19 +00:00
|
|
|
return status;
|
2012-10-24 17:45:23 +00:00
|
|
|
}
|
|
|
|
|
2015-04-08 01:14:05 +00:00
|
|
|
int delete_cache(const char *uuid, const char *pkgname, userid_t userid)
|
2012-10-24 17:45:23 +00:00
|
|
|
{
|
2015-04-08 01:14:05 +00:00
|
|
|
std::string _cachedir(
|
2015-04-30 22:58:19 +00:00
|
|
|
create_data_user_package_path(uuid, userid, pkgname) + CACHE_DIR_POSTFIX);
|
2015-04-08 01:14:05 +00:00
|
|
|
const char* cachedir = _cachedir.c_str();
|
2012-10-24 17:45:23 +00:00
|
|
|
|
2014-07-16 04:49:51 +00:00
|
|
|
/* delete contents, not the directory, no exceptions */
|
2014-06-10 12:16:47 +00:00
|
|
|
return delete_dir_contents(cachedir, 0, NULL);
|
2012-10-24 17:45:23 +00:00
|
|
|
}
|
|
|
|
|
2015-04-08 01:14:05 +00:00
|
|
|
int delete_code_cache(const char *uuid, const char *pkgname, userid_t userid)
|
2014-07-16 04:49:51 +00:00
|
|
|
{
|
2015-04-08 01:14:05 +00:00
|
|
|
std::string _codecachedir(
|
2015-06-24 06:57:06 +00:00
|
|
|
create_data_user_package_path(uuid, userid, pkgname) + CODE_CACHE_DIR_POSTFIX);
|
2015-04-08 01:14:05 +00:00
|
|
|
const char* codecachedir = _codecachedir.c_str();
|
2014-07-16 04:49:51 +00:00
|
|
|
|
2015-04-08 01:14:05 +00:00
|
|
|
struct stat s;
|
2014-07-16 04:49:51 +00:00
|
|
|
|
2014-09-09 00:14:26 +00:00
|
|
|
/* it's okay if code cache is missing */
|
|
|
|
if (lstat(codecachedir, &s) == -1 && errno == ENOENT) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-07-16 04:49:51 +00:00
|
|
|
/* delete contents, not the directory, no exceptions */
|
|
|
|
return delete_dir_contents(codecachedir, 0, NULL);
|
|
|
|
}
|
|
|
|
|
2012-10-24 17:45:23 +00:00
|
|
|
/* Try to ensure free_size bytes of storage are available.
|
|
|
|
* Returns 0 on success.
|
|
|
|
* This is rather simple-minded because doing a full LRU would
|
|
|
|
* be potentially memory-intensive, and without atime it would
|
|
|
|
* also require that apps constantly modify file metadata even
|
|
|
|
* when just reading from the cache, which is pretty awful.
|
|
|
|
*/
|
2015-04-09 18:34:03 +00:00
|
|
|
int free_cache(const char *uuid, int64_t free_size)
|
2012-10-24 17:45:23 +00:00
|
|
|
{
|
|
|
|
cache_t* cache;
|
|
|
|
int64_t avail;
|
|
|
|
DIR *d;
|
|
|
|
struct dirent *de;
|
|
|
|
char tmpdir[PATH_MAX];
|
|
|
|
char *dirpos;
|
|
|
|
|
2015-04-09 18:34:03 +00:00
|
|
|
std::string data_path(create_data_path(uuid));
|
|
|
|
|
|
|
|
avail = data_disk_free(data_path);
|
2012-10-24 17:45:23 +00:00
|
|
|
if (avail < 0) return -1;
|
|
|
|
|
|
|
|
ALOGI("free_cache(%" PRId64 ") avail %" PRId64 "\n", free_size, avail);
|
|
|
|
if (avail >= free_size) return 0;
|
|
|
|
|
|
|
|
cache = start_cache_collection();
|
|
|
|
|
2015-04-09 18:34:03 +00:00
|
|
|
// Special case for owner on internal storage
|
|
|
|
if (uuid == nullptr) {
|
|
|
|
std::string _tmpdir(create_data_user_path(nullptr, 0));
|
|
|
|
add_cache_files(cache, _tmpdir.c_str(), "cache");
|
2012-10-24 17:45:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Search for other users and add any cache files from them.
|
2015-04-09 18:34:03 +00:00
|
|
|
std::string _tmpdir(create_data_path(uuid) + "/" + SECONDARY_USER_PREFIX);
|
|
|
|
strcpy(tmpdir, _tmpdir.c_str());
|
|
|
|
|
2012-10-24 17:45:23 +00:00
|
|
|
dirpos = tmpdir + strlen(tmpdir);
|
|
|
|
d = opendir(tmpdir);
|
|
|
|
if (d != NULL) {
|
|
|
|
while ((de = readdir(d))) {
|
|
|
|
if (de->d_type == DT_DIR) {
|
|
|
|
const char *name = de->d_name;
|
|
|
|
/* always skip "." and ".." */
|
|
|
|
if (name[0] == '.') {
|
|
|
|
if (name[1] == 0) continue;
|
|
|
|
if ((name[1] == '.') && (name[2] == 0)) continue;
|
|
|
|
}
|
|
|
|
if ((strlen(name)+(dirpos-tmpdir)) < (sizeof(tmpdir)-1)) {
|
|
|
|
strcpy(dirpos, name);
|
|
|
|
//ALOGI("adding cache files from %s\n", tmpdir);
|
|
|
|
add_cache_files(cache, tmpdir, "cache");
|
|
|
|
} else {
|
|
|
|
ALOGW("Path exceeds limit: %s%s", tmpdir, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir(d);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Collect cache files on external storage for all users (if it is mounted as part
|
|
|
|
// of the internal storage).
|
|
|
|
strcpy(tmpdir, android_media_dir.path);
|
|
|
|
dirpos = tmpdir + strlen(tmpdir);
|
|
|
|
d = opendir(tmpdir);
|
|
|
|
if (d != NULL) {
|
|
|
|
while ((de = readdir(d))) {
|
|
|
|
if (de->d_type == DT_DIR) {
|
|
|
|
const char *name = de->d_name;
|
|
|
|
/* skip any dir that doesn't start with a number, so not a user */
|
|
|
|
if (name[0] < '0' || name[0] > '9') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ((strlen(name)+(dirpos-tmpdir)) < (sizeof(tmpdir)-1)) {
|
|
|
|
strcpy(dirpos, name);
|
|
|
|
if (lookup_media_dir(tmpdir, "Android") == 0
|
|
|
|
&& lookup_media_dir(tmpdir, "data") == 0) {
|
|
|
|
//ALOGI("adding cache files from %s\n", tmpdir);
|
|
|
|
add_cache_files(cache, tmpdir, "cache");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ALOGW("Path exceeds limit: %s%s", tmpdir, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir(d);
|
|
|
|
}
|
|
|
|
|
2015-04-09 18:34:03 +00:00
|
|
|
clear_cache_files(data_path, cache, free_size);
|
2012-10-24 17:45:23 +00:00
|
|
|
finish_cache_collection(cache);
|
|
|
|
|
2015-04-09 18:34:03 +00:00
|
|
|
return data_disk_free(data_path) >= free_size ? 0 : -1;
|
2012-10-24 17:45:23 +00:00
|
|
|
}
|
|
|
|
|
2014-04-11 12:17:00 +00:00
|
|
|
int move_dex(const char *src, const char *dst, const char *instruction_set)
|
2012-10-24 17:45:23 +00:00
|
|
|
{
|
|
|
|
char src_dex[PKG_PATH_MAX];
|
|
|
|
char dst_dex[PKG_PATH_MAX];
|
|
|
|
|
2014-09-09 00:14:26 +00:00
|
|
|
if (validate_apk_path(src)) {
|
|
|
|
ALOGE("invalid apk path '%s' (bad prefix)\n", src);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (validate_apk_path(dst)) {
|
|
|
|
ALOGE("invalid apk path '%s' (bad prefix)\n", dst);
|
|
|
|
return -1;
|
|
|
|
}
|
2012-10-24 17:45:23 +00:00
|
|
|
|
2014-04-11 12:17:00 +00:00
|
|
|
if (create_cache_path(src_dex, src, instruction_set)) return -1;
|
|
|
|
if (create_cache_path(dst_dex, dst, instruction_set)) return -1;
|
2012-10-24 17:45:23 +00:00
|
|
|
|
|
|
|
ALOGV("move %s -> %s\n", src_dex, dst_dex);
|
|
|
|
if (rename(src_dex, dst_dex) < 0) {
|
|
|
|
ALOGE("Couldn't move %s: %s\n", src_dex, strerror(errno));
|
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-11 12:17:00 +00:00
|
|
|
int rm_dex(const char *path, const char *instruction_set)
|
2012-10-24 17:45:23 +00:00
|
|
|
{
|
|
|
|
char dex_path[PKG_PATH_MAX];
|
|
|
|
|
2014-09-09 00:14:26 +00:00
|
|
|
if (validate_apk_path(path) && validate_system_app_path(path)) {
|
|
|
|
ALOGE("invalid apk path '%s' (bad prefix)\n", path);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-04-11 12:17:00 +00:00
|
|
|
if (create_cache_path(dex_path, path, instruction_set)) return -1;
|
2012-10-24 17:45:23 +00:00
|
|
|
|
|
|
|
ALOGV("unlink %s\n", dex_path);
|
|
|
|
if (unlink(dex_path) < 0) {
|
2014-09-09 00:14:26 +00:00
|
|
|
if (errno != ENOENT) {
|
|
|
|
ALOGE("Couldn't unlink %s: %s\n", dex_path, strerror(errno));
|
|
|
|
}
|
2012-10-24 17:45:23 +00:00
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-30 22:58:19 +00:00
|
|
|
int get_size(const char *uuid, const char *pkgname, int userid, const char *apkpath,
|
2013-05-02 01:55:10 +00:00
|
|
|
const char *libdirpath, const char *fwdlock_apkpath, const char *asecpath,
|
2014-04-11 12:17:00 +00:00
|
|
|
const char *instruction_set, int64_t *_codesize, int64_t *_datasize,
|
|
|
|
int64_t *_cachesize, int64_t* _asecsize)
|
2012-10-24 17:45:23 +00:00
|
|
|
{
|
|
|
|
DIR *d;
|
|
|
|
int dfd;
|
|
|
|
struct dirent *de;
|
|
|
|
struct stat s;
|
|
|
|
char path[PKG_PATH_MAX];
|
|
|
|
|
|
|
|
int64_t codesize = 0;
|
|
|
|
int64_t datasize = 0;
|
|
|
|
int64_t cachesize = 0;
|
|
|
|
int64_t asecsize = 0;
|
|
|
|
|
2015-04-30 22:58:19 +00:00
|
|
|
/* count the source apk as code -- but only if it's not
|
|
|
|
* on the /system partition and its not on the sdcard. */
|
2012-10-24 17:45:23 +00:00
|
|
|
if (validate_system_app_path(apkpath) &&
|
|
|
|
strncmp(apkpath, android_asec_dir.path, android_asec_dir.len) != 0) {
|
|
|
|
if (stat(apkpath, &s) == 0) {
|
|
|
|
codesize += stat_size(&s);
|
2015-04-30 22:58:19 +00:00
|
|
|
if (S_ISDIR(s.st_mode)) {
|
|
|
|
d = opendir(apkpath);
|
|
|
|
if (d != NULL) {
|
|
|
|
dfd = dirfd(d);
|
|
|
|
codesize += calculate_dir_size(dfd);
|
|
|
|
closedir(d);
|
|
|
|
}
|
|
|
|
}
|
2012-10-24 17:45:23 +00:00
|
|
|
}
|
|
|
|
}
|
2015-04-30 22:58:19 +00:00
|
|
|
|
|
|
|
/* count the forward locked apk as code if it is given */
|
2012-10-24 17:45:23 +00:00
|
|
|
if (fwdlock_apkpath != NULL && fwdlock_apkpath[0] != '!') {
|
|
|
|
if (stat(fwdlock_apkpath, &s) == 0) {
|
|
|
|
codesize += stat_size(&s);
|
|
|
|
}
|
|
|
|
}
|
2015-04-30 22:58:19 +00:00
|
|
|
|
|
|
|
/* count the cached dexfile as code */
|
2014-04-11 12:17:00 +00:00
|
|
|
if (!create_cache_path(path, apkpath, instruction_set)) {
|
2012-10-24 17:45:23 +00:00
|
|
|
if (stat(path, &s) == 0) {
|
|
|
|
codesize += stat_size(&s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-30 22:58:19 +00:00
|
|
|
/* add in size of any libraries */
|
2013-05-02 01:55:10 +00:00
|
|
|
if (libdirpath != NULL && libdirpath[0] != '!') {
|
|
|
|
d = opendir(libdirpath);
|
2012-10-24 17:45:23 +00:00
|
|
|
if (d != NULL) {
|
|
|
|
dfd = dirfd(d);
|
|
|
|
codesize += calculate_dir_size(dfd);
|
|
|
|
closedir(d);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-30 22:58:19 +00:00
|
|
|
/* compute asec size if it is given */
|
2012-10-24 17:45:23 +00:00
|
|
|
if (asecpath != NULL && asecpath[0] != '!') {
|
|
|
|
if (stat(asecpath, &s) == 0) {
|
|
|
|
asecsize += stat_size(&s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-30 22:58:19 +00:00
|
|
|
std::vector<userid_t> users;
|
|
|
|
if (userid == -1) {
|
|
|
|
users = get_known_users(uuid);
|
|
|
|
} else {
|
|
|
|
users.push_back(userid);
|
2012-10-24 17:45:23 +00:00
|
|
|
}
|
|
|
|
|
2015-04-30 22:58:19 +00:00
|
|
|
for (auto user : users) {
|
|
|
|
std::string _pkgdir(create_data_user_package_path(uuid, user, pkgname));
|
|
|
|
const char* pkgdir = _pkgdir.c_str();
|
2012-10-24 17:45:23 +00:00
|
|
|
|
2015-04-30 22:58:19 +00:00
|
|
|
d = opendir(pkgdir);
|
|
|
|
if (d == NULL) {
|
|
|
|
PLOG(WARNING) << "Failed to open " << pkgdir;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
dfd = dirfd(d);
|
|
|
|
|
|
|
|
/* most stuff in the pkgdir is data, except for the "cache"
|
|
|
|
* directory and below, which is cache, and the "lib" directory
|
|
|
|
* and below, which is code...
|
|
|
|
*/
|
|
|
|
while ((de = readdir(d))) {
|
|
|
|
const char *name = de->d_name;
|
|
|
|
|
|
|
|
if (de->d_type == DT_DIR) {
|
|
|
|
int subfd;
|
|
|
|
int64_t statsize = 0;
|
|
|
|
int64_t dirsize = 0;
|
|
|
|
/* always skip "." and ".." */
|
|
|
|
if (name[0] == '.') {
|
|
|
|
if (name[1] == 0) continue;
|
|
|
|
if ((name[1] == '.') && (name[2] == 0)) continue;
|
|
|
|
}
|
|
|
|
if (fstatat(dfd, name, &s, AT_SYMLINK_NOFOLLOW) == 0) {
|
|
|
|
statsize = stat_size(&s);
|
|
|
|
}
|
|
|
|
subfd = openat(dfd, name, O_RDONLY | O_DIRECTORY);
|
|
|
|
if (subfd >= 0) {
|
|
|
|
dirsize = calculate_dir_size(subfd);
|
|
|
|
}
|
|
|
|
if(!strcmp(name,"lib")) {
|
|
|
|
codesize += dirsize + statsize;
|
|
|
|
} else if(!strcmp(name,"cache")) {
|
|
|
|
cachesize += dirsize + statsize;
|
|
|
|
} else {
|
|
|
|
datasize += dirsize + statsize;
|
|
|
|
}
|
|
|
|
} else if (de->d_type == DT_LNK && !strcmp(name,"lib")) {
|
|
|
|
// This is the symbolic link to the application's library
|
|
|
|
// code. We'll count this as code instead of data, since
|
|
|
|
// it is not something that the app creates.
|
|
|
|
if (fstatat(dfd, name, &s, AT_SYMLINK_NOFOLLOW) == 0) {
|
|
|
|
codesize += stat_size(&s);
|
|
|
|
}
|
2012-10-24 17:45:23 +00:00
|
|
|
} else {
|
2015-04-30 22:58:19 +00:00
|
|
|
if (fstatat(dfd, name, &s, AT_SYMLINK_NOFOLLOW) == 0) {
|
|
|
|
datasize += stat_size(&s);
|
|
|
|
}
|
2012-10-24 17:45:23 +00:00
|
|
|
}
|
|
|
|
}
|
2015-04-30 22:58:19 +00:00
|
|
|
closedir(d);
|
2012-10-24 17:45:23 +00:00
|
|
|
}
|
|
|
|
*_codesize = codesize;
|
|
|
|
*_datasize = datasize;
|
|
|
|
*_cachesize = cachesize;
|
|
|
|
*_asecsize = asecsize;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-04-11 12:17:00 +00:00
|
|
|
int create_cache_path(char path[PKG_PATH_MAX], const char *src, const char *instruction_set)
|
2012-10-24 17:45:23 +00:00
|
|
|
{
|
|
|
|
char *tmp;
|
|
|
|
int srclen;
|
|
|
|
int dstlen;
|
|
|
|
|
|
|
|
srclen = strlen(src);
|
|
|
|
|
|
|
|
/* demand that we are an absolute path */
|
|
|
|
if ((src == 0) || (src[0] != '/') || strstr(src,"..")) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (srclen > PKG_PATH_MAX) { // XXX: PKG_NAME_MAX?
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-01-30 22:19:23 +00:00
|
|
|
dstlen = srclen + strlen(DALVIK_CACHE_PREFIX) +
|
2014-04-11 12:17:00 +00:00
|
|
|
strlen(instruction_set) +
|
|
|
|
strlen(DALVIK_CACHE_POSTFIX) + 2;
|
2014-01-30 22:19:23 +00:00
|
|
|
|
2012-10-24 17:45:23 +00:00
|
|
|
if (dstlen > PKG_PATH_MAX) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-04-11 12:17:00 +00:00
|
|
|
sprintf(path,"%s%s/%s%s",
|
2012-10-24 17:45:23 +00:00
|
|
|
DALVIK_CACHE_PREFIX,
|
2014-04-11 12:17:00 +00:00
|
|
|
instruction_set,
|
2012-10-24 17:45:23 +00:00
|
|
|
src + 1, /* skip the leading / */
|
|
|
|
DALVIK_CACHE_POSTFIX);
|
2014-01-30 22:19:23 +00:00
|
|
|
|
2014-04-11 12:17:00 +00:00
|
|
|
for(tmp = path + strlen(DALVIK_CACHE_PREFIX) + strlen(instruction_set) + 1; *tmp; tmp++) {
|
2012-10-24 17:45:23 +00:00
|
|
|
if (*tmp == '/') {
|
|
|
|
*tmp = '@';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-09-08 10:02:10 +00:00
|
|
|
static int split_count(const char *str)
|
|
|
|
{
|
|
|
|
char *ctx;
|
|
|
|
int count = 0;
|
|
|
|
char buf[PROPERTY_VALUE_MAX];
|
|
|
|
|
|
|
|
strncpy(buf, str, sizeof(buf));
|
|
|
|
char *pBuf = buf;
|
|
|
|
|
|
|
|
while(strtok_r(pBuf, " ", &ctx) != NULL) {
|
|
|
|
count++;
|
|
|
|
pBuf = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2015-01-07 09:46:13 +00:00
|
|
|
static int split(char *buf, const char **argv)
|
2014-09-08 10:02:10 +00:00
|
|
|
{
|
|
|
|
char *ctx;
|
|
|
|
int count = 0;
|
|
|
|
char *tok;
|
|
|
|
char *pBuf = buf;
|
|
|
|
|
|
|
|
while((tok = strtok_r(pBuf, " ", &ctx)) != NULL) {
|
|
|
|
argv[count++] = tok;
|
|
|
|
pBuf = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2014-07-21 19:23:48 +00:00
|
|
|
static void run_patchoat(int input_fd, int oat_fd, const char* input_file_name,
|
2014-09-11 21:44:46 +00:00
|
|
|
const char* output_file_name, const char *pkgname __unused, const char *instruction_set)
|
2014-07-21 19:23:48 +00:00
|
|
|
{
|
|
|
|
static const int MAX_INT_LEN = 12; // '-'+10dig+'\0' -OR- 0x+8dig
|
2014-08-19 17:48:50 +00:00
|
|
|
static const unsigned int MAX_INSTRUCTION_SET_LEN = 7;
|
2014-07-21 19:23:48 +00:00
|
|
|
|
|
|
|
static const char* PATCHOAT_BIN = "/system/bin/patchoat";
|
|
|
|
if (strlen(instruction_set) >= MAX_INSTRUCTION_SET_LEN) {
|
|
|
|
ALOGE("Instruction set %s longer than max length of %d",
|
|
|
|
instruction_set, MAX_INSTRUCTION_SET_LEN);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* input_file_name/input_fd should be the .odex/.oat file that is precompiled. I think*/
|
|
|
|
char instruction_set_arg[strlen("--instruction-set=") + MAX_INSTRUCTION_SET_LEN];
|
|
|
|
char output_oat_fd_arg[strlen("--output-oat-fd=") + MAX_INT_LEN];
|
|
|
|
char input_oat_fd_arg[strlen("--input-oat-fd=") + MAX_INT_LEN];
|
|
|
|
const char* patched_image_location_arg = "--patched-image-location=/system/framework/boot.art";
|
|
|
|
// The caller has already gotten all the locks we need.
|
|
|
|
const char* no_lock_arg = "--no-lock-output";
|
|
|
|
sprintf(instruction_set_arg, "--instruction-set=%s", instruction_set);
|
|
|
|
sprintf(output_oat_fd_arg, "--output-oat-fd=%d", oat_fd);
|
|
|
|
sprintf(input_oat_fd_arg, "--input-oat-fd=%d", input_fd);
|
2014-08-11 17:07:02 +00:00
|
|
|
ALOGV("Running %s isa=%s in-fd=%d (%s) out-fd=%d (%s)\n",
|
2014-07-21 19:23:48 +00:00
|
|
|
PATCHOAT_BIN, instruction_set, input_fd, input_file_name, oat_fd, output_file_name);
|
|
|
|
|
|
|
|
/* patchoat, patched-image-location, no-lock, isa, input-fd, output-fd */
|
|
|
|
char* argv[7];
|
|
|
|
argv[0] = (char*) PATCHOAT_BIN;
|
|
|
|
argv[1] = (char*) patched_image_location_arg;
|
|
|
|
argv[2] = (char*) no_lock_arg;
|
|
|
|
argv[3] = instruction_set_arg;
|
|
|
|
argv[4] = output_oat_fd_arg;
|
|
|
|
argv[5] = input_oat_fd_arg;
|
|
|
|
argv[6] = NULL;
|
|
|
|
|
|
|
|
execv(PATCHOAT_BIN, (char* const *)argv);
|
|
|
|
ALOGE("execv(%s) failed: %s\n", PATCHOAT_BIN, strerror(errno));
|
|
|
|
}
|
|
|
|
|
2015-04-24 21:30:04 +00:00
|
|
|
static bool check_boolean_property(const char* property_name, bool default_value = false) {
|
|
|
|
char tmp_property_value[PROPERTY_VALUE_MAX];
|
|
|
|
bool have_property = property_get(property_name, tmp_property_value, nullptr) > 0;
|
|
|
|
if (!have_property) {
|
|
|
|
return default_value;
|
|
|
|
}
|
|
|
|
return strcmp(tmp_property_value, "true") == 0;
|
|
|
|
}
|
|
|
|
|
2013-03-22 01:20:22 +00:00
|
|
|
static void run_dex2oat(int zip_fd, int oat_fd, const char* input_file_name,
|
2014-12-11 00:41:11 +00:00
|
|
|
const char* output_file_name, int swap_fd, const char *pkgname, const char *instruction_set,
|
2015-09-14 23:33:11 +00:00
|
|
|
bool vm_safe_mode, bool debuggable, bool post_bootcomplete)
|
2013-03-22 01:20:22 +00:00
|
|
|
{
|
2014-08-19 17:48:50 +00:00
|
|
|
static const unsigned int MAX_INSTRUCTION_SET_LEN = 7;
|
|
|
|
|
|
|
|
if (strlen(instruction_set) >= MAX_INSTRUCTION_SET_LEN) {
|
|
|
|
ALOGE("Instruction set %s longer than max length of %d",
|
|
|
|
instruction_set, MAX_INSTRUCTION_SET_LEN);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-27 23:03:06 +00:00
|
|
|
char prop_buf[PROPERTY_VALUE_MAX];
|
|
|
|
bool profiler = (property_get("dalvik.vm.profiler", prop_buf, "0") > 0) && (prop_buf[0] == '1');
|
|
|
|
|
|
|
|
char dex2oat_Xms_flag[PROPERTY_VALUE_MAX];
|
|
|
|
bool have_dex2oat_Xms_flag = property_get("dalvik.vm.dex2oat-Xms", dex2oat_Xms_flag, NULL) > 0;
|
|
|
|
|
|
|
|
char dex2oat_Xmx_flag[PROPERTY_VALUE_MAX];
|
|
|
|
bool have_dex2oat_Xmx_flag = property_get("dalvik.vm.dex2oat-Xmx", dex2oat_Xmx_flag, NULL) > 0;
|
|
|
|
|
2014-07-29 02:13:28 +00:00
|
|
|
char dex2oat_compiler_filter_flag[PROPERTY_VALUE_MAX];
|
|
|
|
bool have_dex2oat_compiler_filter_flag = property_get("dalvik.vm.dex2oat-filter",
|
|
|
|
dex2oat_compiler_filter_flag, NULL) > 0;
|
|
|
|
|
2015-03-31 01:45:03 +00:00
|
|
|
char dex2oat_threads_buf[PROPERTY_VALUE_MAX];
|
2015-09-14 23:33:11 +00:00
|
|
|
bool have_dex2oat_threads_flag = false;
|
|
|
|
if (!post_bootcomplete) {
|
|
|
|
have_dex2oat_threads_flag = property_get("dalvik.vm.boot-dex2oat-threads",
|
|
|
|
dex2oat_threads_buf,
|
|
|
|
NULL) > 0;
|
|
|
|
// If there's no boot property, fall back to the image property.
|
|
|
|
if (!have_dex2oat_threads_flag) {
|
|
|
|
have_dex2oat_threads_flag = property_get("dalvik.vm.image-dex2oat-threads",
|
|
|
|
dex2oat_threads_buf,
|
|
|
|
NULL) > 0;
|
|
|
|
}
|
|
|
|
// If there's neither, fall back to the default property.
|
|
|
|
}
|
|
|
|
if (!have_dex2oat_threads_flag) {
|
|
|
|
have_dex2oat_threads_flag = property_get("dalvik.vm.dex2oat-threads",
|
|
|
|
dex2oat_threads_buf,
|
|
|
|
NULL) > 0;
|
|
|
|
}
|
2015-03-31 01:45:03 +00:00
|
|
|
char dex2oat_threads_arg[PROPERTY_VALUE_MAX + 2];
|
|
|
|
if (have_dex2oat_threads_flag) {
|
|
|
|
sprintf(dex2oat_threads_arg, "-j%s", dex2oat_threads_buf);
|
|
|
|
}
|
|
|
|
|
2014-08-19 17:48:50 +00:00
|
|
|
char dex2oat_isa_features_key[PROPERTY_KEY_MAX];
|
|
|
|
sprintf(dex2oat_isa_features_key, "dalvik.vm.isa.%s.features", instruction_set);
|
|
|
|
char dex2oat_isa_features[PROPERTY_VALUE_MAX];
|
|
|
|
bool have_dex2oat_isa_features = property_get(dex2oat_isa_features_key,
|
|
|
|
dex2oat_isa_features, NULL) > 0;
|
|
|
|
|
2014-11-09 00:58:13 +00:00
|
|
|
char dex2oat_isa_variant_key[PROPERTY_KEY_MAX];
|
|
|
|
sprintf(dex2oat_isa_variant_key, "dalvik.vm.isa.%s.variant", instruction_set);
|
|
|
|
char dex2oat_isa_variant[PROPERTY_VALUE_MAX];
|
|
|
|
bool have_dex2oat_isa_variant = property_get(dex2oat_isa_variant_key,
|
|
|
|
dex2oat_isa_variant, NULL) > 0;
|
|
|
|
|
2015-01-07 09:46:13 +00:00
|
|
|
const char *dex2oat_norelocation = "-Xnorelocate";
|
|
|
|
bool have_dex2oat_relocation_skip_flag = false;
|
|
|
|
|
2014-02-11 00:42:52 +00:00
|
|
|
char dex2oat_flags[PROPERTY_VALUE_MAX];
|
2014-09-08 10:02:10 +00:00
|
|
|
int dex2oat_flags_count = property_get("dalvik.vm.dex2oat-flags",
|
|
|
|
dex2oat_flags, NULL) <= 0 ? 0 : split_count(dex2oat_flags);
|
2014-02-11 00:42:52 +00:00
|
|
|
ALOGV("dalvik.vm.dex2oat-flags=%s\n", dex2oat_flags);
|
|
|
|
|
2014-07-30 21:37:11 +00:00
|
|
|
// If we booting without the real /data, don't spend time compiling.
|
|
|
|
char vold_decrypt[PROPERTY_VALUE_MAX];
|
|
|
|
bool have_vold_decrypt = property_get("vold.decrypt", vold_decrypt, "") > 0;
|
|
|
|
bool skip_compilation = (have_vold_decrypt &&
|
|
|
|
(strcmp(vold_decrypt, "trigger_restart_min_framework") == 0 ||
|
|
|
|
(strcmp(vold_decrypt, "1") == 0)));
|
|
|
|
|
2015-04-24 21:30:04 +00:00
|
|
|
bool use_jit = check_boolean_property("debug.usejit");
|
2015-05-28 15:55:50 +00:00
|
|
|
bool generate_debug_info = check_boolean_property("debug.generate-debug-info");
|
2015-03-20 22:39:47 +00:00
|
|
|
|
2013-03-22 01:20:22 +00:00
|
|
|
static const char* DEX2OAT_BIN = "/system/bin/dex2oat";
|
2014-06-27 21:15:19 +00:00
|
|
|
|
|
|
|
static const char* RUNTIME_ARG = "--runtime-arg";
|
|
|
|
|
2013-03-22 01:20:22 +00:00
|
|
|
static const int MAX_INT_LEN = 12; // '-'+10dig+'\0' -OR- 0x+8dig
|
2014-04-11 12:17:00 +00:00
|
|
|
|
2013-03-22 01:20:22 +00:00
|
|
|
char zip_fd_arg[strlen("--zip-fd=") + MAX_INT_LEN];
|
|
|
|
char zip_location_arg[strlen("--zip-location=") + PKG_PATH_MAX];
|
|
|
|
char oat_fd_arg[strlen("--oat-fd=") + MAX_INT_LEN];
|
2014-06-16 20:28:03 +00:00
|
|
|
char oat_location_arg[strlen("--oat-location=") + PKG_PATH_MAX];
|
2014-04-11 12:17:00 +00:00
|
|
|
char instruction_set_arg[strlen("--instruction-set=") + MAX_INSTRUCTION_SET_LEN];
|
2014-11-09 00:58:13 +00:00
|
|
|
char instruction_set_variant_arg[strlen("--instruction-set-variant=") + PROPERTY_VALUE_MAX];
|
2014-08-19 17:48:50 +00:00
|
|
|
char instruction_set_features_arg[strlen("--instruction-set-features=") + PROPERTY_VALUE_MAX];
|
2014-06-06 15:58:43 +00:00
|
|
|
char profile_file_arg[strlen("--profile-file=") + PKG_PATH_MAX];
|
|
|
|
char top_k_profile_threshold_arg[strlen("--top-k-profile-threshold=") + PROPERTY_VALUE_MAX];
|
2014-06-27 23:03:06 +00:00
|
|
|
char dex2oat_Xms_arg[strlen("-Xms") + PROPERTY_VALUE_MAX];
|
|
|
|
char dex2oat_Xmx_arg[strlen("-Xmx") + PROPERTY_VALUE_MAX];
|
2014-07-29 02:13:28 +00:00
|
|
|
char dex2oat_compiler_filter_arg[strlen("--compiler-filter=") + PROPERTY_VALUE_MAX];
|
2014-12-11 00:41:11 +00:00
|
|
|
bool have_dex2oat_swap_fd = false;
|
|
|
|
char dex2oat_swap_fd[strlen("--swap-fd=") + MAX_INT_LEN];
|
2013-03-22 01:20:22 +00:00
|
|
|
|
|
|
|
sprintf(zip_fd_arg, "--zip-fd=%d", zip_fd);
|
|
|
|
sprintf(zip_location_arg, "--zip-location=%s", input_file_name);
|
|
|
|
sprintf(oat_fd_arg, "--oat-fd=%d", oat_fd);
|
|
|
|
sprintf(oat_location_arg, "--oat-location=%s", output_file_name);
|
2014-04-11 12:17:00 +00:00
|
|
|
sprintf(instruction_set_arg, "--instruction-set=%s", instruction_set);
|
2014-11-09 00:58:13 +00:00
|
|
|
sprintf(instruction_set_variant_arg, "--instruction-set-variant=%s", dex2oat_isa_variant);
|
2014-08-19 17:48:50 +00:00
|
|
|
sprintf(instruction_set_features_arg, "--instruction-set-features=%s", dex2oat_isa_features);
|
2014-12-11 00:41:11 +00:00
|
|
|
if (swap_fd >= 0) {
|
|
|
|
have_dex2oat_swap_fd = true;
|
|
|
|
sprintf(dex2oat_swap_fd, "--swap-fd=%d", swap_fd);
|
|
|
|
}
|
2014-06-06 13:42:16 +00:00
|
|
|
|
2014-06-06 15:58:43 +00:00
|
|
|
bool have_profile_file = false;
|
|
|
|
bool have_top_k_profile_threshold = false;
|
2014-06-06 13:42:16 +00:00
|
|
|
if (profiler && (strcmp(pkgname, "*") != 0)) {
|
|
|
|
char profile_file[PKG_PATH_MAX];
|
|
|
|
snprintf(profile_file, sizeof(profile_file), "%s/%s",
|
2014-01-30 22:19:23 +00:00
|
|
|
DALVIK_CACHE_PREFIX "profiles", pkgname);
|
2014-06-06 13:42:16 +00:00
|
|
|
struct stat st;
|
2014-06-06 15:58:43 +00:00
|
|
|
if ((stat(profile_file, &st) == 0) && (st.st_size > 0)) {
|
2014-06-06 13:42:16 +00:00
|
|
|
sprintf(profile_file_arg, "--profile-file=%s", profile_file);
|
2014-06-06 15:58:43 +00:00
|
|
|
have_profile_file = true;
|
|
|
|
if (property_get("dalvik.vm.profile.top-k-thr", prop_buf, NULL) > 0) {
|
|
|
|
snprintf(top_k_profile_threshold_arg, sizeof(top_k_profile_threshold_arg),
|
|
|
|
"--top-k-profile-threshold=%s", prop_buf);
|
|
|
|
have_top_k_profile_threshold = true;
|
|
|
|
}
|
2014-06-06 13:42:16 +00:00
|
|
|
}
|
2014-01-30 22:19:23 +00:00
|
|
|
}
|
2013-03-22 01:20:22 +00:00
|
|
|
|
2014-06-27 23:03:06 +00:00
|
|
|
if (have_dex2oat_Xms_flag) {
|
|
|
|
sprintf(dex2oat_Xms_arg, "-Xms%s", dex2oat_Xms_flag);
|
|
|
|
}
|
|
|
|
if (have_dex2oat_Xmx_flag) {
|
|
|
|
sprintf(dex2oat_Xmx_arg, "-Xmx%s", dex2oat_Xmx_flag);
|
|
|
|
}
|
2014-07-30 21:37:11 +00:00
|
|
|
if (skip_compilation) {
|
2014-08-15 16:55:50 +00:00
|
|
|
strcpy(dex2oat_compiler_filter_arg, "--compiler-filter=verify-none");
|
2014-07-30 21:37:11 +00:00
|
|
|
have_dex2oat_compiler_filter_flag = true;
|
2015-01-07 09:46:13 +00:00
|
|
|
have_dex2oat_relocation_skip_flag = true;
|
2014-08-21 18:05:20 +00:00
|
|
|
} else if (vm_safe_mode) {
|
|
|
|
strcpy(dex2oat_compiler_filter_arg, "--compiler-filter=interpret-only");
|
2014-08-27 15:10:03 +00:00
|
|
|
have_dex2oat_compiler_filter_flag = true;
|
2015-03-20 22:39:47 +00:00
|
|
|
} else if (use_jit) {
|
|
|
|
strcpy(dex2oat_compiler_filter_arg, "--compiler-filter=verify-at-runtime");
|
|
|
|
have_dex2oat_compiler_filter_flag = true;
|
2014-07-30 21:37:11 +00:00
|
|
|
} else if (have_dex2oat_compiler_filter_flag) {
|
2014-07-29 02:13:28 +00:00
|
|
|
sprintf(dex2oat_compiler_filter_arg, "--compiler-filter=%s", dex2oat_compiler_filter_flag);
|
|
|
|
}
|
2014-06-27 23:03:06 +00:00
|
|
|
|
2015-03-03 17:15:06 +00:00
|
|
|
// Check whether all apps should be compiled debuggable.
|
|
|
|
if (!debuggable) {
|
|
|
|
debuggable =
|
|
|
|
(property_get("dalvik.vm.always_debuggable", prop_buf, "0") > 0) &&
|
|
|
|
(prop_buf[0] == '1');
|
|
|
|
}
|
|
|
|
|
2013-03-22 01:20:22 +00:00
|
|
|
ALOGV("Running %s in=%s out=%s\n", DEX2OAT_BIN, input_file_name, output_file_name);
|
2014-06-06 15:58:43 +00:00
|
|
|
|
2015-01-07 09:46:13 +00:00
|
|
|
const char* argv[7 // program name, mandatory arguments and the final NULL
|
|
|
|
+ (have_dex2oat_isa_variant ? 1 : 0)
|
|
|
|
+ (have_dex2oat_isa_features ? 1 : 0)
|
|
|
|
+ (have_profile_file ? 1 : 0)
|
|
|
|
+ (have_top_k_profile_threshold ? 1 : 0)
|
|
|
|
+ (have_dex2oat_Xms_flag ? 2 : 0)
|
|
|
|
+ (have_dex2oat_Xmx_flag ? 2 : 0)
|
|
|
|
+ (have_dex2oat_compiler_filter_flag ? 1 : 0)
|
2015-03-31 01:45:03 +00:00
|
|
|
+ (have_dex2oat_threads_flag ? 1 : 0)
|
2015-01-07 09:46:13 +00:00
|
|
|
+ (have_dex2oat_swap_fd ? 1 : 0)
|
|
|
|
+ (have_dex2oat_relocation_skip_flag ? 2 : 0)
|
2015-05-28 15:55:50 +00:00
|
|
|
+ (generate_debug_info ? 1 : 0)
|
2015-03-03 17:15:06 +00:00
|
|
|
+ (debuggable ? 1 : 0)
|
2015-01-07 09:46:13 +00:00
|
|
|
+ dex2oat_flags_count];
|
2014-06-06 15:58:43 +00:00
|
|
|
int i = 0;
|
2015-01-07 09:46:13 +00:00
|
|
|
argv[i++] = DEX2OAT_BIN;
|
2014-06-06 15:58:43 +00:00
|
|
|
argv[i++] = zip_fd_arg;
|
|
|
|
argv[i++] = zip_location_arg;
|
|
|
|
argv[i++] = oat_fd_arg;
|
|
|
|
argv[i++] = oat_location_arg;
|
|
|
|
argv[i++] = instruction_set_arg;
|
2014-11-09 00:58:13 +00:00
|
|
|
if (have_dex2oat_isa_variant) {
|
|
|
|
argv[i++] = instruction_set_variant_arg;
|
|
|
|
}
|
2014-08-19 17:48:50 +00:00
|
|
|
if (have_dex2oat_isa_features) {
|
|
|
|
argv[i++] = instruction_set_features_arg;
|
|
|
|
}
|
2014-06-06 15:58:43 +00:00
|
|
|
if (have_profile_file) {
|
|
|
|
argv[i++] = profile_file_arg;
|
|
|
|
}
|
|
|
|
if (have_top_k_profile_threshold) {
|
|
|
|
argv[i++] = top_k_profile_threshold_arg;
|
|
|
|
}
|
2014-06-27 23:03:06 +00:00
|
|
|
if (have_dex2oat_Xms_flag) {
|
2015-01-07 09:46:13 +00:00
|
|
|
argv[i++] = RUNTIME_ARG;
|
2014-06-27 23:03:06 +00:00
|
|
|
argv[i++] = dex2oat_Xms_arg;
|
|
|
|
}
|
|
|
|
if (have_dex2oat_Xmx_flag) {
|
2015-01-07 09:46:13 +00:00
|
|
|
argv[i++] = RUNTIME_ARG;
|
2014-06-27 23:03:06 +00:00
|
|
|
argv[i++] = dex2oat_Xmx_arg;
|
|
|
|
}
|
2014-07-29 02:13:28 +00:00
|
|
|
if (have_dex2oat_compiler_filter_flag) {
|
|
|
|
argv[i++] = dex2oat_compiler_filter_arg;
|
|
|
|
}
|
2015-03-31 01:45:03 +00:00
|
|
|
if (have_dex2oat_threads_flag) {
|
|
|
|
argv[i++] = dex2oat_threads_arg;
|
|
|
|
}
|
2014-12-11 00:41:11 +00:00
|
|
|
if (have_dex2oat_swap_fd) {
|
|
|
|
argv[i++] = dex2oat_swap_fd;
|
|
|
|
}
|
2015-05-28 15:55:50 +00:00
|
|
|
if (generate_debug_info) {
|
|
|
|
argv[i++] = "--generate-debug-info";
|
2015-04-24 21:30:04 +00:00
|
|
|
}
|
2015-03-03 17:15:06 +00:00
|
|
|
if (debuggable) {
|
|
|
|
argv[i++] = "--debuggable";
|
|
|
|
}
|
2014-09-08 10:02:10 +00:00
|
|
|
if (dex2oat_flags_count) {
|
|
|
|
i += split(dex2oat_flags, argv + i);
|
2014-06-06 15:58:43 +00:00
|
|
|
}
|
2015-01-07 09:46:13 +00:00
|
|
|
if (have_dex2oat_relocation_skip_flag) {
|
|
|
|
argv[i++] = RUNTIME_ARG;
|
|
|
|
argv[i++] = dex2oat_norelocation;
|
|
|
|
}
|
2014-06-27 23:03:06 +00:00
|
|
|
// Do not add after dex2oat_flags, they should override others for debugging.
|
2014-06-06 15:58:43 +00:00
|
|
|
argv[i] = NULL;
|
|
|
|
|
2015-01-07 09:46:13 +00:00
|
|
|
execv(DEX2OAT_BIN, (char * const *)argv);
|
2014-09-08 10:02:10 +00:00
|
|
|
ALOGE("execv(%s) failed: %s\n", DEX2OAT_BIN, strerror(errno));
|
2013-03-22 01:20:22 +00:00
|
|
|
}
|
|
|
|
|
Runtime resource overlay, iteration 2
Support any number of overlay packages. Support any target package.
UPDATED PACKAGE MATCHING
------------------------
In Runtime resource overlay, iteration 1, only a single overlay package
was considered. Package matching was based on file paths:
/vendor/overlay/system/framework-res.apk corresponded to
/system/framework-res.apk. Introduce a more flexible matching scheme
where any package is an overlay package if its manifest includes
<overlay targetPackage="com.target.package"/>
For security reasons, an overlay package must fulfill certain criteria
to take effect: see below.
THE IDMAP TOOL AND IDMAP FILES
------------------------------
Idmap files are created by the 'idmap' binary; idmap files must be
present when loading packages. For the Android system, Zygote calls
'idmap' as part of the resource pre-loading. For application packages,
'idmap' is invoked via 'installd' during package installation (similar
to 'dexopt').
UPDATED FLOW
------------
The following is an outline of the start-up sequences for the Android
system and Android apps. Steps marked with '+' are introduced by this
commit.
Zygote initialization
Initial AssetManager object created
+ idmap --scan creates idmaps for overlays targeting 'android', \
stores list of overlays in /data/resource-cache/overlays.list
AssetManager caches framework-res.apk
+ AssetManager caches overlay packages listed in overlays.list
Android boot
New AssetManager's ResTable acquired
AssetManager re-uses cached framework-res.apk
+ AssetManager re-uses cached 'android' overlays (if any)
App boot
ActivityThread prepares AssetManager to load app.apk
+ ActivityThread prepares AssetManager to load app overlays (if any)
New AssetManager's ResTable acquired as per Android boot
SECURITY
--------
Overlay packages are required to be pre-loaded (in /vendor/overlay).
These packages are trusted by definition. A future iteration of runtime
resource overlay may add support for downloaded overlays, which would
likely require target and overlay signatures match for the overlay to
be trusted.
LOOKUP PRIORITY
---------------
During resource lookup, packages are sequentially queried to provide a
best match, given the constraints of the current configuration. If any
package provide a better match than what has been found so far, it
replaces the previous match. The target package is always queried last.
When loading a package with more than one overlay, the order in which
the overlays are added become significant if several packages overlay
the same resource.
Had downloaded overlays been supported, the install time could have been
used to determine the load order. Regardless, for pre-installed
overlays, the install time is randomly determined by the order in which
the Package Manager locates the packages during initial boot. To support
a well-defined order, pre-installed overlay packages are expected to
define an additional 'priority' attribute in their <overlay> tags:
<overlay targetPackage="com.target.package" priority="1234"/>
Pre-installed overlays are loaded in order of their priority attributes,
sorted in ascending order.
Assigning the same priority to several overlays targeting the same base
package leads to undefined behaviour. It is the responsibility of the
vendor to avoid this.
The following example shows the ResTable and PackageGroups after loading
an application and two overlays. The resource lookup framework will
query the packages in the order C, B, A.
+------+------+- -+------+------+
| 0x01 | | ... | | 0x7f |
+------+------+- -+------+------+
| |
"android" Target package A
|
Pre-installed overlay B (priority 1)
|
Pre-installed overlay C (priority 2)
Change-Id: If49c963149369b1957f7d2303b3dd27f669ed24e
2014-01-31 13:42:59 +00:00
|
|
|
static int wait_child(pid_t pid)
|
2012-10-24 17:45:23 +00:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
pid_t got_pid;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
got_pid = waitpid(pid, &status, 0);
|
|
|
|
if (got_pid == -1 && errno == EINTR) {
|
|
|
|
printf("waitpid interrupted, retrying\n");
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (got_pid != pid) {
|
|
|
|
ALOGW("waitpid failed: wanted %d, got %d: %s\n",
|
|
|
|
(int) pid, (int) got_pid, strerror(errno));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return status; /* always nonzero */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-11 00:41:11 +00:00
|
|
|
/*
|
2015-07-16 22:55:41 +00:00
|
|
|
* Whether dexopt should use a swap file when compiling an APK.
|
|
|
|
*
|
|
|
|
* If kAlwaysProvideSwapFile, do this on all devices (dex2oat will make a more informed decision
|
|
|
|
* itself, anyways).
|
|
|
|
*
|
|
|
|
* Otherwise, read "dalvik.vm.dex2oat-swap". If the property exists, return whether it is "true".
|
|
|
|
*
|
|
|
|
* Otherwise, return true if this is a low-mem device.
|
|
|
|
*
|
|
|
|
* Otherwise, return default value.
|
2014-12-11 00:41:11 +00:00
|
|
|
*/
|
2015-07-16 22:55:41 +00:00
|
|
|
static bool kAlwaysProvideSwapFile = false;
|
|
|
|
static bool kDefaultProvideSwapFile = true;
|
2014-12-11 00:41:11 +00:00
|
|
|
|
|
|
|
static bool ShouldUseSwapFileForDexopt() {
|
|
|
|
if (kAlwaysProvideSwapFile) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-16 22:55:41 +00:00
|
|
|
// Check the "override" property. If it exists, return value == "true".
|
|
|
|
char dex2oat_prop_buf[PROPERTY_VALUE_MAX];
|
|
|
|
if (property_get("dalvik.vm.dex2oat-swap", dex2oat_prop_buf, "") > 0) {
|
|
|
|
if (strcmp(dex2oat_prop_buf, "true") == 0) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Shortcut for default value. This is an implementation optimization for the process sketched
|
|
|
|
// above. If the default value is true, we can avoid to check whether this is a low-mem device,
|
|
|
|
// as low-mem is never returning false. The compiler will optimize this away if it can.
|
|
|
|
if (kDefaultProvideSwapFile) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool is_low_mem = check_boolean_property("ro.config.low_ram");
|
|
|
|
if (is_low_mem) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Default value must be false here.
|
|
|
|
return kDefaultProvideSwapFile;
|
2014-12-11 00:41:11 +00:00
|
|
|
}
|
|
|
|
|
2015-03-18 19:39:09 +00:00
|
|
|
/*
|
|
|
|
* Computes the odex file for the given apk_path and instruction_set.
|
|
|
|
* /system/framework/whatever.jar -> /system/framework/oat/<isa>/whatever.odex
|
|
|
|
*
|
|
|
|
* Returns false if it failed to determine the odex file path.
|
|
|
|
*/
|
|
|
|
static bool calculate_odex_file_path(char path[PKG_PATH_MAX],
|
|
|
|
const char *apk_path,
|
|
|
|
const char *instruction_set)
|
|
|
|
{
|
|
|
|
if (strlen(apk_path) + strlen("oat/") + strlen(instruction_set)
|
|
|
|
+ strlen("/") + strlen("odex") + 1 > PKG_PATH_MAX) {
|
|
|
|
ALOGE("apk_path '%s' may be too long to form odex file path.\n", apk_path);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
strcpy(path, apk_path);
|
|
|
|
char *end = strrchr(path, '/');
|
|
|
|
if (end == NULL) {
|
|
|
|
ALOGE("apk_path '%s' has no '/'s in it?!\n", apk_path);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const char *apk_end = apk_path + (end - path); // strrchr(apk_path, '/');
|
|
|
|
|
|
|
|
strcpy(end + 1, "oat/"); // path = /system/framework/oat/\0
|
|
|
|
strcat(path, instruction_set); // path = /system/framework/oat/<isa>\0
|
|
|
|
strcat(path, apk_end); // path = /system/framework/oat/<isa>/whatever.jar\0
|
|
|
|
end = strrchr(path, '.');
|
|
|
|
if (end == NULL) {
|
|
|
|
ALOGE("apk_path '%s' has no extension.\n", apk_path);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
strcpy(end + 1, "odex");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-14 23:33:11 +00:00
|
|
|
static void SetDex2OatAndPatchOatScheduling(bool set_to_bg) {
|
|
|
|
if (set_to_bg) {
|
|
|
|
if (set_sched_policy(0, SP_BACKGROUND) < 0) {
|
|
|
|
ALOGE("set_sched_policy failed: %s\n", strerror(errno));
|
|
|
|
exit(70);
|
|
|
|
}
|
|
|
|
if (setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_BACKGROUND) < 0) {
|
|
|
|
ALOGE("setpriority failed: %s\n", strerror(errno));
|
|
|
|
exit(71);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-21 18:05:20 +00:00
|
|
|
int dexopt(const char *apk_path, uid_t uid, bool is_public,
|
2015-03-26 22:47:38 +00:00
|
|
|
const char *pkgname, const char *instruction_set, int dexopt_needed,
|
2015-09-21 20:21:30 +00:00
|
|
|
bool vm_safe_mode, bool debuggable, const char* oat_dir, bool boot_complete)
|
2012-10-24 17:45:23 +00:00
|
|
|
{
|
|
|
|
struct utimbuf ut;
|
2015-04-02 23:59:10 +00:00
|
|
|
struct stat input_stat;
|
2013-03-22 01:20:22 +00:00
|
|
|
char out_path[PKG_PATH_MAX];
|
2014-12-11 00:41:11 +00:00
|
|
|
char swap_file_name[PKG_PATH_MAX];
|
2014-07-21 19:23:48 +00:00
|
|
|
const char *input_file;
|
|
|
|
char in_odex_path[PKG_PATH_MAX];
|
2014-12-11 00:41:11 +00:00
|
|
|
int res, input_fd=-1, out_fd=-1, swap_fd=-1;
|
2012-10-24 17:45:23 +00:00
|
|
|
|
2014-12-11 00:41:11 +00:00
|
|
|
// Early best-effort check whether we can fit the the path into our buffers.
|
|
|
|
// Note: the cache path will require an additional 5 bytes for ".swap", but we'll try to run
|
|
|
|
// without a swap file, if necessary.
|
2012-10-24 17:45:23 +00:00
|
|
|
if (strlen(apk_path) >= (PKG_PATH_MAX - 8)) {
|
2015-03-03 20:25:29 +00:00
|
|
|
ALOGE("apk_path too long '%s'\n", apk_path);
|
2012-10-24 17:45:23 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-03-03 20:25:29 +00:00
|
|
|
if (oat_dir != NULL && oat_dir[0] != '!') {
|
|
|
|
if (validate_apk_path(oat_dir)) {
|
|
|
|
ALOGE("invalid oat_dir '%s'\n", oat_dir);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (calculate_oat_file_path(out_path, oat_dir, apk_path, instruction_set)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (create_cache_path(out_path, apk_path, instruction_set)) {
|
|
|
|
return -1;
|
2014-04-28 07:47:45 +00:00
|
|
|
}
|
2012-10-24 17:45:23 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 22:47:38 +00:00
|
|
|
switch (dexopt_needed) {
|
|
|
|
case DEXOPT_DEX2OAT_NEEDED:
|
|
|
|
input_file = apk_path;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DEXOPT_PATCHOAT_NEEDED:
|
|
|
|
if (!calculate_odex_file_path(in_odex_path, apk_path, instruction_set)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
input_file = in_odex_path;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DEXOPT_SELF_PATCHOAT_NEEDED:
|
|
|
|
input_file = out_path;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ALOGE("Invalid dexopt needed: %d\n", dexopt_needed);
|
|
|
|
exit(72);
|
2014-07-21 19:23:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
memset(&input_stat, 0, sizeof(input_stat));
|
|
|
|
stat(input_file, &input_stat);
|
2012-10-24 17:45:23 +00:00
|
|
|
|
2014-07-21 19:23:48 +00:00
|
|
|
input_fd = open(input_file, O_RDONLY, 0);
|
|
|
|
if (input_fd < 0) {
|
|
|
|
ALOGE("installd cannot open '%s' for input during dexopt\n", input_file);
|
2012-10-24 17:45:23 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-03-22 01:20:22 +00:00
|
|
|
unlink(out_path);
|
|
|
|
out_fd = open(out_path, O_RDWR | O_CREAT | O_EXCL, 0644);
|
|
|
|
if (out_fd < 0) {
|
|
|
|
ALOGE("installd cannot open '%s' for output during dexopt\n", out_path);
|
2012-10-24 17:45:23 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
2013-03-22 01:20:22 +00:00
|
|
|
if (fchmod(out_fd,
|
2012-10-24 17:45:23 +00:00
|
|
|
S_IRUSR|S_IWUSR|S_IRGRP |
|
|
|
|
(is_public ? S_IROTH : 0)) < 0) {
|
2013-03-22 01:20:22 +00:00
|
|
|
ALOGE("installd cannot chmod '%s' during dexopt\n", out_path);
|
2012-10-24 17:45:23 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
2013-03-22 01:20:22 +00:00
|
|
|
if (fchown(out_fd, AID_SYSTEM, uid) < 0) {
|
|
|
|
ALOGE("installd cannot chown '%s' during dexopt\n", out_path);
|
2012-10-24 17:45:23 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2014-01-30 22:19:23 +00:00
|
|
|
// Create profile file if there is a package name present.
|
|
|
|
if (strcmp(pkgname, "*") != 0) {
|
|
|
|
create_profile_file(pkgname, uid);
|
|
|
|
}
|
|
|
|
|
2014-12-11 00:41:11 +00:00
|
|
|
// Create a swap file if necessary.
|
2015-03-26 22:47:38 +00:00
|
|
|
if (ShouldUseSwapFileForDexopt()) {
|
2014-12-11 00:41:11 +00:00
|
|
|
// Make sure there really is enough space.
|
|
|
|
size_t out_len = strlen(out_path);
|
|
|
|
if (out_len + strlen(".swap") + 1 <= PKG_PATH_MAX) {
|
|
|
|
strcpy(swap_file_name, out_path);
|
|
|
|
strcpy(swap_file_name + strlen(out_path), ".swap");
|
|
|
|
unlink(swap_file_name);
|
|
|
|
swap_fd = open(swap_file_name, O_RDWR | O_CREAT | O_EXCL, 0600);
|
|
|
|
if (swap_fd < 0) {
|
|
|
|
// Could not create swap file. Optimistically go on and hope that we can compile
|
|
|
|
// without it.
|
|
|
|
ALOGE("installd could not create '%s' for swap during dexopt\n", swap_file_name);
|
|
|
|
} else {
|
|
|
|
// Immediately unlink. We don't really want to hit flash.
|
|
|
|
unlink(swap_file_name);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Swap file path is too long. Try to run without.
|
|
|
|
ALOGE("installd could not create swap file for path %s during dexopt\n", out_path);
|
|
|
|
}
|
|
|
|
}
|
2014-01-30 22:19:23 +00:00
|
|
|
|
2014-07-21 19:23:48 +00:00
|
|
|
ALOGV("DexInv: --- BEGIN '%s' ---\n", input_file);
|
2012-10-24 17:45:23 +00:00
|
|
|
|
|
|
|
pid_t pid;
|
|
|
|
pid = fork();
|
|
|
|
if (pid == 0) {
|
|
|
|
/* child -- drop privileges before continuing */
|
|
|
|
if (setgid(uid) != 0) {
|
2013-03-22 01:20:22 +00:00
|
|
|
ALOGE("setgid(%d) failed in installd during dexopt\n", uid);
|
2012-10-24 17:45:23 +00:00
|
|
|
exit(64);
|
|
|
|
}
|
|
|
|
if (setuid(uid) != 0) {
|
2013-03-22 01:20:22 +00:00
|
|
|
ALOGE("setuid(%d) failed in installd during dexopt\n", uid);
|
2012-10-24 17:45:23 +00:00
|
|
|
exit(65);
|
|
|
|
}
|
|
|
|
// drop capabilities
|
|
|
|
struct __user_cap_header_struct capheader;
|
|
|
|
struct __user_cap_data_struct capdata[2];
|
|
|
|
memset(&capheader, 0, sizeof(capheader));
|
|
|
|
memset(&capdata, 0, sizeof(capdata));
|
|
|
|
capheader.version = _LINUX_CAPABILITY_VERSION_3;
|
|
|
|
if (capset(&capheader, &capdata[0]) < 0) {
|
|
|
|
ALOGE("capset failed: %s\n", strerror(errno));
|
|
|
|
exit(66);
|
|
|
|
}
|
2015-09-21 20:21:30 +00:00
|
|
|
SetDex2OatAndPatchOatScheduling(boot_complete);
|
2013-03-22 01:20:22 +00:00
|
|
|
if (flock(out_fd, LOCK_EX | LOCK_NB) != 0) {
|
|
|
|
ALOGE("flock(%s) failed: %s\n", out_path, strerror(errno));
|
2012-10-24 17:45:23 +00:00
|
|
|
exit(67);
|
|
|
|
}
|
|
|
|
|
2015-03-26 22:47:38 +00:00
|
|
|
if (dexopt_needed == DEXOPT_PATCHOAT_NEEDED
|
|
|
|
|| dexopt_needed == DEXOPT_SELF_PATCHOAT_NEEDED) {
|
2014-12-15 19:41:11 +00:00
|
|
|
run_patchoat(input_fd, out_fd, input_file, out_path, pkgname, instruction_set);
|
2015-03-26 22:47:38 +00:00
|
|
|
} else if (dexopt_needed == DEXOPT_DEX2OAT_NEEDED) {
|
2015-03-03 20:25:29 +00:00
|
|
|
const char *input_file_name = strrchr(input_file, '/');
|
|
|
|
if (input_file_name == NULL) {
|
|
|
|
input_file_name = input_file;
|
|
|
|
} else {
|
|
|
|
input_file_name++;
|
|
|
|
}
|
|
|
|
run_dex2oat(input_fd, out_fd, input_file_name, out_path, swap_fd, pkgname,
|
2015-09-21 20:21:30 +00:00
|
|
|
instruction_set, vm_safe_mode, debuggable, boot_complete);
|
2015-03-26 22:47:38 +00:00
|
|
|
} else {
|
|
|
|
ALOGE("Invalid dexopt needed: %d\n", dexopt_needed);
|
|
|
|
exit(73);
|
2013-03-22 01:20:22 +00:00
|
|
|
}
|
2012-10-24 17:45:23 +00:00
|
|
|
exit(68); /* only get here on exec failure */
|
|
|
|
} else {
|
Runtime resource overlay, iteration 2
Support any number of overlay packages. Support any target package.
UPDATED PACKAGE MATCHING
------------------------
In Runtime resource overlay, iteration 1, only a single overlay package
was considered. Package matching was based on file paths:
/vendor/overlay/system/framework-res.apk corresponded to
/system/framework-res.apk. Introduce a more flexible matching scheme
where any package is an overlay package if its manifest includes
<overlay targetPackage="com.target.package"/>
For security reasons, an overlay package must fulfill certain criteria
to take effect: see below.
THE IDMAP TOOL AND IDMAP FILES
------------------------------
Idmap files are created by the 'idmap' binary; idmap files must be
present when loading packages. For the Android system, Zygote calls
'idmap' as part of the resource pre-loading. For application packages,
'idmap' is invoked via 'installd' during package installation (similar
to 'dexopt').
UPDATED FLOW
------------
The following is an outline of the start-up sequences for the Android
system and Android apps. Steps marked with '+' are introduced by this
commit.
Zygote initialization
Initial AssetManager object created
+ idmap --scan creates idmaps for overlays targeting 'android', \
stores list of overlays in /data/resource-cache/overlays.list
AssetManager caches framework-res.apk
+ AssetManager caches overlay packages listed in overlays.list
Android boot
New AssetManager's ResTable acquired
AssetManager re-uses cached framework-res.apk
+ AssetManager re-uses cached 'android' overlays (if any)
App boot
ActivityThread prepares AssetManager to load app.apk
+ ActivityThread prepares AssetManager to load app overlays (if any)
New AssetManager's ResTable acquired as per Android boot
SECURITY
--------
Overlay packages are required to be pre-loaded (in /vendor/overlay).
These packages are trusted by definition. A future iteration of runtime
resource overlay may add support for downloaded overlays, which would
likely require target and overlay signatures match for the overlay to
be trusted.
LOOKUP PRIORITY
---------------
During resource lookup, packages are sequentially queried to provide a
best match, given the constraints of the current configuration. If any
package provide a better match than what has been found so far, it
replaces the previous match. The target package is always queried last.
When loading a package with more than one overlay, the order in which
the overlays are added become significant if several packages overlay
the same resource.
Had downloaded overlays been supported, the install time could have been
used to determine the load order. Regardless, for pre-installed
overlays, the install time is randomly determined by the order in which
the Package Manager locates the packages during initial boot. To support
a well-defined order, pre-installed overlay packages are expected to
define an additional 'priority' attribute in their <overlay> tags:
<overlay targetPackage="com.target.package" priority="1234"/>
Pre-installed overlays are loaded in order of their priority attributes,
sorted in ascending order.
Assigning the same priority to several overlays targeting the same base
package leads to undefined behaviour. It is the responsibility of the
vendor to avoid this.
The following example shows the ResTable and PackageGroups after loading
an application and two overlays. The resource lookup framework will
query the packages in the order C, B, A.
+------+------+- -+------+------+
| 0x01 | | ... | | 0x7f |
+------+------+- -+------+------+
| |
"android" Target package A
|
Pre-installed overlay B (priority 1)
|
Pre-installed overlay C (priority 2)
Change-Id: If49c963149369b1957f7d2303b3dd27f669ed24e
2014-01-31 13:42:59 +00:00
|
|
|
res = wait_child(pid);
|
|
|
|
if (res == 0) {
|
2014-07-21 19:23:48 +00:00
|
|
|
ALOGV("DexInv: --- END '%s' (success) ---\n", input_file);
|
Runtime resource overlay, iteration 2
Support any number of overlay packages. Support any target package.
UPDATED PACKAGE MATCHING
------------------------
In Runtime resource overlay, iteration 1, only a single overlay package
was considered. Package matching was based on file paths:
/vendor/overlay/system/framework-res.apk corresponded to
/system/framework-res.apk. Introduce a more flexible matching scheme
where any package is an overlay package if its manifest includes
<overlay targetPackage="com.target.package"/>
For security reasons, an overlay package must fulfill certain criteria
to take effect: see below.
THE IDMAP TOOL AND IDMAP FILES
------------------------------
Idmap files are created by the 'idmap' binary; idmap files must be
present when loading packages. For the Android system, Zygote calls
'idmap' as part of the resource pre-loading. For application packages,
'idmap' is invoked via 'installd' during package installation (similar
to 'dexopt').
UPDATED FLOW
------------
The following is an outline of the start-up sequences for the Android
system and Android apps. Steps marked with '+' are introduced by this
commit.
Zygote initialization
Initial AssetManager object created
+ idmap --scan creates idmaps for overlays targeting 'android', \
stores list of overlays in /data/resource-cache/overlays.list
AssetManager caches framework-res.apk
+ AssetManager caches overlay packages listed in overlays.list
Android boot
New AssetManager's ResTable acquired
AssetManager re-uses cached framework-res.apk
+ AssetManager re-uses cached 'android' overlays (if any)
App boot
ActivityThread prepares AssetManager to load app.apk
+ ActivityThread prepares AssetManager to load app overlays (if any)
New AssetManager's ResTable acquired as per Android boot
SECURITY
--------
Overlay packages are required to be pre-loaded (in /vendor/overlay).
These packages are trusted by definition. A future iteration of runtime
resource overlay may add support for downloaded overlays, which would
likely require target and overlay signatures match for the overlay to
be trusted.
LOOKUP PRIORITY
---------------
During resource lookup, packages are sequentially queried to provide a
best match, given the constraints of the current configuration. If any
package provide a better match than what has been found so far, it
replaces the previous match. The target package is always queried last.
When loading a package with more than one overlay, the order in which
the overlays are added become significant if several packages overlay
the same resource.
Had downloaded overlays been supported, the install time could have been
used to determine the load order. Regardless, for pre-installed
overlays, the install time is randomly determined by the order in which
the Package Manager locates the packages during initial boot. To support
a well-defined order, pre-installed overlay packages are expected to
define an additional 'priority' attribute in their <overlay> tags:
<overlay targetPackage="com.target.package" priority="1234"/>
Pre-installed overlays are loaded in order of their priority attributes,
sorted in ascending order.
Assigning the same priority to several overlays targeting the same base
package leads to undefined behaviour. It is the responsibility of the
vendor to avoid this.
The following example shows the ResTable and PackageGroups after loading
an application and two overlays. The resource lookup framework will
query the packages in the order C, B, A.
+------+------+- -+------+------+
| 0x01 | | ... | | 0x7f |
+------+------+- -+------+------+
| |
"android" Target package A
|
Pre-installed overlay B (priority 1)
|
Pre-installed overlay C (priority 2)
Change-Id: If49c963149369b1957f7d2303b3dd27f669ed24e
2014-01-31 13:42:59 +00:00
|
|
|
} else {
|
2014-07-21 19:23:48 +00:00
|
|
|
ALOGE("DexInv: --- END '%s' --- status=0x%04x, process failed\n", input_file, res);
|
2012-10-24 17:45:23 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-21 19:23:48 +00:00
|
|
|
ut.actime = input_stat.st_atime;
|
|
|
|
ut.modtime = input_stat.st_mtime;
|
2013-03-22 01:20:22 +00:00
|
|
|
utime(out_path, &ut);
|
|
|
|
|
|
|
|
close(out_fd);
|
2014-07-21 19:23:48 +00:00
|
|
|
close(input_fd);
|
2014-12-11 00:41:11 +00:00
|
|
|
if (swap_fd != -1) {
|
|
|
|
close(swap_fd);
|
|
|
|
}
|
2012-10-24 17:45:23 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
2013-03-22 01:20:22 +00:00
|
|
|
if (out_fd >= 0) {
|
|
|
|
close(out_fd);
|
|
|
|
unlink(out_path);
|
2012-10-24 17:45:23 +00:00
|
|
|
}
|
2014-07-21 19:23:48 +00:00
|
|
|
if (input_fd >= 0) {
|
|
|
|
close(input_fd);
|
2012-10-24 17:45:23 +00:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-11-10 15:03:46 +00:00
|
|
|
int mark_boot_complete(const char* instruction_set)
|
|
|
|
{
|
|
|
|
char boot_marker_path[PKG_PATH_MAX];
|
|
|
|
sprintf(boot_marker_path,"%s%s/.booting", DALVIK_CACHE_PREFIX, instruction_set);
|
|
|
|
|
|
|
|
ALOGV("mark_boot_complete : %s", boot_marker_path);
|
|
|
|
if (unlink(boot_marker_path) != 0) {
|
|
|
|
ALOGE("Unable to unlink boot marker at %s, error=%s", boot_marker_path,
|
|
|
|
strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-24 17:45:23 +00:00
|
|
|
void mkinnerdirs(char* path, int basepos, mode_t mode, int uid, int gid,
|
|
|
|
struct stat* statbuf)
|
|
|
|
{
|
|
|
|
while (path[basepos] != 0) {
|
|
|
|
if (path[basepos] == '/') {
|
|
|
|
path[basepos] = 0;
|
|
|
|
if (lstat(path, statbuf) < 0) {
|
|
|
|
ALOGV("Making directory: %s\n", path);
|
|
|
|
if (mkdir(path, mode) == 0) {
|
|
|
|
chown(path, uid, gid);
|
|
|
|
} else {
|
|
|
|
ALOGW("Unable to make directory %s: %s\n", path, strerror(errno));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
path[basepos] = '/';
|
|
|
|
basepos++;
|
|
|
|
}
|
|
|
|
basepos++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int movefileordir(char* srcpath, char* dstpath, int dstbasepos,
|
|
|
|
int dstuid, int dstgid, struct stat* statbuf)
|
|
|
|
{
|
|
|
|
DIR *d;
|
|
|
|
struct dirent *de;
|
|
|
|
int res;
|
|
|
|
|
|
|
|
int srcend = strlen(srcpath);
|
|
|
|
int dstend = strlen(dstpath);
|
2014-01-30 22:19:23 +00:00
|
|
|
|
2012-10-24 17:45:23 +00:00
|
|
|
if (lstat(srcpath, statbuf) < 0) {
|
|
|
|
ALOGW("Unable to stat %s: %s\n", srcpath, strerror(errno));
|
|
|
|
return 1;
|
|
|
|
}
|
2014-01-30 22:19:23 +00:00
|
|
|
|
2012-10-24 17:45:23 +00:00
|
|
|
if ((statbuf->st_mode&S_IFDIR) == 0) {
|
|
|
|
mkinnerdirs(dstpath, dstbasepos, S_IRWXU|S_IRWXG|S_IXOTH,
|
|
|
|
dstuid, dstgid, statbuf);
|
|
|
|
ALOGV("Renaming %s to %s (uid %d)\n", srcpath, dstpath, dstuid);
|
|
|
|
if (rename(srcpath, dstpath) >= 0) {
|
|
|
|
if (chown(dstpath, dstuid, dstgid) < 0) {
|
|
|
|
ALOGE("cannot chown %s: %s\n", dstpath, strerror(errno));
|
|
|
|
unlink(dstpath);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ALOGW("Unable to rename %s to %s: %s\n",
|
|
|
|
srcpath, dstpath, strerror(errno));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
d = opendir(srcpath);
|
|
|
|
if (d == NULL) {
|
|
|
|
ALOGW("Unable to opendir %s: %s\n", srcpath, strerror(errno));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = 0;
|
2014-01-30 22:19:23 +00:00
|
|
|
|
2012-10-24 17:45:23 +00:00
|
|
|
while ((de = readdir(d))) {
|
|
|
|
const char *name = de->d_name;
|
|
|
|
/* always skip "." and ".." */
|
|
|
|
if (name[0] == '.') {
|
|
|
|
if (name[1] == 0) continue;
|
|
|
|
if ((name[1] == '.') && (name[2] == 0)) continue;
|
|
|
|
}
|
2014-01-30 22:19:23 +00:00
|
|
|
|
2012-10-24 17:45:23 +00:00
|
|
|
if ((srcend+strlen(name)) >= (PKG_PATH_MAX-2)) {
|
|
|
|
ALOGW("Source path too long; skipping: %s/%s\n", srcpath, name);
|
|
|
|
continue;
|
|
|
|
}
|
2014-01-30 22:19:23 +00:00
|
|
|
|
2012-10-24 17:45:23 +00:00
|
|
|
if ((dstend+strlen(name)) >= (PKG_PATH_MAX-2)) {
|
|
|
|
ALOGW("Destination path too long; skipping: %s/%s\n", dstpath, name);
|
|
|
|
continue;
|
|
|
|
}
|
2014-01-30 22:19:23 +00:00
|
|
|
|
2012-10-24 17:45:23 +00:00
|
|
|
srcpath[srcend] = dstpath[dstend] = '/';
|
|
|
|
strcpy(srcpath+srcend+1, name);
|
|
|
|
strcpy(dstpath+dstend+1, name);
|
2014-01-30 22:19:23 +00:00
|
|
|
|
2012-10-24 17:45:23 +00:00
|
|
|
if (movefileordir(srcpath, dstpath, dstbasepos, dstuid, dstgid, statbuf) != 0) {
|
|
|
|
res = 1;
|
|
|
|
}
|
2014-01-30 22:19:23 +00:00
|
|
|
|
2012-10-24 17:45:23 +00:00
|
|
|
// Note: we will be leaving empty directories behind in srcpath,
|
|
|
|
// but that is okay, the package manager will be erasing all of the
|
|
|
|
// data associated with .apks that disappear.
|
2014-01-30 22:19:23 +00:00
|
|
|
|
2012-10-24 17:45:23 +00:00
|
|
|
srcpath[srcend] = dstpath[dstend] = 0;
|
|
|
|
}
|
2014-01-30 22:19:23 +00:00
|
|
|
|
2012-10-24 17:45:23 +00:00
|
|
|
closedir(d);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
int movefiles()
|
|
|
|
{
|
|
|
|
DIR *d;
|
|
|
|
int dfd, subfd;
|
|
|
|
struct dirent *de;
|
|
|
|
struct stat s;
|
|
|
|
char buf[PKG_PATH_MAX+1];
|
|
|
|
int bufp, bufe, bufi, readlen;
|
|
|
|
|
|
|
|
char srcpkg[PKG_NAME_MAX];
|
|
|
|
char dstpkg[PKG_NAME_MAX];
|
|
|
|
char srcpath[PKG_PATH_MAX];
|
|
|
|
char dstpath[PKG_PATH_MAX];
|
|
|
|
int dstuid=-1, dstgid=-1;
|
|
|
|
int hasspace;
|
|
|
|
|
|
|
|
d = opendir(UPDATE_COMMANDS_DIR_PREFIX);
|
|
|
|
if (d == NULL) {
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
dfd = dirfd(d);
|
|
|
|
|
|
|
|
/* Iterate through all files in the directory, executing the
|
|
|
|
* file movements requested there-in.
|
|
|
|
*/
|
|
|
|
while ((de = readdir(d))) {
|
|
|
|
const char *name = de->d_name;
|
|
|
|
|
|
|
|
if (de->d_type == DT_DIR) {
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
subfd = openat(dfd, name, O_RDONLY);
|
|
|
|
if (subfd < 0) {
|
|
|
|
ALOGW("Unable to open update commands at %s%s\n",
|
|
|
|
UPDATE_COMMANDS_DIR_PREFIX, name);
|
|
|
|
continue;
|
|
|
|
}
|
2014-01-30 22:19:23 +00:00
|
|
|
|
2012-10-24 17:45:23 +00:00
|
|
|
bufp = 0;
|
|
|
|
bufe = 0;
|
|
|
|
buf[PKG_PATH_MAX] = 0;
|
|
|
|
srcpkg[0] = dstpkg[0] = 0;
|
|
|
|
while (1) {
|
|
|
|
bufi = bufp;
|
|
|
|
while (bufi < bufe && buf[bufi] != '\n') {
|
|
|
|
bufi++;
|
|
|
|
}
|
|
|
|
if (bufi < bufe) {
|
|
|
|
buf[bufi] = 0;
|
|
|
|
ALOGV("Processing line: %s\n", buf+bufp);
|
|
|
|
hasspace = 0;
|
|
|
|
while (bufp < bufi && isspace(buf[bufp])) {
|
|
|
|
hasspace = 1;
|
|
|
|
bufp++;
|
|
|
|
}
|
|
|
|
if (buf[bufp] == '#' || bufp == bufi) {
|
|
|
|
// skip comments and empty lines.
|
|
|
|
} else if (hasspace) {
|
|
|
|
if (dstpkg[0] == 0) {
|
|
|
|
ALOGW("Path before package line in %s%s: %s\n",
|
|
|
|
UPDATE_COMMANDS_DIR_PREFIX, name, buf+bufp);
|
|
|
|
} else if (srcpkg[0] == 0) {
|
|
|
|
// Skip -- source package no longer exists.
|
|
|
|
} else {
|
|
|
|
ALOGV("Move file: %s (from %s to %s)\n", buf+bufp, srcpkg, dstpkg);
|
|
|
|
if (!create_move_path(srcpath, srcpkg, buf+bufp, 0) &&
|
|
|
|
!create_move_path(dstpath, dstpkg, buf+bufp, 0)) {
|
|
|
|
movefileordir(srcpath, dstpath,
|
|
|
|
strlen(dstpath)-strlen(buf+bufp),
|
|
|
|
dstuid, dstgid, &s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
char* div = strchr(buf+bufp, ':');
|
|
|
|
if (div == NULL) {
|
|
|
|
ALOGW("Bad package spec in %s%s; no ':' sep: %s\n",
|
|
|
|
UPDATE_COMMANDS_DIR_PREFIX, name, buf+bufp);
|
|
|
|
} else {
|
|
|
|
*div = 0;
|
|
|
|
div++;
|
|
|
|
if (strlen(buf+bufp) < PKG_NAME_MAX) {
|
|
|
|
strcpy(dstpkg, buf+bufp);
|
|
|
|
} else {
|
|
|
|
srcpkg[0] = dstpkg[0] = 0;
|
|
|
|
ALOGW("Package name too long in %s%s: %s\n",
|
|
|
|
UPDATE_COMMANDS_DIR_PREFIX, name, buf+bufp);
|
|
|
|
}
|
|
|
|
if (strlen(div) < PKG_NAME_MAX) {
|
|
|
|
strcpy(srcpkg, div);
|
|
|
|
} else {
|
|
|
|
srcpkg[0] = dstpkg[0] = 0;
|
|
|
|
ALOGW("Package name too long in %s%s: %s\n",
|
|
|
|
UPDATE_COMMANDS_DIR_PREFIX, name, div);
|
|
|
|
}
|
|
|
|
if (srcpkg[0] != 0) {
|
|
|
|
if (!create_pkg_path(srcpath, srcpkg, PKG_DIR_POSTFIX, 0)) {
|
|
|
|
if (lstat(srcpath, &s) < 0) {
|
|
|
|
// Package no longer exists -- skip.
|
|
|
|
srcpkg[0] = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
srcpkg[0] = 0;
|
|
|
|
ALOGW("Can't create path %s in %s%s\n",
|
|
|
|
div, UPDATE_COMMANDS_DIR_PREFIX, name);
|
|
|
|
}
|
|
|
|
if (srcpkg[0] != 0) {
|
|
|
|
if (!create_pkg_path(dstpath, dstpkg, PKG_DIR_POSTFIX, 0)) {
|
|
|
|
if (lstat(dstpath, &s) == 0) {
|
|
|
|
dstuid = s.st_uid;
|
|
|
|
dstgid = s.st_gid;
|
|
|
|
} else {
|
|
|
|
// Destination package doesn't
|
|
|
|
// exist... due to original-package,
|
|
|
|
// this is normal, so don't be
|
|
|
|
// noisy about it.
|
|
|
|
srcpkg[0] = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
srcpkg[0] = 0;
|
|
|
|
ALOGW("Can't create path %s in %s%s\n",
|
|
|
|
div, UPDATE_COMMANDS_DIR_PREFIX, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ALOGV("Transfering from %s to %s: uid=%d\n",
|
|
|
|
srcpkg, dstpkg, dstuid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bufp = bufi+1;
|
|
|
|
} else {
|
|
|
|
if (bufp == 0) {
|
|
|
|
if (bufp < bufe) {
|
|
|
|
ALOGW("Line too long in %s%s, skipping: %s\n",
|
|
|
|
UPDATE_COMMANDS_DIR_PREFIX, name, buf);
|
|
|
|
}
|
|
|
|
} else if (bufp < bufe) {
|
|
|
|
memcpy(buf, buf+bufp, bufe-bufp);
|
|
|
|
bufe -= bufp;
|
|
|
|
bufp = 0;
|
|
|
|
}
|
|
|
|
readlen = read(subfd, buf+bufe, PKG_PATH_MAX-bufe);
|
|
|
|
if (readlen < 0) {
|
|
|
|
ALOGW("Failure reading update commands in %s%s: %s\n",
|
|
|
|
UPDATE_COMMANDS_DIR_PREFIX, name, strerror(errno));
|
|
|
|
break;
|
|
|
|
} else if (readlen == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
bufe += readlen;
|
|
|
|
buf[bufe] = 0;
|
|
|
|
ALOGV("Read buf: %s\n", buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(subfd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir(d);
|
|
|
|
done:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-08 01:14:05 +00:00
|
|
|
int linklib(const char* uuid, const char* pkgname, const char* asecLibDir, int userId)
|
2012-10-24 17:45:23 +00:00
|
|
|
{
|
|
|
|
struct stat s, libStat;
|
|
|
|
int rc = 0;
|
|
|
|
|
2015-04-30 22:58:19 +00:00
|
|
|
std::string _pkgdir(create_data_user_package_path(uuid, userId, pkgname));
|
2015-04-08 01:14:05 +00:00
|
|
|
std::string _libsymlink(_pkgdir + PKG_LIB_POSTFIX);
|
|
|
|
|
|
|
|
const char* pkgdir = _pkgdir.c_str();
|
|
|
|
const char* libsymlink = _libsymlink.c_str();
|
2012-10-24 17:45:23 +00:00
|
|
|
|
|
|
|
if (stat(pkgdir, &s) < 0) return -1;
|
|
|
|
|
|
|
|
if (chown(pkgdir, AID_INSTALL, AID_INSTALL) < 0) {
|
|
|
|
ALOGE("failed to chown '%s': %s\n", pkgdir, strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (chmod(pkgdir, 0700) < 0) {
|
|
|
|
ALOGE("linklib() 1: failed to chmod '%s': %s\n", pkgdir, strerror(errno));
|
|
|
|
rc = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lstat(libsymlink, &libStat) < 0) {
|
|
|
|
if (errno != ENOENT) {
|
|
|
|
ALOGE("couldn't stat lib dir: %s\n", strerror(errno));
|
|
|
|
rc = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (S_ISDIR(libStat.st_mode)) {
|
2014-06-10 12:16:47 +00:00
|
|
|
if (delete_dir_contents(libsymlink, 1, NULL) < 0) {
|
2012-10-24 17:45:23 +00:00
|
|
|
rc = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
} else if (S_ISLNK(libStat.st_mode)) {
|
|
|
|
if (unlink(libsymlink) < 0) {
|
|
|
|
ALOGE("couldn't unlink lib dir: %s\n", strerror(errno));
|
|
|
|
rc = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (symlink(asecLibDir, libsymlink) < 0) {
|
|
|
|
ALOGE("couldn't symlink directory '%s' -> '%s': %s\n", libsymlink, asecLibDir,
|
|
|
|
strerror(errno));
|
|
|
|
rc = -errno;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (chmod(pkgdir, s.st_mode) < 0) {
|
|
|
|
ALOGE("linklib() 2: failed to chmod '%s': %s\n", pkgdir, strerror(errno));
|
|
|
|
rc = -errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (chown(pkgdir, s.st_uid, s.st_gid) < 0) {
|
|
|
|
ALOGE("failed to chown '%s' : %s\n", pkgdir, strerror(errno));
|
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
Runtime resource overlay, iteration 2
Support any number of overlay packages. Support any target package.
UPDATED PACKAGE MATCHING
------------------------
In Runtime resource overlay, iteration 1, only a single overlay package
was considered. Package matching was based on file paths:
/vendor/overlay/system/framework-res.apk corresponded to
/system/framework-res.apk. Introduce a more flexible matching scheme
where any package is an overlay package if its manifest includes
<overlay targetPackage="com.target.package"/>
For security reasons, an overlay package must fulfill certain criteria
to take effect: see below.
THE IDMAP TOOL AND IDMAP FILES
------------------------------
Idmap files are created by the 'idmap' binary; idmap files must be
present when loading packages. For the Android system, Zygote calls
'idmap' as part of the resource pre-loading. For application packages,
'idmap' is invoked via 'installd' during package installation (similar
to 'dexopt').
UPDATED FLOW
------------
The following is an outline of the start-up sequences for the Android
system and Android apps. Steps marked with '+' are introduced by this
commit.
Zygote initialization
Initial AssetManager object created
+ idmap --scan creates idmaps for overlays targeting 'android', \
stores list of overlays in /data/resource-cache/overlays.list
AssetManager caches framework-res.apk
+ AssetManager caches overlay packages listed in overlays.list
Android boot
New AssetManager's ResTable acquired
AssetManager re-uses cached framework-res.apk
+ AssetManager re-uses cached 'android' overlays (if any)
App boot
ActivityThread prepares AssetManager to load app.apk
+ ActivityThread prepares AssetManager to load app overlays (if any)
New AssetManager's ResTable acquired as per Android boot
SECURITY
--------
Overlay packages are required to be pre-loaded (in /vendor/overlay).
These packages are trusted by definition. A future iteration of runtime
resource overlay may add support for downloaded overlays, which would
likely require target and overlay signatures match for the overlay to
be trusted.
LOOKUP PRIORITY
---------------
During resource lookup, packages are sequentially queried to provide a
best match, given the constraints of the current configuration. If any
package provide a better match than what has been found so far, it
replaces the previous match. The target package is always queried last.
When loading a package with more than one overlay, the order in which
the overlays are added become significant if several packages overlay
the same resource.
Had downloaded overlays been supported, the install time could have been
used to determine the load order. Regardless, for pre-installed
overlays, the install time is randomly determined by the order in which
the Package Manager locates the packages during initial boot. To support
a well-defined order, pre-installed overlay packages are expected to
define an additional 'priority' attribute in their <overlay> tags:
<overlay targetPackage="com.target.package" priority="1234"/>
Pre-installed overlays are loaded in order of their priority attributes,
sorted in ascending order.
Assigning the same priority to several overlays targeting the same base
package leads to undefined behaviour. It is the responsibility of the
vendor to avoid this.
The following example shows the ResTable and PackageGroups after loading
an application and two overlays. The resource lookup framework will
query the packages in the order C, B, A.
+------+------+- -+------+------+
| 0x01 | | ... | | 0x7f |
+------+------+- -+------+------+
| |
"android" Target package A
|
Pre-installed overlay B (priority 1)
|
Pre-installed overlay C (priority 2)
Change-Id: If49c963149369b1957f7d2303b3dd27f669ed24e
2014-01-31 13:42:59 +00:00
|
|
|
|
2015-01-19 16:19:29 +00:00
|
|
|
static void run_idmap(const char *target_apk, const char *overlay_apk, const char *cache_path,
|
|
|
|
int idmap_fd, uint32_t target_hash, uint32_t overlay_hash)
|
Runtime resource overlay, iteration 2
Support any number of overlay packages. Support any target package.
UPDATED PACKAGE MATCHING
------------------------
In Runtime resource overlay, iteration 1, only a single overlay package
was considered. Package matching was based on file paths:
/vendor/overlay/system/framework-res.apk corresponded to
/system/framework-res.apk. Introduce a more flexible matching scheme
where any package is an overlay package if its manifest includes
<overlay targetPackage="com.target.package"/>
For security reasons, an overlay package must fulfill certain criteria
to take effect: see below.
THE IDMAP TOOL AND IDMAP FILES
------------------------------
Idmap files are created by the 'idmap' binary; idmap files must be
present when loading packages. For the Android system, Zygote calls
'idmap' as part of the resource pre-loading. For application packages,
'idmap' is invoked via 'installd' during package installation (similar
to 'dexopt').
UPDATED FLOW
------------
The following is an outline of the start-up sequences for the Android
system and Android apps. Steps marked with '+' are introduced by this
commit.
Zygote initialization
Initial AssetManager object created
+ idmap --scan creates idmaps for overlays targeting 'android', \
stores list of overlays in /data/resource-cache/overlays.list
AssetManager caches framework-res.apk
+ AssetManager caches overlay packages listed in overlays.list
Android boot
New AssetManager's ResTable acquired
AssetManager re-uses cached framework-res.apk
+ AssetManager re-uses cached 'android' overlays (if any)
App boot
ActivityThread prepares AssetManager to load app.apk
+ ActivityThread prepares AssetManager to load app overlays (if any)
New AssetManager's ResTable acquired as per Android boot
SECURITY
--------
Overlay packages are required to be pre-loaded (in /vendor/overlay).
These packages are trusted by definition. A future iteration of runtime
resource overlay may add support for downloaded overlays, which would
likely require target and overlay signatures match for the overlay to
be trusted.
LOOKUP PRIORITY
---------------
During resource lookup, packages are sequentially queried to provide a
best match, given the constraints of the current configuration. If any
package provide a better match than what has been found so far, it
replaces the previous match. The target package is always queried last.
When loading a package with more than one overlay, the order in which
the overlays are added become significant if several packages overlay
the same resource.
Had downloaded overlays been supported, the install time could have been
used to determine the load order. Regardless, for pre-installed
overlays, the install time is randomly determined by the order in which
the Package Manager locates the packages during initial boot. To support
a well-defined order, pre-installed overlay packages are expected to
define an additional 'priority' attribute in their <overlay> tags:
<overlay targetPackage="com.target.package" priority="1234"/>
Pre-installed overlays are loaded in order of their priority attributes,
sorted in ascending order.
Assigning the same priority to several overlays targeting the same base
package leads to undefined behaviour. It is the responsibility of the
vendor to avoid this.
The following example shows the ResTable and PackageGroups after loading
an application and two overlays. The resource lookup framework will
query the packages in the order C, B, A.
+------+------+- -+------+------+
| 0x01 | | ... | | 0x7f |
+------+------+- -+------+------+
| |
"android" Target package A
|
Pre-installed overlay B (priority 1)
|
Pre-installed overlay C (priority 2)
Change-Id: If49c963149369b1957f7d2303b3dd27f669ed24e
2014-01-31 13:42:59 +00:00
|
|
|
{
|
|
|
|
static const char *IDMAP_BIN = "/system/bin/idmap";
|
|
|
|
static const size_t MAX_INT_LEN = 32;
|
|
|
|
char idmap_str[MAX_INT_LEN];
|
2014-11-25 20:04:16 +00:00
|
|
|
char target_hash_str[MAX_INT_LEN];
|
|
|
|
char overlay_hash_str[MAX_INT_LEN];
|
Runtime resource overlay, iteration 2
Support any number of overlay packages. Support any target package.
UPDATED PACKAGE MATCHING
------------------------
In Runtime resource overlay, iteration 1, only a single overlay package
was considered. Package matching was based on file paths:
/vendor/overlay/system/framework-res.apk corresponded to
/system/framework-res.apk. Introduce a more flexible matching scheme
where any package is an overlay package if its manifest includes
<overlay targetPackage="com.target.package"/>
For security reasons, an overlay package must fulfill certain criteria
to take effect: see below.
THE IDMAP TOOL AND IDMAP FILES
------------------------------
Idmap files are created by the 'idmap' binary; idmap files must be
present when loading packages. For the Android system, Zygote calls
'idmap' as part of the resource pre-loading. For application packages,
'idmap' is invoked via 'installd' during package installation (similar
to 'dexopt').
UPDATED FLOW
------------
The following is an outline of the start-up sequences for the Android
system and Android apps. Steps marked with '+' are introduced by this
commit.
Zygote initialization
Initial AssetManager object created
+ idmap --scan creates idmaps for overlays targeting 'android', \
stores list of overlays in /data/resource-cache/overlays.list
AssetManager caches framework-res.apk
+ AssetManager caches overlay packages listed in overlays.list
Android boot
New AssetManager's ResTable acquired
AssetManager re-uses cached framework-res.apk
+ AssetManager re-uses cached 'android' overlays (if any)
App boot
ActivityThread prepares AssetManager to load app.apk
+ ActivityThread prepares AssetManager to load app overlays (if any)
New AssetManager's ResTable acquired as per Android boot
SECURITY
--------
Overlay packages are required to be pre-loaded (in /vendor/overlay).
These packages are trusted by definition. A future iteration of runtime
resource overlay may add support for downloaded overlays, which would
likely require target and overlay signatures match for the overlay to
be trusted.
LOOKUP PRIORITY
---------------
During resource lookup, packages are sequentially queried to provide a
best match, given the constraints of the current configuration. If any
package provide a better match than what has been found so far, it
replaces the previous match. The target package is always queried last.
When loading a package with more than one overlay, the order in which
the overlays are added become significant if several packages overlay
the same resource.
Had downloaded overlays been supported, the install time could have been
used to determine the load order. Regardless, for pre-installed
overlays, the install time is randomly determined by the order in which
the Package Manager locates the packages during initial boot. To support
a well-defined order, pre-installed overlay packages are expected to
define an additional 'priority' attribute in their <overlay> tags:
<overlay targetPackage="com.target.package" priority="1234"/>
Pre-installed overlays are loaded in order of their priority attributes,
sorted in ascending order.
Assigning the same priority to several overlays targeting the same base
package leads to undefined behaviour. It is the responsibility of the
vendor to avoid this.
The following example shows the ResTable and PackageGroups after loading
an application and two overlays. The resource lookup framework will
query the packages in the order C, B, A.
+------+------+- -+------+------+
| 0x01 | | ... | | 0x7f |
+------+------+- -+------+------+
| |
"android" Target package A
|
Pre-installed overlay B (priority 1)
|
Pre-installed overlay C (priority 2)
Change-Id: If49c963149369b1957f7d2303b3dd27f669ed24e
2014-01-31 13:42:59 +00:00
|
|
|
|
|
|
|
snprintf(idmap_str, sizeof(idmap_str), "%d", idmap_fd);
|
2014-11-25 20:04:16 +00:00
|
|
|
snprintf(target_hash_str, sizeof(target_hash_str), "%d", target_hash);
|
|
|
|
snprintf(overlay_hash_str, sizeof(overlay_hash_str), "%d", overlay_hash);
|
Runtime resource overlay, iteration 2
Support any number of overlay packages. Support any target package.
UPDATED PACKAGE MATCHING
------------------------
In Runtime resource overlay, iteration 1, only a single overlay package
was considered. Package matching was based on file paths:
/vendor/overlay/system/framework-res.apk corresponded to
/system/framework-res.apk. Introduce a more flexible matching scheme
where any package is an overlay package if its manifest includes
<overlay targetPackage="com.target.package"/>
For security reasons, an overlay package must fulfill certain criteria
to take effect: see below.
THE IDMAP TOOL AND IDMAP FILES
------------------------------
Idmap files are created by the 'idmap' binary; idmap files must be
present when loading packages. For the Android system, Zygote calls
'idmap' as part of the resource pre-loading. For application packages,
'idmap' is invoked via 'installd' during package installation (similar
to 'dexopt').
UPDATED FLOW
------------
The following is an outline of the start-up sequences for the Android
system and Android apps. Steps marked with '+' are introduced by this
commit.
Zygote initialization
Initial AssetManager object created
+ idmap --scan creates idmaps for overlays targeting 'android', \
stores list of overlays in /data/resource-cache/overlays.list
AssetManager caches framework-res.apk
+ AssetManager caches overlay packages listed in overlays.list
Android boot
New AssetManager's ResTable acquired
AssetManager re-uses cached framework-res.apk
+ AssetManager re-uses cached 'android' overlays (if any)
App boot
ActivityThread prepares AssetManager to load app.apk
+ ActivityThread prepares AssetManager to load app overlays (if any)
New AssetManager's ResTable acquired as per Android boot
SECURITY
--------
Overlay packages are required to be pre-loaded (in /vendor/overlay).
These packages are trusted by definition. A future iteration of runtime
resource overlay may add support for downloaded overlays, which would
likely require target and overlay signatures match for the overlay to
be trusted.
LOOKUP PRIORITY
---------------
During resource lookup, packages are sequentially queried to provide a
best match, given the constraints of the current configuration. If any
package provide a better match than what has been found so far, it
replaces the previous match. The target package is always queried last.
When loading a package with more than one overlay, the order in which
the overlays are added become significant if several packages overlay
the same resource.
Had downloaded overlays been supported, the install time could have been
used to determine the load order. Regardless, for pre-installed
overlays, the install time is randomly determined by the order in which
the Package Manager locates the packages during initial boot. To support
a well-defined order, pre-installed overlay packages are expected to
define an additional 'priority' attribute in their <overlay> tags:
<overlay targetPackage="com.target.package" priority="1234"/>
Pre-installed overlays are loaded in order of their priority attributes,
sorted in ascending order.
Assigning the same priority to several overlays targeting the same base
package leads to undefined behaviour. It is the responsibility of the
vendor to avoid this.
The following example shows the ResTable and PackageGroups after loading
an application and two overlays. The resource lookup framework will
query the packages in the order C, B, A.
+------+------+- -+------+------+
| 0x01 | | ... | | 0x7f |
+------+------+- -+------+------+
| |
"android" Target package A
|
Pre-installed overlay B (priority 1)
|
Pre-installed overlay C (priority 2)
Change-Id: If49c963149369b1957f7d2303b3dd27f669ed24e
2014-01-31 13:42:59 +00:00
|
|
|
|
2015-01-19 16:19:29 +00:00
|
|
|
execl(IDMAP_BIN, IDMAP_BIN, "--fd", target_apk, overlay_apk, cache_path, idmap_str,
|
2014-11-25 20:04:16 +00:00
|
|
|
target_hash_str, overlay_hash_str, (char*)NULL);
|
Runtime resource overlay, iteration 2
Support any number of overlay packages. Support any target package.
UPDATED PACKAGE MATCHING
------------------------
In Runtime resource overlay, iteration 1, only a single overlay package
was considered. Package matching was based on file paths:
/vendor/overlay/system/framework-res.apk corresponded to
/system/framework-res.apk. Introduce a more flexible matching scheme
where any package is an overlay package if its manifest includes
<overlay targetPackage="com.target.package"/>
For security reasons, an overlay package must fulfill certain criteria
to take effect: see below.
THE IDMAP TOOL AND IDMAP FILES
------------------------------
Idmap files are created by the 'idmap' binary; idmap files must be
present when loading packages. For the Android system, Zygote calls
'idmap' as part of the resource pre-loading. For application packages,
'idmap' is invoked via 'installd' during package installation (similar
to 'dexopt').
UPDATED FLOW
------------
The following is an outline of the start-up sequences for the Android
system and Android apps. Steps marked with '+' are introduced by this
commit.
Zygote initialization
Initial AssetManager object created
+ idmap --scan creates idmaps for overlays targeting 'android', \
stores list of overlays in /data/resource-cache/overlays.list
AssetManager caches framework-res.apk
+ AssetManager caches overlay packages listed in overlays.list
Android boot
New AssetManager's ResTable acquired
AssetManager re-uses cached framework-res.apk
+ AssetManager re-uses cached 'android' overlays (if any)
App boot
ActivityThread prepares AssetManager to load app.apk
+ ActivityThread prepares AssetManager to load app overlays (if any)
New AssetManager's ResTable acquired as per Android boot
SECURITY
--------
Overlay packages are required to be pre-loaded (in /vendor/overlay).
These packages are trusted by definition. A future iteration of runtime
resource overlay may add support for downloaded overlays, which would
likely require target and overlay signatures match for the overlay to
be trusted.
LOOKUP PRIORITY
---------------
During resource lookup, packages are sequentially queried to provide a
best match, given the constraints of the current configuration. If any
package provide a better match than what has been found so far, it
replaces the previous match. The target package is always queried last.
When loading a package with more than one overlay, the order in which
the overlays are added become significant if several packages overlay
the same resource.
Had downloaded overlays been supported, the install time could have been
used to determine the load order. Regardless, for pre-installed
overlays, the install time is randomly determined by the order in which
the Package Manager locates the packages during initial boot. To support
a well-defined order, pre-installed overlay packages are expected to
define an additional 'priority' attribute in their <overlay> tags:
<overlay targetPackage="com.target.package" priority="1234"/>
Pre-installed overlays are loaded in order of their priority attributes,
sorted in ascending order.
Assigning the same priority to several overlays targeting the same base
package leads to undefined behaviour. It is the responsibility of the
vendor to avoid this.
The following example shows the ResTable and PackageGroups after loading
an application and two overlays. The resource lookup framework will
query the packages in the order C, B, A.
+------+------+- -+------+------+
| 0x01 | | ... | | 0x7f |
+------+------+- -+------+------+
| |
"android" Target package A
|
Pre-installed overlay B (priority 1)
|
Pre-installed overlay C (priority 2)
Change-Id: If49c963149369b1957f7d2303b3dd27f669ed24e
2014-01-31 13:42:59 +00:00
|
|
|
ALOGE("execl(%s) failed: %s\n", IDMAP_BIN, strerror(errno));
|
|
|
|
}
|
|
|
|
|
2015-01-19 16:19:29 +00:00
|
|
|
static int get_idmap_path(const char *prefix, const char *suffix, char *idmap_path, size_t N)
|
Runtime resource overlay, iteration 2
Support any number of overlay packages. Support any target package.
UPDATED PACKAGE MATCHING
------------------------
In Runtime resource overlay, iteration 1, only a single overlay package
was considered. Package matching was based on file paths:
/vendor/overlay/system/framework-res.apk corresponded to
/system/framework-res.apk. Introduce a more flexible matching scheme
where any package is an overlay package if its manifest includes
<overlay targetPackage="com.target.package"/>
For security reasons, an overlay package must fulfill certain criteria
to take effect: see below.
THE IDMAP TOOL AND IDMAP FILES
------------------------------
Idmap files are created by the 'idmap' binary; idmap files must be
present when loading packages. For the Android system, Zygote calls
'idmap' as part of the resource pre-loading. For application packages,
'idmap' is invoked via 'installd' during package installation (similar
to 'dexopt').
UPDATED FLOW
------------
The following is an outline of the start-up sequences for the Android
system and Android apps. Steps marked with '+' are introduced by this
commit.
Zygote initialization
Initial AssetManager object created
+ idmap --scan creates idmaps for overlays targeting 'android', \
stores list of overlays in /data/resource-cache/overlays.list
AssetManager caches framework-res.apk
+ AssetManager caches overlay packages listed in overlays.list
Android boot
New AssetManager's ResTable acquired
AssetManager re-uses cached framework-res.apk
+ AssetManager re-uses cached 'android' overlays (if any)
App boot
ActivityThread prepares AssetManager to load app.apk
+ ActivityThread prepares AssetManager to load app overlays (if any)
New AssetManager's ResTable acquired as per Android boot
SECURITY
--------
Overlay packages are required to be pre-loaded (in /vendor/overlay).
These packages are trusted by definition. A future iteration of runtime
resource overlay may add support for downloaded overlays, which would
likely require target and overlay signatures match for the overlay to
be trusted.
LOOKUP PRIORITY
---------------
During resource lookup, packages are sequentially queried to provide a
best match, given the constraints of the current configuration. If any
package provide a better match than what has been found so far, it
replaces the previous match. The target package is always queried last.
When loading a package with more than one overlay, the order in which
the overlays are added become significant if several packages overlay
the same resource.
Had downloaded overlays been supported, the install time could have been
used to determine the load order. Regardless, for pre-installed
overlays, the install time is randomly determined by the order in which
the Package Manager locates the packages during initial boot. To support
a well-defined order, pre-installed overlay packages are expected to
define an additional 'priority' attribute in their <overlay> tags:
<overlay targetPackage="com.target.package" priority="1234"/>
Pre-installed overlays are loaded in order of their priority attributes,
sorted in ascending order.
Assigning the same priority to several overlays targeting the same base
package leads to undefined behaviour. It is the responsibility of the
vendor to avoid this.
The following example shows the ResTable and PackageGroups after loading
an application and two overlays. The resource lookup framework will
query the packages in the order C, B, A.
+------+------+- -+------+------+
| 0x01 | | ... | | 0x7f |
+------+------+- -+------+------+
| |
"android" Target package A
|
Pre-installed overlay B (priority 1)
|
Pre-installed overlay C (priority 2)
Change-Id: If49c963149369b1957f7d2303b3dd27f669ed24e
2014-01-31 13:42:59 +00:00
|
|
|
{
|
2015-01-19 16:19:29 +00:00
|
|
|
if (idmap_path == NULL) return -1;
|
2014-11-25 20:04:16 +00:00
|
|
|
|
Runtime resource overlay, iteration 2
Support any number of overlay packages. Support any target package.
UPDATED PACKAGE MATCHING
------------------------
In Runtime resource overlay, iteration 1, only a single overlay package
was considered. Package matching was based on file paths:
/vendor/overlay/system/framework-res.apk corresponded to
/system/framework-res.apk. Introduce a more flexible matching scheme
where any package is an overlay package if its manifest includes
<overlay targetPackage="com.target.package"/>
For security reasons, an overlay package must fulfill certain criteria
to take effect: see below.
THE IDMAP TOOL AND IDMAP FILES
------------------------------
Idmap files are created by the 'idmap' binary; idmap files must be
present when loading packages. For the Android system, Zygote calls
'idmap' as part of the resource pre-loading. For application packages,
'idmap' is invoked via 'installd' during package installation (similar
to 'dexopt').
UPDATED FLOW
------------
The following is an outline of the start-up sequences for the Android
system and Android apps. Steps marked with '+' are introduced by this
commit.
Zygote initialization
Initial AssetManager object created
+ idmap --scan creates idmaps for overlays targeting 'android', \
stores list of overlays in /data/resource-cache/overlays.list
AssetManager caches framework-res.apk
+ AssetManager caches overlay packages listed in overlays.list
Android boot
New AssetManager's ResTable acquired
AssetManager re-uses cached framework-res.apk
+ AssetManager re-uses cached 'android' overlays (if any)
App boot
ActivityThread prepares AssetManager to load app.apk
+ ActivityThread prepares AssetManager to load app overlays (if any)
New AssetManager's ResTable acquired as per Android boot
SECURITY
--------
Overlay packages are required to be pre-loaded (in /vendor/overlay).
These packages are trusted by definition. A future iteration of runtime
resource overlay may add support for downloaded overlays, which would
likely require target and overlay signatures match for the overlay to
be trusted.
LOOKUP PRIORITY
---------------
During resource lookup, packages are sequentially queried to provide a
best match, given the constraints of the current configuration. If any
package provide a better match than what has been found so far, it
replaces the previous match. The target package is always queried last.
When loading a package with more than one overlay, the order in which
the overlays are added become significant if several packages overlay
the same resource.
Had downloaded overlays been supported, the install time could have been
used to determine the load order. Regardless, for pre-installed
overlays, the install time is randomly determined by the order in which
the Package Manager locates the packages during initial boot. To support
a well-defined order, pre-installed overlay packages are expected to
define an additional 'priority' attribute in their <overlay> tags:
<overlay targetPackage="com.target.package" priority="1234"/>
Pre-installed overlays are loaded in order of their priority attributes,
sorted in ascending order.
Assigning the same priority to several overlays targeting the same base
package leads to undefined behaviour. It is the responsibility of the
vendor to avoid this.
The following example shows the ResTable and PackageGroups after loading
an application and two overlays. The resource lookup framework will
query the packages in the order C, B, A.
+------+------+- -+------+------+
| 0x01 | | ... | | 0x7f |
+------+------+- -+------+------+
| |
"android" Target package A
|
Pre-installed overlay B (priority 1)
|
Pre-installed overlay C (priority 2)
Change-Id: If49c963149369b1957f7d2303b3dd27f669ed24e
2014-01-31 13:42:59 +00:00
|
|
|
memset(idmap_path, 0, N);
|
2015-01-19 16:19:29 +00:00
|
|
|
int len = snprintf(idmap_path, N, "%s/%s", prefix, suffix);
|
2014-11-25 20:04:16 +00:00
|
|
|
if (len < 0 || (size_t)len >= N) {
|
|
|
|
return -1; // error or truncated
|
|
|
|
}
|
Runtime resource overlay, iteration 2
Support any number of overlay packages. Support any target package.
UPDATED PACKAGE MATCHING
------------------------
In Runtime resource overlay, iteration 1, only a single overlay package
was considered. Package matching was based on file paths:
/vendor/overlay/system/framework-res.apk corresponded to
/system/framework-res.apk. Introduce a more flexible matching scheme
where any package is an overlay package if its manifest includes
<overlay targetPackage="com.target.package"/>
For security reasons, an overlay package must fulfill certain criteria
to take effect: see below.
THE IDMAP TOOL AND IDMAP FILES
------------------------------
Idmap files are created by the 'idmap' binary; idmap files must be
present when loading packages. For the Android system, Zygote calls
'idmap' as part of the resource pre-loading. For application packages,
'idmap' is invoked via 'installd' during package installation (similar
to 'dexopt').
UPDATED FLOW
------------
The following is an outline of the start-up sequences for the Android
system and Android apps. Steps marked with '+' are introduced by this
commit.
Zygote initialization
Initial AssetManager object created
+ idmap --scan creates idmaps for overlays targeting 'android', \
stores list of overlays in /data/resource-cache/overlays.list
AssetManager caches framework-res.apk
+ AssetManager caches overlay packages listed in overlays.list
Android boot
New AssetManager's ResTable acquired
AssetManager re-uses cached framework-res.apk
+ AssetManager re-uses cached 'android' overlays (if any)
App boot
ActivityThread prepares AssetManager to load app.apk
+ ActivityThread prepares AssetManager to load app overlays (if any)
New AssetManager's ResTable acquired as per Android boot
SECURITY
--------
Overlay packages are required to be pre-loaded (in /vendor/overlay).
These packages are trusted by definition. A future iteration of runtime
resource overlay may add support for downloaded overlays, which would
likely require target and overlay signatures match for the overlay to
be trusted.
LOOKUP PRIORITY
---------------
During resource lookup, packages are sequentially queried to provide a
best match, given the constraints of the current configuration. If any
package provide a better match than what has been found so far, it
replaces the previous match. The target package is always queried last.
When loading a package with more than one overlay, the order in which
the overlays are added become significant if several packages overlay
the same resource.
Had downloaded overlays been supported, the install time could have been
used to determine the load order. Regardless, for pre-installed
overlays, the install time is randomly determined by the order in which
the Package Manager locates the packages during initial boot. To support
a well-defined order, pre-installed overlay packages are expected to
define an additional 'priority' attribute in their <overlay> tags:
<overlay targetPackage="com.target.package" priority="1234"/>
Pre-installed overlays are loaded in order of their priority attributes,
sorted in ascending order.
Assigning the same priority to several overlays targeting the same base
package leads to undefined behaviour. It is the responsibility of the
vendor to avoid this.
The following example shows the ResTable and PackageGroups after loading
an application and two overlays. The resource lookup framework will
query the packages in the order C, B, A.
+------+------+- -+------+------+
| 0x01 | | ... | | 0x7f |
+------+------+- -+------+------+
| |
"android" Target package A
|
Pre-installed overlay B (priority 1)
|
Pre-installed overlay C (priority 2)
Change-Id: If49c963149369b1957f7d2303b3dd27f669ed24e
2014-01-31 13:42:59 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-01-19 16:19:29 +00:00
|
|
|
int idmap(const char *target_apk, const char *overlay_apk, const char *cache_path,
|
|
|
|
uid_t uid, uint32_t target_hash, uint32_t overlay_hash)
|
Runtime resource overlay, iteration 2
Support any number of overlay packages. Support any target package.
UPDATED PACKAGE MATCHING
------------------------
In Runtime resource overlay, iteration 1, only a single overlay package
was considered. Package matching was based on file paths:
/vendor/overlay/system/framework-res.apk corresponded to
/system/framework-res.apk. Introduce a more flexible matching scheme
where any package is an overlay package if its manifest includes
<overlay targetPackage="com.target.package"/>
For security reasons, an overlay package must fulfill certain criteria
to take effect: see below.
THE IDMAP TOOL AND IDMAP FILES
------------------------------
Idmap files are created by the 'idmap' binary; idmap files must be
present when loading packages. For the Android system, Zygote calls
'idmap' as part of the resource pre-loading. For application packages,
'idmap' is invoked via 'installd' during package installation (similar
to 'dexopt').
UPDATED FLOW
------------
The following is an outline of the start-up sequences for the Android
system and Android apps. Steps marked with '+' are introduced by this
commit.
Zygote initialization
Initial AssetManager object created
+ idmap --scan creates idmaps for overlays targeting 'android', \
stores list of overlays in /data/resource-cache/overlays.list
AssetManager caches framework-res.apk
+ AssetManager caches overlay packages listed in overlays.list
Android boot
New AssetManager's ResTable acquired
AssetManager re-uses cached framework-res.apk
+ AssetManager re-uses cached 'android' overlays (if any)
App boot
ActivityThread prepares AssetManager to load app.apk
+ ActivityThread prepares AssetManager to load app overlays (if any)
New AssetManager's ResTable acquired as per Android boot
SECURITY
--------
Overlay packages are required to be pre-loaded (in /vendor/overlay).
These packages are trusted by definition. A future iteration of runtime
resource overlay may add support for downloaded overlays, which would
likely require target and overlay signatures match for the overlay to
be trusted.
LOOKUP PRIORITY
---------------
During resource lookup, packages are sequentially queried to provide a
best match, given the constraints of the current configuration. If any
package provide a better match than what has been found so far, it
replaces the previous match. The target package is always queried last.
When loading a package with more than one overlay, the order in which
the overlays are added become significant if several packages overlay
the same resource.
Had downloaded overlays been supported, the install time could have been
used to determine the load order. Regardless, for pre-installed
overlays, the install time is randomly determined by the order in which
the Package Manager locates the packages during initial boot. To support
a well-defined order, pre-installed overlay packages are expected to
define an additional 'priority' attribute in their <overlay> tags:
<overlay targetPackage="com.target.package" priority="1234"/>
Pre-installed overlays are loaded in order of their priority attributes,
sorted in ascending order.
Assigning the same priority to several overlays targeting the same base
package leads to undefined behaviour. It is the responsibility of the
vendor to avoid this.
The following example shows the ResTable and PackageGroups after loading
an application and two overlays. The resource lookup framework will
query the packages in the order C, B, A.
+------+------+- -+------+------+
| 0x01 | | ... | | 0x7f |
+------+------+- -+------+------+
| |
"android" Target package A
|
Pre-installed overlay B (priority 1)
|
Pre-installed overlay C (priority 2)
Change-Id: If49c963149369b1957f7d2303b3dd27f669ed24e
2014-01-31 13:42:59 +00:00
|
|
|
{
|
2015-01-19 16:19:29 +00:00
|
|
|
ALOGD("idmap target_apk=%s overlay_apk=%s cache_path=%s uid=%d\n", target_apk, overlay_apk,
|
|
|
|
cache_path, uid);
|
Runtime resource overlay, iteration 2
Support any number of overlay packages. Support any target package.
UPDATED PACKAGE MATCHING
------------------------
In Runtime resource overlay, iteration 1, only a single overlay package
was considered. Package matching was based on file paths:
/vendor/overlay/system/framework-res.apk corresponded to
/system/framework-res.apk. Introduce a more flexible matching scheme
where any package is an overlay package if its manifest includes
<overlay targetPackage="com.target.package"/>
For security reasons, an overlay package must fulfill certain criteria
to take effect: see below.
THE IDMAP TOOL AND IDMAP FILES
------------------------------
Idmap files are created by the 'idmap' binary; idmap files must be
present when loading packages. For the Android system, Zygote calls
'idmap' as part of the resource pre-loading. For application packages,
'idmap' is invoked via 'installd' during package installation (similar
to 'dexopt').
UPDATED FLOW
------------
The following is an outline of the start-up sequences for the Android
system and Android apps. Steps marked with '+' are introduced by this
commit.
Zygote initialization
Initial AssetManager object created
+ idmap --scan creates idmaps for overlays targeting 'android', \
stores list of overlays in /data/resource-cache/overlays.list
AssetManager caches framework-res.apk
+ AssetManager caches overlay packages listed in overlays.list
Android boot
New AssetManager's ResTable acquired
AssetManager re-uses cached framework-res.apk
+ AssetManager re-uses cached 'android' overlays (if any)
App boot
ActivityThread prepares AssetManager to load app.apk
+ ActivityThread prepares AssetManager to load app overlays (if any)
New AssetManager's ResTable acquired as per Android boot
SECURITY
--------
Overlay packages are required to be pre-loaded (in /vendor/overlay).
These packages are trusted by definition. A future iteration of runtime
resource overlay may add support for downloaded overlays, which would
likely require target and overlay signatures match for the overlay to
be trusted.
LOOKUP PRIORITY
---------------
During resource lookup, packages are sequentially queried to provide a
best match, given the constraints of the current configuration. If any
package provide a better match than what has been found so far, it
replaces the previous match. The target package is always queried last.
When loading a package with more than one overlay, the order in which
the overlays are added become significant if several packages overlay
the same resource.
Had downloaded overlays been supported, the install time could have been
used to determine the load order. Regardless, for pre-installed
overlays, the install time is randomly determined by the order in which
the Package Manager locates the packages during initial boot. To support
a well-defined order, pre-installed overlay packages are expected to
define an additional 'priority' attribute in their <overlay> tags:
<overlay targetPackage="com.target.package" priority="1234"/>
Pre-installed overlays are loaded in order of their priority attributes,
sorted in ascending order.
Assigning the same priority to several overlays targeting the same base
package leads to undefined behaviour. It is the responsibility of the
vendor to avoid this.
The following example shows the ResTable and PackageGroups after loading
an application and two overlays. The resource lookup framework will
query the packages in the order C, B, A.
+------+------+- -+------+------+
| 0x01 | | ... | | 0x7f |
+------+------+- -+------+------+
| |
"android" Target package A
|
Pre-installed overlay B (priority 1)
|
Pre-installed overlay C (priority 2)
Change-Id: If49c963149369b1957f7d2303b3dd27f669ed24e
2014-01-31 13:42:59 +00:00
|
|
|
|
|
|
|
int idmap_fd = -1;
|
|
|
|
char idmap_path[PATH_MAX];
|
|
|
|
|
2015-01-19 16:19:29 +00:00
|
|
|
if (get_idmap_path(cache_path, IDMAP_SUFFIX, idmap_path, sizeof(idmap_path)) == -1) {
|
Runtime resource overlay, iteration 2
Support any number of overlay packages. Support any target package.
UPDATED PACKAGE MATCHING
------------------------
In Runtime resource overlay, iteration 1, only a single overlay package
was considered. Package matching was based on file paths:
/vendor/overlay/system/framework-res.apk corresponded to
/system/framework-res.apk. Introduce a more flexible matching scheme
where any package is an overlay package if its manifest includes
<overlay targetPackage="com.target.package"/>
For security reasons, an overlay package must fulfill certain criteria
to take effect: see below.
THE IDMAP TOOL AND IDMAP FILES
------------------------------
Idmap files are created by the 'idmap' binary; idmap files must be
present when loading packages. For the Android system, Zygote calls
'idmap' as part of the resource pre-loading. For application packages,
'idmap' is invoked via 'installd' during package installation (similar
to 'dexopt').
UPDATED FLOW
------------
The following is an outline of the start-up sequences for the Android
system and Android apps. Steps marked with '+' are introduced by this
commit.
Zygote initialization
Initial AssetManager object created
+ idmap --scan creates idmaps for overlays targeting 'android', \
stores list of overlays in /data/resource-cache/overlays.list
AssetManager caches framework-res.apk
+ AssetManager caches overlay packages listed in overlays.list
Android boot
New AssetManager's ResTable acquired
AssetManager re-uses cached framework-res.apk
+ AssetManager re-uses cached 'android' overlays (if any)
App boot
ActivityThread prepares AssetManager to load app.apk
+ ActivityThread prepares AssetManager to load app overlays (if any)
New AssetManager's ResTable acquired as per Android boot
SECURITY
--------
Overlay packages are required to be pre-loaded (in /vendor/overlay).
These packages are trusted by definition. A future iteration of runtime
resource overlay may add support for downloaded overlays, which would
likely require target and overlay signatures match for the overlay to
be trusted.
LOOKUP PRIORITY
---------------
During resource lookup, packages are sequentially queried to provide a
best match, given the constraints of the current configuration. If any
package provide a better match than what has been found so far, it
replaces the previous match. The target package is always queried last.
When loading a package with more than one overlay, the order in which
the overlays are added become significant if several packages overlay
the same resource.
Had downloaded overlays been supported, the install time could have been
used to determine the load order. Regardless, for pre-installed
overlays, the install time is randomly determined by the order in which
the Package Manager locates the packages during initial boot. To support
a well-defined order, pre-installed overlay packages are expected to
define an additional 'priority' attribute in their <overlay> tags:
<overlay targetPackage="com.target.package" priority="1234"/>
Pre-installed overlays are loaded in order of their priority attributes,
sorted in ascending order.
Assigning the same priority to several overlays targeting the same base
package leads to undefined behaviour. It is the responsibility of the
vendor to avoid this.
The following example shows the ResTable and PackageGroups after loading
an application and two overlays. The resource lookup framework will
query the packages in the order C, B, A.
+------+------+- -+------+------+
| 0x01 | | ... | | 0x7f |
+------+------+- -+------+------+
| |
"android" Target package A
|
Pre-installed overlay B (priority 1)
|
Pre-installed overlay C (priority 2)
Change-Id: If49c963149369b1957f7d2303b3dd27f669ed24e
2014-01-31 13:42:59 +00:00
|
|
|
ALOGE("idmap cannot generate idmap path for overlay %s\n", overlay_apk);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
unlink(idmap_path);
|
|
|
|
idmap_fd = open(idmap_path, O_RDWR | O_CREAT | O_EXCL, 0644);
|
|
|
|
if (idmap_fd < 0) {
|
|
|
|
ALOGE("idmap cannot open '%s' for output: %s\n", idmap_path, strerror(errno));
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
if (fchown(idmap_fd, AID_SYSTEM, uid) < 0) {
|
|
|
|
ALOGE("idmap cannot chown '%s'\n", idmap_path);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
if (fchmod(idmap_fd, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) < 0) {
|
|
|
|
ALOGE("idmap cannot chmod '%s'\n", idmap_path);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
pid_t pid;
|
|
|
|
pid = fork();
|
|
|
|
if (pid == 0) {
|
|
|
|
/* child -- drop privileges before continuing */
|
|
|
|
if (setgid(uid) != 0) {
|
|
|
|
ALOGE("setgid(%d) failed during idmap\n", uid);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (setuid(uid) != 0) {
|
|
|
|
ALOGE("setuid(%d) failed during idmap\n", uid);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (flock(idmap_fd, LOCK_EX | LOCK_NB) != 0) {
|
|
|
|
ALOGE("flock(%s) failed during idmap: %s\n", idmap_path, strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2015-01-19 16:19:29 +00:00
|
|
|
run_idmap(target_apk, overlay_apk, cache_path, idmap_fd, target_hash, overlay_hash);
|
Runtime resource overlay, iteration 2
Support any number of overlay packages. Support any target package.
UPDATED PACKAGE MATCHING
------------------------
In Runtime resource overlay, iteration 1, only a single overlay package
was considered. Package matching was based on file paths:
/vendor/overlay/system/framework-res.apk corresponded to
/system/framework-res.apk. Introduce a more flexible matching scheme
where any package is an overlay package if its manifest includes
<overlay targetPackage="com.target.package"/>
For security reasons, an overlay package must fulfill certain criteria
to take effect: see below.
THE IDMAP TOOL AND IDMAP FILES
------------------------------
Idmap files are created by the 'idmap' binary; idmap files must be
present when loading packages. For the Android system, Zygote calls
'idmap' as part of the resource pre-loading. For application packages,
'idmap' is invoked via 'installd' during package installation (similar
to 'dexopt').
UPDATED FLOW
------------
The following is an outline of the start-up sequences for the Android
system and Android apps. Steps marked with '+' are introduced by this
commit.
Zygote initialization
Initial AssetManager object created
+ idmap --scan creates idmaps for overlays targeting 'android', \
stores list of overlays in /data/resource-cache/overlays.list
AssetManager caches framework-res.apk
+ AssetManager caches overlay packages listed in overlays.list
Android boot
New AssetManager's ResTable acquired
AssetManager re-uses cached framework-res.apk
+ AssetManager re-uses cached 'android' overlays (if any)
App boot
ActivityThread prepares AssetManager to load app.apk
+ ActivityThread prepares AssetManager to load app overlays (if any)
New AssetManager's ResTable acquired as per Android boot
SECURITY
--------
Overlay packages are required to be pre-loaded (in /vendor/overlay).
These packages are trusted by definition. A future iteration of runtime
resource overlay may add support for downloaded overlays, which would
likely require target and overlay signatures match for the overlay to
be trusted.
LOOKUP PRIORITY
---------------
During resource lookup, packages are sequentially queried to provide a
best match, given the constraints of the current configuration. If any
package provide a better match than what has been found so far, it
replaces the previous match. The target package is always queried last.
When loading a package with more than one overlay, the order in which
the overlays are added become significant if several packages overlay
the same resource.
Had downloaded overlays been supported, the install time could have been
used to determine the load order. Regardless, for pre-installed
overlays, the install time is randomly determined by the order in which
the Package Manager locates the packages during initial boot. To support
a well-defined order, pre-installed overlay packages are expected to
define an additional 'priority' attribute in their <overlay> tags:
<overlay targetPackage="com.target.package" priority="1234"/>
Pre-installed overlays are loaded in order of their priority attributes,
sorted in ascending order.
Assigning the same priority to several overlays targeting the same base
package leads to undefined behaviour. It is the responsibility of the
vendor to avoid this.
The following example shows the ResTable and PackageGroups after loading
an application and two overlays. The resource lookup framework will
query the packages in the order C, B, A.
+------+------+- -+------+------+
| 0x01 | | ... | | 0x7f |
+------+------+- -+------+------+
| |
"android" Target package A
|
Pre-installed overlay B (priority 1)
|
Pre-installed overlay C (priority 2)
Change-Id: If49c963149369b1957f7d2303b3dd27f669ed24e
2014-01-31 13:42:59 +00:00
|
|
|
exit(1); /* only if exec call to idmap failed */
|
|
|
|
} else {
|
|
|
|
int status = wait_child(pid);
|
|
|
|
if (status != 0) {
|
|
|
|
ALOGE("idmap failed, status=0x%04x\n", status);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
close(idmap_fd);
|
|
|
|
return 0;
|
|
|
|
fail:
|
|
|
|
if (idmap_fd >= 0) {
|
|
|
|
close(idmap_fd);
|
|
|
|
unlink(idmap_path);
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2014-02-20 15:25:56 +00:00
|
|
|
|
2014-11-25 20:04:16 +00:00
|
|
|
static void run_aapt(const char *source_apk, const char *internal_path,
|
|
|
|
int resapk_fd, int pkgId, int min_sdk_version, const char *common_res_path)
|
|
|
|
{
|
|
|
|
static const char *AAPT_BIN = "/system/bin/aapt";
|
|
|
|
static const char *MANIFEST = "/data/app/AndroidManifest.xml";
|
|
|
|
static const char *FRAMEWORK_RES = "/system/framework/framework-res.apk";
|
|
|
|
|
|
|
|
static const size_t MAX_INT_LEN = 32;
|
|
|
|
char resapk_str[MAX_INT_LEN];
|
|
|
|
char pkgId_str[MAX_INT_LEN];
|
|
|
|
char minSdkVersion_str[MAX_INT_LEN];
|
|
|
|
|
|
|
|
snprintf(resapk_str, sizeof(resapk_str), "%d", resapk_fd);
|
|
|
|
snprintf(pkgId_str, sizeof(pkgId_str), "%d", pkgId);
|
|
|
|
snprintf(minSdkVersion_str, sizeof(minSdkVersion_str), "%d", min_sdk_version);
|
|
|
|
bool hasCommonResources = (common_res_path != NULL && common_res_path[0] != '\0');
|
|
|
|
|
|
|
|
if (hasCommonResources) {
|
|
|
|
execl(AAPT_BIN, AAPT_BIN, "package",
|
|
|
|
"--min-sdk-version", minSdkVersion_str,
|
|
|
|
"-M", MANIFEST,
|
|
|
|
"-S", source_apk,
|
|
|
|
"-X", internal_path,
|
|
|
|
"-I", FRAMEWORK_RES,
|
|
|
|
"-I", common_res_path,
|
|
|
|
"-r", resapk_str,
|
|
|
|
"-x", pkgId_str,
|
2015-10-28 21:11:01 +00:00
|
|
|
"-f",
|
2014-11-25 20:04:16 +00:00
|
|
|
(char*)NULL);
|
|
|
|
} else {
|
|
|
|
execl(AAPT_BIN, AAPT_BIN, "package",
|
|
|
|
"--min-sdk-version", minSdkVersion_str,
|
|
|
|
"-M", MANIFEST,
|
|
|
|
"-S", source_apk,
|
|
|
|
"-X", internal_path,
|
|
|
|
"-I", FRAMEWORK_RES,
|
|
|
|
"-r", resapk_str,
|
|
|
|
"-x", pkgId_str,
|
2015-10-28 21:11:01 +00:00
|
|
|
"-f",
|
2014-11-25 20:04:16 +00:00
|
|
|
(char*)NULL);
|
|
|
|
}
|
|
|
|
ALOGE("execl(%s) failed: %s\n", AAPT_BIN, strerror(errno));
|
|
|
|
}
|
|
|
|
|
|
|
|
int aapt(const char *source_apk, const char *internal_path, const char *out_restable, uid_t uid,
|
|
|
|
int pkgId, int min_sdk_version, const char *common_res_path)
|
|
|
|
{
|
2015-10-29 01:35:09 +00:00
|
|
|
ALOGD("aapt source_apk=%s internal_path=%s out_restable=%s uid=%d, pkgId=%d,min_sdk_version=%d, common_res_path=%s",
|
2014-11-25 20:04:16 +00:00
|
|
|
source_apk, internal_path, out_restable, uid, pkgId, min_sdk_version, common_res_path);
|
|
|
|
static const int PARENT_READ_PIPE = 0;
|
|
|
|
static const int CHILD_WRITE_PIPE = 1;
|
|
|
|
|
|
|
|
int resapk_fd = -1;
|
|
|
|
char restable_path[PATH_MAX];
|
|
|
|
char resapk_path[PATH_MAX];
|
|
|
|
|
2015-10-29 01:35:09 +00:00
|
|
|
// create pipes for redirecting STDERR to a buffer that can be displayed in logcat
|
2014-11-25 20:04:16 +00:00
|
|
|
int pipefd[2];
|
2015-10-29 01:35:09 +00:00
|
|
|
if (pipe(pipefd) != 0) {
|
|
|
|
pipefd[0] = pipefd[1] = -1;
|
|
|
|
}
|
|
|
|
|
2014-11-25 20:04:16 +00:00
|
|
|
pid_t pid = fork();
|
|
|
|
|
|
|
|
if (pid == 0) {
|
2015-10-30 18:36:57 +00:00
|
|
|
// get file descriptor for resources.arsc
|
|
|
|
snprintf(restable_path, PATH_MAX, "%s/resources.arsc", out_restable);
|
|
|
|
unlink(restable_path);
|
|
|
|
|
|
|
|
// get file descriptor for resources.apk
|
|
|
|
snprintf(resapk_path, PATH_MAX, "%s/resources.apk", out_restable);
|
|
|
|
unlink(resapk_path);
|
|
|
|
resapk_fd = open(resapk_path, O_RDWR | O_CREAT | O_EXCL, 0644);
|
|
|
|
if (resapk_fd < 0) {
|
|
|
|
ALOGE("aapt cannot open '%s' for output: %s\n", resapk_path, strerror(errno));
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
if (fchown(resapk_fd, AID_SYSTEM, uid) < 0) {
|
|
|
|
ALOGE("aapt cannot chown '%s'\n", resapk_path);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
if (fchmod(resapk_fd, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) < 0) {
|
|
|
|
ALOGE("aapt cannot chmod '%s'\n", resapk_path);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2014-11-25 20:04:16 +00:00
|
|
|
/* child -- drop privileges before continuing */
|
|
|
|
if (setgid(uid) != 0) {
|
|
|
|
ALOGE("setgid(%d) failed during aapt\n", uid);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (setuid(uid) != 0) {
|
|
|
|
ALOGE("setuid(%d) failed during aapt\n", uid);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flock(resapk_fd, LOCK_EX | LOCK_NB) != 0) {
|
|
|
|
ALOGE("flock(%s) failed during aapt: %s\n", out_restable, strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pipefd[PARENT_READ_PIPE] > 0 && pipefd[CHILD_WRITE_PIPE] > 0) {
|
|
|
|
close(pipefd[PARENT_READ_PIPE]); // close unused read end
|
|
|
|
if (dup2(pipefd[CHILD_WRITE_PIPE], STDERR_FILENO) != STDERR_FILENO) {
|
|
|
|
pipefd[CHILD_WRITE_PIPE] = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
run_aapt(source_apk, internal_path, resapk_fd, pkgId, min_sdk_version, common_res_path);
|
|
|
|
|
2015-10-30 18:36:57 +00:00
|
|
|
close(resapk_fd);
|
2014-11-25 20:04:16 +00:00
|
|
|
if (pipefd[CHILD_WRITE_PIPE] > 0) {
|
|
|
|
close(pipefd[CHILD_WRITE_PIPE]);
|
|
|
|
}
|
|
|
|
exit(1); /* only if exec call to idmap failed */
|
|
|
|
} else {
|
|
|
|
int status, i;
|
|
|
|
char buffer[1024];
|
|
|
|
ssize_t readlen;
|
|
|
|
|
|
|
|
if (pipefd[CHILD_WRITE_PIPE] > 0) {
|
|
|
|
close(pipefd[CHILD_WRITE_PIPE]); // close unused write end
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pipefd[PARENT_READ_PIPE] > 0) {
|
|
|
|
while ((readlen = read(pipefd[PARENT_READ_PIPE], buffer, sizeof(buffer) - 1)) > 0) {
|
|
|
|
// in case buffer has more than one string in it, replace '\0' with '\n'
|
|
|
|
for (i = 0; i < readlen; i++) {
|
|
|
|
if (buffer[i] == '\0') buffer[i] = '\n';
|
|
|
|
}
|
|
|
|
// null terminate buffer at readlen
|
|
|
|
buffer[readlen] = '\0';
|
|
|
|
ALOG(LOG_ERROR, "InstallTheme", "%s", buffer);
|
|
|
|
}
|
|
|
|
waitpid(pid, &status, 0);
|
|
|
|
|
|
|
|
if (pipefd[PARENT_READ_PIPE] > 0) {
|
|
|
|
close(pipefd[PARENT_READ_PIPE]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
status = wait_child(pid);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status != 0) {
|
|
|
|
ALOGE("aapt failed, status=0x%04x\n", status);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
fail:
|
|
|
|
if (resapk_fd >= 0) {
|
|
|
|
close(resapk_fd);
|
|
|
|
unlink(resapk_path);
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-04-09 20:10:03 +00:00
|
|
|
int restorecon_data(const char* uuid, const char* pkgName,
|
2015-04-09 16:52:45 +00:00
|
|
|
const char* seinfo, uid_t uid)
|
2014-02-20 15:25:56 +00:00
|
|
|
{
|
2014-03-27 14:21:12 +00:00
|
|
|
struct dirent *entry;
|
|
|
|
DIR *d;
|
|
|
|
struct stat s;
|
|
|
|
int ret = 0;
|
2014-02-20 15:25:56 +00:00
|
|
|
|
2014-03-27 14:21:12 +00:00
|
|
|
// SELINUX_ANDROID_RESTORECON_DATADATA flag is set by libselinux. Not needed here.
|
|
|
|
unsigned int flags = SELINUX_ANDROID_RESTORECON_RECURSE;
|
2014-02-20 15:25:56 +00:00
|
|
|
|
2014-03-27 14:21:12 +00:00
|
|
|
if (!pkgName || !seinfo) {
|
|
|
|
ALOGE("Package name or seinfo tag is null when trying to restorecon.");
|
|
|
|
return -1;
|
|
|
|
}
|
2014-02-20 15:25:56 +00:00
|
|
|
|
2015-04-09 18:34:03 +00:00
|
|
|
// Special case for owner on internal storage
|
|
|
|
if (uuid == nullptr) {
|
2015-04-30 22:58:19 +00:00
|
|
|
std::string path(create_data_user_package_path(nullptr, 0, pkgName));
|
2014-02-20 15:25:56 +00:00
|
|
|
|
2015-04-09 18:34:03 +00:00
|
|
|
if (selinux_android_restorecon_pkgdir(path.c_str(), seinfo, uid, flags) < 0) {
|
|
|
|
PLOG(ERROR) << "restorecon failed for " << path;
|
|
|
|
ret |= -1;
|
|
|
|
}
|
2014-02-20 15:25:56 +00:00
|
|
|
}
|
|
|
|
|
2014-03-27 14:21:12 +00:00
|
|
|
// Relabel package directory for all secondary users.
|
2015-04-09 18:34:03 +00:00
|
|
|
std::string userdir(create_data_path(uuid) + "/" + SECONDARY_USER_PREFIX);
|
|
|
|
d = opendir(userdir.c_str());
|
2014-03-27 14:21:12 +00:00
|
|
|
if (d == NULL) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((entry = readdir(d))) {
|
|
|
|
if (entry->d_type != DT_DIR) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *user = entry->d_name;
|
|
|
|
// Ignore "." and ".."
|
|
|
|
if (!strcmp(user, ".") || !strcmp(user, "..")) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// user directories start with a number
|
|
|
|
if (user[0] < '0' || user[0] > '9') {
|
|
|
|
ALOGE("Expecting numbered directory during restorecon. Instead got '%s'.", user);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-04-09 03:56:42 +00:00
|
|
|
std::string pkgdir(StringPrintf("%s%s/%s", userdir.c_str(), user, pkgName));
|
2015-04-09 18:34:03 +00:00
|
|
|
if (stat(pkgdir.c_str(), &s) < 0) {
|
2014-03-27 14:21:12 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-04-09 18:34:03 +00:00
|
|
|
if (selinux_android_restorecon_pkgdir(pkgdir.c_str(), seinfo, s.st_uid, flags) < 0) {
|
|
|
|
PLOG(ERROR) << "restorecon failed for " << pkgdir;
|
2014-03-27 14:21:12 +00:00
|
|
|
ret |= -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
closedir(d);
|
2014-02-20 15:25:56 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2014-06-10 12:16:47 +00:00
|
|
|
|
2015-03-03 20:25:29 +00:00
|
|
|
int create_oat_dir(const char* oat_dir, const char* instruction_set)
|
|
|
|
{
|
|
|
|
char oat_instr_dir[PKG_PATH_MAX];
|
|
|
|
|
|
|
|
if (validate_apk_path(oat_dir)) {
|
|
|
|
ALOGE("invalid apk path '%s' (bad prefix)\n", oat_dir);
|
|
|
|
return -1;
|
|
|
|
}
|
2015-04-07 02:09:02 +00:00
|
|
|
if (fs_prepare_dir(oat_dir, S_IRWXU | S_IRWXG | S_IXOTH, AID_SYSTEM, AID_INSTALL)) {
|
2015-03-03 20:25:29 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (selinux_android_restorecon(oat_dir, 0)) {
|
|
|
|
ALOGE("cannot restorecon dir '%s': %s\n", oat_dir, strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
snprintf(oat_instr_dir, PKG_PATH_MAX, "%s/%s", oat_dir, instruction_set);
|
2015-04-07 02:09:02 +00:00
|
|
|
if (fs_prepare_dir(oat_instr_dir, S_IRWXU | S_IRWXG | S_IXOTH, AID_SYSTEM, AID_INSTALL)) {
|
2015-03-03 20:25:29 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int rm_package_dir(const char* apk_path)
|
|
|
|
{
|
|
|
|
if (validate_apk_path(apk_path)) {
|
|
|
|
ALOGE("invalid apk path '%s' (bad prefix)\n", apk_path);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return delete_dir_contents(apk_path, 1 /* also_delete_dir */ , NULL /* exclusion_predicate */);
|
|
|
|
}
|
|
|
|
|
2015-06-04 12:20:27 +00:00
|
|
|
int link_file(const char* relative_path, const char* from_base, const char* to_base) {
|
|
|
|
char from_path[PKG_PATH_MAX];
|
|
|
|
char to_path[PKG_PATH_MAX];
|
|
|
|
snprintf(from_path, PKG_PATH_MAX, "%s/%s", from_base, relative_path);
|
|
|
|
snprintf(to_path, PKG_PATH_MAX, "%s/%s", to_base, relative_path);
|
|
|
|
|
|
|
|
if (validate_apk_path_subdirs(from_path)) {
|
|
|
|
ALOGE("invalid app data sub-path '%s' (bad prefix)\n", from_path);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (validate_apk_path_subdirs(to_path)) {
|
|
|
|
ALOGE("invalid app data sub-path '%s' (bad prefix)\n", to_path);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int ret = link(from_path, to_path);
|
|
|
|
if (ret < 0) {
|
|
|
|
ALOGE("link(%s, %s) failed : %s", from_path, to_path, strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-03 20:25:29 +00:00
|
|
|
int calculate_oat_file_path(char path[PKG_PATH_MAX], const char *oat_dir, const char *apk_path,
|
|
|
|
const char *instruction_set) {
|
|
|
|
char *file_name_start;
|
|
|
|
char *file_name_end;
|
|
|
|
|
|
|
|
file_name_start = strrchr(apk_path, '/');
|
|
|
|
if (file_name_start == NULL) {
|
|
|
|
ALOGE("apk_path '%s' has no '/'s in it\n", apk_path);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
file_name_end = strrchr(apk_path, '.');
|
|
|
|
if (file_name_end < file_name_start) {
|
|
|
|
ALOGE("apk_path '%s' has no extension\n", apk_path);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate file_name
|
|
|
|
int file_name_len = file_name_end - file_name_start - 1;
|
|
|
|
char file_name[file_name_len + 1];
|
|
|
|
memcpy(file_name, file_name_start + 1, file_name_len);
|
|
|
|
file_name[file_name_len] = '\0';
|
|
|
|
|
|
|
|
// <apk_parent_dir>/oat/<isa>/<file_name>.odex
|
|
|
|
snprintf(path, PKG_PATH_MAX, "%s/%s/%s.odex", oat_dir, instruction_set, file_name);
|
|
|
|
return 0;
|
|
|
|
}
|