15
15
16
16
#include " log.h"
17
17
18
+ namespace {
19
+
18
20
class PackageInfoPlusTizenPlugin : public flutter ::Plugin {
19
21
public:
20
22
static void RegisterWithRegistrar (flutter::PluginRegistrar *registrar) {
@@ -41,89 +43,80 @@ class PackageInfoPlusTizenPlugin : public flutter::Plugin {
41
43
void HandleMethodCall (
42
44
const flutter::MethodCall<flutter::EncodableValue> &method_call,
43
45
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
44
- LOG_INFO (" method : %s" , method_call.method_name ().data ());
45
- std::string replay = " " ;
46
+ const auto &method_name = method_call.method_name ();
46
47
47
- if (method_call. method_name (). compare ( " getAll " ) != 0 ) {
48
- result->Error ( " -1 " , " Not supported method " );
48
+ if (method_name != " getAll " ) {
49
+ result->NotImplemented ( );
49
50
return ;
50
51
}
51
52
52
- char *app_id = nullptr ;
53
- char *pkg_name = nullptr ;
54
- char *version = nullptr ;
55
- char *label = nullptr ;
56
- package_info_h package_info = nullptr ;
57
- flutter::EncodableMap msg;
53
+ flutter::EncodableMap map;
58
54
59
- int ret = app_get_id (&app_id);
60
- if (ret != APP_ERROR_NONE || app_id == nullptr ) {
61
- result->Error (std::to_string (ret), " Failed to get app_id" ,
55
+ char *id = nullptr ;
56
+ int ret = app_get_id (&id);
57
+ if (ret != APP_ERROR_NONE) {
58
+ result->Error (std::to_string (ret), " Failed to get find the app ID." ,
62
59
flutter::EncodableValue (get_error_message (ret)));
63
- goto cleanup ;
60
+ return ;
64
61
}
65
- LOG_INFO (" app id : %s\n " , app_id);
62
+ auto app_id = std::string (id);
63
+ free (id);
66
64
67
- ret = package_info_create (app_id, &package_info);
68
- if (ret != PACKAGE_MANAGER_ERROR_NONE || package_info == nullptr ) {
69
- result->Error (std::to_string (ret), " Failed to create package_info" ,
65
+ package_info_h package_info = nullptr ;
66
+ ret = package_info_create (app_id.c_str (), &package_info);
67
+ if (ret != PACKAGE_MANAGER_ERROR_NONE) {
68
+ result->Error (std::to_string (ret),
69
+ " Failed to create a package_info handle." ,
70
70
flutter::EncodableValue (get_error_message (ret)));
71
- goto cleanup ;
71
+ return ;
72
72
}
73
73
74
+ char *label = nullptr ;
74
75
ret = package_info_get_label (package_info, &label);
75
- if (ret != PACKAGE_MANAGER_ERROR_NONE || label == nullptr ) {
76
- result->Error (std::to_string (ret), " Failed to get app name " ,
76
+ if (ret != PACKAGE_MANAGER_ERROR_NONE) {
77
+ result->Error (std::to_string (ret), " Failed to get the app label. " ,
77
78
flutter::EncodableValue (get_error_message (ret)));
78
- goto cleanup;
79
+ package_info_destroy (package_info);
80
+ return ;
79
81
}
80
- LOG_INFO (" package label : %s\n " , label);
81
-
82
- ret = package_info_get_package (package_info, &pkg_name);
83
- if (ret != PACKAGE_MANAGER_ERROR_NONE || pkg_name == nullptr ) {
84
- result->Error (std::to_string (ret), " Failed to get package name" ,
82
+ map[flutter::EncodableValue (" appName" )] =
83
+ flutter::EncodableValue (std::string (label));
84
+ free (label);
85
+
86
+ char *package_name = nullptr ;
87
+ ret = package_info_get_package (package_info, &package_name);
88
+ if (ret != PACKAGE_MANAGER_ERROR_NONE) {
89
+ result->Error (std::to_string (ret), " Failed to get the package name." ,
85
90
flutter::EncodableValue (get_error_message (ret)));
86
- goto cleanup;
91
+ package_info_destroy (package_info);
92
+ return ;
87
93
}
88
- LOG_INFO (" package name : %s\n " , pkg_name);
94
+ map[flutter::EncodableValue (" packageName" )] =
95
+ flutter::EncodableValue (std::string (package_name));
96
+ free (package_name);
89
97
98
+ char *version = nullptr ;
90
99
ret = package_info_get_version (package_info, &version);
91
- if (ret != PACKAGE_MANAGER_ERROR_NONE || version == nullptr ) {
92
- result->Error (std::to_string (ret), " Failed to get version" ,
100
+ if (ret != PACKAGE_MANAGER_ERROR_NONE) {
101
+ result->Error (std::to_string (ret), " Failed to get the package version. " ,
93
102
flutter::EncodableValue (get_error_message (ret)));
94
- goto cleanup;
95
- }
96
- LOG_INFO (" package version : %s\n " , version);
97
-
98
- msg.insert (std::pair<flutter::EncodableValue, flutter::EncodableValue>(
99
- " appName" , std::string (label)));
100
- msg.insert (std::pair<flutter::EncodableValue, flutter::EncodableValue>(
101
- " packageName" , std::string (pkg_name)));
102
- msg.insert (std::pair<flutter::EncodableValue, flutter::EncodableValue>(
103
- " version" , std::string (version)));
104
- msg.insert (std::pair<flutter::EncodableValue, flutter::EncodableValue>(
105
- " buildNumber" , " Not supported property" ));
106
- result->Success (flutter::EncodableValue (msg));
107
-
108
- cleanup:
109
- if (app_id) {
110
- free (app_id);
111
- }
112
- if (label) {
113
- free (label);
114
- }
115
- if (pkg_name) {
116
- free (pkg_name);
117
- }
118
- if (version) {
119
- free (version);
120
- }
121
- if (package_info) {
122
103
package_info_destroy (package_info);
104
+ return ;
123
105
}
106
+ map[flutter::EncodableValue (" version" )] =
107
+ flutter::EncodableValue (std::string (version));
108
+ free (version);
109
+ package_info_destroy (package_info);
110
+
111
+ map[flutter::EncodableValue (" buildNumber" )] =
112
+ flutter::EncodableValue (" Not supported property" );
113
+
114
+ result->Success (flutter::EncodableValue (map));
124
115
}
125
116
};
126
117
118
+ } // namespace
119
+
127
120
void PackageInfoPlusTizenPluginRegisterWithRegistrar (
128
121
FlutterDesktopPluginRegistrarRef registrar) {
129
122
PackageInfoPlusTizenPlugin::RegisterWithRegistrar (
0 commit comments