mirror of https://github.com/M66B/NetGuard.git
Changed IAB logic
Still crashing: 11-19 09:18:19.688 28800 28800 E AndroidRuntime: java.lang.NullPointerException: Attempt to read from field 'com.google.android.finsky.protos.Acquisition$AutoDismissTemplate com.google.android.finsky.protos.Acquisition$PostAcquisitionPrompt.autoDismissTemplate' on a null object reference 11-19 09:18:19.688 28800 28800 E AndroidRuntime: at com.google.android.finsky.billing.SuccessStep.getLayoutResId(SuccessStep.java:75) 11-19 09:18:19.688 28800 28800 E AndroidRuntime: at com.google.android.finsky.billing.lightpurchase.PurchaseFragment.onStateChange(PurchaseFragment.java:31066) 11-19 09:18:19.688 28800 28800 E AndroidRuntime: at com.google.android.finsky.fragments.SidecarFragment.notifyListener(SidecarFragment.java:255) 11-19 09:18:19.688 28800 28800 E AndroidRuntime: at com.google.android.finsky.fragments.SidecarFragment.setState(SidecarFragment.java:250) 11-19 09:18:19.688 28800 28800 E AndroidRuntime: at com.google.android.finsky.billing.lightpurchase.CheckoutPurchaseSidecar.confirmAuthChoiceSelected(CheckoutPurchaseSidecar.java:631) 11-19 09:18:19.688 28800 28800 E AndroidRuntime: at com.google.android.finsky.billing.lightpurchase.purchasesteps.SuccessStepWithAuthChoices.onClick(SuccessStepWithAuthChoices.java:5156)
This commit is contained in:
parent
e66daf0e4d
commit
878ba1eeec
|
@ -20,6 +20,7 @@ package eu.faircode.netguard;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
|
import android.app.PendingIntent;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
@ -259,20 +260,12 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
||||||
SinkholeService.start(this);
|
SinkholeService.start(this);
|
||||||
|
|
||||||
} else if (requestCode == REQUEST_IAB) {
|
} else if (requestCode == REQUEST_IAB) {
|
||||||
if (resultCode == RESULT_OK) {
|
// Handle IAB result
|
||||||
// Handle donation
|
Intent intent = new Intent(IAB.ACTION_IAB);
|
||||||
Intent intent = new Intent(IAB.ACTION_PURCHASED);
|
intent.putExtra("RESULT_CODE", resultCode);
|
||||||
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
|
if (data != null)
|
||||||
} else {
|
intent.putExtra("RESPONSE_CODE", data.getIntExtra("RESPONSE_CODE", -1));
|
||||||
int response = (data == null ? -1 : data.getIntExtra("RESPONSE_CODE", -1));
|
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
|
||||||
Log.i(TAG, "IAB response=" + IAB.getIABResult(response));
|
|
||||||
|
|
||||||
// Fail-safe
|
|
||||||
Intent donate = new Intent(Intent.ACTION_VIEW);
|
|
||||||
donate.setData(Uri.parse("http://www.netguard.me/"));
|
|
||||||
if (donate.resolveActivity(getPackageManager()) != null)
|
|
||||||
startActivity(donate);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (requestCode == REQUEST_INVITE) {
|
} else if (requestCode == REQUEST_INVITE) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
|
@ -470,15 +463,16 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
try {
|
try {
|
||||||
IntentSender sender = iab.getIntentSender();
|
PendingIntent pi = iab.getIntentSender();
|
||||||
if (sender == null) {
|
if (pi == null) {
|
||||||
Log.i(TAG, "Donate");
|
Log.i(TAG, "Donate");
|
||||||
Intent donate = new Intent(Intent.ACTION_VIEW);
|
Intent donate = new Intent(Intent.ACTION_VIEW);
|
||||||
donate.setData(Uri.parse("http://www.netguard.me/"));
|
donate.setData(Uri.parse("http://www.netguard.me/"));
|
||||||
startActivity(donate);
|
startActivity(donate);
|
||||||
} else {
|
} else {
|
||||||
|
btnDonate.setEnabled(false);
|
||||||
Log.i(TAG, "IAB donate");
|
Log.i(TAG, "IAB donate");
|
||||||
startIntentSenderForResult(sender, REQUEST_IAB, new Intent(), 0, 0, 0);
|
startIntentSenderForResult(pi.getIntentSender(), REQUEST_IAB, new Intent(), 0, 0, 0);
|
||||||
}
|
}
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
|
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
|
||||||
|
@ -486,24 +480,36 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Handle donated
|
// Handle IAB result
|
||||||
final BroadcastReceiver onIABPurchased = new BroadcastReceiver() {
|
final BroadcastReceiver onIABResult = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
Log.i(TAG, "IAB donated");
|
int resultCode = intent.getIntExtra("RESULT_CODE", RESULT_CANCELED);
|
||||||
|
int responseCode = intent.getIntExtra("RESPONSE_CODE", -1);
|
||||||
|
final boolean ok = (resultCode == RESULT_OK);
|
||||||
|
Log.i(TAG, "IAB result ok=" + ok + " response=" + IAB.getIABResult(responseCode));
|
||||||
|
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (running) {
|
if (running) {
|
||||||
btnDonate.setVisibility(View.GONE);
|
btnDonate.setEnabled(true);
|
||||||
tvThanks.setVisibility(View.VISIBLE);
|
if (ok) {
|
||||||
|
btnDonate.setVisibility(View.GONE);
|
||||||
|
tvThanks.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
Intent donate = new Intent(Intent.ACTION_VIEW);
|
||||||
|
donate.setData(Uri.parse("http://www.netguard.me/"));
|
||||||
|
if (donate.resolveActivity(getPackageManager()) != null)
|
||||||
|
startActivity(donate);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
IntentFilter iff = new IntentFilter(IAB.ACTION_PURCHASED);
|
IntentFilter iff = new IntentFilter(IAB.ACTION_IAB);
|
||||||
LocalBroadcastManager.getInstance(this).registerReceiver(onIABPurchased, iff);
|
LocalBroadcastManager.getInstance(this).registerReceiver(onIABResult, iff);
|
||||||
|
|
||||||
// Show dialog
|
// Show dialog
|
||||||
dialogAbout = new AlertDialog.Builder(this)
|
dialogAbout = new AlertDialog.Builder(this)
|
||||||
|
@ -513,7 +519,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
||||||
@Override
|
@Override
|
||||||
public void onDismiss(DialogInterface dialogInterface) {
|
public void onDismiss(DialogInterface dialogInterface) {
|
||||||
if (running)
|
if (running)
|
||||||
LocalBroadcastManager.getInstance(ActivityMain.this).unregisterReceiver(onIABPurchased);
|
LocalBroadcastManager.getInstance(ActivityMain.this).unregisterReceiver(onIABResult);
|
||||||
|
|
||||||
iab.unbind();
|
iab.unbind();
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ package eu.faircode.netguard;
|
||||||
Copyright 2015 by Marcel Bokhorst (M66B)
|
Copyright 2015 by Marcel Bokhorst (M66B)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
@ -50,7 +51,7 @@ public class IAB implements ServiceConnection {
|
||||||
// adb shell am start -n eu.faircode.netguard/eu.faircode.netguard.ActivityMain
|
// adb shell am start -n eu.faircode.netguard/eu.faircode.netguard.ActivityMain
|
||||||
private static final String SKU_DONATE = "donation";
|
private static final String SKU_DONATE = "donation";
|
||||||
// private static final String SKU_DONATE = "android.test.purchased";
|
// private static final String SKU_DONATE = "android.test.purchased";
|
||||||
public static final String ACTION_PURCHASED = "eu.faircode.netguard.IAB";
|
public static final String ACTION_IAB = "eu.faircode.netguard.IAB";
|
||||||
|
|
||||||
public IAB(Context context) {
|
public IAB(Context context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
@ -63,8 +64,8 @@ public class IAB implements ServiceConnection {
|
||||||
context.bindService(serviceIntent, this, Context.BIND_AUTO_CREATE);
|
context.bindService(serviceIntent, this, Context.BIND_AUTO_CREATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IntentSender getIntentSender() throws RemoteException {
|
public PendingIntent getIntentSender() throws RemoteException {
|
||||||
return (service != null && available ? IABgetIntent(SKU_DONATE) : null);
|
return (service != null && available ? IABgetBuyIntent(SKU_DONATE) : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unbind() {
|
public void unbind() {
|
||||||
|
@ -82,7 +83,8 @@ public class IAB implements ServiceConnection {
|
||||||
service = IInAppBillingService.Stub.asInterface(binder);
|
service = IInAppBillingService.Stub.asInterface(binder);
|
||||||
|
|
||||||
if (IABisPurchased(SKU_DONATE)) {
|
if (IABisPurchased(SKU_DONATE)) {
|
||||||
Intent intent = new Intent(ACTION_PURCHASED);
|
Intent intent = new Intent(ACTION_IAB);
|
||||||
|
intent.putExtra("RESULT_CODE", Activity.RESULT_OK);
|
||||||
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
|
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
|
||||||
} else
|
} else
|
||||||
available = (service != null && IABisAvailable(SKU_DONATE));
|
available = (service != null && IABisAvailable(SKU_DONATE));
|
||||||
|
@ -144,16 +146,15 @@ public class IAB implements ServiceConnection {
|
||||||
return (skus != null && skus.contains(sku));
|
return (skus != null && skus.contains(sku));
|
||||||
}
|
}
|
||||||
|
|
||||||
private IntentSender IABgetIntent(String sku) throws RemoteException {
|
private PendingIntent IABgetBuyIntent(String sku) throws RemoteException {
|
||||||
Bundle bundle = service.getBuyIntent(IAB_VERSION, context.getPackageName(), sku, "inapp", "");
|
Bundle bundle = service.getBuyIntent(IAB_VERSION, context.getPackageName(), sku, "inapp", "netguard");
|
||||||
Log.i(TAG, "getBuyIntent");
|
Log.i(TAG, "getBuyIntent");
|
||||||
Util.logBundle(TAG, bundle);
|
Util.logBundle(TAG, bundle);
|
||||||
int response = (bundle == null ? -1 : bundle.getInt("RESPONSE_CODE", -1));
|
int response = (bundle == null ? -1 : bundle.getInt("RESPONSE_CODE", -1));
|
||||||
Log.i(TAG, "Response=" + getIABResult(response));
|
Log.i(TAG, "Response=" + getIABResult(response));
|
||||||
if (response != 0 || !bundle.containsKey("BUY_INTENT"))
|
if (response != 0 || !bundle.containsKey("BUY_INTENT"))
|
||||||
return null;
|
return null;
|
||||||
PendingIntent pi = bundle.getParcelable("BUY_INTENT");
|
return bundle.getParcelable("BUY_INTENT");
|
||||||
return (pi == null ? null : pi.getIntentSender());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getIABResult(int responseCode) {
|
public static String getIABResult(int responseCode) {
|
||||||
|
|
Loading…
Reference in New Issue