MTK Android 默认值修改笔记

时间:2022-03-22 16:17:24

1.设置菜单:

1.1位置信息(Location)默认关闭:

请将

alps\frameworks\base\packages\SettingsProvider\res\values\default.xml

中的

<string name="def_location_providers_allowed" translatable="false">gps</string>

修改为

<string name="def_location_providers_allowed" translatable="false"></string>

然后重新build ,format 手机,download新的image测试。

1.2默认系统时间的修改(请区别于RTC时间)

首先找到vendor\mediatek\proprietary\frameworks\base\res\res\values下的2个xml文件,

symbols.xml,config.xml,.

2个文件分辨定义了默认时间的key和值,默认只定义了年分,可以自行添加月,日,时,分,秒。

如:

symbols.xml

<java-symbol type="string" name="config_mm_package_name" />
<java-symbol type="integer" name="default_restore_year" />
<java-symbol type="integer" name="default_restore_month" />
<java-symbol type="integer" name="default_restore_day" />
<java-symbol type="integer" name="default_restore_hour" />
<java-symbol type="integer" name="default_restore_minute" />
<java-symbol type="integer" name="default_restore_second" />

config.xml

<!-- default year for first power on-->
<integer name="default_restore_year">2015</integer>
<!-- default month for first power on-->
<integer name="default_restore_month">0</integer>
<!-- default day for first power on-->
<integer name="default_restore_day">1</integer>
<!-- default hour for first power on-->
<integer name="default_restore_hour"></integer>
<!-- default minute for first power on-->
<integer name="default_restore_minute"></integer>
<!-- default second for first power on-->
<integer name="default_restore_second"></integer>

具体设置生效是在JAVA类里面实现,请看NetworkTimeUpdateService.java,位于framework/base/services下面:

Time today = new Time(Time.getCurrentTimezone());
today.setToNow();
Log.d(TAG, "First boot:" + tempString + " with date:" + today);
today.set(mDefaultDay, mDefaultMonth, mDefaultYear);

mDefaultDay,mDefaultMonth,mDefaultYear即是通过上述XML文件得到的值,可以发现这个set有个带6个参数的重载方法,正是此方法可以精确到秒,自行尝试吧。

注意:today.set(mDefaultDay, mDefaultMonth, mDefaultYear)此句是我修改过的,源码是today.set(1, 0, mDefaultYear),0代表January。

2.Launcher:

当有多个launcher可供选择时,默认选择某个launcher,而不弹出选择框。

修改ActivityManagerService.java的startHomeActivityLocked方法:

boolean startHomeActivityLocked(int userId, String reason) {

if (mFactoryTest == FactoryTest.FACTORY_TEST_LOW_LEVEL
&& mTopAction == null) {
// We are running in factory test mode, but unable to find
// the factory test app, so just sit around displaying the
// error message and don't try to start anything.
return false;
} /**
* mtk add
* set default launcher
*/ ComponentName DefaultLauncher=new ComponentName("com.android.launcher3","com.android.launcher3.Launcher"); //此处设置默认Launcher的包名和类名
//Slog.d(TAG,"set default launcher");
final PackageManager mPm = mContext.getPackageManager();
ArrayList<ResolveInfo> homeActivities = new ArrayList<ResolveInfo>();
ComponentName currentDefaultHome = mPm.getHomeActivities(homeActivities); ComponentName[]mHomeComponentSet = new ComponentName[homeActivities.size()];
for (int i = 0; i < homeActivities.size(); i++) {
final ResolveInfo candidate = homeActivities.get(i);
//Slog.d(TAG,"homeActivities"+candidate);
final ActivityInfo info = candidate.activityInfo;
ComponentName activityName = new ComponentName(info.packageName, info.name);
mHomeComponentSet[i] = activityName;
}
IntentFilter mHomeFilter = new IntentFilter(Intent.ACTION_MAIN);
mHomeFilter.addCategory(Intent.CATEGORY_HOME);
mHomeFilter.addCategory(Intent.CATEGORY_DEFAULT);
List<ComponentName>Activities=new ArrayList();
mPm.replacePreferredActivity(mHomeFilter, IntentFilter.MATCH_CATEGORY_EMPTY,mHomeComponentSet, DefaultLauncher); /**
* set default launcher end
*/ Intent intent = getHomeIntent();
ActivityInfo aInfo =
resolveActivityInfo(intent, STOCK_PM_FLAGS, userId);
......

PS:

1.如果用户在设置->应用程序->管理应用程序->所有应用程序列表,找到之前设置的默认Launcher,并取消了默认值,系统会重新弹出launcher选择框。但重启后会进入上述代码设置的默认Launcher。

2.如果用户在设置->主屏幕中修改了默认的Launcher,下次重启后将进入修改后的Launcher

3.Settings:

设置下的一些默认值不是在xml修改,就是在SettingsProvider下的DataHelper.java下修改,loadSettings方法

4.相机:

常用的设置方法:SettingDataBase下找到DEFAULT_VALUE_FOR_SETTING_ID,更改对应ID的XML文件值.

5.音乐播放器:

1.均衡器(Equalizer)相关:ControlPanelEffect.java相关定义和代码修改