blob: efd1ba49763af51bd68c5be66cc5d7a751c6ecc9 [file] [log] [blame]
Sailesh Nepal905dfba2014-07-14 08:20:41 -07001/*
2 * Copyright (C) 2013 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
17package com.android.telecomm;
18
19import android.content.ComponentName;
20import android.content.Intent;
21import android.content.pm.PackageManager;
22import android.content.pm.ResolveInfo;
23import android.content.pm.ServiceInfo;
Santos Cordonf2f14ef2014-07-20 18:00:20 -070024import android.telecomm.ConnectionService;
Sailesh Nepal905dfba2014-07-14 08:20:41 -070025
26import java.util.ArrayList;
27import java.util.Collection;
28import java.util.HashMap;
29
30/**
31 * Searches for and returns connection services.
32 */
33final class ConnectionServiceRepository
34 implements ServiceBinder.Listener<ConnectionServiceWrapper> {
Sailesh Nepal905dfba2014-07-14 08:20:41 -070035 private final HashMap<ComponentName, ConnectionServiceWrapper> mServiceCache =
36 new HashMap<ComponentName, ConnectionServiceWrapper>();
37
Sailesh Nepal664837f2014-07-14 16:31:51 -070038 ConnectionServiceRepository() {
Sailesh Nepal905dfba2014-07-14 08:20:41 -070039 }
40
Sailesh Nepal905dfba2014-07-14 08:20:41 -070041 ConnectionServiceWrapper getService(ComponentName componentName) {
42 ConnectionServiceWrapper service = mServiceCache.get(componentName);
43 if (service == null) {
Ihab Awadb78b2762014-07-25 15:16:23 -070044 service = new ConnectionServiceWrapper(
45 componentName,
46 this,
47 TelecommApp.getInstance().getPhoneAccountRegistrar());
Sailesh Nepal905dfba2014-07-14 08:20:41 -070048 service.addListener(this);
49 mServiceCache.put(componentName, service);
50 }
51 return service;
52 }
53
54 /**
55 * Removes the specified service from the cache when the service unbinds.
56 *
57 * {@inheritDoc}
58 */
59 @Override
60 public void onUnbind(ConnectionServiceWrapper service) {
61 mServiceCache.remove(service.getComponentName());
62 }
63}