The open source OpenXR runtime
at main 217 lines 7.8 kB view raw
1// Copyright 2020-2025, Collabora, Ltd. 2// SPDX-License-Identifier: BSL-1.0 3// Author: Rylie Pavlik <rylie.pavlik@collabora.com> 4// Inline implementations: do not include on its own! 5 6#pragma once 7 8#include "android.content.pm.h" 9#include "android.database.h" 10#include "android.net.h" 11#include "android.os.h" 12#include "android.view.h" 13#include "java.io.h" 14#include "java.lang.h" 15#include <string> 16 17namespace wrap { 18namespace android::content { 19inline std::string Context::DISPLAY_SERVICE() { 20 auto &data = Meta::data(true); 21 auto ret = get(data.DISPLAY_SERVICE, data.clazz()); 22 data.dropClassRef(); 23 return ret; 24} 25 26inline std::string Context::WINDOW_SERVICE() { 27 auto &data = Meta::data(true); 28 auto ret = get(data.WINDOW_SERVICE, data.clazz()); 29 data.dropClassRef(); 30 return ret; 31} 32 33inline pm::PackageManager Context::getPackageManager() { 34 assert(!isNull()); 35 return pm::PackageManager( 36 object().call<jni::Object>(Meta::data().getPackageManager)); 37} 38 39inline std::string Context::getPackageName() { 40 assert(!isNull()); 41 return std::string( 42 object().call<std::string>(Meta::data().getPackageName)); 43} 44 45inline ContentResolver Context::getContentResolver() const { 46 assert(!isNull()); 47 return ContentResolver( 48 object().call<jni::Object>(Meta::data().getContentResolver)); 49} 50 51inline Context Context::getApplicationContext() { 52 assert(!isNull()); 53 return Context( 54 object().call<jni::Object>(Meta::data().getApplicationContext)); 55} 56 57inline java::lang::ClassLoader Context::getClassLoader() { 58 assert(!isNull()); 59 return java::lang::ClassLoader( 60 object().call<jni::Object>(Meta::data().getClassLoader)); 61} 62 63inline java::io::File Context::getExternalFilesDir(std::string const &type) { 64 assert(!isNull()); 65 return java::io::File( 66 object().call<jni::Object>(Meta::data().getExternalFilesDir, type)); 67} 68 69inline java::io::File Context::getFilesDir() { 70 assert(!isNull()); 71 return java::io::File(object().call<jni::Object>(Meta::data().getFilesDir)); 72} 73 74inline void Context::startActivity(Intent const &intent) { 75 assert(!isNull()); 76 return object().call<void>(Meta::data().startActivity, intent.object()); 77} 78 79inline void Context::startActivity(Intent const &intent, 80 os::Bundle const &bundle) { 81 assert(!isNull()); 82 return object().call<void>(Meta::data().startActivity1, intent.object(), 83 bundle.object()); 84} 85 86inline jni::Object Context::getSystemService(std::string const &name) { 87 assert(!isNull()); 88 return object().call<jni::Object>(Meta::data().getSystemService, name); 89} 90 91inline Context Context::createPackageContext(std::string const &packageName, 92 int32_t flags) { 93 assert(!isNull()); 94 return Context(object().call<jni::Object>(Meta::data().createPackageContext, 95 packageName, flags)); 96} 97 98inline Context Context::createDisplayContext(view::Display const &display) { 99 assert(!isNull()); 100 return Context(object().call<jni::Object>(Meta::data().createDisplayContext, 101 display.object())); 102} 103 104inline net::Uri_Builder ContentUris::appendId(net::Uri_Builder &uri_Builder, 105 long long longParam) { 106 auto &data = Meta::data(true); 107 auto ret = net::Uri_Builder(data.clazz().call<jni::Object>( 108 data.appendId, uri_Builder.object(), longParam)); 109 data.dropClassRef(); 110 return ret; 111} 112 113inline ComponentName ComponentName::construct(std::string const &pkg, 114 std::string const &className) { 115 return ComponentName( 116 Meta::data().clazz().newInstance(Meta::data().init, pkg, className)); 117} 118 119inline ComponentName ComponentName::construct(Context const &context, 120 std::string const &className) { 121 return ComponentName(Meta::data().clazz().newInstance( 122 Meta::data().init1, context.object(), className)); 123} 124 125inline ComponentName ComponentName::construct(Context const &context, 126 java::lang::Class const &cls) { 127 return ComponentName(Meta::data().clazz().newInstance( 128 Meta::data().init2, context.object(), cls.object())); 129} 130 131inline ComponentName ComponentName::construct(jni::Object const &parcel) { 132 return ComponentName( 133 Meta::data().clazz().newInstance(Meta::data().init3, parcel)); 134} 135 136inline int32_t Intent::FLAG_ACTIVITY_NEW_TASK() { 137 return get(Meta::data().FLAG_ACTIVITY_NEW_TASK, Meta::data().clazz()); 138} 139 140inline Intent Intent::construct() { 141 return Intent(Meta::data().clazz().newInstance(Meta::data().init)); 142} 143 144inline Intent Intent::construct(Intent const &intent) { 145 return Intent( 146 Meta::data().clazz().newInstance(Meta::data().init1, intent.object())); 147} 148 149inline Intent Intent::construct(std::string const &action) { 150 return Intent(Meta::data().clazz().newInstance(Meta::data().init2, action)); 151} 152 153inline Intent Intent::construct(std::string const &action, 154 net::Uri const &uri) { 155 return Intent(Meta::data().clazz().newInstance(Meta::data().init3, action, 156 uri.object())); 157} 158 159inline Intent Intent::construct(Context const &context, 160 java::lang::Class const &classParam) { 161 return Intent(Meta::data().clazz().newInstance( 162 Meta::data().init4, context.object(), classParam.object())); 163} 164 165inline Intent Intent::construct(std::string const &action, net::Uri const &uri, 166 Context const &context, 167 java::lang::Class const &classParam) { 168 return Intent(Meta::data().clazz().newInstance( 169 Meta::data().init5, action, uri.object(), context.object(), 170 classParam.object())); 171} 172 173inline Intent Intent::setFlags(int32_t flags) { 174 assert(!isNull()); 175 return Intent(object().call<jni::Object>(Meta::data().setFlags, flags)); 176} 177 178inline database::Cursor ContentResolver::query( 179 net::Uri const &uri, jni::Array<std::string> const &projection, 180 std::string const &selection, jni::Array<std::string> const &selectionArgs, 181 std::string const &sortOrder) { 182 assert(!isNull()); 183 return database::Cursor( 184 object().call<jni::Object>(Meta::data().query, uri.object(), projection, 185 selection, selectionArgs, sortOrder)); 186} 187 188inline database::Cursor 189ContentResolver::query(net::Uri const &uri, 190 jni::Array<std::string> const &projection) { 191 assert(!isNull()); 192 return database::Cursor( 193 object().call<jni::Object>(Meta::data().query, uri.object(), projection, 194 nullptr, nullptr, nullptr)); 195} 196 197inline database::Cursor ContentResolver::query( 198 net::Uri const &uri, jni::Array<std::string> const &projection, 199 std::string const &selection, jni::Array<std::string> const &selectionArgs, 200 std::string const &sortOrder, jni::Object const &cancellationSignal) { 201 assert(!isNull()); 202 return database::Cursor(object().call<jni::Object>( 203 Meta::data().query1, uri.object(), projection, selection, selectionArgs, 204 sortOrder, cancellationSignal)); 205} 206 207inline database::Cursor ContentResolver::query( 208 net::Uri const &uri, jni::Array<std::string> const &projection, 209 os::Bundle const &queryArgs, jni::Object const &cancellationSignal) { 210 assert(!isNull()); 211 return database::Cursor(object().call<jni::Object>( 212 Meta::data().query2, uri.object(), projection, queryArgs.object(), 213 cancellationSignal)); 214} 215 216} // namespace android::content 217} // namespace wrap