1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.imsserviceentitlement;
18 
19 import android.content.Intent;
20 import android.telephony.SubscriptionManager;
21 import android.util.Log;
22 
23 /**
24  * Constants shared by framework to start WFC activation activity.
25  *
26  * <p>Must match with WifiCallingSettings.
27  */
28 public final class ActivityConstants {
29     public static final String TAG = "IMSSE-ActivityConstants";
30 
31     /** Constants shared by WifiCallingSettings */
32     public static final String EXTRA_LAUNCH_CARRIER_APP = "EXTRA_LAUNCH_CARRIER_APP";
33 
34     public static final int LAUNCH_APP_ACTIVATE = 0;
35     public static final int LAUNCH_APP_UPDATE = 1;
36     public static final int LAUNCH_APP_SHOW_TC = 2;
37 
38     /** Constants shared by QNS module */
39     public static final String EXTRA_URL = "EXTRA_URL";
40 
41     /**
42      * Returns {@code true} if the app is launched for WFC activation; {@code false} for emergency
43      * address update or displaying terms & conditions.
44      */
isActivationFlow(Intent intent)45     public static boolean isActivationFlow(Intent intent) {
46         int intention = getLaunchIntention(intent);
47         Log.d(TAG, "Start Activity intention : " + intention);
48         return intention == LAUNCH_APP_ACTIVATE;
49     }
50 
51     /** Returns the launch intention extra in the {@code intent}. */
getLaunchIntention(Intent intent)52     public static int getLaunchIntention(Intent intent) {
53         if (intent == null) {
54             return LAUNCH_APP_ACTIVATE;
55         }
56 
57         return intent.getIntExtra(EXTRA_LAUNCH_CARRIER_APP, LAUNCH_APP_ACTIVATE);
58     }
59 
60     /** Returns the subscription id of starting the WFC activation activity. */
getSubId(Intent intent)61     public static int getSubId(Intent intent) {
62         if (intent == null) {
63             return SubscriptionManager.INVALID_SUBSCRIPTION_ID;
64         }
65         int subId =
66                 intent.getIntExtra(
67                         SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX,
68                         SubscriptionManager.INVALID_SUBSCRIPTION_ID);
69         Log.d(TAG, "Start Activity with subId : " + subId);
70         return subId;
71     }
72 
getUrl(Intent intent)73     public static String getUrl(Intent intent) {
74         String url = "";
75         if (intent == null || (url = intent.getStringExtra(EXTRA_URL)) == null) {
76             return "";
77         }
78         return url;
79     }
80 
ActivityConstants()81     private ActivityConstants() {}
82 }
83