Merge tag 'android-13.0.0_r16' into int/13/fp3

Android 13.0.0 Release 16 (TQ1A.221205.011)

* tag 'android-13.0.0_r16':

Change-Id: I847561e46c63a9f7b66be7fb6c13c9be654a6854
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index f6b8db3..88c0793 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -31,6 +31,7 @@
             <intent-filter>
                 <category android:name="android.intent.category.DEFAULT"/>
                 <action android:name="android.intent.action.VIEW"/>
+                <data android:scheme="file" />
                 <data android:scheme="content"/>
                 <data android:mimeType="text/html"/>
                 <data android:mimeType="text/plain"/>
diff --git a/res/layout/elabellayout.xml b/res/layout/elabellayout.xml
new file mode 100644
index 0000000..a0ea6dc
--- /dev/null
+++ b/res/layout/elabellayout.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2014 The Android Open Source 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.
+-->
+
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:background="@*android:color/white">
+
+    <com.android.htmlviewer.FairphoneWebView
+        android:id="@+id/webview"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"/>
+
+    <ProgressBar
+        android:id="@+id/loading"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="center"
+        android:indeterminate="true"
+        style="?android:attr/progressBarStyle" />
+
+</FrameLayout>
diff --git a/src/com/android/htmlviewer/FairphoneWebView.java b/src/com/android/htmlviewer/FairphoneWebView.java
new file mode 100644
index 0000000..7d2ef5d
--- /dev/null
+++ b/src/com/android/htmlviewer/FairphoneWebView.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2020-2022 Fairphone B.V.
+ *
+ * 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.
+ */
+
+package com.android.htmlviewer;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.webkit.WebView;
+
+public class FairphoneWebView extends WebView {
+    private static final String TAG = "FairphoneWebView";
+
+    public FairphoneWebView(Context context) {
+        super(context);
+    }
+
+    public FairphoneWebView(Context context, AttributeSet attrs) {
+        super(context, attrs);
+    }
+
+    public FairphoneWebView(Context context, AttributeSet attrs, int defStyleAttr) {
+        super(context, attrs, defStyleAttr);
+    }
+
+    @Override
+    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
+        super.onScrollChanged(l, t, oldl, oldt);
+        Log.d(TAG, "onScrollChanged:l:" + l + ",t:" + t + ",oldl:" + oldl + ",oldt:" + oldt);
+        scrollTo(0, t);
+    }
+}
diff --git a/src/com/android/htmlviewer/HTMLViewerActivity.java b/src/com/android/htmlviewer/HTMLViewerActivity.java
index 233a87d..5a7546d 100644
--- a/src/com/android/htmlviewer/HTMLViewerActivity.java
+++ b/src/com/android/htmlviewer/HTMLViewerActivity.java
@@ -34,6 +34,7 @@
 import android.webkit.WebViewClient;
 import android.widget.Toast;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URISyntaxException;
@@ -51,11 +52,21 @@
     private View mLoading;
     private Intent mIntent;
 
+    public static final String EXTRA_MODULE = "extra.module";
+    public static final String EXTRA_MODULE_REGULATORY_INFORMATION = "Regulatory information";
+    public static final String EXTRA_MODULE_OSS_LICENSES = "open_source_lisences";
+
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
-        setContentView();
+        mIntent = getIntent();
+        String extra = mIntent.getStringExtra(EXTRA_MODULE);
+        if (EXTRA_MODULE_REGULATORY_INFORMATION.equals(extra)) {
+            setContentView(R.layout.elabellayout);
+        } else {
+            setContentView(R.layout.main);
+        }
 
         mWebView = findViewById(R.id.webview);
         mLoading = findViewById(R.id.loading);
@@ -78,7 +89,17 @@
         s.setJavaScriptEnabled(false);
         s.setDefaultTextEncodingName("utf-8");
 
-        mIntent = getIntent();
+        if (EXTRA_MODULE_OSS_LICENSES.equals(extra)) {
+            s.setUseWideViewPort(true);
+            s.setLoadWithOverviewMode(true);
+            mWebView.setInitialScale(100);
+        }
+
+        if (EXTRA_MODULE_REGULATORY_INFORMATION.equals(extra)) {
+            s.setSupportZoom(false);
+            s.setBuiltInZoomControls(false);
+        }
+
         setBackButton();
         loadUrl();
     }
@@ -91,7 +112,23 @@
         if (mIntent.hasExtra(Intent.EXTRA_TITLE)) {
             setTitle(mIntent.getStringExtra(Intent.EXTRA_TITLE));
         }
-        mWebView.loadUrl(String.valueOf(mIntent.getData()));
+        Uri uri = mIntent.getData();
+        if (ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())) {
+            // HTMLViewer does not understand file provider content scheme,
+            // so convert into its equivalent file scheme
+            String path = uri.getPath();
+            final File file = new File(path);
+            if (isFileValid(file)) {
+                // Handle file scheme
+                mWebView.loadUrl(ContentResolver.SCHEME_FILE + "://" + path);
+                return;
+            }
+        }
+        mWebView.loadUrl(String.valueOf(uri));
+    }
+
+    private boolean isFileValid(final File file) {
+        return file.exists() && file.length() != 0;
     }
 
     private void setBackButton() {