1b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon/*
2b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon * Copyright (C) 2015 The Android Open Source Project
3b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon *
4b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon * Licensed under the Apache License, Version 2.0 (the "License");
5b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon * you may not use this file except in compliance with the License.
6b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon * You may obtain a copy of the License at
7b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon *
8b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon *      http://www.apache.org/licenses/LICENSE-2.0
9b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon *
10b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon * Unless required by applicable law or agreed to in writing, software
11b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon * distributed under the License is distributed on an "AS IS" BASIS,
12b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon * See the License for the specific language governing permissions and
14b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon * limitations under the License
15b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon */
16b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon
17b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordonpackage com.android.providers.contacts;
18b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon
19b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordonimport android.content.BroadcastReceiver;
20b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordonimport android.content.ContentProvider;
21b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordonimport android.content.Context;
22b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordonimport android.content.IContentProvider;
23b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordonimport android.content.Intent;
24b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordonimport android.provider.CallLog;
25b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordonimport android.telecom.PhoneAccountHandle;
26b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordonimport android.telecom.TelecomManager;
27b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon
28b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon/**
29b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon * This will be launched when a new phone account is registered in telecom. It is used by the call
30b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon * log to un-hide any entries which were previously hidden after a backup-restore until it's
31b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon * associated phone-account is registered with telecom.
32b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon *
33b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon * IOW, after a restore, we hide call log entries until the user inserts the corresponding SIM,
34b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon * registers the corresponding SIP account, or registers a corresponding alternative phone-account.
35b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon */
36b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordonpublic class PhoneAccountRegistrationReceiver extends BroadcastReceiver {
37b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon    static final String TAG = "PhoneAccountReceiver";
38b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon
39b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon    @Override
40b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon    public void onReceive(Context context, Intent intent) {
41b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon        // We are now running with the system up, but no apps started,
42b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon        // so can do whatever cleanup after an upgrade that we want.
43b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon        if (TelecomManager.ACTION_PHONE_ACCOUNT_REGISTERED.equals(intent.getAction())) {
44b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon
45b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon            PhoneAccountHandle handle = (PhoneAccountHandle) intent.getParcelableExtra(
46b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon                    TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE);
47b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon
48b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon            IContentProvider iprovider =
49b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon                    context.getContentResolver().acquireProvider(CallLog.AUTHORITY);
50b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon            ContentProvider provider = ContentProvider.coerceToLocalContentProvider(iprovider);
51b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon            if (provider instanceof CallLogProvider) {
52b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon                ((CallLogProvider) provider).adjustForNewPhoneAccount(handle);
53b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon            }
54b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon        }
55b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon    }
56b39eeb4f07db680e542ccaf142136a42f9d305f8Santos Cordon}
57