Merge "Added flag and tests for SubscriptionPlan changes" into main am: e73da557d5
Original change: https://android-review.googlesource.com/c/platform/frameworks/opt/telephony/+/3344423
Change-Id: I19c00c4c1d9b4437117703d02d3cd7ba538b74f4
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/flags/subscription.aconfig b/flags/subscription.aconfig
index 76485be..87c7408 100644
--- a/flags/subscription.aconfig
+++ b/flags/subscription.aconfig
@@ -58,6 +58,14 @@
}
}
+# OWNER=jmattis TARGET=25Q2
+flag {
+ name: "subscription_plan_allow_status_and_end_date"
+ namespace: "telephony"
+ description: "Provide APIs to retrieve the status and recurrence rule info on a subscription plan"
+ bug: "357272015"
+}
+
# OWNER=songferngwang TARGET=24Q3
flag {
name: "reset_primary_sim_default_values"
diff --git a/tests/telephonytests/src/com/android/internal/telephony/subscription/SubscriptionPlanTest.java b/tests/telephonytests/src/com/android/internal/telephony/subscription/SubscriptionPlanTest.java
new file mode 100644
index 0000000..2c13d3b
--- /dev/null
+++ b/tests/telephonytests/src/com/android/internal/telephony/subscription/SubscriptionPlanTest.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.telephony.subscription;
+
+import static android.telephony.SubscriptionPlan.SUBSCRIPTION_STATUS_ACTIVE;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
+
+import android.platform.test.annotations.RequiresFlagsEnabled;
+import android.telephony.SubscriptionPlan;
+import android.testing.AndroidTestingRunner;
+
+import com.android.internal.telephony.flags.Flags;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.time.Period;
+import java.time.ZonedDateTime;
+
+@RunWith(AndroidTestingRunner.class)
+public class SubscriptionPlanTest {
+ private static final ZonedDateTime ZONED_DATE_TIME_START =
+ ZonedDateTime.parse("2007-03-14T00:00:00.000Z");
+
+ @Test
+ @RequiresFlagsEnabled(Flags.FLAG_SUBSCRIPTION_PLAN_ALLOW_STATUS_AND_END_DATE)
+ public void testBuilderExpirationDateSetsCorrectly() {
+ ZonedDateTime endDate = ZonedDateTime.parse("2024-11-07T00:00:00.000Z");
+
+ SubscriptionPlan planNonRecurring = SubscriptionPlan.Builder
+ .createNonrecurring(ZONED_DATE_TIME_START, endDate)
+ .setTitle("unit test")
+ .build();
+ SubscriptionPlan planRecurring = SubscriptionPlan.Builder
+ .createRecurring(ZONED_DATE_TIME_START, Period.ofMonths(1))
+ .setTitle("unit test")
+ .build();
+
+ assertThat(planNonRecurring.getPlanEndDate()).isEqualTo(endDate);
+ assertNull(planRecurring.getPlanEndDate());
+ }
+
+ @Test
+ @RequiresFlagsEnabled(Flags.FLAG_SUBSCRIPTION_PLAN_ALLOW_STATUS_AND_END_DATE)
+ public void testBuilderValidSubscriptionStatusSetsCorrectly() {
+ @SubscriptionPlan.SubscriptionStatus int status = SUBSCRIPTION_STATUS_ACTIVE;
+
+ SubscriptionPlan plan = SubscriptionPlan.Builder
+ .createRecurring(ZONED_DATE_TIME_START, Period.ofMonths(1))
+ .setSubscriptionStatus(status)
+ .setTitle("unit test")
+ .build();
+
+ assertThat(plan.getSubscriptionStatus()).isEqualTo(status);
+ }
+
+ @Test
+ @RequiresFlagsEnabled(Flags.FLAG_SUBSCRIPTION_PLAN_ALLOW_STATUS_AND_END_DATE)
+ public void testBuilderInvalidSubscriptionStatusThrowsError() {
+ int minInvalid = -1;
+ int maxInvalid = 5;
+
+ assertThrows(IllegalArgumentException.class, () -> {
+ SubscriptionPlan.Builder
+ .createRecurring(ZONED_DATE_TIME_START, Period.ofMonths(1))
+ .setSubscriptionStatus(minInvalid)
+ .setTitle("unit test")
+ .build();
+ });
+
+ assertThrows(IllegalArgumentException.class, () -> {
+ SubscriptionPlan.Builder
+ .createRecurring(ZONED_DATE_TIME_START, Period.ofMonths(1))
+ .setSubscriptionStatus(maxInvalid)
+ .setTitle("unit test")
+ .build();
+ });
+ }
+}