summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
Diffstat (limited to 'java')
-rw-r--r--java/com/android/dialer/helplines/AndroidManifest.xml2
-rwxr-xr-xjava/com/android/dialer/helplines/HelplineActivity.java71
-rw-r--r--java/com/android/dialer/helplines/res/layout/dialog_webview.xml52
-rw-r--r--java/com/android/dialer/helplines/res/values/strings.xml2
-rw-r--r--java/com/android/dialer/helplines/utils/HelplineUtils.java23
5 files changed, 101 insertions, 49 deletions
diff --git a/java/com/android/dialer/helplines/AndroidManifest.xml b/java/com/android/dialer/helplines/AndroidManifest.xml
index 45706cdad..a16c36c0d 100644
--- a/java/com/android/dialer/helplines/AndroidManifest.xml
+++ b/java/com/android/dialer/helplines/AndroidManifest.xml
@@ -17,6 +17,8 @@
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.dialer.helplines">
+ <uses-permission android:name="android.permission.INTERNET" />
+
<application>
<activity
diff --git a/java/com/android/dialer/helplines/HelplineActivity.java b/java/com/android/dialer/helplines/HelplineActivity.java
index bf9746822..6452ad5e7 100755
--- a/java/com/android/dialer/helplines/HelplineActivity.java
+++ b/java/com/android/dialer/helplines/HelplineActivity.java
@@ -22,7 +22,6 @@ import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.content.SharedPreferences;
-import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@@ -35,6 +34,10 @@ import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
+import android.webkit.CookieManager;
+import android.webkit.WebResourceRequest;
+import android.webkit.WebView;
+import android.webkit.WebViewClient;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
@@ -45,7 +48,9 @@ import com.android.dialer.helplines.utils.HelplineUtils;
import org.lineageos.lib.phone.spn.Item;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import static android.graphics.Paint.UNDERLINE_TEXT_FLAG;
@@ -226,31 +231,49 @@ public class HelplineActivity extends Activity {
if (isUrl) {
contentView.setPaintFlags(contentView.getPaintFlags() | UNDERLINE_TEXT_FLAG);
- // We want to warn the user that visiting a link might leave traces
+ LayoutInflater inflater = HelplineActivity.this.getLayoutInflater();
contentView.setOnClickListener(v -> {
- Intent intent = new Intent(Intent.ACTION_VIEW);
- intent.setData(Uri.parse(content));
- boolean isIncognito = HelplineUtils.makeIncognito(HelplineActivity.this,
- intent);
- if (isIncognito) {
- mDialog.dismiss();
- finish(); // Finish activity to get rid of own traces
- startActivity(intent);
- } else {
- new AlertDialog.Builder(HelplineActivity.this)
- .setTitle(R.string.helpline_browser_history_title)
- .setMessage(R.string.helpline_browser_history_message)
- .setPositiveButton(android.R.string.ok, (dlg, which) -> {
- mDialog.dismiss();
- dlg.dismiss();
- finish(); // Finish activity to get rid of own traces
- startActivity(intent);
- })
- .setNegativeButton(android.R.string.cancel, null)
- .show();
+ AlertDialog.Builder dialogBuilder =
+ new AlertDialog.Builder(HelplineActivity.this);
+ View webviewDlgView = inflater.inflate(R.layout.dialog_webview, null);
+ dialogBuilder.setView(webviewDlgView);
+ LinearLayout loadingLayout = webviewDlgView.findViewById(R.id.webview_loading);
+
+ // Disable cookies
+ CookieManager.getInstance().setAcceptCookie(false);
+ // Setup WebView
+ WebView webView = webviewDlgView.findViewById(R.id.webview);
+ webView.setWebViewClient(new WebViewClient() {
+ @Override
+ public boolean shouldOverrideUrlLoading(WebView view,
+ WebResourceRequest request) {
+ return false;
}
- }
- );
+
+ @Override
+ public void onPageFinished(WebView view, String url) {
+ super.onPageFinished(view, url);
+ loadingLayout.setVisibility(ProgressBar.INVISIBLE);
+ webView.setVisibility(View.VISIBLE);
+ }
+ });
+ // Override headers to disable cache and add "Do not track"
+ Map<String, String> headers = new HashMap<>(3);
+ headers.put("Pragma", "no-cache");
+ headers.put("Cache-Control", "no-cache");
+ headers.put("DNT", "1");
+ // Start loading the URL
+ webView.loadUrl(content, headers);
+ // Clear any WebView history
+ dialogBuilder.setPositiveButton(android.R.string.ok, (dlg, which) -> {
+ webView.clearHistory();
+ dlg.dismiss();
+ });
+ dialogBuilder.setOnDismissListener(dialog -> webView.clearHistory());
+ dialogBuilder.show();
+ // dismiss the dialog, we show a new one already
+ mDialog.dismiss();
+ });
}
}
};
diff --git a/java/com/android/dialer/helplines/res/layout/dialog_webview.xml b/java/com/android/dialer/helplines/res/layout/dialog_webview.xml
new file mode 100644
index 000000000..b21bff6cb
--- /dev/null
+++ b/java/com/android/dialer/helplines/res/layout/dialog_webview.xml
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2021 The LineageOS Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <WebView
+ android:id="@+id/webview"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:visibility="gone" />
+
+ <LinearLayout
+ android:id="@+id/webview_loading"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:gravity="center"
+ android:orientation="vertical"
+ android:layout_marginTop="32dp">
+
+ <ProgressBar
+ style="@android:style/Widget.DeviceDefault.ProgressBar.Horizontal"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingStart="32dp"
+ android:paddingEnd="32dp"
+ android:indeterminate="true"/>
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="16dp"
+ android:text="@string/helplines_loading"
+ android:textSize="16sp" />
+ </LinearLayout>
+</LinearLayout>
diff --git a/java/com/android/dialer/helplines/res/values/strings.xml b/java/com/android/dialer/helplines/res/values/strings.xml
index 232ac46a8..6e9baa74c 100644
--- a/java/com/android/dialer/helplines/res/values/strings.xml
+++ b/java/com/android/dialer/helplines/res/values/strings.xml
@@ -33,8 +33,6 @@
<string name="helpline_categories">Categories</string>
<string name="helpline_number">Number</string>
<string name="helpline_website">Website</string>
- <string name="helpline_browser_history_title">Attention</string>
- <string name="helpline_browser_history_message">Don\'t forget to clear the browser history</string>
<!-- Format for displaying a helpline name with the country - Example will resolve to "Emotional Support Hotline (US)" -->
<string name="helpline_name_format_country"><xliff:g id="helpline_name" example="Emotional Support Helpline">%1$s</xliff:g> (<xliff:g id="helpline_county" example="US">%2$s</xliff:g>)</string>
diff --git a/java/com/android/dialer/helplines/utils/HelplineUtils.java b/java/com/android/dialer/helplines/utils/HelplineUtils.java
index 7303dddca..a31a9ec44 100644
--- a/java/com/android/dialer/helplines/utils/HelplineUtils.java
+++ b/java/com/android/dialer/helplines/utils/HelplineUtils.java
@@ -15,10 +15,6 @@
*/
package com.android.dialer.helplines.utils;
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.text.TextUtils;
@@ -35,8 +31,6 @@ public class HelplineUtils {
private static final String CATEGORY_STR_FORMAT = "helpline_category_%s";
private static final String LANGUAGE_STR_FORMAT = "helpline_language_%s";
- private static final String PKG_NAME_JELLY = "org.lineageos.jelly";
-
/* Get the name of the helpline, fall back to the number if not given */
public static String getName(Resources res, Item item, String countryIso) {
if (item != null) {
@@ -94,21 +88,4 @@ public class HelplineUtils {
}
return "";
}
-
- /* Check if the browser is known and make it launch in incognito mode
- * Returns true if it succeeded
- */
- public static boolean makeIncognito(Context context, Intent intent) {
- final PackageManager pm = context.getPackageManager();
- ResolveInfo info = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
- if (info != null) {
- String pkgName = info.activityInfo.applicationInfo.packageName;
- if (PKG_NAME_JELLY.equals(pkgName)) {
- intent.putExtra("extra_incognito", true);
- return true;
- }
- }
-
- return false;
- }
}