| 1 |
diff --git a/platform/android/java/src/com/google/android/vending/expansion/downloader/DownloaderClientMarshaller.java b/platform/android/java/src/com/google/android/vending/expansion/downloader/DownloaderClientMarshaller.java |
| 2 |
index ad6ea0de6..452c7d148 100644 |
| 3 |
--- a/platform/android/java/src/com/google/android/vending/expansion/downloader/DownloaderClientMarshaller.java |
| 4 |
+++ b/platform/android/java/src/com/google/android/vending/expansion/downloader/DownloaderClientMarshaller.java |
| 5 |
@@ -32,6 +32,9 @@ import android.os.Messenger; |
| 6 |
import android.os.RemoteException; |
| 7 |
import android.util.Log; |
| 8 |
|
| 9 |
+// -- GODOT start -- |
| 10 |
+import java.lang.ref.WeakReference; |
| 11 |
+// -- GODOT end -- |
| 12 |
|
| 13 |
|
| 14 |
/** |
| 15 |
@@ -118,29 +121,46 @@ public class DownloaderClientMarshaller { |
| 16 |
/** |
| 17 |
* Target we publish for clients to send messages to IncomingHandler. |
| 18 |
*/ |
| 19 |
- final Messenger mMessenger = new Messenger(new Handler() { |
| 20 |
+ // -- GODOT start -- |
| 21 |
+ private final MessengerHandlerClient mMsgHandler = new MessengerHandlerClient(this); |
| 22 |
+ final Messenger mMessenger = new Messenger(mMsgHandler); |
| 23 |
+ |
| 24 |
+ private static class MessengerHandlerClient extends Handler { |
| 25 |
+ private final WeakReference<Stub> mDownloader; |
| 26 |
+ public MessengerHandlerClient(Stub downloader) { |
| 27 |
+ mDownloader = new WeakReference<>(downloader); |
| 28 |
+ } |
| 29 |
+ |
| 30 |
@Override |
| 31 |
public void handleMessage(Message msg) { |
| 32 |
- switch (msg.what) { |
| 33 |
- case MSG_ONDOWNLOADPROGRESS: |
| 34 |
- Bundle bun = msg.getData(); |
| 35 |
- if ( null != mContext ) { |
| 36 |
- bun.setClassLoader(mContext.getClassLoader()); |
| 37 |
- DownloadProgressInfo dpi = (DownloadProgressInfo) msg.getData() |
| 38 |
- .getParcelable(PARAM_PROGRESS); |
| 39 |
- mItf.onDownloadProgress(dpi); |
| 40 |
- } |
| 41 |
- break; |
| 42 |
- case MSG_ONDOWNLOADSTATE_CHANGED: |
| 43 |
- mItf.onDownloadStateChanged(msg.getData().getInt(PARAM_NEW_STATE)); |
| 44 |
- break; |
| 45 |
- case MSG_ONSERVICECONNECTED: |
| 46 |
- mItf.onServiceConnected( |
| 47 |
- (Messenger) msg.getData().getParcelable(PARAM_MESSENGER)); |
| 48 |
- break; |
| 49 |
+ Stub downloader = mDownloader.get(); |
| 50 |
+ if (downloader != null) { |
| 51 |
+ downloader.handleMessage(msg); |
| 52 |
} |
| 53 |
} |
| 54 |
- }); |
| 55 |
+ } |
| 56 |
+ |
| 57 |
+ private void handleMessage(Message msg) { |
| 58 |
+ switch (msg.what) { |
| 59 |
+ case MSG_ONDOWNLOADPROGRESS: |
| 60 |
+ Bundle bun = msg.getData(); |
| 61 |
+ if (null != mContext) { |
| 62 |
+ bun.setClassLoader(mContext.getClassLoader()); |
| 63 |
+ DownloadProgressInfo dpi = (DownloadProgressInfo)msg.getData() |
| 64 |
+ .getParcelable(PARAM_PROGRESS); |
| 65 |
+ mItf.onDownloadProgress(dpi); |
| 66 |
+ } |
| 67 |
+ break; |
| 68 |
+ case MSG_ONDOWNLOADSTATE_CHANGED: |
| 69 |
+ mItf.onDownloadStateChanged(msg.getData().getInt(PARAM_NEW_STATE)); |
| 70 |
+ break; |
| 71 |
+ case MSG_ONSERVICECONNECTED: |
| 72 |
+ mItf.onServiceConnected( |
| 73 |
+ (Messenger)msg.getData().getParcelable(PARAM_MESSENGER)); |
| 74 |
+ break; |
| 75 |
+ } |
| 76 |
+ } |
| 77 |
+ // -- GODOT end -- |
| 78 |
|
| 79 |
public Stub(IDownloaderClient itf, Class<?> downloaderService) { |
| 80 |
mItf = itf; |
| 81 |
diff --git a/platform/android/java/src/com/google/android/vending/expansion/downloader/DownloaderServiceMarshaller.java b/platform/android/java/src/com/google/android/vending/expansion/downloader/DownloaderServiceMarshaller.java |
| 82 |
index 979352299..3771d19c9 100644 |
| 83 |
--- a/platform/android/java/src/com/google/android/vending/expansion/downloader/DownloaderServiceMarshaller.java |
| 84 |
+++ b/platform/android/java/src/com/google/android/vending/expansion/downloader/DownloaderServiceMarshaller.java |
| 85 |
@@ -25,6 +25,9 @@ import android.os.Message; |
| 86 |
import android.os.Messenger; |
| 87 |
import android.os.RemoteException; |
| 88 |
|
| 89 |
+// -- GODOT start -- |
| 90 |
+import java.lang.ref.WeakReference; |
| 91 |
+// -- GODOT end -- |
| 92 |
|
| 93 |
|
| 94 |
/** |
| 95 |
@@ -108,32 +111,49 @@ public class DownloaderServiceMarshaller { |
| 96 |
|
| 97 |
private static class Stub implements IStub { |
| 98 |
private IDownloaderService mItf = null; |
| 99 |
- final Messenger mMessenger = new Messenger(new Handler() { |
| 100 |
+ // -- GODOT start -- |
| 101 |
+ private final MessengerHandlerServer mMsgHandler = new MessengerHandlerServer(this); |
| 102 |
+ final Messenger mMessenger = new Messenger(mMsgHandler); |
| 103 |
+ |
| 104 |
+ private static class MessengerHandlerServer extends Handler { |
| 105 |
+ private final WeakReference<Stub> mDownloader; |
| 106 |
+ public MessengerHandlerServer(Stub downloader) { |
| 107 |
+ mDownloader = new WeakReference<>(downloader); |
| 108 |
+ } |
| 109 |
+ |
| 110 |
@Override |
| 111 |
public void handleMessage(Message msg) { |
| 112 |
- switch (msg.what) { |
| 113 |
- case MSG_REQUEST_ABORT_DOWNLOAD: |
| 114 |
- mItf.requestAbortDownload(); |
| 115 |
- break; |
| 116 |
- case MSG_REQUEST_CONTINUE_DOWNLOAD: |
| 117 |
- mItf.requestContinueDownload(); |
| 118 |
- break; |
| 119 |
- case MSG_REQUEST_PAUSE_DOWNLOAD: |
| 120 |
- mItf.requestPauseDownload(); |
| 121 |
- break; |
| 122 |
- case MSG_SET_DOWNLOAD_FLAGS: |
| 123 |
- mItf.setDownloadFlags(msg.getData().getInt(PARAMS_FLAGS)); |
| 124 |
- break; |
| 125 |
- case MSG_REQUEST_DOWNLOAD_STATE: |
| 126 |
- mItf.requestDownloadStatus(); |
| 127 |
- break; |
| 128 |
- case MSG_REQUEST_CLIENT_UPDATE: |
| 129 |
- mItf.onClientUpdated((Messenger) msg.getData().getParcelable( |
| 130 |
- PARAM_MESSENGER)); |
| 131 |
- break; |
| 132 |
+ Stub downloader = mDownloader.get(); |
| 133 |
+ if (downloader != null) { |
| 134 |
+ downloader.handleMessage(msg); |
| 135 |
} |
| 136 |
} |
| 137 |
- }); |
| 138 |
+ } |
| 139 |
+ |
| 140 |
+ private void handleMessage(Message msg) { |
| 141 |
+ switch (msg.what) { |
| 142 |
+ case MSG_REQUEST_ABORT_DOWNLOAD: |
| 143 |
+ mItf.requestAbortDownload(); |
| 144 |
+ break; |
| 145 |
+ case MSG_REQUEST_CONTINUE_DOWNLOAD: |
| 146 |
+ mItf.requestContinueDownload(); |
| 147 |
+ break; |
| 148 |
+ case MSG_REQUEST_PAUSE_DOWNLOAD: |
| 149 |
+ mItf.requestPauseDownload(); |
| 150 |
+ break; |
| 151 |
+ case MSG_SET_DOWNLOAD_FLAGS: |
| 152 |
+ mItf.setDownloadFlags(msg.getData().getInt(PARAMS_FLAGS)); |
| 153 |
+ break; |
| 154 |
+ case MSG_REQUEST_DOWNLOAD_STATE: |
| 155 |
+ mItf.requestDownloadStatus(); |
| 156 |
+ break; |
| 157 |
+ case MSG_REQUEST_CLIENT_UPDATE: |
| 158 |
+ mItf.onClientUpdated((Messenger)msg.getData().getParcelable( |
| 159 |
+ PARAM_MESSENGER)); |
| 160 |
+ break; |
| 161 |
+ } |
| 162 |
+ } |
| 163 |
+ // -- GODOT end -- |
| 164 |
|
| 165 |
public Stub(IDownloaderService itf) { |
| 166 |
mItf = itf; |
| 167 |
diff --git a/platform/android/java/src/com/google/android/vending/expansion/downloader/Helpers.java b/platform/android/java/src/com/google/android/vending/expansion/downloader/Helpers.java |
| 168 |
index e4b1b0f1c..36cd6aacf 100644 |
| 169 |
--- a/platform/android/java/src/com/google/android/vending/expansion/downloader/Helpers.java |
| 170 |
+++ b/platform/android/java/src/com/google/android/vending/expansion/downloader/Helpers.java |
| 171 |
@@ -24,7 +24,10 @@ import android.os.StatFs; |
| 172 |
import android.os.SystemClock; |
| 173 |
import android.util.Log; |
| 174 |
|
| 175 |
-import com.android.vending.expansion.downloader.R; |
| 176 |
+// -- GODOT start -- |
| 177 |
+//import com.android.vending.expansion.downloader.R; |
| 178 |
+import org.godotengine.godot.R; |
| 179 |
+// -- GODOT end -- |
| 180 |
|
| 181 |
import java.io.File; |
| 182 |
import java.text.SimpleDateFormat; |
| 183 |
@@ -146,12 +149,14 @@ public class Helpers { |
| 184 |
} |
| 185 |
return ""; |
| 186 |
} |
| 187 |
- return String.format("%.2f", |
| 188 |
+ // -- GODOT start -- |
| 189 |
+ return String.format(Locale.ENGLISH, "%.2f", |
| 190 |
(float) overallProgress / (1024.0f * 1024.0f)) |
| 191 |
+ "MB /" + |
| 192 |
- String.format("%.2f", (float) overallTotal / |
| 193 |
+ String.format(Locale.ENGLISH, "%.2f", (float) overallTotal / |
| 194 |
(1024.0f * 1024.0f)) |
| 195 |
+ "MB"; |
| 196 |
+ // -- GODOT end -- |
| 197 |
} |
| 198 |
|
| 199 |
/** |
| 200 |
@@ -184,7 +189,9 @@ public class Helpers { |
| 201 |
} |
| 202 |
|
| 203 |
public static String getSpeedString(float bytesPerMillisecond) { |
| 204 |
- return String.format("%.2f", bytesPerMillisecond * 1000 / 1024); |
| 205 |
+ // -- GODOT start -- |
| 206 |
+ return String.format(Locale.ENGLISH, "%.2f", bytesPerMillisecond * 1000 / 1024); |
| 207 |
+ // -- GODOT end -- |
| 208 |
} |
| 209 |
|
| 210 |
public static String getTimeRemaining(long durationInMilliseconds) { |
| 211 |
diff --git a/platform/android/java/src/com/google/android/vending/expansion/downloader/SystemFacade.java b/platform/android/java/src/com/google/android/vending/expansion/downloader/SystemFacade.java |
| 212 |
index 12edd97ab..a0e1165cc 100644 |
| 213 |
--- a/platform/android/java/src/com/google/android/vending/expansion/downloader/SystemFacade.java |
| 214 |
+++ b/platform/android/java/src/com/google/android/vending/expansion/downloader/SystemFacade.java |
| 215 |
@@ -26,6 +26,10 @@ import android.net.NetworkInfo; |
| 216 |
import android.telephony.TelephonyManager; |
| 217 |
import android.util.Log; |
| 218 |
|
| 219 |
+// -- GODOT start -- |
| 220 |
+import android.annotation.SuppressLint; |
| 221 |
+// -- GODOT end -- |
| 222 |
+ |
| 223 |
/** |
| 224 |
* Contains useful helper functions, typically tied to the application context. |
| 225 |
*/ |
| 226 |
@@ -51,6 +55,7 @@ class SystemFacade { |
| 227 |
return null; |
| 228 |
} |
| 229 |
|
| 230 |
+ @SuppressLint("MissingPermission") |
| 231 |
NetworkInfo activeInfo = connectivity.getActiveNetworkInfo(); |
| 232 |
if (activeInfo == null) { |
| 233 |
if (Constants.LOGVV) { |
| 234 |
@@ -69,6 +74,7 @@ class SystemFacade { |
| 235 |
return false; |
| 236 |
} |
| 237 |
|
| 238 |
+ @SuppressLint("MissingPermission") |
| 239 |
NetworkInfo info = connectivity.getActiveNetworkInfo(); |
| 240 |
boolean isMobile = (info != null && info.getType() == ConnectivityManager.TYPE_MOBILE); |
| 241 |
TelephonyManager tm = (TelephonyManager) mContext |
| 242 |
diff --git a/platform/android/java/src/com/google/android/vending/expansion/downloader/impl/DownloadNotification.java b/platform/android/java/src/com/google/android/vending/expansion/downloader/impl/DownloadNotification.java |
| 243 |
index f1536e80e..4b214b22d 100644 |
| 244 |
--- a/platform/android/java/src/com/google/android/vending/expansion/downloader/impl/DownloadNotification.java |
| 245 |
+++ b/platform/android/java/src/com/google/android/vending/expansion/downloader/impl/DownloadNotification.java |
| 246 |
@@ -16,7 +16,11 @@ |
| 247 |
|
| 248 |
package com.google.android.vending.expansion.downloader.impl; |
| 249 |
|
| 250 |
-import com.android.vending.expansion.downloader.R; |
| 251 |
+// -- GODOT start -- |
| 252 |
+//import com.android.vending.expansion.downloader.R; |
| 253 |
+import org.godotengine.godot.R; |
| 254 |
+// -- GODOT end -- |
| 255 |
+ |
| 256 |
import com.google.android.vending.expansion.downloader.DownloadProgressInfo; |
| 257 |
import com.google.android.vending.expansion.downloader.DownloaderClientMarshaller; |
| 258 |
import com.google.android.vending.expansion.downloader.Helpers; |
| 259 |
diff --git a/platform/android/java/src/com/google/android/vending/expansion/downloader/impl/DownloadThread.java b/platform/android/java/src/com/google/android/vending/expansion/downloader/impl/DownloadThread.java |
| 260 |
index b2e0e7af0..c114b8a64 100644 |
| 261 |
--- a/platform/android/java/src/com/google/android/vending/expansion/downloader/impl/DownloadThread.java |
| 262 |
+++ b/platform/android/java/src/com/google/android/vending/expansion/downloader/impl/DownloadThread.java |
| 263 |
@@ -146,8 +146,12 @@ public class DownloadThread { |
| 264 |
|
| 265 |
try { |
| 266 |
PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); |
| 267 |
- wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, Constants.TAG); |
| 268 |
- wakeLock.acquire(); |
| 269 |
+ // -- GODOT start -- |
| 270 |
+ //wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, Constants.TAG); |
| 271 |
+ //wakeLock.acquire(); |
| 272 |
+ wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "org.godot.game:wakelock"); |
| 273 |
+ wakeLock.acquire(20 * 60 * 1000L /*20 minutes*/); |
| 274 |
+ // -- GODOT end -- |
| 275 |
|
| 276 |
if (Constants.LOGV) { |
| 277 |
Log.v(Constants.TAG, "initiating download for " + mInfo.mFileName); |
| 278 |
diff --git a/platform/android/java/src/com/google/android/vending/expansion/downloader/impl/DownloaderService.java b/platform/android/java/src/com/google/android/vending/expansion/downloader/impl/DownloaderService.java |
| 279 |
index 4babe476f..8d41a7690 100644 |
| 280 |
--- a/platform/android/java/src/com/google/android/vending/expansion/downloader/impl/DownloaderService.java |
| 281 |
+++ b/platform/android/java/src/com/google/android/vending/expansion/downloader/impl/DownloaderService.java |
| 282 |
@@ -50,6 +50,10 @@ import android.provider.Settings.Secure; |
| 283 |
import android.telephony.TelephonyManager; |
| 284 |
import android.util.Log; |
| 285 |
|
| 286 |
+// -- GODOT start -- |
| 287 |
+import android.annotation.SuppressLint; |
| 288 |
+// -- GODOT end -- |
| 289 |
+ |
| 290 |
import java.io.File; |
| 291 |
|
| 292 |
/** |
| 293 |
@@ -578,6 +582,7 @@ public abstract class DownloaderService extends CustomIntentService implements I |
| 294 |
Log.w(Constants.TAG, |
| 295 |
"couldn't get connectivity manager to poll network state"); |
| 296 |
} else { |
| 297 |
+ @SuppressLint("MissingPermission") |
| 298 |
NetworkInfo activeInfo = mConnectivityManager |
| 299 |
.getActiveNetworkInfo(); |
| 300 |
updateNetworkState(activeInfo); |