Skip to content

Commit a594a82

Browse files
authored
Merge pull request #364 from Microsoft/feature/distribute/prod_testing
Use pre-release in test app, fix API URL
2 parents 4365c42 + 698ce78 commit a594a82

File tree

7 files changed

+48
-60
lines changed

7 files changed

+48
-60
lines changed

apps/sasquatch/build.gradle

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,19 @@ android {
2121
}
2222
}
2323

24+
repositories {
25+
maven {
26+
url "http://dl.bintray.com/mobile-center/mobile-center-snapshot"
27+
}
28+
}
29+
2430
dependencies {
25-
def version = "0.5.0"
31+
def version = "0.6.0-3"
2632
compile "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
2733
projectDependencyCompile project(':sdk:mobile-center-analytics')
2834
projectDependencyCompile project(':sdk:mobile-center-crashes')
2935
projectDependencyCompile project(':sdk:mobile-center-distribute')
3036
jcenterDependencyCompile "com.microsoft.azure.mobile:mobile-center-analytics:${version}"
3137
jcenterDependencyCompile "com.microsoft.azure.mobile:mobile-center-crashes:${version}"
38+
jcenterDependencyCompile "com.microsoft.azure.mobile:mobile-center-distribute:${version}"
3239
}

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

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,15 @@
1818
import android.widget.Toast;
1919

2020
import com.microsoft.azure.mobile.MobileCenter;
21-
import com.microsoft.azure.mobile.MobileCenterService;
2221
import com.microsoft.azure.mobile.ResultCallback;
2322
import com.microsoft.azure.mobile.analytics.Analytics;
2423
import com.microsoft.azure.mobile.crashes.AbstractCrashesListener;
2524
import com.microsoft.azure.mobile.crashes.Crashes;
2625
import com.microsoft.azure.mobile.crashes.model.ErrorReport;
26+
import com.microsoft.azure.mobile.distribute.Distribute;
2727
import com.microsoft.azure.mobile.sasquatch.R;
2828
import com.microsoft.azure.mobile.sasquatch.features.TestFeatures;
2929
import com.microsoft.azure.mobile.sasquatch.features.TestFeaturesListAdapter;
30-
import com.microsoft.azure.mobile.utils.MobileCenterLog;
31-
32-
import java.lang.reflect.Method;
3330

3431
public class MainActivity extends AppCompatActivity {
3532

@@ -49,33 +46,26 @@ protected void onCreate(Bundle savedInstanceState) {
4946
/* Set custom log URL if one was configured in settings. */
5047
String logUrl = sSharedPreferences.getString(LOG_URL_KEY, getString(R.string.log_url));
5148
if (!TextUtils.isEmpty(logUrl)) {
52-
try {
53-
54-
/* Method name changed and jCenter not yet updated so need to use reflection. */
55-
Method setLogUrl;
56-
try {
57-
setLogUrl = MobileCenter.class.getMethod("setLogUrl", String.class);
58-
} catch (NoSuchMethodException e) {
59-
setLogUrl = MobileCenter.class.getMethod("setServerUrl", String.class);
60-
}
61-
setLogUrl.invoke(null, logUrl);
62-
} catch (Exception e) {
63-
throw new RuntimeException(e);
64-
}
49+
MobileCenter.setLogUrl(logUrl);
6550
}
51+
52+
/* Set crash listener. */
6653
Crashes.setListener(getCrashesListener());
67-
MobileCenter.start(getApplication(), sSharedPreferences.getString(APP_SECRET_KEY, getString(R.string.app_secret)), Analytics.class, Crashes.class);
68-
try {
69-
70-
@SuppressWarnings("unchecked")
71-
Class<? extends MobileCenterService> distribute = (Class<? extends MobileCenterService>) Class.forName("com.microsoft.azure.mobile.distribute.Distribute");
72-
distribute.getMethod("setInstallUrl", String.class).invoke(null, "http://install.asgard-int.trafficmanager.net");
73-
distribute.getMethod("setApiUrl", String.class).invoke(null, "https://asgard-int.trafficmanager.net/api/v0.1");
74-
MobileCenter.start(distribute);
75-
} catch (Exception e) {
76-
MobileCenterLog.info(LOG_TAG, "Distribute class not yet available in this flavor.");
54+
55+
/* Set distribute urls. */
56+
String installUrl = getString(R.string.install_url);
57+
if (!TextUtils.isEmpty(installUrl)) {
58+
Distribute.setInstallUrl(installUrl);
59+
}
60+
String apiUrl = getString(R.string.api_url);
61+
if (!TextUtils.isEmpty(apiUrl)) {
62+
Distribute.setApiUrl(apiUrl);
7763
}
7864

65+
/* Start Mobile center. */
66+
MobileCenter.start(getApplication(), sSharedPreferences.getString(APP_SECRET_KEY, getString(R.string.app_secret)), Analytics.class, Crashes.class, Distribute.class);
67+
68+
/* Print last crash. */
7969
Log.i(LOG_TAG, "Crashes.hasCrashedInLastSession=" + Crashes.hasCrashedInLastSession());
8070
Crashes.getLastSessionCrashReport(new ResultCallback<ErrorReport>() {
8171

@@ -87,6 +77,7 @@ public void onResult(@Nullable ErrorReport data) {
8777
}
8878
});
8979

80+
/* Populate UI. */
9081
((TextView) findViewById(R.id.package_name)).setText(String.format(getString(R.string.sdk_source_format), getPackageName().substring(getPackageName().lastIndexOf(".") + 1)));
9182
TestFeatures.initialize(this);
9283
ListView listView = (ListView) findViewById(R.id.list);

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

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@
1616
import android.widget.Toast;
1717

1818
import com.microsoft.azure.mobile.MobileCenter;
19-
import com.microsoft.azure.mobile.MobileCenterService;
2019
import com.microsoft.azure.mobile.analytics.Analytics;
2120
import com.microsoft.azure.mobile.analytics.AnalyticsPrivateHelper;
2221
import com.microsoft.azure.mobile.crashes.Crashes;
22+
import com.microsoft.azure.mobile.distribute.Distribute;
2323
import com.microsoft.azure.mobile.sasquatch.R;
2424
import com.microsoft.azure.mobile.utils.PrefStorageConstants;
2525
import com.microsoft.azure.mobile.utils.storage.StorageHelper;
2626

27-
import java.lang.reflect.Method;
2827
import java.util.UUID;
2928

3029
import static com.microsoft.azure.mobile.sasquatch.activities.MainActivity.APP_SECRET_KEY;
@@ -91,36 +90,23 @@ public boolean isEnabled() {
9190
return Crashes.isEnabled();
9291
}
9392
});
94-
try {
95-
96-
@SuppressWarnings("unchecked")
97-
Class<? extends MobileCenterService> distribute = (Class<? extends MobileCenterService>) Class.forName("com.microsoft.azure.mobile.distribute.Distribute");
98-
final Method isEnabled = distribute.getMethod("isEnabled");
99-
final Method setEnabled = distribute.getMethod("setEnabled", boolean.class);
100-
initCheckBoxSetting(R.string.mobile_center_distribute_state_key, (boolean) isEnabled.invoke(null), R.string.mobile_center_distribute_state_summary_enabled, R.string.mobile_center_distribute_state_summary_disabled, new HasEnabled() {
101-
102-
@Override
103-
public void setEnabled(boolean enabled) {
104-
try {
105-
setEnabled.invoke(null, enabled);
106-
distributeEnabledPreference.setChecked((boolean) isEnabled.invoke(null));
107-
} catch (Exception e) {
108-
throw new RuntimeException(e);
109-
}
110-
}
93+
initCheckBoxSetting(R.string.mobile_center_distribute_state_key, Distribute.isEnabled(), R.string.mobile_center_distribute_state_summary_enabled, R.string.mobile_center_distribute_state_summary_disabled, new HasEnabled() {
11194

112-
@Override
113-
public boolean isEnabled() {
114-
try {
115-
return (boolean) isEnabled.invoke(null);
116-
} catch (Exception e) {
117-
throw new RuntimeException(e);
118-
}
95+
@Override
96+
public void setEnabled(boolean enabled) {
97+
try {
98+
Distribute.setEnabled(enabled);
99+
distributeEnabledPreference.setChecked(Distribute.isEnabled());
100+
} catch (Exception e) {
101+
throw new RuntimeException(e);
119102
}
120-
});
121-
} catch (Exception e) {
122-
getPreferenceScreen().removePreference(findPreference(getString(R.string.distribute_key)));
123-
}
103+
}
104+
105+
@Override
106+
public boolean isEnabled() {
107+
return Distribute.isEnabled();
108+
}
109+
});
124110
initCheckBoxSetting(R.string.mobile_center_auto_page_tracking_key, AnalyticsPrivateHelper.isAutoPageTrackingEnabled(), R.string.mobile_center_auto_page_tracking_enabled, R.string.mobile_center_auto_page_tracking_disabled, new HasEnabled() {
125111

126112
@Override

apps/sasquatch/src/main/res/values/env.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="TypographyDashes">
33
<string name="app_secret">45d1d9f6-2492-4e68-bd44-7190351eb5f3</string>
44
<string name="log_url"/>
5+
<string name="install_url"/>
6+
<string name="api_url">https://api.mobile.azure.com/v0.1</string> <!-- FIXME set to blank in 0.6.0-4 or more recent -->
57
</resources>

apps/sasquatch/src/projectDependency/res/values/env.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="TypographyDashes">
33
<string name="app_secret">9e0d97c1-7838-46d0-9dab-1a0ef66aec6e</string>
44
<string name="log_url">https://in-integration.dev.avalanch.es</string>
5+
<string name="install_url">http://install.asgard-int.trafficmanager.net</string>
6+
<string name="api_url">https://asgard-int.trafficmanager.net/api/v0.1</string>
57
</resources>

sdk/mobile-center-distribute/src/main/java/com/microsoft/azure/mobile/distribute/DistributeConstants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ final class DistributeConstants {
3838
/**
3939
* Base URL to call server to check latest release.
4040
*/
41-
static final String DEFAULT_API_URL = "https://api.mobile.azure.com";
41+
static final String DEFAULT_API_URL = "https://api.mobile.azure.com/v0.1";
4242

4343
/**
4444
* Update setup URL path. Contains the app secret variable to replace.

versions.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ ext {
77
targetSdkVersion = 25
88
compileSdkVersion = 25
99
buildToolsVersion = '25.0.2'
10-
supportLibVersion = '25.2.0'
10+
supportLibVersion = '25.3.0'
1111
}

0 commit comments

Comments
 (0)