2 * The MIT License (MIT)
4 * Copyright 2016 Arnab Chakraborty. http://arnab.ch
6 * Permission is hereby granted, free of charge, to any person obtaining a copy of this
7 * software and associated documentation files (the "Software"), to deal in the Software
8 * without restriction, including without limitation the rights to use, copy, modify,
9 * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to the following
13 * The above copyright notice and this permission notice shall be included in all copies
14 * or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
17 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
18 * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 package org.anbox.appmgr;
26 import android.content.BroadcastReceiver;
27 import android.content.Context;
28 import android.content.Intent;
29 import android.content.IntentFilter;
32 * Helper class to look for interesting changes to the installed apps
33 * so that the loader can be updated.
35 * @Credit http://developer.android.com/reference/android/content/AsyncTaskLoader.html
37 public class PackageIntentReceiver extends BroadcastReceiver {
39 final AppsLoader mLoader;
41 public PackageIntentReceiver(AppsLoader loader) {
44 IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
45 filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
46 filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
47 filter.addDataScheme("package");
48 mLoader.getContext().registerReceiver(this, filter);
50 // Register for events related to sdcard installation.
51 IntentFilter sdFilter = new IntentFilter();
52 sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
53 sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
54 mLoader.getContext().registerReceiver(this, sdFilter);
57 @Override public void onReceive(Context context, Intent intent) {
58 // Tell the loader about the change.
59 mLoader.onContentChanged();