/// Copyright 2016 by Samsung Electronics, Inc.,
///
/// This software is the confidential and proprietary information
/// of Samsung Electronics, Inc. ("Confidential Information"). You
/// shall not disclose such Confidential Information and shall use
/// it only in accordance with the terms of the license agreement
/// you entered into with Samsung.
using System;
using System.Collections.Generic;
namespace Tizen.Applications.Managers
{
///
/// InstalledApplicationFilter class. This class is a parameter of InstallerApplicationAppsAsync method.
///
public class InstalledApplicationFilter : IDisposable
{
///
/// Keys class. This class is a possible key to use in the InstalledApplicationFilter.
///
public static class Keys
{
///
///
///
public const string Id = "PACKAGE_INFO_PROP_APP_ID";
///
///
///
public const string Type = "PACKAGE_INFO_PROP_APP_TYPE";
///
///
///
public const string Category = "PACKAGE_INFO_PROP_APP_CATEGORY";
///
///
///
public const string NoDisplay = "PACKAGE_INFO_PROP_APP_NODISPLAY";
///
///
///
public const string TaskManage = "PACKAGE_INFO_PROP_APP_TASKMANAGE";
}
private IntPtr _handle;
private bool disposed = false;
private const string LogTag = "Tizen.Applications.Managers";
private int ret = 0;
public InstalledApplicationFilter(IDictionary filter)
{
ret = Interop.ApplicationManager.AppInfoFilterCreate(out _handle);
if (ret != 0)
{
ApplicationManagerErrorFactory.ExceptionChecker(ret, _handle, "InstalledApplicationFilter creation failed.");
}
foreach (var item in filter)
{
if ((item.Key == Keys.Id) || (item.Key == Keys.Type) || (item.Key == Keys.Category))
{
ret = Interop.ApplicationManager.AppInfoFilterAddString(_handle, item.Key, item.Value);
if (ret != 0)
{
ApplicationManagerErrorFactory.ExceptionChecker(ret, _handle, "InstalledApplicationFilter item add failed.");
}
}
else if ((item.Key == Keys.NoDisplay) || (item.Key == Keys.TaskManage))
{
ret = Interop.ApplicationManager.AppInfoFilterAddBool(_handle, item.Key, Convert.ToBoolean(item.Value));
if (ret != 0)
{
ApplicationManagerErrorFactory.ExceptionChecker(ret, _handle, "InstalledApplicationFilter item add failed.");
}
}
else
{
Log.Warn(LogTag, "InstalledApplicationFilter is NOT supported " + item.Key + " key.");
}
}
}
internal IntPtr Handle
{
get
{
return _handle;
}
}
~InstalledApplicationFilter()
{
Dispose(false);
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool disposing)
{
if (disposed)
return;
if (disposing)
{
// to be used if there are any other disposable objects
}
if (_handle != IntPtr.Zero)
{
Interop.ApplicationManager.AppInfoFilterDestroy(_handle);
}
disposed = true;
}
}
}