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

Commit 42375b5e authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 13819123 from 1c1c6683 to 25Q4-release

Change-Id: I5eded765c106ccffc65809a05bddb7146fb94bcf
parents 509c1181 1c1c6683
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -21,6 +21,19 @@ package {
    default_applicable_licenses: ["frameworks_native_license"],
}

aconfig_declarations {
    name: "rss_hwm_reset_flags",
    package: "com.android.rss_hwm_reset",
    container: "system",
    srcs: ["rss_hwm_reset.aconfig"],

}

cc_aconfig_library {
    name: "rss_hwm_reset_flags_c_lib",
    aconfig_declarations: "rss_hwm_reset_flags",
}

cc_binary {
    name: "rss_hwm_reset",

@@ -31,6 +44,11 @@ cc_binary {
    shared_libs: [
        "libbase",
        "liblog",
        "libaconfig_storage_read_api_cc",
    ],

    static_libs: [
        "rss_hwm_reset_flags_c_lib",
    ],

    init_rc: ["rss_hwm_reset.rc"],
+9 −0
Original line number Diff line number Diff line
package: "com.android.rss_hwm_reset"
container: "system"

flag {
    name: "enable_reset_dmabuf_rss_hwm"
    namespace: "android_kernel"
    description: "dmabuf accounting enable rss hwm"
    bug: "415360445"
}
+43 −0
Original line number Diff line number Diff line
@@ -30,12 +30,54 @@
#include <dirent.h>

#include <string>
#include <unistd.h>

#include <com_android_rss_hwm_reset.h>
#include <android-base/file.h>
#include <android-base/stringprintf.h>
#include <log/log.h>

using ::com::android::rss_hwm_reset::enable_reset_dmabuf_rss_hwm;

namespace {
enum DmabufRssHwmState {
    UNKNOWN,
    EXISTS,
    MISSING
};

// Resets dmabuf RSS HWM counter for the selected process by writing 0 to
// /proc/PID/dmabuf_rss_hwm.
void reset_dmabuf_rss_hwm(const char* pid) {
    if (!enable_reset_dmabuf_rss_hwm()) return;

    // If kernel does not support dmabuf_rss_hwm return immediately
    static DmabufRssHwmState dmabuf_rss_hwm_state = UNKNOWN;

    if (dmabuf_rss_hwm_state == MISSING) return;

    std::string dmabuf_rss_hwm_path =
            ::android::base::StringPrintf("/proc/%s/dmabuf_rss_hwm", pid);

    if (dmabuf_rss_hwm_state == UNKNOWN) {
        // File existence check can be done for any PID
        if (::access(dmabuf_rss_hwm_path.c_str(), F_OK) != 0) {
            std::string pid_path = ::android::base::StringPrintf("/proc/%s", pid);

            // Confirm that the entire process did not disappear
            if (::access(pid_path.c_str(), F_OK) == 0) {
                dmabuf_rss_hwm_state = MISSING;
            }
            return;
        }
        dmabuf_rss_hwm_state = EXISTS;
    }

    if (!::android::base::WriteStringToFile("0", dmabuf_rss_hwm_path)) {
        ALOGE("unable to write %s", dmabuf_rss_hwm_path.c_str());
    }
}

// Resets RSS HWM counter for the selected process by writing 5 to
// /proc/PID/clear_refs.
void reset_rss_hwm(const char* pid) {
@@ -66,6 +108,7 @@ int main(int /* argc */, char** /* argv[] */) {

        pid = entry->d_name;
        reset_rss_hwm(pid);
        reset_dmabuf_rss_hwm(pid);
    }
    closedir(dirp);
    return 0;
+20 −6
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@
#include <android/os/IInputConstants.h>
#include <android/os/MotionEventFlag.h>
#endif
#include <android/os/PointerCaptureMode.h>
#include <android/os/PointerIconType.h>
#include <ftl/flags.h>
#include <math.h>
@@ -1284,23 +1285,36 @@ public:
    TouchModeEvent* createTouchModeEvent() override { return new TouchModeEvent(); };
};

/** Modes in which the pointer can be captured by a window. */
enum class PointerCaptureMode : int32_t {
    UNCAPTURED = static_cast<int32_t>(::android::os::PointerCaptureMode::UNCAPTURED),
    ABSOLUTE = static_cast<int32_t>(::android::os::PointerCaptureMode::ABSOLUTE),
    ftl_first = UNCAPTURED,
    ftl_last = ABSOLUTE,
};

/*
 * Describes a unique request to enable or disable Pointer Capture.
 */
struct PointerCaptureRequest {
public:
    inline PointerCaptureRequest() : window(), seq(0) {}
    inline PointerCaptureRequest(sp<IBinder> window, uint32_t seq) : window(window), seq(seq) {}
    inline PointerCaptureRequest() : window(), mode(PointerCaptureMode::UNCAPTURED), seq(0) {}
    inline PointerCaptureRequest(sp<IBinder> window, uint32_t seq)
          : window(window), mode(PointerCaptureMode::ABSOLUTE), seq(seq) {}
    inline bool operator==(const PointerCaptureRequest& other) const {
        return window == other.window && seq == other.seq;
        return window == other.window && mode == other.mode && seq == other.seq;
    }
    inline bool isEnable() const {
        return mode != PointerCaptureMode::UNCAPTURED && window != nullptr;
    }
    inline bool isEnable() const { return window != nullptr; }

    // The requesting window.
    // If the request is to enable the capture, this is the input token of the window that requested
    // pointer capture. Otherwise, this is nullptr.
    // If the request is for a mode other than UNCAPTURED, this is the input token of the window
    // that requested pointer capture. Otherwise, this is nullptr.
    sp<IBinder> window;

    PointerCaptureMode mode;

    // The sequence number for the request.
    uint32_t seq;
};
+21 −1
Original line number Diff line number Diff line
@@ -18,15 +18,27 @@
#include <cutils/ashmem.h>
#include <fcntl.h>

#include <android-base/file.h>
#include <android-base/stringprintf.h>

#include <gtest/gtest.h>
using namespace android;
#ifdef __BIONIC__
static bool is_memfd_fd(int fd) {
    std::string fd_path = android::base::StringPrintf("/proc/self/fd/%d", fd);
    std::string result;
    if (!android::base::Readlink(fd_path, &result)) {
        return false;
    }
    return result.starts_with("/memfd:");
}

TEST(MemoryHeapBase, ForceMemfdRespected) {
    auto mHeap = sp<MemoryHeapBase>::make(10, MemoryHeapBase::FORCE_MEMFD, "Test mapping");
    ASSERT_NE(mHeap.get(), nullptr);
    int fd = mHeap->getHeapID();
    EXPECT_NE(fd, -1);
    EXPECT_FALSE(ashmem_valid(fd));
    EXPECT_TRUE(is_memfd_fd(fd));
    EXPECT_NE(fcntl(fd, F_GET_SEALS), -1);
}

@@ -37,6 +49,7 @@ TEST(MemoryHeapBase, MemfdSealed) {
    ASSERT_NE(mHeap.get(), nullptr);
    int fd = mHeap->getHeapID();
    EXPECT_NE(fd, -1);
    EXPECT_TRUE(is_memfd_fd(fd));
    EXPECT_EQ(fcntl(fd, F_GET_SEALS), F_SEAL_GROW | F_SEAL_SHRINK | F_SEAL_SEAL);
    EXPECT_EQ(ftruncate(fd, 4096), -1);
}
@@ -49,6 +62,7 @@ TEST(MemoryHeapBase, MemfdUnsealed) {
    ASSERT_NE(mHeap.get(), nullptr);
    int fd = mHeap->getHeapID();
    EXPECT_NE(fd, -1);
    EXPECT_TRUE(is_memfd_fd(fd));
    EXPECT_EQ(fcntl(fd, F_GET_SEALS), F_SEAL_GROW | F_SEAL_SHRINK);
    EXPECT_EQ(ftruncate(fd, 4096), -1);
}
@@ -61,6 +75,7 @@ TEST(MemoryHeapBase, MemfdSealedProtected) {
    ASSERT_NE(mHeap.get(), nullptr);
    int fd = mHeap->getHeapID();
    EXPECT_NE(fd, -1);
    EXPECT_TRUE(is_memfd_fd(fd));
    EXPECT_EQ(fcntl(fd, F_GET_SEALS),
              F_SEAL_GROW | F_SEAL_SHRINK | F_SEAL_SEAL | F_SEAL_FUTURE_WRITE);
    EXPECT_EQ(ftruncate(fd, 4096), -1);
@@ -75,6 +90,7 @@ TEST(MemoryHeapBase, MemfdUnsealedProtected) {
    ASSERT_NE(mHeap.get(), nullptr);
    int fd = mHeap->getHeapID();
    EXPECT_NE(fd, -1);
    EXPECT_TRUE(is_memfd_fd(fd));
    EXPECT_EQ(fcntl(fd, F_GET_SEALS), F_SEAL_GROW | F_SEAL_SHRINK | F_SEAL_FUTURE_WRITE);
    EXPECT_EQ(ftruncate(fd, 4096), -1);
}
@@ -88,6 +104,8 @@ TEST(MemoryHeapBase, HostMemfdExpected) {
    int fd = mHeap->getHeapID();
    void* ptr = mHeap->getBase();
    EXPECT_NE(ptr, MAP_FAILED);
    // ashmem_valid() is fine for this test, because there's no explicit expectation of having a
    // memfd.
    EXPECT_TRUE(ashmem_valid(fd));
    EXPECT_EQ(mHeap->getFlags(), MemoryHeapBase::READ_ONLY);
}
@@ -102,6 +120,8 @@ TEST(MemoryHeapBase,HostMemfdException) {
    int fd = mHeap->getHeapID();
    void* ptr = mHeap->getBase();
    EXPECT_EQ(mHeap->getFlags(), MemoryHeapBase::READ_ONLY);
    // ashmem_valid() is fine for this test, because there's no explicit expectation of having a
    // memfd.
    EXPECT_TRUE(ashmem_valid(fd));
    EXPECT_NE(ptr, MAP_FAILED);
}
Loading