Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for api 30 and 31 #85

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
19 changes: 10 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ buildscript {

repositories {
google()
jcenter()
mavenCentral()
maven{ url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'gradle.plugin.org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.10.2'
classpath "io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.11.0"
classpath 'com.android.tools.build:gradle:4.2.2'
classpath 'gradle.plugin.org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.12.0'
classpath "io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.30.0"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -22,7 +22,7 @@ apply plugin: 'io.codearte.nexus-staging'
allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven {
url "https://s3.amazonaws.com/repo.commonsware.com"
}
Expand All @@ -41,10 +41,11 @@ ext {
group = GROUP
version = VERSION_NAME

androidBuildToolsVersion = "28.0.3"
androidMinSdkVersion = 18
androidCompileSdkVersion = 28
androidTargetSdkVersion = 28
ext.androidToolsBuildGradle = '4.2.2'
ext.androidBuildToolsVersion = '30.0.3'
ext.androidMinSdkVersion = 19
ext.androidCompileSdkVersion = 31
ext.androidTargetSdkVersion = 31
}

ext {
Expand Down
7 changes: 5 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ org.gradle.jvmargs=-Xmx1536m
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
android.enableUnitTestBinaryResources=true
VERSION_NAME=0.3.7-SNAPSHOT
android.enableUnitTestBinaryResources=false
VERSION_NAME=0.4.0-SNAPSHOT
VERSION_CODE=1
GROUP=org.smartregister
POM_SETTING_DESCRIPTION=Android Peer-to-Peer Sync
Expand All @@ -26,5 +26,8 @@ POM_SETTING_LICENCE_DIST=repo
POM_SETTING_DEVELOPER_ID=opensrp
POM_SETTING_DEVELOPER_NAME=OpenSRP Onadev
POM_SETTING_NAME=Android Peer-to-Peer Sync
android.useAndroidX=true
android.enableJetifier=true
POM_SETTING_ARTIFACT_ID=android-p2p-sync
POM_SETTING_PACKAGING=aar
android.jetifier.blacklist=bcprov
6 changes: 3 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Mar 07 16:20:14 EAT 2019
#Thu Feb 02 12:10:28 EAT 2023
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
zipStoreBase=GRADLE_USER_HOME
46 changes: 29 additions & 17 deletions p2p-sync/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ jacoco {
}

android {
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}

compileSdkVersion androidCompileSdkVersion
buildToolsVersion androidBuildToolsVersion

Expand All @@ -16,8 +21,6 @@ android {
defaultConfig {
minSdkVersion androidMinSdkVersion
targetSdkVersion androidTargetSdkVersion
versionCode 1
versionName version

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand All @@ -42,37 +45,45 @@ android {
}
}

testOptions.unitTests.includeAndroidResources = true
lintOptions.abortOnError = false
testOptions {
unitTests {
includeAndroidResources = true
}
}
lintOptions {
lintConfig file("lint.xml")
abortOnError false
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.android.gms:play-services-nearby:16.0.0'
implementation ('com.google.android.gms:play-services-location:16.0.0') {
implementation('com.google.android.gms:play-services-location:16.0.0') {
exclude group: 'com.android.support', module: 'support-v4'
}

implementation 'com.google.android.gms:play-services-vision:17.0.2'
implementation 'com.google.android.gms:play-services-vision:20.1.3'

implementation 'com.jakewharton.timber:timber:4.7.1'
implementation 'com.jakewharton.timber:timber:5.0.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'

testImplementation 'junit:junit:4.12'
testImplementation 'junit:junit:4.13.2'
testImplementation project(path: ':p2p-sync')
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
testImplementation 'org.mockito:mockito-inline:2.25.0'
testImplementation "org.robolectric:robolectric:4.2"
testImplementation "org.robolectric:robolectric:4.3.1"

// ZXING DEPENDENCIES
implementation('com.journeyapps:zxing-android-embedded:3.6.0') {
implementation('com.journeyapps:zxing-android-embedded:4.3.0') {
exclude group: 'com.android.support', module: 'support-v4'
}
implementation 'com.google.zxing:core:3.3.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.google.zxing:core:3.5.1'
implementation 'com.google.code.gson:gson:2.10.1'

// Room
implementation "android.arch.persistence.room:runtime:$room_version"
Expand All @@ -81,7 +92,7 @@ dependencies {
testImplementation "android.arch.persistence.room:testing:$room_version"

// Encrypted SQLite help
implementation "com.commonsware.cwac:saferoom:1.0.2"
implementation 'com.commonsware.cwac:saferoom.x:1.1.2'

}

Expand All @@ -99,15 +110,16 @@ task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'crea
def debugTree = fileTree(dir: "$project.buildDir/intermediates/classes/debug", excludes: fileFilter)
def mainSrc = "$project.projectDir/src/main/java"

sourceDirectories = files([mainSrc])
classDirectories = files([debugTree])
executionData = fileTree(dir: project.buildDir, includes: [
getSourceDirectories().setFrom([mainSrc])
getClassDirectories().setFrom([debugTree])
getExecutionData().setFrom(dir: project.buildDir, includes: [
'jacoco/testDebugUnitTest.exec', 'outputs/code-coverage/connected/*coverage.ec'
])
}

tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
jacoco.excludes = ['jdk.internal.*']
}

coveralls {
Expand Down
4 changes: 3 additions & 1 deletion p2p-sync/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

<!-- Used to get the Wifi Mac address -->
Expand All @@ -19,7 +20,8 @@
<activity
android:label="@string/peer_to_peer_activity_title"
android:windowSoftInputMode="stateHidden|adjustResize"
android:name=".activity.P2pModeSelectActivity"/>
android:exported="true"
android:name="org.smartregister.p2p.activity.P2pModeSelectActivity"/>

<meta-data
android:name="com.google.android.gms.vision.Dependencies"
Expand Down
21 changes: 18 additions & 3 deletions p2p-sync/src/main/java/org/smartregister/p2p/P2PLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import android.content.Context;
import android.os.AsyncTask;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import org.smartregister.p2p.authorizer.P2PAuthorizationService;
import org.smartregister.p2p.callback.SyncFinishedCallback;
Expand Down Expand Up @@ -52,7 +53,7 @@ private P2PLibrary(@NonNull Options options) {

// We should not override the host applications Timber trees
if (Timber.treeCount() == 0) {
Timber.plant(new Timber.DebugTree());
Timber.d(String.valueOf(new Timber.DebugTree()));
}

hashKey = getHashKey();
Expand Down Expand Up @@ -158,6 +159,10 @@ public SyncFinishedCallback getSyncFinishedCallback() {
return options.getSyncFinishedCallback();
}

public Options getOptions() {
return options;
}

public static class Options {

private Context context;
Expand All @@ -167,6 +172,8 @@ public static class Options {
private ReceiverTransferDao receiverTransferDao;
private SenderTransferDao senderTransferDao;
private SyncFinishedCallback syncFinishedCallback;
private Boolean skipQrCodeScan = true;

@Nullable
private RecalledIdentifier recalledIdentifier;
private int batchSize = Constants.DEFAULT_SHARE_BATCH_SIZE;
Expand Down Expand Up @@ -247,5 +254,13 @@ public RecalledIdentifier getRecalledIdentifier() {
public void setRecalledIdentifier(@Nullable RecalledIdentifier recalledIdentifier) {
this.recalledIdentifier = recalledIdentifier;
}

public boolean allowSkipQrCodeScan() {
return skipQrCodeScan != null && skipQrCodeScan;
}

public void setSkipQrCodeScan(boolean skipQrCodeScan) {
this.skipQrCodeScan = skipQrCodeScan;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@
import android.net.Uri;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.annotation.VisibleForTesting;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.annotation.VisibleForTesting;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gms.common.api.ApiException;
import com.google.android.gms.common.api.ResolvableApiException;
Expand All @@ -40,6 +41,8 @@
import org.smartregister.p2p.R;
import org.smartregister.p2p.contract.P2pModeSelectContract;
import org.smartregister.p2p.dialog.ConnectingDialog;
import org.smartregister.p2p.dialog.ReceiverConnectionInfoDialog;
import org.smartregister.p2p.dialog.SenderApprovalDialog;
import org.smartregister.p2p.dialog.SkipQRScanDialog;
import org.smartregister.p2p.dialog.StartDiscoveringModeProgressDialog;
import org.smartregister.p2p.dialog.StartReceiveModeProgressDialog;
Expand Down Expand Up @@ -300,7 +303,8 @@ public boolean removeDiscoveringProgressDialog() {
return removeDialog(Constants.Dialog.START_SEND_MODE_PROGRESS);
}

private boolean removeDialog(@NonNull String tag) {
@Override
public boolean removeDialog(@NonNull String tag) {
Fragment fragment = getSupportFragmentManager()
.findFragmentByTag(tag);

Expand Down Expand Up @@ -347,6 +351,7 @@ public void showQRCodeScanningFragment(@NonNull String deviceName, @NonNull QRCo
@Override
public void showQRCodeGeneratorFragment(@NonNull String authenticationCode, @NonNull String deviceName
, @NonNull QRCodeGeneratorFragment.QRCodeGeneratorCallback qrCodeGeneratorCallback) {
// here
QRCodeGeneratorFragment newFragment = new QRCodeGeneratorFragment();
newFragment.setAuthenticationCode(authenticationCode);
newFragment.setDeviceName(deviceName);
Expand All @@ -362,10 +367,34 @@ public void showQRCodeGeneratorFragment(@NonNull String authenticationCode, @Non
transaction.commit();
}

@Override
public void showSenderApprovalDialog(@NonNull String authenticationCode, @NonNull String deviceName, @Nullable DialogCancelCallback dialogCancelCallback, @NonNull DialogApprovedCallback dialogApprovedCallback) {
FragmentManager fragmentManager = getSupportFragmentManager();
SenderApprovalDialog newFragment = new SenderApprovalDialog();
newFragment.setConnectionDeviceName(deviceName);
newFragment.setConnectionKey(authenticationCode);
newFragment.setDialogCancelCallback(dialogCancelCallback);
newFragment.setDialogApprovedCallback(dialogApprovedCallback);

newFragment.show(fragmentManager, Constants.Dialog.DISPLAY_APPROVAL_KEY);
}

@Override
public void showReceiverApprovalDialog(@NonNull String authenticationCode, @NonNull String deviceName, @Nullable DialogCancelCallback dialogCancelCallback, @NonNull DialogApprovedCallback dialogApprovedCallback) {
FragmentManager fragmentManager = getSupportFragmentManager();
ReceiverConnectionInfoDialog newFragment = new ReceiverConnectionInfoDialog();
newFragment.setConnectionDeviceName(deviceName);
newFragment.setConnectionKey(authenticationCode);
newFragment.setDialogCancelCallback(dialogCancelCallback);
newFragment.setDialogApprovedCallback(dialogApprovedCallback);

newFragment.show(fragmentManager, Constants.Dialog.DISPLAY_APPROVAL_KEY);
}

@Override
public void showConnectionAcceptDialog(@NonNull String receiverDeviceName, @NonNull String authenticationCode
, @NonNull final DialogInterface.OnClickListener onClickListener) {
new android.support.v7.app.AlertDialog.Builder(this)
new AlertDialog.Builder(this)
.setMessage(String.format(getString(R.string.accept_connection_dialog_content), authenticationCode))
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
Expand Down Expand Up @@ -637,7 +666,8 @@ protected void onResume() {
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);

for (OnActivityRequestPermissionHandler onActivityRequestPermissionHandler : onActivityRequestPermissionHandlers) {
// prevent concurrent modification error
for (OnActivityRequestPermissionHandler onActivityRequestPermissionHandler : new ArrayList<>(onActivityRequestPermissionHandlers)) {
if (requestCode == onActivityRequestPermissionHandler.getRequestCode()) {
onActivityRequestPermissionHandler.handlePermissionResult(permissions, grantResults);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.smartregister.p2p.authenticator;

import android.support.annotation.NonNull;
import androidx.annotation.NonNull;

import org.smartregister.p2p.P2PLibrary;
import org.smartregister.p2p.contract.P2pModeSelectContract;
import org.smartregister.p2p.sync.DiscoveredDevice;

Expand Down Expand Up @@ -31,4 +32,8 @@ public interface AuthenticationCallback {

void onAuthenticationCancelled(@NonNull String reason);
}

public boolean allowSkipQrCodeScan(){
return P2PLibrary.getInstance().getOptions().allowSkipQrCodeScan();
}
}
Loading