Skip to content

Commit

Permalink
Fix Android 14 Smart-ID notification handling
Browse files Browse the repository at this point in the history
  • Loading branch information
martenrebane committed Aug 29, 2024
1 parent 63d8945 commit b350fe0
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,29 @@ public final class SmartIdStatusMessages {
.build();

public static String message(Context context, ProcessStatus status) {
Integer resId = MESSAGES.get(status);

Timber.log(Log.DEBUG, String.format("%s - %s", "Smart-ID", context.getString(resId != null ? resId : 1, context.getString(
R.string.signature_update_signature_add_method_smart_id))));

if (resId == null) {
Timber.log(Log.DEBUG, String.format("No message found for status: %s. Using default status: ProcessStatus.GENERAL_ERROR", status));
resId = MESSAGES.get(ProcessStatus.GENERAL_ERROR);

if (resId == null) {
Timber.log(Log.ERROR, "Default status ProcessStatus.GENERAL_ERROR not found. Displaying general error message");
resId = R.string.signature_update_mobile_id_error_general_client;
}
}

if (status.equals(ProcessStatus.TOO_MANY_REQUESTS)) {
Timber.log(Log.DEBUG, String.format("%s - %s", "Smart-ID", context.getString(MESSAGES.get(status), context.getString(
Timber.log(Log.DEBUG, String.format("%s - %s", "Smart-ID", context.getString(resId, context.getString(
R.string.signature_update_signature_add_method_smart_id))));
return context.getString(MESSAGES.get(status), context.getString(
R.string.signature_update_signature_add_method_smart_id));
return context.getString(resId, context.getString(
R.string.signature_update_signature_add_method_smart_id));
}
Timber.log(Log.DEBUG, String.format("%s - %s", "Smart-ID", context.getString(MESSAGES.get(status))));
return context.getString(MESSAGES.get(status));

Timber.log(Log.DEBUG, String.format("%s - %s", "Smart-ID", context.getString(resId)));
return context.getString(resId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,27 @@ public SignatureDetailView(Context context, Signature signature, SignedContainer
a.recycle();
}

if (isCertificateInExistence(signature.signingCertificate())) {
findViewById(R.id.signersCertificateButton).setOnClickListener(view -> navigator.execute(Transaction.push(CertificateDetailScreen.create(signature.signingCertificate()))));
}
if (signature != null) {
if (isCertificateInExistence(signature.signingCertificate())) {
findViewById(R.id.signersCertificateButton).setOnClickListener(view -> navigator.execute(Transaction.push(CertificateDetailScreen.create(signature.signingCertificate()))));
}

if (isCertificateInExistence(signature.tsCertificate())) {
findViewById(R.id.signatureDetailTimestampCertificateButton).setOnClickListener(view -> navigator.execute(Transaction.push(CertificateDetailScreen.create(signature.tsCertificate()))));
}
if (isCertificateInExistence(signature.tsCertificate())) {
findViewById(R.id.signatureDetailTimestampCertificateButton).setOnClickListener(view -> navigator.execute(Transaction.push(CertificateDetailScreen.create(signature.tsCertificate()))));
}

if (isCertificateInExistence(signature.ocspCertificate())) {
findViewById(R.id.signatureDetailOCSPCertificateButton).setOnClickListener(view -> navigator.execute(Transaction.push(CertificateDetailScreen.create(signature.ocspCertificate()))));
}
if (isCertificateInExistence(signature.ocspCertificate())) {
findViewById(R.id.signatureDetailOCSPCertificateButton).setOnClickListener(view -> navigator.execute(Transaction.push(CertificateDetailScreen.create(signature.ocspCertificate()))));
}

setExpandedState(false);
setWarningsData(signature);
setData(signature, signedContainer);
setExpandedState(false);
setWarningsData(signature);
setData(signature, signedContainer);

ContentView.addInvisibleElement(context, this);
ContentView.addInvisibleElement(context, this);
} else {
navigator.execute(Transaction.pop());
}
}

private String getContainerMimeType(SignedContainer signedContainer, boolean isSivaConfirmed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -378,11 +379,19 @@ final class Processor implements ObservableTransformer<Action, Result> {
.toObservable()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.map(signedContainerFile -> {
Transaction transaction;
transaction = Transaction.push(SignatureDetailScreen
.create(action.signature(), signedContainerFile, action.isSivaConfirmed()));
navigator.execute(transaction);
.map(signedContainer -> {
Signature signature = action.signature();
if (signature != null) {
Optional<Signature> signedSignature = signedContainer.signatures().stream()
.filter(obj -> obj.equals(signature))
.findFirst();
if (signedSignature.isPresent()) {
Transaction transaction;
transaction = Transaction.push(SignatureDetailScreen
.create(signedSignature.get(), signedContainer, action.isSivaConfirmed()));
navigator.execute(transaction);
}
}
return Result.SignatureViewResult.idle();
})
.onErrorReturn(ignored -> Result.SignatureViewResult.idle())
Expand Down
21 changes: 11 additions & 10 deletions common-lib/src/main/java/ee/ria/DigiDoc/common/UserAgentUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public final class UserAgentUtil {
private UserAgentUtil() {}

public static String getUserAgent(Context context) {

ArrayList<String> deviceProductNames = new ArrayList<>();
StringBuilder initializingMessage = new StringBuilder();

Expand All @@ -48,19 +47,21 @@ public static String getUserAgent(Context context) {
}

private static List<UsbDevice> getConnectedUsbs(Context context) {
UsbManager usbManager = (UsbManager)context.getSystemService(USB_SERVICE);
UsbManager usbManager = (UsbManager) context.getSystemService(USB_SERVICE);
HashMap<String, UsbDevice> devices = usbManager.getDeviceList();

Map<String, UsbDevice> smartDevices = devices.entrySet()
.stream()
.filter(usbDevice ->
deviceNameFilters
.stream()
.anyMatch(usbDevice.getValue().getProductName()::contains) ||
deviceNameFilters
.stream()
.anyMatch(usbDevice.getValue().getDeviceName()::contains)
)
.filter(usbDeviceEntry -> {
UsbDevice usbDevice = usbDeviceEntry.getValue();
String productName = usbDevice.getProductName();
String deviceName = usbDevice.getDeviceName();

boolean productNameExists = productName != null && deviceNameFilters.stream().anyMatch(productName::contains);
boolean deviceNameExists = deviceNameFilters.stream().anyMatch(deviceName::contains);

return productNameExists || deviceNameExists;
})
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

return new ArrayList<>(smartDevices.values());
Expand Down
12 changes: 10 additions & 2 deletions smart-id-lib/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<!-- Needed for Android SDK 28+ -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
Expand All @@ -7,7 +8,14 @@

<service
android:name=".service.SmartSignService"
android:exported="false" />
android:exported="false"
android:foregroundServiceType="shortService" />

<!-- Needed for Android SDK 34+ -->
<service
android:name="androidx.work.impl.foreground.SystemForegroundService"
android:foregroundServiceType="shortService"
tools:node="merge" />

</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ServiceInfo;
import android.os.Build;
import android.util.Log;

import androidx.annotation.NonNull;
Expand Down Expand Up @@ -158,7 +160,11 @@ public void showEmptyNotification() {
Notification notification = NotificationUtil.createNotification(getApplicationContext(), NOTIFICATION_CHANNEL,
R.mipmap.ic_launcher, null, null, NotificationCompat.PRIORITY_MIN, true);

setForegroundAsync(new ForegroundInfo(NOTIFICATION_PERMISSION_CODE, notification));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
setForegroundAsync(new ForegroundInfo(NOTIFICATION_PERMISSION_CODE, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_SHORT_SERVICE));
} else {
setForegroundAsync(new ForegroundInfo(NOTIFICATION_PERMISSION_CODE, notification));
}
}

@NonNull
Expand Down

0 comments on commit b350fe0

Please sign in to comment.