天天看點

Dialer撥号定制功能

一般大多數android裝置廠家都會對裝置進行定制,這其中就包括dialer,這裡面一般都是一些隐藏功能,比如工廠測試程式等。

這裡以android4.3為基礎,添加一個在撥号界面撥*#520#*字元串就能調出隐藏的程式。

在packages/apps/Dialer/src/com/android/dialer/SpecialCharSequenceMgr.java修改:

1.增加一個字元串定義

private static final String PRL_CLEAN_SD_DISPLAY = "*#520#*";

2.編寫指定撥号序列過濾函數

static private boolean handleCleanSDDisplay(Context context, String input) {
    if (input.equals(PRL_CLEAN_SD_DISPLAY)) {
        try {
            Intent intent = new Intent("android.intent.action.START_CleanSD");
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);
            return true;
        } catch (ActivityNotFoundException e) {
            Log.d(TAG, "no activity to handle showing clean_sd test app.");
        }
    }
    return false;
}
           

一旦檢查到*#520#*撥号序列就會去發送一個為android.intent.action.START_CleanSD的Intent,他就會去啟動這樣的一個隐藏apk,否則就是打電話,其他什麼都沒發生。

至于這個Intent步驟4說明。

3.添加上述2步驟的過濾函數

static boolean handleChars(Context context, String input, boolean useSystemWindow,
            EditText textField) {

        //get rid of the separators so that the string gets parsed correctly
        String dialString = PhoneNumberUtils.stripSeparators(input);

        if (handlePRLVersion(context, dialString)
				|| handleCitTestDisplay(context, dialString)
				||handleDeviceVersionDisplay(context, dialString)/*指定撥号序列過濾且處理的函數*/
				|| handleDeviceInfoDisplay(context, dialString)
                || handleModemTestDisplay(context, dialString)
                || handleIMEIDisplay(context, dialString, useSystemWindow)
                || handleRegulatoryInfoDisplay(context, dialString)
                || handlePinEntry(context, dialString)
                || handleAdnEntry(context, dialString, textField)
                || handleSecretCode(context, dialString)) {
            return true;
        }

        return false;
    }
           

4.設定被啟動的apk

修改被啟動的apk的AndroidManifest.xml,修改片段如下

<activity
    android:name="com.seuic.cleansd.view.MainActivity"
    android:launchMode="singleTop"
    android:screenOrientation="portrait">
    <intent-filter>
        <action android:name="android.intent.action.START_CleanSD" />
        <category android:name="android.intent.category.DEFAULT"/>
    </intent-filter>
</activity>
           

其中intent-filter段的action android:name就是上述步驟2發送的Intent,這個action觸發啟動該apk,啟動類型設定為android.intent.category.DEFAULT,表示這個apk是隐藏的,圖示不可見。