Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/in_app_purchase/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## NEXT
## 0.1.9

* Fix the return type of `sso_get_login_info` and clear the login info after use.
* Fix a crash and a memory leak when reading the country code.
* Report an error from `getCustomId` and `getCountryCode` when the lookup fails.
* Load `libvconf` and `libcapi-system-info` by their major SONAME.
* Remove unused private system info keys.
* Resolve `unintended_html_in_doc_comment` lint.

## 0.1.8
Expand Down
2 changes: 1 addition & 1 deletion packages/in_app_purchase/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ This package is not an _endorsed_ implementation of `in_app_purchase`. Therefore
```yaml
dependencies:
in_app_purchase: ^3.3.0
in_app_purchase_tizen: ^0.1.8
in_app_purchase_tizen: ^0.1.9
```

Then you can import `in_app_purchase` and `in_app_purchase_tizen` in your Dart code:
Expand Down
2 changes: 1 addition & 1 deletion packages/in_app_purchase/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: in_app_purchase_tizen
description: Tizen implementation of the in_app_purchase plugin for Samsung Smart TV.
homepage: https://github.com/flutter-tizen/plugins
repository: https://github.com/flutter-tizen/plugins/tree/main/packages/in_app_purchase
version: 0.1.8
version: 0.1.9

environment:
sdk: ^3.10.0
Expand Down
69 changes: 47 additions & 22 deletions packages/in_app_purchase/tizen/src/billing_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <flutter/encodable_value.h>
#include <flutter/standard_method_codec.h>

#include <cstddef>
#include <cstdlib>
#include <mutex>
#include <string>
#include <variant>
Expand Down Expand Up @@ -53,46 +55,69 @@ bool BillingManager::Init() {
return true;
}

std::string BillingManager::GetCustomId() {
std::optional<std::string> BillingManager::GetCustomId() {
void *handle = dlopen("libsso_api.so", RTLD_LAZY);
std::string custom_id = "";
if (!handle) {
LOG_ERROR("[BillingManager] Fail to open sso APIs.");
} else {
FuncSsoGetLoginInfo sso_get_login_info =
reinterpret_cast<FuncSsoGetLoginInfo>(
dlsym(handle, "sso_get_login_info"));
if (sso_get_login_info) {
sso_login_info_s login_info;
if (!sso_get_login_info(&login_info)) {
custom_id = login_info.uid;
}
}
return std::nullopt;
}
FuncSsoGetLoginInfo sso_get_login_info =
reinterpret_cast<FuncSsoGetLoginInfo>(
dlsym(handle, "sso_get_login_info"));
if (!sso_get_login_info) {
LOG_ERROR("[BillingManager] Fail to find the sso_get_login_info symbol.");
dlclose(handle);
return std::nullopt;
}

std::optional<std::string> custom_id;
sso_login_info_s login_info = {};
int ret = sso_get_login_info(&login_info);
if (ret == SSO_SUCCESS) {
custom_id = login_info.uid;
} else {
LOG_ERROR("[BillingManager] Fail to get the login info. (%d)", ret);
}
// NOTE: written through volatile because a plain memset on a struct that
// is dead afterwards is dropped by the optimizer.
auto *bytes = reinterpret_cast<volatile unsigned char *>(&login_info);
for (std::size_t i = 0; i < sizeof(login_info); ++i) {
bytes[i] = 0;
}
dlclose(handle);
return custom_id;
}

std::string BillingManager::GetCountryCode() {
void *handle = dlopen("libvconf.so.0.3.1", RTLD_LAZY);
char *country_code = "";
std::optional<std::string> BillingManager::GetCountryCode() {
void *handle = dlopen("libvconf.so.0", RTLD_LAZY);
if (!handle) {
LOG_ERROR("[BillingManager] Fail to open vconf APIs.");
} else {
FuncVconfGetStr vconf_get_str =
reinterpret_cast<FuncVconfGetStr>(dlsym(handle, "vconf_get_str"));
if (vconf_get_str) {
country_code = vconf_get_str("db/comss/countrycode");
}
return std::nullopt;
}
FuncVconfGetStr vconf_get_str =
reinterpret_cast<FuncVconfGetStr>(dlsym(handle, "vconf_get_str"));
if (!vconf_get_str) {
LOG_ERROR("[BillingManager] Fail to find the vconf_get_str symbol.");
dlclose(handle);
return std::nullopt;
}

std::optional<std::string> country_code;
char *value = vconf_get_str("db/comss/countrycode");
if (value) {
country_code = value;
free(value);
} else {
LOG_ERROR("[BillingManager] Fail to read db/comss/countrycode.");
}
dlclose(handle);
return country_code;
}

bool BillingManager::IsAvailable(FunctionResult<bool> result) {
LOG_INFO("[BillingManager] Check billing server is available.");

void *handle = dlopen("libcapi-system-info.so.0.2.1", RTLD_LAZY);
void *handle = dlopen("libcapi-system-info.so.0", RTLD_LAZY);
if (!handle) {
LOG_ERROR("[BillingManager] Fail to open system APIs.");
} else {
Expand Down
97 changes: 5 additions & 92 deletions packages/in_app_purchase/tizen/src/billing_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <cassert>
#include <iostream>
#include <mutex>
#include <optional>
#include <string>
#include <variant>

Expand All @@ -18,6 +19,7 @@
#include "rapidjson/document.h"

#define SSO_API_MAX_STRING_LEN 128
#define SSO_SUCCESS 0

namespace in_app_purchase_tizen {

Expand Down Expand Up @@ -50,99 +52,10 @@ typedef enum {
} system_info_error_e;

typedef enum {
SYSTEM_INFO_KEY_NUM_OF_TUNER = 18,
SYSTEM_INFO_KEY_STAMRT_HUB_HBBTV_SUPPORTED = 41,
SYSTEM_INFO_KEY_SMART_LED_SUPPORTED = 56,
SYSTEM_INFO_KEY_KR_CABLE_QAM_SUPPORTED = 59,
SYSTEM_INFO_KEY_SMART_LED_DEMO_POSITION = 63,
SYSTEM_INFO_KEY_PANEL_SIZE = 69,
SYSTEM_INFO_KEY_PANEL_TYPE = 73,
SYSTEM_INFO_KEY_PANEL_TYPE_STRING = 74,
SYSTEM_INFO_KEY_LOCAL_SET = 90,
SYSTEM_INFO_KEY_WIFI_REGION = 109,
SYSTEM_INFO_KEY_NUM_OF_DTV = 110,
SYSTEM_INFO_KEY_NUM_OF_ATV = 112,
SYSTEM_INFO_KEY_NUM_OF_RVU = 121,
SYSTEM_INFO_KEY_NUM_OF_HDMI = 122,
SYSTEM_INFO_KEY_INFO_LINK_SERVER_TYPE = 126,
SYSTEM_INFO_KEY_REGION_KIND = 127,
SYSTEM_INFO_KEY_SW_VERSION = 128,
SYSTEM_INFO_KEY_TUNER_TYPE = 131,
SYSTEM_INFO_KEY_VERSION_MICOM = 133,
SYSTEM_INFO_KEY_VERSION_EMANUAL = 138,
SYSTEM_INFO_KEY_AUTOSTORE = 174,
SYSTEM_INFO_KEY_SERIAL_NUMBER = 187,
SYSTEM_INFO_KEY_SW_VERSION_MODEL = 199,
SYSTEM_INFO_KEY_TARGET_LOCATION = 201,
SYSTEM_INFO_KEY_PANEL_VFREQ = 204,
SYSTEM_INFO_KEY_PANEL_ASPECT_RATIO = 205,
SYSTEM_INFO_KEY_VERSION_EPOP_APP = 209,
SYSTEM_INFO_KEY_VERSION_WIFI = 216,
SYSTEM_INFO_KEY_SATELLITE_MASK = 220,
SYSTEM_INFO_KEY_LANGUAGE_LIST = 227,
SYSTEM_INFO_KEY_USB_COPY_FORMAT_SUPPORTED = 236,
SYSTEM_INFO_KEY_NUM_OF_PVR_RECORD = 238,
SYSTEM_INFO_KEY_CERT_OPTION = 240,
SYSTEM_INFO_KEY_GET_JP_MIGRATION_BACKUP_SOURCE_PATH = 247,
SYSTEM_INFO_KEY_GET_JP_MIGRATION_RESTORE_SOURCE_PATH = 248,
SYSTEM_INFO_KEY_AUTOMOTIONPLUS_CLEAR_BLUR_SUPPORTED = 258,
SYSTEM_INFO_KEY_CHECK_SKIP_LOCALSET = 280,
SYSTEM_INFO_KEY_CHECK_WIFI_VENDOR = 281,
SYSTEM_INFO_KEY_LOCAL_SET_ENUM = 284,
SYSTEM_INFO_KEY_REGION_KIND_ENUM = 285,
SYSTEM_INFO_KEY_PRODUCT_CODE_SW = 291,
SYSTEM_INFO_KEY_PRODUCT_CODE_BOM = 292,
SYSTEM_INFO_KEY_ONTV_SUPPORTED = 304,
SYSTEM_INFO_KEY_HOTEL_TV_SUPPORTED = 315,
SYSTEM_INFO_KEY_ERROR_POPUP_ON_OFF = 320,
SYSTEM_INFO_KEY_TUNER_SHAPE = 325,
SYSTEM_INFO_KEY_PANEL_DEFAULT_VFREQ = 326,
SYSTIM_INFO_KEY_DTV_TYPE = 333,
SYSTEM_INFO_KEY_TUNER_SUP_EPOP = 342,
SYSTEM_INFO_KEY_CES_OPTION = 343,
SYSTEM_INFO_KEY_UPDATE_SUP_EMANUAL = 352,
SYSTEM_INFO_KEY_ENERGY_STAR_LOGO_SUPPORTED = 360,
SYSTEM_INFO_KEY_FHD_EVK_TV_YEAR = 362,
SYSTEM_INFO_KEY_TV_CURRENT_YEAR = 367,
SYSTEM_INFO_KEY_PC_DIMMING_SUPPORT = 370,
SYSTEM_INFO_KEY_EVK_SW_VERSION = 378,
SYSTEM_INFO_KEY_PNP_COUNTRY_LIST = 388,
SYSTEM_INFO_KEY_DIGITAL_COUNTRY_LIST = 389,
SYSTEM_INFO_KEY_ANALOG_COUNTRY_LIST = 390,
SYSTEM_INFO_KEY_VERSION_CAMERA = 457,
SYSTEM_INFO_KEY_VERSION_MIC = 458,
SYSTEM_INFO_KEY_ALWAYS_INSTANT_ON_SUPPORT = 466,
SYSTEM_INFO_KEY_APP_BOOTING_SUPPORT = 488,
SYSTEM_INFO_KEY_PNP_LANGUAGE_LIST = 498,
SYSTEM_INFO_KEY_MODEL_SERIES_INFO = 505,
SYSTEM_INFO_KEY_IOT_HUB_SUPPORTED = 510,
SYSTEM_INFO_KEY_DEFAULT_DIGITAL_COUNTRY = 511,
SYSTEM_INFO_KEY_DEFAULT_ANALOG_COUNTRY = 512,
SYSTEM_INFO_KEY_CH_MAP = 517,
SYSTEM_INFO_KEY_A_PICTURE_DIRECT = 518,
SYSTEM_INFO_KEY_MIN_BACKLIGHT = 532,
SYSTEM_INFO_KEY_CLOUD_SCAN_UPLOAD = 537,
SYSTEM_INFO_KEY_DEFAULT_HDMI_1_BOOTING = 538,
SYSTEM_INFO_KEY_PLATFORM_TYPE = 564,
SYSTEM_INFO_KEY_FRAME_TV = 583,
SYSTEM_INFO_KEY_360VR_SUPPORT = 589,
SYSTEM_INFO_KEY_DYNAMIC_CONTRAST = 590,
SYSTEM_INFO_KEY_RUN_EW = 600,
SYSTEM_INFO_KEY_EXHIBITION_MODE = 601,
SYSTEM_INFO_KEY_ATSC3_SUPPORTED = 604,
SYSTEM_INFO_KEY_PANEL_TIME = 605,
SYSTEM_INFO_KEY_CN_WEB_MODEL = 620,
SYSTEM_INFO_KEY_HOTEL_MIN_VOLUME = 645,
SYSTEM_INFO_KEY_HOTEL_MAX_VOLUME = 646,
SYSTEM_INFO_KEY_HOTEL_MODE = 647,
SYSTEM_INFO_KEY_HOTEL_POWER_ON_VOLUME = 648,
SYSTEM_INFO_KEY_NUM_OF_DISPLAY = 656,
SYSTEM_INFO_KEY_STD_HDR_BL = 668,
SYSTEM_INFO_KEY_HARDWARE_VERSION = 669,
SYSTEM_INFO_KEY_PANEL_TYPE_82INCH_SDC = 670,
} system_info_key_e;

typedef bool (*FuncSsoGetLoginInfo)(sso_login_info_s *login_info);
typedef int (*FuncSsoGetLoginInfo)(sso_login_info_s *login_info);
typedef char *(*FuncVconfGetStr)(const char *in_key);
typedef int (*FuncSystemInfGetValueInt)(system_info_key_e key, int *value);

Expand Down Expand Up @@ -204,8 +117,8 @@ class BillingManager {
bool VerifyInvoice(const char *app_id, const char *custom_id,
const char *invoice_id, const char *country_code,
FunctionResult<VerifyInvoiceAPIResult> result);
std::string GetCustomId();
std::string GetCountryCode();
std::optional<std::string> GetCustomId();
std::optional<std::string> GetCountryCode();

private:
static void OnProducts(const char *detail_result, void *user_data);
Expand Down
12 changes: 10 additions & 2 deletions packages/in_app_purchase/tizen/src/in_app_purchase_tizen_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,19 @@ void InAppPurchaseTizenPlugin::IsServiceAvailable(
}

ErrorOr<std::string> InAppPurchaseTizenPlugin::GetCustomId() {
return billing_->GetCustomId();
std::optional<std::string> custom_id = billing_->GetCustomId();
if (!custom_id.has_value()) {
return FlutterError("Operation failed", "get custom id failed");
}
return *custom_id;
}

ErrorOr<std::string> InAppPurchaseTizenPlugin::GetCountryCode() {
return billing_->GetCountryCode();
std::optional<std::string> country_code = billing_->GetCountryCode();
if (!country_code.has_value()) {
return FlutterError("Operation failed", "get country code failed");
}
return *country_code;
}

} // namespace in_app_purchase_tizen
Expand Down
Loading