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

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

Snap for 9666816 from e2f2f7f6 to udc-release

Change-Id: I2bcf845e4ceaaee4e63fe619effda9cbad7b52a7
parents c7ec5485 e2f2f7f6
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -2062,6 +2062,8 @@ static void DumpstateTelephonyOnly(const std::string& calling_package) {
               SEC_TO_MSEC(10));
    RunDumpsys("DUMPSYS", {"telephony.registry"}, CommandOptions::WithTimeout(90).Build(),
               SEC_TO_MSEC(10));
    RunDumpsys("DUMPSYS", {"telecom"}, CommandOptions::WithTimeout(90).Build(),
               SEC_TO_MSEC(10));
    if (include_sensitive_info) {
        // Contains raw IP addresses, omit from reports on user builds.
        RunDumpsys("DUMPSYS", {"netd"}, CommandOptions::WithTimeout(90).Build(), SEC_TO_MSEC(10));
+47 −5
Original line number Diff line number Diff line
@@ -16,17 +16,59 @@

#define LOG_TAG "Surface"

#include <gui/view/Surface.h>

#include <android/binder_libbinder.h>
#include <android/binder_parcel.h>
#include <android/native_window.h>
#include <binder/Parcel.h>

#include <utils/Log.h>

#include <gui/IGraphicBufferProducer.h>
#include <gui/Surface.h>
#include <gui/view/Surface.h>
#include <system/window.h>
#include <utils/Log.h>

namespace android {
namespace view {

// Since this is a parcelable utility and we want to keep the wire format stable, only build this
// when building the system libgui to detect any issues loading the wrong libgui from
// libnativewindow

#if (!defined(__ANDROID_APEX__) && !defined(__ANDROID_VNDK__))

extern "C" status_t android_view_Surface_writeToParcel(ANativeWindow* _Nonnull window,
                                                       Parcel* _Nonnull parcel) {
    int value;
    int err = (*window->query)(window, NATIVE_WINDOW_CONCRETE_TYPE, &value);
    if (err != OK || value != NATIVE_WINDOW_SURFACE) {
        ALOGE("Error: ANativeWindow is not backed by Surface");
        return STATUS_BAD_VALUE;
    }
    // Use a android::view::Surface to parcelize the window
    android::view::Surface shimSurface;
    shimSurface.graphicBufferProducer = android::Surface::getIGraphicBufferProducer(window);
    shimSurface.surfaceControlHandle = android::Surface::getSurfaceControlHandle(window);
    return shimSurface.writeToParcel(parcel);
}

extern "C" status_t android_view_Surface_readFromParcel(
        const Parcel* _Nonnull parcel, ANativeWindow* _Nullable* _Nonnull outWindow) {
    // Use a android::view::Surface to unparcel the window
    android::view::Surface shimSurface;
    status_t ret = shimSurface.readFromParcel(parcel);
    if (ret != OK) {
        ALOGE("%s: Error: Failed to create android::view::Surface from AParcel", __FUNCTION__);
        return STATUS_BAD_VALUE;
    }
    auto surface = sp<android::Surface>::make(shimSurface.graphicBufferProducer, false,
                                              shimSurface.surfaceControlHandle);
    ANativeWindow* anw = surface.get();
    ANativeWindow_acquire(anw);
    *outWindow = anw;
    return STATUS_OK;
}

#endif

status_t Surface::writeToParcel(Parcel* parcel) const {
    return writeToParcel(parcel, false);
}
+49 −35
Original line number Diff line number Diff line
@@ -24,14 +24,49 @@

#include <private/android/AHardwareBufferHelpers.h>

#include <android/binder_libbinder.h>
#include <dlfcn.h>
#include <log/log.h>
#include <ui/GraphicBuffer.h>
#include <gui/Surface.h>
#include <gui/view/Surface.h>
#include <android/binder_libbinder.h>

using namespace android;

#if defined(__ANDROID_APEX__) || defined(__ANDROID_VNDK__)
#error libnativewindow can only be built for system
#endif

using android_view_Surface_writeToParcel = status_t (*)(ANativeWindow* _Nonnull window,
                                                        Parcel* _Nonnull parcel);

using android_view_Surface_readFromParcel =
        status_t (*)(const Parcel* _Nonnull parcel, ANativeWindow* _Nullable* _Nonnull outWindow);

struct SurfaceParcelables {
    android_view_Surface_writeToParcel write = nullptr;
    android_view_Surface_readFromParcel read = nullptr;
};

const SurfaceParcelables* getSurfaceParcelFunctions() {
    static SurfaceParcelables funcs = []() -> SurfaceParcelables {
        SurfaceParcelables ret;
        void* dl = dlopen("libgui.so", RTLD_NOW);
        LOG_ALWAYS_FATAL_IF(!dl, "Failed to find libgui.so");
        ret.write =
                (android_view_Surface_writeToParcel)dlsym(dl, "android_view_Surface_writeToParcel");
        LOG_ALWAYS_FATAL_IF(!ret.write,
                            "libgui.so missing android_view_Surface_writeToParcel; "
                            "loaded wrong libgui?");
        ret.read =
                (android_view_Surface_readFromParcel)dlsym(dl,
                                                           "android_view_Surface_readFromParcel");
        LOG_ALWAYS_FATAL_IF(!ret.read,
                            "libgui.so missing android_view_Surface_readFromParcel; "
                            "loaded wrong libgui?");
        return ret;
    }();
    return &funcs;
}

static int32_t query(ANativeWindow* window, int what) {
    int value;
    int res = window->query(window, what, &value);
@@ -64,13 +99,6 @@ static bool isDataSpaceValid(ANativeWindow* window, int32_t dataSpace) {
            return false;
    }
}
static sp<IGraphicBufferProducer> IGraphicBufferProducer_from_ANativeWindow(ANativeWindow* window) {
    return Surface::getIGraphicBufferProducer(window);
}

static sp<IBinder> SurfaceControlHandle_from_ANativeWindow(ANativeWindow* window) {
    return Surface::getSurfaceControlHandle(window);
}

/**************************************************************************************************
 * NDK
@@ -355,38 +383,24 @@ int ANativeWindow_setAutoPrerotation(ANativeWindow* window, bool autoPrerotation

binder_status_t ANativeWindow_readFromParcel(
        const AParcel* _Nonnull parcel, ANativeWindow* _Nullable* _Nonnull outWindow) {
    const Parcel* nativeParcel = AParcel_viewPlatformParcel(parcel);

    // Use a android::view::Surface to unparcel the window
    std::shared_ptr<android::view::Surface> shimSurface = std::shared_ptr<android::view::Surface>();
    status_t ret = shimSurface->readFromParcel(nativeParcel);
    if (ret != OK) {
        ALOGE("%s: Error: Failed to create android::view::Surface from AParcel", __FUNCTION__);
        return STATUS_BAD_VALUE;
    auto funcs = getSurfaceParcelFunctions();
    if (funcs->read == nullptr) {
        ALOGE("Failed to load Surface_readFromParcel implementation");
        return STATUS_FAILED_TRANSACTION;
    }
    sp<Surface> surface = sp<Surface>::make(
            shimSurface->graphicBufferProducer, false, shimSurface->surfaceControlHandle);
    ANativeWindow* anw = surface.get();
    ANativeWindow_acquire(anw);
    *outWindow = anw;
    return STATUS_OK;
    const Parcel* nativeParcel = AParcel_viewPlatformParcel(parcel);
    return funcs->read(nativeParcel, outWindow);
}

binder_status_t ANativeWindow_writeToParcel(
        ANativeWindow* _Nonnull window, AParcel* _Nonnull parcel) {
    int value;
    int err = (*window->query)(window, NATIVE_WINDOW_CONCRETE_TYPE, &value);
    if (err != OK || value != NATIVE_WINDOW_SURFACE) {
        ALOGE("Error: ANativeWindow is not backed by Surface");
        return STATUS_BAD_VALUE;
    auto funcs = getSurfaceParcelFunctions();
    if (funcs->write == nullptr) {
        ALOGE("Failed to load Surface_writeToParcel implementation");
        return STATUS_FAILED_TRANSACTION;
    }
    // Use a android::view::Surface to parcelize the window
    std::shared_ptr<android::view::Surface> shimSurface = std::shared_ptr<android::view::Surface>();
    shimSurface->graphicBufferProducer = IGraphicBufferProducer_from_ANativeWindow(window);
    shimSurface->surfaceControlHandle = SurfaceControlHandle_from_ANativeWindow(window);

    Parcel* nativeParcel = AParcel_viewPlatformParcel(parcel);
    return shimSurface->writeToParcel(nativeParcel);
    return funcs->write(window, nativeParcel);
}

/**************************************************************************************************
+6 −3
Original line number Diff line number Diff line
@@ -139,10 +139,12 @@ public:
    }

    virtual sp<ISensorEventConnection> createSensorDirectConnection(const String16& opPackageName,
            uint32_t size, int32_t type, int32_t format, const native_handle_t *resource) {
            int deviceId, uint32_t size, int32_t type, int32_t format,
            const native_handle_t *resource) {
        Parcel data, reply;
        data.writeInterfaceToken(ISensorServer::getInterfaceDescriptor());
        data.writeString16(opPackageName);
        data.writeInt32(deviceId);
        data.writeUint32(size);
        data.writeInt32(type);
        data.writeInt32(format);
@@ -237,6 +239,7 @@ status_t BnSensorServer::onTransact(
        case CREATE_SENSOR_DIRECT_CONNECTION: {
            CHECK_INTERFACE(ISensorServer, data, reply);
            const String16& opPackageName = data.readString16();
            const int deviceId = data.readInt32();
            uint32_t size = data.readUint32();
            int32_t type = data.readInt32();
            int32_t format = data.readInt32();
@@ -246,8 +249,8 @@ status_t BnSensorServer::onTransact(
                return BAD_VALUE;
            }
            native_handle_set_fdsan_tag(resource);
            sp<ISensorEventConnection> ch =
                    createSensorDirectConnection(opPackageName, size, type, format, resource);
            sp<ISensorEventConnection> ch = createSensorDirectConnection(
                    opPackageName, deviceId, size, type, format, resource);
            native_handle_close_with_tag(resource);
            native_handle_delete(resource);
            reply->writeStrongBinder(IInterface::asBinder(ch));
+7 −1
Original line number Diff line number Diff line
@@ -315,6 +315,12 @@ bool SensorManager::isDataInjectionEnabled() {

int SensorManager::createDirectChannel(
        size_t size, int channelType, const native_handle_t *resourceHandle) {
    static constexpr int DEFAULT_DEVICE_ID = 0;
    return createDirectChannel(DEFAULT_DEVICE_ID, size, channelType, resourceHandle);
}

int SensorManager::createDirectChannel(
        int deviceId, size_t size, int channelType, const native_handle_t *resourceHandle) {
    Mutex::Autolock _l(mLock);
    if (assertStateLocked() != NO_ERROR) {
        return NO_INIT;
@@ -327,7 +333,7 @@ int SensorManager::createDirectChannel(
    }

    sp<ISensorEventConnection> conn =
              mSensorServer->createSensorDirectConnection(mOpPackageName,
              mSensorServer->createSensorDirectConnection(mOpPackageName, deviceId,
                  static_cast<uint32_t>(size),
                  static_cast<int32_t>(channelType),
                  SENSOR_DIRECT_FMT_SENSORS_EVENT, resourceHandle);
Loading