From dd507c77b7e5ddb5deb43d0197369a14498abb57 Mon Sep 17 00:00:00 2001 From: Chirayu Desai Date: Mon, 12 Aug 2019 23:56:44 +0530 Subject: [PATCH] Show a changelog. * Changelog is HTML, shown via HTMLViewer, which is also used by Settings -> About -> Legal * Changelog file: --changelog.html * Show changelog if it exists upon tapping the notification, or the settings entry. Potential TODOs: * The view can be zoomed in and out (which may be useful), and also scrolled around easily (not so useful). --- AndroidManifest.xml | 10 +++++ res/values/strings.xml | 3 ++ res/xml/file_paths.xml | 4 ++ res/xml/settings.xml | 4 ++ .../client/NotificationHandler.java | 21 +++++++--- src/app/seamlessupdate/client/Service.java | 24 +++++++++++ src/app/seamlessupdate/client/Settings.java | 42 +++++++++++++++++++ 7 files changed, 103 insertions(+), 5 deletions(-) create mode 100644 res/xml/file_paths.xml diff --git a/AndroidManifest.xml b/AndroidManifest.xml index fd1a10f..3404b2f 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -63,5 +63,15 @@ + + + + diff --git a/res/values/strings.xml b/res/values/strings.xml index 859e32b..60f6a01 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -25,4 +25,7 @@ Automatically reboot once the device is idle after successfully installing an update Updates Tap to check for updates + Changelog + Tap to view changelog + Changelog unavailable diff --git a/res/xml/file_paths.xml b/res/xml/file_paths.xml new file mode 100644 index 0000000..3e61b23 --- /dev/null +++ b/res/xml/file_paths.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/res/xml/settings.xml b/res/xml/settings.xml index 1dcbf9e..67770da 100644 --- a/res/xml/settings.xml +++ b/res/xml/settings.xml @@ -8,6 +8,10 @@ android:title="@string/check_for_updates_title" android:summary="@string/check_for_updates_summary" /> + + { + Intent intent = getChangelogIntent(this, "current.html"); + if (intent != null) { + startActivity(intent); + } else { + changelog.setSummary(getString(R.string.changelog_unavailable)); + } + return true; + }); + final Preference channel = findPreference(KEY_CHANNEL); channel.setOnPreferenceChangeListener((final Preference preference, final Object newValue) -> { getPreferences(this).edit().putString(KEY_CHANNEL,(String) newValue).apply(); @@ -104,5 +122,29 @@ public void onResume() { super.onResume(); final ListPreference networkType = (ListPreference) findPreference(KEY_NETWORK_TYPE); networkType.setValue(Integer.toString(getNetworkType(this))); + final Preference changelog = findPreference(KEY_CHANGELOG); + changelog.setSummary(getString(R.string.changelog_summary)); + } + + static Intent getChangelogIntent(Context context, String filename) { + // From com.android.settings.SettingsLicenseActivity.showHtmlFromUri() + // Kick off external viewer due to WebView security restrictions; we + // carefully point it at HTMLViewer, since it offers to decompress + // before viewing. + final File changelogPath = new File(context.getCacheDir(), "changelog"); + final File changelogFile = new File(changelogPath, filename); + if (!changelogFile.exists()) { + return null; + } + final Uri uri = FileProvider.getUriForFile(context, "app.seamlessupdate.client.fileprovider", changelogFile); + final Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setDataAndType(uri, "text/html"); + intent.putExtra(Intent.EXTRA_TITLE, context.getString(R.string.changelog_title)); + if (ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())) { + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + } + intent.addCategory(Intent.CATEGORY_DEFAULT); + intent.setPackage("com.android.htmlviewer"); + return intent; } }