Merge "[NTN][Geofence] CTS for geofence enhancement" into main
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index cf83585..495c7f2 100644
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -14839,7 +14839,13 @@
     public void setNtnSmsSupported(boolean ntnSmsSupported) {
         enforceSatelliteCommunicationPermission("setNtnSmsSupported");
         enforceSendSmsPermission();
-        mSatelliteController.setNtnSmsSupportedByMessagesApp(ntnSmsSupported);
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            mSatelliteController.setNtnSmsSupportedByMessagesApp(ntnSmsSupported);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     /**
diff --git a/src/com/android/phone/satellite/accesscontrol/SatelliteAccessConfigurationParser.java b/src/com/android/phone/satellite/accesscontrol/SatelliteAccessConfigurationParser.java
index 0658279..895edfd 100644
--- a/src/com/android/phone/satellite/accesscontrol/SatelliteAccessConfigurationParser.java
+++ b/src/com/android/phone/satellite/accesscontrol/SatelliteAccessConfigurationParser.java
@@ -60,7 +60,6 @@
     public static final String SATELLITE_BANDS = "bands";
     public static final String SATELLITE_TAG_ID_LIST = "tag_ids";
 
-
     /**
      * Parses a JSON file containing satellite access configurations.
      *
@@ -193,15 +192,17 @@
         return satelliteId;
     }
 
-    @Nullable
+    @NonNull
     protected static SatellitePosition parseSatellitePosition(
             @NonNull JSONObject satelliteInfoJson) {
         JSONObject jsonObject = satelliteInfoJson.optJSONObject(SATELLITE_POSITION);
+        SatellitePosition satellitePosition = new SatellitePosition(Double.NaN, Double.NaN);
+
         if (jsonObject == null) {
             loge("parseSatellitePosition: jsonObject is null");
-            return null;
+            return satellitePosition;
         }
-        SatellitePosition satellitePosition;
+
         try {
             double longitude = jsonObject.getDouble(SATELLITE_LONGITUDE);
             double altitude = jsonObject.getDouble(SATELLITE_ALTITUDE);
@@ -209,11 +210,11 @@
                 satellitePosition = new SatellitePosition(longitude, altitude);
             } else {
                 loge("parseSatellitePosition: invalid value: " + longitude + " | " + altitude);
-                return null;
+                return satellitePosition;
             }
         } catch (JSONException e) {
             loge("parseSatellitePosition: json parsing error " + e.getMessage());
-            return null;
+            return satellitePosition;
         }
 
         logd("parseSatellitePosition: " + satellitePosition);
diff --git a/testapps/TestSatelliteApp/res/layout/activity_TestSatelliteWrapper.xml b/testapps/TestSatelliteApp/res/layout/activity_TestSatelliteWrapper.xml
index d046f03..b4df40a 100644
--- a/testapps/TestSatelliteApp/res/layout/activity_TestSatelliteWrapper.xml
+++ b/testapps/TestSatelliteApp/res/layout/activity_TestSatelliteWrapper.xml
@@ -203,6 +203,12 @@
             android:layout_height="wrap_content"
             android:paddingRight="4dp"
             android:text="@string/setNtnSmsSupportedFalse"/>
+        <Button
+            android:id="@+id/requestSatelliteAccessConfigurationForCurrentLocation"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:paddingRight="4dp"
+            android:text="@string/requestSatelliteAccessConfigurationForCurrentLocation"/>
 
         <LinearLayout
             android:layout_width="match_parent"
diff --git a/testapps/TestSatelliteApp/res/values/donottranslate_strings.xml b/testapps/TestSatelliteApp/res/values/donottranslate_strings.xml
index 4b5ea5b..5c3a72d 100644
--- a/testapps/TestSatelliteApp/res/values/donottranslate_strings.xml
+++ b/testapps/TestSatelliteApp/res/values/donottranslate_strings.xml
@@ -109,4 +109,6 @@
 
     <string name="registerForModemStateChanged">registerForModemStateChanged</string>
     <string name="unregisterForModemStateChanged">unregisterForModemStateChanged</string>
+
+    <string name="requestSatelliteAccessConfigurationForCurrentLocation">requestSatelliteAccessConfigurationForCurrentLocation</string>
 </resources>
diff --git a/testapps/TestSatelliteApp/src/com/android/phone/testapps/satellitetestapp/TestSatelliteWrapper.java b/testapps/TestSatelliteApp/src/com/android/phone/testapps/satellitetestapp/TestSatelliteWrapper.java
index 7d5e9af..5092d03 100644
--- a/testapps/TestSatelliteApp/src/com/android/phone/testapps/satellitetestapp/TestSatelliteWrapper.java
+++ b/testapps/TestSatelliteApp/src/com/android/phone/testapps/satellitetestapp/TestSatelliteWrapper.java
@@ -26,6 +26,7 @@
 import android.telephony.satellite.wrapper.CarrierRoamingNtnModeListenerWrapper2;
 import android.telephony.satellite.wrapper.NtnSignalStrengthCallbackWrapper;
 import android.telephony.satellite.wrapper.NtnSignalStrengthWrapper;
+import android.telephony.satellite.wrapper.SatelliteAccessConfigurationWrapper;
 import android.telephony.satellite.wrapper.SatelliteCapabilitiesCallbackWrapper;
 import android.telephony.satellite.wrapper.SatelliteCommunicationAllowedStateCallbackWrapper;
 import android.telephony.satellite.wrapper.SatelliteManagerWrapper;
@@ -131,6 +132,9 @@
                 .setOnClickListener(this::setNtnSmsSupportedTrue);
         findViewById(R.id.setNtnSmsSupportedFalse)
                 .setOnClickListener(this::setNtnSmsSupportedFalse);
+        findViewById(R.id.requestSatelliteAccessConfigurationForCurrentLocation)
+                .setOnClickListener(this::requestSatelliteAccessConfigurationForCurrentLocation);
+
 
 
         findViewById(R.id.Back).setOnClickListener(new OnClickListener() {
@@ -703,6 +707,47 @@
         }
     }
 
+    private void requestSatelliteAccessConfigurationForCurrentLocation(View view) {
+        addLogMessage("requestSatelliteAccessConfigurationForCurrentLocation");
+        logd("requestSatelliteAccessConfigurationForCurrentLocation");
+        OutcomeReceiver<SatelliteAccessConfigurationWrapper,
+                SatelliteManagerWrapper.SatelliteExceptionWrapper> receiver =
+                new OutcomeReceiver<>() {
+                    @Override
+                    public void onResult(SatelliteAccessConfigurationWrapper result) {
+                        if (result != null) {
+                            addLogMessage("requestSatelliteAccessConfigurationForCurrentLocation: "
+                                    + result.getSatelliteInfos());
+                        } else {
+                            addLogMessage("requestSatelliteAccessConfigurationForCurrentLocation: "
+                                    + "null");
+                        }
+                    }
+
+                    @Override
+                    public void onError(
+                            SatelliteManagerWrapper.SatelliteExceptionWrapper exception) {
+                        if (exception != null) {
+                            String onError = "requestSatelliteAccessConfigurationForCurrentLocation"
+                                    + " exception: "
+                                    + translateResultCodeToString(exception.getErrorCode());
+                            logd(onError);
+                            addLogMessage(onError);
+                        }
+                    }
+                };
+
+        try {
+            mSatelliteManagerWrapper
+                    .requestSatelliteAccessConfigurationForCurrentLocation(mExecutor, receiver);
+        } catch (SecurityException ex) {
+            String errorMessage = "requestSatelliteAccessConfigurationForCurrentLocation: "
+                    + ex.getMessage();
+            logd(errorMessage);
+            addLogMessage(errorMessage);
+        }
+    }
+
     private void addAttachRestrictionForCarrier(View view) {
         addLogMessage("addAttachRestrictionForCarrier");
         logd("addAttachRestrictionForCarrier");
diff --git a/tests/src/com/android/phone/satellite/accesscontrol/SatelliteAccessConfigurationParserTest.java b/tests/src/com/android/phone/satellite/accesscontrol/SatelliteAccessConfigurationParserTest.java
index d577a63..72fb705 100644
--- a/tests/src/com/android/phone/satellite/accesscontrol/SatelliteAccessConfigurationParserTest.java
+++ b/tests/src/com/android/phone/satellite/accesscontrol/SatelliteAccessConfigurationParserTest.java
@@ -301,7 +301,10 @@
             for (int j = 0; j < satelliteInfoArray.length(); j++) {
                 JSONObject infoJson = satelliteInfoArray.getJSONObject(i);
                 assertNull(parseSatelliteId(infoJson));
-                assertNull(parseSatellitePosition(infoJson));
+                SatellitePosition satellitePosition = parseSatellitePosition(infoJson);
+                assertNotNull(satellitePosition);
+                assertTrue(Double.isNaN(satellitePosition.getLongitudeDegrees()));
+                assertTrue(Double.isNaN(satellitePosition.getAltitudeKm()));
                 assertTrue(parseSatelliteEarfcnRangeList(infoJson).isEmpty());
                 assertNotNull(parseSatelliteBandList(infoJson));
                 assertEquals(0, parseSatelliteBandList(infoJson).size());