X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Factivities%2FMainWebViewActivity.java;h=d89e287b9268f08fb06cc20f952a82c444f18cf0;hb=d941ca283544e1c3231f59796a3f64270e747a99;hp=800b3b044b5c618c3a96e4376c2bbea784e700c5;hpb=641d15ace34579762580ed8297f324133354499b;p=PrivacyBrowserAndroid.git diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java index 800b3b04..d89e287b 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java @@ -48,11 +48,13 @@ import android.net.http.SslError; import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; +import android.os.Environment; import android.os.Handler; import android.os.Message; import android.preference.PreferenceManager; import android.print.PrintDocumentAdapter; import android.print.PrintManager; +import android.provider.DocumentsContract; import android.text.Editable; import android.text.Spanned; import android.text.TextWatcher; @@ -2029,14 +2031,50 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Make it so. startActivity(requestsIntent); } else if (menuItemId == R.id.downloads) { // Downloads. - // Launch the system Download Manager. - Intent downloadManagerIntent = new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS); + // Try the default system download manager. + try { + // Launch the default system Download Manager. + Intent defaultDownloadManagerIntent = new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS); - // Launch as a new task so that Download Manager and Privacy Browser show as separate windows in the recent tasks list. - downloadManagerIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + // Launch as a new task so that the download manager and Privacy Browser show as separate windows in the recent tasks list. + defaultDownloadManagerIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - // Make it so. - startActivity(downloadManagerIntent); + // Make it so. + startActivity(defaultDownloadManagerIntent); + } catch (Exception defaultDownloadManagerException) { + // Try a generic file manager. + try { + // Create a generic file manager intent. + Intent genericFileManagerIntent = new Intent(Intent.ACTION_VIEW); + + // Open the download directory. + genericFileManagerIntent.setDataAndType(Uri.parse(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString()), DocumentsContract.Document.MIME_TYPE_DIR); + + // Launch as a new task so that the file manager and Privacy Browser show as separate windows in the recent tasks list. + genericFileManagerIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + + // Make it so. + startActivity(genericFileManagerIntent); + } catch (Exception genericFileManagerException) { + // Try an alternate file manager. + try { + // Create an alternate file manager intent. + Intent alternateFileManagerIntent = new Intent(Intent.ACTION_VIEW); + + // Open the download directory. + alternateFileManagerIntent.setDataAndType(Uri.parse(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString()), "resource/folder"); + + // Launch as a new task so that the file manager and Privacy Browser show as separate windows in the recent tasks list. + alternateFileManagerIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + + // Open the alternate file manager. + startActivity(alternateFileManagerIntent); + } catch (Exception alternateFileManagerException) { + // Display a snackbar. + Snackbar.make(currentWebView, R.string.no_file_manager_detected, Snackbar.LENGTH_INDEFINITE).show(); + } + } + } } else if (menuItemId == R.id.domains) { // Domains. // Set the flag to reapply the domain settings on restart when returning from Domain Settings. reapplyDomainSettingsOnRestart = true; @@ -3567,7 +3605,6 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Store the values from the shared preferences in variables. incognitoModeEnabled = sharedPreferences.getBoolean("incognito_mode", false); - boolean doNotTrackEnabled = sharedPreferences.getBoolean("do_not_track", false); sanitizeGoogleAnalytics = sharedPreferences.getBoolean("google_analytics", true); sanitizeFacebookClickIds = sharedPreferences.getBoolean("facebook_click_ids", true); sanitizeTwitterAmpRedirects = sharedPreferences.getBoolean("twitter_amp_redirects", true); @@ -3598,13 +3635,6 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Apply the proxy. applyProxy(false); - // Set Do Not Track status. - if (doNotTrackEnabled) { - customHeaders.put("DNT", "1"); - } else { - customHeaders.remove("DNT"); - } - // Get the current layout parameters. Using coordinator layout parameters allows the `setBehavior()` command and using app bar layout parameters allows the `setScrollFlags()` command. CoordinatorLayout.LayoutParams swipeRefreshLayoutParams = (CoordinatorLayout.LayoutParams) swipeRefreshLayout.getLayoutParams(); AppBarLayout.LayoutParams toolbarLayoutParams = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();