├── app ├── .gitignore ├── src │ └── main │ │ ├── res │ │ ├── mipmap-hdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ │ └── ic_launcher.png │ │ ├── values │ │ │ ├── strings.xml │ │ │ ├── colors.xml │ │ │ └── styles.xml │ │ └── layout │ │ │ └── activity_main.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── io │ │ └── github │ │ └── tslamic │ │ └── premiumer │ │ ├── LogPremiumerListener.java │ │ └── MainActivity.java ├── build.gradle └── proguard-rules.pro ├── prem ├── .gitignore ├── src │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ │ └── io │ │ │ │ └── github │ │ │ │ └── tslamic │ │ │ │ └── prem │ │ │ │ ├── Billing.java │ │ │ │ ├── Binder.java │ │ │ │ ├── Constant.java │ │ │ │ ├── PurchaseVerifier.java │ │ │ │ ├── PayloadGenerator.java │ │ │ │ ├── Util.java │ │ │ │ ├── BillingItem.java │ │ │ │ ├── PremiumerListenerProxy.java │ │ │ │ ├── SimpleBinder.java │ │ │ │ ├── SimplePremiumerListener.java │ │ │ │ ├── PurchaseCache.java │ │ │ │ ├── Builder.java │ │ │ │ ├── PremiumerHandler.java │ │ │ │ ├── PremiumerListener.java │ │ │ │ ├── Premiumer.java │ │ │ │ ├── PremiumerBuilder.java │ │ │ │ ├── SkuDetails.java │ │ │ │ ├── SimpleBilling.java │ │ │ │ ├── Purchase.java │ │ │ │ └── SimplePremiumer.java │ │ └── aidl │ │ │ └── com │ │ │ └── android │ │ │ └── vending │ │ │ └── billing │ │ │ └── IInAppBillingService.aidl │ └── test │ │ └── java │ │ └── io │ │ └── github │ │ └── tslamic │ │ └── prem │ │ ├── BillingNullTest.java │ │ ├── AssertUtil.java │ │ ├── TestFactory.java │ │ ├── CacheTest.java │ │ ├── BadBillingTest.java │ │ ├── stub │ │ ├── BillingServiceStub.java │ │ ├── PackageManagerStub.java │ │ └── ContextStub.java │ │ ├── TestUtil.java │ │ ├── BillingRemoteExceptionTest.java │ │ ├── BillingBadResponseTest.java │ │ ├── SkuDetailsTest.java │ │ ├── SuccessfulBillingService.java │ │ ├── PurchaseTest.java │ │ ├── BuilderTest.java │ │ ├── PremiumerHandlerTest.java │ │ ├── SimplePremiumerBindTest.java │ │ ├── SimpleBinderTest.java │ │ ├── BillingTest.java │ │ └── PremiumerTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .travis.yml ├── .gitignore ├── gradle.properties ├── gradlew.bat ├── gradlew ├── config └── checkstyle │ └── checkstyle.xml └── README.md /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /prem/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':prem' 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tslamic/premiumer/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tslamic/premiumer/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tslamic/premiumer/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tslamic/premiumer/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tslamic/premiumer/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Premiumer 3 | 4 | Hello world! 5 | Settings 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /prem/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Jan 20 06:55:09 GMT 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: android 2 | 3 | jdk: 4 | - oraclejdk8 5 | 6 | android: 7 | components: 8 | - tools 9 | - tools 10 | - platform-tools 11 | - build-tools-25.0.2 12 | - android-25 13 | - extra-android-m2repository 14 | - extra-google-m2repository 15 | - extra-android-support 16 | - extra-google-google_play_services 17 | 18 | licenses: 19 | - 'android-sdk-preview-license-.+' 20 | - 'android-sdk-license-.+' 21 | 22 | after_success: 23 | - bash <(curl -s https://codecov.io/bash) 24 | 25 | sudo: false 26 | -------------------------------------------------------------------------------- /prem/src/main/java/io/github/tslamic/prem/Billing.java: -------------------------------------------------------------------------------- 1 | package io.github.tslamic.prem; 2 | 3 | import android.app.Activity; 4 | import android.support.annotation.NonNull; 5 | import android.support.annotation.Nullable; 6 | 7 | interface Billing { 8 | boolean isBillingSupported(); 9 | boolean purchase(@NonNull Activity activity, @NonNull String sku, int requestCode, 10 | @Nullable String payload); 11 | @Nullable SkuDetails skuDetails(@NonNull String sku); 12 | boolean consumeSku(@NonNull String purchaseToken); 13 | boolean ownsSku(@NonNull String sku); 14 | } 15 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.2" 6 | 7 | defaultConfig { 8 | applicationId "io.github.tslamic.premiumer" 9 | minSdkVersion 9 10 | targetSdkVersion 25 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile 'com.android.support:appcompat-v7:25.1.0' 24 | compile project(":prem") 25 | } 26 | -------------------------------------------------------------------------------- /prem/src/main/java/io/github/tslamic/prem/Binder.java: -------------------------------------------------------------------------------- 1 | package io.github.tslamic.prem; 2 | 3 | import android.content.Intent; 4 | import android.content.ServiceConnection; 5 | import android.os.IBinder; 6 | import android.support.annotation.NonNull; 7 | import com.android.vending.billing.IInAppBillingService; 8 | 9 | interface Binder { 10 | @NonNull IInAppBillingService service(IBinder binder); 11 | @NonNull Billing billing(@NonNull String packageName, @NonNull IInAppBillingService service); 12 | boolean hasBillingCapabilities(@NonNull Intent intent); 13 | boolean bind(@NonNull Intent intent, @NonNull ServiceConnection conn, int flags); 14 | void unbind(); 15 | boolean isBound(); 16 | } 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | *.iml 3 | 4 | .gradle 5 | /local.properties 6 | /.idea/workspace.xml 7 | /.idea/libraries 8 | .DS_Store 9 | /build 10 | /captures 11 | 12 | # Built application files 13 | *.apk 14 | *.ap_ 15 | 16 | # Files for the Dalvik VM 17 | *.dex 18 | 19 | # Java class files 20 | *.class 21 | 22 | # Generated files 23 | bin/ 24 | gen/ 25 | 26 | # Gradle files 27 | .gradle/ 28 | build/ 29 | 30 | # Local configuration file (sdk path, etc) 31 | local.properties 32 | 33 | # Proguard folder generated by Eclipse 34 | proguard/ 35 | 36 | # Log Files 37 | *.log 38 | 39 | # Android Studio Navigation editor temp files 40 | .navigation/ 41 | 42 | # Android Studio captures folder 43 | captures/ 44 | 45 | javadoc/ 46 | -------------------------------------------------------------------------------- /prem/src/test/java/io/github/tslamic/prem/BillingNullTest.java: -------------------------------------------------------------------------------- 1 | package io.github.tslamic.prem; 2 | 3 | import com.android.vending.billing.IInAppBillingService; 4 | import io.github.tslamic.prem.stub.BillingServiceStub; 5 | import org.junit.runner.RunWith; 6 | import org.robolectric.RobolectricTestRunner; 7 | 8 | @RunWith(RobolectricTestRunner.class) public class BillingNullTest extends BadBillingTest { 9 | @Override public void isBillingSupported() { 10 | // Do nothing as response is non-null. 11 | } 12 | 13 | @Override public void consumeSku() { 14 | // Do nothing as response is non-null. 15 | } 16 | 17 | @Override IInAppBillingService service() { 18 | return new BillingServiceStub(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/slamitad/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /prem/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/slamitad/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /prem/src/main/java/io/github/tslamic/prem/Constant.java: -------------------------------------------------------------------------------- 1 | package io.github.tslamic.prem; 2 | 3 | final class Constant { 4 | private Constant() { 5 | throw new AssertionError(); 6 | } 7 | 8 | static final String RESPONSE_CODE = "RESPONSE_CODE"; 9 | static final String RESPONSE_DETAILS_LIST = "DETAILS_LIST"; 10 | static final String RESPONSE_BUY_INTENT = "BUY_INTENT"; 11 | static final String RESPONSE_PURCHASE_DATA = "INAPP_PURCHASE_DATA"; 12 | static final String RESPONSE_SIGNATURE = "INAPP_DATA_SIGNATURE"; 13 | static final String RESPONSE_ITEM_LIST = "INAPP_PURCHASE_ITEM_LIST"; 14 | static final String REQUEST_ITEM_ID_LIST = "ITEM_ID_LIST"; 15 | static final String BILLING_TYPE = "inapp"; 16 | static final int BILLING_RESPONSE_RESULT_OK = 0; 17 | } 18 | -------------------------------------------------------------------------------- /prem/src/main/java/io/github/tslamic/prem/PurchaseVerifier.java: -------------------------------------------------------------------------------- 1 | package io.github.tslamic.prem; 2 | 3 | import android.support.annotation.NonNull; 4 | import android.support.annotation.Nullable; 5 | import android.support.annotation.WorkerThread; 6 | 7 | /** 8 | * Provides means to verify a purchase. 9 | */ 10 | public interface PurchaseVerifier { 11 | /** 12 | * Verifies a purchase. 13 | * 14 | * @param signatureBase64 the base64-encoded public key to use for verifying. 15 | * @param purchaseData the signed JSON string (signed, not encrypted) 16 | * @param purchaseSignature the signature for the data, signed with the private key 17 | * @return {@code true} if purchase is successfully verified, {@code false} otherwise. 18 | */ 19 | @WorkerThread boolean verify(@Nullable String signatureBase64, @NonNull String purchaseData, 20 | @NonNull String purchaseSignature); 21 | } 22 | -------------------------------------------------------------------------------- /prem/src/main/java/io/github/tslamic/prem/PayloadGenerator.java: -------------------------------------------------------------------------------- 1 | package io.github.tslamic.prem; 2 | 3 | import android.support.annotation.MainThread; 4 | import android.support.annotation.Nullable; 5 | import java.util.UUID; 6 | 7 | /** 8 | * Generates {@link String}s denoting a developer payload. 9 | */ 10 | public interface PayloadGenerator { 11 | /** 12 | * Generates random {@link UUID} strings denoting a developer payload. 13 | */ 14 | final class UuidPayloadGenerator implements PayloadGenerator { 15 | /** 16 | * Generates a random {@link UUID} string. 17 | */ 18 | @Override @MainThread @Nullable public String generate() { 19 | return UUID.randomUUID().toString(); 20 | } 21 | } 22 | 23 | /** 24 | * Returns a developer-specified {@link String} containing supplemental information about a 25 | * purchase. 26 | */ 27 | @MainThread @Nullable String generate(); 28 | } 29 | -------------------------------------------------------------------------------- /prem/src/test/java/io/github/tslamic/prem/AssertUtil.java: -------------------------------------------------------------------------------- 1 | package io.github.tslamic.prem; 2 | 3 | import android.support.annotation.NonNull; 4 | import android.support.annotation.Nullable; 5 | import org.mockito.Mockito; 6 | 7 | import static com.google.common.truth.Truth.assertThat; 8 | 9 | final class AssertUtil { 10 | private AssertUtil() { 11 | throw new AssertionError(); 12 | } 13 | 14 | static void assertEq(@Nullable Object fst, @Nullable Object snd) { 15 | assertThat(fst).isEqualTo(snd); 16 | if (fst != null) { 17 | assertThat(fst.hashCode()).isEqualTo(snd.hashCode()); 18 | } 19 | } 20 | 21 | static T assertInvokedOnce(@NonNull T mock) { 22 | return Mockito.verify(mock, Mockito.times(1)); 23 | } 24 | 25 | static T assertInvokedNever(@NonNull T mock) { 26 | return Mockito.verify(mock, Mockito.never()); 27 | } 28 | 29 | static void assertNoInteraction(@NonNull T mock) { 30 | Mockito.verifyZeroInteractions(mock); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /prem/src/main/java/io/github/tslamic/prem/Util.java: -------------------------------------------------------------------------------- 1 | package io.github.tslamic.prem; 2 | 3 | import android.support.annotation.NonNull; 4 | import android.support.annotation.Nullable; 5 | import java.util.ArrayList; 6 | import java.util.Collections; 7 | 8 | final class Util { 9 | private Util() { 10 | throw new AssertionError(); 11 | } 12 | 13 | static T checkNotNull(@Nullable T obj, @NonNull String message) { 14 | if (obj == null) { 15 | throw new NullPointerException(message); 16 | } 17 | return obj; 18 | } 19 | 20 | static boolean isBlank(@Nullable CharSequence string) { 21 | return string == null || string.toString().trim().length() == 0; 22 | } 23 | 24 | static boolean safeEquals(@Nullable Object fst, @Nullable Object snd) { 25 | return fst == snd || fst != null && fst.equals(snd); 26 | } 27 | 28 | @SafeVarargs static ArrayList arrayList(@NonNull T... items) { 29 | checkNotNull(items, "items == null"); 30 | final ArrayList list = new ArrayList<>(items.length); 31 | Collections.addAll(list, items); 32 | return list; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /prem/src/test/java/io/github/tslamic/prem/TestFactory.java: -------------------------------------------------------------------------------- 1 | package io.github.tslamic.prem; 2 | 3 | import android.content.Context; 4 | import android.os.Handler; 5 | import com.android.vending.billing.IInAppBillingService; 6 | 7 | import static io.github.tslamic.prem.TestUtil.PACKAGE_NAME; 8 | 9 | final class TestFactory { 10 | private TestFactory() { 11 | throw new AssertionError(); 12 | } 13 | 14 | static Billing billing(IInAppBillingService service) { 15 | return new SimpleBilling(PACKAGE_NAME, service); 16 | } 17 | 18 | static Binder binder(Context context) { 19 | return new SimpleBinder(context); 20 | } 21 | 22 | static Premiumer premiumer(Builder builder, Binder binder) { 23 | if (!(builder instanceof PremiumerBuilder)) { 24 | throw new AssertionError(); 25 | } 26 | return new SimplePremiumer((PremiumerBuilder) builder, binder); 27 | } 28 | 29 | static PurchaseCache cache(Context context) { 30 | return new PurchaseCache.SharedPrefsCache(context); 31 | } 32 | 33 | static Handler premiumerHandler(PremiumerListener listener) { 34 | return new PremiumerHandler(listener); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /prem/src/test/java/io/github/tslamic/prem/CacheTest.java: -------------------------------------------------------------------------------- 1 | package io.github.tslamic.prem; 2 | 3 | import android.content.Context; 4 | import org.junit.Before; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.robolectric.RobolectricTestRunner; 8 | import org.robolectric.RuntimeEnvironment; 9 | 10 | import static com.google.common.truth.Truth.assertThat; 11 | import static io.github.tslamic.prem.AssertUtil.assertEq; 12 | import static io.github.tslamic.prem.TestUtil.JSON_PURCHASE; 13 | 14 | @RunWith(RobolectricTestRunner.class) public class CacheTest { 15 | private PurchaseCache cache; 16 | 17 | @Before public void setUp() { 18 | final Context context = RuntimeEnvironment.application; 19 | cache = TestFactory.cache(context); 20 | } 21 | 22 | @Test public void checkAll() throws Exception { 23 | final String signature = "signature"; 24 | final Purchase p = new Purchase(JSON_PURCHASE, signature); 25 | cache.cache(p); 26 | 27 | final Purchase q = cache.load(); 28 | assertEq(p, q); 29 | 30 | cache.clear(); 31 | final Purchase r = cache.load(); 32 | assertThat(r).isNull(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /prem/src/main/java/io/github/tslamic/prem/BillingItem.java: -------------------------------------------------------------------------------- 1 | package io.github.tslamic.prem; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | import android.support.annotation.NonNull; 6 | import org.json.JSONException; 7 | import org.json.JSONObject; 8 | 9 | import static io.github.tslamic.prem.Util.checkNotNull; 10 | 11 | abstract class BillingItem implements Parcelable { 12 | private final String json; 13 | 14 | BillingItem(@NonNull String json) throws JSONException { 15 | checkNotNull(json, "json == null"); 16 | final JSONObject object = new JSONObject(json); 17 | this.json = json; 18 | init(object); 19 | } 20 | 21 | @SuppressWarnings("UnusedParameters") BillingItem(@NonNull Parcel parcel) { 22 | json = parcel.readString(); 23 | } 24 | 25 | @Override public int describeContents() { 26 | return 0; // No special content. 27 | } 28 | 29 | @Override public void writeToParcel(Parcel dest, int flags) { 30 | dest.writeString(json); 31 | } 32 | 33 | @NonNull public final String asJson() { 34 | return json; 35 | } 36 | 37 | @Override public String toString() { 38 | return asJson(); 39 | } 40 | 41 | abstract void init(@NonNull JSONObject object) throws JSONException; 42 | } 43 | -------------------------------------------------------------------------------- /prem/src/test/java/io/github/tslamic/prem/BadBillingTest.java: -------------------------------------------------------------------------------- 1 | package io.github.tslamic.prem; 2 | 3 | import android.app.Activity; 4 | import com.android.vending.billing.IInAppBillingService; 5 | import org.junit.Test; 6 | 7 | import static com.google.common.truth.Truth.assertThat; 8 | import static io.github.tslamic.prem.TestUtil.SKU; 9 | 10 | public abstract class BadBillingTest { 11 | @Test public void isBillingSupported() { 12 | final boolean supported = billing().isBillingSupported(); 13 | assertThat(supported).isFalse(); 14 | } 15 | 16 | @Test public void purchase() { 17 | final boolean purchased = billing().purchase(new Activity(), SKU, 0, null); 18 | assertThat(purchased).isFalse(); 19 | } 20 | 21 | @Test public void skuDetails() { 22 | final SkuDetails details = billing().skuDetails(SKU); 23 | assertThat(details).isNull(); 24 | } 25 | 26 | @Test public void consumeSku() { 27 | final boolean consumed = billing().consumeSku(SKU); 28 | assertThat(consumed).isFalse(); 29 | } 30 | 31 | @Test public void ownsSku() { 32 | final boolean owned = billing().ownsSku(SKU); 33 | assertThat(owned).isFalse(); 34 | } 35 | 36 | Billing billing() { 37 | return TestFactory.billing(service()); 38 | } 39 | 40 | abstract IInAppBillingService service(); 41 | } 42 | -------------------------------------------------------------------------------- /prem/src/test/java/io/github/tslamic/prem/stub/BillingServiceStub.java: -------------------------------------------------------------------------------- 1 | package io.github.tslamic.prem.stub; 2 | 3 | import android.os.Bundle; 4 | import android.os.IBinder; 5 | import android.os.RemoteException; 6 | import com.android.vending.billing.IInAppBillingService; 7 | 8 | public class BillingServiceStub implements IInAppBillingService { 9 | @Override public int isBillingSupported(int apiVersion, String packageName, String type) 10 | throws RemoteException { 11 | return 0; 12 | } 13 | 14 | @Override 15 | public Bundle getSkuDetails(int apiVersion, String packageName, String type, Bundle skusBundle) 16 | throws RemoteException { 17 | return null; 18 | } 19 | 20 | @Override public Bundle getBuyIntent(int apiVersion, String packageName, String sku, String type, 21 | String developerPayload) throws RemoteException { 22 | return null; 23 | } 24 | 25 | @Override public Bundle getPurchases(int apiVersion, String packageName, String type, 26 | String continuationToken) throws RemoteException { 27 | return null; 28 | } 29 | 30 | @Override public int consumePurchase(int apiVersion, String packageName, String purchaseToken) 31 | throws RemoteException { 32 | return 0; 33 | } 34 | 35 | @Override public IBinder asBinder() { 36 | throw new AssertionError(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /prem/src/test/java/io/github/tslamic/prem/TestUtil.java: -------------------------------------------------------------------------------- 1 | package io.github.tslamic.prem; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | import android.support.annotation.NonNull; 6 | import java.util.concurrent.Executor; 7 | 8 | final class TestUtil { 9 | private TestUtil() { 10 | throw new AssertionError(); 11 | } 12 | 13 | static final String PACKAGE_NAME = "dummy.package"; 14 | static final String SKU = "dummy.sku"; 15 | 16 | static final Executor EAGER_EXECUTOR = new Executor() { 17 | @Override public void execute(@NonNull Runnable command) { 18 | command.run(); 19 | } 20 | }; 21 | 22 | static final String JSON_SKU = "{" 23 | + " \"title\":\"TestTitle\"," 24 | + " \"price\":\"€7.99\"," 25 | + " \"type\":\"inapp\"," 26 | + " \"description\":\"TestDescription\"," 27 | + " \"price_amount_micros\":\"7990000\"," 28 | + " \"price_currency_code\":\"EUR\"," 29 | + " \"productId\":\"TestProductId\"" 30 | + "}"; 31 | 32 | static final String JSON_PURCHASE = "{" 33 | + " \"orderId\":\"TestOrder\"," 34 | + " \"packageName\":\"com.example.app\"," 35 | + " \"productId\":\"TestProductId\"," 36 | + " \"purchaseTime\":1345678900000," 37 | + " \"purchaseState\":0," 38 | + " \"developerPayload\":\"TestDeveloperPayload\"," 39 | + " \"purchaseToken\":\"TestPurchaseToken\"" 40 | + "}"; 41 | 42 | static T fromParcel(T src, Parcelable.Creator creator) { 43 | final Parcel parcel = Parcel.obtain(); 44 | src.writeToParcel(parcel, 0); 45 | parcel.setDataPosition(0); 46 | return creator.createFromParcel(parcel); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /prem/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'jacoco-android' 3 | apply plugin: 'checkstyle' 4 | 5 | def isCi = 'true'.equals(System.getenv('CI')) 6 | 7 | android { 8 | compileSdkVersion 25 9 | buildToolsVersion "25.0.2" 10 | 11 | defaultConfig { 12 | minSdkVersion 9 13 | targetSdkVersion 25 14 | versionCode 1 15 | versionName "1.0" 16 | } 17 | 18 | testOptions { 19 | unitTests.all { 20 | jacoco { 21 | includeNoLocationClasses = true 22 | } 23 | } 24 | } 25 | 26 | buildTypes { 27 | debug { 28 | testCoverageEnabled = true 29 | } 30 | release { 31 | minifyEnabled false 32 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 33 | } 34 | } 35 | } 36 | 37 | apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle' 38 | 39 | dependencies { 40 | compile 'com.android.support:support-annotations:25.1.0' 41 | testCompile "org.robolectric:robolectric:3.2.2" 42 | testCompile "org.mockito:mockito-core:2.6.8" 43 | testCompile "com.google.truth:truth:0.31" 44 | } 45 | 46 | task checkCodingStyle(type: Checkstyle) { 47 | description 'Runs Checkstyle inspection against Android sourcesets.' 48 | group = 'Code Quality' 49 | ignoreFailures = false 50 | showViolations = false 51 | source 'src' 52 | include '**/*.java' 53 | exclude '**/gen/**' 54 | exclude '**/R.java' 55 | exclude '**/BuildConfig.java' 56 | reports { 57 | xml.destination "$project.buildDir/reports/checkstyle/report.xml" 58 | } 59 | classpath = files() 60 | configFile = file("${rootProject.rootDir}/config/checkstyle/checkstyle.xml") 61 | } 62 | 63 | if (isCi) { 64 | build.finalizedBy([checkCodingStyle, jacocoTestReport]) 65 | } 66 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | 20 | VERSION_NAME=1.0 21 | VERSION_CODE=1 22 | GROUP=com.github.tslamic 23 | 24 | POM_NAME=Premiumer2 25 | POM_ARTIFACT_ID=premiumer2 26 | POM_PACKAGING=aar 27 | 28 | POM_DESCRIPTION=Premiumer makes removing ads with a single in-app purchase as easy as pie. 29 | POM_URL=https://github.com/tslamic/premiumer 30 | POM_SCM_URL=https://github.com/tslamic/premiumer 31 | POM_SCM_CONNECTION=scm:git@github.com:tslamic/premiumer.git 32 | POM_SCM_DEV_CONNECTION=scm:git@github.com:tslamic/premiumer.git 33 | POM_LICENCE_NAME=The Apache Software License, Version 2.0 34 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt 35 | POM_LICENCE_DIST=repo 36 | POM_DEVELOPER_ID=tslamic 37 | POM_DEVELOPER_NAME=Tadej Slamic 38 | 39 | SNAPSHOT_REPOSITORY_URL=https://oss.sonatype.org/content/repositories/snapshots 40 | RELEASE_REPOSITORY_URL=https://oss.sonatype.org/service/local/staging/deploy/maven2 41 | -------------------------------------------------------------------------------- /prem/src/test/java/io/github/tslamic/prem/BillingRemoteExceptionTest.java: -------------------------------------------------------------------------------- 1 | package io.github.tslamic.prem; 2 | 3 | import android.os.Bundle; 4 | import android.os.IBinder; 5 | import android.os.RemoteException; 6 | import com.android.vending.billing.IInAppBillingService; 7 | import org.junit.runner.RunWith; 8 | import org.robolectric.RobolectricTestRunner; 9 | 10 | @RunWith(RobolectricTestRunner.class) public class BillingRemoteExceptionTest 11 | extends BadBillingTest { 12 | @Override IInAppBillingService service() { 13 | return new RemoteExceptionBillingService(); 14 | } 15 | 16 | private static final class RemoteExceptionBillingService implements IInAppBillingService { 17 | @Override public int isBillingSupported(int apiVersion, String packageName, String type) 18 | throws RemoteException { 19 | throw new RemoteException(); 20 | } 21 | 22 | @Override 23 | public Bundle getSkuDetails(int apiVersion, String packageName, String type, Bundle skusBundle) 24 | throws RemoteException { 25 | throw new RemoteException(); 26 | } 27 | 28 | @Override 29 | public Bundle getBuyIntent(int apiVersion, String packageName, String sku, String type, 30 | String developerPayload) throws RemoteException { 31 | throw new RemoteException(); 32 | } 33 | 34 | @Override public Bundle getPurchases(int apiVersion, String packageName, String type, 35 | String continuationToken) throws RemoteException { 36 | throw new RemoteException(); 37 | } 38 | 39 | @Override public int consumePurchase(int apiVersion, String packageName, String purchaseToken) 40 | throws RemoteException { 41 | throw new RemoteException(); 42 | } 43 | 44 | @Override public IBinder asBinder() { 45 | throw new AssertionError(); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 |