2 * Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
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.
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.
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/>.
18 package org.anbox.appmgr;
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;
26 public class PackageEventReceiver extends BroadcastReceiver {
27 private static final String TAG = "AnboxAppMgr";
29 private PlatformService mPlatformService;
31 private String getPackageName(Intent intent) {
32 Uri uri = intent.getData();
33 String package_name = (uri != null ? uri.getSchemeSpecificPart() : null);
38 public void onReceive(Context context, Intent intent) {
39 if (mPlatformService == null)
40 mPlatformService = new PlatformService(context);
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));