1 /* 2 * Copyright (C) 2018 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.dialer.preferredsim; 18 19 import android.telecom.PhoneAccountHandle; 20 import com.android.contacts.common.widget.SelectPhoneAccountDialogOptions; 21 import com.android.dialer.preferredsim.suggestion.SuggestionProvider.Suggestion; 22 import com.google.auto.value.AutoValue; 23 import com.google.common.base.Optional; 24 import com.google.common.util.concurrent.ListenableFuture; 25 import java.util.List; 26 27 /** Query a preferred SIM to make a call with. */ 28 @SuppressWarnings({"missingPermission", "Guava"}) 29 public interface PreferredAccountWorker { 30 31 /** Result of the query. */ 32 @AutoValue 33 abstract class Result { 34 35 /** 36 * The phone account to dial with for the number. Absent if no account can be auto selected. If 37 * absent, {@link #getSelectedPhoneAccountHandle()} will be present to show a dialog for the 38 * user to manually select. 39 */ getSelectedPhoneAccountHandle()40 public abstract Optional<PhoneAccountHandle> getSelectedPhoneAccountHandle(); 41 42 /** 43 * The {@link SelectPhoneAccountDialogOptions} that should be used to show the selection dialog. 44 * Absent if {@link #getSelectedPhoneAccountHandle()} is present, which should be used directly 45 * instead of asking the user. 46 */ getDialogOptionsBuilder()47 public abstract Optional<SelectPhoneAccountDialogOptions.Builder> getDialogOptionsBuilder(); 48 49 /** 50 * {@link android.provider.ContactsContract.Data#_ID} of the row matching the number. If the 51 * preferred account is to be set it should be stored in this row 52 */ getDataId()53 public abstract Optional<String> getDataId(); 54 getSuggestion()55 public abstract Optional<Suggestion> getSuggestion(); 56 builder(PhoneAccountHandle selectedPhoneAccountHandle)57 public static Builder builder(PhoneAccountHandle selectedPhoneAccountHandle) { 58 return new AutoValue_PreferredAccountWorker_Result.Builder() 59 .setSelectedPhoneAccountHandle(selectedPhoneAccountHandle); 60 } 61 builder(SelectPhoneAccountDialogOptions.Builder optionsBuilder)62 public static Builder builder(SelectPhoneAccountDialogOptions.Builder optionsBuilder) { 63 return new AutoValue_PreferredAccountWorker_Result.Builder() 64 .setDialogOptionsBuilder(optionsBuilder); 65 } 66 67 /** For implementations of {@link PreferredAccountWorker} only. */ 68 @AutoValue.Builder 69 public abstract static class Builder { 70 setSelectedPhoneAccountHandle(PhoneAccountHandle phoneAccountHandle)71 abstract Builder setSelectedPhoneAccountHandle(PhoneAccountHandle phoneAccountHandle); 72 setDataId(String dataId)73 public abstract Builder setDataId(String dataId); 74 setDialogOptionsBuilder( SelectPhoneAccountDialogOptions.Builder optionsBuilder)75 abstract Builder setDialogOptionsBuilder( 76 SelectPhoneAccountDialogOptions.Builder optionsBuilder); 77 setSuggestion(Suggestion suggestion)78 public abstract Builder setSuggestion(Suggestion suggestion); 79 build()80 public abstract Result build(); 81 } 82 } 83 84 /** 85 * @return a {@link SelectPhoneAccountDialogOptions} for a dialog to select SIM for voicemail call 86 */ getVoicemailDialogOptions()87 SelectPhoneAccountDialogOptions getVoicemailDialogOptions(); 88 89 /** 90 * Return {@link Result} for the best {@link PhoneAccountHandle} among {@code candidates} to call 91 * the number with. If none are eligible, a {@link SelectPhoneAccountDialogOptions} will be 92 * provided to show a dialog for the user to manually select. 93 */ selectAccount(String phoneNumber, List<PhoneAccountHandle> candidates)94 ListenableFuture<Result> selectAccount(String phoneNumber, List<PhoneAccountHandle> candidates); 95 } 96