Merge "dexopt: Replace -Xhidden-api-checks with -Xhidden-api-policy" into qt-dev
am: a6962908b9
Change-Id: I24099a013c9333e2c52c1e3e76ce10a6632e026c
diff --git a/cmds/dumpstate/DumpstateService.cpp b/cmds/dumpstate/DumpstateService.cpp
index ddae9ea..37ba4f9 100644
--- a/cmds/dumpstate/DumpstateService.cpp
+++ b/cmds/dumpstate/DumpstateService.cpp
@@ -151,15 +151,15 @@
signalErrorAndExit(listener, IDumpstateListener::BUGREPORT_ERROR_INVALID_INPUT);
}
- if (bugreport_fd.get() == -1 || screenshot_fd.get() == -1) {
- // TODO(b/111441001): screenshot fd should be optional
+ std::unique_ptr<Dumpstate::DumpOptions> options = std::make_unique<Dumpstate::DumpOptions>();
+ options->Initialize(static_cast<Dumpstate::BugreportMode>(bugreport_mode), bugreport_fd,
+ screenshot_fd);
+
+ if (bugreport_fd.get() == -1 || (options->do_fb && screenshot_fd.get() == -1)) {
MYLOGE("Invalid filedescriptor");
signalErrorAndExit(listener, IDumpstateListener::BUGREPORT_ERROR_INVALID_INPUT);
}
- std::unique_ptr<Dumpstate::DumpOptions> options = std::make_unique<Dumpstate::DumpOptions>();
- options->Initialize(static_cast<Dumpstate::BugreportMode>(bugreport_mode), bugreport_fd,
- screenshot_fd);
ds_ = &(Dumpstate::GetInstance());
ds_->SetOptions(std::move(options));
diff --git a/cmds/dumpstate/binder/android/os/IDumpstate.aidl b/cmds/dumpstate/binder/android/os/IDumpstate.aidl
index 347856d..cb2d8b8 100644
--- a/cmds/dumpstate/binder/android/os/IDumpstate.aidl
+++ b/cmds/dumpstate/binder/android/os/IDumpstate.aidl
@@ -73,7 +73,7 @@
* @param callingUid UID of the original application that requested the report.
* @param callingPackage package of the original application that requested the report.
* @param bugreportFd the file to which the zipped bugreport should be written
- * @param screenshotFd the file to which screenshot should be written; optional
+ * @param screenshotFd the file to which screenshot should be written
* @param bugreportMode the mode that specifies other run time options; must be one of above
* @param listener callback for updates; optional
*/
diff --git a/cmds/dumpstate/tests/dumpstate_test.cpp b/cmds/dumpstate/tests/dumpstate_test.cpp
index e6a7735..71d15f4 100644
--- a/cmds/dumpstate/tests/dumpstate_test.cpp
+++ b/cmds/dumpstate/tests/dumpstate_test.cpp
@@ -666,8 +666,7 @@
EXPECT_THAT(err, StrEq("stderr\n"));
// We don't know the exact duration, so we check the prefix and suffix
EXPECT_THAT(out,
- StartsWith("------ I AM GROOT (" + kSimpleCommand + ") ------\nstdout\n------"));
- EXPECT_THAT(out, EndsWith("s was the duration of 'I AM GROOT' ------\n"));
+ StartsWith("------ I AM GROOT (" + kSimpleCommand + ") ------\nstdout\n"));
}
TEST_F(DumpstateTest, RunCommandWithLoggingMessage) {
@@ -702,8 +701,7 @@
EXPECT_EQ(0, RunCommand("I AM GROOT", {kSimpleCommand}));
// We don't know the exact duration, so we check the prefix and suffix
EXPECT_THAT(out, StartsWith("------ I AM GROOT (" + kSimpleCommand +
- ") ------\n\t(skipped on dry run)\n------"));
- EXPECT_THAT(out, EndsWith("s was the duration of 'I AM GROOT' ------\n"));
+ ") ------\n\t(skipped on dry run)\n"));
EXPECT_THAT(err, IsEmpty());
}
@@ -1042,7 +1040,6 @@
// We don't know the exact duration, so we check the prefix and suffix
EXPECT_THAT(out, StartsWith("*** Error dumping /I/cant/believe/I/exist (Y U NO EXIST?): No "
"such file or directory\n"));
- EXPECT_THAT(out, EndsWith("s was the duration of 'Y U NO EXIST?' ------\n"));
}
TEST_F(DumpstateTest, DumpFileSingleLine) {
@@ -1082,8 +1079,7 @@
EXPECT_THAT(err, IsEmpty());
EXPECT_THAT(
out, StartsWith("------ Might as well dump. Dump! (" + kTestDataPath + "single-line.txt:"));
- EXPECT_THAT(out, HasSubstr("\n\t(skipped on dry run)\n------"));
- EXPECT_THAT(out, EndsWith("s was the duration of 'Might as well dump. Dump!' ------\n"));
+ EXPECT_THAT(out, HasSubstr("\n\t(skipped on dry run)\n"));
}
TEST_F(DumpstateTest, DumpFileUpdateProgress) {
diff --git a/cmds/installd/dexopt.cpp b/cmds/installd/dexopt.cpp
index dbb4f22..7eee749 100644
--- a/cmds/installd/dexopt.cpp
+++ b/cmds/installd/dexopt.cpp
@@ -2117,14 +2117,20 @@
// Create a swap file if necessary.
unique_fd swap_fd = maybe_open_dexopt_swap_file(out_oat_path);
- // Create the app image file if needed.
- Dex2oatFileWrapper image_fd = maybe_open_app_image(
- out_oat_path, generate_app_image, is_public, uid, is_secondary_dex);
-
// Open the reference profile if needed.
Dex2oatFileWrapper reference_profile_fd = maybe_open_reference_profile(
pkgname, dex_path, profile_name, profile_guided, is_public, uid, is_secondary_dex);
+ if (reference_profile_fd.get() == -1) {
+ // We don't create an app image without reference profile since there is no speedup from
+ // loading it in that case and instead will be a small overhead.
+ generate_app_image = false;
+ }
+
+ // Create the app image file if needed.
+ Dex2oatFileWrapper image_fd = maybe_open_app_image(
+ out_oat_path, generate_app_image, is_public, uid, is_secondary_dex);
+
unique_fd dex_metadata_fd;
if (dex_metadata_path != nullptr) {
dex_metadata_fd.reset(TEMP_FAILURE_RETRY(open(dex_metadata_path, O_RDONLY | O_NOFOLLOW)));
diff --git a/cmds/installd/tests/Android.bp b/cmds/installd/tests/Android.bp
index aa79fdc..bd45005 100644
--- a/cmds/installd/tests/Android.bp
+++ b/cmds/installd/tests/Android.bp
@@ -89,6 +89,8 @@
"libinstalld",
"liblog",
"liblogwrap",
+ "libziparchive",
+ "libz",
],
test_config: "installd_dexopt_test.xml",
}
diff --git a/cmds/installd/tests/installd_dexopt_test.cpp b/cmds/installd/tests/installd_dexopt_test.cpp
index fa2b0d9..13fd067 100644
--- a/cmds/installd/tests/installd_dexopt_test.cpp
+++ b/cmds/installd/tests/installd_dexopt_test.cpp
@@ -41,6 +41,7 @@
#include "globals.h"
#include "tests/test_utils.h"
#include "utils.h"
+#include "ziparchive/zip_writer.h"
using android::base::ReadFully;
using android::base::unique_fd;
@@ -195,6 +196,7 @@
std::unique_ptr<std::string> volume_uuid_;
std::string package_name_;
std::string apk_path_;
+ std::string empty_dm_file_;
std::string app_apk_dir_;
std::string app_private_dir_ce_;
std::string app_private_dir_de_;
@@ -260,6 +262,26 @@
<< " : " << error_msg;
}
+ // Create an empty dm file.
+ empty_dm_file_ = apk_path_ + ".dm";
+ {
+ int fd = open(empty_dm_file_.c_str(), O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
+ if (fd < 0) {
+ return ::testing::AssertionFailure() << "Could not open " << empty_dm_file_;
+ }
+ FILE* file = fdopen(fd, "wb");
+ if (file == nullptr) {
+ return ::testing::AssertionFailure() << "Null file for " << empty_dm_file_
+ << " fd=" << fd;
+ }
+ ZipWriter writer(file);
+ // Add vdex to zip.
+ writer.StartEntry("primary.prof", ZipWriter::kCompress);
+ writer.FinishEntry();
+ writer.Finish();
+ close(fd);
+ }
+
// Create the app user data.
status = service_->createAppData(
volume_uuid_,
@@ -479,7 +501,7 @@
bool prof_result;
ASSERT_BINDER_SUCCESS(service_->prepareAppProfile(
package_name_, kTestUserId, kTestAppId, *profile_name_ptr, apk_path_,
- /*dex_metadata*/ nullptr, &prof_result));
+ dm_path_ptr, &prof_result));
ASSERT_TRUE(prof_result);
binder::Status result = service_->dexopt(apk_path_,
@@ -645,7 +667,9 @@
DEXOPT_BOOTCOMPLETE | DEXOPT_PROFILE_GUIDED | DEXOPT_GENERATE_APP_IMAGE,
app_oat_dir_.c_str(),
kTestAppGid,
- DEX2OAT_FROM_SCRATCH);
+ DEX2OAT_FROM_SCRATCH,
+ /*binder_result=*/nullptr,
+ empty_dm_file_.c_str());
}
TEST_F(DexoptTest, DexoptPrimaryProfilePublic) {
@@ -655,7 +679,9 @@
DEXOPT_GENERATE_APP_IMAGE,
app_oat_dir_.c_str(),
kTestAppGid,
- DEX2OAT_FROM_SCRATCH);
+ DEX2OAT_FROM_SCRATCH,
+ /*binder_result=*/nullptr,
+ empty_dm_file_.c_str());
}
TEST_F(DexoptTest, DexoptPrimaryBackgroundOk) {
@@ -665,7 +691,9 @@
DEXOPT_GENERATE_APP_IMAGE,
app_oat_dir_.c_str(),
kTestAppGid,
- DEX2OAT_FROM_SCRATCH);
+ DEX2OAT_FROM_SCRATCH,
+ /*binder_result=*/nullptr,
+ empty_dm_file_.c_str());
}
TEST_F(DexoptTest, ResolveStartupConstStrings) {
@@ -684,7 +712,9 @@
DEXOPT_GENERATE_APP_IMAGE,
app_oat_dir_.c_str(),
kTestAppGid,
- DEX2OAT_FROM_SCRATCH);
+ DEX2OAT_FROM_SCRATCH,
+ /*binder_result=*/nullptr,
+ empty_dm_file_.c_str());
run_cmd_and_process_output(
"oatdump --header-only --oat-file=" + odex,
[&](const std::string& line) {
@@ -701,7 +731,9 @@
DEXOPT_GENERATE_APP_IMAGE,
app_oat_dir_.c_str(),
kTestAppGid,
- DEX2OAT_FROM_SCRATCH);
+ DEX2OAT_FROM_SCRATCH,
+ /*binder_result=*/nullptr,
+ empty_dm_file_.c_str());
run_cmd_and_process_output(
"oatdump --header-only --oat-file=" + odex,
[&](const std::string& line) {
diff --git a/libs/binder/IPCThreadState.cpp b/libs/binder/IPCThreadState.cpp
index 9a561cb..54333de 100644
--- a/libs/binder/IPCThreadState.cpp
+++ b/libs/binder/IPCThreadState.cpp
@@ -116,7 +116,7 @@
static const char* getReturnString(uint32_t cmd)
{
- size_t idx = cmd & 0xff;
+ size_t idx = cmd & _IOC_NRMASK;
if (idx < sizeof(kReturnStrings) / sizeof(kReturnStrings[0]))
return kReturnStrings[idx];
else
diff --git a/libs/binder/IServiceManager.cpp b/libs/binder/IServiceManager.cpp
index 4ba6c2a..0203d41 100644
--- a/libs/binder/IServiceManager.cpp
+++ b/libs/binder/IServiceManager.cpp
@@ -36,6 +36,9 @@
sp<IServiceManager> defaultServiceManager()
{
+ static Mutex gDefaultServiceManagerLock;
+ static sp<IServiceManager> gDefaultServiceManager;
+
if (gDefaultServiceManager != nullptr) return gDefaultServiceManager;
{
@@ -74,10 +77,13 @@
bool checkPermission(const String16& permission, pid_t pid, uid_t uid)
{
+ static Mutex gPermissionControllerLock;
+ static sp<IPermissionController> gPermissionController;
+
sp<IPermissionController> pc;
- gDefaultServiceManagerLock.lock();
+ gPermissionControllerLock.lock();
pc = gPermissionController;
- gDefaultServiceManagerLock.unlock();
+ gPermissionControllerLock.unlock();
int64_t startTime = 0;
@@ -101,11 +107,11 @@
}
// Object is dead!
- gDefaultServiceManagerLock.lock();
+ gPermissionControllerLock.lock();
if (gPermissionController == pc) {
gPermissionController = nullptr;
}
- gDefaultServiceManagerLock.unlock();
+ gPermissionControllerLock.unlock();
}
// Need to retrieve the permission controller.
@@ -121,9 +127,9 @@
} else {
pc = interface_cast<IPermissionController>(binder);
// Install the new permission controller, and try again.
- gDefaultServiceManagerLock.lock();
+ gPermissionControllerLock.lock();
gPermissionController = pc;
- gDefaultServiceManagerLock.unlock();
+ gPermissionControllerLock.unlock();
}
}
}
@@ -142,6 +148,8 @@
virtual sp<IBinder> getService(const String16& name) const
{
+ static bool gSystemBootCompleted = false;
+
sp<IBinder> svc = checkService(name);
if (svc != nullptr) return svc;
diff --git a/libs/binder/ProcessState.cpp b/libs/binder/ProcessState.cpp
index 63f49dd..2d156df 100644
--- a/libs/binder/ProcessState.cpp
+++ b/libs/binder/ProcessState.cpp
@@ -40,7 +40,7 @@
#include <sys/stat.h>
#include <sys/types.h>
-#define BINDER_VM_SIZE ((1 * 1024 * 1024) - sysconf(_SC_PAGE_SIZE) * 2)
+#define DEFAULT_BINDER_VM_SIZE ((1 * 1024 * 1024) - sysconf(_SC_PAGE_SIZE) * 2)
#define DEFAULT_MAX_BINDER_THREADS 15
#ifdef __ANDROID_VNDK__
@@ -77,7 +77,13 @@
if (gProcess != nullptr) {
return gProcess;
}
- gProcess = new ProcessState(kDefaultDriver);
+ gProcess = new ProcessState(kDefaultDriver, DEFAULT_BINDER_VM_SIZE);
+ return gProcess;
+}
+
+sp<ProcessState> ProcessState::selfOrNull()
+{
+ Mutex::Autolock _l(gProcessMutex);
return gProcess;
}
@@ -98,13 +104,19 @@
driver = "/dev/binder";
}
- gProcess = new ProcessState(driver);
+ gProcess = new ProcessState(driver, DEFAULT_BINDER_VM_SIZE);
return gProcess;
}
-sp<ProcessState> ProcessState::selfOrNull()
-{
+sp<ProcessState> ProcessState::initWithMmapSize(size_t mmap_size) {
Mutex::Autolock _l(gProcessMutex);
+ if (gProcess != nullptr) {
+ LOG_ALWAYS_FATAL_IF(mmap_size != gProcess->getMmapSize(),
+ "ProcessState already initialized with a different mmap size.");
+ return gProcess;
+ }
+
+ gProcess = new ProcessState(kDefaultDriver, mmap_size);
return gProcess;
}
@@ -237,6 +249,10 @@
return count;
}
+size_t ProcessState::getMmapSize() {
+ return mMmapSize;
+}
+
void ProcessState::setCallRestriction(CallRestriction restriction) {
LOG_ALWAYS_FATAL_IF(IPCThreadState::selfOrNull(), "Call restrictions must be set before the threadpool is started.");
@@ -421,7 +437,7 @@
return fd;
}
-ProcessState::ProcessState(const char *driver)
+ProcessState::ProcessState(const char *driver, size_t mmap_size)
: mDriverName(String8(driver))
, mDriverFD(open_driver(driver))
, mVMStart(MAP_FAILED)
@@ -435,11 +451,12 @@
, mBinderContextUserData(nullptr)
, mThreadPoolStarted(false)
, mThreadPoolSeq(1)
+ , mMmapSize(mmap_size)
, mCallRestriction(CallRestriction::NONE)
{
if (mDriverFD >= 0) {
// mmap the binder, providing a chunk of virtual address space to receive transactions.
- mVMStart = mmap(nullptr, BINDER_VM_SIZE, PROT_READ, MAP_PRIVATE | MAP_NORESERVE, mDriverFD, 0);
+ mVMStart = mmap(nullptr, mMmapSize, PROT_READ, MAP_PRIVATE | MAP_NORESERVE, mDriverFD, 0);
if (mVMStart == MAP_FAILED) {
// *sigh*
ALOGE("Using %s failed: unable to mmap transaction memory.\n", mDriverName.c_str());
@@ -456,7 +473,7 @@
{
if (mDriverFD >= 0) {
if (mVMStart != MAP_FAILED) {
- munmap(mVMStart, BINDER_VM_SIZE);
+ munmap(mVMStart, mMmapSize);
}
close(mDriverFD);
}
diff --git a/libs/binder/Static.cpp b/libs/binder/Static.cpp
index bd0e6f9..8625c6f 100644
--- a/libs/binder/Static.cpp
+++ b/libs/binder/Static.cpp
@@ -75,13 +75,4 @@
Mutex& gProcessMutex = *new Mutex;
sp<ProcessState> gProcess;
-// ------------ IServiceManager.cpp
-
-Mutex gDefaultServiceManagerLock;
-sp<IServiceManager> gDefaultServiceManager;
-#ifndef __ANDROID_VNDK__
-sp<IPermissionController> gPermissionController;
-#endif
-bool gSystemBootCompleted = false;
-
} // namespace android
diff --git a/libs/binder/include/binder/BpBinder.h b/libs/binder/include/binder/BpBinder.h
index 1d4f881..78f2e1d 100644
--- a/libs/binder/include/binder/BpBinder.h
+++ b/libs/binder/include/binder/BpBinder.h
@@ -67,7 +67,6 @@
virtual BpBinder* remoteBinder();
- status_t setConstantData(const void* data, size_t size);
void sendObituary();
static uint32_t getBinderProxyCount(uint32_t uid);
diff --git a/libs/binder/include/binder/ProcessState.h b/libs/binder/include/binder/ProcessState.h
index 224cb36..8a1f7e2 100644
--- a/libs/binder/include/binder/ProcessState.h
+++ b/libs/binder/include/binder/ProcessState.h
@@ -36,6 +36,8 @@
public:
static sp<ProcessState> self();
static sp<ProcessState> selfOrNull();
+ // Note: don't call self() or selfOrNull() before initWithMmapSize()
+ static sp<ProcessState> initWithMmapSize(size_t mmapSize); // size in bytes
/* initWithDriver() can be used to configure libbinder to use
* a different binder driver dev node. It must be called *before*
@@ -76,6 +78,7 @@
String8 getDriverName();
ssize_t getKernelReferences(size_t count, uintptr_t* buf);
+ size_t getMmapSize();
enum class CallRestriction {
// all calls okay
@@ -92,7 +95,7 @@
private:
friend class IPCThreadState;
- explicit ProcessState(const char* driver);
+ explicit ProcessState(const char* driver, size_t mmap_size);
~ProcessState();
ProcessState(const ProcessState& o);
@@ -135,6 +138,7 @@
String8 mRootDir;
bool mThreadPoolStarted;
volatile int32_t mThreadPoolSeq;
+ const size_t mMmapSize;
CallRestriction mCallRestriction;
};
diff --git a/libs/binder/include/private/binder/Static.h b/libs/binder/include/private/binder/Static.h
index 171be77..f8e0ee5 100644
--- a/libs/binder/include/private/binder/Static.h
+++ b/libs/binder/include/private/binder/Static.h
@@ -21,10 +21,6 @@
#include <binder/IBinder.h>
#include <binder/ProcessState.h>
-#ifndef __ANDROID_VNDK__
-#include <binder/IPermissionController.h>
-#endif
-#include <binder/IServiceManager.h>
namespace android {
@@ -35,12 +31,4 @@
extern Mutex& gProcessMutex;
extern sp<ProcessState> gProcess;
-// For IServiceManager.cpp
-extern Mutex gDefaultServiceManagerLock;
-extern sp<IServiceManager> gDefaultServiceManager;
-#ifndef __ANDROID_VNDK__
-extern sp<IPermissionController> gPermissionController;
-#endif
-extern bool gSystemBootCompleted;
-
} // namespace android