From 678948068bbde7f12a9c5f28a467b6cf4d127851 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Fri, 1 Aug 2014 22:10:38 -0300 Subject: Small Issues & Maintenance -=-=-=-=-=-=-=-=-=-=-=-=-= -Begin work on Navigation Meshes (simple pathfinding for now, will improve soon) -More doc on theme overriding -Upgraded OpenSSL to version without bugs -Misc bugfixes --- .../android/java/src/com/android/godot/Godot.java | 380 +++++++++++++++++---- .../godot/GodotDownloaderAlarmReceiver.java | 3 + .../com/android/godot/GodotDownloaderService.java | 13 +- .../java/src/com/android/godot/GodotPaymentV3.java | 32 +- .../android/godot/payments/GenericConsumeTask.java | 53 +++ .../android/godot/payments/HandlePurchaseTask.java | 4 +- .../android/godot/payments/PaymentsManager.java | 41 ++- .../com/android/godot/payments/PurchaseTask.java | 26 +- .../godot/payments/ReleaseAllConsumablesTask.java | 87 +++++ 9 files changed, 537 insertions(+), 102 deletions(-) create mode 100644 platform/android/java/src/com/android/godot/payments/GenericConsumeTask.java create mode 100644 platform/android/java/src/com/android/godot/payments/ReleaseAllConsumablesTask.java (limited to 'platform/android/java/src/com') diff --git a/platform/android/java/src/com/android/godot/Godot.java b/platform/android/java/src/com/android/godot/Godot.java index 658c272321..57b0943a85 100644 --- a/platform/android/java/src/com/android/godot/Godot.java +++ b/platform/android/java/src/com/android/godot/Godot.java @@ -28,16 +28,20 @@ /*************************************************************************/ package com.android.godot; +import android.R; import android.app.Activity; import android.os.Bundle; import android.view.MotionEvent; +import android.view.View; +import android.widget.Button; +import android.widget.ProgressBar; import android.widget.RelativeLayout; import android.widget.LinearLayout; +import android.widget.TextView; import android.view.ViewGroup.LayoutParams; - - import android.app.*; import android.content.*; +import android.content.SharedPreferences.Editor; import android.view.*; import android.view.inputmethod.InputMethodManager; import android.os.*; @@ -48,33 +52,82 @@ import android.text.*; import android.media.*; import android.hardware.*; import android.content.*; - +import android.content.pm.PackageManager.NameNotFoundException; import android.net.Uri; import android.media.MediaPlayer; import java.lang.reflect.Method; import java.util.List; import java.util.ArrayList; + import com.android.godot.payments.PaymentsManager; + import java.io.IOException; + import android.provider.Settings.Secure; import android.widget.FrameLayout; + import com.android.godot.input.*; -import java.io.InputStream; +import java.io.InputStream; import javax.microedition.khronos.opengles.GL10; import java.security.MessageDigest; import java.io.File; import java.io.FileInputStream; import java.util.LinkedList; -public class Godot extends Activity implements SensorEventListener +import com.google.android.vending.expansion.downloader.Constants; +import com.google.android.vending.expansion.downloader.DownloadProgressInfo; +import com.google.android.vending.expansion.downloader.DownloaderClientMarshaller; +import com.google.android.vending.expansion.downloader.DownloaderServiceMarshaller; +import com.google.android.vending.expansion.downloader.Helpers; +import com.google.android.vending.expansion.downloader.IDownloaderClient; +import com.google.android.vending.expansion.downloader.IDownloaderService; +import com.google.android.vending.expansion.downloader.IStub; + +import android.os.Bundle; +import android.os.Messenger; +import android.os.SystemClock; + + +public class Godot extends Activity implements SensorEventListener, IDownloaderClient { static final int MAX_SINGLETONS = 64; - + private IStub mDownloaderClientStub; + private IDownloaderService mRemoteService; + private TextView mStatusText; + private TextView mProgressFraction; + private TextView mProgressPercent; + private TextView mAverageSpeed; + private TextView mTimeRemaining; + private ProgressBar mPB; + + private View mDashboard; + private View mCellMessage; + + private Button mPauseButton; + private Button mWiFiSettingsButton; + + private boolean mStatePaused; + private int mState; + + private void setState(int newState) { + if (mState != newState) { + mState = newState; + mStatusText.setText(Helpers.getDownloaderStringResourceIDFromState(newState)); + } + } + + private void setButtonPausedState(boolean paused) { + mStatePaused = paused; + int stringResourceID = paused ? com.godot.game.R.string.text_button_resume : + com.godot.game.R.string.text_button_pause; + mPauseButton.setText(stringResourceID); + } + static public class SingletonBase { - + protected void registerClass(String p_name, String[] p_methods) { GodotLib.singleton(p_name,this); @@ -83,20 +136,20 @@ public class Godot extends Activity implements SensorEventListener Method[] methods = clazz.getDeclaredMethods(); for (Method method : methods) { boolean found=false; - System.out.printf("METHOD: %s\n",method.getName()); + Log.d("XXX","METHOD: %s\n" + method.getName()); for (String s : p_methods) { - System.out.printf("METHOD CMP WITH: %s\n",s); + Log.d("XXX", "METHOD CMP WITH: %s\n" + s); if (s.equals(method.getName())) { found=true; - System.out.printf("METHOD CMP VALID"); + Log.d("XXX","METHOD CMP VALID"); break; } } if (!found) continue; - System.out.printf("METHOD FOUND: %s\n",method.getName()); + Log.d("XXX","METHOD FOUND: %s\n" + method.getName()); List ptr = new ArrayList(); @@ -230,7 +283,7 @@ public class Godot extends Activity implements SensorEventListener byte[] len = new byte[4]; int r = is.read(len); if (r<4) { - System.out.printf("**ERROR** Wrong cmdline length.\n"); + Log.d("XXX","**ERROR** Wrong cmdline length.\n"); Log.d("GODOT", "**ERROR** Wrong cmdline length.\n"); return new String[0]; } @@ -258,7 +311,6 @@ public class Godot extends Activity implements SensorEventListener return cmdline; } catch (Exception e) { e.printStackTrace(); - System.out.printf("**ERROR** No commandline.\n"); Log.d("GODOT", "**ERROR** Exception " + e.getClass().getName() + ":" + e.getMessage()); return new String[0]; } @@ -277,12 +329,14 @@ public class Godot extends Activity implements SensorEventListener String[] new_cmdline; int cll=0; if (command_line!=null) { + Log.d("GODOT", "initializeGodot: command_line: is not null" ); new_cmdline = new String[ command_line.length + 2 ]; cll=command_line.length; for(int i=0;i 0) { - complete.update(buffer, 0, numRead); - } - } while (numRead != -1); - - - fis.close(); - byte[] messageDigest = complete.digest(); - - // Create Hex String - StringBuffer hexString = new StringBuffer(); - for (int i=0; i 0) { + complete.update(buffer, 0, numRead); + } + } while (numRead != -1); + + + fis.close(); + byte[] messageDigest = complete.digest(); + + // Create Hex String + StringBuffer hexString = new StringBuffer(); + for (int i=0; i> 8)); + mPB.setProgress((int) (progress.mOverallProgress >> 8)); + mProgressPercent.setText(Long.toString(progress.mOverallProgress + * 100 / + progress.mOverallTotal) + "%"); + mProgressFraction.setText(Helpers.getDownloadProgressString + (progress.mOverallProgress, + progress.mOverallTotal)); + + } + } diff --git a/platform/android/java/src/com/android/godot/GodotDownloaderAlarmReceiver.java b/platform/android/java/src/com/android/godot/GodotDownloaderAlarmReceiver.java index d945a8b192..e82c3eb0fe 100644 --- a/platform/android/java/src/com/android/godot/GodotDownloaderAlarmReceiver.java +++ b/platform/android/java/src/com/android/godot/GodotDownloaderAlarmReceiver.java @@ -6,6 +6,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager.NameNotFoundException; +import android.util.Log; /** * You should start your derived downloader class when this receiver gets the message @@ -18,10 +19,12 @@ public class GodotDownloaderAlarmReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { + Log.d("GODOT", "Alarma recivida"); try { DownloaderClientMarshaller.startDownloadServiceIfRequired(context, intent, GodotDownloaderService.class); } catch (NameNotFoundException e) { e.printStackTrace(); + Log.d("GODOT", "Exception: " + e.getClass().getName() + ":" + e.getMessage()); } } } diff --git a/platform/android/java/src/com/android/godot/GodotDownloaderService.java b/platform/android/java/src/com/android/godot/GodotDownloaderService.java index e0fe95ad96..2657edc1d2 100644 --- a/platform/android/java/src/com/android/godot/GodotDownloaderService.java +++ b/platform/android/java/src/com/android/godot/GodotDownloaderService.java @@ -1,5 +1,9 @@ package com.android.godot; +import android.content.Context; +import android.content.SharedPreferences; +import android.util.Log; + import com.google.android.vending.expansion.downloader.impl.DownloaderService; /** @@ -21,7 +25,11 @@ public class GodotDownloaderService extends DownloaderService { */ @Override public String getPublicKey() { - return BASE64_PUBLIC_KEY; + SharedPreferences prefs = getApplicationContext().getSharedPreferences("app_data_keys", Context.MODE_PRIVATE); + Log.d("GODOT", "getting public key:" + prefs.getString("store_public_key", null)); + return prefs.getString("store_public_key", null); + +// return BASE64_PUBLIC_KEY; } /** @@ -41,7 +49,8 @@ public class GodotDownloaderService extends DownloaderService { */ @Override public String getAlarmReceiverClassName() { - return GodotDownloaderAlarmReceiver.class.getName(); + Log.d("GODOT", "getAlarmReceiverClassName()"); + return GodotDownloaderAlarmReceiver.class.getName(); } } diff --git a/platform/android/java/src/com/android/godot/GodotPaymentV3.java b/platform/android/java/src/com/android/godot/GodotPaymentV3.java index dba4a9a774..a459f8e15c 100644 --- a/platform/android/java/src/com/android/godot/GodotPaymentV3.java +++ b/platform/android/java/src/com/android/godot/GodotPaymentV3.java @@ -1,8 +1,6 @@ package com.android.godot; - -import org.json.JSONObject; - +import com.android.godot.Dictionary; import android.app.Activity; import android.util.Log; @@ -44,10 +42,20 @@ public class GodotPaymentV3 extends Godot.SingletonBase { public GodotPaymentV3(Activity p_activity) { - registerClass("GodotPayments", new String[] {"purchase", "setPurchaseCallbackId", "setPurchaseValidationUrlPrefix", "setTransactionId", "getSignature"}); + registerClass("GodotPayments", new String[] {"purchase", "setPurchaseCallbackId", "setPurchaseValidationUrlPrefix", "setTransactionId", "getSignature", "consumeUnconsumedPurchases"}); activity=(Godot) p_activity; } + public void consumeUnconsumedPurchases(){ + activity.getPaymentsManager().setBaseSingleton(this); + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + activity.getPaymentsManager().consumeUnconsumedPurchases(); + } + }); + + } private String signature; public String getSignature(){ @@ -56,9 +64,19 @@ public class GodotPaymentV3 extends Godot.SingletonBase { public void callbackSuccess(String ticket, String signature){ - Log.d(this.getClass().getName(), "PRE-Send callback to purchase success"); - GodotLib.calldeferred(purchaseCallbackId, "purchase_success", new Object[]{ticket, signature}); - Log.d(this.getClass().getName(), "POST-Send callback to purchase success"); + Log.d(this.getClass().getName(), "PRE-Send callback to purchase success"); + GodotLib.callobject(purchaseCallbackId, "purchase_success", new Object[]{ticket, signature}); + Log.d(this.getClass().getName(), "POST-Send callback to purchase success"); +} + + public void callbackSuccessProductMassConsumed(String ticket, String signature, String sku){ + Log.d(this.getClass().getName(), "PRE-Send callback to consume success"); + GodotLib.calldeferred(purchaseCallbackId, "consume_success", new Object[]{ticket, signature, sku}); + Log.d(this.getClass().getName(), "POST-Send callback to consume success"); + } + + public void callbackSuccessNoUnconsumedPurchases(){ + GodotLib.calldeferred(purchaseCallbackId, "no_validation_required", new Object[]{}); } public void callbackFail(){ diff --git a/platform/android/java/src/com/android/godot/payments/GenericConsumeTask.java b/platform/android/java/src/com/android/godot/payments/GenericConsumeTask.java new file mode 100644 index 0000000000..88cf28798e --- /dev/null +++ b/platform/android/java/src/com/android/godot/payments/GenericConsumeTask.java @@ -0,0 +1,53 @@ +package com.android.godot.payments; + +import com.android.vending.billing.IInAppBillingService; + +import android.content.Context; +import android.os.AsyncTask; +import android.os.RemoteException; +import android.util.Log; + +abstract public class GenericConsumeTask extends AsyncTask{ + + private Context context; + private IInAppBillingService mService; + + + + + public GenericConsumeTask(Context context, IInAppBillingService mService, String sku, String receipt, String signature, String token){ + this.context = context; + this.mService = mService; + this.sku = sku; + this.receipt = receipt; + this.signature = signature; + this.token = token; + } + + private String sku; + private String receipt; + private String signature; + private String token; + + @Override + protected String doInBackground(String... params) { + try { + Log.d("godot", "Requesting to consume an item with token ." + token); + int response = mService.consumePurchase(3, context.getPackageName(), token); + Log.d("godot", "consumePurchase response: " + response); + if(response == 0 || response == 8){ + return null; + } + } catch (Exception e) { + Log.d("godot", "Error " + e.getClass().getName() + ":" + e.getMessage()); + } + return null; + } + + protected void onPostExecute(String sarasa){ + onSuccess(sku, receipt, signature, token); + } + + abstract public void onSuccess(String sku, String receipt, String signature, String token); + +} diff --git a/platform/android/java/src/com/android/godot/payments/HandlePurchaseTask.java b/platform/android/java/src/com/android/godot/payments/HandlePurchaseTask.java index a810ac40ae..24eec9f30b 100644 --- a/platform/android/java/src/com/android/godot/payments/HandlePurchaseTask.java +++ b/platform/android/java/src/com/android/godot/payments/HandlePurchaseTask.java @@ -64,7 +64,7 @@ abstract public class HandlePurchaseTask { pc.setConsumableFlag("block", productId, true); pc.setConsumableValue("token", productId, purchaseToken); - success(productId, dataSignature); + success(productId, dataSignature, purchaseData); return; } catch (JSONException e) { error(e.getMessage()); @@ -74,7 +74,7 @@ abstract public class HandlePurchaseTask { } } - abstract protected void success(String ticket, String signature); + abstract protected void success(String sku, String signature, String ticket); abstract protected void error(String message); abstract protected void canceled(); diff --git a/platform/android/java/src/com/android/godot/payments/PaymentsManager.java b/platform/android/java/src/com/android/godot/payments/PaymentsManager.java index d85a8ea8ea..fd1a62738a 100644 --- a/platform/android/java/src/com/android/godot/payments/PaymentsManager.java +++ b/platform/android/java/src/com/android/godot/payments/PaymentsManager.java @@ -1,5 +1,9 @@ package com.android.godot.payments; +import java.util.ArrayList; +import java.util.List; + +import android.os.RemoteException; import android.app.Activity; import android.content.ComponentName; import android.content.Context; @@ -7,7 +11,13 @@ import android.content.Intent; import android.content.ServiceConnection; import android.os.IBinder; import android.util.Log; +import android.os.Bundle; + +import org.json.JSONException; +import org.json.JSONObject; +import org.json.JSONStringer; +import com.android.godot.Dictionary; import com.android.godot.Godot; import com.android.godot.GodotPaymentV3; import com.android.vending.billing.IInAppBillingService; @@ -23,7 +33,6 @@ public class PaymentsManager { private Activity activity; IInAppBillingService mService; - public void setActivity(Activity activity){ this.activity = activity; } @@ -81,18 +90,39 @@ public class PaymentsManager { } + public void consumeUnconsumedPurchases(){ + new ReleaseAllConsumablesTask(mService, activity) { + + @Override + protected void success(String sku, String receipt, String signature, String token) { + godotPaymentV3.callbackSuccessProductMassConsumed(receipt, signature, sku); + } + + @Override + protected void error(String message) { + godotPaymentV3.callbackFail(); + + } + + @Override + protected void notRequired() { + godotPaymentV3.callbackSuccessNoUnconsumedPurchases(); + + } + }.consumeItAll(); + } + public void processPurchaseResponse(int resultCode, Intent data) { new HandlePurchaseTask(activity){ @Override - protected void success(final String sku, final String signature) { + protected void success(final String sku, final String signature, final String ticket) { + godotPaymentV3.callbackSuccess(ticket, signature); new ConsumeTask(mService, activity) { @Override protected void success(String ticket) { // godotPaymentV3.callbackSuccess(""); - Log.d("XXX", "calling success:" + signature); - godotPaymentV3.callbackSuccess(ticket, signature); } @Override @@ -103,7 +133,7 @@ public class PaymentsManager { }.consume(sku); - +// godotPaymentV3.callbackSuccess(new PaymentsCache(activity).getConsumableValue("ticket", sku),signature); // godotPaymentV3.callbackSuccess(ticket); //validatePurchase(purchaseToken, sku); } @@ -166,5 +196,6 @@ public class PaymentsManager { this.godotPaymentV3 = godotPaymentV3; } + } diff --git a/platform/android/java/src/com/android/godot/payments/PurchaseTask.java b/platform/android/java/src/com/android/godot/payments/PurchaseTask.java index 0856b4e900..75662a442e 100644 --- a/platform/android/java/src/com/android/godot/payments/PurchaseTask.java +++ b/platform/android/java/src/com/android/godot/payments/PurchaseTask.java @@ -64,31 +64,7 @@ abstract public class PurchaseTask { canceled(); return ; } - if(responseCode == 7){ - new ConsumeTask(mService, context) { - - @Override - protected void success(String ticket) { -// Log.d("XXX", "Product was erroniously purchased!"); - if(isLooping){ -// Log.d("XXX", "It is looping"); - error("Error while purchasing product"); - return; - } - isLooping=true; - PurchaseTask.this.purchase(sku, transactionId); - - } - - @Override - protected void error(String message) { - PurchaseTask.this.error(message); - - } - }.consume(sku); - return; - } - + PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT"); pc.setConsumableValue("validation_hash", sku, hash); diff --git a/platform/android/java/src/com/android/godot/payments/ReleaseAllConsumablesTask.java b/platform/android/java/src/com/android/godot/payments/ReleaseAllConsumablesTask.java new file mode 100644 index 0000000000..2f590a4e68 --- /dev/null +++ b/platform/android/java/src/com/android/godot/payments/ReleaseAllConsumablesTask.java @@ -0,0 +1,87 @@ +package com.android.godot.payments; + +import java.util.ArrayList; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.android.godot.Dictionary; +import com.android.godot.Godot; +import com.android.vending.billing.IInAppBillingService; + +import android.content.Context; +import android.os.AsyncTask; +import android.os.Bundle; +import android.os.RemoteException; +import android.util.Log; + +abstract public class ReleaseAllConsumablesTask { + + private Context context; + private IInAppBillingService mService; + + public ReleaseAllConsumablesTask(IInAppBillingService mService, Context context ){ + this.context = context; + this.mService = mService; + } + + + public void consumeItAll(){ + try{ + Log.d("godot", "consumeItall for " + context.getPackageName()); + Bundle bundle = mService.getPurchases(3, context.getPackageName(), "inapp",null); + + for (String key : bundle.keySet()) { + Object value = bundle.get(key); + Log.d("godot", String.format("%s %s (%s)", key, + value.toString(), value.getClass().getName())); + } + + + if (bundle.getInt("RESPONSE_CODE") == 0){ + + final ArrayList myPurchases = bundle.getStringArrayList("INAPP_PURCHASE_DATA_LIST"); + final ArrayList mySignatures = bundle.getStringArrayList("INAPP_DATA_SIGNATURE_LIST"); + + + if (myPurchases == null || myPurchases.size() == 0){ + Log.d("godot", "No purchases!"); + notRequired(); + return; + } + + + Log.d("godot", "# products to be consumed:" + myPurchases.size()); + for (int i=0;i