1 /* 2 * Copyright (C) 2021 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 com.android.networkstack.apishim.common; 18 19 import androidx.annotation.Nullable; 20 21 import java.util.List; 22 import java.util.concurrent.Executor; 23 24 /** 25 * Interface used to access API methods in {@link android.telephony.TelephonyManager}, with 26 * appropriate fallbacks if the methods are not yet part of the released API. 27 * 28 * <p>This interface makes it easier for callers to use TelephonyManagerShimImpl, as it's more 29 * obvious what methods must be implemented on each API level, and it abstracts from callers the 30 * need to reference classes that have different implementations (which also does not work well 31 * with IDEs). 32 */ 33 public interface TelephonyManagerShim { 34 /** See android.telephony.TelephonyManager.CarrierPrivilegesListener */ 35 interface CarrierPrivilegesListenerShim { 36 /** See android.telephony.TelephonyManager 37 * .CarrierPrivilegesCallback#onCarrierPrivilegesChanged */ onCarrierPrivilegesChanged( List<String> privilegedPackageNames, int[] privilegedUids)38 default void onCarrierPrivilegesChanged( 39 List<String> privilegedPackageNames, 40 int[] privilegedUids) {} 41 // TODO : remove the default implementation of this method once all changes are in 42 /** See CarrierPrivilegesCallback#onCarrierServiceChanged */ onCarrierServiceChanged( @ullable String carrierServicePackageName, int carrierServiceUid)43 default void onCarrierServiceChanged( 44 @Nullable String carrierServicePackageName, 45 int carrierServiceUid) {} 46 } 47 48 /** See android.telephony.TelephonyManager#addCarrierPrivilegesListener */ addCarrierPrivilegesListener( int logicalSlotIndex, Executor executor, CarrierPrivilegesListenerShim listener)49 default void addCarrierPrivilegesListener( 50 int logicalSlotIndex, 51 Executor executor, 52 CarrierPrivilegesListenerShim listener) 53 throws UnsupportedApiLevelException { 54 throw new UnsupportedApiLevelException("Only supported starting from API 33"); 55 } 56 57 /** See android.telephony.TelephonyManager#addCarrierPrivilegesListener */ removeCarrierPrivilegesListener( CarrierPrivilegesListenerShim listener)58 default void removeCarrierPrivilegesListener( 59 CarrierPrivilegesListenerShim listener) 60 throws UnsupportedApiLevelException { 61 throw new UnsupportedApiLevelException("Only supported starting from API 33"); 62 } 63 64 // TODO : remove this method when all changes are in 65 /** See android.telephony.TelephonyManager#getCarrierServicePackageNameForLogicalSlot */ getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex)66 default String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) 67 throws UnsupportedApiLevelException { 68 throw new UnsupportedApiLevelException("Only supported starting from API 33"); 69 } 70 } 71