Loading cmds/atrace/atrace.rc +4 −0 Original line number Diff line number Diff line Loading @@ -107,6 +107,10 @@ on late-init chmod 0666 /sys/kernel/tracing/events/lowmemorykiller/lowmemory_kill/enable chmod 0666 /sys/kernel/debug/tracing/events/oom/oom_score_adj_update/enable chmod 0666 /sys/kernel/tracing/events/oom/oom_score_adj_update/enable chmod 0666 /sys/kernel/debug/tracing/events/task/task_rename/enable chmod 0666 /sys/kernel/tracing/events/task/task_rename/enable chmod 0666 /sys/kernel/debug/tracing/events/task/task_newtask/enable chmod 0666 /sys/kernel/tracing/events/task/task_newtask/enable # disk chmod 0666 /sys/kernel/tracing/events/f2fs/f2fs_get_data_block/enable Loading cmds/installd/InstalldNativeService.cpp +13 −5 Original line number Diff line number Diff line Loading @@ -808,11 +808,6 @@ static int32_t copy_directory_recursive(const char* from, const char* to) { // TODO(narayan): For snapshotAppData as well as restoreAppDataSnapshot, we // should validate that volumeUuid is either nullptr or TEST, we won't support // anything else. // // TODO(narayan): We need to be clearer about the expected behaviour for the // case where a snapshot already exists. We either need to clear the contents // of the snapshot directory before we make a copy, or we need to ensure that // the caller always clears it before requesting a snapshot. binder::Status InstalldNativeService::snapshotAppData( const std::unique_ptr<std::string>& volumeUuid, const std::string& packageName, int32_t user, int32_t storageFlags) { Loading Loading @@ -857,6 +852,12 @@ binder::Status InstalldNativeService::snapshotAppData( auto from = create_data_user_de_package_path(volume_uuid, user, package_name); auto to = create_data_misc_de_rollback_path(volume_uuid, user); int rd = delete_dir_contents(to, true /* ignore_if_missing */); if (rd != 0) { res = error(rd, "Failed clearing existing snapshot " + to); return res; } int rc = copy_directory_recursive(from.c_str(), to.c_str()); if (rc != 0) { res = error(rc, "Failed copying " + from + " to " + to); Loading @@ -868,6 +869,13 @@ binder::Status InstalldNativeService::snapshotAppData( if (storageFlags & FLAG_STORAGE_CE) { auto from = create_data_user_ce_package_path(volume_uuid, user, package_name); auto to = create_data_misc_ce_rollback_path(volume_uuid, user); int rd = delete_dir_contents(to, true /* ignore_if_missing */); if (rd != 0) { res = error(rd, "Failed clearing existing snapshot " + to); return res; } int rc = copy_directory_recursive(from.c_str(), to.c_str()); if (rc != 0) { res = error(rc, "Failed copying " + from + " to " + to); Loading cmds/installd/tests/installd_service_test.cpp +49 −0 Original line number Diff line number Diff line Loading @@ -363,6 +363,55 @@ TEST_F(ServiceTest, CreateAppDataSnapshot_AppDataAbsent) { ASSERT_EQ(-1, stat((rollback_de_dir + "/com.foo").c_str(), &sb)); } TEST_F(ServiceTest, CreateAppDataSnapshot_ClearsExistingSnapshot) { auto rollback_ce_dir = create_data_misc_ce_rollback_path("TEST", 0); auto rollback_de_dir = create_data_misc_de_rollback_path("TEST", 0); ASSERT_TRUE(mkdirs(rollback_ce_dir, 700)); ASSERT_TRUE(mkdirs(rollback_de_dir, 700)); auto fake_package_ce_path = create_data_user_ce_package_path("TEST", 0, "com.foo"); auto fake_package_de_path = create_data_user_de_package_path("TEST", 0, "com.foo"); ASSERT_TRUE(mkdirs(fake_package_ce_path, 700)); ASSERT_TRUE(mkdirs(fake_package_de_path, 700)); auto deleter = [&rollback_ce_dir, &rollback_de_dir, &fake_package_ce_path, &fake_package_de_path]() { delete_dir_contents(rollback_ce_dir, true); delete_dir_contents(rollback_de_dir, true); delete_dir_contents(fake_package_ce_path, true); delete_dir_contents(fake_package_de_path, true); rmdir(rollback_ce_dir.c_str()); rmdir(rollback_de_dir.c_str()); }; auto scope_guard = android::base::make_scope_guard(deleter); // Simulate presence of an existing snapshot ASSERT_TRUE(android::base::WriteStringToFile( "TEST_CONTENT_CE", rollback_ce_dir + "/file1", 0700, 10000, 20000, false /* follow_symlinks */)); ASSERT_TRUE(android::base::WriteStringToFile( "TEST_CONTENT_DE", rollback_de_dir + "/file1", 0700, 10000, 20000, false /* follow_symlinks */)); // Create app data. ASSERT_TRUE(android::base::WriteStringToFile( "TEST_CONTENT_2_CE", fake_package_ce_path + "/file2", 0700, 10000, 20000, false /* follow_symlinks */)); ASSERT_TRUE(android::base::WriteStringToFile( "TEST_CONTENT_2_DE", fake_package_de_path + "/file2", 0700, 10000, 20000, false /* follow_symlinks */)); ASSERT_TRUE(service->snapshotAppData(std::make_unique<std::string>("TEST"), "com.foo", 0, FLAG_STORAGE_DE | FLAG_STORAGE_CE).isOk()); // Previous snapshot (with data for file1) must be cleared. struct stat sb; ASSERT_EQ(-1, stat((rollback_ce_dir + "/com.foo/file1").c_str(), &sb)); ASSERT_EQ(-1, stat((rollback_de_dir + "/com.foo/file1").c_str(), &sb)); } TEST_F(ServiceTest, RestoreAppDataSnapshot) { auto rollback_ce_dir = create_data_misc_ce_rollback_path("TEST", 0); auto rollback_de_dir = create_data_misc_de_rollback_path("TEST", 0); Loading libs/ui/BufferHubBuffer.cpp +11 −5 Original line number Diff line number Diff line Loading @@ -167,19 +167,26 @@ int BufferHubBuffer::initWithBufferTraits(const BufferTraits& bufferTraits) { return -EINVAL; } int bufferId = bufferTraits.bufferInfo->data[1]; int bufferId = bufferTraits.bufferInfo->data[2]; if (bufferId < 0) { ALOGE("%s: Received an invalid (negative) id!", __FUNCTION__); return -EINVAL; } uint32_t clientBitMask; memcpy(&clientBitMask, &bufferTraits.bufferInfo->data[2], sizeof(clientBitMask)); memcpy(&clientBitMask, &bufferTraits.bufferInfo->data[3], sizeof(clientBitMask)); if (clientBitMask == 0U) { ALOGE("%s: Received a invalid client state mask!", __FUNCTION__); return -EINVAL; } const int eventFd = bufferTraits.bufferInfo->data[1]; if (eventFd < 0) { ALOGE("%s: Received a invalid event fd!", __FUNCTION__); return -EINVAL; } mEventFd = BufferHubEventFd(eventFd); // Import the metadata. Dup since hidl_handle owns the fd unique_fd ashmemFd(fcntl(bufferTraits.bufferInfo->data[0], F_DUPFD_CLOEXEC, 0)); mMetadata = BufferHubMetadata::Import(std::move(ashmemFd)); Loading @@ -190,7 +197,7 @@ int BufferHubBuffer::initWithBufferTraits(const BufferTraits& bufferTraits) { } uint32_t userMetadataSize; memcpy(&userMetadataSize, &bufferTraits.bufferInfo->data[3], sizeof(userMetadataSize)); memcpy(&userMetadataSize, &bufferTraits.bufferInfo->data[4], sizeof(userMetadataSize)); if (mMetadata.user_metadata_size() != userMetadataSize) { ALOGE("%s: user metadata size not match: expected %u, actual %zu.", __FUNCTION__, userMetadataSize, mMetadata.user_metadata_size()); Loading Loading @@ -314,9 +321,8 @@ int BufferHubBuffer::Release() { } bool BufferHubBuffer::IsValid() const { // TODO(b/68770788): check eventFd once implemented return mBufferHandle.getNativeHandle() != nullptr && mId >= 0 && mClientStateMask != 0U && mMetadata.IsValid() && mBufferClient != nullptr; mEventFd.get() >= 0 && mMetadata.IsValid() && mBufferClient != nullptr; } native_handle_t* BufferHubBuffer::Duplicate() { Loading libs/ui/BufferHubEventFd.cpp +2 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,8 @@ namespace android { BufferHubEventFd::BufferHubEventFd() : mFd(eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK)) {} BufferHubEventFd::BufferHubEventFd(int fd) : mFd(fd) {} status_t BufferHubEventFd::signal() const { if (!isValid()) { ALOGE("%s: cannot signal an invalid eventfd.", __FUNCTION__); Loading Loading
cmds/atrace/atrace.rc +4 −0 Original line number Diff line number Diff line Loading @@ -107,6 +107,10 @@ on late-init chmod 0666 /sys/kernel/tracing/events/lowmemorykiller/lowmemory_kill/enable chmod 0666 /sys/kernel/debug/tracing/events/oom/oom_score_adj_update/enable chmod 0666 /sys/kernel/tracing/events/oom/oom_score_adj_update/enable chmod 0666 /sys/kernel/debug/tracing/events/task/task_rename/enable chmod 0666 /sys/kernel/tracing/events/task/task_rename/enable chmod 0666 /sys/kernel/debug/tracing/events/task/task_newtask/enable chmod 0666 /sys/kernel/tracing/events/task/task_newtask/enable # disk chmod 0666 /sys/kernel/tracing/events/f2fs/f2fs_get_data_block/enable Loading
cmds/installd/InstalldNativeService.cpp +13 −5 Original line number Diff line number Diff line Loading @@ -808,11 +808,6 @@ static int32_t copy_directory_recursive(const char* from, const char* to) { // TODO(narayan): For snapshotAppData as well as restoreAppDataSnapshot, we // should validate that volumeUuid is either nullptr or TEST, we won't support // anything else. // // TODO(narayan): We need to be clearer about the expected behaviour for the // case where a snapshot already exists. We either need to clear the contents // of the snapshot directory before we make a copy, or we need to ensure that // the caller always clears it before requesting a snapshot. binder::Status InstalldNativeService::snapshotAppData( const std::unique_ptr<std::string>& volumeUuid, const std::string& packageName, int32_t user, int32_t storageFlags) { Loading Loading @@ -857,6 +852,12 @@ binder::Status InstalldNativeService::snapshotAppData( auto from = create_data_user_de_package_path(volume_uuid, user, package_name); auto to = create_data_misc_de_rollback_path(volume_uuid, user); int rd = delete_dir_contents(to, true /* ignore_if_missing */); if (rd != 0) { res = error(rd, "Failed clearing existing snapshot " + to); return res; } int rc = copy_directory_recursive(from.c_str(), to.c_str()); if (rc != 0) { res = error(rc, "Failed copying " + from + " to " + to); Loading @@ -868,6 +869,13 @@ binder::Status InstalldNativeService::snapshotAppData( if (storageFlags & FLAG_STORAGE_CE) { auto from = create_data_user_ce_package_path(volume_uuid, user, package_name); auto to = create_data_misc_ce_rollback_path(volume_uuid, user); int rd = delete_dir_contents(to, true /* ignore_if_missing */); if (rd != 0) { res = error(rd, "Failed clearing existing snapshot " + to); return res; } int rc = copy_directory_recursive(from.c_str(), to.c_str()); if (rc != 0) { res = error(rc, "Failed copying " + from + " to " + to); Loading
cmds/installd/tests/installd_service_test.cpp +49 −0 Original line number Diff line number Diff line Loading @@ -363,6 +363,55 @@ TEST_F(ServiceTest, CreateAppDataSnapshot_AppDataAbsent) { ASSERT_EQ(-1, stat((rollback_de_dir + "/com.foo").c_str(), &sb)); } TEST_F(ServiceTest, CreateAppDataSnapshot_ClearsExistingSnapshot) { auto rollback_ce_dir = create_data_misc_ce_rollback_path("TEST", 0); auto rollback_de_dir = create_data_misc_de_rollback_path("TEST", 0); ASSERT_TRUE(mkdirs(rollback_ce_dir, 700)); ASSERT_TRUE(mkdirs(rollback_de_dir, 700)); auto fake_package_ce_path = create_data_user_ce_package_path("TEST", 0, "com.foo"); auto fake_package_de_path = create_data_user_de_package_path("TEST", 0, "com.foo"); ASSERT_TRUE(mkdirs(fake_package_ce_path, 700)); ASSERT_TRUE(mkdirs(fake_package_de_path, 700)); auto deleter = [&rollback_ce_dir, &rollback_de_dir, &fake_package_ce_path, &fake_package_de_path]() { delete_dir_contents(rollback_ce_dir, true); delete_dir_contents(rollback_de_dir, true); delete_dir_contents(fake_package_ce_path, true); delete_dir_contents(fake_package_de_path, true); rmdir(rollback_ce_dir.c_str()); rmdir(rollback_de_dir.c_str()); }; auto scope_guard = android::base::make_scope_guard(deleter); // Simulate presence of an existing snapshot ASSERT_TRUE(android::base::WriteStringToFile( "TEST_CONTENT_CE", rollback_ce_dir + "/file1", 0700, 10000, 20000, false /* follow_symlinks */)); ASSERT_TRUE(android::base::WriteStringToFile( "TEST_CONTENT_DE", rollback_de_dir + "/file1", 0700, 10000, 20000, false /* follow_symlinks */)); // Create app data. ASSERT_TRUE(android::base::WriteStringToFile( "TEST_CONTENT_2_CE", fake_package_ce_path + "/file2", 0700, 10000, 20000, false /* follow_symlinks */)); ASSERT_TRUE(android::base::WriteStringToFile( "TEST_CONTENT_2_DE", fake_package_de_path + "/file2", 0700, 10000, 20000, false /* follow_symlinks */)); ASSERT_TRUE(service->snapshotAppData(std::make_unique<std::string>("TEST"), "com.foo", 0, FLAG_STORAGE_DE | FLAG_STORAGE_CE).isOk()); // Previous snapshot (with data for file1) must be cleared. struct stat sb; ASSERT_EQ(-1, stat((rollback_ce_dir + "/com.foo/file1").c_str(), &sb)); ASSERT_EQ(-1, stat((rollback_de_dir + "/com.foo/file1").c_str(), &sb)); } TEST_F(ServiceTest, RestoreAppDataSnapshot) { auto rollback_ce_dir = create_data_misc_ce_rollback_path("TEST", 0); auto rollback_de_dir = create_data_misc_de_rollback_path("TEST", 0); Loading
libs/ui/BufferHubBuffer.cpp +11 −5 Original line number Diff line number Diff line Loading @@ -167,19 +167,26 @@ int BufferHubBuffer::initWithBufferTraits(const BufferTraits& bufferTraits) { return -EINVAL; } int bufferId = bufferTraits.bufferInfo->data[1]; int bufferId = bufferTraits.bufferInfo->data[2]; if (bufferId < 0) { ALOGE("%s: Received an invalid (negative) id!", __FUNCTION__); return -EINVAL; } uint32_t clientBitMask; memcpy(&clientBitMask, &bufferTraits.bufferInfo->data[2], sizeof(clientBitMask)); memcpy(&clientBitMask, &bufferTraits.bufferInfo->data[3], sizeof(clientBitMask)); if (clientBitMask == 0U) { ALOGE("%s: Received a invalid client state mask!", __FUNCTION__); return -EINVAL; } const int eventFd = bufferTraits.bufferInfo->data[1]; if (eventFd < 0) { ALOGE("%s: Received a invalid event fd!", __FUNCTION__); return -EINVAL; } mEventFd = BufferHubEventFd(eventFd); // Import the metadata. Dup since hidl_handle owns the fd unique_fd ashmemFd(fcntl(bufferTraits.bufferInfo->data[0], F_DUPFD_CLOEXEC, 0)); mMetadata = BufferHubMetadata::Import(std::move(ashmemFd)); Loading @@ -190,7 +197,7 @@ int BufferHubBuffer::initWithBufferTraits(const BufferTraits& bufferTraits) { } uint32_t userMetadataSize; memcpy(&userMetadataSize, &bufferTraits.bufferInfo->data[3], sizeof(userMetadataSize)); memcpy(&userMetadataSize, &bufferTraits.bufferInfo->data[4], sizeof(userMetadataSize)); if (mMetadata.user_metadata_size() != userMetadataSize) { ALOGE("%s: user metadata size not match: expected %u, actual %zu.", __FUNCTION__, userMetadataSize, mMetadata.user_metadata_size()); Loading Loading @@ -314,9 +321,8 @@ int BufferHubBuffer::Release() { } bool BufferHubBuffer::IsValid() const { // TODO(b/68770788): check eventFd once implemented return mBufferHandle.getNativeHandle() != nullptr && mId >= 0 && mClientStateMask != 0U && mMetadata.IsValid() && mBufferClient != nullptr; mEventFd.get() >= 0 && mMetadata.IsValid() && mBufferClient != nullptr; } native_handle_t* BufferHubBuffer::Duplicate() { Loading
libs/ui/BufferHubEventFd.cpp +2 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,8 @@ namespace android { BufferHubEventFd::BufferHubEventFd() : mFd(eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK)) {} BufferHubEventFd::BufferHubEventFd(int fd) : mFd(fd) {} status_t BufferHubEventFd::signal() const { if (!isValid()) { ALOGE("%s: cannot signal an invalid eventfd.", __FUNCTION__); Loading