1 /* 2 * Copyright (C) 2025 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.telecom.cts.apps; 18 19 import android.telecom.Connection; 20 21 import java.util.ArrayList; 22 import java.util.List; 23 24 /* Mimics the HoldTracker class used by Telephony to update the holdability of managed connection 25 * for the purpose of CUJ testing. This is simplified class that only applies to connections. */ 26 public class HoldableTracker { 27 private static final List<Connection> sTrackedConnections = new ArrayList<>(); 28 addHoldable(Connection conn)29 public static void addHoldable(Connection conn) { 30 sTrackedConnections.add(conn); 31 updateHoldCapability(); 32 } 33 removeHoldable(Connection conn)34 public static void removeHoldable(Connection conn) { 35 sTrackedConnections.remove(conn); 36 updateHoldCapability(); 37 } 38 updateHoldCapability()39 private static void updateHoldCapability() { 40 boolean isHoldable = sTrackedConnections.size() < 2; 41 int mask = (1 << 31) - 1; 42 int clearHoldMask = (~Connection.CAPABILITY_HOLD) & mask; 43 for (Connection conn : sTrackedConnections) { 44 int finalCaps = 45 isHoldable 46 ? conn.getConnectionCapabilities() | Connection.CAPABILITY_HOLD 47 : conn.getConnectionCapabilities() & clearHoldMask; 48 conn.setConnectionCapabilities(finalCaps); 49 } 50 } 51 52 public static void clearTrackedConnections() { 53 sTrackedConnections.clear(); 54 } 55 56 public static boolean canHold() { 57 return sTrackedConnections.size() < 2; 58 } 59 } 60