Home | History | Annotate | Download | only in contacts
      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 
     17 package com.android.providers.contacts;
     18 
     19 import android.content.BroadcastReceiver;
     20 import android.content.ContentProvider;
     21 import android.content.Context;
     22 import android.content.IContentProvider;
     23 import android.content.Intent;
     24 import android.provider.CallLog;
     25 import android.telecom.PhoneAccountHandle;
     26 import 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  */
     36 public 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