From bf66baf5a1b9e565df74681fdb1bd1b5ceb07b15 Mon Sep 17 00:00:00 2001 From: Anastasia Senyushina Date: Thu, 9 Dec 2021 11:15:04 +0300 Subject: [PATCH 1/6] Update version and changelog --- CHANGELOG.md | 4 ++++ versions.gradle | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9015bd0e4..42053dce0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # App Center SDK for Android Change Log +## Version 4.4.2 (Under active development) + +___ + ## Version 4.4.1 ### App Center diff --git a/versions.gradle b/versions.gradle index aa14816f9..e6f82ed99 100644 --- a/versions.gradle +++ b/versions.gradle @@ -6,8 +6,8 @@ // Version constants ext { - versionCode = 65 - versionName = '4.4.1' + versionCode = 66 + versionName = '4.4.2' minSdkVersion = 21 compileSdkVersion = 30 targetSdkVersion = 30 From 4ce6dca678a157233ae3758b6936c30032e19b2a Mon Sep 17 00:00:00 2001 From: Anastasia Senyushina Date: Thu, 16 Dec 2021 12:09:01 +0300 Subject: [PATCH 2/6] Fix parsing startServiceLog --- .../models/json/LogSerializerAndroidTest.java | 31 +++++++++++++++++++ .../ingestion/models/StartServiceLog.java | 6 ++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/sdk/appcenter/src/androidTest/java/com/microsoft/appcenter/ingestion/models/json/LogSerializerAndroidTest.java b/sdk/appcenter/src/androidTest/java/com/microsoft/appcenter/ingestion/models/json/LogSerializerAndroidTest.java index b30b4a621..3f3762fb8 100644 --- a/sdk/appcenter/src/androidTest/java/com/microsoft/appcenter/ingestion/models/json/LogSerializerAndroidTest.java +++ b/sdk/appcenter/src/androidTest/java/com/microsoft/appcenter/ingestion/models/json/LogSerializerAndroidTest.java @@ -11,6 +11,7 @@ import com.microsoft.appcenter.ingestion.models.StartServiceLog; import org.json.JSONException; +import org.junit.Assert; import org.junit.Test; import java.util.ArrayList; @@ -63,6 +64,36 @@ public void deserializeUnknownType() throws JSONException { new DefaultLogSerializer().deserializeLog(payload, null); } + @Test + public void readJsonWhenIsOneCollectorPropertyEnabledIsNull() throws JSONException { + + // Prepare start service log. + StartServiceLog serviceLog = new StartServiceLog(); + List services = new ArrayList<>(); + services.add("FIRST"); + services.add("SECOND"); + serviceLog.setServices(services); + UUID sid = UUID.randomUUID(); + serviceLog.setSid(sid); + serviceLog.setTimestamp(new Date()); + + // Prepare log container. + ArrayList logArrayList = new ArrayList<>(); + logArrayList.add(serviceLog); + LogContainer serializerContainer = new LogContainer(); + serializerContainer.setLogs(logArrayList); + + // Serializer log container. + LogSerializer serializer = new DefaultLogSerializer(); + serializer.addLogFactory(StartServiceLog.TYPE, new StartServiceLogFactory()); + String payload = serializer.serializeContainer(serializerContainer); + + // Deserialize log container. + LogContainer deserializeContainer = serializer.deserializeContainer(payload, null); + StartServiceLog deserializeStartServiceLog = (StartServiceLog) deserializeContainer.getLogs().get(0); + Assert.assertNull(deserializeStartServiceLog.isOneCollectorEnabled()); + } + @Test public void startServiceLog() throws JSONException { StartServiceLog log = new StartServiceLog(); diff --git a/sdk/appcenter/src/main/java/com/microsoft/appcenter/ingestion/models/StartServiceLog.java b/sdk/appcenter/src/main/java/com/microsoft/appcenter/ingestion/models/StartServiceLog.java index 078bc739f..cd47d02ff 100644 --- a/sdk/appcenter/src/main/java/com/microsoft/appcenter/ingestion/models/StartServiceLog.java +++ b/sdk/appcenter/src/main/java/com/microsoft/appcenter/ingestion/models/StartServiceLog.java @@ -31,7 +31,7 @@ public class StartServiceLog extends AbstractLog { /** * OneCollector usage status. */ - private boolean isOneCollectorEnabled = false; + private Boolean isOneCollectorEnabled = null; /** * The list of services of the AppCenter start call. @@ -61,11 +61,11 @@ public void setServices(List services) { this.services = services; } - public void oneCollectorEnabled(boolean isEnabled) { + public void oneCollectorEnabled(Boolean isEnabled) { isOneCollectorEnabled = isEnabled; } - public boolean isOneCollectorEnabled() { + public Boolean isOneCollectorEnabled() { return isOneCollectorEnabled; } From c2c60f0fba0f6a9a865940d7793903dec32096dd Mon Sep 17 00:00:00 2001 From: Anastasia Senyushina Date: Thu, 16 Dec 2021 12:53:43 +0300 Subject: [PATCH 3/6] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 42053dce0..adbee704a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Version 4.4.2 (Under active development) +* **[Fix]** Fix a crash during trying to get `startServiceLog` from the database after upgrading App Center SDK from the old versions. + ___ ## Version 4.4.1 From 8be2c1102f542d815be8984e0a7d593fcfbfedc8 Mon Sep 17 00:00:00 2001 From: Anastasia Senyushina Date: Fri, 17 Dec 2021 09:11:08 +0300 Subject: [PATCH 4/6] Revert assert logs --- CHANGELOG.md | 2 ++ .../appcenter/utils/AppCenterLog.java | 27 +++++++++++++++++++ .../appcenter/utils/AppCenterLogTest.java | 2 ++ 3 files changed, 31 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 42053dce0..6b62c2a0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Version 4.4.2 (Under active development) +* **[Fix]** Fix print logs with `ASSERT` level. + ___ ## Version 4.4.1 diff --git a/sdk/appcenter/src/main/java/com/microsoft/appcenter/utils/AppCenterLog.java b/sdk/appcenter/src/main/java/com/microsoft/appcenter/utils/AppCenterLog.java index c895ebd34..b1a5de278 100644 --- a/sdk/appcenter/src/main/java/com/microsoft/appcenter/utils/AppCenterLog.java +++ b/sdk/appcenter/src/main/java/com/microsoft/appcenter/utils/AppCenterLog.java @@ -249,6 +249,33 @@ public static void error(@NonNull String tag, @NonNull String message, Throwable } } + /** + * Log a message with level ASSERT + * + * @param tag the log tag for your message + * @param message the log message + */ + @SuppressWarnings("WeakerAccess") + public static void logAssert(@NonNull String tag, @NonNull String message) { + if (sLogLevel <= Log.ASSERT) { + Log.println(Log.ASSERT, tag, message); + } + } + + /** + * Log a message with level ASSERT + * + * @param tag the log tag for your message + * @param message the log message + * @param throwable the throwable you want to log + */ + @SuppressWarnings({"WeakerAccess", "SameParameterValue"}) + public static void logAssert(@NonNull String tag, @NonNull String message, Throwable throwable) { + if (sLogLevel <= Log.ASSERT) { + Log.println(Log.ASSERT, tag, message + "\n" + Log.getStackTraceString(throwable)); + } + } + private static String getMessageWithTag(String tag, String message) { return String.format("%s: %s", tag, message); } diff --git a/sdk/appcenter/src/test/java/com/microsoft/appcenter/utils/AppCenterLogTest.java b/sdk/appcenter/src/test/java/com/microsoft/appcenter/utils/AppCenterLogTest.java index 5568cc55c..c517dcfa1 100644 --- a/sdk/appcenter/src/test/java/com/microsoft/appcenter/utils/AppCenterLogTest.java +++ b/sdk/appcenter/src/test/java/com/microsoft/appcenter/utils/AppCenterLogTest.java @@ -39,6 +39,8 @@ public class AppCenterLogTest { private static void callLogs() { + AppCenterLog.logAssert("my-tag", "error with my-tag"); + AppCenterLog.logAssert("my-tag", "error with my-tag with exception", new Exception()); AppCenterLog.error("my-tag", "error with my-tag"); AppCenterLog.error("my-tag", "error with my-tag with exception", new Exception()); AppCenterLog.warn("my-tag", "warn with my-tag"); From 456bb78752c8161f29da737bdd13645bd4c6b6d6 Mon Sep 17 00:00:00 2001 From: Anastasia Senyushina Date: Mon, 20 Dec 2021 10:55:49 +0300 Subject: [PATCH 5/6] Fix missing required flag on Android 31 API --- CHANGELOG.md | 4 +++ .../AppCenterPackageInstallerReceiver.java | 14 ++++---- .../appcenter/distribute/InstallerUtils.java | 7 +++- ...AppCenterPackageInstallerReceiverTest.java | 9 ++--- .../distribute/InstallerUtilsTest.java | 35 +++++++++++++++++++ versions.gradle | 4 +-- 6 files changed, 60 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 42053dce0..754a3dfbf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Version 4.4.2 (Under active development) +### App Center Distribute + +* **[Fix]** Fix missing required flag on Android 31 API for `PendingIntent` which is used for starting the process of installing a new release. + ___ ## Version 4.4.1 diff --git a/sdk/appcenter-distribute/src/main/java/com/microsoft/appcenter/distribute/AppCenterPackageInstallerReceiver.java b/sdk/appcenter-distribute/src/main/java/com/microsoft/appcenter/distribute/AppCenterPackageInstallerReceiver.java index 56ddef92e..7da03a000 100644 --- a/sdk/appcenter-distribute/src/main/java/com/microsoft/appcenter/distribute/AppCenterPackageInstallerReceiver.java +++ b/sdk/appcenter-distribute/src/main/java/com/microsoft/appcenter/distribute/AppCenterPackageInstallerReceiver.java @@ -5,6 +5,8 @@ package com.microsoft.appcenter.distribute; +import static com.microsoft.appcenter.distribute.DistributeConstants.LOG_TAG; + import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -27,7 +29,7 @@ public class AppCenterPackageInstallerReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (MY_PACKAGE_REPLACED_ACTION.equals(intent.getAction())) { - AppCenterLog.debug(AppCenterLog.LOG_TAG, "Restart application after installing a new release."); + AppCenterLog.debug(LOG_TAG, "Restart application after installing a new release."); Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName()); launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); context.startActivity(launchIntent); @@ -37,13 +39,13 @@ public void onReceive(Context context, Intent intent) { String message = extras.getString(PackageInstaller.EXTRA_STATUS_MESSAGE); switch (status) { case PackageInstaller.STATUS_PENDING_USER_ACTION: - AppCenterLog.debug(AppCenterLog.LOG_TAG, "Ask confirmation to install a new release."); + AppCenterLog.debug(LOG_TAG, "Ask confirmation to install a new release."); Intent confirmIntent = (Intent) extras.get(Intent.EXTRA_INTENT); confirmIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(confirmIntent); break; case PackageInstaller.STATUS_SUCCESS: - AppCenterLog.debug(AppCenterLog.LOG_TAG, "Application was successfully updated."); + AppCenterLog.debug(LOG_TAG, "Application was successfully updated."); break; case PackageInstaller.STATUS_FAILURE: case PackageInstaller.STATUS_FAILURE_ABORTED: @@ -52,15 +54,15 @@ public void onReceive(Context context, Intent intent) { case PackageInstaller.STATUS_FAILURE_INCOMPATIBLE: case PackageInstaller.STATUS_FAILURE_INVALID: case PackageInstaller.STATUS_FAILURE_STORAGE: - AppCenterLog.debug(AppCenterLog.LOG_TAG, String.format(Locale.ENGLISH, "Failed to install a new release with status: %s. Error message: %s.", status, message)); + AppCenterLog.debug(LOG_TAG, String.format(Locale.ENGLISH, "Failed to install a new release with status: %s. Error message: %s.", status, message)); Toast.makeText(context, context.getString(R.string.appcenter_distribute_something_went_wrong_during_installing_new_release), Toast.LENGTH_SHORT).show(); break; default: - AppCenterLog.debug(AppCenterLog.LOG_TAG, String.format(Locale.ENGLISH, "Unrecognized status received from installer: %s", status)); + AppCenterLog.debug(LOG_TAG, String.format(Locale.ENGLISH, "Unrecognized status received from installer: %s", status)); Toast.makeText(context, context.getString(R.string.appcenter_distribute_something_went_wrong_during_installing_new_release), Toast.LENGTH_SHORT).show(); } } else { - AppCenterLog.debug(AppCenterLog.LOG_TAG, String.format(Locale.ENGLISH, "Unrecognized action %s - do nothing.", intent.getAction())); + AppCenterLog.debug(LOG_TAG, String.format(Locale.ENGLISH, "Unrecognized action %s - do nothing.", intent.getAction())); } } } diff --git a/sdk/appcenter-distribute/src/main/java/com/microsoft/appcenter/distribute/InstallerUtils.java b/sdk/appcenter-distribute/src/main/java/com/microsoft/appcenter/distribute/InstallerUtils.java index 6fbcf5571..7bb3c59f4 100644 --- a/sdk/appcenter-distribute/src/main/java/com/microsoft/appcenter/distribute/InstallerUtils.java +++ b/sdk/appcenter-distribute/src/main/java/com/microsoft/appcenter/distribute/InstallerUtils.java @@ -5,6 +5,7 @@ package com.microsoft.appcenter.distribute; +import static android.app.PendingIntent.FLAG_MUTABLE; import static com.microsoft.appcenter.distribute.DistributeConstants.LOG_TAG; import android.app.PendingIntent; @@ -190,11 +191,15 @@ public synchronized static void installPackage(@NonNull InputStream data, Contex * @return IntentSender with receiver. */ public synchronized static IntentSender createIntentSender(Context context, int sessionId) { + int flag = 0; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + flag = FLAG_MUTABLE; + } PendingIntent pendingIntent = PendingIntent.getBroadcast( context, sessionId, new Intent(AppCenterPackageInstallerReceiver.START_ACTION), - 0); + flag); return pendingIntent.getIntentSender(); } } diff --git a/sdk/appcenter-distribute/src/test/java/com/microsoft/appcenter/distribute/AppCenterPackageInstallerReceiverTest.java b/sdk/appcenter-distribute/src/test/java/com/microsoft/appcenter/distribute/AppCenterPackageInstallerReceiverTest.java index 11051cace..d93c8d31b 100644 --- a/sdk/appcenter-distribute/src/test/java/com/microsoft/appcenter/distribute/AppCenterPackageInstallerReceiverTest.java +++ b/sdk/appcenter-distribute/src/test/java/com/microsoft/appcenter/distribute/AppCenterPackageInstallerReceiverTest.java @@ -7,6 +7,7 @@ import static com.microsoft.appcenter.distribute.AppCenterPackageInstallerReceiver.MY_PACKAGE_REPLACED_ACTION; import static com.microsoft.appcenter.distribute.AppCenterPackageInstallerReceiver.START_ACTION; +import static com.microsoft.appcenter.distribute.DistributeConstants.LOG_TAG; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyInt; @@ -130,7 +131,7 @@ public void onReceiveWithStartIntentWithStatusSuccess() { /* Verify. */ verifyStatic(); - AppCenterLog.debug(eq(AppCenterLog.LOG_TAG), eq("Application was successfully updated.")); + AppCenterLog.debug(eq(LOG_TAG), eq("Application was successfully updated.")); } @Test @@ -179,7 +180,7 @@ private void onReceiveWithStartFailureAction(int status) { /* Verify that log was called. */ verifyStatic(); - AppCenterLog.debug(eq(AppCenterLog.LOG_TAG), eq("Failed to install a new release with status: " + status + ". Error message: null.")); + AppCenterLog.debug(eq(LOG_TAG), eq("Failed to install a new release with status: " + status + ". Error message: null.")); } @Test @@ -198,7 +199,7 @@ public void onReceiveWithStartIntentWithUnrecognizedStatus() { /* Verify that log was called. */ verifyStatic(); - AppCenterLog.debug(eq(AppCenterLog.LOG_TAG), eq("Unrecognized status received from installer: " + status)); + AppCenterLog.debug(eq(LOG_TAG), eq("Unrecognized status received from installer: " + status)); } @Test @@ -210,7 +211,7 @@ public void onReceiverWithUnknownAction() { /* Verify that log was called. */ verifyStatic(); - AppCenterLog.debug(eq(AppCenterLog.LOG_TAG), eq("Unrecognized action UnknownAction - do nothing.")); + AppCenterLog.debug(eq(LOG_TAG), eq("Unrecognized action UnknownAction - do nothing.")); } } diff --git a/sdk/appcenter-distribute/src/test/java/com/microsoft/appcenter/distribute/InstallerUtilsTest.java b/sdk/appcenter-distribute/src/test/java/com/microsoft/appcenter/distribute/InstallerUtilsTest.java index 1a0ed6345..e89b9181c 100644 --- a/sdk/appcenter-distribute/src/test/java/com/microsoft/appcenter/distribute/InstallerUtilsTest.java +++ b/sdk/appcenter-distribute/src/test/java/com/microsoft/appcenter/distribute/InstallerUtilsTest.java @@ -5,6 +5,7 @@ package com.microsoft.appcenter.distribute; +import static android.app.PendingIntent.FLAG_MUTABLE; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.any; @@ -27,11 +28,14 @@ import android.os.Build; import android.provider.Settings; +import org.junit.Assert; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.mockito.Matchers; import org.mockito.Mock; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.rule.PowerMockRule; @@ -186,6 +190,37 @@ public void isSystemAlertWindowsEnabledReturnsFalseIfBuildVersionQorHigherAndCan assertFalse(InstallerUtils.isSystemAlertWindowsEnabled(mContext)); } + @Test + public void createIntentSenderOnAndroidS() throws Exception { + + /* Mock SDK_INT to S. */ + setFinalStatic(Build.VERSION.class.getField("SDK_INT"), Build.VERSION_CODES.S); + createIntentSender(FLAG_MUTABLE); + } + + @Test + public void createIntentSenderOnAndroidLowS() throws Exception { + + /* Mock SDK_INT to M. */ + setFinalStatic(Build.VERSION.class.getField("SDK_INT"), Build.VERSION_CODES.M); + createIntentSender(0); + } + + private void createIntentSender(final int expectedFlag) { + mockStatic(PendingIntent.class); + final PendingIntent mockIntent = mock(PendingIntent.class); + when(mockIntent.getIntentSender()).thenReturn(mock(IntentSender.class)); + when(PendingIntent.getBroadcast(any(Context.class), anyInt(), any(Intent.class), anyInt())).then(new Answer() { + @Override + public PendingIntent answer(InvocationOnMock invocation) throws Throwable { + int flag = (int)invocation.getArguments()[3]; + Assert.assertEquals(flag, expectedFlag); + return mockIntent; + } + }); + InstallerUtils.createIntentSender(mContext, 1); + } + /** * This is used ot set a specific Build.VERSION.SDK_INT for tests. * @param field static field diff --git a/versions.gradle b/versions.gradle index e6f82ed99..a94dea3bb 100644 --- a/versions.gradle +++ b/versions.gradle @@ -9,7 +9,7 @@ ext { versionCode = 66 versionName = '4.4.2' minSdkVersion = 21 - compileSdkVersion = 30 - targetSdkVersion = 30 + compileSdkVersion = 31 + targetSdkVersion = 31 annotationVersion = '1.2.0' } From 384c7e7aff9cc41a24948ad732108ffad4e9c861 Mon Sep 17 00:00:00 2001 From: Anastasia Senyushina Date: Tue, 21 Dec 2021 09:21:51 +0300 Subject: [PATCH 6/6] Update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f74a9ba2..864f79335 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # App Center SDK for Android Change Log -## Version 4.4.2 (Under active development) +## Version 4.4.2 ### App Center