/*********************************************************************
* I.MX6 Android 移除 Settings wifi功能
* 说明:
* 本文主要记录如何修改Android Settings中的主选项,初衷是有些
* 设置并不是我们需要,隐藏掉还是比较好的。
*
* 2016-3-5 深圳 南山平山村 曾剑锋
********************************************************************/
参考文档:
. Android Settings开发之修改
http://blog.csdn.net/wangjinyu501/article/details/22077803
. Android Settings和SettingsProvider源码分析与修改
http://www.cncoders.net/article/11633/
. 何时使用 Preference Headers
http://blog.csdn.net/ixiaobu/article/details/8609935
一、cat packages/apps/Settings/AndroidManifest.xml
......
<!-- Settings -->
<activity android:name="Settings" ------+
android:label="@string/settings_label_launcher" |
android:taskAffinity="com.android.settings" |
android:launchMode="singleTask"> |
<intent-filter> |
<action android:name="android.intent.action.MAIN" /> |
<action android:name="android.settings.SETTINGS" /> |
<category android:name="android.intent.category.DEFAULT" /> |
<category android:name="android.intent.category.LAUNCHER" /> |
</intent-filter> |
</activity> |
...... |
|
二、cat packages/apps/Settings/src/com/android/settings/Settings.java <---+
......
/**
* Populate the activity with the top-level headers.
*/
@Override
public void onBuildHeaders(List<Header> headers) {
loadHeadersFromResource(R.xml.settings_headers, headers);
|
updateHeaderList(headers); |
} |
...... |
V
三、cat packages/apps/Settings/res/xml/settings_headers.xml
......
<!-- Wifi -->
<!--
<header
android:id="@+id/wifi_settings"
android:fragment="com.android.settings.wifi.WifiSettings"
android:title="@string/wifi_settings_title"
android:icon="@drawable/ic_settings_wireless" />
-->
......
四、error:
. error :
. 现象:
......
make: Entering directory `/home/myzr/myandroid'
target R.java/Manifest.java: Settings (out/target/common/obj/APPS/Settings_intermediates/src/R.stamp)
/home/myzr/myandroid/packages/apps/Settings/AndroidManifest.xml:: error: Error: No resource found that matches the given name (at 'resource' with value '@id/wifi_settings').
/home/myzr/myandroid/packages/apps/Settings/AndroidManifest.xml:: error: Error: No resource found that matches the given name (at 'resource' with value '@id/wifi_settings').
/home/myzr/myandroid/packages/apps/Settings/AndroidManifest.xml:: error: Error: No resource found that matches the given name (at 'resource' with value '@id/wifi_settings').
make: *** [out/target/common/obj/APPS/Settings_intermediates/src/R.stamp] Error
make: Leaving directory `/home/myzr/myandroid'
. 解决办法:
cat packages/apps/Settings/AndroidManifest.xml
......
<!-- Top-level settings -->
<!--
<activity android:name="Settings$WifiSettingsActivity"
android:taskAffinity=""
android:label="@string/wifi_settings"
android:configChanges="orientation|keyboardHidden|screenSize"
android:excludeFromRecents="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.settings.WIFI_SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.VOICE_LAUNCH" />
<category android:name="com.android.settings.SHORTCUT" />
</intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.wifi.WifiSettings" />
<meta-data android:name="com.android.settings.TOP_LEVEL_HEADER_ID"
android:resource="@id/wifi_settings" />
</activity>
-->
<!-- Keep compatibility with old shortcuts. -->
<!--
<activity-alias android:name=".wifi.WifiSettings"
android:taskAffinity="com.android.settings"
android:label="@string/wifi_settings"
android:targetActivity="Settings$WifiSettingsActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:exported="true">
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.wifi.WifiSettings" />
<meta-data android:name="com.android.settings.TOP_LEVEL_HEADER_ID"
android:resource="@id/wifi_settings" />
</activity-alias>
<activity android:name=".wifi.WifiPickerActivity"
android:taskAffinity="com.android.settings"
android:parentActivityName="Settings">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.net.wifi.PICK_WIFI_NETWORK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".wifi.WifiSetupActivity"
android:theme="@style/setup_wizard_theme"
android:label="@string/wifi_setup_wizard_title"
android:icon="@drawable/empty_icon"
android:clearTaskOnLaunch="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="com.android.net.wifi.SETUP_WIFI_NETWORK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".wifi.WifiSettingsForSetupWizardXL"
android:theme="@android:style/Theme.Holo.NoActionBar"
android:screenOrientation="behind"
android:clearTaskOnLaunch="true"
android:windowSoftInputMode="adjustResize"
android:exported="true" />
<activity android:name="Settings$AdvancedWifiSettingsActivity"
android:taskAffinity="com.android.settings"
android:label="@string/wifi_advanced_settings_label"
android:configChanges="orientation|keyboardHidden|screenSize"
android:parentActivityName="Settings$WifiSettingsActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.settings.WIFI_IP_SETTINGS" />
<category android:name="android.intent.category.VOICE_LAUNCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.wifi.AdvancedWifiSettings" />
<meta-data android:name="com.android.settings.TOP_LEVEL_HEADER_ID"
android:resource="@id/wifi_settings" />
<meta-data android:name="com.android.settings.PARENT_FRAGMENT_TITLE"
android:resource="@string/wifi_settings" />
<meta-data android:name="com.android.settings.PARENT_FRAGMENT_CLASS"
android:value="com.android.settings.Settings$WifiSettingsActivity" />
</activity>
-->
......
. error :
. 现象:
......
No private recovery resources for TARGET_DEVICE sabresd_6dq
make: Entering directory `/home/myzr/myandroid'
target R.java/Manifest.java: Settings (out/target/common/obj/APPS/Settings_intermediates/src/R.stamp)
(skipping file '.settings_headers.xml.swp' due to ANDROID_AAPT_IGNORE pattern '.*')
target Java: Settings (out/target/common/obj/APPS/Settings_intermediates/classes)
/home/myzr/myandroid/packages/apps/Settings/src/com/android/settings/Settings.java:: cannot find symbol
symbol : variable wifi_settings
location: class com.android.settings.R.id
} else if (id == R.id.wifi_settings) {
^
/home/myzr/myandroid/packages/apps/Settings/src/com/android/settings/Settings.java:: cannot find symbol
symbol : variable wifi_settings
location: class com.android.settings.R.id
} else if (header.id == R.id.wifi_settings || header.id == R.id.bluetooth_settings) {
^
/home/myzr/myandroid/packages/apps/Settings/src/com/android/settings/Settings.java:: cannot find symbol
symbol : variable wifi_settings
location: class com.android.settings.R.id
if (header.id == R.id.wifi_settings) {
^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
errors
make: *** [out/target/common/obj/APPS/Settings_intermediates/classes-full-debug.jar] Error
make: Leaving directory `/home/myzr/myandroid'
. 解决办法:
cat packages/apps/Settings/src/com/android/settings/Settings.java
......
// Show only these settings for restricted users
private int[] SETTINGS_FOR_RESTRICTED = {
R.id.wireless_section,
//R.id.wifi_settings,
R.id.bluetooth_settings,
R.id.data_usage_settings,
R.id.wireless_settings,
R.id.device_section,
R.id.sound_settings,
R.id.display_settings,
R.id.storage_settings,
R.id.application_settings,
R.id.battery_settings,
R.id.personal_section,
R.id.location_settings,
R.id.security_settings,
R.id.language_settings,
R.id.user_settings,
R.id.account_settings,
R.id.account_add,
R.id.system_section,
R.id.date_time_settings,
R.id.about_settings,
R.id.accessibility_settings
}
......
private void updateHeaderList(List<Header> target) {
while (i < target.size()) {
Header header = target.get(i);
// Ids are integers, so downcasting
int id = (int) header.id;
if (id == R.id.operator_settings || id == R.id.manufacturer_settings) {
Utils.updateHeaderToSpecificActivityFromMetaDataOrRemove(this, target, header);
}
/** annotation this part
else if (id == R.id.wifi_settings) {
// Remove WiFi Settings if WiFi service is not available.
if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)) {
target.remove(i);
}
}
*/
else if (id == R.id.bluetooth_settings) {
// Remove Bluetooth Settings if Bluetooth service is not available.
if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) {
target.remove(i);
}
} else if (id == R.id.data_usage_settings) {
......
......
}
......
private static class HeaderAdapter extends ArrayAdapter<Header> {
......
static int getHeaderType(Header header) {
if (header.fragment == null && header.intent == null) {
return HEADER_TYPE_CATEGORY;
} else if (
/** annotation this part
header.id == R.id.wifi_settings ||
*/
header.id == R.id.bluetooth_settings) {
return HEADER_TYPE_SWITCH;
} else {
return HEADER_TYPE_NORMAL;
}
}
......
}
......
@Override
public View getView(int position, View convertView, ViewGroup parent) {
......
// All view fields must be updated every time, because the view may be recycled
switch (headerType) {
case HEADER_TYPE_CATEGORY:
holder.title.setText(header.getTitle(getContext().getResources()));
break;
case HEADER_TYPE_SWITCH:
// Would need a different treatment if the main menu had more switches
/** annotation this part
if (header.id == R.id.wifi_settings) {
mWifiEnabler.setSwitch(holder.switch_);
} else {
*/
mBluetoothEnabler.setSwitch(holder.switch_);
/*
}
*/
// No break, fall through on purpose to update common fields
//$FALL-THROUGH$
case HEADER_TYPE_NORMAL:
if (header.extras != null
&& header.extras.containsKey(ManageAccountsSettings.KEY_ACCOUNT_TYPE)) {
String accType = header.extras.getString(
ManageAccountsSettings.KEY_ACCOUNT_TYPE);
ViewGroup.LayoutParams lp = holder.icon.getLayoutParams();
lp.width = getContext().getResources().getDimensionPixelSize(
R.dimen.header_icon_width);
lp.height = lp.width;
holder.icon.setLayoutParams(lp);
Drawable icon = mAuthHelper.getDrawableForType(getContext(), accType);
holder.icon.setImageDrawable(icon);
} else {
holder.icon.setImageResource(header.iconRes);
}
holder.title.setText(header.getTitle(getContext().getResources()));
CharSequence summary = header.getSummary(getContext().getResources());
if (!TextUtils.isEmpty(summary)) {
holder.summary.setVisibility(View.VISIBLE);
holder.summary.setText(summary);
} else {
holder.summary.setVisibility(View.GONE);
}
break;
}
......
}
......