Synchronize application icons with the host
This commit is contained in:
parent
8caaa1f35c
commit
5c7b0adf8c
11 changed files with 103 additions and 41 deletions
|
|
@ -27,8 +27,14 @@ import android.content.Context;
|
|||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.net.Uri;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Bitmap.Config;
|
||||
import android.graphics.Canvas;
|
||||
|
||||
import java.util.List;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
public final class PlatformService {
|
||||
private static final String TAG = "AnboxAppMgr";
|
||||
|
|
@ -69,28 +75,41 @@ public final class PlatformService {
|
|||
data.writeInt(apps.size());
|
||||
for (int n = 0; n < apps.size(); n++) {
|
||||
ApplicationInfo appInfo = apps.get(n);
|
||||
|
||||
Intent launchIntent = mPm.getLaunchIntentForPackage(appInfo.packageName);
|
||||
if (launchIntent == null)
|
||||
continue;
|
||||
|
||||
Drawable icon = null;
|
||||
try {
|
||||
icon = mPm.getApplicationIcon(appInfo.packageName);
|
||||
}
|
||||
catch (PackageManager.NameNotFoundException ex) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (icon == null)
|
||||
continue;
|
||||
|
||||
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);
|
||||
}
|
||||
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);
|
||||
|
||||
// FIXME add icon, flags, ...
|
||||
Bitmap iconBitmap = drawableToBitmap(icon);
|
||||
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
|
||||
iconBitmap.compress(Bitmap.CompressFormat.PNG, 90, outStream);
|
||||
data.writeByteArray(outStream.toByteArray());
|
||||
}
|
||||
|
||||
Parcel reply = Parcel.obtain();
|
||||
|
|
@ -107,4 +126,16 @@ public final class PlatformService {
|
|||
|
||||
public void notifyPackageRemoved(Intent intent) {
|
||||
}
|
||||
|
||||
private Bitmap drawableToBitmap(Drawable drawable) {
|
||||
if (drawable instanceof BitmapDrawable)
|
||||
return ((BitmapDrawable)drawable).getBitmap();
|
||||
|
||||
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
|
||||
drawable.draw(canvas);
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,6 +81,8 @@ void PlatformApiStub::update_application_list(const ApplicationListUpdate &updat
|
|||
auto c = launch_intent->add_categories();
|
||||
*c = category;
|
||||
}
|
||||
|
||||
app->set_icon(a.icon.data(), a.icon.size());
|
||||
}
|
||||
|
||||
rpc_channel_->send_event(seq);
|
||||
|
|
|
|||
|
|
@ -73,6 +73,7 @@ public:
|
|||
std::vector<std::string> categories;
|
||||
};
|
||||
Intent launch_intent;
|
||||
std::vector<int8_t> icon;
|
||||
};
|
||||
std::vector<Application> applications;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -97,27 +97,27 @@ status_t PlatformService::update_application_list(const Parcel &data) {
|
|||
package_name.string(),
|
||||
};
|
||||
|
||||
if (data.readInt32() == 1) {
|
||||
String8 action(data.readString16());
|
||||
String8 uri(data.readString16());
|
||||
String8 type(data.readString16());
|
||||
String8 component_package(data.readString16());
|
||||
String8 component_class(data.readString16());
|
||||
String8 action(data.readString16());
|
||||
String8 uri(data.readString16());
|
||||
String8 type(data.readString16());
|
||||
String8 component_package(data.readString16());
|
||||
String8 component_class(data.readString16());
|
||||
|
||||
std::vector<std::string> categories;
|
||||
unsigned int num_categories = data.readInt32();
|
||||
for (int m = 0; m < num_categories; m++)
|
||||
categories.push_back(String8(data.readString16()).string());
|
||||
std::vector<std::string> categories;
|
||||
unsigned int num_categories = data.readInt32();
|
||||
for (int m = 0; m < num_categories; m++)
|
||||
categories.push_back(String8(data.readString16()).string());
|
||||
|
||||
p.launch_intent.action = action;
|
||||
p.launch_intent.uri = uri;
|
||||
p.launch_intent.type = type;
|
||||
p.launch_intent.package = component_package;
|
||||
p.launch_intent.component = component_class;
|
||||
p.launch_intent.categories = categories;
|
||||
p.launch_intent.action = action;
|
||||
p.launch_intent.uri = uri;
|
||||
p.launch_intent.type = type;
|
||||
p.launch_intent.package = component_package;
|
||||
p.launch_intent.component = component_class;
|
||||
p.launch_intent.categories = categories;
|
||||
|
||||
update.applications.push_back(p);
|
||||
};
|
||||
data.readByteVector(&p.icon);
|
||||
|
||||
update.applications.push_back(p);
|
||||
}
|
||||
|
||||
platform_api_stub_->update_application_list(update);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue