Add deprovisionSatelliteService API

Bug: 266013384
Test: atest android.telephony.cts.SatelliteManagerTest

Change-Id: Iafc69f2d7ba64e9d818db4cc27ec455d0cd5344f
diff --git a/telephony/java/android/telephony/satellite/ISatelliteStateListener.aidl b/telephony/java/android/telephony/satellite/ISatelliteStateListener.aidl
index 6fb0979..d3924d6 100644
--- a/telephony/java/android/telephony/satellite/ISatelliteStateListener.aidl
+++ b/telephony/java/android/telephony/satellite/ISatelliteStateListener.aidl
@@ -23,7 +23,7 @@
  * @hide
  */
 oneway interface ISatelliteStateListener {
-    void onSatelliteProvisionStateChanged(in int[] features, in boolean provisioned);
+    void onSatelliteProvisionStateChanged(in boolean provisioned);
     void onSatellitePositionUpdate(in PointingInfo pointingInfo);
     void onMessageTransferStateUpdate(in int state);
 }
diff --git a/telephony/java/android/telephony/satellite/SatelliteCallback.java b/telephony/java/android/telephony/satellite/SatelliteCallback.java
index 1b82d06..6d0a992 100644
--- a/telephony/java/android/telephony/satellite/SatelliteCallback.java
+++ b/telephony/java/android/telephony/satellite/SatelliteCallback.java
@@ -18,7 +18,6 @@
 
 import android.annotation.NonNull;
 import android.os.Binder;
-import android.telephony.satellite.stub.SatelliteImplBase;
 
 import java.lang.ref.WeakReference;
 import java.util.concurrent.Executor;
@@ -63,12 +62,10 @@
         /**
          * Called when satellite provision state changes.
          *
-         * @param features The list of provisioned features.
          * @param provisioned The new provision state. {@code true} means satellite is provisioned
          *                    {@code false} means satellite is not provisioned.
          */
-        void onSatelliteProvisionStateChanged(
-                @SatelliteImplBase.Feature int[] features, boolean provisioned);
+        void onSatelliteProvisionStateChanged(boolean provisioned);
     }
 
     /**
@@ -100,14 +97,13 @@
             mExecutor = executor;
         }
 
-        public void onSatelliteProvisionStateChanged(
-                @SatelliteImplBase.Feature int[] features, boolean provisioned) {
+        public void onSatelliteProvisionStateChanged(boolean provisioned) {
             SatelliteProvisionStateListener listener =
                     (SatelliteProvisionStateListener) mSatelliteCallbackWeakRef.get();
             if (listener == null) return;
 
             Binder.withCleanCallingIdentity(() -> mExecutor.execute(
-                    () -> listener.onSatelliteProvisionStateChanged(features, provisioned)));
+                    () -> listener.onSatelliteProvisionStateChanged(provisioned)));
         }
 
         public void onSatellitePositionUpdate(@NonNull PointingInfo pointingInfo) {
diff --git a/telephony/java/android/telephony/satellite/SatelliteManager.java b/telephony/java/android/telephony/satellite/SatelliteManager.java
index 129d4ca..9763950 100644
--- a/telephony/java/android/telephony/satellite/SatelliteManager.java
+++ b/telephony/java/android/telephony/satellite/SatelliteManager.java
@@ -638,7 +638,8 @@
      * Provision the device with a satellite provider.
      * This is needed if the provider allows dynamic registration.
      *
-     * @param token The security token of the device/subscription to be provisioned.
+     * @param token The token to be used as a unique identifier for provisioning with satellite
+     *              gateway.
      * @param cancellationSignal The optional signal used by the caller to cancel the provision
      *                           request. Even when the cancellation is signaled, Telephony will
      *                           still trigger the callback to return the result of this request.
@@ -682,6 +683,48 @@
     }
 
     /**
+     * Deprovision the device with the satellite provider.
+     * This is needed if the provider allows dynamic registration. Once deprovisioned,
+     * {@link SatelliteCallback.SatelliteProvisionStateListener#onSatelliteProvisionStateChanged}
+     * should report as deprovisioned.
+     * For provisioning satellite service, refer to
+     * {@link #provisionSatelliteService(String, CancellationSignal, Executor, Consumer)}.
+     *
+     * @param token The token of the device/subscription to be deprovisioned.
+     * @param errorCodeListener Listener for the {@link SatelliteError} result of the operation.
+     *
+     * @throws SecurityException if the caller doesn't have required permission.
+     * @throws IllegalStateException if the Telephony process is not currently available.
+     */
+    @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
+    public void deprovisionSatelliteService(@NonNull String token,
+            @NonNull @CallbackExecutor Executor executor,
+            @SatelliteError @NonNull Consumer<Integer> errorCodeListener) {
+        Objects.requireNonNull(token);
+        Objects.requireNonNull(executor);
+        Objects.requireNonNull(errorCodeListener);
+
+        try {
+            ITelephony telephony = getITelephony();
+            if (telephony != null) {
+                IIntegerConsumer errorCallback = new IIntegerConsumer.Stub() {
+                    @Override
+                    public void accept(int result) {
+                        executor.execute(() -> Binder.withCleanCallingIdentity(
+                                () -> errorCodeListener.accept(result)));
+                    }
+                };
+                telephony.deprovisionSatelliteService(mSubId, token, errorCallback);
+            } else {
+                throw new IllegalStateException("telephony service is null.");
+            }
+        } catch (RemoteException ex) {
+            loge("deprovisionSatelliteService RemoteException=" + ex);
+            ex.rethrowFromSystemServer();
+        }
+    }
+
+    /**
      * Register for the satellite provision state change.
      *
      * @param executor The executor on which the callback and error code listener will be called.
diff --git a/telephony/java/com/android/internal/telephony/ITelephony.aidl b/telephony/java/com/android/internal/telephony/ITelephony.aidl
index 07deead..3121c3c 100644
--- a/telephony/java/com/android/internal/telephony/ITelephony.aidl
+++ b/telephony/java/com/android/internal/telephony/ITelephony.aidl
@@ -2783,7 +2783,8 @@
      * This is needed to register the subscription if the provider allows dynamic registration.
      *
      * @param subId The subId of the subscription to be provisioned.
-     * @param token The security token of the device/subscription to be provisioned.
+     * @param token The token to be used as a unique identifier for provisioning with satellite
+     *              gateway.
      * @param callback The callback to get the error code of the request.
      *
      * @return The signal transport used by callers to cancel the provision request.
@@ -2794,6 +2795,22 @@
             in IIntegerConsumer callback);
 
     /**
+     * Unregister the subscription with the satellite provider.
+     * This is needed to unregister the subscription if the provider allows dynamic registration.
+     * Once deprovisioned,
+     * {@link SatelliteCallback.SatelliteProvisionStateListener#onSatelliteProvisionStateChanged}
+     * should report as deprovisioned.
+     *
+     * @param subId The subId of the subscription to be deprovisioned.
+     * @param token The token of the device/subscription to be deprovisioned.
+     * @param callback The callback to get the error code of the request.
+     */
+    @JavaPassthrough(annotation="@android.annotation.RequiresPermission("
+            + "android.Manifest.permission.SATELLITE_COMMUNICATION)")
+    void deprovisionSatelliteService(int subId, in String token, in IIntegerConsumer callback);
+
+
+    /**
      * Register for the satellite provision state change.
      *
      * @param subId The subId of the subscription to register for provision state changes for.