aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain
diff options
context:
space:
mode:
authorDaniel Albert <albert_daniel@t-online.de>2014-07-12 12:42:48 +0200
committerDaniel Albert <albert_daniel@t-online.de>2014-07-12 12:42:48 +0200
commit2568ea4b2edaa1a13b15395d1951e7f941fba073 (patch)
treebd8ab572a093b0c1ac7afcc36046e9ed1c4fd589 /OpenKeychain
parentcf40517eaca2c852a0a0022b93c46e7a41766d80 (diff)
downloadopen-keychain-2568ea4b2edaa1a13b15395d1951e7f941fba073.tar.gz
open-keychain-2568ea4b2edaa1a13b15395d1951e7f941fba073.tar.bz2
open-keychain-2568ea4b2edaa1a13b15395d1951e7f941fba073.zip
Added Purging for Android < 4.1
Diffstat (limited to 'OpenKeychain')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java79
1 files changed, 51 insertions, 28 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java
index 9d998f18f..84ad441cb 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java
@@ -26,6 +26,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Binder;
+import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
@@ -353,39 +354,61 @@ public class PassphraseCacheService extends Service {
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if(mPassphraseCache.size() > 0) {
- NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
+ NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
- builder.setSmallIcon(R.drawable.ic_launcher)
- .setContentTitle("Open Keychain")
- .setContentText("Open Keychain has cached " + mPassphraseCache.size() + " keys.");
+ builder.setSmallIcon(R.drawable.ic_launcher)
+ .setContentTitle("Open Keychain")
+ .setContentText("Open Keychain has cached " + mPassphraseCache.size() + " keys.");
- NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
+ NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
- inboxStyle.setBigContentTitle("Cached Passphrases:");
+ inboxStyle.setBigContentTitle("Cached Passphrases:");
- // Moves events into the big view
- for (int i = 0; i < mPassphraseCache.size(); i++) {
- inboxStyle.addLine(mPassphraseCache.valueAt(i).getPrimaryUserID());
- }
+ // Moves events into the big view
+ for (int i = 0; i < mPassphraseCache.size(); i++) {
+ inboxStyle.addLine(mPassphraseCache.valueAt(i).getPrimaryUserID());
+ }
- // Moves the big view style object into the notification object.
- builder.setStyle(inboxStyle);
-
- // Add purging action
- Intent intent = new Intent(getApplicationContext(), PassphraseCacheService.class);
- intent.setAction(ACTION_PASSPHRASE_CACHE_PURGE);
- builder.addAction(
- R.drawable.abc_ic_clear_normal,
- "Purge Cache",
- PendingIntent.getService(
- getApplicationContext(),
- 0,
- intent,
- PendingIntent.FLAG_UPDATE_CURRENT
- )
- );
-
- notificationManager.notify(NOTIFICATION_ID, builder.build());
+ // Moves the big view style object into the notification object.
+ builder.setStyle(inboxStyle);
+
+ // Add purging action
+ Intent intent = new Intent(getApplicationContext(), PassphraseCacheService.class);
+ intent.setAction(ACTION_PASSPHRASE_CACHE_PURGE);
+ builder.addAction(
+ R.drawable.abc_ic_clear_normal,
+ "Purge Cache",
+ PendingIntent.getService(
+ getApplicationContext(),
+ 0,
+ intent,
+ PendingIntent.FLAG_UPDATE_CURRENT
+ )
+ );
+
+ notificationManager.notify(NOTIFICATION_ID, builder.build());
+ } else { // Fallback, since expandable notifications weren't available back then
+ NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
+
+ builder.setSmallIcon(R.drawable.ic_launcher)
+ .setContentTitle("Open Keychain has cached " + mPassphraseCache.size() + " keys.")
+ .setContentText("Click to purge the cache");
+
+ Intent intent = new Intent(getApplicationContext(), PassphraseCacheService.class);
+ intent.setAction(ACTION_PASSPHRASE_CACHE_PURGE);
+
+ builder.setContentIntent(
+ PendingIntent.getService(
+ getApplicationContext(),
+ 0,
+ intent,
+ PendingIntent.FLAG_UPDATE_CURRENT
+ )
+ );
+
+ notificationManager.notify(NOTIFICATION_ID, builder.build());
+ }
} else {
notificationManager.cancel(NOTIFICATION_ID);