aboutsummaryrefslogtreecommitdiff
path: root/shadows/framework/src/main/java/org/robolectric/shadows/CellIdentityNrBuilder.java
blob: 22a0e75c0a93a8ba0acd62ffb9f7d6c30c8d507e (plain)
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
package org.robolectric.shadows;

import static org.robolectric.util.reflector.Reflector.reflector;

import android.os.Build;
import android.telephony.CellIdentityNr;
import android.telephony.CellInfo;
import androidx.annotation.RequiresApi;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.annotation.Nullable;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.util.reflector.Constructor;
import org.robolectric.util.reflector.ForType;

/** Builder for {@link android.telephony.CellIdentityNr}. */
@RequiresApi(Build.VERSION_CODES.Q)
public class CellIdentityNrBuilder {

  private int pci = CellInfo.UNAVAILABLE;
  private int tac = CellInfo.UNAVAILABLE;
  private int nrarfcn = CellInfo.UNAVAILABLE;
  private int[] bands = new int[0];
  @Nullable private String mcc = null;
  @Nullable private String mnc = null;
  private long nci = CellInfo.UNAVAILABLE;
  @Nullable private String alphal = null;
  @Nullable private String alphas = null;
  private List<String> additionalPlmns = new ArrayList<>();

  private CellIdentityNrBuilder() {}

  public static CellIdentityNrBuilder newBuilder() {
    return new CellIdentityNrBuilder();
  }

  // An empty constructor is not available on Q.
  @RequiresApi(Build.VERSION_CODES.R)
  protected static CellIdentityNr getDefaultInstance() {
    return reflector(CellIdentityNrReflector.class).newCellIdentityNr();
  }

  public CellIdentityNrBuilder setNci(long nci) {
    this.nci = nci;
    return this;
  }

  public CellIdentityNrBuilder setPci(int pci) {
    this.pci = pci;
    return this;
  }

  public CellIdentityNrBuilder setTac(int tac) {
    this.tac = tac;
    return this;
  }

  public CellIdentityNrBuilder setNrarfcn(int nrarfcn) {
    this.nrarfcn = nrarfcn;
    return this;
  }

  public CellIdentityNrBuilder setMcc(String mcc) {
    this.mcc = mcc;
    return this;
  }

  public CellIdentityNrBuilder setMnc(String mnc) {
    this.mnc = mnc;
    return this;
  }

  public CellIdentityNrBuilder setBands(int[] bands) {
    this.bands = bands;
    return this;
  }

  public CellIdentityNrBuilder setLongOperatorName(String longOperatorName) {
    this.alphal = longOperatorName;
    return this;
  }

  public CellIdentityNrBuilder setShortOperatorName(String shortOperatorName) {
    this.alphas = shortOperatorName;
    return this;
  }

  public CellIdentityNrBuilder setAdditionalPlmns(List<String> additionalPlmns) {
    this.additionalPlmns = additionalPlmns;
    return this;
  }

  public CellIdentityNr build() {
    CellIdentityNrReflector cellIdentityReflector = reflector(CellIdentityNrReflector.class);
    if (RuntimeEnvironment.getApiLevel() < Build.VERSION_CODES.R) {
      return cellIdentityReflector.newCellIdentityNr(
          pci, tac, nrarfcn, mcc, mnc, nci, alphal, alphas);
    } else {
      return cellIdentityReflector.newCellIdentityNr(
          pci, tac, nrarfcn, bands, mcc, mnc, nci, alphal, alphas, additionalPlmns);
    }
  }

  @ForType(CellIdentityNr.class)
  private interface CellIdentityNrReflector {

    @Constructor
    CellIdentityNr newCellIdentityNr();

    @Constructor
    CellIdentityNr newCellIdentityNr(
        int pci,
        int tac,
        int nrarfcn,
        String mcc,
        String mnc,
        long nci,
        String alphal,
        String alphas);

    @Constructor
    CellIdentityNr newCellIdentityNr(
        int pci,
        int tac,
        int nrarfcn,
        int[] bands,
        String mcc,
        String mnc,
        long nci,
        String alphal,
        String alphas,
        Collection<String> additionalPlmns);
  }
}