1f299ba160ff5e268e415c1819729d00ba3077d4
[iec.git] / src / type3_AndroidCloud / anbox-master / android / appmgr / src / org / anbox / appmgr / PackageEventReceiver.java
1 /*
2  * Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 3, as published
6  * by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranties of
10  * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11  * PURPOSE.  See the GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program.  If not, see <http://www.gnu.org/licenses/>.
15  *
16  */
17
18 package org.anbox.appmgr;
19
20 import android.content.BroadcastReceiver;
21 import android.content.Context;
22 import android.content.Intent;
23 import android.net.Uri;
24 import android.util.Log;
25
26 public class PackageEventReceiver extends BroadcastReceiver {
27     private static final String TAG = "AnboxAppMgr";
28
29     private PlatformService mPlatformService;
30
31     private String getPackageName(Intent intent) {
32         Uri uri = intent.getData();
33         String package_name = (uri != null ? uri.getSchemeSpecificPart() : null);
34         return package_name;
35     }
36
37     @Override
38     public void onReceive(Context context, Intent intent) {
39         if (mPlatformService == null)
40             mPlatformService = new PlatformService(context);
41
42         if (intent.getAction() == Intent.ACTION_PACKAGE_ADDED ||
43             intent.getAction() == Intent.ACTION_PACKAGE_CHANGED) {
44             // Send updated list of applications to the host so that it
45             // can update the list of applications available for the user.
46             mPlatformService.sendApplicationListUpdate();
47         } else if (intent.getAction() == Intent.ACTION_PACKAGE_REMOVED) {
48             // Only send notification when package got removed and not replaced
49             if (!intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
50                 mPlatformService.notifyPackageRemoved(getPackageName(intent));
51             }
52         }
53     }
54 }