summaryrefslogtreecommitdiff
path: root/src/com/android
diff options
context:
space:
mode:
authorShubang Lu <shubang@google.com>2018-03-21 21:31:07 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2018-03-21 21:31:07 +0000
commit1ce0091b107ac3cc1c036fe4e67bb96a8ed9cfb0 (patch)
tree0ba32cc1d231232c4b5edfe50f15bfcdd5fbe969 /src/com/android
parenta14e7cd4f1ee3caf0f7c4ec8f47e8b5e5988bfb6 (diff)
parent1d5fc6e1308bfcfa6f35e38ff17f62cb3b56a513 (diff)
downloadTvProvider-1ce0091b107ac3cc1c036fe4e67bb96a8ed9cfb0.tar.gz
Merge "Remove preview channels and preview programs when disabled"
Diffstat (limited to 'src/com/android')
-rw-r--r--src/com/android/providers/tv/PackageChangedReceiver.java91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/com/android/providers/tv/PackageChangedReceiver.java b/src/com/android/providers/tv/PackageChangedReceiver.java
new file mode 100644
index 0000000..c5348ad
--- /dev/null
+++ b/src/com/android/providers/tv/PackageChangedReceiver.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.providers.tv;
+
+import android.content.BroadcastReceiver;
+import android.content.ContentProviderOperation;
+import android.content.ContentProviderResult;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.OperationApplicationException;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.media.tv.TvContract;
+import android.os.RemoteException;
+import android.util.Log;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+/**
+ * This will be launched when PACKAGE_CHANGED intent is broadcast.
+ */
+public class PackageChangedReceiver extends BroadcastReceiver {
+ private static final boolean DEBUG = true;
+ private static final String TAG = "PackageChangedReceiver";
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (Intent.ACTION_PACKAGE_CHANGED.equals(intent.getAction()) && intent.getData() != null) {
+ String packageName = intent.getData().getSchemeSpecificPart();
+ PackageManager pm = context.getPackageManager();
+ try {
+ ApplicationInfo appInfo = pm.getApplicationInfo(packageName, 0);
+ if (appInfo.enabled) {
+ return;
+ }
+ } catch (PackageManager.NameNotFoundException e) {
+ Log.e(TAG, "Error: package " + packageName + " not found", e);
+ return;
+ }
+ ArrayList<ContentProviderOperation> operations = new ArrayList<>();
+ int uid = intent.getIntExtra(Intent.EXTRA_UID, 0);
+
+ String ProgramsSelection = TvContract.BaseTvColumns.COLUMN_PACKAGE_NAME + "=?";
+ String[] ProgramsSelectionArgs = {packageName};
+ operations.add(ContentProviderOperation
+ .newDelete(TvContract.WatchNextPrograms.CONTENT_URI)
+ .withSelection(ProgramsSelection, ProgramsSelectionArgs).build());
+ operations.add(ContentProviderOperation
+ .newDelete(TvContract.PreviewPrograms.CONTENT_URI)
+ .withSelection(ProgramsSelection, ProgramsSelectionArgs).build());
+
+
+ String ChannelsSelection = TvContract.BaseTvColumns.COLUMN_PACKAGE_NAME + "=? AND "
+ + TvContract.Channels.COLUMN_TYPE + "=?";
+ String[] ChannelsSelectionArgs = {packageName, TvContract.Channels.TYPE_PREVIEW};
+ operations.add(ContentProviderOperation
+ .newDelete(TvContract.Channels.CONTENT_URI)
+ .withSelection(ChannelsSelection, ChannelsSelectionArgs).build());
+
+ ContentProviderResult[] results = null;
+ try {
+ ContentResolver cr = context.getContentResolver();
+ results = cr.applyBatch(TvContract.AUTHORITY, operations);
+ } catch (RemoteException | OperationApplicationException e) {
+ Log.e(TAG, "error in applyBatch", e);
+ }
+
+ if (DEBUG) {
+ Log.d(TAG, "onPackageFullyChanged(packageName=" + packageName + ", uid=" + uid
+ + ")");
+ Log.d(TAG, "results=" + Arrays.toString(results));
+ }
+ }
+ }
+}