1/*
2 * Copyright (C) 2015 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.providers.contacts;
18
19import android.content.BroadcastReceiver;
20import android.content.ContentProvider;
21import android.content.Context;
22import android.content.IContentProvider;
23import android.content.Intent;
24import android.provider.CallLog;
25import android.telecom.PhoneAccountHandle;
26import android.telecom.TelecomManager;
27
28/**
29 * This will be launched when a new phone account is registered in telecom. It is used by the call
30 * log to un-hide any entries which were previously hidden after a backup-restore until it's
31 * associated phone-account is registered with telecom.
32 *
33 * IOW, after a restore, we hide call log entries until the user inserts the corresponding SIM,
34 * registers the corresponding SIP account, or registers a corresponding alternative phone-account.
35 */
36public class PhoneAccountRegistrationReceiver extends BroadcastReceiver {
37    static final String TAG = "PhoneAccountReceiver";
38
39    @Override
40    public void onReceive(Context context, Intent intent) {
41        // We are now running with the system up, but no apps started,
42        // so can do whatever cleanup after an upgrade that we want.
43        if (TelecomManager.ACTION_PHONE_ACCOUNT_REGISTERED.equals(intent.getAction())) {
44
45            PhoneAccountHandle handle = (PhoneAccountHandle) intent.getParcelableExtra(
46                    TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE);
47
48            IContentProvider iprovider =
49                    context.getContentResolver().acquireProvider(CallLog.AUTHORITY);
50            ContentProvider provider = ContentProvider.coerceToLocalContentProvider(iprovider);
51            if (provider instanceof CallLogProvider) {
52                ((CallLogProvider) provider).adjustForNewPhoneAccount(handle);
53            }
54        }
55    }
56}
57