Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Team decided to do a breaking change in getErrorReport #306

Merged
merged 2 commits into from
Jan 19, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.StrictMode;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
Expand All @@ -17,6 +17,7 @@
import android.widget.Toast;

import com.microsoft.azure.mobile.MobileCenter;
import com.microsoft.azure.mobile.ResultCallback;
import com.microsoft.azure.mobile.analytics.Analytics;
import com.microsoft.azure.mobile.crashes.AbstractCrashesListener;
import com.microsoft.azure.mobile.crashes.Crashes;
Expand Down Expand Up @@ -55,16 +56,15 @@ protected void onCreate(Bundle savedInstanceState) {
MobileCenter.start(getApplication(), getAppSecret(), Analytics.class, Crashes.class);

Log.i(LOG_TAG, "Crashes.hasCrashedInLastSession=" + Crashes.hasCrashedInLastSession());
new AsyncTask<Void, Void, Void>() {
Crashes.getLastSessionCrashReport(new ResultCallback<ErrorReport>() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should wait for new binaries for this change. We don't have this method available in jcenter.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops


@Override
protected Void doInBackground(Void[] params) {
ErrorReport lastSessionCrashReport = Crashes.getLastSessionCrashReport();
if (lastSessionCrashReport != null) {
Log.i(LOG_TAG, "Crashes.getLastSessionCrashReport().getThrowable()=", lastSessionCrashReport.getThrowable());
public void onResult(@Nullable ErrorReport data) {
if (data != null) {
Log.i(LOG_TAG, "Crashes.getLastSessionCrashReport().getThrowable()=", data.getThrowable());
}
return null;
}
}.execute();
});

((TextView) findViewById(R.id.package_name)).setText(String.format(getString(R.string.sdk_source_format), getPackageName().substring(getPackageName().lastIndexOf(".") + 1)));
TestFeatures.initialize(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public Object answer(InvocationOnMock invocationOnMock) throws Throwable {

/* Check last session error report. */
assertTrue(Crashes.hasCrashedInLastSession());
Crashes.getLastSessionCrashReportAsync(new ResultCallback<ErrorReport>() {
Crashes.getLastSessionCrashReport(new ResultCallback<ErrorReport>() {

@Override
public void onResult(ErrorReport errorReport) {
Expand Down Expand Up @@ -193,7 +193,7 @@ public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
Crashes.getInstance().onChannelReady(sContext, channel);
waitForCrashesHandlerTasksToComplete();
assertFalse(Crashes.hasCrashedInLastSession());
Crashes.getLastSessionCrashReportAsync(new ResultCallback<ErrorReport>() {
Crashes.getLastSessionCrashReport(new ResultCallback<ErrorReport>() {

@Override
public void onResult(ErrorReport errorReport) {
Expand Down Expand Up @@ -277,7 +277,7 @@ public void run() {
Crashes.unsetInstance();
Crashes.getInstance().onChannelReady(sContext, channel);
waitForCrashesHandlerTasksToComplete();
Crashes.getLastSessionCrashReportAsync(new ResultCallback<ErrorReport>() {
Crashes.getLastSessionCrashReport(new ResultCallback<ErrorReport>() {

@Override
public void onResult(ErrorReport errorReport) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,14 @@ public static boolean hasCrashedInLastSession() {
/**
* Provides information about any available crash report from the last session, if it crashed.
* This method is a synchronous call and blocks caller thread.
* Use {@link #getLastSessionCrashReportAsync(ResultCallback)} for asynchronous call.
* Use {@link #getLastSessionCrashReport(ResultCallback)} for asynchronous call.
*
* @return The crash report from the last session if one was set.
* @see #getLastSessionCrashReportAsync(ResultCallback)
* @see #getLastSessionCrashReport(ResultCallback)
*/
@Nullable
@WorkerThread
public static ErrorReport getLastSessionCrashReport() {
static ErrorReport getLastSessionCrashReport() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of this, can you call getInstance().getInstanceLastSessionCrashReport() directly from Xamarin?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe not because it is private?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to check something before I can answer that.

return getInstance().getInstanceLastSessionCrashReport();
}

Expand All @@ -279,8 +279,8 @@ public static ErrorReport getLastSessionCrashReport() {
*
* @param callback The callback that will receive crash in the last session.
*/
public static void getLastSessionCrashReportAsync(ResultCallback<ErrorReport> callback) {
getInstance().getInstanceLastSessionCrashReportAsync(callback);
public static void getLastSessionCrashReport(ResultCallback<ErrorReport> callback) {
getInstance().getInstanceLastSessionCrashReport(callback);
}

/**
Expand All @@ -306,9 +306,9 @@ private synchronized ErrorReport getInstanceLastSessionCrashReport() {
}

/**
* Implements {@link #getLastSessionCrashReportAsync(ResultCallback)} at instance level.
* Implements {@link #getLastSessionCrashReport(ResultCallback)} at instance level.
*/
private synchronized void getInstanceLastSessionCrashReportAsync(final ResultCallback<ErrorReport> callback) {
private synchronized void getInstanceLastSessionCrashReport(final ResultCallback<ErrorReport> callback) {
if (mCountDownLatch == null || mCountDownLatch.getCount() <= 0)
HandlerUtils.runOnUiThread(new Runnable() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -865,10 +865,10 @@ public void onResult(ErrorReport data) {
}
};

Crashes.getLastSessionCrashReportAsync(callback);
Crashes.getLastSessionCrashReport(callback);
Crashes.getInstance().onChannelReady(mock(Context.class), mock(Channel.class));
assertFalse(Crashes.hasCrashedInLastSession());
Crashes.getLastSessionCrashReportAsync(callback);
Crashes.getLastSessionCrashReport(callback);
}

@Test
Expand Down Expand Up @@ -911,8 +911,8 @@ public void onResult(ErrorReport data) {
public String answer(InvocationOnMock invocation) throws Throwable {

/* Call twice for multiple listeners during initialize. */
Crashes.getLastSessionCrashReportAsync(callback);
Crashes.getLastSessionCrashReportAsync(callback);
Crashes.getLastSessionCrashReport(callback);
Crashes.getLastSessionCrashReport(callback);
return "";
}
});
Expand All @@ -930,7 +930,7 @@ public String answer(InvocationOnMock invocation) throws Throwable {

assertTrue(Crashes.hasCrashedInLastSession());

Crashes.getLastSessionCrashReportAsync(new ResultCallback<ErrorReport>() {
Crashes.getLastSessionCrashReport(new ResultCallback<ErrorReport>() {

@Override
public void onResult(ErrorReport errorReport) {
Expand All @@ -954,7 +954,7 @@ public void noCrashInLastSessionWhenDisabled() {
Crashes.setEnabled(false);

assertFalse(Crashes.hasCrashedInLastSession());
Crashes.getLastSessionCrashReportAsync(new ResultCallback<ErrorReport>() {
Crashes.getLastSessionCrashReport(new ResultCallback<ErrorReport>() {

@Override
public void onResult(ErrorReport data) {
Expand Down Expand Up @@ -997,11 +997,11 @@ public void onResult(ErrorReport data) {
* Here the service is enabled by default but we are waiting channel to be ready, simulate that.
*/
assertTrue(Crashes.isEnabled());
Crashes.getLastSessionCrashReportAsync(callback);
Crashes.getLastSessionCrashReport(callback);
Crashes.getInstance().onChannelReady(mock(Context.class), mock(Channel.class));

assertFalse(Crashes.hasCrashedInLastSession());
Crashes.getLastSessionCrashReportAsync(callback);
Crashes.getLastSessionCrashReport(callback);

/*
* De-serializing fails twice: processing the log from last time as part of the bulk processing.
Expand All @@ -1019,7 +1019,7 @@ public void crashInLastSessionCorrupted() throws IOException {
when(ErrorLogHelper.getLastErrorLogFile()).thenReturn(file);
Crashes.getInstance().onChannelReady(mock(Context.class), mock(Channel.class));
assertFalse(Crashes.hasCrashedInLastSession());
Crashes.getLastSessionCrashReportAsync(new ResultCallback<ErrorReport>() {
Crashes.getLastSessionCrashReport(new ResultCallback<ErrorReport>() {

@Override
public void onResult(ErrorReport data) {
Expand All @@ -1043,8 +1043,8 @@ public void onResult(ErrorReport data) {
};

/* Call twice for multiple callbacks before initialize. */
Crashes.getLastSessionCrashReportAsync(callback);
Crashes.getLastSessionCrashReportAsync(callback);
Crashes.getLastSessionCrashReport(callback);
Crashes.getLastSessionCrashReport(callback);
Crashes.getInstance().onChannelReady(mock(Context.class), mock(Channel.class));
assertFalse(Crashes.hasCrashedInLastSession());
}
Expand Down