• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 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.app.IntentService;
20 import android.content.ContentResolver;
21 import android.content.Intent;
22 import android.provider.VoicemailContract.Status;
23 import android.provider.VoicemailContract.Voicemails;
24 import android.util.Log;
25 
26 import com.google.common.annotations.VisibleForTesting;
27 
28 /**
29  * A service that cleans up voicemail related data for packages that are uninstalled.
30  */
31 public class VoicemailCleanupService extends IntentService {
32     private static final String TAG = "VoicemailCleanupService";
33 
VoicemailCleanupService()34     public VoicemailCleanupService() {
35         super("VoicemailCleanupService");
36     }
37 
38     @Override
onHandleIntent(Intent intent)39     protected void onHandleIntent(Intent intent) {
40         handleIntentInternal(intent, getContentResolver());
41     }
42 
43     @VisibleForTesting
handleIntentInternal(Intent intent, ContentResolver contentResolver)44     void handleIntentInternal(Intent intent,
45             ContentResolver contentResolver) {
46         if (intent.getAction().equals(Intent.ACTION_PACKAGE_REMOVED) &&
47                 !intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
48             String packageUninstalled = intent.getData().getSchemeSpecificPart();
49             Log.d(TAG, "Cleaning up data for package: " + packageUninstalled);
50             // Delete both voicemail content and voicemail status entries for this package.
51             contentResolver.delete(Voicemails.buildSourceUri(packageUninstalled), null, null);
52             contentResolver.delete(Status.buildSourceUri(packageUninstalled), null, null);
53         } else {
54             Log.w(TAG, "Unexpected intent: " + intent);
55         }
56     }
57 }
58