Added BitBucket beta update channel

This commit is contained in:
M66B 2022-10-31 15:52:31 +01:00
parent 8c00260019
commit bb9fa8da64
5 changed files with 126 additions and 39 deletions

View File

@ -163,6 +163,8 @@ android {
buildConfigField "String", "CHANGELOG", "\"https://github.com/M66B/FairEmail/releases/\""
buildConfigField "String", "GITHUB_LATEST_API", "\"https://api.github.com/repos/M66B/FairEmail/releases/latest\""
buildConfigField "String", "GITHUB_LATEST_URI", "\"https://github.com/M66B/FairEmail/releases\""
buildConfigField "String", "BITBUCKET_DOWNLOADS_API", "\"https://api.bitbucket.org/2.0/repositories/M66B/fairemail-test/downloads\""
buildConfigField "String", "BITBUCKET_DOWNLOADS_URI", "\"https://bitbucket.org/M66B/fairemail-test/downloads/\""
buildConfigField "String", "TX_URI", localProperties.getProperty("paypal.uri", "\"\"")
buildConfigField "String", "GPA_URI", localProperties.getProperty("gpa.uri", "\"\"")
buildConfigField "String", "INFO_URI", localProperties.getProperty("info.uri", "\"\"")
@ -179,6 +181,8 @@ android {
buildConfigField "String", "CHANGELOG", "\"https://github.com/M66B/FairEmail/releases/\""
buildConfigField "String", "GITHUB_LATEST_API", "\"https://api.github.com/repos/M66B/FairEmail/releases/latest\""
buildConfigField "String", "GITHUB_LATEST_URI", "\"https://github.com/M66B/FairEmail/releases\""
buildConfigField "String", "BITBUCKET_DOWNLOADS_API", "\"https://api.bitbucket.org/2.0/repositories/M66B/fairemail-test/downloads\""
buildConfigField "String", "BITBUCKET_DOWNLOADS_URI", "\"https://bitbucket.org/M66B/fairemail-test/downloads/\""
buildConfigField "String", "TX_URI", "\"\""
buildConfigField "String", "GPA_URI", "\"\""
buildConfigField "String", "INFO_URI", "\"\""
@ -196,6 +200,8 @@ android {
buildConfigField "String", "CHANGELOG", "\"\""
buildConfigField "String", "GITHUB_LATEST_API", "\"\""
buildConfigField "String", "GITHUB_LATEST_URI", "\"\""
buildConfigField "String", "BITBUCKET_DOWNLOADS_API", "\"\""
buildConfigField "String", "BITBUCKET_DOWNLOADS_URI", "\"\""
buildConfigField "String", "TX_URI", "\"\""
buildConfigField "String", "GPA_URI", "\"\""
buildConfigField "String", "INFO_URI", "\"\""
@ -213,6 +219,8 @@ android {
buildConfigField "String", "CHANGELOG", "\"\""
buildConfigField "String", "GITHUB_LATEST_API", "\"\""
buildConfigField "String", "GITHUB_LATEST_URI", "\"\""
buildConfigField "String", "BITBUCKET_DOWNLOADS_API", "\"\""
buildConfigField "String", "BITBUCKET_DOWNLOADS_URI", "\"\""
buildConfigField "String", "TX_URI", "\"\""
buildConfigField "String", "GPA_URI", "\"\""
buildConfigField "String", "INFO_URI", "\"\""

View File

@ -1506,6 +1506,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean updates = prefs.getBoolean("updates", true);
boolean beta = prefs.getBoolean("beta", false);
boolean weekly = prefs.getBoolean("weekly", Helper.hasPlayStore(this));
long last_update_check = prefs.getLong("last_update_check", 0);
@ -1518,14 +1519,17 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
Bundle args = new Bundle();
args.putBoolean("always", always);
args.putBoolean("beta", beta);
new SimpleTask<UpdateInfo>() {
@Override
protected UpdateInfo onExecute(Context context, Bundle args) throws Throwable {
boolean beta = args.getBoolean("beta");
StringBuilder response = new StringBuilder();
HttpsURLConnection urlConnection = null;
try {
URL latest = new URL(BuildConfig.GITHUB_LATEST_API);
URL latest = new URL(beta ? BuildConfig.BITBUCKET_DOWNLOADS_API : BuildConfig.GITHUB_LATEST_API);
urlConnection = (HttpsURLConnection) latest.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setReadTimeout(UPDATE_TIMEOUT);
@ -1551,50 +1555,100 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
JSONObject jmessage = new JSONObject(response.toString());
if (jmessage.has("message"))
throw new IllegalArgumentException(jmessage.getString("message"));
throw new IOException("HTTP " + status + ": " + response.toString());
throw new IOException("HTTP " + status + ": " + response);
}
if (status != HttpsURLConnection.HTTP_OK)
throw new IOException("HTTP " + status + ": " + response.toString());
throw new IOException("HTTP " + status + ": " + response);
JSONObject jroot = new JSONObject(response.toString());
if (!jroot.has("tag_name") || jroot.isNull("tag_name"))
throw new IOException("tag_name field missing");
//if (!jroot.has("html_url") || jroot.isNull("html_url"))
// throw new IOException("html_url field missing");
if (!jroot.has("assets") || jroot.isNull("assets"))
throw new IOException("assets section missing");
if (beta) {
if (!jroot.has("values"))
throw new IOException("values field missing");
// Get update info
UpdateInfo info = new UpdateInfo();
info.tag_name = jroot.getString("tag_name");
info.html_url = jroot.getString("html_url");
//if (TextUtils.isEmpty(info.html_url))
info.html_url = BuildConfig.GITHUB_LATEST_URI;
JSONArray jvalues = jroot.getJSONArray("values");
for (int i = 0; i < jvalues.length(); i++) {
JSONObject jitem = jvalues.getJSONObject(i);
if (!jitem.has("links"))
continue;
// Check if new release
JSONArray jassets = jroot.getJSONArray("assets");
for (int i = 0; i < jassets.length(); i++) {
JSONObject jasset = jassets.getJSONObject(i);
if (jasset.has("name") && !jasset.isNull("name")) {
String name = jasset.getString("name");
if (name.endsWith(".apk")) {
info.download_url = jasset.optString("browser_download_url");
Log.i("Latest version=" + info.tag_name);
if (BuildConfig.DEBUG)
return info;
try {
if (Double.parseDouble(info.tag_name) <=
Double.parseDouble(BuildConfig.VERSION_NAME))
return null;
else
return info;
} catch (Throwable ex) {
Log.e(ex);
if (BuildConfig.VERSION_NAME.equals(info.tag_name))
return null;
else
JSONObject jlinks = jitem.getJSONObject("links");
if (!jlinks.has("self"))
continue;
JSONObject jself = jlinks.getJSONObject("self");
if (!jself.has("href"))
continue;
// .../FairEmail-v1.1995a-play-preview-release.apk
String link = jself.getString("href");
if (!link.endsWith(".apk"))
continue;
int slash = link.lastIndexOf('/');
if (slash < 0)
continue;
String[] c = link.substring(slash + 1).split("-");
if (c.length < 4 ||
!"FairEmail".equals(c[0]) ||
c[1].length() < 8 ||
!"github".equals(c[2]) ||
!"update".equals(c[3]))
return null;
// v1.1995a
Integer version = Helper.parseInt(c[1].substring(3, c[1].length() - 1));
if (version == null)
return null;
char revision = c[1].charAt(c[1].length() - 1);
if (BuildConfig.DEBUG ||
version > BuildConfig.VERSION_CODE ||
(version == BuildConfig.VERSION_CODE && revision > BuildConfig.REVISION.charAt(0))) {
UpdateInfo info = new UpdateInfo();
info.tag_name = c[1];
info.html_url = BuildConfig.BITBUCKET_DOWNLOADS_URI;
info.download_url = link;
return info;
} else
return null;
}
} else {
if (!jroot.has("tag_name") || jroot.isNull("tag_name"))
throw new IOException("tag_name field missing");
if (!jroot.has("assets") || jroot.isNull("assets"))
throw new IOException("assets section missing");
// Get update info
UpdateInfo info = new UpdateInfo();
info.tag_name = jroot.getString("tag_name");
info.html_url = BuildConfig.GITHUB_LATEST_URI;
// Check if new release
JSONArray jassets = jroot.getJSONArray("assets");
for (int i = 0; i < jassets.length(); i++) {
JSONObject jasset = jassets.getJSONObject(i);
if (jasset.has("name") && !jasset.isNull("name")) {
String name = jasset.getString("name");
if (name.endsWith(".apk")) {
info.download_url = jasset.optString("browser_download_url");
Log.i("Latest version=" + info.tag_name);
if (BuildConfig.DEBUG)
return info;
try {
if (Double.parseDouble(info.tag_name) <=
Double.parseDouble(BuildConfig.VERSION_NAME))
return null;
else
return info;
} catch (Throwable ex) {
Log.e(ex);
if (BuildConfig.VERSION_NAME.equals(info.tag_name))
return null;
else
return info;
}
}
}
}

View File

@ -139,6 +139,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private SwitchCompat swUpdates;
private ImageButton ibChannelUpdated;
private SwitchCompat swCheckWeekly;
private SwitchCompat swBeta;
private SwitchCompat swChangelog;
private SwitchCompat swCrashReports;
private TextView tvUuid;
@ -249,7 +250,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
"deepl_enabled",
"vt_enabled", "vt_apikey",
"send_enabled", "send_host",
"updates", "weekly", "show_changelog",
"updates", "weekly", "beta", "show_changelog",
"crash_reports", "cleanup_attachments",
"watchdog", "experiments", "main_log", "main_log_memory", "protocol", "log_level", "debug", "leak_canary",
"test1", "test2", "test3", "test4", "test5",
@ -351,6 +352,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
swUpdates = view.findViewById(R.id.swUpdates);
ibChannelUpdated = view.findViewById(R.id.ibChannelUpdated);
swCheckWeekly = view.findViewById(R.id.swWeekly);
swBeta = view.findViewById(R.id.swBeta);
swChangelog = view.findViewById(R.id.swChangelog);
swCrashReports = view.findViewById(R.id.swCrashReports);
tvUuid = view.findViewById(R.id.tvUuid);
@ -806,6 +808,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("updates", checked).apply();
swCheckWeekly.setEnabled(checked);
swBeta.setEnabled(checked);
if (!checked) {
NotificationManager nm =
Helper.getSystemService(getContext(), NotificationManager.class);
@ -833,6 +836,13 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
}
});
swBeta.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("beta", checked).apply();
}
});
swChangelog.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -2062,6 +2072,8 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
swUpdates.setChecked(prefs.getBoolean("updates", true));
swCheckWeekly.setChecked(prefs.getBoolean("weekly", Helper.hasPlayStore(getContext())));
swCheckWeekly.setEnabled(swUpdates.isChecked());
swBeta.setChecked(prefs.getBoolean("beta", false));
swBeta.setEnabled(swUpdates.isChecked());
swChangelog.setChecked(prefs.getBoolean("show_changelog", !BuildConfig.PLAY_STORE_RELEASE));
swExperiments.setChecked(prefs.getBoolean("experiments", false));
swCrashReports.setChecked(prefs.getBoolean("crash_reports", false));

View File

@ -559,6 +559,18 @@
app:layout_constraintTop_toBottomOf="@id/ibChannelUpdated"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swBeta"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_beta"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swWeekly"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swChangelog"
android:layout_width="0dp"
@ -567,7 +579,7 @@
android:text="@string/title_advanced_changelog"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swWeekly"
app:layout_constraintTop_toBottomOf="@id/swBeta"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat

View File

@ -761,6 +761,7 @@
<string name="title_advanced_watchdog">Periodically check if FairEmail is still active</string>
<string name="title_advanced_updates">Check for GitHub updates</string>
<string name="title_advanced_check_weekly">Check weekly instead of daily</string>
<string name="title_advanced_beta">Check for test versions on BitBucket</string>
<string name="title_advanced_changelog">Show changelog after update</string>
<string name="title_advanced_experiments">Try experimental features</string>
<string name="title_advanced_crash_reports">Send error reports</string>