Skip to content

Commit aac25cf

Browse files
author
reisxd
committed
feat: expose app version in h5vcc api
Change-Id: I92cae8c658d55aa33ba6217597eb4d23070fd9f5
1 parent 17ee61f commit aac25cf

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

cobalt/h5vcc/h5vcc_tizen_tube.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@ bool H5vccTizenTube::InstallAppFromURL(const std::string& url) const {
4545
return false;
4646
}
4747

48+
std::string H5vccTizenTube::GetVersion() const {
49+
#if defined(ANDROID)
50+
JniEnvExt* env = JniEnvExt::Get();
51+
ScopedLocalJavaRef<jstring> j_version(env->CallStarboardObjectMethodOrAbort(
52+
"getVersion", "()Ljava/lang/String;"));
53+
const char* version_cstr = env->GetStringUTFChars(j_version.Get(), nullptr);
54+
std::string version(version_cstr);
55+
env->ReleaseStringUTFChars(j_version.Get(), version_cstr);
56+
return version;
57+
#endif
58+
return "";
59+
}
60+
4861

4962
} // namespace h5vcc
5063
} // namespace cobalt

cobalt/h5vcc/h5vcc_tizen_tube.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class H5vccTizenTube : public script::Wrappable {
4646
// Calls a Java method in order to download the APK
4747
// and install it.
4848
bool InstallAppFromURL(const std::string& url) const;
49+
std::string GetVersion() const;
4950

5051
DEFINE_WRAPPABLE_TYPE(H5vccTizenTube);
5152

cobalt/h5vcc/h5vcc_tizen_tube.idl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@
1414

1515
interface H5vccTizenTube {
1616
boolean InstallAppFromURL(DOMString url);
17+
DOMString GetVersion();
1718
};

starboard/android/apk/app/src/main/java/dev/cobalt/coat/StarboardBridge.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,4 +864,17 @@ protected boolean installAppFromURL(String url) {
864864
});
865865
return true;
866866
}
867+
868+
@SuppressWarnings("unused")
869+
@UsedByNative
870+
protected String getVersion() {
871+
try {
872+
android.content.pm.PackageInfo packageInfo =
873+
appContext.getPackageManager().getPackageInfo(appContext.getPackageName(), 0);
874+
return packageInfo.versionName;
875+
} catch (android.content.pm.PackageManager.NameNotFoundException e) {
876+
Log.e(TAG, "Failed to get package info", e);
877+
return "unknown";
878+
}
879+
}
867880
}

0 commit comments

Comments
 (0)