Use a secure setting for default browser geolocation permissions

Partly reverts I6308b476ad18b1d71d7438b936c592a45365c9f0

Bug: http://b/issue?id=2535598

Change-Id: Ib488c6d4f10a87b714ecb78eef6fe58f572907c6
diff --git a/api/current.xml b/api/current.xml
index 047c25c..d282e06 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -1233,17 +1233,6 @@
  visibility="public"
 >
 </field>
-<field name="WRITE_GEOLOCATION_PERMISSIONS"
- type="java.lang.String"
- transient="false"
- volatile="false"
- value="&quot;com.android.browser.permission.WRITE_GEOLOCATION_PERMISSIONS&quot;"
- static="true"
- final="true"
- deprecated="not deprecated"
- visibility="public"
->
-</field>
 <field name="WRITE_GSERVICES"
  type="java.lang.String"
  transient="false"
@@ -124196,21 +124185,6 @@
 <parameter name="search" type="java.lang.String">
 </parameter>
 </method>
-<method name="allowGeolocation"
- return="void"
- abstract="false"
- native="false"
- synchronized="false"
- static="true"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-<parameter name="cr" type="android.content.ContentResolver">
-</parameter>
-<parameter name="origin" type="java.lang.String">
-</parameter>
-</method>
 <method name="canClearHistory"
  return="boolean"
  abstract="false"
@@ -124224,21 +124198,6 @@
 <parameter name="cr" type="android.content.ContentResolver">
 </parameter>
 </method>
-<method name="clearGeolocation"
- return="void"
- abstract="false"
- native="false"
- synchronized="false"
- static="true"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-<parameter name="cr" type="android.content.ContentResolver">
-</parameter>
-<parameter name="origin" type="java.lang.String">
-</parameter>
-</method>
 <method name="clearHistory"
  return="void"
  abstract="false"
@@ -124438,16 +124397,6 @@
  visibility="public"
 >
 </field>
-<field name="GEOLOCATION_URI"
- type="android.net.Uri"
- transient="false"
- volatile="false"
- static="true"
- final="true"
- deprecated="not deprecated"
- visibility="public"
->
-</field>
 <field name="HISTORY_PROJECTION"
  type="java.lang.String[]"
  transient="false"
@@ -124720,34 +124669,6 @@
 >
 </field>
 </class>
-<class name="Browser.GeolocationColumns"
- extends="java.lang.Object"
- abstract="false"
- static="true"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-<constructor name="Browser.GeolocationColumns"
- type="android.provider.Browser.GeolocationColumns"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-</constructor>
-<field name="ORIGIN"
- type="java.lang.String"
- transient="false"
- volatile="false"
- value="&quot;origin&quot;"
- static="true"
- final="true"
- deprecated="not deprecated"
- visibility="public"
->
-</field>
-</class>
 <class name="Browser.SearchColumns"
  extends="java.lang.Object"
  abstract="false"
@@ -135935,6 +135856,17 @@
  visibility="public"
 >
 </field>
+<field name="ALLOWED_GEOLOCATION_ORIGINS"
+ type="java.lang.String"
+ transient="false"
+ volatile="false"
+ value="&quot;allowed_geolocation_origins&quot;"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="ALLOW_MOCK_LOCATION"
  type="java.lang.String"
  transient="false"
diff --git a/core/java/android/provider/Browser.java b/core/java/android/provider/Browser.java
index a1ad1ee..b466b40 100644
--- a/core/java/android/provider/Browser.java
+++ b/core/java/android/provider/Browser.java
@@ -121,15 +121,6 @@
     private static final int MAX_HISTORY_COUNT = 250;
 
     /**
-     * URI for writing geolocation permissions. This requires the
-     * {@link android.Manifest.permission#WRITE_GEOLOCATION_PERMISSIONS}.
-     */
-    public static final Uri GEOLOCATION_URI =
-            Uri.parse("content://browser/geolocation");
-
-    private static final String GEOLOCATION_WHERE_CLAUSE = GeolocationColumns.ORIGIN + " = ?";
-
-    /**
      *  Open the AddBookmark activity to save a bookmark.  Launch with
      *  and/or url, which can be edited by the user before saving.
      *  @param c        Context used to launch the AddBookmark activity.
@@ -614,42 +605,6 @@
         }
     }
 
-    /**
-     * Allows geolocation for the specified origin.
-     * This requires the {@link android.Manifest.permission#WRITE_GEOLOCATION_PERMISSIONS}
-     * permission.
-     *
-     * @param origin The origin to allow geolocation for, e.g. "http://www.google.com". The string
-     *        should not include a trailing slash.
-     */
-    public static void allowGeolocation(ContentResolver cr, String origin) {
-        try {
-            ContentValues map = new ContentValues();
-            map.put(GeolocationColumns.ORIGIN, origin);
-            cr.insert(GEOLOCATION_URI, map);
-        } catch (IllegalStateException e) {
-            Log.e(LOGTAG, "allowGeolocation", e);
-            return;
-        }
-    }
-
-    /**
-     * Clears the geolocation permission state for the specified origin.
-     * This requires the {@link android.Manifest.permission#WRITE_GEOLOCATION_PERMISSIONS}
-     * permission.
-     *
-     * @param origin The origin to allow geolocation for, e.g. "http://www.google.com". The string
-     *        should not include a trailing slash.
-     */
-    public static void clearGeolocation(ContentResolver cr, String origin) {
-        try {
-            String[] whereArgs = { origin };
-            cr.delete(GEOLOCATION_URI, GEOLOCATION_WHERE_CLAUSE, whereArgs);
-        } catch (IllegalStateException e) {
-            Log.e(LOGTAG, "clearGeolocation", e);
-        }
-    }
-
     public static class BookmarkColumns implements BaseColumns {
         public static final String URL = "url";
         public static final String VISITS = "visits";
@@ -677,8 +632,4 @@
         public static final String SEARCH = "search";
         public static final String DATE = "date";
     }
-
-    public static class GeolocationColumns {
-        public static final String ORIGIN = "origin";
-    }
 }
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index c4d11e7..6e37f69 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -2630,6 +2630,13 @@
         public static final String BACKGROUND_DATA = "background_data";
 
         /**
+         * Origins for which browsers should allow geolocation by default.
+         * The value is a space-separated list of origins.
+         */
+        public static final String ALLOWED_GEOLOCATION_ORIGINS
+                = "allowed_geolocation_origins";
+
+        /**
          * Whether mobile data connections are allowed by the user.  See
          * ConnectivityManager for more info.
          * @hide
@@ -2710,14 +2717,6 @@
         public static final String TTY_MODE_ENABLED = "tty_mode_enabled";
 
         /**
-         * Flag for allowing service provider to use location information to improve products and
-         * services.
-         * Type: int ( 0 = disallow, 1 = allow )
-         * @hide
-         */
-        public static final String USE_LOCATION_FOR_SERVICES = "use_location";
-
-        /**
          * Controls whether settings backup is enabled.
          * Type: int ( 0 = disabled, 1 = enabled )
          * @hide
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index a3c73d8..8eb5e96 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -250,14 +250,6 @@
         android:description="@string/permdesc_writeHistoryBookmarks"
         android:protectionLevel="dangerous" />
 
-    <!-- Allows an application to write to (but not read) the user's
-         geolocation permissions.. -->
-    <permission android:name="com.android.browser.permission.WRITE_GEOLOCATION_PERMISSIONS"
-        android:permissionGroup="android.permission-group.LOCATION"
-        android:label="@string/permlab_writeGeolocationPermissions"
-        android:description="@string/permdesc_writeGeolocationPermissions"
-        android:protectionLevel="signatureOrSystem" />
-
     <!-- ======================================= -->
     <!-- Permissions for accessing location info -->
     <!-- ======================================= -->