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 */ RadioAccessSpecifier(int ran, int[] bands, int[] channels)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 */ getRadioAccessNetwork()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}, {@link AccessNetworkConstants.EutranBand}, 101 * and {@link AccessNetworkConstants.NgranBands}, and it depends on 102 * the returned value of {@link #getRadioAccessNetwork()}. 103 */ getBands()104 public int[] getBands() { 105 return mBands == null ? null : mBands.clone(); 106 } 107 108 /** Returns the frequency channels that need to be scanned. */ getChannels()109 public int[] getChannels() { 110 return mChannels == null ? null : mChannels.clone(); 111 } 112 113 public static final @android.annotation.NonNull Parcelable.Creator<RadioAccessSpecifier> CREATOR = 114 new Parcelable.Creator<RadioAccessSpecifier> (){ 115 @Override 116 public RadioAccessSpecifier createFromParcel(Parcel in) { 117 return new RadioAccessSpecifier(in); 118 } 119 120 @Override 121 public RadioAccessSpecifier[] newArray(int size) { 122 return new RadioAccessSpecifier[size]; 123 } 124 }; 125 126 @Override describeContents()127 public int describeContents() { 128 return 0; 129 } 130 131 @Override writeToParcel(Parcel dest, int flags)132 public void writeToParcel(Parcel dest, int flags) { 133 dest.writeInt(mRadioAccessNetwork); 134 dest.writeIntArray(mBands); 135 dest.writeIntArray(mChannels); 136 } 137 RadioAccessSpecifier(Parcel in)138 private RadioAccessSpecifier(Parcel in) { 139 mRadioAccessNetwork = in.readInt(); 140 mBands = in.createIntArray(); 141 mChannels = in.createIntArray(); 142 } 143 144 @Override equals(Object o)145 public boolean equals (Object o) { 146 RadioAccessSpecifier ras; 147 148 try { 149 ras = (RadioAccessSpecifier) o; 150 } catch (ClassCastException ex) { 151 return false; 152 } 153 154 if (o == null) { 155 return false; 156 } 157 158 return (mRadioAccessNetwork == ras.mRadioAccessNetwork 159 && Arrays.equals(mBands, ras.mBands) 160 && Arrays.equals(mChannels, ras.mChannels)); 161 } 162 163 @Override hashCode()164 public int hashCode () { 165 return ((mRadioAccessNetwork * 31) 166 + (Arrays.hashCode(mBands) * 37) 167 + (Arrays.hashCode(mChannels)) * 39); 168 } 169 } 170