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 public class ApplicationInfo : IDisposable
27 private const string LogTag = "Tizen.Applications";
28 private bool _disposed = false;
29 private IntPtr _infoHandle = IntPtr.Zero;
30 private string _applicationId = string.Empty;
31 private Interop.ApplicationManager.ErrorCode err = Interop.ApplicationManager.ErrorCode.None;
33 internal ApplicationInfo(IntPtr infoHandle)
35 err = Interop.ApplicationManager.AppInfoGetAppId(infoHandle, out _applicationId);
36 if (err != Interop.ApplicationManager.ErrorCode.None)
38 throw new ArgumentException("Invalid native handle.");
40 _infoHandle = infoHandle;
44 /// A constructor of ApplicationInfo that takes the application id.
46 /// <param name="applicationId">application id.</param>
47 public ApplicationInfo(string applicationId)
49 _applicationId = applicationId;
53 /// Destructor of the class
61 /// Gets the application id.
63 public string ApplicationId
67 if (!string.IsNullOrEmpty(_applicationId))
68 return _applicationId;
69 IntPtr infoHandle = GetInfoHandle();
70 string appid = string.Empty;
71 if (infoHandle != IntPtr.Zero)
73 err = Interop.ApplicationManager.AppInfoGetAppId(infoHandle, out appid);
74 if (err != Interop.ApplicationManager.ErrorCode.None)
76 Log.Warn(LogTag, "Failed to get the application id. err = " + err);
84 /// Gets the package id of the application.
86 public string PackageId
90 IntPtr infoHandle = GetInfoHandle();
91 string packageid = string.Empty;
92 if (infoHandle != IntPtr.Zero)
94 err = Interop.ApplicationManager.AppInfoGetPackage(infoHandle, out packageid);
95 if (err != Interop.ApplicationManager.ErrorCode.None)
97 Log.Warn(LogTag, "Failed to get the package id of " + _applicationId + ". err = " + err);
105 /// Gets the label of the application.
111 IntPtr infoHandle = GetInfoHandle();
112 string label = string.Empty;
113 if (infoHandle != IntPtr.Zero)
115 err = Interop.ApplicationManager.AppInfoGetLabel(infoHandle, out label);
116 if (err != Interop.ApplicationManager.ErrorCode.None)
118 Log.Warn(LogTag, "Failed to get the app label of " + _applicationId + ". err = " + err);
126 /// Gets the executable path of the application.
128 public string ExecutablePath
132 IntPtr infoHandle = GetInfoHandle();
133 string exec = string.Empty;
134 if (infoHandle != IntPtr.Zero)
136 err = Interop.ApplicationManager.AppInfoGetExec(infoHandle, out exec);
137 if (err != Interop.ApplicationManager.ErrorCode.None)
139 Log.Warn(LogTag, "Failed to get the executable file path of " + _applicationId + ". err = " + err);
147 /// Gets the absolute path to the icon image.
149 public string IconPath
153 IntPtr infoHandle = GetInfoHandle();
154 string path = string.Empty;
155 if (infoHandle != IntPtr.Zero)
157 err = Interop.ApplicationManager.AppInfoGetIcon(infoHandle, out path);
158 if (err != Interop.ApplicationManager.ErrorCode.None)
160 Log.Warn(LogTag, "Failed to get the app icon path of " + _applicationId + ". err = " + err);
168 /// Gets the application type name.
170 public string ApplicationType
174 IntPtr infoHandle = GetInfoHandle();
175 string type = string.Empty;
176 if (infoHandle != IntPtr.Zero)
178 err = Interop.ApplicationManager.AppInfoGetType(infoHandle, out type);
179 if (err != Interop.ApplicationManager.ErrorCode.None)
181 Log.Warn(LogTag, "Failed to get the application type of " + _applicationId + ". err = " + err);
189 /// Gets the application's metadata.
191 public IDictionary<String, String> Metadata
195 IDictionary<string, string> metadata = new Dictionary<String, String>();
197 Interop.ApplicationManager.AppInfoMetadataCallback cb = (string key, string value, IntPtr userData) =>
201 metadata.Add(key, value);
206 IntPtr infoHandle = GetInfoHandle();
207 if (infoHandle != IntPtr.Zero)
209 err = Interop.ApplicationManager.AppInfoForeachMetadata(infoHandle, cb, IntPtr.Zero);
210 if (err != Interop.ApplicationManager.ErrorCode.None)
212 Log.Warn(LogTag, "Failed to get application metadata of " + _applicationId + ". err = " + err);
220 /// Checks whether application information is nodisplay. If the application icon is not displayed on the menu screen, true; otherwise, false.
222 public bool IsNoDisplay
226 IntPtr infoHandle = GetInfoHandle();
227 bool nodisplay = false;
228 if (infoHandle != IntPtr.Zero)
230 err = Interop.ApplicationManager.AppInfoIsNodisplay(infoHandle, out nodisplay);
231 if (err != Interop.ApplicationManager.ErrorCode.None)
233 Log.Warn(LogTag, "Failed to get the IsNoDisplay value of " + _applicationId + ". err = " + err);
242 /// Checks whether application is launched on booting time. If the application will be automatically start on boot, true; otherwise, false.
248 IntPtr infoHandle = GetInfoHandle();
250 if (infoHandle != IntPtr.Zero)
252 err = Interop.ApplicationManager.AppInfoIsOnBoot(infoHandle, out onboot);
253 if (err != Interop.ApplicationManager.ErrorCode.None)
255 Log.Warn(LogTag, "Failed to get the IsOnBoot value of " + _applicationId + ". err = " + err);
263 /// Checks whether application is preloaded. If the application is preloaded, true; otherwise, false.
265 public bool IsPreload
269 IntPtr infoHandle = GetInfoHandle();
270 bool preloaded = false;
271 if (infoHandle != IntPtr.Zero)
273 err = Interop.ApplicationManager.AppInfoIsPreLoad(infoHandle, out preloaded);
274 if (err != Interop.ApplicationManager.ErrorCode.None)
276 Log.Warn(LogTag, "Failed to get the IsPreload value of " + _applicationId + ". err = " + err);
284 /// Gets the shared data path.
286 public string SharedDataPath
290 string path = string.Empty;
291 err = Interop.ApplicationManager.AppManagerGetSharedDataPath(ApplicationId, out path);
292 if (err != Interop.ApplicationManager.ErrorCode.None)
294 Log.Warn(LogTag, "Failed to get the SharedDataPath of " + _applicationId + ". err = " + err);
301 /// Gets the shared resource path.
303 public string SharedResourcePath
307 string path = string.Empty;
308 err = Interop.ApplicationManager.AppManagerGetSharedResourcePath(ApplicationId, out path);
309 if (err != Interop.ApplicationManager.ErrorCode.None)
311 Log.Warn(LogTag, "Failed to get the SharedResourcePath of " + _applicationId + ". err = " + err);
318 /// Gets the shared trust path.
320 public string SharedTrustedPath
324 string path = string.Empty;
325 err = Interop.ApplicationManager.AppManagerGetSharedTrustedPath(ApplicationId, out path);
326 if (err != Interop.ApplicationManager.ErrorCode.None)
328 Log.Warn(LogTag, "Failed to get the SharedTrustedPath of " + _applicationId + ". err = " + err);
335 /// Gets the external shared data path.
337 public string ExternalSharedDataPath
341 string path = string.Empty;
342 err = Interop.ApplicationManager.AppManagerGetExternalSharedDataPath(ApplicationId, out path);
343 if (err != Interop.ApplicationManager.ErrorCode.None)
345 Log.Warn(LogTag, "Failed to get the ExternalSharedDataPath of " + _applicationId + ". err = " + err);
352 /// Gets the localized label of application for the given locale.
354 /// <param name="locale">locale.</param>
355 public string GetLocalizedLabel(string locale)
357 string label = string.Empty;
358 err = Interop.ApplicationManager.AppInfoGetLocaledLabel(ApplicationId, locale, out label);
359 if (err != Interop.ApplicationManager.ErrorCode.None)
361 Log.Warn(LogTag, "Failed to get the GetLocalizedLabel of " + _applicationId + ". err = " + err);
367 private IntPtr GetInfoHandle()
369 if (_infoHandle == IntPtr.Zero)
371 IntPtr infoHandle = IntPtr.Zero;
372 err = Interop.ApplicationManager.AppManagerGetAppInfo(_applicationId, out infoHandle);
373 if (err != Interop.ApplicationManager.ErrorCode.None)
375 Log.Warn(LogTag, "Failed to get the handle of the ApplicationInfo. err = " + err);
377 _infoHandle = infoHandle;
383 /// Releases all resources used by the ApplicationInfo class.
385 public void Dispose()
388 GC.SuppressFinalize(this);
391 private void Dispose(bool disposing)
398 if (_infoHandle != IntPtr.Zero)
400 Interop.ApplicationManager.AppInfoDestroy(_infoHandle);
401 _infoHandle = IntPtr.Zero;