Bitwarden-app-android-iphon.../src/Android/Utilities/AndroidHelpers.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

71 lines
2.3 KiB
C#
Raw Normal View History

2020-02-10 20:07:06 +01:00
using System.Collections.Generic;
using System.Threading.Tasks;
using Android.App;
2020-02-10 20:07:06 +01:00
using Android.Content;
using Android.OS;
2019-05-11 05:43:35 +02:00
using Android.Provider;
2020-02-10 20:07:06 +01:00
using Bit.App.Utilities;
2019-05-11 05:43:35 +02:00
namespace Bit.Droid.Utilities
{
public static class AndroidHelpers
{
2020-02-10 20:07:06 +01:00
private static string BaseEnvironmentUrlRestrictionKey = "baseEnvironmentUrl";
2019-05-11 05:43:35 +02: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 05:43:35 +02:00
{
try
{
if (metaCursor.MoveToFirst())
2019-05-11 05:43:35 +02:00
{
name = metaCursor.GetString(0);
}
}
finally
{
metaCursor.Close();
}
}
return name;
}
2020-02-10 20:07:06 +01: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 20:07:06 +01:00
{
dict.Add(BaseEnvironmentUrlRestrictionKey, restrictions.GetString(BaseEnvironmentUrlRestrictionKey));
}
if (dict.Count > 0)
2020-02-10 20:07:06 +01:00
{
await AppHelpers.SetPreconfiguredSettingsAsync(dict);
}
}
public static PendingIntentFlags AddPendingIntentMutabilityFlag(PendingIntentFlags pendingIntentFlags, bool isMutable)
{
//Mutable flag was added on API level 31
if (isMutable && Build.VERSION.SdkInt >= BuildVersionCodes.S)
{
return pendingIntentFlags | PendingIntentFlags.Mutable;
}
//Immutable flag was added on API level 23
if (!isMutable && Build.VERSION.SdkInt >= BuildVersionCodes.M)
{
return pendingIntentFlags | PendingIntentFlags.Immutable;
}
return pendingIntentFlags;
}
2019-05-11 05:43:35 +02:00
}
}