|
|
@ -190,15 +190,29 @@ public class KeyCachingService extends Service {
|
|
|
|
|
|
|
|
|
|
|
|
private void foregroundServiceModern() {
|
|
|
|
private void foregroundServiceModern() {
|
|
|
|
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
|
|
|
|
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
|
|
|
|
RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.key_caching_notification);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Intent intent = new Intent(this, KeyCachingService.class);
|
|
|
|
builder.setContentTitle(getString(R.string.KeyCachingService_passphrase_cached));
|
|
|
|
intent.setAction(PASSPHRASE_EXPIRED_EVENT);
|
|
|
|
builder.setContentText(getString(R.string.KeyCachingService_textsecure_passphrase_cached));
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(), 0, intent, 0);
|
|
|
|
builder.setSmallIcon(R.drawable.icon_cached);
|
|
|
|
remoteViews.setOnClickPendingIntent(R.id.lock_cache_icon, pendingIntent);
|
|
|
|
builder.setWhen(0);
|
|
|
|
|
|
|
|
builder.setPriority(Notification.PRIORITY_LOW);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
builder.addAction(R.drawable.ic_menu_lock_holo_dark, getString(R.string.KeyCachingService_lock), buildLockIntent());
|
|
|
|
|
|
|
|
builder.setContentIntent(buildLaunchIntent());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stopForeground(true);
|
|
|
|
|
|
|
|
startForeground(SERVICE_RUNNING_ID, builder.build());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void foregroundServiceICS() {
|
|
|
|
|
|
|
|
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
|
|
|
|
|
|
|
|
RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.key_caching_notification);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
remoteViews.setOnClickPendingIntent(R.id.lock_cache_icon, buildLockIntent());
|
|
|
|
|
|
|
|
|
|
|
|
builder.setSmallIcon(R.drawable.icon_cached);
|
|
|
|
builder.setSmallIcon(R.drawable.icon_cached);
|
|
|
|
builder.setContent(remoteViews);
|
|
|
|
builder.setContent(remoteViews);
|
|
|
|
|
|
|
|
builder.setContentIntent(buildLaunchIntent());
|
|
|
|
|
|
|
|
|
|
|
|
stopForeground(true);
|
|
|
|
stopForeground(true);
|
|
|
|
startForeground(SERVICE_RUNNING_ID, builder.build());
|
|
|
|
startForeground(SERVICE_RUNNING_ID, builder.build());
|
|
|
@ -208,14 +222,11 @@ public class KeyCachingService extends Service {
|
|
|
|
Notification notification = new Notification(R.drawable.icon_cached,
|
|
|
|
Notification notification = new Notification(R.drawable.icon_cached,
|
|
|
|
getString(R.string.KeyCachingService_textsecure_passphrase_cached),
|
|
|
|
getString(R.string.KeyCachingService_textsecure_passphrase_cached),
|
|
|
|
System.currentTimeMillis());
|
|
|
|
System.currentTimeMillis());
|
|
|
|
Intent intent = new Intent(this, RoutingActivity.class);
|
|
|
|
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PendingIntent launchIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
|
|
|
|
|
|
|
|
notification.setLatestEventInfo(getApplicationContext(),
|
|
|
|
notification.setLatestEventInfo(getApplicationContext(),
|
|
|
|
getString(R.string.KeyCachingService_passphrase_cached),
|
|
|
|
getString(R.string.KeyCachingService_passphrase_cached),
|
|
|
|
getString(R.string.KeyCachingService_textsecure_passphrase_cached),
|
|
|
|
getString(R.string.KeyCachingService_textsecure_passphrase_cached),
|
|
|
|
launchIntent);
|
|
|
|
buildLaunchIntent());
|
|
|
|
|
|
|
|
notification.tickerText = null;
|
|
|
|
|
|
|
|
|
|
|
|
stopForeground(true);
|
|
|
|
stopForeground(true);
|
|
|
|
startForeground(SERVICE_RUNNING_ID, notification);
|
|
|
|
startForeground(SERVICE_RUNNING_ID, notification);
|
|
|
@ -227,8 +238,13 @@ public class KeyCachingService extends Service {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= 11) foregroundServiceModern();
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
|
|
|
else foregroundServiceLegacy();
|
|
|
|
foregroundServiceModern();
|
|
|
|
|
|
|
|
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
|
|
|
|
|
|
|
|
foregroundServiceICS();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
foregroundServiceLegacy();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void broadcastNewSecret() {
|
|
|
|
private void broadcastNewSecret() {
|
|
|
@ -246,6 +262,19 @@ public class KeyCachingService extends Service {
|
|
|
|
.getBoolean(ApplicationPreferencesActivity.DISABLE_PASSPHRASE_PREF, false);
|
|
|
|
.getBoolean(ApplicationPreferencesActivity.DISABLE_PASSPHRASE_PREF, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private PendingIntent buildLockIntent() {
|
|
|
|
|
|
|
|
Intent intent = new Intent(this, KeyCachingService.class);
|
|
|
|
|
|
|
|
intent.setAction(PASSPHRASE_EXPIRED_EVENT);
|
|
|
|
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(), 0, intent, 0);
|
|
|
|
|
|
|
|
return pendingIntent;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private PendingIntent buildLaunchIntent() {
|
|
|
|
|
|
|
|
Intent intent = new Intent(this, RoutingActivity.class);
|
|
|
|
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
|
|
|
|
|
|
PendingIntent launchIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
|
|
|
|
|
|
|
|
return launchIntent;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public IBinder onBind(Intent arg0) {
|
|
|
|
public IBinder onBind(Intent arg0) {
|
|
|
|