summaryrefslogtreecommitdiffstats
path: root/src-ambient/com/android/phone/common/incall/ContactsDataSubscription.java
blob: 2b38b1e86a3a761a113078f3df3f1fabd3be3839 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
 * Copyright (C)  2016 The CyanogenMod Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.phone.common.incall;

import android.content.ComponentName;
import android.content.Context;

import com.android.phone.common.ambient.SingletonHolder;
import com.android.phone.common.ambient.TypedPendingResult;
import com.android.phone.common.incall.api.InCallListeners;
import com.android.phone.common.incall.api.InCallQueries;
import com.android.phone.common.nudge.api.NudgeQueries;
import com.cyanogen.ambient.discovery.util.NudgeKey;
import com.cyanogen.ambient.incall.extension.InCallContactInfo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

public class ContactsDataSubscription extends DialerDataSubscription {

    public ContactsDataSubscription(Context context) {
        super(context);
    }

    private static final SingletonHolder<ContactsDataSubscription, Context> sInstance =
            new SingletonHolder<ContactsDataSubscription, Context>() {

                @Override
                protected ContactsDataSubscription create(Context context) {
                    // Let's get started here.
                    return new ContactsDataSubscription(context);
                }
            };


    public static ContactsDataSubscription get(Context context) {
        return sInstance.get(context);
    }

    public static boolean isCreated() {
        return sInstance.isCreated();
    }

    public static void init(Context context) {
        ContactsDataSubscription.get(context).refresh();
    }

    @Override
    public void onDynamicRefreshRequested(ArrayList<TypedPendingResult> queries,
                                          ComponentName componentName) {
        queries.add(InCallQueries.getCallMethodAuthenticated(mClient, componentName));
        queries.add(InCallQueries.getCallMethodAccountHandle(mClient, componentName));
    }

    @Override
    protected void enableListeners(CallMethodInfo mod) {
        InCallListeners.enableAuthListener(this, mod);
    }

    @Override
    protected void disableListeners(CallMethodInfo mod) {
        InCallListeners.disableAuthListener(this, mod);
    }

    @Override
    protected void requestedModInfo(ArrayList<TypedPendingResult> queries,
            ComponentName componentName) {

        queries.add(InCallQueries.getCallMethodInfo(mClient, componentName));
        queries.add(InCallQueries.getCallMethodStatus(mClient, componentName));
        queries.add(InCallQueries.getCallMethodMimeType(mClient, componentName));
        queries.add(InCallQueries.getCallMethodVideoCallableMimeType(mClient, componentName));
        queries.add(InCallQueries.getCallMethodAuthenticated(mClient, componentName));
        queries.add(InCallQueries.getLoginIntent(mClient, componentName));
        queries.add(InCallQueries.getDefaultDirectorySearchIntent(mClient, componentName));
        queries.add(InCallQueries.getCallMethodImMimeType(mClient, componentName));

        TypedPendingResult fragLogin = NudgeQueries.getNudgeConfig(mClient, mContext, componentName,
                NudgeKey.INCALL_CONTACT_FRAGMENT_LOGIN);
        if (fragLogin != null) {
            queries.add(fragLogin);
        }
        TypedPendingResult cardLogin = NudgeQueries.getNudgeConfig(mClient, mContext, componentName,
                NudgeKey.INCALL_CONTACT_CARD_LOGIN);
        if (cardLogin != null) {
            queries.add(cardLogin);
        }
        TypedPendingResult cardDownload = NudgeQueries.getNudgeConfig(mClient, mContext,
                componentName, NudgeKey.INCALL_CONTACT_CARD_DOWNLOAD);
        if (cardDownload != null) {
            queries.add(cardDownload);
        }
    }

    public static void refreshPendingIntents(InCallContactInfo contactInfo) {
        // TODO: implement
    }

    public Set<String> getAllPluginComponentNames() {
        Set<String> names = new HashSet<String>();
        HashMap<ComponentName, CallMethodInfo> plugins = this.getPluginInfo();
        for (ComponentName cn : plugins.keySet()) {
            names.add(cn.flattenToString());
        }
        return names;
    }
}