android-jni-wrap: Update to add more things

This commit is contained in:
Ryan Pavlik 2023-04-24 11:43:30 -05:00
parent aa052046a8
commit f57bc4a849
9 changed files with 93 additions and 68 deletions

View file

@ -1,4 +1,4 @@
// Copyright 2020-2021, Collabora, Ltd. // Copyright 2020-2023, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0 // SPDX-License-Identifier: BSL-1.0
// Author: Ryan Pavlik <ryan.pavlik@collabora.com> // Author: Ryan Pavlik <ryan.pavlik@collabora.com>
@ -18,19 +18,20 @@ Context::Meta::Meta(bool deferDrop)
"getApplicationContext", "()Landroid/content/Context;")), "getApplicationContext", "()Landroid/content/Context;")),
getClassLoader( getClassLoader(
classRef().getMethod("getClassLoader", "()Ljava/lang/ClassLoader;")), classRef().getMethod("getClassLoader", "()Ljava/lang/ClassLoader;")),
getExternalFilesDir(classRef().getMethod(
"getExternalFilesDir", "(Ljava/lang/String;)Ljava/io/File;")),
startActivity( startActivity(
classRef().getMethod("startActivity", "(Landroid/content/Intent;)V")), classRef().getMethod("startActivity", "(Landroid/content/Intent;)V")),
startActivity1(classRef().getMethod( startActivity1(classRef().getMethod(
"startActivity", "(Landroid/content/Intent;Landroid/os/Bundle;)V")), "startActivity", "(Landroid/content/Intent;Landroid/os/Bundle;)V")),
getSystemService(classRef().getMethod(
"getSystemService", "(Ljava/lang/String;)Ljava/lang/Object;")),
createPackageContext(classRef().getMethod( createPackageContext(classRef().getMethod(
"createPackageContext", "createPackageContext",
"(Ljava/lang/String;I)Landroid/content/Context;")), "(Ljava/lang/String;I)Landroid/content/Context;")),
createDisplayContext(classRef().getMethod( createDisplayContext(classRef().getMethod(
"createDisplayContext", "(Landroid/view/Display;)Landroid/content/Context;")), "createDisplayContext",
getSystemService(classRef().getMethod( "(Landroid/view/Display;)Landroid/content/Context;")) {
"getSystemService", "(Ljava/lang/String;)Ljava/lang/Object;")),
getExternalFilesDir(classRef().getMethod(
"getExternalFilesDir", "(Ljava/lang/String;)Ljava/io/File;")) {
if (!deferDrop) { if (!deferDrop) {
MetaBaseDroppable::dropClassRef(); MetaBaseDroppable::dropClassRef();
} }

View file

@ -8,10 +8,6 @@
#include <string> #include <string>
namespace wrap { namespace wrap {
namespace java::io {
class File;
} // namespace java::io
namespace android::content { namespace android::content {
class ComponentName; class ComponentName;
class ContentResolver; class ContentResolver;
@ -32,13 +28,17 @@ class Uri;
class Uri_Builder; class Uri_Builder;
} // namespace android::net } // namespace android::net
namespace android::os {
class Bundle;
} // namespace android::os
namespace android::view { namespace android::view {
class Display; class Display;
} // namespace android::view } // namespace android::view
namespace android::os { namespace java::io {
class Bundle; class File;
} // namespace android::os } // namespace java::io
namespace java::lang { namespace java::lang {
class Class; class Class;
@ -125,6 +125,17 @@ class Context : public ObjectWrapperBase {
*/ */
java::lang::ClassLoader getClassLoader(); java::lang::ClassLoader getClassLoader();
/*!
* Wrapper for the getExternalFilesDir method
*
* Java prototype:
* `public abstract java.io.File getExternalFilesDir(java.lang.String);`
*
* JNI signature: (Ljava/lang/String;)Ljava/io/File;
*
*/
java::io::File getExternalFilesDir(std::string const &type);
/*! /*!
* Wrapper for the startActivity method * Wrapper for the startActivity method
* *
@ -148,6 +159,17 @@ class Context : public ObjectWrapperBase {
*/ */
void startActivity(Intent const &intent, os::Bundle const &bundle); void startActivity(Intent const &intent, os::Bundle const &bundle);
/*!
* Wrapper for the getSystemService method
*
* Java prototype:
* `public abstract java.lang.Object getSystemService(java.lang.String);`
*
* JNI signature: (Ljava/lang/String;)Ljava/lang/Object;
*
*/
jni::Object getSystemService(std::string const &name);
/*! /*!
* Wrapper for the createPackageContext method * Wrapper for the createPackageContext method
* *
@ -165,34 +187,13 @@ class Context : public ObjectWrapperBase {
* Wrapper for the createDisplayContext method * Wrapper for the createDisplayContext method
* *
* Java prototype: * Java prototype:
* `public abstract Context createDisplayContext(android.view.Display display)` * `public abstract android.content.Context
* createDisplayContext(android.view.Display);`
* *
* JNI signature: (Landroid/view/Display;)Landroid/content/Context; * JNI signature: (Landroid/view/Display;)Landroid/content/Context;
* *
*/ */
Context createDisplayContext(wrap::android::view::Display const &display); Context createDisplayContext(view::Display const &display);
/*!
* Wrapper for the getSystemService method
*
* Java prototype:
* `public abstract java.lang.Object getSystemService(java.lang.String);`
*
* JNI signature: (Ljava/lang/String;)Ljava/lang/Object;
*
*/
jni::Object getSystemService(std::string const &name);
/*!
* Wrapper for the getExternalFilesDir method
*
* Java prototype:
* `public abstract java.io.File getExternalFilesDir(java.lang.String);`
*
* JNI signature: (Ljava/lang/String;)Ljava/io/File;
*
*/
java::io::File getExternalFilesDir(std::string const &type);
enum { enum {
CONTEXT_INCLUDE_CODE = 1, CONTEXT_INCLUDE_CODE = 1,
@ -209,12 +210,12 @@ class Context : public ObjectWrapperBase {
jni::method_t getContentResolver; jni::method_t getContentResolver;
jni::method_t getApplicationContext; jni::method_t getApplicationContext;
jni::method_t getClassLoader; jni::method_t getClassLoader;
jni::method_t getExternalFilesDir;
jni::method_t startActivity; jni::method_t startActivity;
jni::method_t startActivity1; jni::method_t startActivity1;
jni::method_t getSystemService;
jni::method_t createPackageContext; jni::method_t createPackageContext;
jni::method_t createDisplayContext; jni::method_t createDisplayContext;
jni::method_t getSystemService;
jni::method_t getExternalFilesDir;
/*! /*!
* Singleton accessor * Singleton accessor

View file

@ -1,4 +1,4 @@
// Copyright 2020-2021, Collabora, Ltd. // Copyright 2020-2023, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0 // SPDX-License-Identifier: BSL-1.0
// Author: Ryan Pavlik <ryan.pavlik@collabora.com> // Author: Ryan Pavlik <ryan.pavlik@collabora.com>
// Inline implementations: do not include on its own! // Inline implementations: do not include on its own!
@ -54,6 +54,12 @@ inline java::lang::ClassLoader Context::getClassLoader() {
object().call<jni::Object>(Meta::data().getClassLoader)); object().call<jni::Object>(Meta::data().getClassLoader));
} }
inline java::io::File Context::getExternalFilesDir(std::string const &type) {
assert(!isNull());
return java::io::File(
object().call<jni::Object>(Meta::data().getExternalFilesDir, type));
}
inline void Context::startActivity(Intent const &intent) { inline void Context::startActivity(Intent const &intent) {
assert(!isNull()); assert(!isNull());
return object().call<void>(Meta::data().startActivity, intent.object()); return object().call<void>(Meta::data().startActivity, intent.object());
@ -66,6 +72,11 @@ inline void Context::startActivity(Intent const &intent,
bundle.object()); bundle.object());
} }
inline jni::Object Context::getSystemService(std::string const &name) {
assert(!isNull());
return object().call<jni::Object>(Meta::data().getSystemService, name);
}
inline Context Context::createPackageContext(std::string const &packageName, inline Context Context::createPackageContext(std::string const &packageName,
int32_t flags) { int32_t flags) {
assert(!isNull()); assert(!isNull());
@ -73,19 +84,10 @@ inline Context Context::createPackageContext(std::string const &packageName,
packageName, flags)); packageName, flags));
} }
inline Context Context::createDisplayContext(const wrap::android::view::Display &display) { inline Context Context::createDisplayContext(view::Display const &display) {
assert(!isNull()); assert(!isNull());
return Context(object().call<jni::Object>(Meta::data().createDisplayContext, display.object())); return Context(object().call<jni::Object>(Meta::data().createDisplayContext,
} display.object()));
inline jni::Object Context::getSystemService(std::string const &name) {
assert(!isNull());
return object().call<jni::Object>(Meta::data().getSystemService, name);
}
inline java::io::File Context::getExternalFilesDir(std::string const &type) {
assert(!isNull());
return java::io::File(object().call<jni::Object>(Meta::data().getExternalFilesDir, type));
} }
inline net::Uri_Builder ContentUris::appendId(net::Uri_Builder &uri_Builder, inline net::Uri_Builder ContentUris::appendId(net::Uri_Builder &uri_Builder,

View file

@ -1,4 +1,4 @@
// Copyright 2020-2021, Collabora, Ltd. // Copyright 2020-2023, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0 // SPDX-License-Identifier: BSL-1.0
// Author: Ryan Pavlik <ryan.pavlik@collabora.com> // Author: Ryan Pavlik <ryan.pavlik@collabora.com>
@ -12,7 +12,9 @@ PackageItemInfo::Meta::Meta()
packageName(classRef(), "packageName") { packageName(classRef(), "packageName") {
MetaBaseDroppable::dropClassRef(); MetaBaseDroppable::dropClassRef();
} }
ComponentInfo::Meta::Meta() : MetaBaseDroppable(ComponentInfo::getTypeName()) { ComponentInfo::Meta::Meta()
: MetaBaseDroppable(ComponentInfo::getTypeName()),
applicationInfo(classRef(), "applicationInfo") {
MetaBaseDroppable::dropClassRef(); MetaBaseDroppable::dropClassRef();
} }
ServiceInfo::Meta::Meta() : MetaBaseDroppable(ServiceInfo::getTypeName()) { ServiceInfo::Meta::Meta() : MetaBaseDroppable(ServiceInfo::getTypeName()) {

View file

@ -1,4 +1,4 @@
// Copyright 2020-2021, Collabora, Ltd. // Copyright 2020-2023, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0 // SPDX-License-Identifier: BSL-1.0
// Author: Ryan Pavlik <ryan.pavlik@collabora.com> // Author: Ryan Pavlik <ryan.pavlik@collabora.com>
@ -105,10 +105,22 @@ class ComponentInfo : public PackageItemInfo {
return "android/content/pm/ComponentInfo"; return "android/content/pm/ComponentInfo";
} }
/*!
* Getter for the applicationInfo field value
*
* Java prototype:
* `public android.content.pm.ApplicationInfo applicationInfo;`
*
* JNI signature: Landroid/content/pm/ApplicationInfo;
*
*/
ApplicationInfo getApplicationInfo() const;
/*! /*!
* Class metadata * Class metadata
*/ */
struct Meta : public MetaBaseDroppable { struct Meta : public MetaBaseDroppable {
impl::WrappedFieldId<ApplicationInfo> applicationInfo;
/*! /*!
* Singleton accessor * Singleton accessor
@ -126,9 +138,9 @@ class ComponentInfo : public PackageItemInfo {
/*! /*!
* Wrapper for android.content.pm.ServiceInfo objects. * Wrapper for android.content.pm.ServiceInfo objects.
*/ */
class ServiceInfo : public PackageItemInfo { class ServiceInfo : public ComponentInfo {
public: public:
using PackageItemInfo::PackageItemInfo; using ComponentInfo::ComponentInfo;
static constexpr const char *getTypeName() noexcept { static constexpr const char *getTypeName() noexcept {
return "android/content/pm/ServiceInfo"; return "android/content/pm/ServiceInfo";
} }

View file

@ -1,4 +1,4 @@
// Copyright 2020-2021, Collabora, Ltd. // Copyright 2020-2023, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0 // SPDX-License-Identifier: BSL-1.0
// Author: Ryan Pavlik <ryan.pavlik@collabora.com> // Author: Ryan Pavlik <ryan.pavlik@collabora.com>
// Inline implementations: do not include on its own! // Inline implementations: do not include on its own!
@ -26,6 +26,11 @@ inline std::string PackageItemInfo::getPackageName() const {
return get(Meta::data().packageName, object()); return get(Meta::data().packageName, object());
} }
inline ApplicationInfo ComponentInfo::getApplicationInfo() const {
assert(!isNull());
return get(Meta::data().applicationInfo, object());
}
inline std::string ApplicationInfo::getNativeLibraryDir() const { inline std::string ApplicationInfo::getNativeLibraryDir() const {
assert(!isNull()); assert(!isNull());
return get(Meta::data().nativeLibraryDir, object()); return get(Meta::data().nativeLibraryDir, object());

View file

@ -1,4 +1,4 @@
// Copyright 2020-2021, Collabora, Ltd. // Copyright 2020-2023, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0 // SPDX-License-Identifier: BSL-1.0
// Author: Ryan Pavlik <ryan.pavlik@collabora.com> // Author: Ryan Pavlik <ryan.pavlik@collabora.com>
@ -10,6 +10,6 @@ Settings::Meta::Meta()
: MetaBase(Settings::getTypeName()), : MetaBase(Settings::getTypeName()),
ACTION_VR_LISTENER_SETTINGS(classRef(), "ACTION_VR_LISTENER_SETTINGS"), ACTION_VR_LISTENER_SETTINGS(classRef(), "ACTION_VR_LISTENER_SETTINGS"),
canDrawOverlays(classRef().getStaticMethod( canDrawOverlays(classRef().getStaticMethod(
"canDrawOverlays", "(Landroid/content/Context;)Z")) {} "canDrawOverlays", "(Landroid/content/Context;)Z")) {}
} // namespace android::provider } // namespace android::provider
} // namespace wrap } // namespace wrap

View file

@ -1,4 +1,4 @@
// Copyright 2020-2021, Collabora, Ltd. // Copyright 2020-2023, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0 // SPDX-License-Identifier: BSL-1.0
// Author: Ryan Pavlik <ryan.pavlik@collabora.com> // Author: Ryan Pavlik <ryan.pavlik@collabora.com>
@ -9,9 +9,12 @@
namespace wrap { namespace wrap {
namespace android::content { namespace android::content {
class Context; class Context;
} // namespace android::content } // namespace android::content
} // namespace wrap
namespace wrap {
namespace android::provider { namespace android::provider {
/*! /*!
* Wrapper for android.provider.Settings objects. * Wrapper for android.provider.Settings objects.
@ -38,14 +41,12 @@ class Settings : public ObjectWrapperBase {
* Wrapper for the canDrawOverlays static method * Wrapper for the canDrawOverlays static method
* *
* Java prototype: * Java prototype:
* `public static final boolean * `public static boolean canDrawOverlays(android.content.Context);`
* canDrawOverlays(android.content.Context);`
* *
* JNI signature: * JNI signature: (Landroid/content/Context;)Z
* (Landroid/content/Context;)Z
* *
*/ */
static bool canDrawOverlays(content::Context const &context); static bool canDrawOverlays(const content::Context &context);
/*! /*!
* Class metadata * Class metadata

View file

@ -1,4 +1,4 @@
// Copyright 2020-2021, Collabora, Ltd. // Copyright 2020-2023, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0 // SPDX-License-Identifier: BSL-1.0
// Author: Ryan Pavlik <ryan.pavlik@collabora.com> // Author: Ryan Pavlik <ryan.pavlik@collabora.com>
// Inline implementations: do not include on its own! // Inline implementations: do not include on its own!
@ -17,5 +17,6 @@ inline bool Settings::canDrawOverlays(const content::Context &context) {
return Meta::data().clazz().call<bool>(Meta::data().canDrawOverlays, return Meta::data().clazz().call<bool>(Meta::data().canDrawOverlays,
context.object()); context.object());
} }
} // namespace android::provider } // namespace android::provider
} // namespace wrap } // namespace wrap