aboutsummaryrefslogtreecommitdiff
path: root/src/java/com/android/internal/telephony/domainselection/NormalCallDomainSelectionConnection.java
blob: e157d24f377738683bb76945e1e51e6019bb833e (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
136
137
138
139
140
141
142
143
144
145
146
/*
 * Copyright (C) 2022 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 com.android.internal.telephony.domainselection;

import static android.telephony.DomainSelectionService.SELECTOR_TYPE_CALLING;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.telephony.AccessNetworkConstants.RadioAccessNetworkType;
import android.telephony.Annotation.DisconnectCauses;
import android.telephony.DomainSelectionService;
import android.telephony.DomainSelectionService.EmergencyScanType;
import android.telephony.NetworkRegistrationInfo;
import android.telephony.ims.ImsReasonInfo;

import com.android.internal.telephony.Phone;

import java.util.concurrent.CompletableFuture;

/**
 * Manages the information of request and the callback binder for normal calling.
 */
public class NormalCallDomainSelectionConnection extends DomainSelectionConnection {

    private static final boolean DBG = false;

    private static final String PREFIX_WPS = "*272";

    // WPS prefix when CLIR is being activated for the call.
    private static final String PREFIX_WPS_CLIR_ACTIVATE = "*31#*272";

    // WPS prefix when CLIR is being deactivated for the call.
    private static final String PREFIX_WPS_CLIR_DEACTIVATE = "#31#*272";


    private @Nullable DomainSelectionConnectionCallback mCallback;

    /**
     * Create an instance.
     *
     * @param phone For which this service is requested.
     * @param controller The controller to communicate with the domain selection service.
     */
    public NormalCallDomainSelectionConnection(@NonNull Phone phone,
            @NonNull DomainSelectionController controller) {
        super(phone, SELECTOR_TYPE_CALLING, false, controller);
        mTag = "NormalCallDomainSelectionConnection";
    }

    /** {@inheritDoc} */
    @Override
    public void onWlanSelected() {
        CompletableFuture<Integer> future = getCompletableFuture();
        future.complete(NetworkRegistrationInfo.DOMAIN_PS);
    }

    /** {@inheritDoc} */
    @Override
    public void onWwanSelected() {
    }

    /** {@inheritDoc} */
    @Override
    public void onSelectionTerminated(@DisconnectCauses int cause) {
        if (mCallback != null) mCallback.onSelectionTerminated(cause);
    }

    /** {@inheritDoc} */
    @Override
    public void onRequestEmergencyNetworkScan(@RadioAccessNetworkType int[] preferredNetworks,
            @EmergencyScanType int scanType) {
        // Not expected with normal calling.
        // Override to prevent abnormal behavior.
    }

    /**
     * Request a domain for normal call.
     *
     * @param attr The attributes required to determine the domain.
     * @param callback A callback to receive the response.
     * @return A {@link CompletableFuture} callback to receive the result.
     */
    public CompletableFuture<Integer> createNormalConnection(
            @NonNull DomainSelectionService.SelectionAttributes attr,
            @NonNull DomainSelectionConnectionCallback callback) {
        mCallback = callback;
        selectDomain(attr);
        return getCompletableFuture();
    }

    /**
     * Returns the attributes required to determine the domain for a normal call.
     *
     * @param slotId The slot identifier.
     * @param subId The subscription identifier.
     * @param callId The call identifier.
     * @param number The dialed number.
     * @param isVideoCall flag for video call.
     * @param callFailCause The reason why the last CS attempt failed.
     * @param imsReasonInfo The reason why the last PS attempt failed.
     * @return The attributes required to determine the domain.
     */
    public static @NonNull DomainSelectionService.SelectionAttributes getSelectionAttributes(
            int slotId, int subId, @NonNull String callId, @NonNull String number,
            boolean isVideoCall, int callFailCause, @Nullable ImsReasonInfo imsReasonInfo) {

        DomainSelectionService.SelectionAttributes.Builder builder =
                new DomainSelectionService.SelectionAttributes.Builder(
                        slotId, subId, SELECTOR_TYPE_CALLING)
                        .setEmergency(false)
                        .setCallId(callId)
                        .setNumber(number)
                        .setCsDisconnectCause(callFailCause)
                        .setVideoCall(isVideoCall);

        if (imsReasonInfo != null) {
            builder.setPsDisconnectCause(imsReasonInfo);
        }
        return builder.build();
    }

    /**
     * Check if the call is Wireless Priority Service call
     * @param dialString  The number being dialed.
     * @return {@code true} if dialString matches WPS pattern and {@code false} otherwise.
     */
    public static boolean isWpsCall(String dialString) {
        return (dialString != null) && (dialString.startsWith(PREFIX_WPS)
                || dialString.startsWith(PREFIX_WPS_CLIR_ACTIVATE)
                || dialString.startsWith(PREFIX_WPS_CLIR_DEACTIVATE));
    }
}