Improve application manangement and create desktop entries for available app

This commit is contained in:
Simon Fels 2016-12-02 16:11:38 +01:00
commit 00aadb5467
45 changed files with 1435 additions and 249 deletions

19
android/appmgr/Android.mk Normal file
View file

@ -0,0 +1,19 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_STATIC_JAVA_LIBRARIES := \
android-common \
android-support-v13
LOCAL_SRC_FILES := $(call all-java-files-under, src)
# LOCAL_SDK_VERSION := current
LOCAL_PACKAGE_NAME := AnboxAppMgr
LOCAL_CERTIFICATE := shared
LOCAL_PRIVILEGED_MODULE := true
LOCAL_OVERRIDES_PACKAGES := \
Home \
Launcher2 \
Launcher3 \
LatinIME \
QuickSearchBox
include $(BUILD_PACKAGE)

View file

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="org.anbox.appmgr">
<application
android:name="org.anbox.appmgr.MainApplication">
<activity
android:name=".LauncherActivity"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<service
android:name=".LauncherService"
android:exported="false">
</service>
<receiver android:name=".PackageEventReceiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<action android:name="android.intent.action.PACAKGE_REMOVED"/>
<action android:name="android.intent.action.PACKAGE_CHANGED"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="package"/>
</intent-filter>
</receiver>
</application>
</manifest>

View file

@ -0,0 +1,3 @@
<resources>
<string name="app_name">Anbox Application Manager</string>
</resources>

View file

@ -0,0 +1,47 @@
/*
* Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3, as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package org.anbox.appmgr;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.content.Intent;
public final class LauncherActivity extends Activity {
private static final String TAG = "AnboxAppMgr";
@Override
public void onCreate(Bundle info) {
super.onCreate(info);
Intent intent = new Intent(this, LauncherService.class);
startService(intent);
Log.i(TAG, "Created launcher activity");
}
@Override
public void onDestroy() {
Log.i(TAG, "Destroyed launcher activity");
Intent intent = new Intent(this, LauncherService.class);
stopService(intent);
super.onDestroy();
}
}

View file

@ -0,0 +1,53 @@
/*
* Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3, as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package org.anbox.appmgr;
import android.app.Service;
import android.util.Log;
import android.content.Intent;
import android.os.IBinder;
public final class LauncherService extends Service {
public static final String TAG = "AnboxAppMgr";
private PlatformService mPlatformService;
public LauncherService() {
super();
Log.i(TAG, "Service created");
}
@Override
public void onCreate() {
mPlatformService = new PlatformService(getBaseContext());
// Send all necessary initial updates
mPlatformService.sendApplicationListUpdate();
Log.i(TAG, "Service started");
}
@Override
public void onDestroy() {
Log.i(TAG, "Service stopped");
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
}

View file

@ -0,0 +1,23 @@
/*
* Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3, as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package org.anbox.appmgr;
import android.app.Application;
public final class MainApplication extends Application {
}

View file

@ -0,0 +1,32 @@
/*
* Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3, as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package org.anbox.appmgr;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class PackageEventReceiver extends BroadcastReceiver {
private static final String TAG = "AnboxAppMgr";
@Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "Received intent " + intent.toString());
}
}

View file

@ -0,0 +1,110 @@
/*
* Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3, as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package org.anbox.appmgr;
import android.os.ServiceManager;
import android.os.IBinder;
import android.os.Parcel;
import android.os.RemoteException;
import android.util.Log;
import android.content.Intent;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.ApplicationInfo;
import android.net.Uri;
import java.util.List;
public final class PlatformService {
private static final String TAG = "AnboxAppMgr";
private static final String SERVICE_NAME = "org.anbox.PlatformService";
private static final String DESCRIPTOR = "org.anbox.IPlatformService";
private static final int TRANSACTION_updateApplicationList = (IBinder.FIRST_CALL_TRANSACTION + 2);
private IBinder mService = null;
private PackageManager mPm = null;
private void connectService() {
if (mService != null)
return;
mService = ServiceManager.getService(SERVICE_NAME);
}
public PlatformService(Context context) {
if (context != null) {
mPm = context.getPackageManager();
} else {
Log.w(TAG, "No context available");
}
Log.i(TAG, "Connected to platform service");
}
public void sendApplicationListUpdate() {
connectService();
if (mPm == null || mService == null)
return;
Parcel data = Parcel.obtain();
data.writeInterfaceToken(DESCRIPTOR);
List<ApplicationInfo> apps = mPm.getInstalledApplications(0);
data.writeInt(apps.size());
for (int n = 0; n < apps.size(); n++) {
ApplicationInfo appInfo = apps.get(n);
data.writeString(appInfo.name);
data.writeString(appInfo.packageName);
Intent launchIntent = mPm.getLaunchIntentForPackage(appInfo.packageName);
if (launchIntent != null) {
data.writeInt(1);
data.writeString(launchIntent.getAction());
if (launchIntent.getData() != null)
data.writeString(launchIntent.getData().toString());
else
data.writeString("");
data.writeString(launchIntent.getType());
data.writeString(launchIntent.getComponent().getPackageName());
data.writeString(launchIntent.getComponent().getClassName());
data.writeInt(launchIntent.getCategories().size());
for (String category : launchIntent.getCategories())
data.writeString(category);
} else {
data.writeInt(0);
}
// FIXME add icon, flags, ...
}
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 notifyPackageAdded(Intent intent) {
}
public void notifyPackageRemoved(Intent intent) {
}
}