2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Collections.Generic;
20 namespace Tizen.Applications
23 /// This class provides methods and properties to get information of the application.
25 /// <since_tizen> 3 </since_tizen>
26 public class ApplicationInfo : IDisposable
28 private const string LogTag = "Tizen.Applications";
29 private bool _disposed = false;
30 private IntPtr _infoHandle = IntPtr.Zero;
31 private string _applicationId = string.Empty;
32 private Interop.ApplicationManager.ErrorCode err = Interop.ApplicationManager.ErrorCode.None;
34 internal ApplicationInfo(IntPtr infoHandle)
36 err = Interop.ApplicationManager.AppInfoGetAppId(infoHandle, out _applicationId);
37 if (err != Interop.ApplicationManager.ErrorCode.None)
39 throw new ArgumentException("Invalid native handle.");
41 _infoHandle = infoHandle;
45 /// A constructor of ApplicationInfo that takes the application ID.
47 /// <param name="applicationId">Application ID.</param>
48 /// <since_tizen> 3 </since_tizen>
49 public ApplicationInfo(string applicationId)
51 _applicationId = applicationId;
55 /// Destructor of the class.
63 /// Gets the application ID.
65 /// <since_tizen> 3 </since_tizen>
66 public string ApplicationId
70 if (!string.IsNullOrEmpty(_applicationId))
71 return _applicationId;
72 IntPtr infoHandle = GetInfoHandle();
73 string appid = string.Empty;
74 if (infoHandle != IntPtr.Zero)
76 err = Interop.ApplicationManager.AppInfoGetAppId(infoHandle, out appid);
77 if (err != Interop.ApplicationManager.ErrorCode.None)
79 Log.Warn(LogTag, "Failed to get the application id. err = " + err);
87 /// Gets the package ID of the application.
89 /// <since_tizen> 3 </since_tizen>
90 public string PackageId
94 IntPtr infoHandle = GetInfoHandle();
95 string packageid = string.Empty;
96 if (infoHandle != IntPtr.Zero)
98 err = Interop.ApplicationManager.AppInfoGetPackage(infoHandle, out packageid);
99 if (err != Interop.ApplicationManager.ErrorCode.None)
101 Log.Warn(LogTag, "Failed to get the package id of " + _applicationId + ". err = " + err);
109 /// Gets the label of the application.
111 /// <since_tizen> 3 </since_tizen>
116 IntPtr infoHandle = GetInfoHandle();
117 string label = string.Empty;
118 if (infoHandle != IntPtr.Zero)
120 err = Interop.ApplicationManager.AppInfoGetLabel(infoHandle, out label);
121 if (err != Interop.ApplicationManager.ErrorCode.None)
123 Log.Warn(LogTag, "Failed to get the app label of " + _applicationId + ". err = " + err);
131 /// Gets the executable path of the application.
133 /// <since_tizen> 3 </since_tizen>
134 public string ExecutablePath
138 IntPtr infoHandle = GetInfoHandle();
139 string exec = string.Empty;
140 if (infoHandle != IntPtr.Zero)
142 err = Interop.ApplicationManager.AppInfoGetExec(infoHandle, out exec);
143 if (err != Interop.ApplicationManager.ErrorCode.None)
145 Log.Warn(LogTag, "Failed to get the executable file path of " + _applicationId + ". err = " + err);
153 /// Gets the absolute path to the icon image.
155 /// <since_tizen> 3 </since_tizen>
156 public string IconPath
160 IntPtr infoHandle = GetInfoHandle();
161 string path = string.Empty;
162 if (infoHandle != IntPtr.Zero)
164 err = Interop.ApplicationManager.AppInfoGetIcon(infoHandle, out path);
165 if (err != Interop.ApplicationManager.ErrorCode.None)
167 Log.Warn(LogTag, "Failed to get the app icon path of " + _applicationId + ". err = " + err);
175 /// Gets the application type name.
177 /// <since_tizen> 3 </since_tizen>
178 public string ApplicationType
182 IntPtr infoHandle = GetInfoHandle();
183 string type = string.Empty;
184 if (infoHandle != IntPtr.Zero)
186 err = Interop.ApplicationManager.AppInfoGetType(infoHandle, out type);
187 if (err != Interop.ApplicationManager.ErrorCode.None)
189 Log.Warn(LogTag, "Failed to get the application type of " + _applicationId + ". err = " + err);
197 /// Gets the application's metadata.
199 /// <since_tizen> 3 </since_tizen>
200 public IDictionary<String, String> Metadata
204 IDictionary<string, string> metadata = new Dictionary<String, String>();
206 Interop.ApplicationManager.AppInfoMetadataCallback cb = (string key, string value, IntPtr userData) =>
210 metadata.Add(key, value);
215 IntPtr infoHandle = GetInfoHandle();
216 if (infoHandle != IntPtr.Zero)
218 err = Interop.ApplicationManager.AppInfoForeachMetadata(infoHandle, cb, IntPtr.Zero);
219 if (err != Interop.ApplicationManager.ErrorCode.None)
221 Log.Warn(LogTag, "Failed to get application metadata of " + _applicationId + ". err = " + err);
229 /// Checks whether the application information is nodisplay. If the application icon is not displayed on the menu screen, true; otherwise, false.
231 /// <since_tizen> 3 </since_tizen>
232 public bool IsNoDisplay
236 IntPtr infoHandle = GetInfoHandle();
237 bool nodisplay = false;
238 if (infoHandle != IntPtr.Zero)
240 err = Interop.ApplicationManager.AppInfoIsNodisplay(infoHandle, out nodisplay);
241 if (err != Interop.ApplicationManager.ErrorCode.None)
243 Log.Warn(LogTag, "Failed to get the IsNoDisplay value of " + _applicationId + ". err = " + err);
252 /// Checks whether the application is launched on booting time. If the application automatically starts on boot, true; otherwise, false.
254 /// <since_tizen> 3 </since_tizen>
259 IntPtr infoHandle = GetInfoHandle();
261 if (infoHandle != IntPtr.Zero)
263 err = Interop.ApplicationManager.AppInfoIsOnBoot(infoHandle, out onboot);
264 if (err != Interop.ApplicationManager.ErrorCode.None)
266 Log.Warn(LogTag, "Failed to get the IsOnBoot value of " + _applicationId + ". err = " + err);
274 /// Checks whether the application is preloaded. If the application is preloaded, true; otherwise, false.
276 /// <since_tizen> 3 </since_tizen>
277 public bool IsPreload
281 IntPtr infoHandle = GetInfoHandle();
282 bool preloaded = false;
283 if (infoHandle != IntPtr.Zero)
285 err = Interop.ApplicationManager.AppInfoIsPreLoad(infoHandle, out preloaded);
286 if (err != Interop.ApplicationManager.ErrorCode.None)
288 Log.Warn(LogTag, "Failed to get the IsPreload value of " + _applicationId + ". err = " + err);
296 /// Gets the shared data path.
299 /// An application that wants to use shared/data directory must declare http://tizen.org/privilege/appdir.shareddata privilege. If the application doesn't declare the privilege, the framework will not create shared/data directory for the application. This property will return empty string when the application doesn't have shared/data directory.
301 /// <since_tizen> 3 </since_tizen>
302 public string SharedDataPath
306 string path = string.Empty;
307 err = Interop.ApplicationManager.AppManagerGetSharedDataPath(ApplicationId, out path);
308 if (err != Interop.ApplicationManager.ErrorCode.None)
310 Log.Warn(LogTag, "Failed to get the SharedDataPath of " + _applicationId + ". err = " + err);
317 /// Gets the shared resource path.
319 /// <since_tizen> 3 </since_tizen>
320 public string SharedResourcePath
324 string path = string.Empty;
325 err = Interop.ApplicationManager.AppManagerGetSharedResourcePath(ApplicationId, out path);
326 if (err != Interop.ApplicationManager.ErrorCode.None)
328 Log.Warn(LogTag, "Failed to get the SharedResourcePath of " + _applicationId + ". err = " + err);
335 /// Gets the shared trust path.
337 /// <since_tizen> 3 </since_tizen>
338 public string SharedTrustedPath
342 string path = string.Empty;
343 err = Interop.ApplicationManager.AppManagerGetSharedTrustedPath(ApplicationId, out path);
344 if (err != Interop.ApplicationManager.ErrorCode.None)
346 Log.Warn(LogTag, "Failed to get the SharedTrustedPath of " + _applicationId + ". err = " + err);
353 /// Gets the external shared data path.
355 /// <since_tizen> 3 </since_tizen>
356 public string ExternalSharedDataPath
360 string path = string.Empty;
361 err = Interop.ApplicationManager.AppManagerGetExternalSharedDataPath(ApplicationId, out path);
362 if (err != Interop.ApplicationManager.ErrorCode.None)
364 Log.Warn(LogTag, "Failed to get the ExternalSharedDataPath of " + _applicationId + ". err = " + err);
371 /// Gets the localized label of the application for the given locale.
373 /// <param name="locale">Locale.</param>
374 /// <since_tizen> 3 </since_tizen>
375 public string GetLocalizedLabel(string locale)
377 string label = string.Empty;
378 err = Interop.ApplicationManager.AppInfoGetLocaledLabel(ApplicationId, locale, out label);
379 if (err != Interop.ApplicationManager.ErrorCode.None)
381 Log.Warn(LogTag, "Failed to get the GetLocalizedLabel of " + _applicationId + ". err = " + err);
387 private IntPtr GetInfoHandle()
389 if (_infoHandle == IntPtr.Zero)
391 IntPtr infoHandle = IntPtr.Zero;
392 err = Interop.ApplicationManager.AppManagerGetAppInfo(_applicationId, out infoHandle);
393 if (err != Interop.ApplicationManager.ErrorCode.None)
395 Log.Warn(LogTag, "Failed to get the handle of the ApplicationInfo. err = " + err);
397 _infoHandle = infoHandle;
403 /// Releases all resources used by the ApplicationInfo class.
405 /// <since_tizen> 3 </since_tizen>
406 public void Dispose()
409 GC.SuppressFinalize(this);
412 private void Dispose(bool disposing)
419 if (_infoHandle != IntPtr.Zero)
421 Interop.ApplicationManager.AppInfoDestroy(_infoHandle);
422 _infoHandle = IntPtr.Zero;