Home | History | Annotate | Download | only in telephony
      1 /*
      2  * Copyright (C) 2017 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 android.telephony;
     18 
     19 import android.os.Parcel;
     20 import android.os.Parcelable;
     21 
     22 import java.util.Arrays;
     23 
     24 /**
     25  * Describes a particular radio access network to be scanned.
     26  *
     27  * The scan can be performed on either bands or channels for a specific radio access network type.
     28  */
     29 public final class RadioAccessSpecifier implements Parcelable {
     30 
     31     /**
     32      * The radio access network that needs to be scanned
     33      *
     34      * This parameter must be provided or else the scan will be rejected.
     35      *
     36      * See {@link AccessNetworkConstants.AccessNetworkType} for details.
     37      */
     38     private int mRadioAccessNetwork;
     39 
     40     /**
     41      * The frequency bands that need to be scanned
     42      *
     43      * When no specific bands are specified (empty array or null), all the frequency bands
     44      * supported by the modem will be scanned.
     45      *
     46      * See {@link AccessNetworkConstants} for details.
     47      */
     48     private int[] mBands;
     49 
     50     /**
     51      * The frequency channels that need to be scanned
     52      *
     53      * When any specific channels are provided for scan, the corresponding frequency bands that
     54      * contains those channels must also be provided, or else the channels will be ignored.
     55      *
     56      * When no specific channels are specified (empty array or null), all the frequency channels
     57      * supported by the modem will be scanned.
     58      *
     59      * See {@link AccessNetworkConstants} for details.
     60      */
     61     private int[] mChannels;
     62 
     63     /**
     64     * Creates a new RadioAccessSpecifier with radio network, bands and channels
     65     *
     66     * The user must specify the radio network type, and at least specify either of frequency
     67     * bands or channels.
     68     *
     69     * @param ran The type of the radio access network
     70     * @param bands the frequency bands to be scanned
     71     * @param channels the frequency bands to be scanned
     72     */
     73     public RadioAccessSpecifier(int ran, int[] bands, int[] channels) {
     74         this.mRadioAccessNetwork = ran;
     75         if (bands != null) {
     76             this.mBands = bands.clone();
     77         } else {
     78             this.mBands = null;
     79         }
     80         if (channels != null) {
     81             this.mChannels = channels.clone();
     82         } else {
     83             this.mChannels = null;
     84         }
     85     }
     86 
     87     /**
     88      * Returns the radio access network that needs to be scanned.
     89      *
     90      * The returned value is define in {@link AccessNetworkConstants.AccessNetworkType};
     91      */
     92     public int getRadioAccessNetwork() {
     93         return mRadioAccessNetwork;
     94     }
     95 
     96     /**
     97      * Returns the frequency bands that need to be scanned.
     98      *
     99      * The returned value is defined in either of {@link AccessNetworkConstants.GeranBand},
    100      * {@link AccessNetworkConstants.UtranBand} and {@link AccessNetworkConstants.EutranBand}, and
    101      * it depends on the returned value of {@link #getRadioAccessNetwork()}.
    102      */
    103     public int[] getBands() {
    104         return mBands == null ? null : mBands.clone();
    105     }
    106 
    107     /** Returns the frequency channels that need to be scanned. */
    108     public int[] getChannels() {
    109         return mChannels == null ? null : mChannels.clone();
    110     }
    111 
    112     public static final Parcelable.Creator<RadioAccessSpecifier> CREATOR =
    113             new Parcelable.Creator<RadioAccessSpecifier> (){
    114                 @Override
    115                 public RadioAccessSpecifier createFromParcel(Parcel in) {
    116                     return new RadioAccessSpecifier(in);
    117                 }
    118 
    119                 @Override
    120                 public RadioAccessSpecifier[] newArray(int size) {
    121                     return new RadioAccessSpecifier[size];
    122                 }
    123             };
    124 
    125     @Override
    126     public int describeContents() {
    127         return 0;
    128     }
    129 
    130     @Override
    131     public void writeToParcel(Parcel dest, int flags) {
    132         dest.writeInt(mRadioAccessNetwork);
    133         dest.writeIntArray(mBands);
    134         dest.writeIntArray(mChannels);
    135     }
    136 
    137     private RadioAccessSpecifier(Parcel in) {
    138         mRadioAccessNetwork = in.readInt();
    139         mBands = in.createIntArray();
    140         mChannels = in.createIntArray();
    141     }
    142 
    143     @Override
    144     public boolean equals (Object o) {
    145         RadioAccessSpecifier ras;
    146 
    147         try {
    148             ras = (RadioAccessSpecifier) o;
    149         } catch (ClassCastException ex) {
    150             return false;
    151         }
    152 
    153         if (o == null) {
    154             return false;
    155         }
    156 
    157         return (mRadioAccessNetwork == ras.mRadioAccessNetwork
    158                 && Arrays.equals(mBands, ras.mBands)
    159                 && Arrays.equals(mChannels, ras.mChannels));
    160     }
    161 
    162     @Override
    163     public int hashCode () {
    164         return ((mRadioAccessNetwork * 31)
    165                 + (Arrays.hashCode(mBands) * 37)
    166                 + (Arrays.hashCode(mChannels)) * 39);
    167     }
    168 }
    169