Skip to content

Commit

Permalink
Merge pull request #1580 from microsoft/v-ankubo/release-4.4.0-patch-1
Browse files Browse the repository at this point in the history
Patch with fixes after testing release 4.4.0
  • Loading branch information
Anastasia Senyushina authored Dec 8, 2021
2 parents 1c75a2a + 8ecdaa3 commit fedfc38
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# App Center SDK for Android Change Log

## Version 4.4.0
## Version 4.4.1

### App Center

Expand All @@ -19,6 +19,7 @@
* **[Feature]** Remove the download manager task if the download doesn't start within 10 seconds.
* **[Feature]** Replace installing a new release using the deprecated intent action [ACTION_INSTALL_PACKAGE](https://developer.android.com/reference/android/content/Intent#ACTION_INSTALL_PACKAGE) with the `PackageInstaller` API.
* **[Feature]** Add sumcheck on the downloaded file before starting the install process.
* **[Fix]** Fix a crash after discarding the installation if the download of a new release was interrupted in the previous application start and resumed in the current one.

___

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ final class ActivityConstants {
/**
* Default Analytics transmission interval in seconds.
*/
static final int DEFAULT_TRANSMISSION_INTERVAL_IN_SECONDS = 3;
static final int DEFAULT_TRANSMISSION_INTERVAL_IN_SECONDS = 6;
}
Original file line number Diff line number Diff line change
Expand Up @@ -1540,7 +1540,7 @@ private synchronized void showUpdateDialog() {
}
mUsingDefaultUpdateDialog = !customized;
}
if (mUsingDefaultUpdateDialog) {
if (mUsingDefaultUpdateDialog != null && mUsingDefaultUpdateDialog) {
if (!shouldRefreshDialog(mUpdateDialog)) {
return;
}
Expand Down Expand Up @@ -1952,6 +1952,10 @@ synchronized private void installUpdate() {
* @param totalSize total size of downloaded file.
*/
synchronized void showSystemSettingsDialogOrStartInstalling(long downloadId, long totalSize) {
if (mReleaseInstallerListener == null) {
AppCenterLog.debug(LOG_TAG, "Installing couldn't start due to the release installer wasn't initialized.");
return;
}
mReleaseInstallerListener.setDownloadId(downloadId);
mReleaseInstallerListener.setTotalSize(totalSize);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Matchers;
import org.mockito.Mockito;
import org.mockito.internal.util.reflection.Whitebox;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
Expand Down Expand Up @@ -996,6 +997,65 @@ public void checkInstallProgressState() {
verify(mReleaseInstallerListener, times(2)).hideInstallProgressDialog();
}

@Test
public void showSystemSettingsDialogWhenPackageInstallerNull() {

/* Try to show dialog. */
Distribute.getInstance().showSystemSettingsDialogOrStartInstalling(1L, 1L);

/* Verify that log was called. */
verifyStatic();
AppCenterLog.debug(eq(LOG_TAG), eq("Installing couldn't start due to the release installer wasn't initialized."));
}

@Test
public void showUpdateDialogAfterShowingInstallReleaseDialogTest() {

/* Mock App Center log. */
mockStatic(AppCenterLog.class);

/* Mock system alert settings. */
mockStatic(InstallerUtils.class);
when(InstallerUtils.isSystemAlertWindowsEnabled(any(Context.class))).thenReturn(false);

/* Mock distribute utils. */
mockStatic(DistributeUtils.class);
when(DistributeUtils.getStoredDownloadState()).thenReturn(-1).thenReturn(1);

/* Mock that download time is bigger than packageInfo.lastUpdateTime. */
when(SharedPreferencesManager.getLong(eq(PREFERENCE_KEY_DOWNLOAD_TIME))).thenReturn(3L);

/* mReleaseDetails is not null and it's a mandatory update. */
when(DistributeUtils.loadCachedReleaseDetails()).thenReturn(mReleaseDetails);
when(mReleaseDetails.isMandatoryUpdate()).thenReturn(true);
when(mReleaseDownloader.isDownloading()).thenReturn(false);

/* Prepare distribute listener. */
Distribute.setListener(Mockito.mock(DistributeListener.class));

/* Show install settings dialog. */
Distribute.getInstance().startFromBackground(mContext);
resumeWorkflow(mActivity);
Distribute.getInstance().showSystemSettingsDialogOrStartInstalling(1L, 1L);

/* Emulate that settings was applied. */
Distribute.getInstance().onActivityPaused(mActivity);
Distribute.getInstance().onActivityStopped(mActivity);
resumeWorkflow(mActivity);

/* Verify that install progress was started. */
verify(mReleaseInstallerListener).startInstall();

/* Emulate system confirmation dialog about installing new release. */
Distribute.getInstance().onActivityPaused(mActivity);
Distribute.getInstance().onActivityStopped(mActivity);
resumeWorkflow(mActivity);

/* Verify that SDK wasn't crash with NPE and don't show dialog. */
verifyStatic(never());
AppCenterLog.debug(eq(LOG_TAG), eq("Show default update dialog."));
}

private void firstDownloadNotification(int apiLevel) throws Exception {
TestUtils.setInternalState(Build.VERSION.class, "SDK_INT", apiLevel);
mockStatic(DistributeUtils.class);
Expand Down
2 changes: 1 addition & 1 deletion versions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

ext {
versionCode = 65
versionName = '4.4.0'
versionName = '4.4.1'
minSdkVersion = 21
compileSdkVersion = 30
targetSdkVersion = 30
Expand Down

0 comments on commit fedfc38

Please sign in to comment.