2020-02-10 20:07:06 +01:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
2022-09-16 17:44:15 +02:00
|
|
|
|
using Android.App;
|
2020-02-10 20:07:06 +01:00
|
|
|
|
using Android.Content;
|
2022-09-16 17:44:15 +02:00
|
|
|
|
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);
|
2020-03-28 14:16:28 +01:00
|
|
|
|
if (metaCursor != null)
|
2019-05-11 05:43:35 +02:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2020-03-28 14:16:28 +01:00
|
|
|
|
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>();
|
2020-03-28 14:16:28 +01:00
|
|
|
|
if (restrictions.ContainsKey(BaseEnvironmentUrlRestrictionKey))
|
2020-02-10 20:07:06 +01:00
|
|
|
|
{
|
|
|
|
|
dict.Add(BaseEnvironmentUrlRestrictionKey, restrictions.GetString(BaseEnvironmentUrlRestrictionKey));
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 14:16:28 +01:00
|
|
|
|
if (dict.Count > 0)
|
2020-02-10 20:07:06 +01:00
|
|
|
|
{
|
|
|
|
|
await AppHelpers.SetPreconfiguredSettingsAsync(dict);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-09-16 17:44:15 +02:00
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|