|
|
@ -19,7 +19,6 @@ import com.android.vending.billing.IMarketBillingService;
|
|
|
|
import com.todoroo.astrid.billing.BillingConstants.PurchaseState;
|
|
|
|
import com.todoroo.astrid.billing.BillingConstants.PurchaseState;
|
|
|
|
import com.todoroo.astrid.billing.BillingConstants.ResponseCode;
|
|
|
|
import com.todoroo.astrid.billing.BillingConstants.ResponseCode;
|
|
|
|
import com.todoroo.astrid.billing.Security.VerifiedPurchase;
|
|
|
|
import com.todoroo.astrid.billing.Security.VerifiedPurchase;
|
|
|
|
import com.todoroo.astrid.utility.Constants;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("nls")
|
|
|
|
@SuppressWarnings("nls")
|
|
|
|
public class BillingService extends Service implements ServiceConnection {
|
|
|
|
public class BillingService extends Service implements ServiceConnection {
|
|
|
@ -86,13 +85,13 @@ public class BillingService extends Service implements ServiceConnection {
|
|
|
|
* is not connected or there was an error when trying to use it
|
|
|
|
* is not connected or there was an error when trying to use it
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public boolean runIfConnected() {
|
|
|
|
public boolean runIfConnected() {
|
|
|
|
if (Constants.DEBUG) {
|
|
|
|
if (BillingConstants.DEBUG) {
|
|
|
|
Log.d(TAG, getClass().getSimpleName());
|
|
|
|
Log.d(TAG, getClass().getSimpleName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mService != null) {
|
|
|
|
if (mService != null) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
mRequestId = run();
|
|
|
|
mRequestId = run();
|
|
|
|
if (Constants.DEBUG) {
|
|
|
|
if (BillingConstants.DEBUG) {
|
|
|
|
Log.d(TAG, "request id: " + mRequestId);
|
|
|
|
Log.d(TAG, "request id: " + mRequestId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mRequestId >= 0) {
|
|
|
|
if (mRequestId >= 0) {
|
|
|
@ -143,7 +142,7 @@ public class BillingService extends Service implements ServiceConnection {
|
|
|
|
protected void logResponseCode(String method, Bundle response) {
|
|
|
|
protected void logResponseCode(String method, Bundle response) {
|
|
|
|
ResponseCode responseCode = ResponseCode.valueOf(
|
|
|
|
ResponseCode responseCode = ResponseCode.valueOf(
|
|
|
|
response.getInt(BillingConstants.BILLING_RESPONSE_RESPONSE_CODE));
|
|
|
|
response.getInt(BillingConstants.BILLING_RESPONSE_RESPONSE_CODE));
|
|
|
|
if (Constants.DEBUG) {
|
|
|
|
if (BillingConstants.DEBUG) {
|
|
|
|
Log.e(TAG, method + " received " + responseCode.toString());
|
|
|
|
Log.e(TAG, method + " received " + responseCode.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -198,7 +197,7 @@ public class BillingService extends Service implements ServiceConnection {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Bundle response = mService.sendBillingRequest(request);
|
|
|
|
Bundle response = mService.sendBillingRequest(request);
|
|
|
|
int responseCode = response.getInt(BillingConstants.BILLING_RESPONSE_RESPONSE_CODE);
|
|
|
|
int responseCode = response.getInt(BillingConstants.BILLING_RESPONSE_RESPONSE_CODE);
|
|
|
|
if (Constants.DEBUG) {
|
|
|
|
if (BillingConstants.DEBUG) {
|
|
|
|
Log.i(TAG, "CheckBillingSupported response code: " +
|
|
|
|
Log.i(TAG, "CheckBillingSupported response code: " +
|
|
|
|
ResponseCode.valueOf(responseCode));
|
|
|
|
ResponseCode.valueOf(responseCode));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -406,7 +405,7 @@ public class BillingService extends Service implements ServiceConnection {
|
|
|
|
if (intent == null)
|
|
|
|
if (intent == null)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
String action = intent.getAction();
|
|
|
|
String action = intent.getAction();
|
|
|
|
if (Constants.DEBUG) {
|
|
|
|
if (BillingConstants.DEBUG) {
|
|
|
|
Log.i(TAG, "handleCommand() action: " + action);
|
|
|
|
Log.i(TAG, "handleCommand() action: " + action);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (BillingConstants.ACTION_CONFIRM_NOTIFICATION.equals(action)) {
|
|
|
|
if (BillingConstants.ACTION_CONFIRM_NOTIFICATION.equals(action)) {
|
|
|
@ -435,7 +434,7 @@ public class BillingService extends Service implements ServiceConnection {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private boolean bindToMarketBillingService() {
|
|
|
|
private boolean bindToMarketBillingService() {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (Constants.DEBUG) {
|
|
|
|
if (BillingConstants.DEBUG) {
|
|
|
|
Log.i(TAG, "binding to Market billing service");
|
|
|
|
Log.i(TAG, "binding to Market billing service");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
boolean bindResult = bindService(
|
|
|
|
boolean bindResult = bindService(
|
|
|
@ -576,7 +575,7 @@ public class BillingService extends Service implements ServiceConnection {
|
|
|
|
private void checkResponseCode(long requestId, ResponseCode responseCode) {
|
|
|
|
private void checkResponseCode(long requestId, ResponseCode responseCode) {
|
|
|
|
BillingRequest request = mSentRequests.get(requestId);
|
|
|
|
BillingRequest request = mSentRequests.get(requestId);
|
|
|
|
if (request != null) {
|
|
|
|
if (request != null) {
|
|
|
|
if (Constants.DEBUG) {
|
|
|
|
if (BillingConstants.DEBUG) {
|
|
|
|
Log.d(TAG, request.getClass().getSimpleName() + ": " + responseCode);
|
|
|
|
Log.d(TAG, request.getClass().getSimpleName() + ": " + responseCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
request.responseCodeReceived(responseCode);
|
|
|
|
request.responseCodeReceived(responseCode);
|
|
|
@ -613,7 +612,7 @@ public class BillingService extends Service implements ServiceConnection {
|
|
|
|
// is not -1, then one of the requests started the service, so we can
|
|
|
|
// is not -1, then one of the requests started the service, so we can
|
|
|
|
// stop it now.
|
|
|
|
// stop it now.
|
|
|
|
if (maxStartId >= 0) {
|
|
|
|
if (maxStartId >= 0) {
|
|
|
|
if (Constants.DEBUG) {
|
|
|
|
if (BillingConstants.DEBUG) {
|
|
|
|
Log.i(TAG, "stopping service, startId: " + maxStartId);
|
|
|
|
Log.i(TAG, "stopping service, startId: " + maxStartId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stopSelf(maxStartId);
|
|
|
|
stopSelf(maxStartId);
|
|
|
@ -626,7 +625,7 @@ public class BillingService extends Service implements ServiceConnection {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onServiceConnected(ComponentName name, IBinder service) {
|
|
|
|
public void onServiceConnected(ComponentName name, IBinder service) {
|
|
|
|
if (Constants.DEBUG) {
|
|
|
|
if (BillingConstants.DEBUG) {
|
|
|
|
Log.d(TAG, "Billing service connected");
|
|
|
|
Log.d(TAG, "Billing service connected");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mService = IMarketBillingService.Stub.asInterface(service);
|
|
|
|
mService = IMarketBillingService.Stub.asInterface(service);
|
|
|
|