PackageReceiver.java revision 758f97e46df203659c46941dc4483f7b369a5640
1758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkey/*
2758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkey * Copyright (C) 2013 The Android Open Source Project
3758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkey *
4758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkey * Licensed under the Apache License, Version 2.0 (the "License");
5758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkey * you may not use this file except in compliance with the License.
6758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkey * You may obtain a copy of the License at
7758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkey *
8758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkey *      http://www.apache.org/licenses/LICENSE-2.0
9758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkey *
10758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkey * Unless required by applicable law or agreed to in writing, software
11758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkey * distributed under the License is distributed on an "AS IS" BASIS,
12758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkey * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkey * See the License for the specific language governing permissions and
14758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkey * limitations under the License.
15758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkey */
16758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkey
17758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkeypackage com.android.documentsui;
18758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkey
19758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkeyimport android.content.BroadcastReceiver;
20758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkeyimport android.content.ContentResolver;
21758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkeyimport android.content.Context;
22758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkeyimport android.content.Intent;
23758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkeyimport android.net.Uri;
24758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkey
25758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkey/**
26758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkey * Clean up {@link RecentsProvider} when packages are removed.
27758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkey */
28758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkeypublic class PackageReceiver extends BroadcastReceiver {
29758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkey    @Override
30758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkey    public void onReceive(Context context, Intent intent) {
31758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkey        final ContentResolver resolver = context.getContentResolver();
32758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkey
33758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkey        final String action = intent.getAction();
34758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkey        if (Intent.ACTION_PACKAGE_FULLY_REMOVED.equals(action)) {
35758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkey            resolver.call(RecentsProvider.buildRecent(), RecentsProvider.METHOD_PURGE, null, null);
36758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkey
37758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkey        } else if (Intent.ACTION_PACKAGE_DATA_CLEARED.equals(action)) {
38758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkey            final Uri data = intent.getData();
39758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkey            if (data != null) {
40758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkey                final String packageName = data.getSchemeSpecificPart();
41758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkey                resolver.call(RecentsProvider.buildRecent(), RecentsProvider.METHOD_PURGE_PACKAGE,
42758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkey                        packageName, null);
43758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkey            }
44758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkey        }
45758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkey    }
46758f97e46df203659c46941dc4483f7b369a5640Jeff Sharkey}
47