网上有说必须加 GMS 框架后才能生效,我这里验证的是不需要,将 GMS 包中的 Chrome.apk 和 TrichromeLibrary.apk 拷贝出来
在 package/apps 目录下新建 Chrome 文件夹,将俩 apk 拷贝至此出,新建 Android.mk
packages\apps\Chrome\Android.mk
############################################################################### # Chrome LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := Chrome LOCAL_MODULE_TAGS := optional LOCAL_PRODUCT_MODULE := true LOCAL_SRC_FILES := $(LOCAL_MODULE).apk LOCAL_OVERRIDES_PACKAGES := Browser Browser2 MtkBrowser MtkBrowserAutoTests BrowserSanityTest LOCAL_REQUIRED_MODULES := TrichromeLibrary BookmarkProvider PartnerBookmarksProvider LOCAL_MULTILIB := both LOCAL_MODULE_CLASS := APPS LOCAL_DEX_PREOPT := false LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX) LOCAL_CERTIFICATE := PRESIGNED include $(BUILD_PREBUILT) include $(CLEAR_VARS) LOCAL_MODULE := TrichromeLibrary LOCAL_MODULE_TAGS := optional LOCAL_PRODUCT_MODULE := true LOCAL_SRC_FILES := $(LOCAL_MODULE).apk LOCAL_MULTILIB := both LOCAL_MODULE_CLASS := APPS LOCAL_DEX_PREOPT := false LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX) LOCAL_CERTIFICATE := PRESIGNED include $(BUILD_PREBUILT)
在 core.mk 或者 handheld_system.mk 中添加 Chrome 、 TrichromeLibrary 编译,这样预装就搞定了。
接下来修改默认主页面
在 PartnerBookmarksProvider 下新建 PartnerHomepageProvider.java,其中的 HOMEPAGE_URI 就是默认主页
alps\packages\providers\PartnerBookmarksProvider\src\com\android\providers\partnerbookmarks\PartnerHomepageProvider.java
package com.android.providers.partnerbookmarks; import android.content.ContentProvider; import android.content.ContentValues; import android.content.UriMatcher; import android.database.Cursor; import android.database.MatrixCursor; import android.net.Uri; public class PartnerHomepageProvider extends ContentProvider { private static String HOMEPAGE_URI = "https://www.cisco.com"; private static final int URI_MATCH_HOMEPAGE = 0; private static final UriMatcher URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH); static { URI_MATCHER.addURI("com.android.partnerbrowsercustomizations", "homepage", URI_MATCH_HOMEPAGE); } @Override public boolean onCreate() { return true; } @Override public String getType(Uri uri) { switch (URI_MATCHER.match(uri)) { case URI_MATCH_HOMEPAGE: return "vnd.android.cursor.item/partnerhomepage"; default: return null; } } @Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { switch (URI_MATCHER.match(uri)) { case URI_MATCH_HOMEPAGE: MatrixCursor cursor = new MatrixCursor(new String[] { "homepage" }, 1); cursor.addRow(new Object[] { HOMEPAGE_URI }); return cursor; default: return null; } } @Override public Uri insert(Uri uri, ContentValues values) { throw new UnsupportedOperationException(); } @Override public int delete(Uri uri, String selection, String[] selectionArgs) { throw new UnsupportedOperationException(); } @Override public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { throw new UnsupportedOperationException(); } }
配置 provider 使它能够被 Chrome apk 访问到。重新编译大功告成。
alps\packages\providers\PartnerBookmarksProvider\AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.providers.partnerbookmarks"> <!-- We add an application tag here just to indicate the authorities --> <application> <provider android:name="PartnerBookmarksProvider" android:authorities="com.android.partnerbookmarks" android:exported="true" /> <provider android:name="PartnerHomepageProvider" android:authorities="com.android.partnerbrowsercustomizations" android:exported="true" /> </application> </manifest>