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.contacts.common.widget;
18 
19 import android.telecom.PhoneAccountHandle;
20 import com.android.dialer.common.Assert;
21 import com.android.dialer.telecom.TelecomUtil;
22 import java.util.Collection;
23 
24 /** Provides common operation on a {@link SelectPhoneAccountDialogOptions} */
25 public final class SelectPhoneAccountDialogOptionsUtil {
SelectPhoneAccountDialogOptionsUtil()26   private SelectPhoneAccountDialogOptionsUtil() {}
27 
getPhoneAccountHandle( SelectPhoneAccountDialogOptions.Entry entry)28   public static PhoneAccountHandle getPhoneAccountHandle(
29       SelectPhoneAccountDialogOptions.Entry entry) {
30     return Assert.isNotNull(
31         TelecomUtil.composePhoneAccountHandle(
32             entry.getPhoneAccountHandleComponentName(), entry.getPhoneAccountHandleId()));
33   }
34 
setPhoneAccountHandle( SelectPhoneAccountDialogOptions.Entry.Builder entryBuilder, PhoneAccountHandle phoneAccountHandle)35   public static SelectPhoneAccountDialogOptions.Entry.Builder setPhoneAccountHandle(
36       SelectPhoneAccountDialogOptions.Entry.Builder entryBuilder,
37       PhoneAccountHandle phoneAccountHandle) {
38     entryBuilder.setPhoneAccountHandleComponentName(
39         phoneAccountHandle.getComponentName().flattenToString());
40     entryBuilder.setPhoneAccountHandleId(phoneAccountHandle.getId());
41     return entryBuilder;
42   }
43 
builderWithAccounts( Collection<PhoneAccountHandle> phoneAccountHandles)44   public static SelectPhoneAccountDialogOptions.Builder builderWithAccounts(
45       Collection<PhoneAccountHandle> phoneAccountHandles) {
46     SelectPhoneAccountDialogOptions.Builder optionsBuilder =
47         SelectPhoneAccountDialogOptions.newBuilder();
48     for (PhoneAccountHandle phoneAccountHandle : phoneAccountHandles) {
49       optionsBuilder.addEntries(
50           SelectPhoneAccountDialogOptionsUtil.setPhoneAccountHandle(
51               SelectPhoneAccountDialogOptions.Entry.newBuilder(), phoneAccountHandle));
52     }
53     return optionsBuilder;
54   }
55 }
56