1abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad/*
2abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad * Copyright (C) 2015 The Android Open Source Project
3abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad *
4abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad * Licensed under the Apache License, Version 2.0 (the "License");
5abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad * you may not use this file except in compliance with the License.
6abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad * You may obtain a copy of the License at
7abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad *
8abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad *      http://www.apache.org/licenses/LICENSE-2.0
9abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad *
10abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad * Unless required by applicable law or agreed to in writing, software
11abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad * distributed under the License is distributed on an "AS IS" BASIS,
12abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad * See the License for the specific language governing permissions and
14abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad * limitations under the License.
15abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad */
16abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad
172c93c50e5be7d85b78c4af15aaa10e44f0bcdf3eBrad Ebingerpackage com.android.server.telecom.tests;
18abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad
19abcbce4441720c52a443d292d5adc2d95f446494Ihab Awadimport com.android.internal.telephony.CallerInfo;
20abcbce4441720c52a443d292d5adc2d95f446494Ihab Awadimport com.android.internal.telephony.CallerInfoAsyncQuery;
212c93c50e5be7d85b78c4af15aaa10e44f0bcdf3eBrad Ebingerimport com.android.server.telecom.CallerInfoAsyncQueryFactory;
22abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad
23abcbce4441720c52a443d292d5adc2d95f446494Ihab Awadimport android.content.Context;
24a3eccfee788c3ac3c831a443b085b141b39bb63dBrad Ebingerimport android.telecom.Log;
25abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad
26c6e42ef0465fe01b35bb3aa94fbcbc081e3b45edAbhijith Shastryimport org.mockito.Mockito;
27c6e42ef0465fe01b35bb3aa94fbcbc081e3b45edAbhijith Shastry
28abcbce4441720c52a443d292d5adc2d95f446494Ihab Awadimport java.util.ArrayList;
29f7a0897fa1fc5e759505500b690267ad14d860c0Brad Ebingerimport java.util.Collections;
30abcbce4441720c52a443d292d5adc2d95f446494Ihab Awadimport java.util.List;
31abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad
32abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad/**
33abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad * Controls a test {@link CallerInfoAsyncQueryFactory} to abstract away the asynchronous retrieval
34abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad * of caller information from the Android contacts database.
35abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad */
36abcbce4441720c52a443d292d5adc2d95f446494Ihab Awadpublic class CallerInfoAsyncQueryFactoryFixture implements
37abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad        TestFixture<CallerInfoAsyncQueryFactory> {
38abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad
39abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad    static class Request {
40abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad        int mToken;
41abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad        Object mCookie;
42abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad        CallerInfoAsyncQuery.OnQueryCompleteListener mListener;
43abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad        void reply() {
44c6e42ef0465fe01b35bb3aa94fbcbc081e3b45edAbhijith Shastry            replyWithCallerInfo(new CallerInfo());
45c6e42ef0465fe01b35bb3aa94fbcbc081e3b45edAbhijith Shastry        }
46c6e42ef0465fe01b35bb3aa94fbcbc081e3b45edAbhijith Shastry
47c6e42ef0465fe01b35bb3aa94fbcbc081e3b45edAbhijith Shastry        void replyWithCallerInfo(CallerInfo callerInfo) {
48c6e42ef0465fe01b35bb3aa94fbcbc081e3b45edAbhijith Shastry            mListener.onQueryComplete(mToken, mCookie, callerInfo);
49abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad        }
50abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad    }
51abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad
52abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad    CallerInfoAsyncQueryFactory mCallerInfoAsyncQueryFactory = new CallerInfoAsyncQueryFactory() {
53abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad        @Override
54abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad        public CallerInfoAsyncQuery startQuery(int token, Context context, String number,
55abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad                CallerInfoAsyncQuery.OnQueryCompleteListener listener, Object cookie) {
56abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad            Request r = new Request();
57abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad            r.mToken = token;
58abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad            r.mCookie = cookie;
59abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad            r.mListener = listener;
60abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad            mRequests.add(r);
61c6e42ef0465fe01b35bb3aa94fbcbc081e3b45edAbhijith Shastry            return Mockito.mock(CallerInfoAsyncQuery.class);
62abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad        }
63abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad    };
64abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad
65f7a0897fa1fc5e759505500b690267ad14d860c0Brad Ebinger    final List<Request> mRequests = Collections.synchronizedList(new ArrayList<Request>());
66abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad
67abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad    public CallerInfoAsyncQueryFactoryFixture() throws Exception {
68abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad        Log.i(this, "Creating ...");
69abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad    }
70abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad
71abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad    @Override
72abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad    public CallerInfoAsyncQueryFactory getTestDouble() {
73abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad        return mCallerInfoAsyncQueryFactory;
74abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad    }
75abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad}
76