Merge "Implement the Telephony API to remove the UCE requests cannot be sent status"
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index e51be20..4d81766 100755
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -5770,6 +5770,8 @@
                                 .setCallingUid(Binder.getCallingUid())
                                 .setMethod("getCellNetworkScanResults")
                                 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
+                                .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
+                                .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
                                 .build());
         switch (locationResult) {
             case DENIED_HARD:
@@ -7449,6 +7451,8 @@
                                 .setMethod("getServiceStateForSubscriber")
                                 .setLogAsInfo(true)
                                 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
+                                .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
+                                .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
                                 .build());
 
         LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
@@ -7461,6 +7465,8 @@
                                 .setMethod("getServiceStateForSubscriber")
                                 .setLogAsInfo(true)
                                 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
+                                .setMinSdkVersionForFine(Integer.MAX_VALUE)
+                                .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
                                 .build());
         // We don't care about hard or soft here -- all we need to know is how much info to scrub.
         boolean hasFinePermission =
diff --git a/tests/src/com/android/phone/LocationAccessPolicyBuilderTest.java b/tests/src/com/android/phone/LocationAccessPolicyBuilderTest.java
new file mode 100644
index 0000000..4fe2da9
--- /dev/null
+++ b/tests/src/com/android/phone/LocationAccessPolicyBuilderTest.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+package com.android.phone;
+
+import static org.junit.Assert.fail;
+
+import android.os.Build;
+import android.telephony.LocationAccessPolicy;
+
+import androidx.test.runner.AndroidJUnit4;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AndroidJUnit4.class)
+public class LocationAccessPolicyBuilderTest {
+    @Test
+    public void testBuilderMissingMinCoarse() {
+        try {
+            new LocationAccessPolicy.LocationPermissionQuery.Builder()
+                    .setMethod("test")
+                    .setCallingPackage("com.android.test")
+                    .setCallingFeatureId(null)
+                    .setCallingPid(0)
+                    .setCallingUid(0)
+                    .setMinSdkVersionForFine(Build.VERSION_CODES.N)
+                    .build();
+            fail("Should have failed without specifying min version for coarse");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+    }
+
+    @Test
+    public void testBuilderMissingMinFine() {
+        try {
+            new LocationAccessPolicy.LocationPermissionQuery.Builder()
+                    .setMethod("test")
+                    .setCallingPackage("com.android.test")
+                    .setCallingFeatureId(null)
+                    .setCallingPid(0)
+                    .setCallingUid(0)
+                    .setMinSdkVersionForCoarse(Build.VERSION_CODES.N)
+                    .build();
+            fail("Should have failed without specifying min version for fine");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+    }
+
+    @Test
+    public void testBuilderMissingMinEnforcement() {
+        try {
+            new LocationAccessPolicy.LocationPermissionQuery.Builder()
+                    .setMethod("test")
+                    .setCallingPackage("com.android.test")
+                    .setCallingFeatureId(null)
+                    .setCallingPid(0)
+                    .setCallingUid(0)
+                    .setMinSdkVersionForFine(Build.VERSION_CODES.N)
+                    .setMinSdkVersionForCoarse(Build.VERSION_CODES.N)
+                    .build();
+            fail("Should have failed without specifying min version for any enforcement");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+    }
+}
diff --git a/tests/src/com/android/phone/LocationAccessPolicyTest.java b/tests/src/com/android/phone/LocationAccessPolicyTest.java
index b2489e7..84bf619 100644
--- a/tests/src/com/android/phone/LocationAccessPolicyTest.java
+++ b/tests/src/com/android/phone/LocationAccessPolicyTest.java
@@ -242,6 +242,7 @@
                 .setAppSdkLevel(Build.VERSION_CODES.P)
                 .setIsDynamicLocationEnabled(false)
                 .setQuery(getDefaultQueryBuilder()
+                        .setMinSdkVersionForEnforcement(Build.VERSION_CODES.N)
                         .setMinSdkVersionForFine(Build.VERSION_CODES.N)
                         .setMinSdkVersionForCoarse(Build.VERSION_CODES.N).build())
                 .setExpectedResult(LocationAccessPolicy.LocationPermissionResult.DENIED_SOFT)
@@ -254,6 +255,7 @@
                 .setAppSdkLevel(Build.VERSION_CODES.P)
                 .setIsDynamicLocationEnabled(true)
                 .setQuery(getDefaultQueryBuilder()
+                        .setMinSdkVersionForEnforcement(Build.VERSION_CODES.N)
                         .setMinSdkVersionForFine(Build.VERSION_CODES.N)
                         .setMinSdkVersionForCoarse(Build.VERSION_CODES.N).build())
                 .setExpectedResult(LocationAccessPolicy.LocationPermissionResult.ALLOWED)
@@ -266,6 +268,7 @@
                 .setAppSdkLevel(Build.VERSION_CODES.JELLY_BEAN)
                 .setIsDynamicLocationEnabled(true)
                 .setQuery(getDefaultQueryBuilder()
+                        .setMinSdkVersionForEnforcement(Build.VERSION_CODES.JELLY_BEAN)
                         .setMinSdkVersionForFine(Build.VERSION_CODES.M)
                         .setMinSdkVersionForCoarse(Build.VERSION_CODES.JELLY_BEAN).build())
                 .setExpectedResult(LocationAccessPolicy.LocationPermissionResult.ALLOWED)
@@ -278,6 +281,7 @@
                 .setAppSdkLevel(Build.VERSION_CODES.P)
                 .setIsDynamicLocationEnabled(true)
                 .setQuery(getDefaultQueryBuilder()
+                        .setMinSdkVersionForEnforcement(Build.VERSION_CODES.N)
                         .setMinSdkVersionForFine(Build.VERSION_CODES.N)
                         .setMinSdkVersionForCoarse(Build.VERSION_CODES.N).build())
                 .setExpectedResult(LocationAccessPolicy.LocationPermissionResult.DENIED_HARD)
@@ -292,6 +296,7 @@
                 .setQuery(getDefaultQueryBuilder()
                         .setMinSdkVersionForFine(
                                 LocationAccessPolicy.MAX_SDK_FOR_ANY_ENFORCEMENT + 1)
+                        .setMinSdkVersionForEnforcement(Build.VERSION_CODES.N)
                         .setMinSdkVersionForCoarse(Build.VERSION_CODES.N).build())
                 .setExpectedResult(LocationAccessPolicy.LocationPermissionResult.ALLOWED)
                 .build());
@@ -303,6 +308,7 @@
                 .setAppSdkLevel(Build.VERSION_CODES.P)
                 .setIsDynamicLocationEnabled(true)
                 .setQuery(getDefaultQueryBuilder()
+                        .setMinSdkVersionForEnforcement(Build.VERSION_CODES.N)
                         .setMinSdkVersionForFine(Build.VERSION_CODES.P)
                         .setMinSdkVersionForCoarse(Build.VERSION_CODES.N).build())
                 .setExpectedResult(LocationAccessPolicy.LocationPermissionResult.DENIED_HARD)
@@ -316,6 +322,7 @@
                 .setAppSdkLevel(Build.VERSION_CODES.P)
                 .setIsDynamicLocationEnabled(true)
                 .setQuery(getDefaultQueryBuilder()
+                        .setMinSdkVersionForEnforcement(Build.VERSION_CODES.O)
                         .setMinSdkVersionForFine(Build.VERSION_CODES.P)
                         .setMinSdkVersionForCoarse(Build.VERSION_CODES.O).build())
                 .setExpectedResult(LocationAccessPolicy.LocationPermissionResult.DENIED_HARD)
@@ -326,6 +333,7 @@
                 .setAppSdkLevel(Build.VERSION_CODES.N)
                 .setIsDynamicLocationEnabled(true)
                 .setQuery(getDefaultQueryBuilder()
+                        .setMinSdkVersionForEnforcement(Build.VERSION_CODES.O)
                         .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
                         .setMinSdkVersionForCoarse(Build.VERSION_CODES.O).build())
                 .setExpectedResult(LocationAccessPolicy.LocationPermissionResult.ALLOWED)
@@ -338,6 +346,9 @@
                 .setAppSdkLevel(Build.VERSION_CODES.P)
                 .setIsDynamicLocationEnabled(true)
                 .setQuery(getDefaultQueryBuilder()
+                        .setMinSdkVersionForEnforcement(Build.VERSION_CODES.P)
+                        .setMinSdkVersionForFine(
+                                LocationAccessPolicy.MAX_SDK_FOR_ANY_ENFORCEMENT + 1)
                         .setMinSdkVersionForCoarse(Build.VERSION_CODES.P).build())
                 .setExpectedResult(LocationAccessPolicy.LocationPermissionResult.ALLOWED)
                 .build());