System-Bluetooth name/WiFi AP name/sleep add never/Notification popup

最后更新于:2022-04-01 14:48:29

今天拿到一个客户新的订单需求,大概有40多个需求,今天先讲更改系统的蓝牙/wifi 热点/消息通知/sleep 添加 never选项,分别是: 蓝牙:连接显示名、系统界面显示名字,重命名前的默认名字 wifi 热点:连接名字,重命名前默认 Network name Notification popup :系统 Notification popup 默认不勾选 休眠添加never选项,默认30s:添加永不休眠,默认30s 首先我们要知道系统默认的蓝牙名字 ANDROID BT Linux input ...> find 你的源码根目录/ -type f|xargs grep "ANDROID BT" -l 这句命令是找出源码下所有带有字符串 ANDROID BT 所在的文件,搜索无果,直接进入源码 packages\apps\Settings\src\com\android\settings\bluetooth\BluetoothSettins.java 跟踪源码找到如下代码 ~~~ @Override public void onResume() { ...... if (mLocalAdapter != null) { updateContent(mLocalAdapter.getBluetoothState()); } } ~~~ 跟踪updateContent函数,修改如下代码 ~~~ if (mMyDevicePreference == null) { mMyDevicePreference = new Preference(getActivity()); } // Engineer-Jsp add default bluetooth name if (android.os.SystemProperties.isWalPadVersion()) { mMyDevicePreference.setSummary(getResources().getString( R.string.bluetooth_is_visible_message, "Walpad C")); }else{ mMyDevicePreference.setSummary(getResources().getString( R.string.bluetooth_is_visible_message, mLocalAdapter.getName())); } mMyDevicePreference.setSelectable(false); ~~~ 其中 isWalpadVersion 函数是我在frameworks/base/core/java/android/os/SystemProperties.java中定义的 ~~~ public static boolean isWalPadVersion(){ return SystemProperties.get("ro.product.model").contains("Walpad"); } ~~~ 根据编译文件设置的客户平板型号定制产品而定,这样写有人可能会觉得多此一举,显的麻烦,但是作为一个系统,能把它做成兼容模式岂不是更好? 因为下次再有系统定制订单需求,我们只需要修改配置文件和分支就够了,轻松方便,而不需要再去new 代码了 setSummary(...,...)函数就是蓝牙设置打开蓝牙之后在界面显示的效果 R.string.bluetooth.is.visible_message 内容: ~~~ <string name="bluetooth_is_visible_message"><xliff:g id="device_name">%1$s</xliff:g> is visible to nearby devices while Bluetooth Settings is open.</string> ~~~ device_name 即为我们替换的名字,即Walpad C,效果图: ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-03-10_56e0e2a2b28b5.jpg) 接下来修改重名命选项的蓝牙设备名称,onOptionsItemSelected(MenuItem item) 根据 item 追踪重命名的 Dialog 找到如下逻辑: ~~~ @Override public Dialog onCreateDialog(Bundle savedInstanceState) { ...... mAlertDialog = new AlertDialog.Builder(getActivity()) .setTitle(R.string.bluetooth_rename_device) .setView(createDialogView(deviceName))// 继续追踪createDialogView(deviceName)方法 ...... return mAlertDialog; } ~~~ 根据逻辑,修改如下: ~~~ private View createDialogView(String deviceName) { ...... // Engineer-Jsp add default bluetooth name if (android.os.SystemProperties.isWalPadVersion()) {// 根据model显示名称 mDeviceNameView.setText("Walpad C"); }else{ mDeviceNameView.setText(deviceName); // set initial value before adding listener } ...... return view; } ~~~ 效果图: ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-03-10_56e0e2a2c417d.jpg) 连接显示名修改: ~~~ // Engineer-Jsp add default bluetooth name if (android.os.SystemProperties.isWalPadVersion()) { mMyDevicePreference.setSummary(getResources().getString( R.string.bluetooth_is_visible_message, "Walpad C")); mLocalAdapter.setName("Walpad C");//在之前讲到的修改除再添加此句 }else{ mMyDevicePreference.setSummary(getResources().getString( R.string.bluetooth_is_visible_message, mLocalAdapter.getName())); } ~~~ 效果: ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-03-10_56e0e2a317ec8.jpg) 修改wifi重命名前的名字,根据信息搜索到源码packages\apps\Settings\src\com\android\settings\wifi\WifiApDialog.java 根据逻辑,查找到如下代码: ~~~ @Override protected void onCreate(Bundle savedInstanceState) { Context context = getContext(); ...... if (mWifiConfig != null) { // Engineer-Jsp add default bluetooth name if (android.os.SystemProperties.isWalPadVersion()) { //根据型号显示ssid mSsid.setText("Walpad C"); }else{ mSsid.setText(mWifiConfig.SSID); } /// M: set selection mSecurity.setSelection(mExt.getSelection(mSecurityTypeIndex)); if (mSecurityTypeIndex == WPA2_INDEX) { mPassword.setText(mWifiConfig.preSharedKey); } ///M: get configured channel @{ mChannel = mWifiConfig.channel; mChannelWidth = mWifiConfig.channelWidth; /// @} } ...... } ~~~ 效果: ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-03-10_56e0e2a3397e7.jpg) 连接名字: ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-03-10_56e0e2a35bd0a.jpg) 修改系统 Notification popup 默认不勾选 搜索关键字:源码目录...>find ./ -name ".xml" | xargs grep "Popup notification" 找到xml文件之后找到对应string name 名称,发现他被一个布局文件调用,packages\apps\Mms\res\xml\notificationpreferences.xml - pref_summary_popup_notification -  defaultValue="false" 把这个默认false,即可 效果: ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-03-10_56e0e2a373ef7.jpg) 修改休眠选项默认 30s 添加永不休眠选项: 默认休眠30s修改:frameworks\base\packages\SettingsProvider\res\values\defaults.xml ~~~ <integer name="def_screen_off_timeout">30000</integer> ~~~ 添加永不休眠选项: ~~~ private static final boolean sNeedScreenTimeoutNever = true; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ...... if (sNeedScreenTimeoutNever && mScreenTimeoutPreference != null) { //rmt add Resources res = getResources(); final String[] entries = res.getStringArray(R.array.screen_timeout_entries); final String[] values = res.getStringArray(R.array.screen_timeout_values); int entriesLength = entries.length; final String[] newEntries = new String[entriesLength + 1]; for (int i = 0; i < entriesLength + 1; i++) { if (i != entriesLength) { newEntries[i] = entries[i]; } else { newEntries[i] = res.getString(R.string.zen_mode_when_never); } } int valuesLength = values.length; final String[] newValues = new String[valuesLength + 1]; for (int i = 0; i < valuesLength + 1; i++) { if (i != valuesLength) { newValues[i] = values[i]; } else { newValues[i] = "2147483647"; } } mScreenTimeoutPreference.setEntries(newEntries); mScreenTimeoutPreference.setEntryValues(newValues); ...... } private void updateTimeoutPreferenceDescription(long currentTimeout) { ...... } else if(currentTimeout == Integer.MAX_VALUE) { //Engineer-Jsp add summary = preference.getContext().getString(R.string.zen_mode_when_never); } ....... } ~~~ 效果: ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-03-10_56e0e2a38ac55.jpg)
';