1 /* 2 * Copyright (C) 2020 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.telephony.ims.cts; 18 19 import android.net.Uri; 20 import android.telephony.ims.ImsException; 21 import android.telephony.ims.cts.TestImsService.DeviceCapPublishListener; 22 import android.telephony.ims.stub.RcsCapabilityExchangeImplBase; 23 import android.util.Log; 24 25 import java.util.Collection; 26 import java.util.Set; 27 28 /** 29 * A implementation class of RcsCapabilityExchangeImplBase for the TestRcsFeature. 30 */ 31 public class TestRcsCapabilityExchangeImpl extends RcsCapabilityExchangeImplBase { 32 33 private static final String LOG_TAG = "TestRcsCapExchangeImpl"; 34 35 @FunctionalInterface 36 public interface PublishOperation { execute(DeviceCapPublishListener listener, String pidfXml, PublishResponseCallback cb)37 void execute(DeviceCapPublishListener listener, String pidfXml, PublishResponseCallback cb) 38 throws ImsException; 39 } 40 41 @FunctionalInterface 42 public interface SubscribeOperation { execute(Collection<Uri> uris, SubscribeResponseCallback cb)43 void execute(Collection<Uri> uris, SubscribeResponseCallback cb) throws ImsException; 44 } 45 46 @FunctionalInterface 47 public interface OptionsOperation { execute(Uri contactUri, Set<String> myCapabilities, OptionsResponseCallback callback)48 void execute(Uri contactUri, Set<String> myCapabilities, OptionsResponseCallback callback) 49 throws ImsException; 50 } 51 52 private DeviceCapPublishListener mPublishListener; 53 54 // The operation of publishing capabilities 55 private PublishOperation mPublishOperation; 56 57 // The operation of requesting capabilities. 58 private SubscribeOperation mSubscribeOperation; 59 60 // The operation of send Options 61 private OptionsOperation mOptionsOperation; 62 63 /** 64 * Create a new RcsCapabilityExchangeImplBase instance. 65 */ TestRcsCapabilityExchangeImpl(DeviceCapPublishListener listener)66 public TestRcsCapabilityExchangeImpl(DeviceCapPublishListener listener) { 67 mPublishListener = listener; 68 } 69 setPublishOperator(PublishOperation operation)70 public void setPublishOperator(PublishOperation operation) { 71 mPublishOperation = operation; 72 } 73 setSubscribeOperation(SubscribeOperation operator)74 public void setSubscribeOperation(SubscribeOperation operator) { 75 mSubscribeOperation = operator; 76 } 77 setOptionsOperation(OptionsOperation operation)78 public void setOptionsOperation(OptionsOperation operation) { 79 mOptionsOperation = operation; 80 } 81 82 @Override publishCapabilities(String pidfXml, PublishResponseCallback cb)83 public void publishCapabilities(String pidfXml, PublishResponseCallback cb) { 84 try { 85 mPublishOperation.execute(mPublishListener, pidfXml, cb); 86 } catch (ImsException e) { 87 Log.w(LOG_TAG, "publishCapabilities exception: " + e); 88 } 89 } 90 91 @Override subscribeForCapabilities(Collection<Uri> uris, SubscribeResponseCallback cb)92 public void subscribeForCapabilities(Collection<Uri> uris, SubscribeResponseCallback cb) { 93 try { 94 mSubscribeOperation.execute(uris, cb); 95 } catch (ImsException e) { 96 Log.w(LOG_TAG, "subscribeForCapabilities exception: " + e); 97 } 98 } 99 100 @Override sendOptionsCapabilityRequest(Uri contactUri, Set<String> myCapabilities, OptionsResponseCallback callback)101 public void sendOptionsCapabilityRequest(Uri contactUri, Set<String> myCapabilities, 102 OptionsResponseCallback callback) { 103 try { 104 mOptionsOperation.execute(contactUri, myCapabilities, callback); 105 } catch (ImsException e) { 106 Log.w(LOG_TAG, "sendOptionsCapabilityRequest exception: " + e); 107 } 108 } 109 } 110