首先将chrome加入进来:
vendor/mediatek/proprietary/packages/3rd-party/chrome/
这个目录下创建一个chrome模块,
将apk放到这里,并添加mk文件:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := chrome
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_CERTIFICATE := PRESIGNED
LOCAL_MULTILIB := 32
LOCAL_DEX_PREOPT := ture
include $(BUILD_PREBUILT)
然后在device/mediatek/common/device.mk中添加一句:
PRODUCT_PACKAGES += chrome
这样就能顺利的将chrome编译到我们的项目中来了;然后在mk中找到原生的浏览器的定义地方,将他注释就ok。
下面就是替换chrome的图标
Launcher中基本关于图片的处理都在这个类中:
src/com/android/launcher3/IconCache.java
当然图标的生成和我们要做的替换也是不例外的,共有3个地方:
a.
@Thunk synchronized void addIconToDBAndMemCache(LauncherActivityInfo app,
PackageInfo info, long userSerial, boolean replaceExisting) {
final ComponentKey key = new ComponentKey(app.getComponentName(), app.getUser());
CacheEntry entry = null;
if (!replaceExisting) {
entry = mCache.get(key);
// We can't reuse the entry if the high-res icon is not present.
if (entry == null || entry.isLowResIcon || entry.icon == null) {
entry = null;
}
}
if (entry == null) {
entry = new CacheEntry();
entry.icon = LauncherIcons.createIconBitmap(getFullResIcon(app), mContext);
/* begin */
if (app.getComponentName() != null && app.getComponentName().getPackageName() != null
&& app.getComponentName().getPackageName().equals("com.android.chrome")) {
entry.icon = IconUtil.getBitmap(mContext, R.drawable.icon_chrome);
}
/* end */
}
entry.title = app.getLabel();
entry.contentDescription = mUserManager.getBadgedLabelForUser(entry.title, app.getUser());
mCache.put(key, entry);
Bitmap lowResIcon = generateLowResIcon(entry.icon);
ContentValues values = newContentValues(entry.icon, lowResIcon, entry.title.toString(),
app.getApplicationInfo().packageName);
addIconToDB(values, app.getComponentName(), info, userSerial);
}
b.
protected CacheEntry cacheLocked(
@NonNull ComponentName componentName,
@NonNull Provider infoProvider,
UserHandle user, boolean usePackageIcon, boolean useLowResIcon) {
.....
/* begin */
if (componentName != null && componentName.getPackageName() != null && componentName.getPackageName().equals("com.android.chrome")) {
entry.icon = IconUtil.getBitmap(mContext, R.drawable.icon_chrome);
}
/* end */
return entry;
}
c.
private CacheEntry getEntryForPackageLocked(String packageName, UserHandle user,
boolean useLowResIcon) {
......
/* begin */
if("com.android.chrome".equals(packageName)){
icon = IconUtil.getBitmap(mContext,R.drawable.icon_chrome);
}
/* end */
Bitmap lowResIcon = generateLowResIcon(icon);
entry.title = appInfo.loadLabel(mPackageManager);
entry.contentDescription = mUserManager.getBadgedLabelForUser(entry.title, user);
entry.icon = useLowResIcon ? lowResIcon : icon;
entry.isLowResIcon = useLowResIcon;
......
还有一个getBitmap()方法:
public static Bitmap getBitmap(Context context, int res) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_4444;
return BitmapFactory.decodeResource(context.getResources(), res, options);
}
这样就大功告成啦!