external: Update android-jni-wrap

This commit is contained in:
Jarvis Huang 2021-11-29 22:10:00 +08:00 committed by Ryan Pavlik
parent 3e7187686b
commit 6fd645f4ac
15 changed files with 480 additions and 25 deletions

View file

@ -1,8 +1,9 @@
// Copyright 2020, Collabora, Ltd.
// Copyright 2020-2021, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
// Author: Ryan Pavlik <ryan.pavlik@collabora.com>
#pragma once
#include <assert.h>
#include <jni.h>
#include <jnipp.h>

View file

@ -11,6 +11,7 @@ Service::Meta::Meta() : MetaBaseDroppable(Service::getTypeName()) {
}
Activity::Meta::Meta()
: MetaBaseDroppable(Activity::getTypeName()),
getWindow(classRef().getMethod("getWindow", "()Landroid/view/Window;")),
getSystemService(classRef().getMethod(
"getSystemService", "(Ljava/lang/String;)Ljava/lang/Object;")),
setVrModeEnabled(classRef().getMethod(

View file

@ -53,6 +53,17 @@ class Activity : public content::Context {
return "android/app/Activity";
}
/*!
* Wrapper for the getWindow method
*
* Java prototype:
* `public android.view.Window getWindow();`
*
* JNI signature: ()Landroid/view/Window;
*
*/
jni::Object getWindow();
/*!
* Wrapper for the getSystemService method
*
@ -81,6 +92,7 @@ class Activity : public content::Context {
* Class metadata
*/
struct Meta : public MetaBaseDroppable {
jni::method_t getWindow;
jni::method_t getSystemService;
jni::method_t setVrModeEnabled;

View file

@ -11,6 +11,11 @@
namespace wrap {
namespace android::app {
inline jni::Object Activity::getWindow() {
assert(!isNull());
return object().call<jni::Object>(Meta::data().getWindow);
}
inline jni::Object Activity::getSystemService(std::string const &name) {
assert(!isNull());
return object().call<jni::Object>(Meta::data().getSystemService, name);

View file

@ -29,6 +29,15 @@ Context::Meta::Meta(bool deferDrop)
MetaBaseDroppable::dropClassRef();
}
}
ContentUris::Meta::Meta(bool deferDrop)
: MetaBaseDroppable(ContentUris::getTypeName()),
appendId(classRef().getStaticMethod(
"appendId",
"(Landroid/net/Uri$Builder;J)Landroid/net/Uri$Builder;")) {
if (!deferDrop) {
MetaBaseDroppable::dropClassRef();
}
}
ComponentName::Meta::Meta()
: MetaBase(ComponentName::getTypeName()),
init(classRef().getMethod("<init>",
@ -41,6 +50,7 @@ ComponentName::Meta::Meta()
Intent::Meta::Meta()
: MetaBase(Intent::getTypeName()),
FLAG_ACTIVITY_NEW_TASK(classRef(), "FLAG_ACTIVITY_NEW_TASK"),
init(classRef().getMethod("<init>", "()V")),
init1(classRef().getMethod("<init>", "(Landroid/content/Intent;)V")),
init2(classRef().getMethod("<init>", "(Ljava/lang/String;)V")),
init3(classRef().getMethod("<init>",

View file

@ -23,6 +23,11 @@ namespace android::database {
class Cursor;
} // namespace android::database
namespace android::net {
class Uri;
class Uri_Builder;
} // namespace android::net
namespace android::os {
class Bundle;
} // namespace android::os
@ -180,6 +185,48 @@ class Context : public ObjectWrapperBase {
};
};
/*!
* Wrapper for android.content.ContentUris objects.
*/
class ContentUris : public ObjectWrapperBase {
public:
using ObjectWrapperBase::ObjectWrapperBase;
static constexpr const char *getTypeName() noexcept {
return "android/content/ContentUris";
}
/*!
* Wrapper for the appendId static method
*
* Java prototype:
* `public static android.net.Uri$Builder appendId(android.net.Uri$Builder,
* long);`
*
* JNI signature: (Landroid/net/Uri$Builder;J)Landroid/net/Uri$Builder;
*
*/
static net::Uri_Builder appendId(net::Uri_Builder &uri_Builder,
long long longParam);
/*!
* Class metadata
*/
struct Meta : public MetaBaseDroppable {
jni::method_t appendId;
/*!
* Singleton accessor
*/
static Meta &data(bool deferDrop = false) {
static Meta instance{deferDrop};
return instance;
}
private:
explicit Meta(bool deferDrop);
};
};
/*!
* Wrapper for android.content.ComponentName objects.
*/
@ -283,6 +330,17 @@ class Intent : public ObjectWrapperBase {
*/
static int32_t FLAG_ACTIVITY_NEW_TASK();
/*!
* Wrapper for a constructor
*
* Java prototype:
* `public android.content.Intent();`
*
* JNI signature: ()V
*
*/
static Intent construct();
/*!
* Wrapper for a constructor
*
@ -314,7 +372,7 @@ class Intent : public ObjectWrapperBase {
* JNI signature: (Ljava/lang/String;Landroid/net/Uri;)V
*
*/
static Intent construct(std::string const &action, jni::Object const &uri);
static Intent construct(std::string const &action, net::Uri const &uri);
/*!
* Wrapper for a constructor
@ -340,7 +398,7 @@ class Intent : public ObjectWrapperBase {
* (Ljava/lang/String;Landroid/net/Uri;Landroid/content/Context;Ljava/lang/Class;)V
*
*/
static Intent construct(std::string const &action, jni::Object const &uri,
static Intent construct(std::string const &action, net::Uri const &uri,
Context const &context,
java::lang::Class const &classParam);
@ -360,6 +418,7 @@ class Intent : public ObjectWrapperBase {
*/
struct Meta : public MetaBase {
impl::StaticFieldId<int32_t> FLAG_ACTIVITY_NEW_TASK;
jni::method_t init;
jni::method_t init1;
jni::method_t init2;
jni::method_t init3;
@ -402,12 +461,29 @@ class ContentResolver : public ObjectWrapperBase {
* (Landroid/net/Uri;[Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)Landroid/database/Cursor;
*
*/
database::Cursor query(jni::Object const &uri,
database::Cursor query(net::Uri const &uri,
jni::Array<std::string> const &projection,
std::string const &selection,
jni::Array<std::string> const &selectionArgs,
std::string const &sortOrder);
/*!
* Wrapper for the query method - overload added in API level 1
*
* Java prototype:
* `public final android.database.Cursor query(android.net.Uri,
* java.lang.String[], java.lang.String, java.lang.String[],
* java.lang.String);`
*
* JNI signature:
* (Landroid/net/Uri;[Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)Landroid/database/Cursor;
*
* This is a way to call the main query() function without the three
* trailing optional arguments.
*/
database::Cursor query(net::Uri const &uri,
jni::Array<std::string> const &projection);
/*!
* Wrapper for the query method - overload added in API level 16
*
@ -420,7 +496,7 @@ class ContentResolver : public ObjectWrapperBase {
* (Landroid/net/Uri;[Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;Landroid/os/CancellationSignal;)Landroid/database/Cursor;
*
*/
database::Cursor query(jni::Object const &uri,
database::Cursor query(net::Uri const &uri,
jni::Array<std::string> const &projection,
std::string const &selection,
jni::Array<std::string> const &selectionArgs,
@ -438,7 +514,7 @@ class ContentResolver : public ObjectWrapperBase {
* (Landroid/net/Uri;[Ljava/lang/String;Landroid/os/Bundle;Landroid/os/CancellationSignal;)Landroid/database/Cursor;
*
*/
database::Cursor query(jni::Object const &uri,
database::Cursor query(net::Uri const &uri,
jni::Array<std::string> const &projection,
os::Bundle const &queryArgs,
jni::Object const &cancellationSignal);

View file

@ -7,6 +7,7 @@
#include "android.content.pm.h"
#include "android.database.h"
#include "android.net.h"
#include "android.os.h"
#include "java.lang.h"
#include <string>
@ -70,6 +71,15 @@ inline Context Context::createPackageContext(std::string const &packageName,
packageName, flags));
}
inline net::Uri_Builder ContentUris::appendId(net::Uri_Builder &uri_Builder,
long long longParam) {
auto &data = Meta::data(true);
auto ret = net::Uri_Builder(data.clazz().call<jni::Object>(
data.appendId, uri_Builder.object(), longParam));
data.dropClassRef();
return ret;
}
inline ComponentName ComponentName::construct(std::string const &pkg,
std::string const &className) {
return ComponentName(
@ -97,6 +107,10 @@ inline int32_t Intent::FLAG_ACTIVITY_NEW_TASK() {
return get(Meta::data().FLAG_ACTIVITY_NEW_TASK, Meta::data().clazz());
}
inline Intent Intent::construct() {
return Intent(Meta::data().clazz().newInstance(Meta::data().init));
}
inline Intent Intent::construct(Intent const &intent) {
return Intent(
Meta::data().clazz().newInstance(Meta::data().init1, intent.object()));
@ -107,9 +121,9 @@ inline Intent Intent::construct(std::string const &action) {
}
inline Intent Intent::construct(std::string const &action,
jni::Object const &uri) {
return Intent(
Meta::data().clazz().newInstance(Meta::data().init3, action, uri));
net::Uri const &uri) {
return Intent(Meta::data().clazz().newInstance(Meta::data().init3, action,
uri.object()));
}
inline Intent Intent::construct(Context const &context,
@ -118,12 +132,12 @@ inline Intent Intent::construct(Context const &context,
Meta::data().init4, context.object(), classParam.object()));
}
inline Intent Intent::construct(std::string const &action,
jni::Object const &uri, Context const &context,
inline Intent Intent::construct(std::string const &action, net::Uri const &uri,
Context const &context,
java::lang::Class const &classParam) {
return Intent(Meta::data().clazz().newInstance(Meta::data().init5, action,
uri, context.object(),
classParam.object()));
return Intent(Meta::data().clazz().newInstance(
Meta::data().init5, action, uri.object(), context.object(),
classParam.object()));
}
inline Intent Intent::setFlags(int32_t flags) {
@ -132,32 +146,41 @@ inline Intent Intent::setFlags(int32_t flags) {
}
inline database::Cursor ContentResolver::query(
jni::Object const &uri, jni::Array<std::string> const &projection,
net::Uri const &uri, jni::Array<std::string> const &projection,
std::string const &selection, jni::Array<std::string> const &selectionArgs,
std::string const &sortOrder) {
assert(!isNull());
return database::Cursor(
object().call<jni::Object>(Meta::data().query, uri, projection,
object().call<jni::Object>(Meta::data().query, uri.object(), projection,
selection, selectionArgs, sortOrder));
}
inline database::Cursor
ContentResolver::query(net::Uri const &uri,
jni::Array<std::string> const &projection) {
assert(!isNull());
return database::Cursor(
object().call<jni::Object>(Meta::data().query, uri.object(), projection,
nullptr, nullptr, nullptr));
}
inline database::Cursor ContentResolver::query(
jni::Object const &uri, jni::Array<std::string> const &projection,
net::Uri const &uri, jni::Array<std::string> const &projection,
std::string const &selection, jni::Array<std::string> const &selectionArgs,
std::string const &sortOrder, jni::Object const &cancellationSignal) {
assert(!isNull());
return database::Cursor(object().call<jni::Object>(
Meta::data().query1, uri, projection, selection, selectionArgs,
Meta::data().query1, uri.object(), projection, selection, selectionArgs,
sortOrder, cancellationSignal));
}
inline database::Cursor ContentResolver::query(
jni::Object const &uri, jni::Array<std::string> const &projection,
net::Uri const &uri, jni::Array<std::string> const &projection,
os::Bundle const &queryArgs, jni::Object const &cancellationSignal) {
assert(!isNull());
return database::Cursor(
object().call<jni::Object>(Meta::data().query2, uri, projection,
queryArgs.object(), cancellationSignal));
return database::Cursor(object().call<jni::Object>(
Meta::data().query2, uri.object(), projection, queryArgs.object(),
cancellationSignal));
}
} // namespace android::content

View file

@ -0,0 +1,27 @@
// Copyright 2020-2021, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
// Author: Ryan Pavlik <ryan.pavlik@collabora.com>
#include "android.net.h"
namespace wrap {
namespace android::net {
Uri::Meta::Meta()
: MetaBaseDroppable(Uri::getTypeName()),
toString(classRef().getMethod("toString", "()Ljava/lang/String;")) {
MetaBaseDroppable::dropClassRef();
}
Uri_Builder::Meta::Meta()
: MetaBaseDroppable(Uri_Builder::getTypeName()),
init(classRef().getMethod("<init>", "()V")),
scheme(classRef().getMethod(
"scheme", "(Ljava/lang/String;)Landroid/net/Uri$Builder;")),
authority(classRef().getMethod(
"authority", "(Ljava/lang/String;)Landroid/net/Uri$Builder;")),
appendPath(classRef().getMethod(
"appendPath", "(Ljava/lang/String;)Landroid/net/Uri$Builder;")),
build(classRef().getMethod("build", "()Landroid/net/Uri;")) {
MetaBaseDroppable::dropClassRef();
}
} // namespace android::net
} // namespace wrap

View file

@ -0,0 +1,149 @@
// Copyright 2020-2021, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
// Author: Ryan Pavlik <ryan.pavlik@collabora.com>
#pragma once
#include "ObjectWrapperBase.h"
namespace wrap {
namespace android::net {
class Uri;
class Uri_Builder;
} // namespace android::net
} // namespace wrap
namespace wrap {
namespace android::net {
/*!
* Wrapper for android.net.Uri objects.
*/
class Uri : public ObjectWrapperBase {
public:
using ObjectWrapperBase::ObjectWrapperBase;
static constexpr const char *getTypeName() noexcept {
return "android/net/Uri";
}
/*!
* Wrapper for the toString method
*
* Java prototype:
* `public abstract java.lang.String toString();`
*
* JNI signature: ()Ljava/lang/String;
*
*/
std::string toString() const;
/*!
* Class metadata
*/
struct Meta : public MetaBaseDroppable {
jni::method_t toString;
/*!
* Singleton accessor
*/
static Meta &data() {
static Meta instance{};
return instance;
}
private:
Meta();
};
};
/*!
* Wrapper for android.net.Uri$Builder objects.
*/
class Uri_Builder : public ObjectWrapperBase {
public:
using ObjectWrapperBase::ObjectWrapperBase;
static constexpr const char *getTypeName() noexcept {
return "android/net/Uri$Builder";
}
/*!
* Wrapper for a constructor
*
* Java prototype:
* `public android.net.Uri$Builder();`
*
* JNI signature: ()V
*
*/
static Uri_Builder construct();
/*!
* Wrapper for the scheme method
*
* Java prototype:
* `public android.net.Uri$Builder scheme(java.lang.String);`
*
* JNI signature: (Ljava/lang/String;)Landroid/net/Uri$Builder;
*
*/
Uri_Builder &scheme(std::string const &stringParam);
/*!
* Wrapper for the authority method
*
* Java prototype:
* `public android.net.Uri$Builder authority(java.lang.String);`
*
* JNI signature: (Ljava/lang/String;)Landroid/net/Uri$Builder;
*
*/
Uri_Builder &authority(std::string const &stringParam);
/*!
* Wrapper for the appendPath method
*
* Java prototype:
* `public android.net.Uri$Builder appendPath(java.lang.String);`
*
* JNI signature: (Ljava/lang/String;)Landroid/net/Uri$Builder;
*
*/
Uri_Builder &appendPath(std::string const &stringParam);
/*!
* Wrapper for the build method
*
* Java prototype:
* `public android.net.Uri build();`
*
* JNI signature: ()Landroid/net/Uri;
*
*/
Uri build();
/*!
* Class metadata
*/
struct Meta : public MetaBaseDroppable {
jni::method_t init;
jni::method_t scheme;
jni::method_t authority;
jni::method_t appendPath;
jni::method_t build;
/*!
* Singleton accessor
*/
static Meta &data() {
static Meta instance{};
return instance;
}
private:
Meta();
};
};
} // namespace android::net
} // namespace wrap
#include "android.net.impl.h"

View file

@ -0,0 +1,45 @@
// Copyright 2020-2021, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
// Author: Ryan Pavlik <ryan.pavlik@collabora.com>
// Inline implementations: do not include on its own!
#pragma once
#include <string>
namespace wrap {
namespace android::net {
inline std::string Uri::toString() const {
assert(!isNull());
return object().call<std::string>(Meta::data().toString);
}
inline Uri_Builder Uri_Builder::construct() {
return Uri_Builder(Meta::data().clazz().newInstance(Meta::data().init));
}
inline Uri_Builder &Uri_Builder::scheme(std::string const &stringParam) {
assert(!isNull());
object().call<jni::Object>(Meta::data().scheme, stringParam);
return *this;
}
inline Uri_Builder &Uri_Builder::authority(std::string const &stringParam) {
assert(!isNull());
object().call<jni::Object>(Meta::data().authority, stringParam);
return *this;
}
inline Uri_Builder &Uri_Builder::appendPath(std::string const &stringParam) {
assert(!isNull());
object().call<jni::Object>(Meta::data().appendPath, stringParam);
return *this;
}
inline Uri Uri_Builder::build() {
assert(!isNull());
return Uri(object().call<jni::Object>(Meta::data().build));
}
} // namespace android::net
} // namespace wrap

View file

@ -74,7 +74,7 @@ class Toast : public ObjectWrapperBase {
*
*/
static Toast makeText(content::Context const &context,
jni::Object const &text, int32_t duration);
std::string const &stringParam, int32_t duration);
/*!
* Wrapper for the makeText static method

View file

@ -23,9 +23,9 @@ inline void Toast::show() const {
}
inline Toast Toast::makeText(content::Context const &context,
jni::Object const &text, int32_t duration) {
std::string const &stringParam, int32_t duration) {
return Toast(Meta::data().clazz().call<jni::Object>(
Meta::data().makeText, context.object(), text, duration));
Meta::data().makeText, context.object(), stringParam, duration));
}
inline Toast Toast::makeText(content::Context const &context, int32_t resId,

View file

@ -0,0 +1,15 @@
// Copyright 2020-2021, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
// Author: Ryan Pavlik <ryan.pavlik@collabora.com>
#include "dalvik.system.h"
namespace wrap {
namespace dalvik::system {
DexClassLoader::Meta::Meta()
: MetaBase(DexClassLoader::getTypeName()),
init(classRef().getMethod("<init>",
"(Ljava/lang/String;Ljava/lang/String;Ljava/"
"lang/String;Ljava/lang/ClassLoader;)V")) {}
} // namespace dalvik::system
} // namespace wrap

View file

@ -0,0 +1,68 @@
// Copyright 2020-2021, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
// Author: Ryan Pavlik <ryan.pavlik@collabora.com>
#pragma once
#include "ObjectWrapperBase.h"
namespace wrap {
namespace dalvik::system {
class DexClassLoader;
} // namespace dalvik::system
namespace java::lang {
class ClassLoader;
} // namespace java::lang
} // namespace wrap
namespace wrap {
namespace dalvik::system {
/*!
* Wrapper for dalvik.system.DexClassLoader objects.
*/
class DexClassLoader : public ObjectWrapperBase {
public:
using ObjectWrapperBase::ObjectWrapperBase;
static constexpr const char *getTypeName() noexcept {
return "dalvik/system/DexClassLoader";
}
/*!
* Wrapper for a constructor
*
* Java prototype:
* `public dalvik.system.DexClassLoader(java.lang.String, java.lang.String,
* java.lang.String, java.lang.ClassLoader);`
*
* JNI signature:
* (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/ClassLoader;)V
*
*/
static DexClassLoader construct(std::string const &searchPath,
std::string const &nativeSearchPath,
jni::Object parentClassLoader);
/*!
* Class metadata
*/
struct Meta : public MetaBase {
jni::method_t init;
/*!
* Singleton accessor
*/
static Meta &data() {
static Meta instance{};
return instance;
}
private:
Meta();
};
};
} // namespace dalvik::system
} // namespace wrap
#include "dalvik.system.impl.h"

View file

@ -0,0 +1,23 @@
// Copyright 2020-2021, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
// Author: Ryan Pavlik <ryan.pavlik@collabora.com>
// Inline implementations: do not include on its own!
#pragma once
#include "java.lang.h"
#include <string>
namespace wrap {
namespace dalvik::system {
inline DexClassLoader
DexClassLoader::construct(std::string const &searchPath,
std::string const &nativeSearchPath,
jni::Object parentClassLoader) {
return DexClassLoader{
Meta::data().clazz().newInstance(Meta::data().init, searchPath, "",
nativeSearchPath, parentClassLoader)};
}
} // namespace dalvik::system
} // namespace wrap