Android系統之路(初識MTK) ------ System-Bluetooth name/WiFi AP name/sleep add never/Notification popup

來源:互聯網
上載者:User

Android系統之路(初識MTK) ------ System-Bluetooth name/WiFi AP name/sleep add never/Notification popup

今天拿到一個客戶新的訂單需求,大概有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 內容:

%1$s is visible to nearby devices while Bluetooth Settings is open.
device_name 即為我們替換的名字,即Walpad C,:

接下來修改重名命選項的藍牙裝置名稱,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;    }

修改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;            /// @}        }      ......    }

效果:

 

串連名字:


修改系統 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,即可

效果:

修改休眠選項預設 30s 添加永不休眠選項:

預設休眠30s修改:frameworks\base\packages\SettingsProvider\res\values\defaults.xml

30000
添加永不休眠選項:
    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);}.......    }
效果:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.