framework优化记录

 分类:Android, Java 阅读 (36)
5月 152020
 

本文只是随手笔记,可能会有很多错误,仅供参考

基本Android8.1系统

一、healthd裁剪
1. system/core/rootdir/init.rc
屏蔽healthd服务
#service healthd /system/bin/healthd
# class core
# critical
# group root system wakelock

删除后系统没办法启动了

二、app删除
2. 启动模拟器看是否有Contacts和Email应用: 有
3. 去掉build/make/target/product/core.mk中PRODUCT_PACKAGES下的Emailt和Contacts并编译看系统中是否还这两个应用: 还有
4. 删除out下对应设备目录下的system/app/Email和system/priv-app/Contacts目录,并编译看系统中是否还这两个应用: 还有
5. 把out目录里的system.img删除掉,再试: 不行
6. 把out/target/common/obj/Apps目录下Email和Contacts相关目录删除再试: 还是有
7. 重启一下系统试试: 不行
8. 把修改core.mk中,把mmsservice也删除掉试试:不行
9. 把源码中packages/apps中的Contacts和Email目录删除,Email目录保留emailcommon目录:好了,这次没了
此阶段结论:其实第3步后make clean一下也可以,但是不想make clean
10. 把Calendar、ExactCalculator(calculator2)、Music、Gallery、Gallery2、SoundRecorder、TvSettings全删掉

三、mediaserver裁剪
在frameworks/av/media/mediaserver/mediaserver.rc中,将mediaserver启动项屏蔽掉
编译后系统可以启动,但是没有壁纸了,设置壁纸也没作用

四、framework服务删减
1、VibratorService删除
屏蔽掉SystemServer.java中启动这个服务的代码
//traceBeginAndSlog(“StartVibratorService”);
//vibrator = new VibratorService(context);
//ServiceManager.addService(“vibrator”, vibrator);
//traceEnd();
删除后,应用调用Vibrator时不会崩溃,log会提示no vibrator service

下面这一段也屏蔽掉:
/* by liuderu
traceBeginAndSlog(“MakeVibratorServiceReady”);
try {
vibrator.systemReady();
} catch (Throwable e) {
reportWtf(“making Vibrator Service ready”, e);
}
traceEnd(); */

2. ConsumerIrService删除
在system/core/rootdir/init.rc中on boot节点中增加如下代码:
setprop config.disable_consumerir true

3. LockSettingsService
在SystemServer.java中屏蔽LOCK_SETTINGS_SERVICE_CLASS的启动
/* by liuderu
traceBeginAndSlog(“StartLockSettingsService”);
try {
mSystemServiceManager.startService(LOCK_SETTINGS_SERVICE_CLASS);
lockSettings = ILockSettings.Stub.asInterface(
ServiceManager.getService(“lock_settings”));
} catch (Throwable e) {
reportWtf(“starting LockSettingsService service”, e);
}
traceEnd(); */

屏蔽bootPhase对lockSetting的检查:
/* by liuderu
traceBeginAndSlog(“StartBootPhaseLockSettingsReady”);
mSystemServiceManager.startBootPhase(SystemService.PHASE_LOCK_SETTINGS_READY);
traceEnd();
*/

4. MmsServiceBroker
删除SystemServer中
/* by liuderu
traceBeginAndSlog(“StartMmsService”);
mmsService = mSystemServiceManager.startService(MmsServiceBroker.class);
traceEnd();
*/

第二个地方
/*by liuderu
traceBeginAndSlog(“MakeMmsServiceReady”);
try {
if (mmsServiceF != null) mmsServiceF.systemRunning();
} catch (Throwable e) {
reportWtf(“Notifying MmsService running”, e);
}
traceEnd();
*/

5. TextServicesManagerService
禁止拼写检查服务
public boolean isSpellCheckerEnabled() {
//default from true to false, by liuderu
return getBoolean(Settings.Secure.SPELL_CHECKER_ENABLED, false);
}

6. AccountManagerService裁剪
SystemServer.java去掉相关代码
/* by liuderu traceBeginAndSlog(“StartAccountManagerService”);
mSystemServiceManager.startService(ACCOUNT_SERVICE_CLASS);
traceEnd();*/

ContentService.java
private SyncManager getSyncManager() {
if (SystemProperties.getBoolean(“config.disable_network”, false)) {
return null;
}

return null;

/*by liuderu
synchronized(mSyncManagerLock) {
try {
// Try to create the SyncManager, return null if it fails (e.g. the disk is full).
if (mSyncManager == null) mSyncManager = new SyncManager(mContext, mFactoryTest);
} catch (SQLiteException e) {
Log.e(TAG, “Can’t create SyncManager”, e);
}
return mSyncManager;
} */
}

DefaultPermissionGrantPolicy.java
第一部分:
/*by liuderu
// Calendar provider
PackageParser.Package calendarProviderPackage = getDefaultProviderAuthorityPackageLPr(
CalendarContract.AUTHORITY, userId);
if (calendarProviderPackage != null) {
grantRuntimePermissionsLPw(calendarProviderPackage, CONTACTS_PERMISSIONS, userId);
grantRuntimePermissionsLPw(calendarProviderPackage, CALENDAR_PERMISSIONS,
true, userId);
grantRuntimePermissionsLPw(calendarProviderPackage, STORAGE_PERMISSIONS, userId);
}

// Calendar provider sync adapters

List<PackageParser.Package> calendarSyncAdapters = getHeadlessSyncAdapterPackagesLPr(
calendarSyncAdapterPackages, userId);
final int calendarSyncAdapterCount = calendarSyncAdapters.size();
for (int i = 0; i < calendarSyncAdapterCount; i++) {
PackageParser.Package calendarSyncAdapter = calendarSyncAdapters.get(i);
if (doesPackageSupportRuntimePermissions(calendarSyncAdapter)) {
grantRuntimePermissionsLPw(calendarSyncAdapter, CALENDAR_PERMISSIONS, userId);
}
}

// Contacts
Intent contactsIntent = new Intent(Intent.ACTION_MAIN);
contactsIntent.addCategory(Intent.CATEGORY_APP_CONTACTS);
PackageParser.Package contactsPackage = getDefaultSystemHandlerActivityPackageLPr(
contactsIntent, userId);
if (contactsPackage != null
&& doesPackageSupportRuntimePermissions(contactsPackage)) {
grantRuntimePermissionsLPw(contactsPackage, CONTACTS_PERMISSIONS, userId);
grantRuntimePermissionsLPw(contactsPackage, PHONE_PERMISSIONS, userId);
}

// Contacts provider sync adapters
List<PackageParser.Package> contactsSyncAdapters = getHeadlessSyncAdapterPackagesLPr(
contactsSyncAdapterPackages, userId);
final int contactsSyncAdapterCount = contactsSyncAdapters.size();
for (int i = 0; i < contactsSyncAdapterCount; i++) {
PackageParser.Package contactsSyncAdapter = contactsSyncAdapters.get(i);
if (doesPackageSupportRuntimePermissions(contactsSyncAdapter)) {
grantRuntimePermissionsLPw(contactsSyncAdapter, CONTACTS_PERMISSIONS, userId);
}
}

// Contacts provider
PackageParser.Package contactsProviderPackage = getDefaultProviderAuthorityPackageLPr(
ContactsContract.AUTHORITY, userId);
if (contactsProviderPackage != null) {
grantRuntimePermissionsLPw(contactsProviderPackage, CONTACTS_PERMISSIONS,
true, userId);
grantRuntimePermissionsLPw(contactsProviderPackage, PHONE_PERMISSIONS,
true, userId);
grantRuntimePermissionsLPw(contactsProviderPackage, STORAGE_PERMISSIONS, userId);
}*/

第二部分:
/* by liuderu
String[] contactsSyncAdapterPackages = (syncAdapterPackagesProvider != null) ?
syncAdapterPackagesProvider.getPackages(ContactsContract.AUTHORITY, userId) : null;
String[] calendarSyncAdapterPackages = (syncAdapterPackagesProvider != null) ?
syncAdapterPackagesProvider.getPackages(CalendarContract.AUTHORITY, userId) : null;*/

UsageStatsService.java

void reportContentProviderUsage(String authority, String providerPkgName, int userId) {
/*by liuderu
// Get sync adapters for the authority
String[] packages = ContentResolver.getSyncAdapterPackagesForAuthorityAsUser(
authority, userId);
for (String packageName: packages) {
// Only force the sync adapters to active if the provider is not in the same package and
// the sync adapter is a system package.
try {
PackageInfo pi = mPackageManager.getPackageInfoAsUser(
packageName, PackageManager.MATCH_SYSTEM_ONLY, userId);
if (pi == null || pi.applicationInfo == null) {
continue;
}
if (!packageName.equals(providerPkgName)) {
setAppIdleAsync(packageName, false, userId);
}
} catch (NameNotFoundException e) {
// Shouldn’t happen
}
}
*/
}

ContactsProvider2.java
case BACKGROUND_TASK_UPDATE_ACCOUNTS: {
/*by liuderu
Context context = getContext();
if (!mAccountUpdateListenerRegistered) {
AccountManager.get(context).addOnAccountsUpdatedListener(this, null, false);
mAccountUpdateListenerRegistered = true;
}

// Update the accounts for both the contacts and profile DBs.
Account[] accounts = AccountManager.get(context).getAccounts();
switchToContactMode();
boolean accountsChanged = updateAccountsInBackground(accounts);
switchToProfileMode();
accountsChanged |= updateAccountsInBackground(accounts);

switchToContactMode();

updateContactsAccountCount(accounts);
updateDirectoriesInBackground(accountsChanged);*/
break;
}

7. PrintManagerService
在SystemServer中删除相关代码
/*
if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_PRINTING)) {
traceBeginAndSlog(“StartPrintManager”);
mSystemServiceManager.startService(PRINT_MANAGER_SERVICE_CLASS);
traceEnd();
}
*/

8. CoverageService
在SystemServer中删除相关代码
/*by liuderu
if (!disableNonCoreServices && CoverageService.ENABLED) {
traceBeginAndSlog(“AddCoverageService”);
ServiceManager.addService(CoverageService.COVERAGE_SERVICE, new CoverageService());
traceEnd();
}
*/

9. DiskStatsService
在SystemServer中删除相关代码
/*by liuderu
traceBeginAndSlog(“StartDiskStatsService”);
try {
ServiceManager.addService(“diskstats”, new DiskStatsService(context));
} catch (Throwable e) {
reportWtf(“starting DiskStats Service”, e);
}
traceEnd();
*/

 

打赏
 Posted by on 2020-05-15

Sorry, the comment form is closed at this time.