Skip to content

Commit 865e8fc

Browse files
authored
Merge pull request #465 from Microsoft/develop
v0.10.0
2 parents f3b846f + 071f0fb commit 865e8fc

File tree

28 files changed

+390
-139
lines changed

28 files changed

+390
-139
lines changed

apps/sasquatch/src/main/AndroidManifest.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
android:supportsRtl="true"
1212
android:theme="@style/AppTheme"
1313
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
14-
<activity android:name=".activities.MainActivity">
14+
<activity
15+
android:name=".activities.MainActivity"
16+
android:launchMode="singleTop">
1517
<intent-filter>
1618
<action android:name="android.intent.action.MAIN"/>
1719

@@ -41,7 +43,9 @@
4143
<activity
4244
android:name=".activities.ManagedErrorActivity"
4345
android:label="@string/title_error"/>
44-
<activity android:name=".activities.CustomPropertiesActivity"></activity>
46+
<activity
47+
android:name=".activities.CustomPropertiesActivity"
48+
android:label="@string/title_custom_properties"/>
4549
</application>
4650

4751
</manifest>

apps/sasquatch/src/main/java/com/microsoft/azure/mobile/sasquatch/activities/MainActivity.java

Lines changed: 91 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22

33
import android.app.Activity;
44
import android.content.Context;
5+
import android.content.DialogInterface;
56
import android.content.Intent;
67
import android.content.SharedPreferences;
8+
import android.graphics.Bitmap;
9+
import android.graphics.BitmapFactory;
710
import android.os.Bundle;
811
import android.os.StrictMode;
912
import android.support.annotation.NonNull;
1013
import android.support.annotation.Nullable;
1114
import android.support.annotation.VisibleForTesting;
1215
import android.support.test.espresso.idling.CountingIdlingResource;
16+
import android.support.v7.app.AlertDialog;
1317
import android.support.v7.app.AppCompatActivity;
1418
import android.text.TextUtils;
1519
import android.util.Log;
@@ -26,7 +30,9 @@
2630
import com.microsoft.azure.mobile.analytics.channel.AnalyticsListener;
2731
import com.microsoft.azure.mobile.analytics.ingestion.models.EventLog;
2832
import com.microsoft.azure.mobile.analytics.ingestion.models.PageLog;
33+
import com.microsoft.azure.mobile.crashes.AbstractCrashesListener;
2934
import com.microsoft.azure.mobile.crashes.Crashes;
35+
import com.microsoft.azure.mobile.crashes.ingestion.models.ErrorAttachmentLog;
3036
import com.microsoft.azure.mobile.crashes.model.ErrorReport;
3137
import com.microsoft.azure.mobile.distribute.Distribute;
3238
import com.microsoft.azure.mobile.ingestion.models.LogWithProperties;
@@ -37,11 +43,12 @@
3743
import com.microsoft.azure.mobile.sasquatch.SasquatchDistributeListener;
3844
import com.microsoft.azure.mobile.sasquatch.features.TestFeatures;
3945
import com.microsoft.azure.mobile.sasquatch.features.TestFeaturesListAdapter;
40-
import com.microsoft.azure.mobile.sasquatch.utils.SasquatchCrashesListener;
4146
import com.microsoft.azure.mobile.utils.MobileCenterLog;
4247

4348
import org.json.JSONObject;
4449

50+
import java.io.ByteArrayOutputStream;
51+
import java.util.Arrays;
4552
import java.util.Map;
4653

4754

@@ -74,7 +81,7 @@ protected void onCreate(Bundle savedInstanceState) {
7481

7582
/* Set listeners. */
7683
AnalyticsPrivateHelper.setListener(getAnalyticsListener());
77-
Crashes.setListener(new SasquatchCrashesListener(this));
84+
Crashes.setListener(getCrashesListener());
7885
Distribute.setListener(new SasquatchDistributeListener());
7986
Push.setListener(getPushListener());
8087

@@ -132,6 +139,15 @@ public boolean onOptionsItemSelected(MenuItem item) {
132139
return true;
133140
}
134141

142+
@Override
143+
protected void onNewIntent(Intent intent) {
144+
super.onNewIntent(intent);
145+
try {
146+
Push.class.getMethod("checkLaunchedFromNotification", Activity.class, Intent.class).invoke(null, this, intent);
147+
} catch (Exception ignored) {
148+
}
149+
}
150+
135151
private AnalyticsListener getAnalyticsListener() {
136152
return new AnalyticsListener() {
137153

@@ -179,6 +195,79 @@ public void onSendingSucceeded(com.microsoft.azure.mobile.ingestion.models.Log l
179195
};
180196
}
181197

198+
@NonNull
199+
private AbstractCrashesListener getCrashesListener() {
200+
return new AbstractCrashesListener() {
201+
202+
@Override
203+
public boolean shouldAwaitUserConfirmation() {
204+
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
205+
builder
206+
.setTitle(R.string.crash_confirmation_dialog_title)
207+
.setMessage(R.string.crash_confirmation_dialog_message)
208+
.setPositiveButton(R.string.crash_confirmation_dialog_send_button, new DialogInterface.OnClickListener() {
209+
@Override
210+
public void onClick(DialogInterface dialog, int which) {
211+
Crashes.notifyUserConfirmation(Crashes.SEND);
212+
}
213+
})
214+
.setNegativeButton(R.string.crash_confirmation_dialog_not_send_button, new DialogInterface.OnClickListener() {
215+
@Override
216+
public void onClick(DialogInterface dialog, int which) {
217+
Crashes.notifyUserConfirmation(Crashes.DONT_SEND);
218+
}
219+
})
220+
.setNeutralButton(R.string.crash_confirmation_dialog_always_send_button, new DialogInterface.OnClickListener() {
221+
@Override
222+
public void onClick(DialogInterface dialog, int which) {
223+
Crashes.notifyUserConfirmation(Crashes.ALWAYS_SEND);
224+
}
225+
});
226+
builder.create().show();
227+
return true;
228+
}
229+
230+
@Override
231+
public Iterable<ErrorAttachmentLog> getErrorAttachments(ErrorReport report) {
232+
233+
/* Attach some text. */
234+
ErrorAttachmentLog textLog = ErrorAttachmentLog.attachmentWithText("This is a text attachment.", "text.txt");
235+
236+
/* Attach app icon to test binary. */
237+
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
238+
ByteArrayOutputStream stream = new ByteArrayOutputStream();
239+
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
240+
byte[] bitMapData = stream.toByteArray();
241+
ErrorAttachmentLog binaryLog = ErrorAttachmentLog.attachmentWithBinary(bitMapData, "icon.jpeg", "image/jpeg");
242+
243+
/* Return attachments as list. */
244+
return Arrays.asList(textLog, binaryLog);
245+
}
246+
247+
@Override
248+
public void onBeforeSending(ErrorReport report) {
249+
Toast.makeText(MainActivity.this, R.string.crash_before_sending, Toast.LENGTH_SHORT).show();
250+
crashesIdlingResource.increment();
251+
}
252+
253+
@Override
254+
public void onSendingFailed(ErrorReport report, Exception e) {
255+
Toast.makeText(MainActivity.this, R.string.crash_sent_failed, Toast.LENGTH_SHORT).show();
256+
crashesIdlingResource.decrement();
257+
}
258+
259+
@Override
260+
public void onSendingSucceeded(ErrorReport report) {
261+
String message = String.format("%s\nCrash ID: %s", getString(R.string.crash_sent_succeeded), report.getId());
262+
if (report.getThrowable() != null) {
263+
message += String.format("\nThrowable: %s", report.getThrowable().toString());
264+
}
265+
Toast.makeText(MainActivity.this, message, Toast.LENGTH_SHORT).show();
266+
crashesIdlingResource.decrement();
267+
}
268+
};
269+
}
270+
182271
@NonNull
183272
private PushListener getPushListener() {
184273
return new PushListener() {

apps/sasquatch/src/main/java/com/microsoft/azure/mobile/sasquatch/utils/SasquatchCrashesListener.java

Lines changed: 0 additions & 89 deletions
This file was deleted.

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ buildscript {
99
}
1010

1111
dependencies {
12-
classpath 'com.android.tools.build:gradle:2.3.2'
12+
classpath 'com.android.tools.build:gradle:2.3.3'
1313
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7'
1414
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
1515
classpath 'com.google.gms:google-services:3.0.0'

gradle/wrapper/gradle-wrapper.jar

0 Bytes
Binary file not shown.

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#Wed May 17 17:09:08 PDT 2017
1+
#Fri Jun 09 15:55:05 PDT 2017
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME

sdk/mobile-center-analytics/src/androidTest/java/com/microsoft/azure/mobile/analytics/AnalyticsAndroidTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package com.microsoft.azure.mobile.analytics;
22

33
import android.annotation.SuppressLint;
4+
import android.app.Application;
45
import android.content.Context;
56
import android.support.test.InstrumentationRegistry;
67

7-
import com.microsoft.azure.mobile.Constants;
8+
import com.microsoft.azure.mobile.MobileCenter;
89
import com.microsoft.azure.mobile.analytics.channel.AnalyticsListener;
910
import com.microsoft.azure.mobile.analytics.ingestion.models.EventLog;
1011
import com.microsoft.azure.mobile.channel.Channel;
@@ -41,8 +42,7 @@ public class AnalyticsAndroidTest {
4142
public static void setUpClass() {
4243
MobileCenterLog.setLogLevel(android.util.Log.VERBOSE);
4344
sContext = InstrumentationRegistry.getContext();
44-
Constants.loadFromContext(sContext);
45-
StorageHelper.initialize(sContext);
45+
MobileCenter.configure((Application) sContext.getApplicationContext(), "dummy");
4646
}
4747

4848
@Before
@@ -54,7 +54,6 @@ public void cleanup() {
5454

5555
@Test
5656
public void testAnalyticsListener() {
57-
5857
AnalyticsListener analyticsListener = mock(AnalyticsListener.class);
5958
Analytics.setListener(analyticsListener);
6059
Channel channel = mock(Channel.class);

sdk/mobile-center-analytics/src/main/java/com/microsoft/azure/mobile/analytics/channel/SessionTracker.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.microsoft.azure.mobile.analytics.ingestion.models.StartSessionLog;
88
import com.microsoft.azure.mobile.channel.Channel;
99
import com.microsoft.azure.mobile.ingestion.models.Log;
10+
import com.microsoft.azure.mobile.ingestion.models.StartServiceLog;
1011
import com.microsoft.azure.mobile.utils.MobileCenterLog;
1112
import com.microsoft.azure.mobile.utils.UUIDUtils;
1213
import com.microsoft.azure.mobile.utils.storage.StorageHelper;
@@ -110,9 +111,13 @@ public SessionTracker(Channel channel, String groupName) {
110111
@Override
111112
public synchronized void onEnqueuingLog(@NonNull Log log, @NonNull String groupName) {
112113

113-
/* Since we enqueue start session logs, skip them to avoid infinite loop. */
114-
if (log instanceof StartSessionLog)
114+
/*
115+
* Since we enqueue start session logs, skip them to avoid infinite loop.
116+
* Also skip start service log as it's always sent and should not trigger a session.
117+
*/
118+
if (log instanceof StartSessionLog || log instanceof StartServiceLog) {
115119
return;
120+
}
116121

117122
/*
118123
* If the log has already specified a timestamp, try correlating with a past session.
@@ -143,7 +148,7 @@ public synchronized void onEnqueuingLog(@NonNull Log log, @NonNull String groupN
143148
* Generate a new session identifier if the first time or
144149
* we went in background for more X seconds or
145150
* if enough time has elapsed since the last background usage of the API.
146-
*
151+
* <p>
147152
* Indeed the API can be used for events or crashes only for example, we need to renew
148153
* the session even when no pages are triggered but at the same time we want to keep using
149154
* the same session as long as the current activity is not paused (long video for example).
@@ -167,6 +172,12 @@ private void sendStartSessionIfNeeded() {
167172
sessionStorage.add(session.getKey() + STORAGE_KEY_VALUE_SEPARATOR + session.getValue());
168173
StorageHelper.PreferencesStorage.putStringSet(STORAGE_KEY, sessionStorage);
169174

175+
/*
176+
* Record queued time for the session log itself to avoid double log if resuming
177+
* from background after timeout and sending a log at same time we resume like a page.
178+
*/
179+
mLastQueuedLogTime = SystemClock.elapsedRealtime();
180+
170181
/* Enqueue a start session log. */
171182
StartSessionLog startSessionLog = new StartSessionLog();
172183
startSessionLog.setSid(mSid);

0 commit comments

Comments
 (0)