2 * Copyright (c) 2019 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 component.
25 /// <since_tizen> 6 </since_tizen>
26 public class ComponentInfo : IDisposable
28 private const string LogTag = "Tizen.Applications";
29 private bool _disposed = false;
30 private IntPtr _infoHandle = IntPtr.Zero;
31 private string _componentId = string.Empty;
33 internal ComponentInfo(IntPtr infoHandle)
35 Interop.ComponentManager.ErrorCode err = Interop.ComponentManager.ComponentInfoGetComponentId(infoHandle, out _componentId);
36 if (err != Interop.ComponentManager.ErrorCode.None)
38 throw ComponentManager.ComponentManagerErrorFactory.GetException(err, "Invalid native handle.");
40 _infoHandle = infoHandle;
44 /// A constructor of ComponentInfo that takes the component ID.
46 /// <param name="componentId">Component ID.</param>
47 /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
48 /// <exception cref="InvalidOperationException">Thrown when failed because of the system error.</exception>
49 /// <exception cref="OutOfMemoryException">Thrown when failed because of out of memory.</exception>
50 /// <exception cref="UnauthorizedAccessException">Thrown when failed because of permission denied.</exception>>
51 /// <privilege>http://tizen.org/privilege/packagemanager.info</privilege>
52 /// <since_tizen> 6 </since_tizen>
53 public ComponentInfo(string componentId)
55 _componentId = componentId;
56 IntPtr infoHandle = IntPtr.Zero;
57 Interop.ComponentManager.ErrorCode err = Interop.ComponentManager.ComponentInfoCreate(_componentId, out infoHandle);
58 if (err != Interop.ComponentManager.ErrorCode.None)
60 throw ComponentManager.ComponentManagerErrorFactory.GetException(err, "Failed to create the ComponentInfo.");
62 _infoHandle = infoHandle;
66 /// Destructor of the class.
74 /// Gets the component ID.
76 /// <since_tizen> 6 </since_tizen>
77 public string ComponentId
81 if (!string.IsNullOrEmpty(_componentId))
84 string compId = string.Empty;
85 Interop.ComponentManager.ErrorCode err = Interop.ComponentManager.ComponentInfoGetComponentId(_infoHandle, out compId);
86 if (err != Interop.ComponentManager.ErrorCode.None)
88 Log.Warn(LogTag, "Failed to get the ComponentId. err = " + err);
90 _componentId = compId;
97 /// Gets the application ID of the component.
99 /// <since_tizen> 6 </since_tizen>
100 public string ApplicationId
104 string appId = string.Empty;
105 Interop.ComponentManager.ErrorCode err = Interop.ComponentManager.ComponentInfoGetAppId(_infoHandle, out appId);
106 if (err != Interop.ComponentManager.ErrorCode.None)
108 Log.Warn(LogTag, "Failed to get the ApplicationId of " + _componentId + ". err = " + err);
116 /// Gets the type of the component.
118 /// <since_tizen> 6 </since_tizen>
119 public ComponentType ComponentType
123 Interop.ComponentManager.ComponentInfoComponentType type = 0;
124 Interop.ComponentManager.ErrorCode err = Interop.ComponentManager.ComponentInfoGetComponentType(_infoHandle, out type);
125 if (err != Interop.ComponentManager.ErrorCode.None)
127 Log.Warn(LogTag, "Failed to get the Type of " + _componentId + ". err = " + err);
130 return (ComponentType)type;
135 /// Checks whether the icon of the component should be displayed or not.
137 /// <since_tizen> 6 </since_tizen>
138 public bool IsIconDisplayed
142 bool iconDisplay = false;
143 Interop.ComponentManager.ErrorCode err = Interop.ComponentManager.ComponentInfoIsIconDisplay(_infoHandle, out iconDisplay);
144 if (err != Interop.ComponentManager.ErrorCode.None)
146 Log.Warn(LogTag, "Failed to get the IsIconDisplay of " + _componentId + ". err = " + err);
154 /// Checks whether the component should be managed by task-manager or not.
156 /// <since_tizen> 6 </since_tizen>
157 public bool IsManagedByTaskManager
161 bool managed = false;
162 Interop.ComponentManager.ErrorCode err = Interop.ComponentManager.ComponentInfoIsManagedByTaskManager(_infoHandle, out managed);
163 if (err != Interop.ComponentManager.ErrorCode.None)
165 Log.Warn(LogTag, "Failed to get the IsManagedByTaskManager of " + _componentId + ". err = " + err);
173 /// Gets the absolute path of the icon image.
175 /// <since_tizen> 6 </since_tizen>
176 public string IconPath
180 string path = string.Empty;
181 Interop.ComponentManager.ErrorCode err = Interop.ComponentManager.ComponentInfoGetIcon(_infoHandle, out path);
182 if (err != Interop.ComponentManager.ErrorCode.None)
184 Log.Warn(LogTag, "Failed to get the IconPath of " + _componentId + ". err = " + err);
192 /// Gets the label of the component.
198 string label = string.Empty;
199 Interop.ComponentManager.ErrorCode err = Interop.ComponentManager.ComponentInfoGetLabel(_infoHandle, out label);
200 if (err != Interop.ComponentManager.ErrorCode.None)
202 Log.Warn(LogTag, "Failed to get the Label of " + _componentId + ". err = " + err);
210 /// Gets the localized label of the component for the given locale.
212 /// <param name="locale">Locale.</param>
213 /// <remarks>The format of locale is language and country code. (available value: "[2-letter lowercase language code (ISO 639-1)]-[2-letter lowercase country code (ISO 3166-alpha-2)]")</remarks>
214 /// <returns>The localized label.</returns>
215 /// <since_tizen> 6 </since_tizen>
216 public string GetLocalizedLabel(string locale)
218 string label = string.Empty;
219 Interop.ComponentManager.ErrorCode err = Interop.ComponentManager.ComponentInfoGetLocalizedLabel(_infoHandle, locale, out label);
220 if (err != Interop.ComponentManager.ErrorCode.None)
222 Log.Warn(LogTag, "Failed to get the GetLocalizedLabel of " + _componentId + ". err = " + err);
229 /// Releases all resources used by the ComponentInfo class.
231 /// <since_tizen> 6 </since_tizen>
232 public void Dispose()
235 GC.SuppressFinalize(this);
239 /// Releases all resources used by the ComponentInfo class.
241 /// <param name="disposing">Disposing</param>
242 /// <since_tizen> 6 </since_tizen>
243 private void Dispose(bool disposing)
252 if (_infoHandle != IntPtr.Zero)
254 Interop.ComponentManager.ComponentInfoDestroy(_infoHandle);
255 _infoHandle = IntPtr.Zero;