[UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
internal delegate bool PackageInfoDependencyInfoCallback(string from, string to, string type, string requiredVersion, IntPtr userData);
+ [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
+ internal delegate bool PackageInfoResAllowedPackageCallback(string allowedPackage, IntPtr requiredPrivileges, IntPtr userData);
+
// Any change here might require changes in Tizen.Applications.AppType enum
internal enum AppType
{
[DllImport(Libraries.PackageManager, EntryPoint = "package_info_foreach_dependency_info_depends_on")]
internal static extern ErrorCode PackageInfoForeachDependencyInfoDependsOn(IntPtr handle, PackageInfoDependencyInfoCallback callback, IntPtr userData);
+
+ [DllImport(Libraries.PackageManager, EntryPoint = "package_info_foreach_res_allowed_package")]
+ internal static extern ErrorCode PackageInfoForeachResAllowedPackage(IntPtr handle, PackageInfoResAllowedPackageCallback callback, IntPtr user_data);
+
+ [DllImport(Libraries.PackageManager, EntryPoint = "package_info_foreach_required_privilege")]
+ internal static extern ErrorCode PackageInfoForeachRequiredPrivilege(IntPtr privilegeHandle, PackageInfoPrivilegeInfoCallback callback, IntPtr user_data);
}
}
[DllImport(Libraries.PackageManager, EntryPoint = "package_manager_filter_add_bool")]
internal static extern ErrorCode PackageManagerFilterAdd(IntPtr handle, string property, bool value);
+ [DllImport(Libraries.PackageManager, EntryPoint = "package_manager_filter_add_string")]
+ internal static extern ErrorCode PackageManagerFilterAdd(IntPtr handle, string property, string value);
+
[DllImport(Libraries.PackageManager, EntryPoint = "package_manager_filter_foreach_package_info")]
internal static extern ErrorCode PackageManagerFilterForeachPackageInfo(IntPtr handle, PackageManagerPackageInfoCallback callback, IntPtr userData);
private int _callbackId = 0;
private List<PackageDependencyInformation> _dependencyTo;
private List<PackageDependencyInformation> _dependencyFrom;
+ private IReadOnlyDictionary<string, IEnumerable<string>> _allowedPackagesAndPrivilegesList;
private Package(string pkgId)
{
return (CertCompareResultType)compareResult;
}
+ /// <summary>
+ /// The allowed packages and required privileges information.
+ /// </summary>
+ /// <remarks> The dictionary contains application IDs as the keys, and a collection of privileges related to that application as the value.</remarks>
+ /// <since_tizen> 9 </since_tizen>
+ public IReadOnlyDictionary<string, IEnumerable<string>> AllowedPackagesAndPrivileges
+ {
+ get { return _allowedPackagesAndPrivilegesList; }
+ }
+
// This method assumes that given arguments are already validated and have valid values.
internal static Package CreatePackage(IntPtr handle, string pkgId)
{
package._privileges = GetPackagePrivilegeInformation(handle);
package._dependencyTo = GetPackageDependency(handle);
package._dependencyFrom = GetPackageDependencyDependsOn(handle);
+ package._allowedPackagesAndPrivilegesList = GetAllowedPackagesAndPrivileges(handle);
return package;
}
}
return dependencies;
}
+
+ private static Dictionary<string, IEnumerable<string>> GetAllowedPackagesAndPrivileges(IntPtr packageInfoHandle)
+ {
+ Interop.PackageManager.ErrorCode err;
+ Dictionary<string, IEnumerable<string>> allowedPackagesAndPrivileges = new Dictionary<string, IEnumerable<string>>();
+ Interop.Package.PackageInfoResAllowedPackageCallback allowedPackageCallback = (allowedPackage, requiredPrivileges, userData) =>
+ {
+ List<string> requiredPrivilegesList = new List<string>();
+ Interop.Package.PackageInfoPrivilegeInfoCallback requiredPrivCallback = (priv, requiredPrivCbUserData) =>
+ {
+ requiredPrivilegesList.Add(priv);
+ return true;
+ };
+ err = Interop.Package.PackageInfoForeachRequiredPrivilege(requiredPrivileges, requiredPrivCallback, IntPtr.Zero);
+ if (err != Interop.PackageManager.ErrorCode.None)
+ {
+ Log.Warn(LogTag, string.Format("Failed to get required privileges of allowed packages info. err = {0}", err));
+ }
+ else
+ {
+ allowedPackagesAndPrivileges.Add(allowedPackage, requiredPrivilegesList);
+ }
+ return true;
+ };
+
+ err = Interop.Package.PackageInfoForeachResAllowedPackage(packageInfoHandle, allowedPackageCallback, IntPtr.Zero);
+ if (err != Interop.PackageManager.ErrorCode.None)
+ {
+ Log.Warn(LogTag, string.Format("Failed to get allowed packages info. err = {0}", err));
+ }
+ return allowedPackagesAndPrivileges;
+ }
}
}
public class PackageFilter
{
private IDictionary<string, bool> _filter;
+ private IDictionary<string, string> _stringFilter;
/// <summary>
/// The default constructor with an empty filter list. All the installed applications will satisfy this filter unless updated with more specific filters.
public PackageFilter()
{
_filter = new Dictionary<string, bool>();
+ _stringFilter = new Dictionary<string, string>();
}
/// <summary>
}
/// <summary>
+ /// The constructor with specific filters. Using this will filter out the installed packages which do not meet the filter criteria.
+ /// </summary>
+ /// <remarks>The dictionary contains filter keys as the keys, and filter values as the value.</remarks>
+ /// <param name="stringFilter">Package filters using string values.</param>
+ /// <since_tizen> 9 </since_tizen>
+ public PackageFilter(IDictionary<string, string> stringFilter)
+ {
+ _stringFilter = stringFilter;
+ }
+
+ /// <summary>
+ /// The constructor with specific filters. Using this will filter out the installed packages which do not meet the filter criteria.
+ /// </summary>
+ /// <param name="filter">Package filters.</param>
+ /// <param name="stringFilter">Package filters using string values.</param>
+ /// <since_tizen> 9 </since_tizen>
+ public PackageFilter(IDictionary<string, bool> filter, IDictionary<string, string> stringFilter)
+ {
+ _filter = filter;
+ _stringFilter = stringFilter;
+ }
+
+ /// <summary>
/// Filters to be used in the GetPackages method.
/// </summary>
/// <since_tizen> 3 </since_tizen>
}
/// <summary>
+ /// String filters to be used in the GetPackages method.
+ /// </summary>
+ /// <since_tizen> 9 </since_tizen>
+ public IDictionary<string, string> StringFilters
+ {
+ get
+ {
+ return _stringFilter;
+ }
+ }
+
+ /// <summary>
/// This class contains possible keys for the filter to be used in the GetPackages method.
/// </summary>
/// <since_tizen> 3 </since_tizen>
/// </summary>
/// <since_tizen> 3 </since_tizen>
public const string Preload = "PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD";
+
+ /// <summary>
+ /// Key of the string property for filtering the resource type of the package.
+ /// </summary>
+ /// <since_tizen> 9 </since_tizen>
+ public const string ResourceType = "PMINFO_PKGINFO_PROP_PACKAGE_RES_TYPE";
}
}
}
break;
}
}
+
+ }
+
+ if (filter != null && filter.StringFilters != null)
+ {
+ foreach (KeyValuePair<string, string> entry in filter?.StringFilters)
+ {
+ err = Interop.PackageManager.PackageManagerFilterAdd(filterHandle, entry.Key, entry.Value);
+ if (err != Interop.PackageManager.ErrorCode.None)
+ {
+ Log.Warn(LogTag, string.Format("Failed to configure package filter. err = {0}", err));
+ break;
+ }
+ }
}
if (err == Interop.PackageManager.ErrorCode.None)