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;
33 private Interop.ApplicationManager.AppInfoMetadataCallback _metadataCallback;
34 private Interop.ApplicationManager.AppInfoCategoryCallback _categoryCallback;
35 private Interop.ApplicationManager.AppInfoResControlCallback _resControlCallback;
37 internal ApplicationInfo(IntPtr infoHandle)
39 err = Interop.ApplicationManager.AppInfoGetAppId(infoHandle, out _applicationId);
40 if (err != Interop.ApplicationManager.ErrorCode.None)
42 throw new ArgumentException("Invalid native handle.");
44 _infoHandle = infoHandle;
48 /// A constructor of ApplicationInfo that takes the application ID.
50 /// <param name="applicationId">Application ID.</param>
51 /// <since_tizen> 3 </since_tizen>
52 public ApplicationInfo(string applicationId)
54 _applicationId = applicationId;
58 /// Destructor of the class.
66 /// Gets the application ID.
68 /// <since_tizen> 3 </since_tizen>
69 public string ApplicationId
73 if (!string.IsNullOrEmpty(_applicationId))
74 return _applicationId;
75 IntPtr infoHandle = GetInfoHandle();
76 string appid = string.Empty;
77 if (infoHandle != IntPtr.Zero)
79 err = Interop.ApplicationManager.AppInfoGetAppId(infoHandle, out appid);
80 if (err != Interop.ApplicationManager.ErrorCode.None)
82 Log.Warn(LogTag, "Failed to get the application id. err = " + err);
90 /// Gets the package ID of the application.
92 /// <since_tizen> 3 </since_tizen>
93 public string PackageId
97 IntPtr infoHandle = GetInfoHandle();
98 string packageid = string.Empty;
99 if (infoHandle != IntPtr.Zero)
101 err = Interop.ApplicationManager.AppInfoGetPackage(infoHandle, out packageid);
102 if (err != Interop.ApplicationManager.ErrorCode.None)
104 Log.Warn(LogTag, "Failed to get the package id of " + _applicationId + ". err = " + err);
112 /// Gets the label of the application.
114 /// <since_tizen> 3 </since_tizen>
119 IntPtr infoHandle = GetInfoHandle();
120 string label = string.Empty;
121 if (infoHandle != IntPtr.Zero)
123 err = Interop.ApplicationManager.AppInfoGetLabel(infoHandle, out label);
124 if (err != Interop.ApplicationManager.ErrorCode.None)
126 Log.Warn(LogTag, "Failed to get the app label of " + _applicationId + ". err = " + err);
134 /// Gets the executable path of the application.
136 /// <since_tizen> 3 </since_tizen>
137 public string ExecutablePath
141 IntPtr infoHandle = GetInfoHandle();
142 string exec = string.Empty;
143 if (infoHandle != IntPtr.Zero)
145 err = Interop.ApplicationManager.AppInfoGetExec(infoHandle, out exec);
146 if (err != Interop.ApplicationManager.ErrorCode.None)
148 Log.Warn(LogTag, "Failed to get the executable file path of " + _applicationId + ". err = " + err);
156 /// Gets the absolute path to the icon image.
158 /// <since_tizen> 3 </since_tizen>
159 public string IconPath
163 IntPtr infoHandle = GetInfoHandle();
164 string path = string.Empty;
165 if (infoHandle != IntPtr.Zero)
167 err = Interop.ApplicationManager.AppInfoGetIcon(infoHandle, out path);
168 if (err != Interop.ApplicationManager.ErrorCode.None)
170 Log.Warn(LogTag, "Failed to get the app icon path of " + _applicationId + ". err = " + err);
178 /// Gets the application type name.
180 /// <since_tizen> 3 </since_tizen>
181 public string ApplicationType
185 IntPtr infoHandle = GetInfoHandle();
186 string type = string.Empty;
187 if (infoHandle != IntPtr.Zero)
189 err = Interop.ApplicationManager.AppInfoGetType(infoHandle, out type);
190 if (err != Interop.ApplicationManager.ErrorCode.None)
192 Log.Warn(LogTag, "Failed to get the application type of " + _applicationId + ". err = " + err);
200 /// Gets the application component type.
202 /// <since_tizen> 6 </since_tizen>
203 public ApplicationComponentType ComponentType
207 IntPtr infoHandle = GetInfoHandle();
208 Interop.ApplicationManager.AppInfoAppComponentType componentType = 0;
209 if (infoHandle != IntPtr.Zero)
211 err = Interop.ApplicationManager.AppInfoGetAppComponentType(infoHandle, out componentType);
212 if (err != Interop.ApplicationManager.ErrorCode.None)
214 Log.Warn(LogTag, "Failed to get the application component type of " + _applicationId + ". err = " + err);
217 return (ApplicationComponentType)componentType;
222 /// Gets the application's metadata.
224 /// <since_tizen> 3 </since_tizen>
225 public IDictionary<String, String> Metadata
229 IDictionary<string, string> metadata = new Dictionary<String, String>();
231 _metadataCallback = (string key, string value, IntPtr userData) =>
235 if (!metadata.ContainsKey(key))
236 metadata.Add(key, value);
241 IntPtr infoHandle = GetInfoHandle();
242 if (infoHandle != IntPtr.Zero)
244 err = Interop.ApplicationManager.AppInfoForeachMetadata(infoHandle, _metadataCallback, IntPtr.Zero);
245 if (err != Interop.ApplicationManager.ErrorCode.None)
247 Log.Warn(LogTag, "Failed to get application metadata of " + _applicationId + ". err = " + err);
255 /// Checks whether the application information is nodisplay. If the application icon is not displayed on the menu screen, true; otherwise, false.
257 /// <since_tizen> 3 </since_tizen>
258 public bool IsNoDisplay
262 IntPtr infoHandle = GetInfoHandle();
263 bool nodisplay = false;
264 if (infoHandle != IntPtr.Zero)
266 err = Interop.ApplicationManager.AppInfoIsNodisplay(infoHandle, out nodisplay);
267 if (err != Interop.ApplicationManager.ErrorCode.None)
269 Log.Warn(LogTag, "Failed to get the IsNoDisplay value of " + _applicationId + ". err = " + err);
278 /// Checks whether the application is launched on booting time. If the application automatically starts on boot, true; otherwise, false.
280 /// <since_tizen> 3 </since_tizen>
285 IntPtr infoHandle = GetInfoHandle();
287 if (infoHandle != IntPtr.Zero)
289 err = Interop.ApplicationManager.AppInfoIsOnBoot(infoHandle, out onboot);
290 if (err != Interop.ApplicationManager.ErrorCode.None)
292 Log.Warn(LogTag, "Failed to get the IsOnBoot value of " + _applicationId + ". err = " + err);
300 /// Checks whether the application is preloaded. If the application is preloaded, true; otherwise, false.
302 /// <since_tizen> 3 </since_tizen>
303 public bool IsPreload
307 IntPtr infoHandle = GetInfoHandle();
308 bool preloaded = false;
309 if (infoHandle != IntPtr.Zero)
311 err = Interop.ApplicationManager.AppInfoIsPreLoad(infoHandle, out preloaded);
312 if (err != Interop.ApplicationManager.ErrorCode.None)
314 Log.Warn(LogTag, "Failed to get the IsPreload value of " + _applicationId + ". err = " + err);
322 /// Gets the application's category values specified in the tizen-manifest
324 /// <privilege>http://tizen.org/privilege/packagemanager.admin</privilege>
325 /// <privlevel>platform</privlevel>
326 /// <since_tizen> 6 </since_tizen>
327 public IEnumerable<string> Categories
331 List<string> categories = new List<string>();
333 _categoryCallback = (string category, IntPtr userData) =>
335 categories.Add(category);
339 IntPtr infoHandle = GetInfoHandle();
340 if (infoHandle != IntPtr.Zero)
342 err = Interop.ApplicationManager.AppInfoForeachCategory(infoHandle, _categoryCallback, IntPtr.Zero);
343 if (err != Interop.ApplicationManager.ErrorCode.None)
345 Log.Warn(LogTag, "Failed to get application category of " + _applicationId + ". err = " + err);
353 /// Gets the shared data path.
356 /// 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.
358 /// <since_tizen> 3 </since_tizen>
359 public string SharedDataPath
363 string path = string.Empty;
364 err = Interop.ApplicationManager.AppManagerGetSharedDataPath(ApplicationId, out path);
365 if (err != Interop.ApplicationManager.ErrorCode.None)
367 Log.Warn(LogTag, "Failed to get the SharedDataPath of " + _applicationId + ". err = " + err);
374 /// Gets the shared resource path.
376 /// <since_tizen> 3 </since_tizen>
377 public string SharedResourcePath
381 string path = string.Empty;
382 err = Interop.ApplicationManager.AppManagerGetSharedResourcePath(ApplicationId, out path);
383 if (err != Interop.ApplicationManager.ErrorCode.None)
385 Log.Warn(LogTag, "Failed to get the SharedResourcePath of " + _applicationId + ". err = " + err);
392 /// Gets the shared trust path.
394 /// <since_tizen> 3 </since_tizen>
395 public string SharedTrustedPath
399 string path = string.Empty;
400 err = Interop.ApplicationManager.AppManagerGetSharedTrustedPath(ApplicationId, out path);
401 if (err != Interop.ApplicationManager.ErrorCode.None)
403 Log.Warn(LogTag, "Failed to get the SharedTrustedPath of " + _applicationId + ". err = " + err);
410 /// Gets the external shared data path.
412 /// <since_tizen> 3 </since_tizen>
413 public string ExternalSharedDataPath
417 string path = string.Empty;
418 err = Interop.ApplicationManager.AppManagerGetExternalSharedDataPath(ApplicationId, out path);
419 if (err != Interop.ApplicationManager.ErrorCode.None)
421 Log.Warn(LogTag, "Failed to get the ExternalSharedDataPath of " + _applicationId + ". err = " + err);
428 /// Gets the resource controls.
430 /// <since_tizen> 9 </since_tizen>
431 public IEnumerable<ResourceControl> ResourceControls
435 List<ResourceControl> resourceControls = new List<ResourceControl>();
436 _resControlCallback = (string resType, string minResourceVersion, string maxResourceVersion, string isAutoClose, IntPtr userData) =>
438 resourceControls.Add(new ResourceControl(resType, minResourceVersion, maxResourceVersion, isAutoClose == "true"));
442 IntPtr infoHandle = GetInfoHandle();
443 if (infoHandle != null)
445 err = Interop.ApplicationManager.AppInfoForeachResControl(infoHandle, _resControlCallback, IntPtr.Zero);
446 if (err != Interop.ApplicationManager.ErrorCode.None)
448 Log.Warn(LogTag, "Failed to get the resource controls of " + _applicationId + ". err = " + err);
452 return resourceControls;
457 /// Gets the localized label of the application for the given locale.
459 /// <param name="locale">Locale.</param>
460 /// <returns>The localized label.</returns>
461 /// <since_tizen> 3 </since_tizen>
462 public string GetLocalizedLabel(string locale)
464 string label = string.Empty;
465 err = Interop.ApplicationManager.AppInfoGetLocaledLabel(ApplicationId, locale, out label);
466 if (err != Interop.ApplicationManager.ErrorCode.None)
468 Log.Warn(LogTag, "Failed to get the GetLocalizedLabel of " + _applicationId + ". err = " + err);
474 private IntPtr GetInfoHandle()
476 if (_infoHandle == IntPtr.Zero)
478 IntPtr infoHandle = IntPtr.Zero;
479 err = Interop.ApplicationManager.AppManagerGetAppInfo(_applicationId, out infoHandle);
480 if (err != Interop.ApplicationManager.ErrorCode.None)
482 Log.Warn(LogTag, "Failed to get the handle of the ApplicationInfo. err = " + err);
484 _infoHandle = infoHandle;
490 /// Releases all resources used by the ApplicationInfo class.
492 /// <since_tizen> 3 </since_tizen>
493 public void Dispose()
496 GC.SuppressFinalize(this);
499 private void Dispose(bool disposing)
506 if (_infoHandle != IntPtr.Zero)
508 Interop.ApplicationManager.AppInfoDestroy(_infoHandle);
509 _infoHandle = IntPtr.Zero;