add user-facing error reporting

This commit is contained in:
Daniel Micay 2020-04-11 13:21:36 -04:00
parent 89ce54c53a
commit 1fd99ae3b4
3 changed files with 17 additions and 7 deletions

View File

@ -35,6 +35,7 @@ android {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
}
def props = new Properties()

View File

@ -27,6 +27,8 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.loader.app.LoaderManager;
import androidx.loader.content.Loader;
import com.google.android.material.snackbar.Snackbar;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
@ -96,6 +98,7 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
private WebView mWebView;
private TextView mTextView;
private Toast mToast;
private Snackbar snackbar;
private class Channel {
@JavascriptInterface
@ -280,18 +283,15 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
// loader manager impl so that the result will be delivered.
LoaderManager.getInstance(this);
snackbar = Snackbar.make(findViewById(R.id.webview), "", Snackbar.LENGTH_LONG);
final Intent intent = getIntent();
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
if (!"application/pdf".equals(intent.getType())) {
Log.e(TAG, "invalid mime type");
finish();
snackbar.setText(R.string.invalid_mime_type).show();
return;
}
mUri = intent.getData();
if ("file".equals(mUri.getScheme())) {
Log.e(TAG, "invalid legacy file URI: " + mUri);
return;
}
mPage = 1;
}
@ -302,6 +302,11 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
mDocumentOrientationDegrees = savedInstanceState.getInt(STATE_DOCUMENT_ORIENTATION_DEGREES);
}
if ("file".equals(mUri.getScheme())) {
snackbar.setText(R.string.legacy_file_uri).show();
return;
}
if (mUri != null) {
loadPdf();
}
@ -330,7 +335,7 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
}
mInputStream = getContentResolver().openInputStream(mUri);
} catch (IOException e) {
Log.e(TAG, "failed to open URI: " + mUri);
snackbar.setText(R.string.io_error).show();
return;
}
mWebView.loadUrl("https://localhost/viewer.html");

View File

@ -16,4 +16,8 @@
<string name="document_properties_invalid_date">Invalid date</string>
<string name="document_properties_retrieval_failed">Failed to obtain document metadata</string>
<string name="invalid_mime_type">Cannot open file with invalid mime type</string>
<string name="legacy_file_uri">Cannot open legacy file paths from insecure apps</string>
<string name="io_error">Received I/O error trying to open content</string>
</resources>