Home | History | Annotate | Download | only in telephony
      1 /*
      2  * Copyright (c) 2010-2013, The Linux Foundation. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions are
      6  * met:
      7  *     * Redistributions of source code must retain the above copyright
      8  *       notice, this list of conditions and the following disclaimer.
      9  *     * Redistributions in binary form must reproduce the above
     10  *       copyright notice, this list of conditions and the following
     11  *       disclaimer in the documentation and/or other materials provided
     12  *       with the distribution.
     13  *     * Neither the name of The Linux Foundation nor the names of its
     14  *       contributors may be used to endorse or promote products derived
     15  *       from this software without specific prior written permission.
     16  *
     17  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
     18  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
     20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
     21  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
     24  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     25  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
     26  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
     27  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28  */
     29 
     30 package com.android.internal.telephony;
     31 
     32 import android.text.TextUtils;
     33 
     34 import android.telephony.Rlog;
     35 
     36 /**
     37  * Class holding all the information of a subscription from UICC Card.
     38  */
     39 public final class Subscription {
     40     private static final String LOG_TAG = "Subscription";
     41 
     42     public int slotId;                       // Slot id
     43     public int m3gppIndex;                   // Subscription index in the card for GSM
     44     public int m3gpp2Index;                  // Subscription index in the card for CDMA
     45     public int subId;                        // SUB 0 or SUB 1
     46     public SubscriptionStatus subStatus;      // DEACTIVATE = 0, ACTIVATE = 1,
     47                                              // ACTIVATED = 2, DEACTIVATED = 3, INVALID = 4;
     48     public String appId;
     49     public String appLabel;
     50     public String appType;
     51     public String iccId;
     52 
     53     private boolean DEBUG = false;
     54 
     55     /**
     56      * Subscription activation status
     57      */
     58     public enum SubscriptionStatus {
     59         SUB_DEACTIVATE,
     60             SUB_ACTIVATE,
     61             SUB_ACTIVATED,
     62             SUB_DEACTIVATED,
     63             SUB_INVALID
     64     }
     65 
     66     public static final int SUBSCRIPTION_INDEX_INVALID = -1;
     67 
     68     public Subscription() {
     69         clear();
     70     }
     71 
     72     public String toString() {
     73         return "Subscription = { "
     74             + "slotId = " + slotId
     75             + ", 3gppIndex = " + m3gppIndex
     76             + ", 3gpp2Index = " + m3gpp2Index
     77             + ", subId = " + subId
     78             + ", subStatus = " + subStatus
     79             + ", appId = " + appId
     80             + ", appLabel = " + appLabel
     81             + ", appType = " + appType
     82             + ", iccId = " + iccId + " }";
     83     }
     84 
     85     public boolean equals(Subscription sub) {
     86         if (sub != null) {
     87             if ((slotId == sub.slotId) && (m3gppIndex == sub.m3gppIndex)
     88                     && (m3gpp2Index == sub.m3gpp2Index) && (subId == sub.subId)
     89                     && (subStatus == sub.subStatus)
     90                     && ((TextUtils.isEmpty(appId) && TextUtils.isEmpty(sub.appId))
     91                             || TextUtils.equals(appId, sub.appId))
     92                     && ((TextUtils.isEmpty(appLabel) && TextUtils.isEmpty(sub.appLabel))
     93                             || TextUtils.equals(appLabel, sub.appLabel))
     94                     && ((TextUtils.isEmpty(appType) && TextUtils.isEmpty(sub.appType))
     95                             || TextUtils.equals(appType, sub.appType))
     96                     && ((TextUtils.isEmpty(iccId) && TextUtils.isEmpty(sub.iccId))
     97                             || TextUtils.equals(iccId, sub.iccId))) {
     98                 return true;
     99             }
    100         } else {
    101             Rlog.d(LOG_TAG, "Subscription.equals: sub == null");
    102         }
    103         return false;
    104     }
    105 
    106     /**
    107      * Return true if the appIndex, appId, appLabel and iccId are matching.
    108      * @param sub
    109      * @return
    110      */
    111     public boolean isSame(Subscription sub) {
    112         // Not checking the subId, subStatus and slotId, which are related to the
    113         // activated status
    114         if (sub != null) {
    115             if (DEBUG) {
    116                 Rlog.d(LOG_TAG, "isSame(): this = " + m3gppIndex
    117                         + ":" + m3gpp2Index
    118                         + ":" + appId
    119                         + ":" + appType
    120                         + ":" + iccId);
    121                 Rlog.d(LOG_TAG, "compare with = " + sub.m3gppIndex
    122                         + ":" + sub.m3gpp2Index
    123                         + ":" + sub.appId
    124                         + ":" + sub.appType
    125                         + ":" + sub.iccId);
    126             }
    127             if ((m3gppIndex == sub.m3gppIndex)
    128                     && (m3gpp2Index == sub.m3gpp2Index)
    129                     && ((TextUtils.isEmpty(appId) && TextUtils.isEmpty(sub.appId))
    130                             || TextUtils.equals(appId, sub.appId))
    131                     && ((TextUtils.isEmpty(appType) && TextUtils.isEmpty(sub.appType))
    132                             || TextUtils.equals(appType, sub.appType))
    133                     && ((TextUtils.isEmpty(iccId) && TextUtils.isEmpty(sub.iccId))
    134                             || TextUtils.equals(iccId, sub.iccId))){
    135                 return true;
    136             }
    137         }
    138         return false;
    139     }
    140 
    141     /**
    142      * Reset the subscription
    143      */
    144     public void clear() {
    145         slotId = SUBSCRIPTION_INDEX_INVALID;
    146         m3gppIndex = SUBSCRIPTION_INDEX_INVALID;
    147         m3gpp2Index = SUBSCRIPTION_INDEX_INVALID;
    148         subId = SUBSCRIPTION_INDEX_INVALID;
    149         subStatus = SubscriptionStatus.SUB_INVALID;
    150         appId = null;
    151         appLabel = null;
    152         appType = null;
    153         iccId = null;
    154     }
    155 
    156     /**
    157      * Copies the subscription parameters
    158      * @param from
    159      * @return
    160      */
    161     public Subscription copyFrom(Subscription from) {
    162         if (from != null) {
    163             slotId = from.slotId;
    164             m3gppIndex = from.m3gppIndex;
    165             m3gpp2Index = from.m3gpp2Index;
    166             subId = from.subId;
    167             subStatus = from.subStatus;
    168             if (from.appId != null) {
    169                 appId = new String(from.appId);
    170             }
    171             if (from.appLabel != null) {
    172                 appLabel = new String(from.appLabel);
    173             }
    174             if (from.appType != null) {
    175                 appType = new String(from.appType);
    176             }
    177             if (from.iccId != null) {
    178                 iccId = new String(from.iccId);
    179             }
    180         }
    181 
    182         return this;
    183     }
    184 
    185     /**
    186      * Return the valid app index (either 3gpp or 3gpp2 index)
    187      * @return
    188      */
    189     public int getAppIndex() {
    190         if (this.m3gppIndex != SUBSCRIPTION_INDEX_INVALID) {
    191             return this.m3gppIndex;
    192         } else {
    193             return this.m3gpp2Index;
    194         }
    195     }
    196 }
    197