Skip to content

Commit 6dca811

Browse files
authored
Merge pull request #444 from Microsoft/develop
v0.9.0
2 parents e610f07 + 56dc64f commit 6dca811

File tree

28 files changed

+846
-721
lines changed

28 files changed

+846
-721
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.microsoft.azure.mobile.sasquatch.utils;
2+
3+
import android.support.v7.app.AppCompatActivity;
4+
5+
import com.microsoft.azure.mobile.crashes.CrashesListener;
6+
7+
/**
8+
* CrashesListener provider for jcenterDependency flavour.
9+
*/
10+
public class CrashesListenerProvider {
11+
public static CrashesListener provideCrashesListener(AppCompatActivity activity) {
12+
return new SasquatchCrashesListener(activity);
13+
}
14+
}

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

Lines changed: 3 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import android.app.Activity;
44
import android.content.Context;
5-
import android.content.DialogInterface;
65
import android.content.Intent;
76
import android.content.SharedPreferences;
87
import android.os.Bundle;
@@ -11,7 +10,6 @@
1110
import android.support.annotation.Nullable;
1211
import android.support.annotation.VisibleForTesting;
1312
import android.support.test.espresso.idling.CountingIdlingResource;
14-
import android.support.v7.app.AlertDialog;
1513
import android.support.v7.app.AppCompatActivity;
1614
import android.text.TextUtils;
1715
import android.util.Log;
@@ -28,7 +26,6 @@
2826
import com.microsoft.azure.mobile.analytics.channel.AnalyticsListener;
2927
import com.microsoft.azure.mobile.analytics.ingestion.models.EventLog;
3028
import com.microsoft.azure.mobile.analytics.ingestion.models.PageLog;
31-
import com.microsoft.azure.mobile.crashes.AbstractCrashesListener;
3229
import com.microsoft.azure.mobile.crashes.Crashes;
3330
import com.microsoft.azure.mobile.crashes.model.ErrorReport;
3431
import com.microsoft.azure.mobile.distribute.Distribute;
@@ -40,12 +37,14 @@
4037
import com.microsoft.azure.mobile.sasquatch.SasquatchDistributeListener;
4138
import com.microsoft.azure.mobile.sasquatch.features.TestFeatures;
4239
import com.microsoft.azure.mobile.sasquatch.features.TestFeaturesListAdapter;
40+
import com.microsoft.azure.mobile.sasquatch.utils.CrashesListenerProvider;
4341
import com.microsoft.azure.mobile.utils.MobileCenterLog;
4442

4543
import org.json.JSONObject;
4644

4745
import java.util.Map;
4846

47+
4948
public class MainActivity extends AppCompatActivity {
5049

5150
public static final String LOG_TAG = "MobileCenterSasquatch";
@@ -75,7 +74,7 @@ protected void onCreate(Bundle savedInstanceState) {
7574

7675
/* Set listeners. */
7776
AnalyticsPrivateHelper.setListener(getAnalyticsListener());
78-
Crashes.setListener(getCrashesListener());
77+
Crashes.setListener(CrashesListenerProvider.provideCrashesListener(this));
7978
Distribute.setListener(new SasquatchDistributeListener());
8079
Push.setListener(getPushListener());
8180

@@ -133,67 +132,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
133132
return true;
134133
}
135134

136-
private AbstractCrashesListener getCrashesListener() {
137-
return new AbstractCrashesListener() {
138-
@Override
139-
public boolean shouldAwaitUserConfirmation() {
140-
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
141-
builder
142-
.setTitle(R.string.crash_confirmation_dialog_title)
143-
.setMessage(R.string.crash_confirmation_dialog_message)
144-
.setPositiveButton(R.string.crash_confirmation_dialog_send_button, new DialogInterface.OnClickListener() {
145-
@Override
146-
public void onClick(DialogInterface dialog, int which) {
147-
Crashes.notifyUserConfirmation(Crashes.SEND);
148-
}
149-
})
150-
.setNegativeButton(R.string.crash_confirmation_dialog_not_send_button, new DialogInterface.OnClickListener() {
151-
@Override
152-
public void onClick(DialogInterface dialog, int which) {
153-
Crashes.notifyUserConfirmation(Crashes.DONT_SEND);
154-
}
155-
})
156-
.setNeutralButton(R.string.crash_confirmation_dialog_always_send_button, new DialogInterface.OnClickListener() {
157-
@Override
158-
public void onClick(DialogInterface dialog, int which) {
159-
Crashes.notifyUserConfirmation(Crashes.ALWAYS_SEND);
160-
}
161-
});
162-
builder.create().show();
163-
return true;
164-
}
165-
166-
/* TODO (getErrorAttachment): Re-enable error attachment when the feature becomes available. */
167-
// @Override
168-
// public ErrorAttachment getErrorAttachment(ErrorReport report) {
169-
// return ErrorAttachments.attachment("This is a text attachment.", "This is a binary attachment.".getBytes(), "binary.txt", "text/plain");
170-
// }
171-
172-
@Override
173-
public void onBeforeSending(ErrorReport report) {
174-
Toast.makeText(MainActivity.this, R.string.crash_before_sending, Toast.LENGTH_SHORT).show();
175-
crashesIdlingResource.increment();
176-
}
177-
178-
@Override
179-
public void onSendingFailed(ErrorReport report, Exception e) {
180-
Toast.makeText(MainActivity.this, R.string.crash_sent_failed, Toast.LENGTH_SHORT).show();
181-
crashesIdlingResource.decrement();
182-
}
183-
184-
@Override
185-
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
186-
public void onSendingSucceeded(ErrorReport report) {
187-
String message = String.format("%s\nCrash ID: %s", getString(R.string.crash_sent_succeeded), report.getId());
188-
if (report.getThrowable() != null) {
189-
message += String.format("\nThrowable: %s", report.getThrowable().toString());
190-
}
191-
Toast.makeText(MainActivity.this, message, Toast.LENGTH_SHORT).show();
192-
crashesIdlingResource.decrement();
193-
}
194-
};
195-
}
196-
197135
private AnalyticsListener getAnalyticsListener() {
198136
return new AnalyticsListener() {
199137

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.microsoft.azure.mobile.sasquatch.utils;
2+
3+
import android.content.DialogInterface;
4+
import android.support.v7.app.AlertDialog;
5+
import android.support.v7.app.AppCompatActivity;
6+
import android.widget.Toast;
7+
8+
import com.microsoft.azure.mobile.crashes.AbstractCrashesListener;
9+
import com.microsoft.azure.mobile.crashes.Crashes;
10+
import com.microsoft.azure.mobile.crashes.model.ErrorReport;
11+
12+
class SasquatchCrashesListener extends AbstractCrashesListener {
13+
14+
private final AppCompatActivity activity;
15+
16+
SasquatchCrashesListener(AppCompatActivity activity) {
17+
this.activity = activity;
18+
}
19+
20+
@Override
21+
public boolean shouldAwaitUserConfirmation() {
22+
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
23+
builder
24+
.setTitle(com.microsoft.azure.mobile.sasquatch.R.string.crash_confirmation_dialog_title)
25+
.setMessage(com.microsoft.azure.mobile.sasquatch.R.string.crash_confirmation_dialog_message)
26+
.setPositiveButton(com.microsoft.azure.mobile.sasquatch.R.string.crash_confirmation_dialog_send_button, new DialogInterface.OnClickListener() {
27+
@Override
28+
public void onClick(DialogInterface dialog, int which) {
29+
Crashes.notifyUserConfirmation(Crashes.SEND);
30+
}
31+
})
32+
.setNegativeButton(com.microsoft.azure.mobile.sasquatch.R.string.crash_confirmation_dialog_not_send_button, new DialogInterface.OnClickListener() {
33+
@Override
34+
public void onClick(DialogInterface dialog, int which) {
35+
Crashes.notifyUserConfirmation(Crashes.DONT_SEND);
36+
}
37+
})
38+
.setNeutralButton(com.microsoft.azure.mobile.sasquatch.R.string.crash_confirmation_dialog_always_send_button, new DialogInterface.OnClickListener() {
39+
@Override
40+
public void onClick(DialogInterface dialog, int which) {
41+
Crashes.notifyUserConfirmation(Crashes.ALWAYS_SEND);
42+
}
43+
});
44+
builder.create().show();
45+
return true;
46+
}
47+
48+
@Override
49+
public void onBeforeSending(ErrorReport report) {
50+
Toast.makeText(activity, com.microsoft.azure.mobile.sasquatch.R.string.crash_before_sending, Toast.LENGTH_SHORT).show();
51+
}
52+
53+
@Override
54+
public void onSendingFailed(ErrorReport report, Exception e) {
55+
Toast.makeText(activity, com.microsoft.azure.mobile.sasquatch.R.string.crash_sent_failed, Toast.LENGTH_SHORT).show();
56+
}
57+
58+
@Override
59+
public void onSendingSucceeded(ErrorReport report) {
60+
61+
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
62+
String message = String.format("%s\nCrash ID: %s\nThrowable: %s", com.microsoft.azure.mobile.sasquatch.R.string.crash_sent_succeeded, report.getId(), report.getThrowable().toString());
63+
Toast.makeText(activity, message, Toast.LENGTH_LONG).show();
64+
}
65+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.microsoft.azure.mobile.sasquatch.utils;
2+
3+
import android.graphics.Bitmap;
4+
import android.graphics.BitmapFactory;
5+
import android.support.v7.app.AppCompatActivity;
6+
7+
import com.microsoft.azure.mobile.crashes.CrashesListener;
8+
import com.microsoft.azure.mobile.crashes.ingestion.models.ErrorAttachmentLog;
9+
import com.microsoft.azure.mobile.crashes.model.ErrorReport;
10+
import com.microsoft.azure.mobile.sasquatch.R;
11+
12+
import java.io.ByteArrayOutputStream;
13+
import java.util.Arrays;
14+
15+
/**
16+
* CrashesListener provider for projectDependency flavour.
17+
*/
18+
public class CrashesListenerProvider {
19+
public static CrashesListener provideCrashesListener(final AppCompatActivity activity) {
20+
21+
return new SasquatchCrashesListener(activity) {
22+
23+
@Override
24+
public Iterable<ErrorAttachmentLog> getErrorAttachments(ErrorReport report) {
25+
26+
/* Attach some text. */
27+
ErrorAttachmentLog textLog = ErrorAttachmentLog.attachmentWithText("This is a text attachment.", "text.txt");
28+
29+
/* Attach app icon to test binary. */
30+
Bitmap bitmap = BitmapFactory.decodeResource(activity.getResources(), R.mipmap.ic_launcher);
31+
ByteArrayOutputStream stream = new ByteArrayOutputStream();
32+
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
33+
byte[] bitMapData = stream.toByteArray();
34+
ErrorAttachmentLog binaryLog = ErrorAttachmentLog.attachmentWithBinary(bitMapData, "icon.jpeg", "image/jpeg");
35+
36+
/* Return attachments as list. */
37+
return Arrays.asList(textLog, binaryLog);
38+
}
39+
};
40+
}
41+
}

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.1'
12+
classpath 'com.android.tools.build:gradle:2.3.2'
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-
#Thu Apr 06 11:32:15 PDT 2017
1+
#Wed May 17 17:09:08 PDT 2017
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME

sdk/mobile-center-analytics/src/test/java/com/microsoft/azure/mobile/analytics/AnalyticsTest.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.util.Map;
3737
import java.util.UUID;
3838

39+
import static com.microsoft.azure.mobile.test.TestUtils.generateString;
3940
import static org.junit.Assert.assertEquals;
4041
import static org.junit.Assert.assertFalse;
4142
import static org.junit.Assert.assertNotNull;
@@ -496,17 +497,6 @@ public void testAnalyticsListenerNull() {
496497
verify(analyticsListener, never()).onSendingFailed(any(EventLog.class), any(Exception.class));
497498
}
498499

499-
/**
500-
* Generates string of arbitrary length with contents composed of single character.
501-
*
502-
* @param length length of the resulting string.
503-
* @param charToFill character to compose string of.
504-
* @return <code>String</code> of desired length.
505-
*/
506-
private String generateString(int length, char charToFill) {
507-
return new String(new char[length]).replace('\0', charToFill);
508-
}
509-
510500
/**
511501
* Activity with page name automatically resolving to "My" (no "Activity" suffix).
512502
*/

sdk/mobile-center-crashes/src/androidTest/java/com/microsoft/azure/mobile/crashes/CrashesAndroidTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,7 @@ public void onResult(ErrorReport errorReport) {
172172
assertNotNull(log.get());
173173
assertEquals(1, ErrorLogHelper.getErrorStorageDirectory().listFiles().length);
174174

175-
/* TODO (getErrorAttachment): Re-enable error attachment when the feature becomes available. */
176-
// verify(crashesListener).getErrorAttachment(any(ErrorReport.class));
175+
verify(crashesListener).getErrorAttachments(any(ErrorReport.class));
177176
verifyNoMoreInteractions(crashesListener);
178177

179178
/* Third process: sending succeeds. */

0 commit comments

Comments
 (0)