external: Update android-jni-wrap

This commit is contained in:
Jarvis Huang 2023-09-26 14:20:19 +08:00 committed by Jakob Bornecrantz
parent 3587d79494
commit 4f90666b75
6 changed files with 289 additions and 114 deletions

View file

@ -1,4 +1,4 @@
// Copyright 2022, Qualcomm Innovation Center, Inc.
// Copyright 2022-2023, Qualcomm Innovation Center, Inc.
// SPDX-License-Identifier: BSL-1.0
// Author: Jarvis Huang
@ -6,9 +6,23 @@
namespace wrap {
namespace android::hardware::display {
DisplayManager::Meta::Meta()
DisplayManager::Meta::Meta(bool deferDrop)
: MetaBaseDroppable(DisplayManager::getTypeName()),
getDisplay(classRef().getMethod("getDisplay", "(I)Landroid/view/Display;")) {
DISPLAY_CATEGORY_PRESENTATION(classRef(),
"DISPLAY_CATEGORY_PRESENTATION"),
getDisplay(
classRef().getMethod("getDisplay", "(I)Landroid/view/Display;")),
getDisplays(
classRef().getMethod("getDisplays", "()[Landroid/view/Display;")),
getDisplays1(classRef().getMethod(
"getDisplays", "(Ljava/lang/String;)[Landroid/view/Display;")) {
if (!deferDrop) {
MetaBaseDroppable::dropClassRef();
}
}
DeviceProductInfo::Meta::Meta()
: MetaBaseDroppable(DeviceProductInfo::getTypeName()),
getName(classRef().getMethod("getName", "()Ljava/lang/String;")) {
MetaBaseDroppable::dropClassRef();
}
} // namespace android::hardware::display

View file

@ -1,10 +1,11 @@
// Copyright 2022, Qualcomm Innovation Center, Inc.
// Copyright 2022-2023, Qualcomm Innovation Center, Inc.
// SPDX-License-Identifier: BSL-1.0
// Author: Jarvis Huang
#pragma once
#include "ObjectWrapperBase.h"
#include <string>
namespace wrap {
namespace android::view {
@ -24,22 +25,98 @@ class DisplayManager : public ObjectWrapperBase {
return "android/hardware/display/DisplayManager";
}
/*!
* Getter for the DISPLAY_CATEGORY_PRESENTATION static field value
*
* Java prototype:
* `public static final java.lang.String DISPLAY_CATEGORY_PRESENTATION;`
*
* JNI signature: Ljava/lang/String;
*
*/
static std::string DISPLAY_CATEGORY_PRESENTATION();
/*!
* Wrapper for the getDisplay method
*
* Java prototype:
* `public Display getDisplay(int)`
* `public android.view.Display getDisplay(int);`
*
* JNI signature: (I)Landroid/view/Display;
*
*/
android::view::Display getDisplay(int32_t displayId);
view::Display getDisplay(int32_t displayId) const;
/*!
* Wrapper for the getDisplays method
*
* Java prototype:
* `public android.view.Display[] getDisplays();`
*
* JNI signature: ()[Landroid/view/Display;
*
*/
jni::Array<jni::Object> getDisplays() const;
/*!
* Wrapper for the getDisplays method
*
* Java prototype:
* `public android.view.Display[] getDisplays(java.lang.String);`
*
* JNI signature: (Ljava/lang/String;)[Landroid/view/Display;
*
*/
jni::Array<jni::Object> getDisplays(std::string const &category);
/*!
* Class metadata
*/
struct Meta : public MetaBaseDroppable {
impl::StaticFieldId<std::string> DISPLAY_CATEGORY_PRESENTATION;
jni::method_t getDisplay;
jni::method_t getDisplays;
jni::method_t getDisplays1;
/*!
* Singleton accessor
*/
static Meta &data(bool deferDrop = false) {
static Meta instance{deferDrop};
return instance;
}
private:
explicit Meta(bool deferDrop);
};
};
/*!
* Wrapper for android.hardware.display.DeviceProductInfo objects.
*/
class DeviceProductInfo : public ObjectWrapperBase {
public:
using ObjectWrapperBase::ObjectWrapperBase;
static constexpr const char *getTypeName() noexcept {
return "android/hardware/display/DeviceProductInfo";
}
/*!
* Wrapper for the getName method
*
* Java prototype:
* `public java.lang.String getName();`
*
* JNI signature: ()Ljava/lang/String;
*
*/
std::string getName() const;
/*!
* Class metadata
*/
struct Meta : public MetaBaseDroppable {
jni::method_t getName;
/*!
* Singleton accessor

View file

@ -1,4 +1,4 @@
// Copyright 2022, Qualcomm Innovation Center, Inc.
// Copyright 2022-2023, Qualcomm Innovation Center, Inc.
// SPDX-License-Identifier: BSL-1.0
// Author: Jarvis Huang
// Inline implementations: do not include on its own!
@ -6,13 +6,46 @@
#pragma once
#include "android.view.h"
#include <string>
namespace wrap {
namespace android::hardware::display {
inline android::view::Display DisplayManager::getDisplay(int32_t displayId) {
assert(!isNull());
return android::view::Display(
object().call<jni::Object>(Meta::data().getDisplay, displayId));
inline std::string DisplayManager::DISPLAY_CATEGORY_PRESENTATION() {
auto &data = Meta::data(true);
auto ret = get(data.DISPLAY_CATEGORY_PRESENTATION, data.clazz());
data.dropClassRef();
return ret;
}
inline view::Display DisplayManager::getDisplay(int32_t displayId) const {
assert(!isNull());
return view::Display(
object().call<jni::Object>(Meta::data().getDisplay, displayId));
}
inline jni::Array<jni::Object> DisplayManager::getDisplays() const {
assert(!isNull());
return jni::Array<jni::Object>(
(jobjectArray)object()
.call<jni::Object>(Meta::data().getDisplays)
.getHandle(),
0);
}
inline jni::Array<jni::Object>
DisplayManager::getDisplays(std::string const &category) {
assert(!isNull());
return jni::Array<jni::Object>(
(jobjectArray)object()
.call<jni::Object>(Meta::data().getDisplays1, category)
.getHandle(),
0);
}
inline std::string DeviceProductInfo::getName() const {
assert(!isNull());
return object().call<std::string>(Meta::data().getName);
}
} // namespace android::hardware::display
} // namespace wrap

View file

@ -9,11 +9,15 @@ namespace android::view {
Display::Meta::Meta(bool deferDrop)
: MetaBaseDroppable(Display::getTypeName()),
DEFAULT_DISPLAY(classRef(), "DEFAULT_DISPLAY"),
getDisplayId(classRef().getMethod("getDisplayId", "()I")),
getName(classRef().getMethod("getName", "()Ljava/lang/String;")),
getDeviceProductInfo(classRef().getMethod(
"getDeviceProductInfo",
"()Landroid/hardware/display/DeviceProductInfo;")),
getRealSize(
classRef().getMethod("getRealSize", "(Landroid/graphics/Point;)V")),
getRealMetrics(classRef().getMethod("getRealMetrics",
"(Landroid/util/DisplayMetrics;)V")),
getDisplayId(classRef().getMethod("getDisplayId", "()I")) {
"(Landroid/util/DisplayMetrics;)V")) {
if (!deferDrop) {
MetaBaseDroppable::dropClassRef();
}
@ -30,25 +34,23 @@ SurfaceHolder::Meta::Meta()
MetaBaseDroppable::dropClassRef();
}
WindowManager::Meta::Meta()
: MetaBaseDroppable(WindowManager::getTypeName()),
getDefaultDisplay(
classRef().getMethod("getDefaultDisplay", "()Landroid/view/Display;")) {
: MetaBaseDroppable(WindowManager::getTypeName()),
getDefaultDisplay(classRef().getMethod("getDefaultDisplay",
"()Landroid/view/Display;")) {
MetaBaseDroppable::dropClassRef();
}
WindowManager_LayoutParams::Meta::Meta(bool deferDrop)
: MetaBaseDroppable(WindowManager_LayoutParams::getTypeName()),
TYPE_APPLICATION(classRef(), "TYPE_APPLICATION"),
TYPE_APPLICATION_OVERLAY(classRef(), "TYPE_APPLICATION_OVERLAY"),
FLAG_FULLSCREEN(classRef(), "FLAG_FULLSCREEN"),
FLAG_NOT_FOCUSABLE(classRef(), "FLAG_NOT_FOCUSABLE"),
FLAG_NOT_TOUCHABLE(classRef(), "FLAG_NOT_TOUCHABLE"),
init(classRef().getMethod("<init>", "()V")),
init1(classRef().getMethod("<init>", "(I)V")),
init2(classRef().getMethod("<init>", "(II)V")) {
if (!deferDrop) {
MetaBaseDroppable::dropClassRef();
}
}
WindowManager_LayoutParams::Meta::Meta()
: MetaBase(WindowManager_LayoutParams::getTypeName()),
FLAG_FULLSCREEN(classRef(), "FLAG_FULLSCREEN"),
FLAG_NOT_FOCUSABLE(classRef(), "FLAG_NOT_FOCUSABLE"),
FLAG_NOT_TOUCHABLE(classRef(), "FLAG_NOT_TOUCHABLE"),
TYPE_APPLICATION(classRef(), "TYPE_APPLICATION"),
TYPE_APPLICATION_OVERLAY(classRef(), "TYPE_APPLICATION_OVERLAY"),
init(classRef().getMethod("<init>", "()V")),
init1(classRef().getMethod("<init>", "(I)V")),
init2(classRef().getMethod("<init>", "(II)V")),
setTitle(
classRef().getMethod("setTitle", "(Ljava/lang/CharSequence;)V")) {}
Display_Mode::Meta::Meta() : MetaBaseDroppable(Display_Mode::getTypeName()),
getModeId(classRef().getMethod("getModeId", "()I")),
getPhysicalHeight(classRef().getMethod("getPhysicalHeight", "()I")),

View file

@ -11,12 +11,18 @@ namespace android::graphics {
class Point;
} // namespace android::graphics
namespace android::hardware::display {
class DeviceProductInfo;
} // namespace android::hardware::display
namespace android::util {
class DisplayMetrics;
} // namespace android::util
namespace android::view {
class Display;
class Surface;
class WindowManager_LayoutParams;
} // namespace android::view
} // namespace wrap
@ -44,6 +50,40 @@ class Display : public ObjectWrapperBase {
*/
static int32_t DEFAULT_DISPLAY();
/*!
* Wrapper for the getDisplayId method
*
* Java prototype:
* `public int getDisplayId();`
*
* JNI signature: ()I
*
*/
int32_t getDisplayId() const;
/*!
* Wrapper for the getName method
*
* Java prototype:
* `public java.lang.String getName();`
*
* JNI signature: ()Ljava/lang/String;
*
*/
std::string getName() const;
/*!
* Wrapper for the getDeviceProductInfo method
*
* Java prototype:
* `public android.hardware.display.DeviceProductInfo
* getDeviceProductInfo();`
*
* JNI signature: ()Landroid/hardware/display/DeviceProductInfo;
*
*/
hardware::display::DeviceProductInfo getDeviceProductInfo() const;
/*!
* Wrapper for the getRealSize method
*
@ -66,25 +106,16 @@ class Display : public ObjectWrapperBase {
*/
void getRealMetrics(util::DisplayMetrics &out_displayMetrics);
/*!
* Wrapper for the getDisplayId method
*
* Java prototype:
* `public int getDisplayId();`
*
* JNI signature: ()I
*
*/
int32_t getDisplayId();
/*!
* Class metadata
*/
struct Meta : public MetaBaseDroppable {
impl::StaticFieldId<int32_t> DEFAULT_DISPLAY;
jni::method_t getDisplayId;
jni::method_t getName;
jni::method_t getDeviceProductInfo;
jni::method_t getRealSize;
jni::method_t getRealMetrics;
jni::method_t getDisplayId;
/*!
* Singleton accessor
@ -95,7 +126,7 @@ class Display : public ObjectWrapperBase {
}
private:
Meta(bool deferDrop);
explicit Meta(bool deferDrop);
};
};
@ -183,7 +214,7 @@ class SurfaceHolder : public ObjectWrapperBase {
* Wrapper for android.view.WindowManager objects.
*/
class WindowManager : public ObjectWrapperBase {
public:
public:
using ObjectWrapperBase::ObjectWrapperBase;
static constexpr const char *getTypeName() noexcept {
return "android/view/WindowManager";
@ -198,7 +229,7 @@ public:
* JNI signature: ()Landroid/view/Display;
*
*/
Display getDefaultDisplay();
Display getDefaultDisplay() const;
/*!
* Class metadata
@ -214,43 +245,21 @@ public:
return instance;
}
private:
private:
Meta();
};
};
/*!
* Wrapper for android.view.WindowManager objects.
* Wrapper for android.view.WindowManager$LayoutParams objects.
*/
class WindowManager_LayoutParams : public ObjectWrapperBase {
public:
public:
using ObjectWrapperBase::ObjectWrapperBase;
static constexpr const char *getTypeName() noexcept {
return "android/view/WindowManager$LayoutParams";
}
/*!
* Getter for the TYPE_APPLICATION static field value
*
* Java prototype:
* `public static final int TYPE_APPLICATION;`
*
* JNI signature: I
*
*/
static int32_t TYPE_APPLICATION();
/*!
* Getter for the TYPE_APPLICATION_OVERLAY static field value
*
* Java prototype:
* `public static final int TYPE_APPLICATION_OVERLAY;`
*
* JNI signature: I
*
*/
static int32_t TYPE_APPLICATION_OVERLAY();
/*!
* Getter for the FLAG_FULLSCREEN static field value
*
@ -284,6 +293,28 @@ public:
*/
static int32_t FLAG_NOT_TOUCHABLE();
/*!
* Getter for the TYPE_APPLICATION static field value
*
* Java prototype:
* `public static final int TYPE_APPLICATION;`
*
* JNI signature: I
*
*/
static int32_t TYPE_APPLICATION();
/*!
* Getter for the TYPE_APPLICATION_OVERLAY static field value
*
* Java prototype:
* `public static final int TYPE_APPLICATION_OVERLAY;`
*
* JNI signature: I
*
*/
static int32_t TYPE_APPLICATION_OVERLAY();
/*!
* Wrapper for a constructor
*
@ -317,29 +348,41 @@ public:
*/
static WindowManager_LayoutParams construct(int32_t type, int32_t flags);
/*!
* Wrapper for the setTitle method
*
* Java prototype:
* `public final void setTitle(java.lang.CharSequence);`
*
* JNI signature: (Ljava/lang/CharSequence;)V
*
*/
void setTitle(std::string const &title);
/*!
* Class metadata
*/
struct Meta : public MetaBaseDroppable {
impl::StaticFieldId<int32_t> TYPE_APPLICATION;
impl::StaticFieldId<int32_t> TYPE_APPLICATION_OVERLAY;
struct Meta : public MetaBase {
impl::StaticFieldId<int32_t> FLAG_FULLSCREEN;
impl::StaticFieldId<int32_t> FLAG_NOT_FOCUSABLE;
impl::StaticFieldId<int32_t> FLAG_NOT_TOUCHABLE;
impl::StaticFieldId<int32_t> TYPE_APPLICATION;
impl::StaticFieldId<int32_t> TYPE_APPLICATION_OVERLAY;
jni::method_t init;
jni::method_t init1;
jni::method_t init2;
jni::method_t setTitle;
/*!
* Singleton accessor
*/
static Meta &data(bool deferDrop = false) {
static Meta instance{deferDrop};
static Meta &data() {
static Meta instance{};
return instance;
}
private:
Meta(bool deferDrop);
private:
Meta();
};
};

View file

@ -6,7 +6,9 @@
#pragma once
#include "android.graphics.h"
#include "android.hardware.display.h"
#include "android.util.h"
#include <string>
namespace wrap {
namespace android::view {
@ -17,6 +19,23 @@ inline int32_t Display::DEFAULT_DISPLAY() {
return ret;
}
inline int32_t Display::getDisplayId() const {
assert(!isNull());
return object().call<int32_t>(Meta::data().getDisplayId);
}
inline std::string Display::getName() const {
assert(!isNull());
return object().call<std::string>(Meta::data().getName);
}
inline hardware::display::DeviceProductInfo
Display::getDeviceProductInfo() const {
assert(!isNull());
return hardware::display::DeviceProductInfo(
object().call<jni::Object>(Meta::data().getDeviceProductInfo));
}
inline void Display::getRealSize(graphics::Point &out_size) {
assert(!isNull());
return object().call<void>(Meta::data().getRealSize, out_size.object());
@ -28,11 +47,6 @@ inline void Display::getRealMetrics(util::DisplayMetrics &out_displayMetrics) {
out_displayMetrics.object());
}
inline int32_t Display::getDisplayId() {
assert(!isNull());
return object().call<int32_t>(Meta::data().getDisplayId);
}
inline bool Surface::isValid() const {
assert(!isNull());
return object().call<bool>(Meta::data().isValid);
@ -43,59 +57,51 @@ inline Surface SurfaceHolder::getSurface() {
return Surface(object().call<jni::Object>(Meta::data().getSurface));
}
inline Display WindowManager::getDefaultDisplay() {
inline Display WindowManager::getDefaultDisplay() const {
assert(!isNull());
return Display(object().call<jni::Object>(Meta::data().getDefaultDisplay));
}
inline int32_t WindowManager_LayoutParams::TYPE_APPLICATION() {
auto &data = Meta::data(true);
auto ret = get(data.TYPE_APPLICATION, data.clazz());
data.dropClassRef();
return ret;
}
inline int32_t WindowManager_LayoutParams::TYPE_APPLICATION_OVERLAY() {
auto &data = Meta::data(true);
auto ret = get(data.TYPE_APPLICATION_OVERLAY, data.clazz());
data.dropClassRef();
return ret;
}
inline int32_t WindowManager_LayoutParams::FLAG_FULLSCREEN() {
auto &data = Meta::data(true);
auto ret = get(data.FLAG_FULLSCREEN, data.clazz());
data.dropClassRef();
return ret;
return get(Meta::data().FLAG_FULLSCREEN, Meta::data().clazz());
}
inline int32_t WindowManager_LayoutParams::FLAG_NOT_FOCUSABLE() {
auto &data = Meta::data(true);
auto ret = get(data.FLAG_NOT_FOCUSABLE, data.clazz());
data.dropClassRef();
return ret;
return get(Meta::data().FLAG_NOT_FOCUSABLE, Meta::data().clazz());
}
inline int32_t WindowManager_LayoutParams::FLAG_NOT_TOUCHABLE() {
auto &data = Meta::data(true);
auto ret = get(data.FLAG_NOT_TOUCHABLE, data.clazz());
data.dropClassRef();
return ret;
return get(Meta::data().FLAG_NOT_TOUCHABLE, Meta::data().clazz());
}
inline int32_t WindowManager_LayoutParams::TYPE_APPLICATION() {
return get(Meta::data().TYPE_APPLICATION, Meta::data().clazz());
}
inline int32_t WindowManager_LayoutParams::TYPE_APPLICATION_OVERLAY() {
return get(Meta::data().TYPE_APPLICATION_OVERLAY, Meta::data().clazz());
}
inline WindowManager_LayoutParams WindowManager_LayoutParams::construct() {
return WindowManager_LayoutParams(
Meta::data().clazz().newInstance(Meta::data().init));
Meta::data().clazz().newInstance(Meta::data().init));
}
inline WindowManager_LayoutParams WindowManager_LayoutParams::construct(int32_t type) {
inline WindowManager_LayoutParams
WindowManager_LayoutParams::construct(int32_t type) {
return WindowManager_LayoutParams(
Meta::data().clazz().newInstance(Meta::data().init1, type));
Meta::data().clazz().newInstance(Meta::data().init1, type));
}
inline WindowManager_LayoutParams WindowManager_LayoutParams::construct(int32_t type, int32_t flags) {
inline WindowManager_LayoutParams
WindowManager_LayoutParams::construct(int32_t type, int32_t flags) {
return WindowManager_LayoutParams(
Meta::data().clazz().newInstance(Meta::data().init2, type, flags));
Meta::data().clazz().newInstance(Meta::data().init2, type, flags));
}
inline void WindowManager_LayoutParams::setTitle(std::string const &title) {
assert(!isNull());
return object().call<void>(Meta::data().setTitle, title);
}
inline int Display_Mode::getModeId() {