7d19ce7cac1eaf63c219af9bc16d28fc7c5a3f0f
[iec.git] / src / type3_AndroidCloud / anbox-master / android / appmgr / src / org / anbox / appmgr / PackageIntentReceiver.java
1 /*
2  * The MIT License (MIT)
3  *
4  * Copyright 2016 Arnab Chakraborty. http://arnab.ch
5  *
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
11  * conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all copies
14  * or substantial portions of the Software.
15  *
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.
22  */
23
24 package org.anbox.appmgr;
25
26 import android.content.BroadcastReceiver;
27 import android.content.Context;
28 import android.content.Intent;
29 import android.content.IntentFilter;
30
31 /**
32  * Helper class to look for interesting changes to the installed apps
33  * so that the loader can be updated.
34  *
35  * @Credit http://developer.android.com/reference/android/content/AsyncTaskLoader.html
36  */
37 public class PackageIntentReceiver extends BroadcastReceiver {
38
39     final AppsLoader mLoader;
40
41     public PackageIntentReceiver(AppsLoader loader) {
42         mLoader = loader;
43
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);
49
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);
55     }
56
57     @Override public void onReceive(Context context, Intent intent) {
58         // Tell the loader about the change.
59         mLoader.onContentChanged();
60     }
61
62 }