1 /* 2 * Copyright (C) 2017 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.tv; 18 19 import android.content.BroadcastReceiver; 20 import android.content.ContentProviderOperation; 21 import android.content.ContentProviderResult; 22 import android.content.ContentResolver; 23 import android.content.Context; 24 import android.content.Intent; 25 import android.content.OperationApplicationException; 26 import android.media.tv.TvContract; 27 import android.os.RemoteException; 28 import android.util.Log; 29 30 import java.util.ArrayList; 31 import java.util.Arrays; 32 33 /** 34 * This will be launched when PACKAGE_FULLY_REMOVED intent is broadcast. 35 */ 36 public class PackageRemovedReceiver extends BroadcastReceiver { 37 private static final boolean DEBUG = false; 38 private static final String TAG = "PackageRemovedReceiver"; 39 40 @Override 41 public void onReceive(Context context, Intent intent) { 42 if (Intent.ACTION_PACKAGE_FULLY_REMOVED.equals(intent.getAction()) 43 && intent.getData() != null) { 44 String packageName = intent.getData().getSchemeSpecificPart(); 45 ArrayList<ContentProviderOperation> operations = new ArrayList<>(); 46 int uid = intent.getIntExtra(Intent.EXTRA_UID, 0); 47 48 String selection = TvContract.BaseTvColumns.COLUMN_PACKAGE_NAME + "=?"; 49 String[] selectionArgs = {packageName}; 50 51 operations.add(ContentProviderOperation.newDelete(TvContract.Channels.CONTENT_URI) 52 .withSelection(selection, selectionArgs).build()); 53 operations.add(ContentProviderOperation.newDelete(TvContract.Programs.CONTENT_URI) 54 .withSelection(selection, selectionArgs).build()); 55 operations.add(ContentProviderOperation 56 .newDelete(TvContract.WatchedPrograms.CONTENT_URI) 57 .withSelection(selection, selectionArgs).build()); 58 operations.add(ContentProviderOperation 59 .newDelete(TvContract.RecordedPrograms.CONTENT_URI) 60 .withSelection(selection, selectionArgs).build()); 61 operations.add(ContentProviderOperation 62 .newDelete(TvContract.WatchNextPrograms.CONTENT_URI) 63 .withSelection(selection, selectionArgs).build()); 64 65 ContentProviderResult[] results = null; 66 try { 67 ContentResolver cr = context.getContentResolver(); 68 results = cr.applyBatch(TvContract.AUTHORITY, operations); 69 } catch (RemoteException | OperationApplicationException e) { 70 Log.e(TAG, "error in applyBatch", e); 71 } 72 73 if (DEBUG) { 74 Log.d(TAG, "onPackageFullyRemoved(packageName=" + packageName + ", uid=" + uid 75 + ")"); 76 Log.d(TAG, "results=" + Arrays.toString(results)); 77 } 78 } 79 } 80 }