Skip to content

Commit cb66ce6

Browse files
authored
Merge pull request #483 from Microsoft/develop
v0.11.0
2 parents e7ec001 + 0ce9135 commit cb66ce6

File tree

78 files changed

+3284
-2931
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+3284
-2931
lines changed

apps/sasquatch/src/androidTest/java/com/microsoft/azure/mobile/sasquatch/activities/CrashesTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ public void variableMessageTest() throws InterruptedException {
131131
* @param titleId Title string resource to find list item.
132132
* @throws InterruptedException If the current thread is interrupted.
133133
*/
134+
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
134135
private void crashTest(@StringRes int titleId) throws InterruptedException {
135136

136137
/* Crash. */
@@ -144,8 +145,8 @@ private void crashTest(@StringRes int titleId) throws InterruptedException {
144145
.perform(click());
145146

146147
/* Check error report. */
147-
assertTrue(Crashes.hasCrashedInLastSession());
148-
ErrorReport errorReport = CrashesPrivateHelper.getLastSessionCrashReport();
148+
assertTrue(GetHelper.hasCrashedInLastSession());
149+
ErrorReport errorReport = GetHelper.getLastSessionCrashReport();
149150
assertNotNull(errorReport);
150151
assertNotNull(errorReport.getId());
151152
assertEquals(mContext.getMainLooper().getThread().getName(), errorReport.getThreadName());

apps/sasquatch/src/androidTest/java/com/microsoft/azure/mobile/sasquatch/activities/SettingsActivityTest.java

Lines changed: 93 additions & 109 deletions
Large diffs are not rendered by default.
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package com.microsoft.azure.mobile.sasquatch.activities;
2+
3+
import android.support.annotation.Nullable;
4+
import android.util.Log;
5+
6+
import com.microsoft.azure.mobile.MobileCenter;
7+
import com.microsoft.azure.mobile.ResultCallback;
8+
import com.microsoft.azure.mobile.analytics.Analytics;
9+
import com.microsoft.azure.mobile.crashes.Crashes;
10+
import com.microsoft.azure.mobile.crashes.model.ErrorReport;
11+
import com.microsoft.azure.mobile.distribute.Distribute;
12+
import com.microsoft.azure.mobile.push.Push;
13+
14+
import java.util.UUID;
15+
import java.util.concurrent.Semaphore;
16+
import java.util.concurrent.atomic.AtomicReference;
17+
18+
import static com.microsoft.azure.mobile.sasquatch.activities.MainActivity.LOG_TAG;
19+
20+
class GetHelper {
21+
22+
static void testInstallIdAndLastSessionCrash() {
23+
24+
/* Print install ID. */
25+
Log.i(LOG_TAG, "InstallId=" + MobileCenter.getInstallId());
26+
27+
/* Print last crash. */
28+
Log.i(LOG_TAG, "Crashes.hasCrashedInLastSession=" + Crashes.hasCrashedInLastSession());
29+
Crashes.getLastSessionCrashReport(new ResultCallback<ErrorReport>() {
30+
31+
@Override
32+
public void onResult(@Nullable ErrorReport data) {
33+
if (data != null) {
34+
Log.i(LOG_TAG, "Crashes.getLastSessionCrashReport().getThrowable()=", data.getThrowable());
35+
}
36+
}
37+
});
38+
}
39+
40+
static UUID getInstallId() {
41+
return MobileCenter.getInstallId();
42+
}
43+
44+
static boolean hasCrashedInLastSession() {
45+
return Crashes.hasCrashedInLastSession();
46+
}
47+
48+
static ErrorReport getLastSessionCrashReport() {
49+
final Semaphore semaphore = new Semaphore(0);
50+
final AtomicReference<ErrorReport> errorReport = new AtomicReference<>();
51+
Crashes.getLastSessionCrashReport(new ResultCallback<ErrorReport>() {
52+
53+
@Override
54+
public void onResult(@Nullable ErrorReport data) {
55+
errorReport.set(data);
56+
semaphore.release();
57+
}
58+
});
59+
semaphore.acquireUninterruptibly();
60+
return errorReport.get();
61+
}
62+
63+
static boolean isMobileCenterEnabled() {
64+
return MobileCenter.isEnabled();
65+
}
66+
67+
static boolean isAnalyticsEnabled() {
68+
return Analytics.isEnabled();
69+
}
70+
71+
static boolean isCrashesEnabled() {
72+
return Crashes.isEnabled();
73+
}
74+
75+
static boolean isDistributeEnabled() {
76+
return Distribute.isEnabled();
77+
}
78+
79+
static boolean isPushEnabled() {
80+
return Push.isEnabled();
81+
}
82+
}
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.microsoft.azure.mobile.crashes;
22

3-
import com.microsoft.azure.mobile.crashes.model.ErrorReport;
4-
53
public final class CrashesPrivateHelper {
64

75
private CrashesPrivateHelper() {
@@ -14,8 +12,4 @@ public static void trackException(Throwable throwable) {
1412
public static void saveUncaughtException(Thread thread, Throwable exception) {
1513
Crashes.getInstance().saveUncaughtException(thread, exception);
1614
}
17-
18-
public static ErrorReport getLastSessionCrashReport() {
19-
return Crashes.getLastSessionCrashReport();
20-
}
2115
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ protected void onCreate(Bundle savedInstanceState) {
5757
@Override
5858
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
5959
View view = super.getView(position, convertView, parent);
60-
TextView text1 = (TextView) view.findViewById(android.R.id.text1);
61-
TextView text2 = (TextView) view.findViewById(android.R.id.text2);
60+
TextView text1 = view.findViewById(android.R.id.text1);
61+
TextView text2 = view.findViewById(android.R.id.text2);
6262

6363
text1.setText(list.get(position).title);
6464
text2.setText(list.get(position).value);

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
package com.microsoft.azure.mobile.sasquatch.activities;
22

33
import android.content.Context;
4-
import android.content.Intent;
54
import android.os.Bundle;
65
import android.support.v7.app.AppCompatActivity;
7-
import android.text.Editable;
86
import android.text.TextUtils;
9-
import android.text.TextWatcher;
107
import android.view.LayoutInflater;
118
import android.view.Menu;
129
import android.view.MenuItem;

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

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,18 @@
1010
import android.os.Bundle;
1111
import android.os.StrictMode;
1212
import android.support.annotation.NonNull;
13-
import android.support.annotation.Nullable;
1413
import android.support.annotation.VisibleForTesting;
1514
import android.support.test.espresso.idling.CountingIdlingResource;
1615
import android.support.v7.app.AlertDialog;
1716
import android.support.v7.app.AppCompatActivity;
1817
import android.text.TextUtils;
19-
import android.util.Log;
2018
import android.view.Menu;
2119
import android.view.MenuItem;
2220
import android.widget.ListView;
2321
import android.widget.TextView;
2422
import android.widget.Toast;
2523

2624
import com.microsoft.azure.mobile.MobileCenter;
27-
import com.microsoft.azure.mobile.ResultCallback;
2825
import com.microsoft.azure.mobile.analytics.Analytics;
2926
import com.microsoft.azure.mobile.analytics.AnalyticsPrivateHelper;
3027
import com.microsoft.azure.mobile.analytics.channel.AnalyticsListener;
@@ -103,17 +100,8 @@ protected void onCreate(Bundle savedInstanceState) {
103100
/* Start Mobile center. */
104101
MobileCenter.start(getApplication(), sSharedPreferences.getString(APP_SECRET_KEY, getString(R.string.app_secret)), Analytics.class, Crashes.class, Distribute.class, Push.class);
105102

106-
/* Print last crash. */
107-
Log.i(LOG_TAG, "Crashes.hasCrashedInLastSession=" + Crashes.hasCrashedInLastSession());
108-
Crashes.getLastSessionCrashReport(new ResultCallback<ErrorReport>() {
109-
110-
@Override
111-
public void onResult(@Nullable ErrorReport data) {
112-
if (data != null) {
113-
Log.i(LOG_TAG, "Crashes.getLastSessionCrashReport().getThrowable()=", data.getThrowable());
114-
}
115-
}
116-
});
103+
/* Use some mobile center getters. */
104+
GetHelper.testInstallIdAndLastSessionCrash();
117105

118106
/* Populate UI. */
119107
((TextView) findViewById(R.id.package_name)).setText(String.format(getString(R.string.sdk_source_format), getPackageName().substring(getPackageName().lastIndexOf(".") + 1)));
@@ -256,6 +244,7 @@ public void onSendingFailed(ErrorReport report, Exception e) {
256244
crashesIdlingResource.decrement();
257245
}
258246

247+
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
259248
@Override
260249
public void onSendingSucceeded(ErrorReport report) {
261250
String message = String.format("%s\nCrash ID: %s", getString(R.string.crash_sent_succeeded), report.getId());

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

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public void setEnabled(boolean enabled) {
6060

6161
@Override
6262
public boolean isEnabled() {
63-
return MobileCenter.isEnabled();
63+
return GetHelper.isMobileCenterEnabled();
6464
}
6565
});
6666
initCheckBoxSetting(R.string.mobile_center_analytics_state_key, R.string.mobile_center_analytics_state_summary_enabled, R.string.mobile_center_analytics_state_summary_disabled, new HasEnabled() {
@@ -72,7 +72,7 @@ public void setEnabled(boolean enabled) {
7272

7373
@Override
7474
public boolean isEnabled() {
75-
return Analytics.isEnabled();
75+
return GetHelper.isAnalyticsEnabled();
7676
}
7777
});
7878
initCheckBoxSetting(R.string.mobile_center_crashes_state_key, R.string.mobile_center_crashes_state_summary_enabled, R.string.mobile_center_crashes_state_summary_disabled, new HasEnabled() {
@@ -84,7 +84,7 @@ public void setEnabled(boolean enabled) {
8484

8585
@Override
8686
public boolean isEnabled() {
87-
return Crashes.isEnabled();
87+
return GetHelper.isCrashesEnabled();
8888
}
8989
});
9090
initCheckBoxSetting(R.string.mobile_center_distribute_state_key, R.string.mobile_center_distribute_state_summary_enabled, R.string.mobile_center_distribute_state_summary_disabled, new HasEnabled() {
@@ -96,46 +96,42 @@ public void setEnabled(boolean enabled) {
9696

9797
@Override
9898
public boolean isEnabled() {
99-
return Distribute.isEnabled();
99+
return GetHelper.isDistributeEnabled();
100100
}
101101
});
102-
try {
103-
initCheckBoxSetting(R.string.mobile_center_push_state_key, R.string.mobile_center_push_state_summary_enabled, R.string.mobile_center_push_state_summary_disabled, new HasEnabled() {
102+
initCheckBoxSetting(R.string.mobile_center_push_state_key, R.string.mobile_center_push_state_summary_enabled, R.string.mobile_center_push_state_summary_disabled, new HasEnabled() {
104103

105-
@Override
106-
public void setEnabled(boolean enabled) {
107-
Push.setEnabled(enabled);
108-
}
104+
@Override
105+
public void setEnabled(boolean enabled) {
106+
Push.setEnabled(enabled);
107+
}
109108

110-
@Override
111-
public boolean isEnabled() {
112-
return Push.isEnabled();
113-
}
114-
});
115-
initCheckBoxSetting(R.string.mobile_center_push_firebase_state_key, R.string.mobile_center_push_firebase_summary_enabled, R.string.mobile_center_push_firebase_summary_disabled, new HasEnabled() {
116-
117-
@Override
118-
public void setEnabled(boolean enabled) {
119-
try {
120-
if (enabled) {
121-
Push.enableFirebaseAnalytics(getActivity());
122-
} else {
123-
FirebaseAnalytics.getInstance(getActivity()).setAnalyticsCollectionEnabled(false);
124-
}
125-
MainActivity.sSharedPreferences.edit().putBoolean(FIREBASE_ENABLED_KEY, enabled).apply();
126-
} catch (Exception e) {
127-
throw new RuntimeException(e);
109+
@Override
110+
public boolean isEnabled() {
111+
return GetHelper.isPushEnabled();
112+
}
113+
});
114+
initCheckBoxSetting(R.string.mobile_center_push_firebase_state_key, R.string.mobile_center_push_firebase_summary_enabled, R.string.mobile_center_push_firebase_summary_disabled, new HasEnabled() {
115+
116+
@Override
117+
public void setEnabled(boolean enabled) {
118+
try {
119+
if (enabled) {
120+
Push.enableFirebaseAnalytics(getActivity());
121+
} else {
122+
FirebaseAnalytics.getInstance(getActivity()).setAnalyticsCollectionEnabled(false);
128123
}
124+
MainActivity.sSharedPreferences.edit().putBoolean(FIREBASE_ENABLED_KEY, enabled).apply();
125+
} catch (Exception e) {
126+
throw new RuntimeException(e);
129127
}
128+
}
130129

131-
@Override
132-
public boolean isEnabled() {
133-
return isFirebaseEnabled();
134-
}
135-
});
136-
} catch (Exception e) {
137-
getPreferenceScreen().removePreference(findPreference(getString(R.string.push_key)));
138-
}
130+
@Override
131+
public boolean isEnabled() {
132+
return isFirebaseEnabled();
133+
}
134+
});
139135
initCheckBoxSetting(R.string.mobile_center_auto_page_tracking_key, R.string.mobile_center_auto_page_tracking_enabled, R.string.mobile_center_auto_page_tracking_disabled, new HasEnabled() {
140136

141137
@Override
@@ -148,13 +144,13 @@ public void setEnabled(boolean enabled) {
148144
AnalyticsPrivateHelper.setAutoPageTrackingEnabled(enabled);
149145
}
150146
});
151-
initClickableSetting(R.string.install_id_key, String.valueOf(MobileCenter.getInstallId()), new Preference.OnPreferenceClickListener() {
147+
initClickableSetting(R.string.install_id_key, String.valueOf(GetHelper.getInstallId()), new Preference.OnPreferenceClickListener() {
152148

153149
@Override
154150
public boolean onPreferenceClick(final Preference preference) {
155151
final EditText input = new EditText(getActivity());
156152
input.setInputType(InputType.TYPE_CLASS_TEXT);
157-
input.setText(String.valueOf(MobileCenter.getInstallId()));
153+
input.setText(String.valueOf(GetHelper.getInstallId()));
158154

159155
new AlertDialog.Builder(getActivity()).setTitle(R.string.install_id_title).setView(input)
160156
.setPositiveButton(R.string.save, new DialogInterface.OnClickListener() {
@@ -167,7 +163,7 @@ public void onClick(DialogInterface dialog, int which) {
167163
} else {
168164
Toast.makeText(getActivity(), R.string.install_id_invalid, Toast.LENGTH_SHORT).show();
169165
}
170-
preference.setSummary(String.valueOf(MobileCenter.getInstallId()));
166+
preference.setSummary(String.valueOf(GetHelper.getInstallId()));
171167
}
172168
})
173169
.setNegativeButton(R.string.cancel, null)

apps/sasquatch/src/main/java/com/microsoft/azure/mobile/sasquatch/features/TestFeatures.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import android.view.View;
66
import android.widget.AdapterView;
77

8-
import com.microsoft.azure.mobile.crashes.Crashes;
98
import com.microsoft.azure.mobile.sasquatch.R;
109
import com.microsoft.azure.mobile.sasquatch.activities.CrashActivity;
1110
import com.microsoft.azure.mobile.sasquatch.activities.CustomPropertiesActivity;
@@ -31,7 +30,7 @@ public static void initialize(Activity parentActivity) {
3130
sTestFeatureModels.add(new TestFeature(R.string.title_event, R.string.description_event, EventActivity.class));
3231
sTestFeatureModels.add(new TestFeature(R.string.title_page, R.string.description_page, PageActivity.class));
3332
sTestFeatureModels.add(new TestFeature(R.string.title_generate_page_log, R.string.description_generate_page_log, DummyActivity.class));
34-
sTestFeatureModels.add(new TestFeatureTitle(Crashes.hasCrashedInLastSession() ? R.string.crashes_title_with_crash : R.string.crashes_title));
33+
sTestFeatureModels.add(new TestFeatureTitle(R.string.crashes_title));
3534
sTestFeatureModels.add(new TestFeature(R.string.title_crashes, R.string.description_crashes, CrashActivity.class));
3635
sTestFeatureModels.add(new TestFeature(R.string.title_error, R.string.description_error, ManagedErrorActivity.class));
3736
sTestFeatureModels.add(new TestFeatureTitle(R.string.miscellaneous_title));

apps/sasquatch/src/main/java/com/microsoft/azure/mobile/sasquatch/features/TestFeaturesListAdapter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
4747
rowView = convertView;
4848
} else {
4949
rowView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_title, parent, false);
50-
TextView titleView = ((TextView) rowView.findViewById(R.id.title));
50+
TextView titleView = rowView.findViewById(R.id.title);
5151
titleView.setText(((TestFeatures.TestFeatureTitle) item).getTitle());
5252
rowView.setTag(new ViewHolder(TestFeatures.TestFeatureTitle.class, titleView));
5353
}
@@ -60,8 +60,8 @@ public View getView(int position, View convertView, ViewGroup parent) {
6060
rowView = convertView;
6161
} else {
6262
rowView = LayoutInflater.from(parent.getContext()).inflate(android.R.layout.simple_list_item_2, parent, false);
63-
TextView titleView = ((TextView) rowView.findViewById(android.R.id.text1));
64-
TextView descriptionView = ((TextView) rowView.findViewById(android.R.id.text2));
63+
TextView titleView = rowView.findViewById(android.R.id.text1);
64+
TextView descriptionView = rowView.findViewById(android.R.id.text2);
6565
titleView.setText(model.getTitle());
6666
descriptionView.setText(model.getDescription());
6767
rowView.setTag(new ViewHolder(TestFeatures.TestFeatureModel.class, titleView, descriptionView));

0 commit comments

Comments
 (0)