diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..5fdffda --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,30 @@ +version: 2 +jobs: + build: + working_directory: ~/code + docker: + - image: circleci/android:api-29 + environment: + JVM_OPTS: -Xmx3200m + steps: + - checkout + - restore_cache: + key: jars-{{ checksum "build.gradle" }}-{{ checksum "library/build.gradle" }} + - run: + name: Download Dependencies + command: ./gradlew androidDependencies + - save_cache: + paths: + - ~/.gradle + key: jars-{{ checksum "build.gradle" }}-{{ checksum "library/build.gradle" }} + - run: + name: Run Tests + command: ./gradlew check evaluateViolations test + - store_artifacts: + path: library/build/reports + destination: reports + - store_artifacts: + path: library/build/outputs + destination: reports + - store_test_results: + path: library/build/test-results \ No newline at end of file diff --git a/build.gradle b/build.gradle index bfcba32..1b45cf7 100644 --- a/build.gradle +++ b/build.gradle @@ -1,18 +1,32 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. - buildscript { + ext { + app = [ + versionCode: 11, + versionName: "1.2.8" + ] + + general = [ + compileSdkVersion: 29, + minSdkVersion : 15, + targetSdkVersion : 29, + buildToolsVersion: "29.0.3" + ] + } + repositories { jcenter() + google() } + dependencies { - classpath 'com.android.tools.build:gradle:2.0.0' - classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3' + classpath 'com.android.tools.build:gradle:3.5.3' } } allprojects { repositories { jcenter() + google() } } diff --git a/circle.yml b/circle.yml deleted file mode 100644 index 54c7a90..0000000 --- a/circle.yml +++ /dev/null @@ -1,12 +0,0 @@ -dependencies: - pre: - - echo y | android update sdk --no-ui --all --filter "tools,platform-tools,android-23" - - echo y | android update sdk --no-ui --all --filter "build-tools-23.0.2" - -test: - override: - # run lint (tests will come next ...) - - ./gradlew :library:check - - # copy results - - cp -r library/build/reports library/build/outputs $CIRCLE_ARTIFACTS \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 1d3591c..915f0e6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,4 +15,6 @@ # When configured, Gradle will run in incubating parallel mode. # 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 \ No newline at end of file +# org.gradle.parallel=true +android.enableJetifier=true +android.useAndroidX=true \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 122a0dc..337d5c8 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Dec 28 10:00:20 PST 2015 +#Tue Feb 25 09:26:59 EET 2020 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip diff --git a/library/build.gradle b/library/build.gradle index b53377e..179ae23 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,21 +1,24 @@ -apply plugin: 'com.android.library' -apply plugin: 'com.github.dcendents.android-maven' +plugins { + id 'com.android.library' + id 'com.novoda.static-analysis' version '1.2' + id "com.github.spotbugs" version '3.0.0' +} -group='com.github.eggheadgames' +group = 'com.github.eggheadgames' repositories { mavenCentral() } android { - compileSdkVersion 23 - buildToolsVersion "23.0.2" + compileSdkVersion rootProject.ext.general.compileSdkVersion + buildToolsVersion rootProject.ext.general.buildToolsVersion defaultConfig { - minSdkVersion 15 - targetSdkVersion 23 - versionCode 11 - versionName "1.2.8" + minSdkVersion rootProject.ext.general.minSdkVersion + targetSdkVersion rootProject.ext.general.targetSdkVersion + versionCode rootProject.ext.general.versionCode + versionName rootProject.ext.general.versionName } lintOptions { @@ -27,9 +30,28 @@ android { } dependencies { - testCompile 'junit:junit:4.12' - testCompile 'org.mockito:mockito-core:1.10.19' + api files('libs/in-app-purchasing-2.0.61.jar') + api 'androidx.appcompat:appcompat:1.1.0' - compile files('libs/in-app-purchasing-2.0.61.jar') - compile 'com.android.support:appcompat-v7:23.2.1' + testImplementation 'junit:junit:4.13' + testImplementation 'org.mockito:mockito-core:2.24.0' } + +staticAnalysis { + penalty { + maxErrors = 0 + maxWarnings = 0 + } + pmd { + ignoreFailures = false + reportsDir = file("$project.buildDir/outputs/") + } + spotbugs { + ignoreFailures = false + reportsDir = file("$project.buildDir/outputs/") + reportLevel = "medium" + effort = "max" + + excludeFilter rootProject.file('library/findbugs_excludes.xml') + } +} \ No newline at end of file diff --git a/library/findbugs_excludes.xml b/library/findbugs_excludes.xml new file mode 100644 index 0000000..f13278c --- /dev/null +++ b/library/findbugs_excludes.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/library/src/androidTest/java/com/eggheadgames/inapppayments/ApplicationTest.java b/library/src/androidTest/java/com/eggheadgames/inapppayments/ApplicationTest.java deleted file mode 100644 index 82dac6a..0000000 --- a/library/src/androidTest/java/com/eggheadgames/inapppayments/ApplicationTest.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.eggheadgames.inapppayments; - -import android.app.Application; -import android.test.ApplicationTestCase; - -/** - * Testing Fundamentals - */ -public class ApplicationTest extends ApplicationTestCase { - public ApplicationTest() { - super(Application.class); - } -} \ No newline at end of file diff --git a/library/src/main/java/com/android/vending/billing/Base64.java b/library/src/main/java/com/android/vending/billing/Base64.java index 6b3f123..55ea5c0 100644 --- a/library/src/main/java/com/android/vending/billing/Base64.java +++ b/library/src/main/java/com/android/vending/billing/Base64.java @@ -33,6 +33,8 @@ import android.annotation.SuppressLint; +import java.nio.charset.Charset; + /** * Base64 converter class. This code is not a complete MIME encoder; * it simply converts binary data to base64 data and back. @@ -295,7 +297,7 @@ public static String encode(byte[] source, int off, int len, byte[] alphabet, outLen -= 1; } - return new String(outBuff, 0, outLen); + return new String(outBuff, 0, outLen, Charset.defaultCharset()); } /** @@ -430,7 +432,7 @@ private static int decode4to3(byte[] source, int srcOffset, * @since 1.4 */ public static byte[] decode(String s) throws Base64DecoderException { - byte[] bytes = s.getBytes(); + byte[] bytes = s.getBytes(Charset.defaultCharset()); return decode(bytes, 0, bytes.length); } @@ -442,7 +444,7 @@ public static byte[] decode(String s) throws Base64DecoderException { * @return the decoded data */ public static byte[] decodeWebSafe(String s) throws Base64DecoderException { - byte[] bytes = s.getBytes(); + byte[] bytes = s.getBytes(Charset.defaultCharset()); return decodeWebSafe(bytes, 0, bytes.length); } diff --git a/library/src/main/java/com/android/vending/billing/Security.java b/library/src/main/java/com/android/vending/billing/Security.java index ccac35e..105d2b7 100644 --- a/library/src/main/java/com/android/vending/billing/Security.java +++ b/library/src/main/java/com/android/vending/billing/Security.java @@ -18,6 +18,7 @@ import android.text.TextUtils; import android.util.Log; +import java.nio.charset.Charset; import java.security.InvalidKeyException; import java.security.KeyFactory; import java.security.NoSuchAlgorithmException; @@ -100,7 +101,7 @@ public static boolean verify(PublicKey publicKey, String signedData, String sign try { sig = Signature.getInstance(SIGNATURE_ALGORITHM); sig.initVerify(publicKey); - sig.update(signedData.getBytes()); + sig.update(signedData.getBytes(Charset.defaultCharset())); if (!sig.verify(Base64.decode(signature))) { Log.e(TAG, "Signature verification failed."); return false; diff --git a/library/src/main/java/com/android/vending/billing/SkuDetails.java b/library/src/main/java/com/android/vending/billing/SkuDetails.java index ed3c1ed..bc8f190 100644 --- a/library/src/main/java/com/android/vending/billing/SkuDetails.java +++ b/library/src/main/java/com/android/vending/billing/SkuDetails.java @@ -65,6 +65,10 @@ public String getDescription() { return mDescription; } + public String getItemType() { + return mItemType; + } + @Override public String toString() { return "SkuDetails:" + mJson; diff --git a/library/src/main/java/com/billing/BillingService.java b/library/src/main/java/com/billing/BillingService.java index 2ce743f..86a1f91 100644 --- a/library/src/main/java/com/billing/BillingService.java +++ b/library/src/main/java/com/billing/BillingService.java @@ -2,7 +2,7 @@ import android.app.Activity; import android.content.Context; -import android.support.annotation.CallSuper; +import androidx.annotation.CallSuper; import java.util.ArrayList; import java.util.List; diff --git a/library/src/main/java/com/billing/amazon/AmazonBillingListener.java b/library/src/main/java/com/billing/amazon/AmazonBillingListener.java index d8e96da..4f7a0c1 100644 --- a/library/src/main/java/com/billing/amazon/AmazonBillingListener.java +++ b/library/src/main/java/com/billing/amazon/AmazonBillingListener.java @@ -113,7 +113,7 @@ public void onPurchaseResponse(PurchaseResponse response) { @SuppressWarnings({"ConstantConditions", "ToArrayCallWithZeroLengthArrayArgument"}) @Override public void onPurchaseUpdatesResponse(PurchaseUpdatesResponse response) { - logDebug("onPurchaseUpdatesResponse " + response.getRequestStatus()); + logDebug("onPurchaseUpdatesResponse " + (response == null ? "null" : response.getRequestStatus())); if (response == null) return; if (response.getRequestStatus() == PurchaseUpdatesResponse.RequestStatus.SUCCESSFUL) { diff --git a/library/src/main/java/com/eggheadgames/inapppayments/IAPActivity.java b/library/src/main/java/com/eggheadgames/inapppayments/IAPActivity.java index 23b4cad..82f73cc 100644 --- a/library/src/main/java/com/eggheadgames/inapppayments/IAPActivity.java +++ b/library/src/main/java/com/eggheadgames/inapppayments/IAPActivity.java @@ -1,7 +1,7 @@ package com.eggheadgames.inapppayments; import android.content.Intent; -import android.support.v7.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatActivity; import com.billing.BillingService; import com.billing.google.GoogleBillingService; diff --git a/library/src/main/java/com/eggheadgames/inapppayments/IAPManager.java b/library/src/main/java/com/eggheadgames/inapppayments/IAPManager.java index 2754593..f34f54a 100644 --- a/library/src/main/java/com/eggheadgames/inapppayments/IAPManager.java +++ b/library/src/main/java/com/eggheadgames/inapppayments/IAPManager.java @@ -1,5 +1,6 @@ package com.eggheadgames.inapppayments; +import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; @@ -15,16 +16,21 @@ public class IAPManager { + public static final int BUILD_TARGET_GOOGLE = 0; + public static final int BUILD_TARGET_AMAZON = 1; + + @SuppressLint("StaticFieldLeak") private static BillingService billingService; - public static int BUILD_TARGET_GOOGLE = 0; - public static int BUILD_TARGET_AMAZON = 1; public static void build(Context context, int buildTarget, List iapkeys) { + Context applicationContext = context.getApplicationContext(); + Context contextLocal = applicationContext == null ? context : applicationContext; + //Build-specific initializations if (buildTarget == BUILD_TARGET_GOOGLE) { - billingService = new GoogleBillingService(context, iapkeys); + billingService = new GoogleBillingService(contextLocal, iapkeys); } else if (buildTarget == BUILD_TARGET_AMAZON) { - billingService = new AmazonBillingService(context, iapkeys); + billingService = new AmazonBillingService(contextLocal, iapkeys); } }