Merge "Query without a subid uses the default subid"
am: 8af31df84b

Change-Id: Ibe0cd1a415a8b6d07bde7ea6eb0a14d113763566
diff --git a/src/com/android/providers/telephony/ServiceStateProvider.java b/src/com/android/providers/telephony/ServiceStateProvider.java
index f4d9b2b..dcbcc6a 100644
--- a/src/com/android/providers/telephony/ServiceStateProvider.java
+++ b/src/com/android/providers/telephony/ServiceStateProvider.java
@@ -125,7 +125,7 @@
             try {
                 subId = Integer.parseInt(uri.getLastPathSegment());
             } catch (NumberFormatException e) {
-                Log.d(TAG, "insert: no subId provided in uri");
+                Log.e(TAG, "insert: no subId provided in uri");
                 throw e;
             }
             Log.d(TAG, "subId=" + subId);
@@ -200,8 +200,8 @@
             try {
                 subId = Integer.parseInt(uri.getLastPathSegment());
             } catch (NumberFormatException e) {
-                Log.d(TAG, "query: no subId provided in uri");
-                throw e;
+                Log.d(TAG, "query: no subId provided in uri, using default.");
+                subId = getDefaultSubId();
             }
             Log.d(TAG, "subId=" + subId);
 
diff --git a/tests/src/com/android/providers/telephony/ServiceStateProviderTest.java b/tests/src/com/android/providers/telephony/ServiceStateProviderTest.java
index 0d99386..685d9be 100644
--- a/tests/src/com/android/providers/telephony/ServiceStateProviderTest.java
+++ b/tests/src/com/android/providers/telephony/ServiceStateProviderTest.java
@@ -149,12 +149,24 @@
 
     @Test
     @SmallTest
+    public void testQueryServiceStateWithNoSubId() {
+        // Verify that when calling query with no subId in the uri the default ServiceState is
+        // returned.
+        // In this case the subId is set to 0 and the expected service state is
+        // testServiceState.
+        verifyServiceStateForSubId(ServiceStateTable.CONTENT_URI, testServiceState);
+    }
+
+    @Test
+    @SmallTest
     public void testGetServiceStateWithDefaultSubId() {
         // Verify that when calling with the DEFAULT_SUBSCRIPTION_ID the correct ServiceState is
         // returned
         // In this case the subId is set to 0 and the expected service state is
-        // testServiceState
-        verifyServiceStateForSubId(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, testServiceState);
+        // testServiceState.
+        verifyServiceStateForSubId(
+                getUriForSubscriptionId(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID),
+                testServiceState);
     }
 
     /**
@@ -166,11 +178,11 @@
         // Verify that when calling with a specific subId the correct ServiceState is returned
         // In this case the subId is set to 1 and the expected service state is
         // testServiceStateForSubId1
-        verifyServiceStateForSubId(1, testServiceStateForSubId1);
+        verifyServiceStateForSubId(getUriForSubscriptionId(1), testServiceStateForSubId1);
     }
 
-    private void verifyServiceStateForSubId(int subId, ServiceState ss) {
-        Cursor cursor = mContentResolver.query(getUriForSubscriptionId(subId), testProjection, "",
+    private void verifyServiceStateForSubId(Uri uri, ServiceState ss) {
+        Cursor cursor = mContentResolver.query(uri, testProjection, "",
                 null, null);
         assertNotNull(cursor);
         cursor.moveToFirst();