1 /* 2 * Copyright (C) 2017 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.phone.testapps.imstestapp; 18 19 import android.telephony.ims.stub.ImsConfigImplBase; 20 21 import com.android.ims.ImsConfig; 22 23 import java.util.ArrayList; 24 25 public class TestImsConfigImpl extends ImsConfigImplBase { 26 27 public static class ConfigItem { 28 public int item; 29 public int value; 30 public String valueString; 31 ConfigItem(int item, int value)32 public ConfigItem(int item, int value) { 33 this.item = item; 34 this.value = value; 35 } 36 ConfigItem(int item, String value)37 public ConfigItem(int item, String value) { 38 this.item = item; 39 valueString = value; 40 } 41 } 42 43 public interface ImsConfigListener { notifyConfigChanged()44 void notifyConfigChanged(); 45 } 46 47 private static TestImsConfigImpl sTestImsConfigImpl; 48 private ImsConfigListener mListener; 49 private ArrayList<ConfigItem> mArrayOfConfigs = new ArrayList<>(); 50 getInstance()51 public static TestImsConfigImpl getInstance() { 52 if (sTestImsConfigImpl == null) { 53 sTestImsConfigImpl = new TestImsConfigImpl(); 54 } 55 return sTestImsConfigImpl; 56 } 57 TestImsConfigImpl()58 private TestImsConfigImpl() { 59 super(); 60 } 61 setConfigListener(ImsConfigListener listener)62 public void setConfigListener(ImsConfigListener listener) { 63 mListener = listener; 64 } 65 getConfigList()66 public ArrayList<ConfigItem> getConfigList() { 67 return mArrayOfConfigs; 68 } 69 70 @Override setConfig(int item, int value)71 public int setConfig(int item, int value) { 72 replaceConfig(new ConfigItem(item, value)); 73 return ImsConfig.OperationStatusConstants.SUCCESS; 74 } 75 76 @Override setConfig(int item, String value)77 public int setConfig(int item, String value) { 78 replaceConfig(new ConfigItem(item, value)); 79 return ImsConfig.OperationStatusConstants.SUCCESS; 80 } 81 82 @Override getConfigInt(int item)83 public int getConfigInt(int item) { 84 replaceConfig(new ConfigItem(item, ImsConfig.FeatureValueConstants.ON)); 85 return ImsConfig.FeatureValueConstants.ON; 86 } 87 88 @Override getConfigString(int item)89 public String getConfigString(int item) { 90 return null; 91 } 92 setConfigValue(int item, int value)93 public void setConfigValue(int item, int value) { 94 replaceConfig(new ConfigItem(item, value)); 95 notifyProvisionedValueChanged(item, value); 96 } 97 replaceConfig(ConfigItem configItem)98 public void replaceConfig(ConfigItem configItem) { 99 ConfigItem config = mArrayOfConfigs.stream() 100 .filter(configElem -> configElem.item == configItem.item) 101 .findFirst().orElse(null); 102 if (config != null) { 103 mArrayOfConfigs.remove(config); 104 } 105 mArrayOfConfigs.add(configItem); 106 if (mListener != null) { 107 mListener.notifyConfigChanged(); 108 } 109 } 110 } 111