Skip to content

Commit

Permalink
feat: support android 13 (#1193)
Browse files Browse the repository at this point in the history
* chore: compile for and target Android 13 (SDK 33)

* feat: show permissions dialog on Android 13

* feat: ask for notification permission each time app is upgraded if permission has not been granted.

* fix: reset the show notifications flag when there is an app upgrade

* chore: update roboelectric to 4.9.2 to support Android 13
  • Loading branch information
HashEngineering authored Sep 1, 2023
1 parent f3c7b97 commit 32d50f3
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 28 deletions.
4 changes: 2 additions & 2 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ apply plugin: 'kotlin-parcelize'
apply plugin: 'dagger.hilt.android.plugin'

android {
compileSdkVersion 31

defaultConfig {
compileSdk 33
minSdkVersion 23
targetSdkVersion 31
targetSdkVersion 33
vectorDrawables.useSupportLibrary = true

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
7 changes: 3 additions & 4 deletions features/exploredash/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ plugins {
}

android {
compileSdkVersion 31

defaultConfig {
compileSdk 33
minSdkVersion 23
targetSdkVersion 31
targetSdkVersion 33
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
javaCompileOptions {
Expand Down Expand Up @@ -118,7 +117,7 @@ dependencies {
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesVersion"
testImplementation "org.mockito.kotlin:mockito-kotlin:$mockitoVersion"
testImplementation "androidx.arch.core:core-testing:$coreTestingVersion"
testImplementation "org.robolectric:robolectric:4.8.1"
testImplementation "org.robolectric:robolectric:4.9.2"
testImplementation "androidx.room:room-testing:$roomVersion"
kapt "androidx.room:room-compiler:$roomVersion"

Expand Down
5 changes: 2 additions & 3 deletions integrations/coinbase/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ plugins {
}

android {
compileSdkVersion 31
buildToolsVersion "30.0.3"

defaultConfig {
compileSdk 33
minSdkVersion 23
targetSdkVersion 31
targetSdkVersion 33
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
Expand Down
5 changes: 3 additions & 2 deletions integrations/crowdnode/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ plugins {
}

android {
compileSdkVersion 31
compileSdkVersion 33

defaultConfig {
compileSdk 33
minSdkVersion 23
targetSdkVersion 31
targetSdkVersion 33
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}
Expand Down
4 changes: 2 additions & 2 deletions integrations/uphold/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ plugins {
}

android {
compileSdkVersion 31

defaultConfig {
compileSdk 33
minSdkVersion 23
targetSdkVersion 31
targetSdkVersion 33

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
6 changes: 2 additions & 4 deletions sample-integration-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ dependencies {
}

android {
compileSdkVersion 31


sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
Expand All @@ -40,8 +37,9 @@ android {
}

defaultConfig {
compileSdk 33
minSdkVersion 23
targetSdkVersion 31
targetSdkVersion 33
multiDexEnabled true
}
compileOptions {
Expand Down
2 changes: 1 addition & 1 deletion wallet/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<uses-permission android:name="android.permission.CAMERA" /> <!-- group: CAMERA -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<uses-feature
android:name="android.hardware.touchscreen"
Expand Down
4 changes: 2 additions & 2 deletions wallet/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@ if (file("../local.properties").exists()) {
}

android {
compileSdkVersion 31
android.ndkVersion '21.3.6528147'

defaultConfig {
compileSdk 33
minSdkVersion 23
targetSdkVersion 31
targetSdkVersion 33
versionCode project.hasProperty('versionCode') ? project.property('versionCode') as int : 90050
versionName project.hasProperty('versionName') ? project.property('versionName') : "9.0.5"
multiDexEnabled true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public class BootstrapReceiver extends BroadcastReceiver {
protected WalletDataProvider walletDataProvider;
@Inject
protected WalletApplication application;
@Inject
protected Configuration configuration;

@Override
public void onReceive(final Context context, final Intent intent) {
Expand Down Expand Up @@ -101,6 +103,10 @@ private void onAsyncReceive(final Context context, final Intent intent) {
// if the app hasn't been used for a while and contains coins, maybe show reminder
maybeShowInactivityNotification();
application.myPackageReplaced = true;

// reset the notification explainer flag
if (packageReplaced)
configuration.setShowNotificationsExplainer(true);
} else if (ACTION_DISMISS.equals(action)) {
dismissNotification(context);
} else if (ACTION_DISMISS_FOREVER.equals(action)) {
Expand Down
38 changes: 30 additions & 8 deletions wallet/src/de/schildbach/wallet/ui/main/WalletActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@

package de.schildbach.wallet.ui.main;

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.nfc.NdefMessage;
import android.nfc.NfcAdapter;
import android.os.Build;
Expand All @@ -28,7 +30,10 @@
import android.os.LocaleList;
import android.telephony.TelephonyManager;

import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.ViewModelProvider;

import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -368,16 +373,33 @@ public void onLockScreenDeactivated() {
}
}

private final ActivityResultLauncher<String> requestPermissionLauncher =
registerForActivityResult(new ActivityResultContracts.RequestPermission(), granted -> {
// do nothing
});

/**
* Android 13 - Show system dialog to get notification permission from user, if not granted
* ask again with each app upgrade if not granted. This logic is handled by
* {@link #onLockScreenDeactivated} and {@link #onStart}.
* Android 12 and below - show a explainer dialog once only.
*/
private void explainPushNotifications() {
AdaptiveDialog dialog = AdaptiveDialog.create(
R.drawable.ic_info_blue,
getString(R.string.notification_explainer_title),
getString(R.string.notification_explainer_message),
"",
getString(R.string.button_okay)
);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU &&
ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
requestPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS);
} else if (configuration.getShowNotificationsExplainer()) {
AdaptiveDialog dialog = AdaptiveDialog.create(
R.drawable.ic_info_blue,
getString(R.string.notification_explainer_title),
getString(R.string.notification_explainer_message),
"",
getString(R.string.button_okay)
);

dialog.show(this, result -> Unit.INSTANCE);
dialog.show(this, result -> Unit.INSTANCE);
}
// only show either the permissions dialog (Android >= 13) or the explainer (Android <= 12) once
configuration.setShowNotificationsExplainer(false);
}
}

0 comments on commit 32d50f3

Please sign in to comment.