Remove application launcher when its android counterpart is removed
This commit is contained in:
parent
d30e8f1a74
commit
69631a1bfc
10 changed files with 131 additions and 22 deletions
|
|
@ -20,12 +20,14 @@ package org.anbox.appmgr;
|
|||
import android.app.Service;
|
||||
import android.util.Log;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.IBinder;
|
||||
|
||||
public final class LauncherService extends Service {
|
||||
public static final String TAG = "AnboxAppMgr";
|
||||
|
||||
private PlatformService mPlatformService;
|
||||
private PackageEventReceiver mPkgEventReceiver;
|
||||
|
||||
public LauncherService() {
|
||||
super();
|
||||
|
|
@ -35,9 +37,20 @@ public final class LauncherService extends Service {
|
|||
@Override
|
||||
public void onCreate() {
|
||||
mPlatformService = new PlatformService(getBaseContext());
|
||||
// Send all necessary initial updates
|
||||
|
||||
// Send the current list of applications over to the host so
|
||||
// it can rebuild its list of available applications.
|
||||
mPlatformService.sendApplicationListUpdate();
|
||||
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(Intent.ACTION_PACKAGE_ADDED);
|
||||
filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
|
||||
filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
|
||||
filter.addDataScheme("package");
|
||||
|
||||
mPkgEventReceiver = new PackageEventReceiver();
|
||||
registerReceiver(mPkgEventReceiver, filter);
|
||||
|
||||
Log.i(TAG, "Service started");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,13 +20,35 @@ package org.anbox.appmgr;
|
|||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
|
||||
public class PackageEventReceiver extends BroadcastReceiver {
|
||||
private static final String TAG = "AnboxAppMgr";
|
||||
|
||||
private PlatformService mPlatformService;
|
||||
|
||||
private String getPackageName(Intent intent) {
|
||||
Uri uri = intent.getData();
|
||||
String package_name = (uri != null ? uri.getSchemeSpecificPart() : null);
|
||||
return package_name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Log.i(TAG, "Received intent " + intent.toString());
|
||||
if (mPlatformService == null)
|
||||
mPlatformService = new PlatformService(context);
|
||||
|
||||
if (intent.getAction() == Intent.ACTION_PACKAGE_ADDED ||
|
||||
intent.getAction() == Intent.ACTION_PACKAGE_CHANGED) {
|
||||
// Send updated list of applications to the host so that it
|
||||
// can update the list of applications available for the user.
|
||||
mPlatformService.sendApplicationListUpdate();
|
||||
} else if (intent.getAction() == Intent.ACTION_PACKAGE_REMOVED) {
|
||||
// Only send notification when package got removed and not replaced
|
||||
if (!intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
|
||||
mPlatformService.notifyPackageRemoved(getPackageName(intent));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,6 +62,31 @@ public final class PlatformService {
|
|||
Log.i(TAG, "Connected to platform service");
|
||||
}
|
||||
|
||||
public void notifyPackageRemoved(String packageName) {
|
||||
connectService();
|
||||
|
||||
if (mService == null)
|
||||
return;
|
||||
|
||||
Log.i(TAG, "Sending package removed notification to host service");
|
||||
|
||||
Parcel data = Parcel.obtain();
|
||||
data.writeInterfaceToken(DESCRIPTOR);
|
||||
// No added or updated applications to report
|
||||
data.writeInt(0);
|
||||
// .. but a single removed application
|
||||
data.writeInt(1);
|
||||
data.writeString(packageName);
|
||||
|
||||
Parcel reply = Parcel.obtain();
|
||||
try {
|
||||
mService.transact(TRANSACTION_updateApplicationList, data, reply, 0);
|
||||
}
|
||||
catch (RemoteException ex) {
|
||||
Log.w(TAG, "Failed to send updatePackageList request to remote binder service: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void sendApplicationListUpdate() {
|
||||
connectService();
|
||||
|
||||
|
|
@ -112,6 +137,9 @@ public final class PlatformService {
|
|||
data.writeByteArray(outStream.toByteArray());
|
||||
}
|
||||
|
||||
// We don't have any removed applications to include in the update
|
||||
data.writeInt(0);
|
||||
|
||||
Parcel reply = Parcel.obtain();
|
||||
try {
|
||||
mService.transact(TRANSACTION_updateApplicationList, data, reply, 0);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue