am 476520f7: am 3749541a: Merge "Adding helper functions to retrieve settings that are stored per subId." into lmp-mr1-dev

* commit '476520f744a950fc27d6ac466c301a909d92481a':
  Adding helper functions to retrieve settings that are stored per subId.
diff --git a/services/core/java/com/android/server/location/GpsLocationProvider.java b/services/core/java/com/android/server/location/GpsLocationProvider.java
index 7e2b970..b46a450 100644
--- a/services/core/java/com/android/server/location/GpsLocationProvider.java
+++ b/services/core/java/com/android/server/location/GpsLocationProvider.java
@@ -788,8 +788,9 @@
         }
 
         if (info != null) {
-            boolean dataEnabled = Settings.Global.getInt(mContext.getContentResolver(),
-                                                         Settings.Global.MOBILE_DATA, 1) == 1;
+            boolean dataEnabled = TelephonyManager.getIntWithSubId(mContext.getContentResolver(),
+                    Settings.Global.MOBILE_DATA, SubscriptionManager.getDefaultSubId(),
+                    1) == 1;
             boolean networkAvailable = info.isAvailable() && dataEnabled;
             String defaultApn = getSelectedApn();
             if (defaultApn == null) {
diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java
index 7274670..8c45f7b 100644
--- a/telephony/java/android/telephony/TelephonyManager.java
+++ b/telephony/java/android/telephony/TelephonyManager.java
@@ -19,8 +19,11 @@
 import android.annotation.SystemApi;
 import android.annotation.SdkConstant;
 import android.annotation.SdkConstant.SdkConstantType;
+import android.content.ContentResolver;
 import android.content.Context;
 import android.content.Intent;
+import android.provider.Settings;
+import android.provider.Settings.SettingNotFoundException;
 import android.os.Bundle;
 import android.os.RemoteException;
 import android.os.ServiceManager;
@@ -3520,4 +3523,48 @@
         }
         return false;
     }
+
+    /**
+     * This function retrieves value for setting "name+subId", and if that is not found
+     * retrieves value for setting "name", and if that is not found uses def as default
+     *
+     * @hide */
+    public static int getIntWithSubId(ContentResolver cr, String name, int subId, int def) {
+        return Settings.Global.getInt(cr, name + subId, Settings.Global.getInt(cr, name, def));
+    }
+
+    /**
+     * This function retrieves value for setting "name+subId", and if that is not found
+     * retrieves value for setting "name", and if that is not found throws
+     * SettingNotFoundException
+     *
+     * @hide */
+    public static int getIntWithSubId(ContentResolver cr, String name, int subId)
+            throws SettingNotFoundException {
+        try {
+            return Settings.Global.getInt(cr, name + subId);
+        } catch (SettingNotFoundException e) {
+            try {
+                int val = Settings.Global.getInt(cr, name);
+                /* We are now moving from 'setting' to 'setting+subId', and using the value stored
+                 * for 'setting' as default. Reset the default (since it may have a user set
+                 * value). */
+                int default_val = val;
+                if (name.equals(Settings.Global.MOBILE_DATA)) {
+                    default_val = "true".equalsIgnoreCase(
+                            SystemProperties.get("ro.com.android.mobiledata", "true")) ? 1 : 0;
+                }
+
+                if (default_val != val) {
+                    Settings.Global.putInt(cr, name, default_val);
+                }
+
+                return val;
+            } catch (SettingNotFoundException exc) {
+                throw new SettingNotFoundException(name);
+            }
+        }
+    }
 }
+
+