Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into MOPPAND-999
Browse files Browse the repository at this point in the history
  • Loading branch information
martenrebane committed Sep 25, 2023
2 parents 600252d + 015b0b2 commit d9303bc
Show file tree
Hide file tree
Showing 165 changed files with 3,664 additions and 1,221 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
uses: actions/setup-java@v3
with:
distribution: zulu
java-version: 11
java-version: 17
- name: Download Libdigidocpp Android (androidarm) artifact
uses: dawidd6/action-download-artifact@v2
with:
Expand Down Expand Up @@ -62,11 +62,11 @@ jobs:
run: |
pwd
./gradlew common-lib:updateLibdigidocpp --dir=libdigidocpp-files/
- name: Setup Gradle and Build
- name: Setup Gradle, Test and Build
uses: gradle/gradle-build-action@v2
with:
gradle-version: wrapper
arguments: clean --no-daemon fetchAndPackageDefaultConfiguration -PappVersionName=${{ env.APP_VERSION_NAME }}.${{ env.BUILD_NUMBER }} assembleRelease --info
arguments: clean test --no-daemon fetchAndPackageDefaultConfiguration -PappVersionName=${{ env.APP_VERSION_NAME }}.${{ env.BUILD_NUMBER }} assembleRelease --info
- name: Sign app APK
uses: r0adkll/sign-android-release@v1
id: signed_apk
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ on: [push, pull_request]
jobs:
analyze:
name: CodeQL Analyze
if: contains(github.repository, 'open-eid/MOPP-Android') && contains(github.ref, 'master')
runs-on: ubuntu-latest
permissions:
actions: read
Expand All @@ -27,7 +26,7 @@ jobs:
uses: actions/setup-java@v3
with:
distribution: zulu
java-version: 11
java-version: 17

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
Expand Down
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ android {
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}

lint {
Expand All @@ -82,6 +82,7 @@ dependencies {
implementation "androidx.recyclerview:recyclerview:${androidxRecyclerviewVersion}"
implementation "androidx.cardview:cardview:${androidxCardviewVersion}"
implementation "androidx.lifecycle:lifecycle-viewmodel:${androidxLifecycleVersion}"
implementation "androidx.work:work-runtime:${androidxWorkRuntime}"

implementation "com.takisoft.preferencex:preferencex:${preferencexVersion}"

Expand Down
6 changes: 3 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<application
android:name=".android.Application"
android:allowBackup="true"
android:name=".android.ApplicationApp"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:usesCleartextTraffic="true"
android:label="@string/application_name"
Expand All @@ -26,7 +26,7 @@
android:name=".android.Activity"
android:exported="true"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden|locale"
android:screenOrientation="fullSensor">
android:screenOrientation="user">
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
Expand Down
34 changes: 18 additions & 16 deletions app/src/main/java/ee/ria/DigiDoc/android/Activity.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package ee.ria.DigiDoc.android;

import static ee.ria.DigiDoc.android.Constants.DIR_EXTERNALLY_OPENED_FILES;
import static ee.ria.DigiDoc.android.utils.IntentUtils.setIntentData;

import android.app.Dialog;
import android.content.ActivityNotFoundException;
import android.content.ClipData;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
Expand All @@ -20,8 +20,8 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.FileProvider;
import androidx.preference.PreferenceManager;
import androidx.work.WorkManager;

import com.google.android.gms.common.util.CollectionUtils;
import com.google.android.gms.tasks.Task;
Expand All @@ -32,6 +32,7 @@
import java.io.File;
import java.lang.ref.WeakReference;
import java.nio.file.Path;
import java.util.Optional;
import java.util.concurrent.Callable;

import javax.inject.Inject;
Expand Down Expand Up @@ -80,6 +81,8 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {

handleCrashOnPreviousExecution();

WorkManager.getInstance(this).cancelAllWork();

Intent intent = sanitizeIntent(getIntent());

if ((Intent.ACTION_SEND.equals(intent.getAction()) || Intent.ACTION_SEND_MULTIPLE.equals(intent.getAction()) || Intent.ACTION_VIEW.equals(intent.getAction())) && intent.getType() != null) {
Expand Down Expand Up @@ -189,8 +192,10 @@ private Intent sanitizeIntent(Intent intent) {
Uri normalizedUri = FileUtil.normalizeUri(Uri.parse(intent.getDataString()));
intent.setDataAndNormalize(normalizedUri);
}
if (intent.getExtras() != null && !(intent.getExtras().containsKey(Intent.EXTRA_REFERRER) &&
intent.getExtras().get(Intent.EXTRA_REFERRER).equals(R.string.application_name))) {
if (intent.getExtras() != null) {
if (intent.getExtras().containsKey(Intent.EXTRA_REFERRER)) {
intent.getExtras().getString(Intent.EXTRA_REFERRER);
}
intent.replaceExtras(new Bundle());
}
return intent;
Expand All @@ -215,7 +220,7 @@ private void initializeApplicationFileTypesAssociation() {

@Override
protected void attachBaseContext(Context newBase) {
Application.ApplicationComponent component = Application.component(newBase);
ApplicationApp.ApplicationComponent component = ApplicationApp.component(newBase);
navigator = component.navigator();
rootScreenFactory = component.rootScreenFactory();
settingsDataStore = component.settingsDataStore();
Expand All @@ -232,6 +237,14 @@ public void onBackPressed() {
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// If user selects a file from provider menu (Open from -> RIA DigiDoc), it starts a new activity
// Replace the main activity after the new file has been selected
if (Optional.ofNullable(data)
.map(Intent::getAction)
.filter(action -> action.equals(Intent.ACTION_GET_CONTENT))
.isPresent()) {
navigator.onCreate(this, findViewById(android.R.id.content), null);
}
navigator.onActivityResult(requestCode, resultCode, data);
}

Expand Down Expand Up @@ -345,17 +358,6 @@ private static String getFileName(File file) {
}
}
}

private static Intent setIntentData(Intent intent, Path filePath, android.app.Activity activity) {
intent.setData(Uri.parse(filePath.toUri().toString()));
intent.setClipData(ClipData.newRawUri(filePath.getFileName().toString(), FileProvider.getUriForFile(
activity,
activity.getString(R.string.file_provider_authority),
filePath.toFile())));
return intent;
}


}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
import android.content.Intent;
import android.content.SharedPreferences;
import android.hardware.usb.UsbManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.ResultReceiver;
import android.os.StrictMode;
import android.util.Log;
Expand Down Expand Up @@ -72,6 +74,7 @@
import ee.ria.DigiDoc.android.main.diagnostics.source.FileSystemDiagnosticsDataSource;
import ee.ria.DigiDoc.android.main.home.HomeViewModel;
import ee.ria.DigiDoc.android.main.settings.SettingsDataStore;
import ee.ria.DigiDoc.android.main.settings.create.TSACertificateAddViewModel;
import ee.ria.DigiDoc.android.signature.create.SignatureCreateViewModel;
import ee.ria.DigiDoc.android.signature.data.SignatureContainerDataSource;
import ee.ria.DigiDoc.android.signature.data.source.FileSystemSignatureContainerDataSource;
Expand All @@ -98,7 +101,7 @@
import io.reactivex.rxjava3.plugins.RxJavaPlugins;
import timber.log.Timber;

public class Application extends android.app.Application {
public class ApplicationApp extends android.app.Application {

private static ConfigurationProvider configurationProvider;

Expand Down Expand Up @@ -223,11 +226,11 @@ private void setupConfiguration() {

Bundle bundle = new Bundle();
bundle.putParcelable(ConfigurationConstants.CONFIGURATION_PROVIDER, configurationProvider);
ConfigurationProviderReceiver confProviderReceiver = new ConfigurationProviderReceiver(new Handler());
ConfigurationProviderReceiver confProviderReceiver = new ConfigurationProviderReceiver(new Handler(Looper.getMainLooper()));
confProviderReceiver.send(ConfigurationManagerService.NEW_CONFIGURATION_LOADED, bundle);

// Load configuration again in asynchronous manner, from central if needed or cache if present.
initAsyncConfigurationLoad(new ConfigurationProviderReceiver(new Handler()), false);
initAsyncConfigurationLoad(new ConfigurationProviderReceiver(new Handler(Looper.getMainLooper())), false);
}

private boolean isDefaultConfNewerThanCachedConf(ConfigurationProperties confProperties, CachedConfigurationHandler cachedConfHandler) {
Expand All @@ -238,7 +241,7 @@ private boolean isDefaultConfNewerThanCachedConf(ConfigurationProperties confPro

// Following configuration updating should be asynchronous
public void updateConfiguration(DiagnosticsView diagnosticsView) {
ConfigurationProviderReceiver confProviderReceiver = new ConfigurationProviderReceiver(new Handler());
ConfigurationProviderReceiver confProviderReceiver = new ConfigurationProviderReceiver(new Handler(Looper.getMainLooper()));
confProviderReceiver.setDiagnosticView(diagnosticsView);
initAsyncConfigurationLoad(confProviderReceiver, true);
}
Expand Down Expand Up @@ -301,7 +304,11 @@ void setDiagnosticView(DiagnosticsView diagnosticView) {

@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
configurationProvider = resultData.getParcelable(ConfigurationConstants.CONFIGURATION_PROVIDER);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
configurationProvider = resultData.getParcelable(ConfigurationConstants.CONFIGURATION_PROVIDER, ConfigurationProvider.class);
} else {
configurationProvider = resultData.getParcelable(ConfigurationConstants.CONFIGURATION_PROVIDER);
}
if (resultCode == ConfigurationManagerService.NEW_CONFIGURATION_LOADED) {
setupSignLib();
}
Expand All @@ -316,13 +323,13 @@ protected void onReceiveResult(int resultCode, Bundle resultData) {
private ApplicationComponent component;

private void setupDagger() {
component = DaggerApplication_ApplicationComponent.builder()
component = DaggerApplicationApp_ApplicationComponent.builder()
.application(this)
.build();
}

public static ApplicationComponent component(Context context) {
return ((Application) context.getApplicationContext()).component;
return ((ApplicationApp) context.getApplicationContext()).component;
}

@Singleton
Expand Down Expand Up @@ -417,6 +424,10 @@ static ViewModelProvider.Factory viewModelFactory(
@SuppressWarnings("unused")
@Binds @IntoMap @ClassKey(EIDHomeViewModel.class)
abstract ViewModel eidHomeViewModel(EIDHomeViewModel viewModel);

@SuppressWarnings("unused")
@Binds @IntoMap @ClassKey(TSACertificateAddViewModel.class)
abstract ViewModel tsaCertificateAddViewModel(TSACertificateAddViewModel viewModel);
}

@Module
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/ee/ria/DigiDoc/android/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public final class Constants {
public static final int RC_CRYPTO_CREATE_INITIAL = 2;
public static final int RC_CRYPTO_CREATE_DATA_FILE_ADD = 3;
public static final int SAVE_FILE = 4;
public static final int RC_TSA_CERT_ADD = 5;

/**
* Sub-directory name in {@link android.content.Context#getFilesDir() files dir} for signature
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.core.view.AccessibilityDelegateCompat;
Expand All @@ -19,6 +20,8 @@

import com.google.android.material.textfield.TextInputLayout;

import net.cachapa.expandablelayout.ExpandableLayout;

import ee.ria.DigiDoc.android.Activity;
import ee.ria.DigiDoc.common.TextUtil;

Expand All @@ -42,7 +45,7 @@ public static void interrupt(Context context) {
public static void sendAccessibilityEvent(Context context, int eventType, CharSequence message) {
AccessibilityManager accessibilityManager = (AccessibilityManager) context.getSystemService(ACCESSIBILITY_SERVICE);
if (accessibilityManager.isEnabled()) {
AccessibilityEvent event = AccessibilityEvent.obtain();
AccessibilityEvent event = getAccessibilityEvent();
event.setEventType(eventType);
event.getText().add(message);
accessibilityManager.sendAccessibilityEvent(event);
Expand All @@ -52,7 +55,7 @@ public static void sendAccessibilityEvent(Context context, int eventType, CharSe
public static void sendAccessibilityEvent(Context context, int eventType, CharSequence... messages) {
AccessibilityManager accessibilityManager = (AccessibilityManager) context.getSystemService(ACCESSIBILITY_SERVICE);
if (accessibilityManager.isEnabled()) {
AccessibilityEvent event = AccessibilityEvent.obtain();
AccessibilityEvent event = getAccessibilityEvent();
event.setEventType(eventType);
event.getText().add(combineMessages(messages));
accessibilityManager.sendAccessibilityEvent(event);
Expand All @@ -62,7 +65,7 @@ public static void sendAccessibilityEvent(Context context, int eventType, CharSe
public static void sendDelayedAccessibilityEvent(Context context, int eventType, CharSequence message) {
AccessibilityManager accessibilityManager = (AccessibilityManager) context.getSystemService(ACCESSIBILITY_SERVICE);
if (accessibilityManager.isEnabled()) {
AccessibilityEvent event = AccessibilityEvent.obtain();
AccessibilityEvent event = getAccessibilityEvent();
event.setEventType(eventType);
event.getText().add(message);
accessibilityManager.sendAccessibilityEvent(event);
Expand Down Expand Up @@ -100,7 +103,7 @@ public static void disableContentDescription(View view) {
public static void disableDoubleTapToActivateFeedback(View view) {
ViewCompat.setAccessibilityDelegate(view, new AccessibilityDelegateCompat() {
@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
public void onInitializeAccessibilityNodeInfo(@NonNull View host, @NonNull AccessibilityNodeInfoCompat info) {
super.onInitializeAccessibilityNodeInfo(host, info);
info.addAction(AccessibilityNodeInfoCompat.ACTION_FOCUS);
info.removeAction(AccessibilityNodeInfoCompat.AccessibilityActionCompat.ACTION_CLICK);
Expand All @@ -111,7 +114,7 @@ public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCo
public static void setSingleCharactersContentDescription(TextView textView) {
ViewCompat.setAccessibilityDelegate(textView, new AccessibilityDelegateCompat() {
@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
public void onInitializeAccessibilityNodeInfo(@NonNull View host, @NonNull AccessibilityNodeInfoCompat info) {
super.onInitializeAccessibilityNodeInfo(host, info);
StringBuilder textViewAccessibility = new StringBuilder();
String[] personalCodeTextSplit = textView.getText().toString().split(",");
Expand Down Expand Up @@ -142,11 +145,42 @@ public static boolean isLargeFontEnabled(Resources resources) {
return configuration.fontScale > 1;
}

public static boolean isSmallFontEnabled(Resources resources) {
Configuration configuration = resources.getConfiguration();
return configuration.fontScale < 1;
}

public static void setCustomClickAccessibilityFeedBack(TextView titleView, ExpandableLayout containerView) {
ViewCompat.setAccessibilityDelegate(titleView, new AccessibilityDelegateCompat() {
@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
super.onInitializeAccessibilityNodeInfo(host, info);
String message;
if (containerView.isExpanded()) {
message = "deactivate";
} else {
message = "activate";
}
AccessibilityNodeInfoCompat.AccessibilityActionCompat customClick = new AccessibilityNodeInfoCompat.AccessibilityActionCompat(
AccessibilityNodeInfoCompat.ACTION_CLICK, message);
info.addAction(customClick);
}
});
}

private static String combineMessages(CharSequence... messages) {
StringBuilder combinedMessage = new StringBuilder();
for (CharSequence message : messages) {
combinedMessage.append(message).append(", ");
}
return combinedMessage.toString();
}

private static AccessibilityEvent getAccessibilityEvent() {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) {
return new AccessibilityEvent();
} else {
return AccessibilityEvent.obtain();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import java.util.List;

import ee.ria.DigiDoc.R;
import ee.ria.DigiDoc.android.Application;
import ee.ria.DigiDoc.android.ApplicationApp;
import ee.ria.DigiDoc.android.accessibility.AccessibilityUtils;
import ee.ria.DigiDoc.android.utils.Formatter;
import ee.ria.DigiDoc.android.utils.display.DisplayUtil;
Expand Down Expand Up @@ -388,7 +388,7 @@ static final class RecipientViewHolder extends CreateViewHolder<RecipientItem> {

RecipientViewHolder(View itemView) {
super(itemView);
formatter = Application.component(itemView.getContext()).formatter();
formatter = ApplicationApp.component(itemView.getContext()).formatter();
AccessibilityUtils.disableDoubleTapToActivateFeedback(itemView.findViewById(R.id.cryptoRecipient));
nameView = itemView.findViewById(R.id.cryptoRecipientName);
infoView = itemView.findViewById(R.id.cryptoRecipientInfo);
Expand Down
Loading

0 comments on commit d9303bc

Please sign in to comment.