1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
/*
* Copyright (C) 2018 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 android.telephony.ims.feature;
import android.os.Parcel;
import android.os.Parcelable;
import android.telephony.ims.stub.ImsRegistrationImplBase;
import android.util.ArraySet;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
/**
* Request to send to IMS provider, which will try to enable/disable capabilities that are added to
* the request.
* {@hide}
*/
public class CapabilityChangeRequest implements Parcelable {
public static class CapabilityPair {
private final int mCapability;
private final int radioTech;
public CapabilityPair(int capability, int radioTech) {
this.mCapability = capability;
this.radioTech = radioTech;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof CapabilityPair)) return false;
CapabilityPair that = (CapabilityPair) o;
if (getCapability() != that.getCapability()) return false;
return getRadioTech() == that.getRadioTech();
}
@Override
public int hashCode() {
int result = getCapability();
result = 31 * result + getRadioTech();
return result;
}
public @MmTelFeature.MmTelCapabilities.MmTelCapability int getCapability() {
return mCapability;
}
public @ImsRegistrationImplBase.ImsRegistrationTech int getRadioTech() {
return radioTech;
}
}
// Pair contains <radio tech, mCapability>
private final Set<CapabilityPair> mCapabilitiesToEnable;
// Pair contains <radio tech, mCapability>
private final Set<CapabilityPair> mCapabilitiesToDisable;
public CapabilityChangeRequest() {
mCapabilitiesToEnable = new ArraySet<>();
mCapabilitiesToDisable = new ArraySet<>();
}
/**
* Add one or many capabilities to the request to be enabled.
*
* @param capabilities A bitfield of capabilities to enable, valid values are defined in
* {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
* @param radioTech the radio tech that these capabilities should be enabled for, valid
* values are in {@link ImsRegistrationImplBase.ImsRegistrationTech}.
*/
public void addCapabilitiesToEnableForTech(
@MmTelFeature.MmTelCapabilities.MmTelCapability int capabilities,
@ImsRegistrationImplBase.ImsRegistrationTech int radioTech) {
addAllCapabilities(mCapabilitiesToEnable, capabilities, radioTech);
}
/**
* Add one or many capabilities to the request to be disabled.
* @param capabilities A bitfield of capabilities to diable, valid values are defined in
* {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
* @param radioTech the radio tech that these capabilities should be disabled for, valid
* values are in {@link ImsRegistrationImplBase.ImsRegistrationTech}.
*/
public void addCapabilitiesToDisableForTech(
@MmTelFeature.MmTelCapabilities.MmTelCapability int capabilities,
@ImsRegistrationImplBase.ImsRegistrationTech int radioTech) {
addAllCapabilities(mCapabilitiesToDisable, capabilities, radioTech);
}
/**
* @return a {@link List} of {@link CapabilityPair}s that are requesting to be enabled.
*/
public List<CapabilityPair> getCapabilitiesToEnable() {
return new ArrayList<>(mCapabilitiesToEnable);
}
/**
* @return a {@link List} of {@link CapabilityPair}s that are requesting to be disabled.
*/
public List<CapabilityPair> getCapabilitiesToDisable() {
return new ArrayList<>(mCapabilitiesToDisable);
}
// Iterate through capabilities bitfield and add each one as a pair associated with the radio
// technology
private void addAllCapabilities(Set<CapabilityPair> set, int capabilities, int tech) {
long highestCapability = Long.highestOneBit(capabilities);
for (int i = 1; i <= highestCapability; i *= 2) {
if ((i & capabilities) > 0) {
set.add(new CapabilityPair(/*capability*/ i, /*radioTech*/ tech));
}
}
}
protected CapabilityChangeRequest(Parcel in) {
int enableSize = in.readInt();
mCapabilitiesToEnable = new ArraySet<>(enableSize);
for (int i = 0; i < enableSize; i++) {
mCapabilitiesToEnable.add(new CapabilityPair(/*capability*/ in.readInt(),
/*radioTech*/ in.readInt()));
}
int disableSize = in.readInt();
mCapabilitiesToDisable = new ArraySet<>(disableSize);
for (int i = 0; i < disableSize; i++) {
mCapabilitiesToDisable.add(new CapabilityPair(/*capability*/ in.readInt(),
/*radioTech*/ in.readInt()));
}
}
public static final Creator<CapabilityChangeRequest> CREATOR =
new Creator<CapabilityChangeRequest>() {
@Override
public CapabilityChangeRequest createFromParcel(Parcel in) {
return new CapabilityChangeRequest(in);
}
@Override
public CapabilityChangeRequest[] newArray(int size) {
return new CapabilityChangeRequest[size];
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(mCapabilitiesToEnable.size());
for (CapabilityPair pair : mCapabilitiesToEnable) {
dest.writeInt(pair.getCapability());
dest.writeInt(pair.getRadioTech());
}
dest.writeInt(mCapabilitiesToDisable.size());
for (CapabilityPair pair : mCapabilitiesToDisable) {
dest.writeInt(pair.getCapability());
dest.writeInt(pair.getRadioTech());
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof CapabilityChangeRequest)) return false;
CapabilityChangeRequest
that = (CapabilityChangeRequest) o;
if (!mCapabilitiesToEnable.equals(that.mCapabilitiesToEnable)) return false;
return mCapabilitiesToDisable.equals(that.mCapabilitiesToDisable);
}
@Override
public int hashCode() {
int result = mCapabilitiesToEnable.hashCode();
result = 31 * result + mCapabilitiesToDisable.hashCode();
return result;
}
}
|