bitwarden-android/src/Android/Utilities/AndroidHelpers.cs

52 lines
1.7 KiB
C#
Raw Normal View History

2020-02-10 22:07:06 +03:00
using System.Collections.Generic;
using System.Threading.Tasks;
using Android.Content;
2019-05-11 06:43:35 +03:00
using Android.Provider;
2020-02-10 22:07:06 +03:00
using Bit.App.Utilities;
2019-05-11 06:43:35 +03:00
namespace Bit.Droid.Utilities
{
public static class AndroidHelpers
{
2020-02-10 22:07:06 +03:00
private static string BaseEnvironmentUrlRestrictionKey = "baseEnvironmentUrl";
2019-05-11 06:43:35 +03:00
public static string GetFileName(Context context, Android.Net.Uri uri)
{
string name = null;
string[] projection = { MediaStore.MediaColumns.DisplayName };
var metaCursor = context.ContentResolver.Query(uri, projection, null, null, null);
if (metaCursor != null)
2019-05-11 06:43:35 +03:00
{
try
{
if (metaCursor.MoveToFirst())
2019-05-11 06:43:35 +03:00
{
name = metaCursor.GetString(0);
}
}
finally
{
metaCursor.Close();
}
}
return name;
}
2020-02-10 22:07:06 +03:00
public static async Task SetPreconfiguredRestrictionSettingsAsync(Context context)
{
var restrictionsManager = (RestrictionsManager)context.GetSystemService(Context.RestrictionsService);
var restrictions = restrictionsManager.ApplicationRestrictions;
var dict = new Dictionary<string, string>();
if (restrictions.ContainsKey(BaseEnvironmentUrlRestrictionKey))
2020-02-10 22:07:06 +03:00
{
dict.Add(BaseEnvironmentUrlRestrictionKey, restrictions.GetString(BaseEnvironmentUrlRestrictionKey));
}
if (dict.Count > 0)
2020-02-10 22:07:06 +03:00
{
await AppHelpers.SetPreconfiguredSettingsAsync(dict);
}
}
2019-05-11 06:43:35 +03:00
}
}