Skip to content

Commit 6dd8621

Browse files
authored
Merge pull request #381 from Microsoft/develop
Release version 0.6.1
2 parents 3d0a85d + 6168717 commit 6dd8621

File tree

16 files changed

+594
-274
lines changed

16 files changed

+594
-274
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
The Microsoft Mobile Center Android SDK lets you add Mobile Center services to your Android application.
1212

13-
The SDK is currently in private beta release and we support the following services:
13+
The SDK currently supports the following services:
1414

1515
1. **Analytics**: Mobile Center Analytics helps you understand user behavior and customer engagement to improve your Android app. The SDK automatically captures session count and device properties like model, OS Version etc. You can define your own custom events to measure things that matter to your business. All the information captured is available in the Mobile Center portal for you to analyze the data.
1616

sdk/mobile-center-distribute/src/main/java/com/microsoft/azure/mobile/distribute/CheckDownloadTask.java

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import android.os.AsyncTask;
99
import android.os.Build;
1010

11+
import com.microsoft.azure.mobile.utils.HandlerUtils;
1112
import com.microsoft.azure.mobile.utils.MobileCenterLog;
12-
import com.microsoft.azure.mobile.utils.storage.StorageHelper;
1313

1414
import java.util.NoSuchElementException;
1515

@@ -53,7 +53,7 @@ class CheckDownloadTask extends AsyncTask<Void, Void, DownloadProgress> {
5353
* @param releaseDetails release details.
5454
*/
5555
CheckDownloadTask(Context context, long downloadId, boolean checkProgress, ReleaseDetails releaseDetails) {
56-
mContext = context;
56+
mContext = context.getApplicationContext();
5757
mDownloadId = downloadId;
5858
mCheckProgress = checkProgress;
5959
mReleaseDetails = releaseDetails;
@@ -76,10 +76,8 @@ protected DownloadProgress doInBackground(Void... params) {
7676
*/
7777
MobileCenterLog.debug(LOG_TAG, "Check download id=" + mDownloadId);
7878
Distribute distribute = Distribute.getInstance();
79-
if (!distribute.isStarted()) {
80-
MobileCenterLog.debug(LOG_TAG, "Called before onStart, init storage");
81-
StorageHelper.initialize(mContext);
82-
mReleaseDetails = DistributeUtils.loadCachedReleaseDetails();
79+
if (mReleaseDetails == null) {
80+
mReleaseDetails = distribute.startFromBackground(mContext);
8381
}
8482

8583
/* Check intent data is what we expected. */
@@ -105,11 +103,15 @@ protected DownloadProgress doInBackground(Void... params) {
105103
throw new IllegalStateException();
106104
}
107105
if (status != DownloadManager.STATUS_SUCCESSFUL || mCheckProgress) {
108-
distribute.markDownloadStillInProgress(this);
109-
long totalSize = cursor.getLong(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_TOTAL_SIZE_BYTES));
110-
long currentSize = cursor.getLong(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR));
111-
MobileCenterLog.verbose(LOG_TAG, "currentSize=" + currentSize + " totalSize=" + totalSize);
112-
return new DownloadProgress(currentSize, totalSize);
106+
if (mCheckProgress) {
107+
long totalSize = cursor.getLong(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_TOTAL_SIZE_BYTES));
108+
long currentSize = cursor.getLong(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR));
109+
MobileCenterLog.verbose(LOG_TAG, "currentSize=" + currentSize + " totalSize=" + totalSize);
110+
return new DownloadProgress(currentSize, totalSize);
111+
} else {
112+
distribute.markDownloadStillInProgress(mReleaseDetails);
113+
return null;
114+
}
113115
}
114116

115117
/* Build install intent. */
@@ -127,12 +129,12 @@ protected DownloadProgress doInBackground(Void... params) {
127129
}
128130
if (!installerFound) {
129131
MobileCenterLog.error(LOG_TAG, "Installer not found");
130-
distribute.completeWorkflow(this);
132+
distribute.completeWorkflow(mReleaseDetails);
131133
return null;
132134
}
133135

134136
/* Check if a should install now. */
135-
if (!distribute.notifyDownload(mContext, this, intent)) {
137+
if (!distribute.notifyDownload(mReleaseDetails, intent)) {
136138

137139
/*
138140
* This start call triggers strict mode in U.I. thread so it
@@ -146,34 +148,33 @@ protected DownloadProgress doInBackground(Void... params) {
146148
MobileCenterLog.info(LOG_TAG, "Show install UI now.");
147149
mContext.startActivity(intent);
148150
if (mReleaseDetails != null && mReleaseDetails.isMandatoryUpdate()) {
149-
distribute.setInstalling(this);
151+
distribute.setInstalling(mReleaseDetails);
150152
} else {
151-
distribute.completeWorkflow(this);
153+
distribute.completeWorkflow(mReleaseDetails);
152154
}
153155
}
154156
} finally {
155157
cursor.close();
156158
}
157159
} catch (RuntimeException e) {
158160
MobileCenterLog.error(LOG_TAG, "Failed to download update id=" + mDownloadId);
159-
distribute.completeWorkflow(this);
161+
distribute.completeWorkflow(mReleaseDetails);
160162
}
161163
return null;
162164
}
163165

164166
@Override
165-
protected void onPostExecute(DownloadProgress result) {
167+
protected void onPostExecute(final DownloadProgress result) {
166168
if (result != null) {
167-
Distribute.getInstance().updateProgressDialog(this, result);
168-
}
169-
}
170169

171-
/**
172-
* Get context.
173-
*
174-
* @return context.
175-
*/
176-
Context getContext() {
177-
return mContext;
170+
/* onPostExecute is not always called on UI thread due to an old Android bug. */
171+
HandlerUtils.runOnUiThread(new Runnable() {
172+
173+
@Override
174+
public void run() {
175+
Distribute.getInstance().updateProgressDialog(mReleaseDetails, result);
176+
}
177+
});
178+
}
178179
}
179180
}

0 commit comments

Comments
 (0)