switch to TargetSDK 26, implement notification channels allowing customization of notification importance on Android 8, see #178

This commit is contained in:
Philipp Crocoll
2018-02-09 12:07:21 +01:00
parent 5fa2bc3bc8
commit 737c63e8b0
6 changed files with 62 additions and 9 deletions

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="46" android:versionName="0.9.3-release-3" package="keepass2android.keepass2android_debug" android:installLocation="auto">
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="23" />
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="26" />
<permission android:description="@string/permission_desc2" android:icon="@drawable/ic_notify_locked" android:label="KP2A entry search" android:name="keepass2android.keepass2android_debug.permission.KP2aInternalSearch" android:protectionLevel="signature" />
<permission android:description="@string/permission_desc3" android:icon="@drawable/ic_launcher_online" android:label="KP2A choose autofill dataset" android:name="keepass2android.keepass2android_debug.permission.Kp2aChooseAutofill" android:protectionLevel="signature" />
<application android:label="keepass2android" android:icon="@drawable/ic_launcher">

View File

@@ -4,7 +4,7 @@
android:versionName="1.04"
package="keepass2android.keepass2android"
android:installLocation="auto">
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="23" />
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="26" />
<permission android:description="@string/permission_desc2" android:icon="@drawable/ic_launcher_online" android:label="KP2A entry search" android:name="keepass2android.keepass2android.permission.KP2aInternalSearch" android:protectionLevel="signature" />
<permission android:description="@string/permission_desc3" android:icon="@drawable/ic_launcher_online" android:label="KP2A choose autofill dataset" android:name="keepass2android.keepass2android.permission.Kp2aChooseAutofill" android:protectionLevel="signature" />

View File

@@ -689,6 +689,15 @@
</string>
<string name="DbUnlockedChannel_name">Database unlocked</string>
<string name="DbUnlockedChannel_desc">Notification about the database being unlocked</string>
<string name="DbQuicklockedChannel_name">QuickUnlock</string>
<string name="DbQuicklockedChannel_desc">Notification about the database being locked with QuickUnlock</string>
<string name="EntryChannel_name">Entry notifications</string>
<string name="EntryChannel_desc">Notification to simplify access to the currently selected entry.</string>
<string name="ErrorReportTitle">Keepass2Android: An error occurred.</string>
<string name="ErrorReportText">An unexpected error occurred while running Keepass2Android. Please help us fix this by allowing the app to send error reports.</string>
<string name="ErrorReportPromise">Error reports will never contain any contents of your database or master password. You can disable them in the application settings.</string>

View File

@@ -21,6 +21,7 @@ using System.IO;
using System.Net.Security;
using Android.App;
using Android.Content;
using Android.Graphics;
using Android.Graphics.Drawables;
using Android.OS;
using Android.Runtime;
@@ -845,7 +846,11 @@ namespace keepass2android
#endif
public class App : Application {
public App (IntPtr javaReference, JniHandleOwnership transfer)
public const string NotificationChannelIdUnlocked = "channel_db_unlocked_3";
public const string NotificationChannelIdQuicklocked = "channel_db_quicklocked_3";
public const string NotificationChannelIdEntry = "channel_db_entry_3";
public App (IntPtr javaReference, JniHandleOwnership transfer)
: base(javaReference, transfer)
{
}
@@ -857,14 +862,53 @@ namespace keepass2android
Kp2aLog.Log("Creating application "+PackageName+". Version=" + PackageManager.GetPackageInfo(PackageName, 0).VersionCode);
CreateNotificationChannels();
Kp2a.OnCreate(this);
AndroidEnvironment.UnhandledExceptionRaiser += MyApp_UnhandledExceptionHandler;
}
private void CreateNotificationChannels()
{
NotificationManager mNotificationManager =
(NotificationManager)GetSystemService(Context.NotificationService);
public override void OnTerminate() {
{
string name = GetString(Resource.String.DbUnlockedChannel_name);
string desc = GetString(Resource.String.DbUnlockedChannel_desc);
NotificationChannel mChannel =
new NotificationChannel(NotificationChannelIdUnlocked, name, NotificationImportance.Low);
mChannel.Description = desc;
mChannel.EnableLights(false);
mChannel.EnableVibration(false);
mNotificationManager.CreateNotificationChannel(mChannel);
}
{
string name = GetString(Resource.String.DbQuicklockedChannel_name);
string desc = GetString(Resource.String.DbQuicklockedChannel_desc);
NotificationChannel mChannel =
new NotificationChannel(NotificationChannelIdQuicklocked, name, NotificationImportance.Min);
mChannel.Description = desc;
mChannel.EnableLights(false);
mChannel.EnableVibration(false);
mNotificationManager.CreateNotificationChannel(mChannel);
}
{
string name = GetString(Resource.String.EntryChannel_name);
string desc = GetString(Resource.String.EntryChannel_desc);
NotificationChannel mChannel =
new NotificationChannel(NotificationChannelIdEntry, name, NotificationImportance.None);
mChannel.Description = desc;
mChannel.EnableLights(false);
mChannel.EnableVibration(false);
mNotificationManager.CreateNotificationChannel(mChannel);
}
}
public override void OnTerminate() {
base.OnTerminate();
Kp2aLog.Log("Terminating application");
Kp2a.OnTerminate();

View File

@@ -198,7 +198,7 @@ namespace keepass2android
pending = GetPendingIntent(intentText, descResId);
}
var builder = new NotificationCompat.Builder(_ctx);
var builder = new NotificationCompat.Builder(_ctx, App.NotificationChannelIdEntry);
builder.SetSmallIcon(drawableResId)
.SetContentText(desc)
.SetContentTitle(entryName)

View File

@@ -139,7 +139,7 @@ namespace keepass2android
grayIconResouceId = Resource.Drawable.transparent;
}
NotificationCompat.Builder builder =
new NotificationCompat.Builder(this)
new NotificationCompat.Builder(this, App.NotificationChannelIdQuicklocked)
.SetSmallIcon(grayIconResouceId)
.SetLargeIcon(MakeLargeIcon(BitmapFactory.DecodeResource(Resources, AppNames.NotificationLockedIcon)))
.SetVisibility((int)Android.App.NotificationVisibility.Secret)
@@ -183,7 +183,7 @@ namespace keepass2android
private Notification GetUnlockedNotification()
{
NotificationCompat.Builder builder =
new NotificationCompat.Builder(this)
new NotificationCompat.Builder(this, App.NotificationChannelIdUnlocked)
.SetOngoing(true)
.SetSmallIcon(Resource.Drawable.ic_notify)
.SetLargeIcon(MakeLargeIcon(BitmapFactory.DecodeResource(Resources, AppNames.NotificationUnlockedIcon)))