Revert query handling of subid

This was enabled by aosp/541366 but is causing a regression in querying
APNs. This CL reverts back to the previous behavior, which does not
handle sub id when querying.

Bug: 74213956
Test: manual and unit test
Change-Id: Id0fed0de44a02f6baa13b6bf1f1c7b2ec8e190ea
diff --git a/src/com/android/providers/telephony/TelephonyProvider.java b/src/com/android/providers/telephony/TelephonyProvider.java
index fd98fa6..5a8d851 100644
--- a/src/com/android/providers/telephony/TelephonyProvider.java
+++ b/src/com/android/providers/telephony/TelephonyProvider.java
@@ -2349,7 +2349,8 @@
                 }
                 if (DBG) log("subIdString = " + subIdString + " subId = " + subId);
                 constraints.add(NUMERIC + " = '" + mTelephonyManager.getSimOperator(subId) + "'");
-                constraints.add(SUBSCRIPTION_ID + "=" + subIdString);
+                // TODO b/74213956 turn this back on once insertion includes correct sub id
+                // constraints.add(SUBSCRIPTION_ID + "=" + subIdString);
             }
             // intentional fall through from above case
             case URL_TELEPHONY: {
@@ -2366,7 +2367,8 @@
                     return null;
                 }
                 if (DBG) log("subIdString = " + subIdString + " subId = " + subId);
-                constraints.add(SUBSCRIPTION_ID + "=" + subIdString);
+                // TODO b/74213956 turn this back on once insertion includes correct sub id
+                // constraints.add(SUBSCRIPTION_ID + "=" + subIdString);
             }
             //intentional fall through from above case
             case URL_CURRENT: {
@@ -2393,7 +2395,8 @@
                     return null;
                 }
                 if (DBG) log("subIdString = " + subIdString + " subId = " + subId);
-                constraints.add(SUBSCRIPTION_ID + "=" + subIdString);
+                // TODO b/74213956 turn this back on once insertion includes correct sub id
+                // constraints.add(SUBSCRIPTION_ID + "=" + subIdString);
             }
             //intentional fall through from above case
             case URL_PREFERAPN:
@@ -2627,7 +2630,6 @@
                     values = new ContentValues();
                 }
 
-                values.put(SUBSCRIPTION_ID, subId);
                 values = DatabaseHelper.setDefaultValue(values);
                 if (!values.containsKey(EDITED)) {
                     values.put(EDITED, CARRIER_EDITED);
diff --git a/tests/src/com/android/providers/telephony/TelephonyProviderTest.java b/tests/src/com/android/providers/telephony/TelephonyProviderTest.java
index 5e6cb3a..a26a840 100644
--- a/tests/src/com/android/providers/telephony/TelephonyProviderTest.java
+++ b/tests/src/com/android/providers/telephony/TelephonyProviderTest.java
@@ -54,10 +54,16 @@
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.mockito.ArgumentCaptor;
 
 import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.eq;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 import java.util.Map;
@@ -95,6 +101,11 @@
     // Used to test the "restore to default"
     private static final Uri URL_RESTOREAPN_USING_SUBID = Uri.parse(
             "content://telephony/carriers/restore/subId/" + TEST_SUBID);
+    // Used to test the preferred apn
+    private static final Uri URL_PREFERAPN_USING_SUBID = Uri.parse(
+            "content://telephony/carriers/preferapn/subId/" + TEST_SUBID);
+
+    private static final String COLUMN_APN_ID = "apn_id";
 
     // Constants for DPC related tests.
     private static final Uri URI_DPC = Uri.parse("content://telephony/carriers/dpc");
@@ -169,7 +180,7 @@
         }
 
         @Override
-       public SharedPreferences getSharedPreferences(String name, int mode) {
+        public SharedPreferences getSharedPreferences(String name, int mode) {
           return mSharedPreferences;
         }
 
@@ -1032,6 +1043,53 @@
     }
 
     /**
+     * Test URL_PREFERAPN_USING_SUBID works correctly.
+     */
+    @Test
+    @SmallTest
+    public void testQueryPreferredApn() {
+        // create APNs
+        ContentValues preferredValues = new ContentValues();
+        preferredValues.put(Carriers.APN, "apnName");
+        preferredValues.put(Carriers.NAME, "name");
+        preferredValues.put(Carriers.NUMERIC, TEST_OPERATOR);
+        ContentValues otherValues = new ContentValues();
+        final String otherApn = "otherApnName";
+        final String otherName = "otherName";
+        otherValues.put(Carriers.APN, otherApn);
+        otherValues.put(Carriers.NAME, otherName);
+        otherValues.put(Carriers.NUMERIC, TEST_OPERATOR);
+
+        // insert APNs
+        // TODO if using URL_TELEPHONY, SubscriptionManager.getDefaultSubscriptionId() returns -1
+        Log.d(TAG, "testQueryPreferredApn: Bulk inserting contentValues=" + preferredValues + ", "
+                + otherValues);
+        Uri uri = mContentResolver.insert(CONTENT_URI_WITH_SUBID, preferredValues);
+        mContentResolver.insert(CONTENT_URI_WITH_SUBID, otherValues);
+        final String preferredApnIdString = uri.getLastPathSegment();
+        final long preferredApnId = Long.parseLong(preferredApnIdString);
+        Log.d(TAG, "testQueryPreferredApn: preferredApnString=" + preferredApnIdString);
+
+        // set preferred apn
+        preferredValues.put(COLUMN_APN_ID, preferredApnIdString);
+        mContentResolver.insert(URL_PREFERAPN_USING_SUBID, preferredValues);
+
+        // query preferred APN
+        SharedPreferences sp = mContext.getSharedPreferences("", 0);
+        when(sp.getLong(anyString(), anyLong())).thenReturn(preferredApnId);
+        final String[] testProjection = { Carriers.APN, Carriers.NAME };
+        Cursor cursor = mContentResolver.query(
+                URL_PREFERAPN_USING_SUBID, testProjection, null, null, null);
+
+        // verify that preferred apn was set and retreived
+        ArgumentCaptor<Long> argumentCaptor = ArgumentCaptor.forClass(Long.class);
+        SharedPreferences.Editor e = sp.edit();
+        verify(e, times(1)).putLong(eq(COLUMN_APN_ID + TEST_SUBID), argumentCaptor.capture());
+        assertEquals(preferredApnId, (long) argumentCaptor.getValue());
+        assertEquals(1, cursor.getCount());
+    }
+
+    /**
      * Test URL_RESTOREAPN_USING_SUBID works correctly.
      */
     @Test