Guard user disabled slicing error behind feature flag

Test: SlicePurchaseControllerTest
Bug: 307378699
Change-Id: Icd897b37d71b51626f8abb7654658398443a64e2
diff --git a/src/com/android/phone/PhoneGlobals.java b/src/com/android/phone/PhoneGlobals.java
index b11431c..4773a83 100644
--- a/src/com/android/phone/PhoneGlobals.java
+++ b/src/com/android/phone/PhoneGlobals.java
@@ -554,7 +554,7 @@
 
             mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
 
-            phoneMgr = PhoneInterfaceManager.init(this);
+            phoneMgr = PhoneInterfaceManager.init(this, featureFlags);
 
             imsRcsController = ImsRcsController.init(this);
 
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index 26d1e73..4e673d8 100644
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -209,6 +209,7 @@
 import com.android.internal.telephony.domainselection.DomainSelectionResolver;
 import com.android.internal.telephony.emergency.EmergencyNumberTracker;
 import com.android.internal.telephony.euicc.EuiccConnector;
+import com.android.internal.telephony.flags.FeatureFlags;
 import com.android.internal.telephony.ims.ImsResolver;
 import com.android.internal.telephony.imsphone.ImsPhone;
 import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
@@ -402,6 +403,7 @@
     private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
 
     private final PhoneGlobals mApp;
+    private final FeatureFlags mFeatureFlags;
     private final CallManager mCM;
     private final ImsResolver mImsResolver;
 
@@ -2212,8 +2214,8 @@
                     onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
                     PurchasePremiumCapabilityArgument arg =
                             (PurchasePremiumCapabilityArgument) request.argument;
-                    SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability(
-                            arg.capability, onCompleted);
+                    SlicePurchaseController.getInstance(request.phone, mFeatureFlags)
+                            .purchasePremiumCapability(arg.capability, onCompleted);
                     break;
                 }
 
@@ -2426,10 +2428,10 @@
      * Initialize the singleton PhoneInterfaceManager instance.
      * This is only done once, at startup, from PhoneApp.onCreate().
      */
-    /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
+    /* package */ static PhoneInterfaceManager init(PhoneGlobals app, FeatureFlags featureFlags) {
         synchronized (PhoneInterfaceManager.class) {
             if (sInstance == null) {
-                sInstance = new PhoneInterfaceManager(app);
+                sInstance = new PhoneInterfaceManager(app, featureFlags);
             } else {
                 Log.wtf(LOG_TAG, "init() called multiple times!  sInstance = " + sInstance);
             }
@@ -2438,8 +2440,9 @@
     }
 
     /** Private constructor; @see init() */
-    private PhoneInterfaceManager(PhoneGlobals app) {
+    private PhoneInterfaceManager(PhoneGlobals app, FeatureFlags featureFlags) {
         mApp = app;
+        mFeatureFlags = featureFlags;
         mCM = PhoneGlobals.getInstance().mCM;
         mImsResolver = ImsResolver.getInstance();
         mSatelliteController = SatelliteController.getInstance();
@@ -11542,7 +11545,7 @@
         }
         final long identity = Binder.clearCallingIdentity();
         try {
-            return SlicePurchaseController.getInstance(phone)
+            return SlicePurchaseController.getInstance(phone, mFeatureFlags)
                     .isPremiumCapabilityAvailableForPurchase(capability);
         } finally {
             Binder.restoreCallingIdentity(identity);
diff --git a/src/com/android/phone/slice/SlicePurchaseController.java b/src/com/android/phone/slice/SlicePurchaseController.java
index 26d70d2..9a42e16 100644
--- a/src/com/android/phone/slice/SlicePurchaseController.java
+++ b/src/com/android/phone/slice/SlicePurchaseController.java
@@ -58,6 +58,7 @@
 
 import com.android.internal.annotations.VisibleForTesting;
 import com.android.internal.telephony.Phone;
+import com.android.internal.telephony.flags.FeatureFlags;
 
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
@@ -309,6 +310,8 @@
 
     /** The Phone instance used to create the SlicePurchaseController. */
     @NonNull private final Phone mPhone;
+    /** Feature flags to control behavior and errors. */
+    @NonNull private final FeatureFlags mFeatureFlags;
     /** The set of capabilities that are pending network setup. */
     @NonNull private final Set<Integer> mPendingSetupCapabilities = new HashSet<>();
     /** The set of throttled capabilities. */
@@ -417,10 +420,11 @@
                     logd("Slice purchase application unable to show notification for capability: "
                             + TelephonyManager.convertPremiumCapabilityToString(capability)
                             + " because the user has disabled notifications.");
+                    int error = mFeatureFlags.slicingAdditionalErrorCodes()
+                            ? TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_USER_DISABLED
+                            : TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_USER_CANCELED;
                     SlicePurchaseController.getInstance(phoneId)
-                            .handlePurchaseResult(capability,
-                            TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_USER_DISABLED,
-                            true);
+                            .handlePurchaseResult(capability, error, true);
                     break;
                 }
                 case ACTION_SLICE_PURCHASE_APP_RESPONSE_SUCCESS: {
@@ -449,14 +453,16 @@
      * @param phone The Phone to get the SlicePurchaseController for.
      * @return The static SlicePurchaseController instance.
      */
-    @NonNull public static synchronized SlicePurchaseController getInstance(@NonNull Phone phone) {
+    @NonNull public static synchronized SlicePurchaseController getInstance(@NonNull Phone phone,
+            @NonNull FeatureFlags featureFlags) {
         // TODO: Add listeners for multi sim setting changed (maybe carrier config changed too)
         //  that dismiss notifications and update SlicePurchaseController instance
         int phoneId = phone.getPhoneId();
         if (sInstances.get(phoneId) == null) {
             HandlerThread handlerThread = new HandlerThread("SlicePurchaseController");
             handlerThread.start();
-            sInstances.put(phoneId, new SlicePurchaseController(phone, handlerThread.getLooper()));
+            sInstances.put(phoneId,
+                    new SlicePurchaseController(phone, featureFlags, handlerThread.getLooper()));
         }
         return sInstances.get(phoneId);
     }
@@ -476,12 +482,15 @@
      * Create a SlicePurchaseController for the given phone on the given looper.
      *
      * @param phone The Phone to create the SlicePurchaseController for.
+     * @param featureFlags The FeatureFlags that are supported.
      * @param looper The Looper to run the SlicePurchaseController on.
      */
     @VisibleForTesting
-    public SlicePurchaseController(@NonNull Phone phone, @NonNull Looper looper) {
+    public SlicePurchaseController(@NonNull Phone phone, @NonNull FeatureFlags featureFlags,
+            @NonNull Looper looper) {
         super(looper);
         mPhone = phone;
+        mFeatureFlags = featureFlags;
         // TODO: Create a cached value for slicing config in DataIndication and initialize here
         mPhone.mCi.registerForSlicingConfigChanged(this, EVENT_SLICING_CONFIG_CHANGED, null);
         mIsSlicingUpsellEnabled = DeviceConfig.getBoolean(