diff options
26 files changed, 311 insertions, 172 deletions
diff --git a/cmds/installd/dexopt.cpp b/cmds/installd/dexopt.cpp index 838d11d6d8..768d900591 100644 --- a/cmds/installd/dexopt.cpp +++ b/cmds/installd/dexopt.cpp @@ -713,6 +713,7 @@ static constexpr int PROFMAN_BIN_RETURN_CODE_SKIP_COMPILATION = 1; static constexpr int PROFMAN_BIN_RETURN_CODE_BAD_PROFILES = 2; static constexpr int PROFMAN_BIN_RETURN_CODE_ERROR_IO = 3; static constexpr int PROFMAN_BIN_RETURN_CODE_ERROR_LOCKING = 4; +static constexpr int PROFMAN_BIN_RETURN_CODE_SUCCESS = 5; class RunProfman : public ExecVHelper { public: @@ -720,7 +721,9 @@ class RunProfman : public ExecVHelper { const unique_fd& reference_profile_fd, const std::vector<unique_fd>& apk_fds, const std::vector<std::string>& dex_locations, - bool copy_and_update) { + bool copy_and_update, + bool for_snapshot, + bool for_boot_image) { // TODO(calin): Assume for now we run in the bg compile job (which is in // most of the invocation). With the current data flow, is not very easy or @@ -752,6 +755,14 @@ class RunProfman : public ExecVHelper { AddArg("--copy-and-update-profile-key"); } + if (for_snapshot) { + AddArg("--force-merge"); + } + + if (for_boot_image) { + AddArg("--boot-image-merge"); + } + // Do not add after dex2oat_flags, they should override others for debugging. PrepareArgs(profman_bin); } @@ -759,12 +770,16 @@ class RunProfman : public ExecVHelper { void SetupMerge(const std::vector<unique_fd>& profiles_fd, const unique_fd& reference_profile_fd, const std::vector<unique_fd>& apk_fds = std::vector<unique_fd>(), - const std::vector<std::string>& dex_locations = std::vector<std::string>()) { + const std::vector<std::string>& dex_locations = std::vector<std::string>(), + bool for_snapshot = false, + bool for_boot_image = false) { SetupArgs(profiles_fd, reference_profile_fd, apk_fds, dex_locations, - /*copy_and_update=*/false); + /*copy_and_update=*/ false, + for_snapshot, + for_boot_image); } void SetupCopyAndUpdate(unique_fd&& profile_fd, @@ -781,7 +796,9 @@ class RunProfman : public ExecVHelper { reference_profile_fd_, apk_fds_, dex_locations, - /*copy_and_update=*/true); + /*copy_and_update=*/true, + /*for_snapshot*/false, + /*for_boot_image*/false); } void SetupDump(const std::vector<unique_fd>& profiles_fd, @@ -795,7 +812,9 @@ class RunProfman : public ExecVHelper { reference_profile_fd, apk_fds, dex_locations, - /*copy_and_update=*/false); + /*copy_and_update=*/false, + /*for_snapshot*/false, + /*for_boot_image*/false); } void Exec() { @@ -872,7 +891,7 @@ static bool analyze_profiles(uid_t uid, const std::string& package_name, break; default: // Unknown return code or error. Unlink profiles. - LOG(WARNING) << "Unknown error code while processing profiles for location " + LOG(WARNING) << "Unexpected error code while processing profiles for location " << location << ": " << return_code; need_to_compile = false; should_clear_current_profiles = true; @@ -2741,7 +2760,7 @@ static bool create_app_profile_snapshot(int32_t app_id, } RunProfman args; - args.SetupMerge(profiles_fd, snapshot_fd, apk_fds, dex_locations); + args.SetupMerge(profiles_fd, snapshot_fd, apk_fds, dex_locations, /*for_snapshot=*/true); pid_t pid = fork(); if (pid == 0) { /* child -- drop privileges before continuing */ @@ -2756,6 +2775,13 @@ static bool create_app_profile_snapshot(int32_t app_id, return false; } + // Verify that profman finished successfully. + int profman_code = WEXITSTATUS(return_code); + if (profman_code != PROFMAN_BIN_RETURN_CODE_SUCCESS) { + LOG(WARNING) << "profman error for " << package_name << ":" << profile_name + << ":" << profman_code; + return false; + } return true; } @@ -2818,19 +2844,29 @@ static bool create_boot_image_profile_snapshot(const std::string& package_name, // We do this to avoid opening a huge a amount of files. static constexpr size_t kAggregationBatchSize = 10; - std::vector<unique_fd> profiles_fd; for (size_t i = 0; i < profiles.size(); ) { + std::vector<unique_fd> profiles_fd; for (size_t k = 0; k < kAggregationBatchSize && i < profiles.size(); k++, i++) { unique_fd fd = open_profile(AID_SYSTEM, profiles[i], O_RDONLY); if (fd.get() >= 0) { profiles_fd.push_back(std::move(fd)); } } + + // We aggregate (read & write) into the same fd multiple times in a row. + // We need to reset the cursor every time to ensure we read the whole file every time. + if (TEMP_FAILURE_RETRY(lseek(snapshot_fd, 0, SEEK_SET)) == static_cast<off_t>(-1)) { + PLOG(ERROR) << "Cannot reset position for snapshot profile"; + return false; + } + RunProfman args; args.SetupMerge(profiles_fd, snapshot_fd, apk_fds, - dex_locations); + dex_locations, + /*for_snapshot=*/true, + /*for_boot_image=*/true); pid_t pid = fork(); if (pid == 0) { /* child -- drop privileges before continuing */ @@ -2843,12 +2879,21 @@ static bool create_boot_image_profile_snapshot(const std::string& package_name, /* parent */ int return_code = wait_child(pid); + if (!WIFEXITED(return_code)) { PLOG(WARNING) << "profman failed for " << package_name << ":" << profile_name; return false; } - return true; + + // Verify that profman finished successfully. + int profman_code = WEXITSTATUS(return_code); + if (profman_code != PROFMAN_BIN_RETURN_CODE_SUCCESS) { + LOG(WARNING) << "profman error for " << package_name << ":" << profile_name + << ":" << profman_code; + return false; + } } + return true; } diff --git a/cmds/installd/migrate_legacy_obb_data.sh b/cmds/installd/migrate_legacy_obb_data.sh index 10756881be..0e6d7b9c62 100644 --- a/cmds/installd/migrate_legacy_obb_data.sh +++ b/cmds/installd/migrate_legacy_obb_data.sh @@ -15,17 +15,17 @@ # See the License for the specific language governing permissions and # limitations under the License. -rm -rf /sdcard/Android/obb/test_probe -mkdir -p /sdcard/Android/obb/ -touch /sdcard/Android/obb/test_probe +rm -rf /data/media/Android/obb/test_probe +mkdir -p /data/media/Android/obb/ +touch /data/media/Android/obb/test_probe if ! test -f /data/media/0/Android/obb/test_probe ; then log -p i -t migrate_legacy_obb_data "No support for 'unshared_obb'. Not migrating" - rm -rf /sdcard/Android/obb/test_probe + rm -rf /data/media/Android/obb/test_probe exit 0 fi # Delete the test file, and remove the obb folder if it is empty -rm -rf /sdcard/Android/obb/test_probe +rm -rf /data/media/Android/obb/test_probe rmdir /data/media/obb if ! test -d /data/media/obb ; then diff --git a/cmds/installd/tests/installd_dexopt_test.cpp b/cmds/installd/tests/installd_dexopt_test.cpp index 0212bc5564..69fefa199b 100644 --- a/cmds/installd/tests/installd_dexopt_test.cpp +++ b/cmds/installd/tests/installd_dexopt_test.cpp @@ -897,7 +897,9 @@ class ProfileTest : public DexoptTest { std::string expected_profile_content = snap_profile_ + ".expected"; run_cmd("rm -f " + expected_profile_content); run_cmd("touch " + expected_profile_content); - run_cmd("profman --profile-file=" + cur_profile_ + + // We force merging when creating the expected profile to make sure + // that the random profiles do not affect the output. + run_cmd("profman --force-merge --profile-file=" + cur_profile_ + " --profile-file=" + ref_profile_ + " --reference-profile-file=" + expected_profile_content + " --apk=" + apk_path_); @@ -1130,16 +1132,60 @@ TEST_F(ProfileTest, ProfilePrepareFailProfileChangedUid) { class BootProfileTest : public ProfileTest { public: - virtual void setup() { + std::vector<const std::string> extra_apps_; + std::vector<int64_t> extra_ce_data_inodes_; + + virtual void SetUp() { + ProfileTest::SetUp(); intial_android_profiles_dir = android_profiles_dir; + // Generate profiles for some extra apps. + // When merging boot profile we split profiles into small groups to avoid + // opening a lot of file descriptors at the same time. + // (Currently the group size for aggregation is 10) + // + // To stress test that works fine, create profile for more apps. + createAppProfilesForBootMerge(21); } virtual void TearDown() { android_profiles_dir = intial_android_profiles_dir; + deleteAppProfilesForBootMerge(); ProfileTest::TearDown(); } + void createAppProfilesForBootMerge(size_t number_of_profiles) { + for (size_t i = 0; i < number_of_profiles; i++) { + int64_t ce_data_inode; + std::string package_name = "dummy_test_pkg" + std::to_string(i); + LOG(INFO) << package_name; + ASSERT_BINDER_SUCCESS(service_->createAppData( + volume_uuid_, + package_name, + kTestUserId, + kAppDataFlags, + kTestAppUid, + se_info_, + kOSdkVersion, + &ce_data_inode)); + extra_apps_.push_back(package_name); + extra_ce_data_inodes_.push_back(ce_data_inode); + std::string profile = create_current_profile_path( + kTestUserId, package_name, kPrimaryProfile, /*is_secondary_dex*/ false); + SetupProfile(profile, kTestAppUid, kTestAppGid, 0600, 1); + } + } + + void deleteAppProfilesForBootMerge() { + if (kDebug) { + return; + } + for (size_t i = 0; i < extra_apps_.size(); i++) { + service_->destroyAppData( + volume_uuid_, extra_apps_[i], kTestUserId, kAppDataFlags, extra_ce_data_inodes_[i]); + } + } + void UpdateAndroidProfilesDir(const std::string& profile_dir) { android_profiles_dir = profile_dir; // We need to create the reference profile directory in the new profile dir. diff --git a/headers/media_plugin/media/cas/CasAPI.h b/headers/media_plugin/media/cas/CasAPI.h index c87ee5655e..8cc9d365a2 100644 --- a/headers/media_plugin/media/cas/CasAPI.h +++ b/headers/media_plugin/media/cas/CasAPI.h @@ -56,6 +56,11 @@ typedef void (*CasPluginCallbackExt)( size_t size, const CasSessionId *sessionId); +typedef void (*CasPluginStatusCallback)( + void *appData, + int32_t event, + int32_t arg); + struct CasFactory { CasFactory() {} virtual ~CasFactory() {} @@ -91,6 +96,10 @@ struct CasPlugin { CasPlugin() {} virtual ~CasPlugin() {} + // Provide a callback to report plugin status + virtual status_t setStatusCallback( + CasPluginStatusCallback callback) = 0; + // Provide the CA private data from a CA_descriptor in the conditional // access table to a CasPlugin. virtual status_t setPrivateData( @@ -100,6 +109,11 @@ struct CasPlugin { // streams. virtual status_t openSession(CasSessionId *sessionId) = 0; + // Open a session with intend and mode for descrambling a program, or one + // or more elementary streams. + virtual status_t openSession(uint32_t intent, uint32_t mode, + CasSessionId *sessionId) = 0; + // Close a previously opened session. virtual status_t closeSession(const CasSessionId &sessionId) = 0; diff --git a/include/android/sharedmem.h b/include/android/sharedmem.h index 7f5177bde9..6efa4f71cb 100644 --- a/include/android/sharedmem.h +++ b/include/android/sharedmem.h @@ -21,7 +21,7 @@ /** * @file sharedmem.h - * @brief Shared memory buffers that can be shared across process. + * @brief Shared memory buffers that can be shared between processes. */ #ifndef ANDROID_SHARED_MEMORY_H @@ -61,11 +61,15 @@ extern "C" { * * Use close() to release the shared memory region. * + * Use {@link android.os.ParcelFileDescriptor} to pass the file descriptor to + * another process. File descriptors may also be sent to other processes over a Unix domain + * socket with sendmsg and SCM_RIGHTS. See sendmsg(3) and cmsg(3) man pages for more information. + * * Available since API level 26. * * \param name an optional name. * \param size size of the shared memory region - * \return file descriptor that denotes the shared memory; error code on failure. + * \return file descriptor that denotes the shared memory; -1 and sets errno on failure, or -EINVAL if the error is that size was 0. */ int ASharedMemory_create(const char *name, size_t size) __INTRODUCED_IN(26); @@ -109,7 +113,7 @@ size_t ASharedMemory_getSize(int fd) __INTRODUCED_IN(26); * \param fd file descriptor of the shared memory region. * \param prot any bitwise-or'ed combination of PROT_READ, PROT_WRITE, PROT_EXEC denoting * updated access. Note access can only be removed, but not added back. - * \return 0 for success, error code on failure. + * \return 0 for success, -1 and sets errno on failure. */ int ASharedMemory_setProt(int fd, int prot) __INTRODUCED_IN(26); diff --git a/libs/arect/Android.bp b/libs/arect/Android.bp index ad8287c203..2518b1427d 100644 --- a/libs/arect/Android.bp +++ b/libs/arect/Android.bp @@ -13,13 +13,18 @@ // limitations under the License. ndk_headers { - name: "libarect_headers", + name: "libarect_headers_for_ndk", from: "include/android", to: "android", srcs: ["include/android/*.h"], license: "NOTICE", } +cc_library_headers { + name: "libarect_headers", + export_include_dirs: ["include"], +} + cc_library_static { name: "libarect", host_supported: true, diff --git a/libs/binder/include/binder/IServiceManager.h b/libs/binder/include/binder/IServiceManager.h index bd77567290..2c4326393e 100644 --- a/libs/binder/include/binder/IServiceManager.h +++ b/libs/binder/include/binder/IServiceManager.h @@ -113,6 +113,13 @@ sp<INTERFACE> waitForDeclaredService(const String16& name) { return interface_cast<INTERFACE>(sm->waitForService(name)); } +template <typename INTERFACE> +sp<INTERFACE> checkDeclaredService(const String16& name) { + const sp<IServiceManager> sm = defaultServiceManager(); + if (!sm->isDeclared(name)) return nullptr; + return interface_cast<INTERFACE>(sm->checkService(name)); +} + template<typename INTERFACE> sp<INTERFACE> waitForVintfService( const String16& instance = String16("default")) { @@ -121,6 +128,13 @@ sp<INTERFACE> waitForVintfService( } template<typename INTERFACE> +sp<INTERFACE> checkVintfService( + const String16& instance = String16("default")) { + return checkDeclaredService<INTERFACE>( + INTERFACE::descriptor + String16("/") + instance); +} + +template<typename INTERFACE> status_t getService(const String16& name, sp<INTERFACE>* outService) { const sp<IServiceManager> sm = defaultServiceManager(); diff --git a/libs/binder/include/binder/ParcelFileDescriptor.h b/libs/binder/include/binder/ParcelFileDescriptor.h index 662e56e864..4635ad84c6 100644 --- a/libs/binder/include/binder/ParcelFileDescriptor.h +++ b/libs/binder/include/binder/ParcelFileDescriptor.h @@ -42,6 +42,24 @@ public: android::status_t writeToParcel(android::Parcel* parcel) const override; android::status_t readFromParcel(const android::Parcel* parcel) override; + inline bool operator!=(const ParcelFileDescriptor& rhs) const { + return mFd != rhs.mFd; + } + inline bool operator<(const ParcelFileDescriptor& rhs) const { + return mFd < rhs.mFd; + } + inline bool operator<=(const ParcelFileDescriptor& rhs) const { + return mFd <= rhs.mFd; + } + inline bool operator==(const ParcelFileDescriptor& rhs) const { + return mFd == rhs.mFd; + } + inline bool operator>(const ParcelFileDescriptor& rhs) const { + return mFd > rhs.mFd; + } + inline bool operator>=(const ParcelFileDescriptor& rhs) const { + return mFd >= rhs.mFd; + } private: android::base::unique_fd mFd; }; diff --git a/libs/binder/ndk/include_ndk/android/binder_auto_utils.h b/libs/binder/ndk/include_ndk/android/binder_auto_utils.h index 8f37c5e3d3..946ccb79a5 100644 --- a/libs/binder/ndk/include_ndk/android/binder_auto_utils.h +++ b/libs/binder/ndk/include_ndk/android/binder_auto_utils.h @@ -159,13 +159,17 @@ class ScopedAResource { */ T* getR() { return &mT; } - // copy-constructing, or move/copy assignment is disallowed + // copy-constructing/assignment is disallowed ScopedAResource(const ScopedAResource&) = delete; ScopedAResource& operator=(const ScopedAResource&) = delete; - ScopedAResource& operator=(ScopedAResource&&) = delete; - // move-constructing is okay + // move-constructing/assignment is okay ScopedAResource(ScopedAResource&& other) : mT(std::move(other.mT)) { other.mT = DEFAULT; } + ScopedAResource& operator=(ScopedAResource&& other) { + set(other.mT); + other.mT = DEFAULT; + return *this; + } private: T mT; @@ -197,6 +201,7 @@ class ScopedAStatus : public impl::ScopedAResource<AStatus*, void, AStatus_delet explicit ScopedAStatus(AStatus* a = nullptr) : ScopedAResource(a) {} ~ScopedAStatus() {} ScopedAStatus(ScopedAStatus&&) = default; + ScopedAStatus& operator=(ScopedAStatus&&) = default; /** * See AStatus_isOk. diff --git a/libs/binder/ndk/include_platform/android/binder_stability.h b/libs/binder/ndk/include_platform/android/binder_stability.h index 2a4ded8691..56d95a7759 100644 --- a/libs/binder/ndk/include_platform/android/binder_stability.h +++ b/libs/binder/ndk/include_platform/android/binder_stability.h @@ -56,9 +56,11 @@ enum { /** * This interface has the stability of the system image. */ -void AIBinder_markSystemStability(AIBinder* binder); +__attribute__((weak)) void AIBinder_markSystemStability(AIBinder* binder); static inline void AIBinder_markCompilationUnitStability(AIBinder* binder) { + if (AIBinder_markSystemStability == nullptr) return; + AIBinder_markSystemStability(binder); } diff --git a/libs/binder/ndk/libbinder_ndk.map.txt b/libs/binder/ndk/libbinder_ndk.map.txt index d4d5387f33..d59d6e42c6 100644 --- a/libs/binder/ndk/libbinder_ndk.map.txt +++ b/libs/binder/ndk/libbinder_ndk.map.txt @@ -89,12 +89,12 @@ LIBBINDER_NDK { # introduced=29 AStatus_getStatus; AStatus_isOk; AStatus_newOk; - ABinderProcess_joinThreadPool; # apex vndk - ABinderProcess_setThreadPoolMaxThreadCount; # apex vndk - ABinderProcess_startThreadPool; # apex vndk - AServiceManager_addService; # apex vndk - AServiceManager_checkService; # apex vndk - AServiceManager_getService; # apex vndk + ABinderProcess_joinThreadPool; # apex llndk + ABinderProcess_setThreadPoolMaxThreadCount; # apex llndk + ABinderProcess_startThreadPool; # apex llndk + AServiceManager_addService; # apex llndk + AServiceManager_checkService; # apex llndk + AServiceManager_getService; # apex llndk local: *; }; @@ -105,8 +105,8 @@ LIBBINDER_NDK30 { # introduced=30 AIBinder_setExtension; AIBinder_markSystemStability; # apex - AIBinder_markVendorStability; # vndk - AIBinder_markVintfStability; # apex vndk + AIBinder_markVendorStability; # llndk + AIBinder_markVintfStability; # apex llndk local: *; }; diff --git a/libs/binder/tests/Android.bp b/libs/binder/tests/Android.bp index 635ea69fb4..5a7f9a97fa 100644 --- a/libs/binder/tests/Android.bp +++ b/libs/binder/tests/Android.bp @@ -119,12 +119,7 @@ cc_test { srcs: ["binderSafeInterfaceTest.cpp"], cppflags: [ - "-Weverything", - "-Wno-c++98-compat", - "-Wno-c++98-compat-pedantic", - "-Wno-global-constructors", - "-Wno-padded", - "-Wno-weak-vtables", + "-Wextra", ], cpp_std: "experimental", diff --git a/libs/nativewindow/libnativewindow.map.txt b/libs/nativewindow/libnativewindow.map.txt index bad8b11540..fece733bea 100644 --- a/libs/nativewindow/libnativewindow.map.txt +++ b/libs/nativewindow/libnativewindow.map.txt @@ -2,9 +2,9 @@ LIBNATIVEWINDOW { global: AHardwareBuffer_acquire; AHardwareBuffer_allocate; - AHardwareBuffer_createFromHandle; # vndk + AHardwareBuffer_createFromHandle; # llndk AHardwareBuffer_describe; - AHardwareBuffer_getNativeHandle; # vndk + AHardwareBuffer_getNativeHandle; # llndk AHardwareBuffer_isSupported; # introduced=29 AHardwareBuffer_lock; AHardwareBuffer_lockAndGetInfo; # introduced=29 @@ -13,32 +13,32 @@ LIBNATIVEWINDOW { AHardwareBuffer_release; AHardwareBuffer_sendHandleToUnixSocket; AHardwareBuffer_unlock; - ANativeWindowBuffer_getHardwareBuffer; # vndk - ANativeWindow_OemStorageGet; # vndk - ANativeWindow_OemStorageSet; # vndk + ANativeWindowBuffer_getHardwareBuffer; # llndk + ANativeWindow_OemStorageGet; # llndk + ANativeWindow_OemStorageSet; # llndk ANativeWindow_acquire; - ANativeWindow_cancelBuffer; # vndk - ANativeWindow_dequeueBuffer; # vndk + ANativeWindow_cancelBuffer; # llndk + ANativeWindow_dequeueBuffer; # llndk ANativeWindow_getBuffersDataSpace; # introduced=28 ANativeWindow_getFormat; ANativeWindow_getHeight; ANativeWindow_getWidth; ANativeWindow_lock; - ANativeWindow_query; # vndk - ANativeWindow_queryf; # vndk - ANativeWindow_queueBuffer; # vndk + ANativeWindow_query; # llndk + ANativeWindow_queryf; # llndk + ANativeWindow_queueBuffer; # llndk ANativeWindow_release; - ANativeWindow_setAutoRefresh; # vndk - ANativeWindow_setBufferCount; # vndk + ANativeWindow_setAutoRefresh; # llndk + ANativeWindow_setBufferCount; # llndk ANativeWindow_setBuffersDataSpace; # introduced=28 - ANativeWindow_setBuffersDimensions; # vndk - ANativeWindow_setBuffersFormat; # vndk + ANativeWindow_setBuffersDimensions; # llndk + ANativeWindow_setBuffersFormat; # llndk ANativeWindow_setBuffersGeometry; - ANativeWindow_setBuffersTimestamp; # vndk + ANativeWindow_setBuffersTimestamp; # llndk ANativeWindow_setBuffersTransform; - ANativeWindow_setSharedBufferMode; # vndk - ANativeWindow_setSwapInterval; # vndk - ANativeWindow_setUsage; # vndk + ANativeWindow_setSharedBufferMode; # llndk + ANativeWindow_setSwapInterval; # llndk + ANativeWindow_setUsage; # llndk ANativeWindow_unlockAndPost; local: *; diff --git a/libs/sensor/Android.bp b/libs/sensor/Android.bp index 940ff5afbc..e8154a6931 100644 --- a/libs/sensor/Android.bp +++ b/libs/sensor/Android.bp @@ -21,22 +21,7 @@ cc_library_shared { "-Werror", ], cppflags: [ - "-Weverything", - - // The static constructors and destructors in this library have not been noted to - // introduce significant overheads - "-Wno-exit-time-destructors", - "-Wno-global-constructors", - - // We only care about compiling as C++14 - "-Wno-c++98-compat-pedantic", - - // android/sensors.h uses nested anonymous unions and anonymous structs - "-Wno-nested-anon-types", - "-Wno-gnu-anonymous-struct", - - // Don't warn about struct padding - "-Wno-padded", + "-Wextra", ], srcs: [ diff --git a/libs/ui/Android.bp b/libs/ui/Android.bp index 2518e9374d..42b578cce8 100644 --- a/libs/ui/Android.bp +++ b/libs/ui/Android.bp @@ -26,32 +26,18 @@ cc_library_shared { "-Werror", ], cppflags: [ - "-Weverything", - - // The static constructors and destructors in this library have not been noted to - // introduce significant overheads - "-Wno-exit-time-destructors", - "-Wno-global-constructors", - - // We only care about compiling as C++14 - "-Wno-c++98-compat-pedantic", - - // We are aware of the risks inherent in comparing floats for equality - "-Wno-float-equal", - - // We use four-character constants for the GraphicBuffer header, and don't care - // that they're non-portable as long as they're consistent within one execution - "-Wno-four-char-constants", - - // Don't warn about struct padding - "-Wno-padded", - - "-Wno-switch-enum", - "-Wno-format-pedantic", + "-Wextra", ], sanitize: { integer_overflow: true, + misc_undefined: ["bounds"], + diag: { + misc_undefined: ["bounds"], + no_recover: [ + "bounds", + ], + }, }, srcs: [ diff --git a/libs/vr/libpdx_default_transport/Android.bp b/libs/vr/libpdx_default_transport/Android.bp index 1176abf552..1ce9c991d5 100644 --- a/libs/vr/libpdx_default_transport/Android.bp +++ b/libs/vr/libpdx_default_transport/Android.bp @@ -39,7 +39,6 @@ cc_library_shared { "libcutils", "liblog", "libutils", - "libcrypto", "libselinux", ], } diff --git a/opengl/libs/EGL/egl_layers.cpp b/opengl/libs/EGL/egl_layers.cpp index ac01dc8f96..9b1b522731 100644 --- a/opengl/libs/EGL/egl_layers.cpp +++ b/opengl/libs/EGL/egl_layers.cpp @@ -379,14 +379,12 @@ void LayerLoader::LoadLayers() { // any symbol dependencies will be resolved by system libraries. They // can't safely use libc++_shared, for example. Which is one reason // (among several) we only allow them in non-user builds. - void* handle = nullptr; auto app_namespace = android::GraphicsEnv::getInstance().getAppNamespace(); if (app_namespace && !android::base::StartsWith(layer, kSystemLayerLibraryDir)) { - bool native_bridge = false; char* error_message = nullptr; - handle = OpenNativeLibraryInNamespace( - app_namespace, layer.c_str(), &native_bridge, &error_message); - if (!handle) { + dlhandle_ = OpenNativeLibraryInNamespace( + app_namespace, layer.c_str(), &native_bridge_, &error_message); + if (!dlhandle_) { ALOGE("Failed to load layer %s with error: %s", layer.c_str(), error_message); android::NativeLoaderFreeErrorMessage(error_message); @@ -394,11 +392,11 @@ void LayerLoader::LoadLayers() { } } else { - handle = dlopen(layer.c_str(), RTLD_NOW | RTLD_LOCAL); + dlhandle_ = dlopen(layer.c_str(), RTLD_NOW | RTLD_LOCAL); } - if (handle) { - ALOGV("Loaded layer handle (%llu) for layer %s", (unsigned long long)handle, + if (dlhandle_) { + ALOGV("Loaded layer handle (%llu) for layer %s", (unsigned long long)dlhandle_, layers[i].c_str()); } else { // If the layer is found but can't be loaded, try setenforce 0 @@ -411,8 +409,7 @@ void LayerLoader::LoadLayers() { std::string init_func = "AndroidGLESLayer_Initialize"; ALOGV("Looking for entrypoint %s", init_func.c_str()); - layer_init_func LayerInit = - reinterpret_cast<layer_init_func>(dlsym(handle, init_func.c_str())); + layer_init_func LayerInit = GetTrampoline<layer_init_func>(init_func.c_str()); if (LayerInit) { ALOGV("Found %s for layer %s", init_func.c_str(), layer.c_str()); layer_init_.push_back(LayerInit); @@ -425,8 +422,7 @@ void LayerLoader::LoadLayers() { std::string setup_func = "AndroidGLESLayer_GetProcAddress"; ALOGV("Looking for entrypoint %s", setup_func.c_str()); - layer_setup_func LayerSetup = - reinterpret_cast<layer_setup_func>(dlsym(handle, setup_func.c_str())); + layer_setup_func LayerSetup = GetTrampoline<layer_setup_func>(setup_func.c_str()); if (LayerSetup) { ALOGV("Found %s for layer %s", setup_func.c_str(), layer.c_str()); layer_setup_.push_back(LayerSetup); diff --git a/opengl/libs/EGL/egl_layers.h b/opengl/libs/EGL/egl_layers.h index e401b448cf..1e2783fc98 100644 --- a/opengl/libs/EGL/egl_layers.h +++ b/opengl/libs/EGL/egl_layers.h @@ -21,10 +21,15 @@ #include <unordered_map> #include <vector> -#include <EGL/egldefs.h> +#include <android/dlext.h> +#include <dlfcn.h> +#include <EGL/egldefs.h> #include "egl_platform_entries.h" +#include <nativebridge/native_bridge.h> +#include <nativeloader/native_loader.h> + typedef __eglMustCastToProperFunctionPointerType EGLFuncPointer; namespace android { @@ -54,10 +59,21 @@ public: std::vector<layer_setup_func> layer_setup_; private: - LayerLoader() : layers_loaded_(false), initialized_(false), current_layer_(0){}; + LayerLoader() : layers_loaded_(false), initialized_(false), current_layer_(0), dlhandle_(nullptr), native_bridge_(false){}; bool layers_loaded_; bool initialized_; unsigned current_layer_; + void* dlhandle_; + bool native_bridge_; + + template<typename Func = void*> + Func GetTrampoline(const char* name) const { + if (native_bridge_) { + return reinterpret_cast<Func>(android::NativeBridgeGetTrampoline( + dlhandle_, name, nullptr, 0)); + } + return reinterpret_cast<Func>(dlsym(dlhandle_, name)); + } }; }; // namespace android diff --git a/opengl/libs/EGL/egl_platform_entries.cpp b/opengl/libs/EGL/egl_platform_entries.cpp index e996be6853..a3bb6debe9 100644 --- a/opengl/libs/EGL/egl_platform_entries.cpp +++ b/opengl/libs/EGL/egl_platform_entries.cpp @@ -61,7 +61,7 @@ namespace android { using nsecs_t = int64_t; -struct extention_map_t { +struct extension_map_t { const char* name; __eglMustCastToProperFunctionPointerType address; }; @@ -154,7 +154,7 @@ char const * const gClientExtensionString = * (keep in sync with gExtensionString above) * */ -static const extention_map_t sExtensionMap[] = { +static const extension_map_t sExtensionMap[] = { // EGL_KHR_lock_surface { "eglLockSurfaceKHR", (__eglMustCastToProperFunctionPointerType)&eglLockSurfaceKHR }, @@ -257,13 +257,14 @@ static const extention_map_t sExtensionMap[] = { !strcmp((procname), "eglAwakenProcessIMG")) // accesses protected by sExtensionMapMutex -static std::unordered_map<std::string, __eglMustCastToProperFunctionPointerType> sGLExtentionMap; +static std::unordered_map<std::string, __eglMustCastToProperFunctionPointerType> sGLExtensionMap; +static std::unordered_map<std::string, int> sGLExtensionSlotMap; -static int sGLExtentionSlot = 0; +static int sGLExtensionSlot = 0; static pthread_mutex_t sExtensionMapMutex = PTHREAD_MUTEX_INITIALIZER; static void(*findProcAddress(const char* name, - const extention_map_t* map, size_t n))() { + const extension_map_t* map, size_t n))() { for (uint32_t i=0 ; i<n ; i++) { if (!strcmp(name, map[i].name)) { return map[i].address; @@ -1223,7 +1224,7 @@ __eglMustCastToProperFunctionPointerType eglGetProcAddressImpl(const char *procn addr = findBuiltinWrapper(procname); if (addr) return addr; - // this protects accesses to sGLExtentionMap and sGLExtentionSlot + // this protects accesses to sGLExtensionMap, sGLExtensionSlot, and sGLExtensionSlotMap pthread_mutex_lock(&sExtensionMapMutex); /* @@ -1244,51 +1245,69 @@ __eglMustCastToProperFunctionPointerType eglGetProcAddressImpl(const char *procn */ const std::string name(procname); + auto& extensionMap = sGLExtensionMap; + auto& extensionSlotMap = sGLExtensionSlotMap; + egl_connection_t* const cnx = &gEGLImpl; + LayerLoader& layer_loader(LayerLoader::getInstance()); - auto& extentionMap = sGLExtentionMap; - auto pos = extentionMap.find(name); - addr = (pos != extentionMap.end()) ? pos->second : nullptr; - const int slot = sGLExtentionSlot; + // See if we've already looked up this extension + auto pos = extensionMap.find(name); + addr = (pos != extensionMap.end()) ? pos->second : nullptr; - ALOGE_IF(slot >= MAX_NUMBER_OF_GL_EXTENSIONS, - "no more slots for eglGetProcAddress(\"%s\")", - procname); + if (!addr) { + // This is the first time we've looked this function up + // Ensure we have room to track it + const int slot = sGLExtensionSlot; + if (slot < MAX_NUMBER_OF_GL_EXTENSIONS) { - egl_connection_t* const cnx = &gEGLImpl; - LayerLoader& layer_loader(LayerLoader::getInstance()); + if (cnx->dso && cnx->egl.eglGetProcAddress) { - if (!addr && (slot < MAX_NUMBER_OF_GL_EXTENSIONS)) { + // Extensions are independent of the bound context + addr = cnx->egl.eglGetProcAddress(procname); + if (addr) { - if (cnx->dso && cnx->egl.eglGetProcAddress) { + // purposefully track the bottom of the stack in extensionMap + extensionMap[name] = addr; - // Extensions are independent of the bound context - addr = cnx->egl.eglGetProcAddress(procname); - if (addr) { + // Apply layers + addr = layer_loader.ApplyLayers(procname, addr); - // purposefully track the bottom of the stack in extensionMap - extentionMap[name] = addr; + // Track the top most entry point return the extension forwarder + cnx->hooks[egl_connection_t::GLESv1_INDEX]->ext.extensions[slot] = + cnx->hooks[egl_connection_t::GLESv2_INDEX]->ext.extensions[slot] = addr; + addr = gExtensionForwarders[slot]; - // Apply layers - addr = layer_loader.ApplyLayers(procname, addr); + // Remember the slot for this extension + extensionSlotMap[name] = slot; - // Track the top most entry point - cnx->hooks[egl_connection_t::GLESv1_INDEX]->ext.extensions[slot] = - cnx->hooks[egl_connection_t::GLESv2_INDEX]->ext.extensions[slot] = addr; - addr = gExtensionForwarders[slot]; - sGLExtentionSlot++; + // Increment the global extension index + sGLExtensionSlot++; + } } + } else { + // The extension forwarder has a fixed number of slots + ALOGE("no more slots for eglGetProcAddress(\"%s\")", procname); } - } else if (slot < MAX_NUMBER_OF_GL_EXTENSIONS) { + } else { + // We tracked an address, so we've seen this func before + // Look up the slot for this extension + auto slot_pos = extensionSlotMap.find(name); + int ext_slot = (slot_pos != extensionSlotMap.end()) ? slot_pos->second : -1; + if (ext_slot < 0) { + // Something has gone wrong, this should not happen + ALOGE("No extension slot found for %s", procname); + return nullptr; + } - // We've seen this func before, but we tracked the bottom, so re-apply layers - // More layers might have been enabled + // We tracked the bottom of the stack, so re-apply layers since + // more layers might have been enabled addr = layer_loader.ApplyLayers(procname, addr); - // Track the top most entry point - cnx->hooks[egl_connection_t::GLESv1_INDEX]->ext.extensions[slot] = - cnx->hooks[egl_connection_t::GLESv2_INDEX]->ext.extensions[slot] = addr; - addr = gExtensionForwarders[slot]; + // Track the top most entry point and return the extension forwarder + cnx->hooks[egl_connection_t::GLESv1_INDEX]->ext.extensions[ext_slot] = + cnx->hooks[egl_connection_t::GLESv2_INDEX]->ext.extensions[ext_slot] = addr; + addr = gExtensionForwarders[ext_slot]; } pthread_mutex_unlock(&sExtensionMapMutex); diff --git a/opengl/libs/libEGL.map.txt b/opengl/libs/libEGL.map.txt index b2d795745f..0c14e01c7b 100644 --- a/opengl/libs/libEGL.map.txt +++ b/opengl/libs/libEGL.map.txt @@ -28,7 +28,7 @@ LIBEGL { eglDestroySurface; eglDestroySync; # introduced=29 eglDestroySyncKHR; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21 - eglDupNativeFenceFDANDROID; # vndk + eglDupNativeFenceFDANDROID; # llndk eglGetConfigAttrib; eglGetConfigs; eglGetCurrentContext; @@ -54,7 +54,7 @@ LIBEGL { eglQueryStreamTimeKHR; # introduced=23 eglQueryStreamu64KHR; # introduced=23 eglQueryString; - eglQueryStringImplementationANDROID; # vndk + eglQueryStringImplementationANDROID; # llndk eglQuerySurface; eglReleaseTexImage; eglReleaseThread; diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 3057ed13e7..cb6dd8b9eb 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -1808,6 +1808,7 @@ void SurfaceFlinger::handleMessageRefresh() { preComposition(); rebuildLayerStacks(); calculateWorkingSet(); + long compositionTime = elapsedRealtimeNano(); for (const auto& [token, display] : mDisplays) { beginFrame(display); prepareFrame(display); @@ -1837,7 +1838,7 @@ void SurfaceFlinger::handleMessageRefresh() { if (mVisibleRegionsDirty) { mVisibleRegionsDirty = false; if (mTracingEnabled) { - mTracing.notify("visibleRegionsDirty"); + mTracing.notify(compositionTime, "visibleRegionsDirty"); } } } diff --git a/services/surfaceflinger/SurfaceTracing.cpp b/services/surfaceflinger/SurfaceTracing.cpp index 9053f2c7de..5d9be0b8a9 100644 --- a/services/surfaceflinger/SurfaceTracing.cpp +++ b/services/surfaceflinger/SurfaceTracing.cpp @@ -68,8 +68,9 @@ bool SurfaceTracing::addTraceToBuffer(LayersTraceProto& entry) { return mEnabled; } -void SurfaceTracing::notify(const char* where) { +void SurfaceTracing::notify(long compositionTime, const char* where) { std::scoped_lock lock(mSfLock); + mCompositionTime = compositionTime; mWhere = where; mCanStartTrace.notify_one(); } @@ -160,7 +161,7 @@ LayersTraceProto SurfaceTracing::traceLayersLocked(const char* where) { ATRACE_CALL(); LayersTraceProto entry; - entry.set_elapsed_realtime_nanos(elapsedRealtimeNano()); + entry.set_elapsed_realtime_nanos(mCompositionTime); entry.set_where(where); LayersProto layers(mFlinger.dumpDrawingStateProto(mTraceFlags)); entry.mutable_layers()->Swap(&layers); diff --git a/services/surfaceflinger/SurfaceTracing.h b/services/surfaceflinger/SurfaceTracing.h index 4773307a65..395d5622c7 100644 --- a/services/surfaceflinger/SurfaceTracing.h +++ b/services/surfaceflinger/SurfaceTracing.h @@ -46,7 +46,7 @@ public: bool disable(); status_t writeToFile(); bool isEnabled() const; - void notify(const char* where); + void notify(long compositionTime, const char* where); void setBufferSize(size_t bufferSizeInByte); void writeToFileAsync(); @@ -81,6 +81,8 @@ private: std::queue<LayersTraceProto> mStorage; }; + long mCompositionTime; + void mainLoop(); void addFirstEntry(); LayersTraceProto traceWhenNotified(); diff --git a/vulkan/libvulkan/Android.bp b/vulkan/libvulkan/Android.bp index b0c4f3f95a..4d6b2be301 100644 --- a/vulkan/libvulkan/Android.bp +++ b/vulkan/libvulkan/Android.bp @@ -41,12 +41,13 @@ cc_library_shared { "-DVK_NO_PROTOTYPES", "-fvisibility=hidden", "-fstrict-aliasing", - "-Weverything", + "-Wextra", "-Werror", "-Wno-padded", + "-Wno-sign-compare", "-Wno-switch-enum", - "-Wno-undef", - "-Wno-format-pedantic", + "-Wno-unused-variable", + "-Wno-unused-function", // Have clang emit complete debug_info. "-fstandalone-debug", diff --git a/vulkan/nulldrv/Android.bp b/vulkan/nulldrv/Android.bp index dedf419dc3..ba025046fa 100644 --- a/vulkan/nulldrv/Android.bp +++ b/vulkan/nulldrv/Android.bp @@ -23,18 +23,11 @@ cc_library_shared { "-fvisibility=hidden", "-fstrict-aliasing", "-DLOG_TAG=\"vknulldrv\"", - "-Weverything", + "-Wextra", "-Werror", - "-Wno-padded", - "-Wno-undef", - "-Wno-zero-length-array", "-DLOG_NDEBUG=0", ], - cppflags: [ - "-Wno-c++98-compat-pedantic", - "-Wno-c99-extensions", - ], srcs: [ "null_driver.cpp", diff --git a/vulkan/tools/Android.bp b/vulkan/tools/Android.bp index 2514094a15..91d64fe1c9 100644 --- a/vulkan/tools/Android.bp +++ b/vulkan/tools/Android.bp @@ -22,16 +22,8 @@ cc_binary { "-DLOG_TAG=\"vkinfo\"", - "-Weverything", + "-Wextra", "-Werror", - "-Wno-padded", - "-Wno-undef", - "-Wno-switch-enum", - ], - cppflags: [ - "-Wno-c++98-compat-pedantic", - "-Wno-c99-extensions", - "-Wno-old-style-cast", ], srcs: ["vkinfo.cpp"], |