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 com.android.ims.rcs.uce.options; 18 19 import android.annotation.NonNull; 20 import android.content.Context; 21 import android.net.Uri; 22 import android.os.RemoteException; 23 import android.telephony.ims.aidl.IOptionsResponseCallback; 24 import android.telephony.ims.stub.RcsCapabilityExchangeImplBase; 25 import android.util.Log; 26 27 import com.android.ims.RcsFeatureManager; 28 import com.android.ims.rcs.uce.util.UceUtils; 29 30 import java.util.ArrayList; 31 import java.util.Set; 32 33 /** 34 * The implementation of OptionsController. 35 */ 36 public class OptionsControllerImpl implements OptionsController { 37 38 private static final String LOG_TAG = UceUtils.getLogPrefix() + "OptionsController"; 39 40 private final int mSubId; 41 private final Context mContext; 42 private volatile boolean mIsDestroyedFlag; 43 private volatile RcsFeatureManager mRcsFeatureManager; 44 OptionsControllerImpl(Context context, int subId)45 public OptionsControllerImpl(Context context, int subId) { 46 mSubId = subId; 47 mContext = context; 48 } 49 50 @Override onRcsConnected(RcsFeatureManager manager)51 public void onRcsConnected(RcsFeatureManager manager) { 52 mRcsFeatureManager = manager; 53 } 54 55 @Override onRcsDisconnected()56 public void onRcsDisconnected() { 57 mRcsFeatureManager = null; 58 } 59 60 @Override onDestroy()61 public void onDestroy() { 62 mIsDestroyedFlag = true; 63 mRcsFeatureManager = null; 64 } 65 66 @Override onCarrierConfigChanged()67 public void onCarrierConfigChanged() { 68 // Nothing required here. 69 } 70 sendCapabilitiesRequest(Uri contactUri, @NonNull Set<String> deviceFeatureTags, IOptionsResponseCallback c)71 public void sendCapabilitiesRequest(Uri contactUri, @NonNull Set<String> deviceFeatureTags, 72 IOptionsResponseCallback c) throws RemoteException { 73 74 if (mIsDestroyedFlag) { 75 throw new RemoteException("OPTIONS controller is destroyed"); 76 } 77 78 RcsFeatureManager featureManager = mRcsFeatureManager; 79 if (featureManager == null) { 80 Log.w(LOG_TAG, "sendCapabilitiesRequest: Service is unavailable"); 81 c.onCommandError(RcsCapabilityExchangeImplBase.COMMAND_CODE_SERVICE_UNAVAILABLE); 82 return; 83 } 84 85 featureManager.sendOptionsCapabilityRequest(contactUri, new ArrayList<>(deviceFeatureTags), 86 c); 87 } 88 } 89