Documentation for the Unreal C++ Plugin
Loading...
Searching...
No Matches
PixoLauncherSubsystem.cpp
Go to the documentation of this file.
1// Copyright 2023 PixoVR Corp. All Rights Reserved.
2
3
5#include "GenericPlatform/GenericPlatformMisc.h"
6
7DEFINE_LOG_CATEGORY_STATIC(LogPixoLauncherSubsystem, Log, All);
8
9#define Log(pmt, ...) UE_LOG(LogPixoLauncherSubsystem, Log, TEXT(pmt), ##__VA_ARGS__)
10#define Warn(pmt, ...) UE_LOG(LogPixoLauncherSubsystem, Warning, TEXT(pmt), ##__VA_ARGS__)
11#define Error(pmt, ...) UE_LOG(LogPixoLauncherSubsystem, Error, TEXT(pmt), ##__VA_ARGS__)
12#define Fatal(pmt, ...) UE_LOG(LogPixoLauncherSubsystem, Fatal, TEXT(pmt), ##__VA_ARGS__)
13
19
20void UPixoLauncherSubsystem::Initialize(FSubsystemCollectionBase& Collection)
21{
22#if PLATFORM_ANDROID
23 if (JNIEnv* Env = FAndroidApplication::GetJavaEnv())
24 {
25 IsApplicationInstalledFunction = FJavaWrapper::FindMethod(Env, FJavaWrapper::GameActivityClassID, "AndroidThunkJava_IsPackageInstalled", "(Ljava/lang/String;)Z", false);
26 LaunchApplicationFunction = FJavaWrapper::FindMethod(Env, FJavaWrapper::GameActivityClassID, "AndroidThunkJava_Launch", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Z", false);
27 GetApplicationExtraFunction = FJavaWrapper::FindMethod(Env, FJavaWrapper::GameActivityClassID, "AndroidThunkJava_GetApplicationExtra", "(Ljava/lang/String;)Ljava/lang/String;", false);
28 GetDeviceSerialNumberFunction = FJavaWrapper::FindMethod(Env, FJavaWrapper::GameActivityClassID, "AndroidThunkJava_GetDeviceSerialNumber", "()Ljava/lang/String;", false);
29 GetDeviceMacAddressFunction = FJavaWrapper::FindMethod(Env, FJavaWrapper::GameActivityClassID, "AndroidThunkJava_GetMacAddress", "()Ljava/lang/String;", false);
30 }
31#endif
32}
33
34bool UPixoLauncherSubsystem::IsApplicationInstalled(const FString& ApplicationName)
35{
36 bool bResult = false;
37#if PLATFORM_ANDROID
38 if (JNIEnv* Env = FAndroidApplication::GetJavaEnv())
39 {
40 auto PackageNameArg = FJavaHelper::ToJavaString(Env, ApplicationName);
41 bResult = FJavaWrapper::CallBooleanMethod(Env, FJavaWrapper::GameActivityThis, FJavaWrapper::AndroidThunkJava_IsPackageInstalled, *PackageNameArg);
42 }
43
44 Log("UPixoLauncherSubsystem::IsApplicationInstalledFunction: %d", bResult);
45#endif
46 return bResult;
47}
48
49bool UPixoLauncherSubsystem::LaunchApplication(const FString& ApplicationName, const FString& ExtraKey, const FString& ExtraValue)
50{
51 bool bResult = false;
52#if PLATFORM_ANDROID
53 if (JNIEnv* Env = FAndroidApplication::GetJavaEnv())
54 {
55 auto ApplicationNameArg = FJavaHelper::ToJavaString(Env, ApplicationName);
56 auto ExtraKeyArg = FJavaHelper::ToJavaString(Env, ExtraKey);
57 auto ExtraValueArg = FJavaHelper::ToJavaString(Env, ExtraValue);
58 bResult = FJavaWrapper::CallBooleanMethod(Env, FJavaWrapper::GameActivityThis, LaunchApplicationFunction, *ApplicationNameArg, *ExtraKeyArg, *ExtraValueArg);
59 }
60
61 Log("UPixoLauncherSubsystem::LaunchApplication: %s, %s : %s", *ApplicationName, *ExtraKey, *ExtraValue);
62#endif
63 return bResult;
64}
65
66FString UPixoLauncherSubsystem::GetApplicationExtra(const FString& ExtraKey)
67{
68 FString ReturnedExtraValue = FString("");
69#if PLATFORM_ANDROID
70 if (JNIEnv* Env = FAndroidApplication::GetJavaEnv())
71 {
72 auto ExtraKeyArg = FJavaHelper::ToJavaString(Env, ExtraKey);
73 auto JavaKeyValue = (jstring)FJavaWrapper::CallObjectMethod(Env, FJavaWrapper::GameActivityThis, GetApplicationExtraFunction, *ExtraKeyArg);
74 ReturnedExtraValue = FJavaHelper::FStringFromLocalRef(Env, JavaKeyValue);
75 }
76
77 Log("UPixoLauncherSubsystem::GetApplicationExtra: %s", *ReturnedExtraValue);
78#endif
79 return ReturnedExtraValue;
80}
81
83{
84 FString ReturnedExtraValue = FString("");
85#if PLATFORM_ANDROID
86 if (JNIEnv* Env = FAndroidApplication::GetJavaEnv())
87 {
88 auto JavaKeyValue = (jstring)FJavaWrapper::CallObjectMethod(Env, FJavaWrapper::GameActivityThis, GetDeviceSerialNumberFunction);
89 ReturnedExtraValue = FJavaHelper::FStringFromLocalRef(Env, JavaKeyValue);
90 }
91
92 Log("UPixoLauncherSubsystem::GetDeviceSerialNumber: %s", *ReturnedExtraValue);
93#else
94 ReturnedExtraValue = TEXT("");
95#endif
96 return ReturnedExtraValue;
97}
98
100{
101 FString ReturnedExtraValue = FString("");
102#if PLATFORM_ANDROID
103 if (JNIEnv* Env = FAndroidApplication::GetJavaEnv())
104 {
105 auto JavaKeyValue = (jstring)FJavaWrapper::CallObjectMethod(Env, FJavaWrapper::GameActivityThis, GetDeviceMacAddressFunction);
106 ReturnedExtraValue = FJavaHelper::FStringFromLocalRef(Env, JavaKeyValue);
107 }
108
109 Log("UPixoLauncherSubsystem::GetDeviceMacAddress: %s", *ReturnedExtraValue);
110#else
111 ReturnedExtraValue = FGenericPlatformMisc::GetMacAddressString();
112#endif
113 return ReturnedExtraValue;
114}
115
116#undef Fatal
117#undef Error
118#undef Warn
119#undef Log
#define Log(pmt,...)
Definition ApexAPI.cpp:14
DEFINE_LOG_CATEGORY_STATIC(LogPixoLauncherSubsystem, Log, All)
FString GetDeviceSerialNumber()
UFUNCTION(BlueprintCallable, Category = "PixoVR|Launcher")
FString GetApplicationExtra(const FString &ExtraKey)
UFUNCTION(BlueprintCallable, Category = "PixoVR|Launcher")
FString GetDeviceMacAddress()
UFUNCTION(BlueprintCallable, Category = "PixoVR|Launcher")
bool IsApplicationInstalled(const FString &ApplicationName)
UFUNCTION(BlueprintCallable, Category = "PixoVR|Launcher")
bool LaunchApplication(const FString &ApplicationName, const FString &ExtraKey, const FString &ExtraValue)
UFUNCTION(BlueprintCallable, Category = "PixoVR|Launcher")
void Initialize(FSubsystemCollectionBase &Collection)