Android8.1 MTK平台 系统需求定制

1、清空短信记录接口

vendor\mediatek\proprietary\packages\apps\Mms\src\com\android\mms\transaction\NoneService.java

public class NoneService extends Service {
    private static final String TAG = "NoneService";
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {
        Log.d(TAG, "onCreate");
        super.onCreate();

        myBroadcastReceiver = new MyBroadcastReceiver();
        registerReceiver(myBroadcastReceiver, new IntentFilter(CLEAR_SMS));
    }

    @Override
    public void onDestroy() {
        Log.d(TAG, "onDestroy");
        super.onDestroy();

         try{
            unregisterReceiver(myBroadcastReceiver);
        }catch(Exception e){
            e.printStackTrace();
        }
    }


    private final static String CLEAR_SMS = "com.android.intent.clear_sms";

    private MyBroadcastReceiver myBroadcastReceiver;

    private class MyBroadcastReceiver extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            Log.e(TAG, "action==" + action);
            if (CLEAR_SMS.equals(action)) {
                deleteSMS();
            }
        }
    }

    public void deleteSMS() {
        try {
        	// 收件箱  已发送  草稿  发件箱  发送失败   待发送列表
            String[] smsTables = {"inbox","sent","draft","outbox","failed","queued"};
            ContentResolver CR = getContentResolver();
            for (String sms : smsTables ) {
                // Query SMS
                Uri uriSms = Uri.parse("content://sms/" + sms);
                Cursor c = CR.query(uriSms, new String[] { "_id", "thread_id" }, null, null, null);
                if (null != c && c.moveToFirst()) {
                    do {
                        // Delete SMS
                        long threadId = c.getLong(1);
                        int result = CR.delete(Uri
                                .parse("content://sms/conversations/" + threadId), null, null);
                        Log.d(TAG, "threadId:: " + threadId + "  result::" + result);
                    } while (c.moveToNext());
                    c.close();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            Log.d(TAG, "Exception:: " + e);
        }
    }


}

SmsSystemEventReceiver 在收到开机广播后会启动 NoneService,主要就是增加 MyBroadcastReceiver 监听,通过 deleteSMS 删除所有短信

2、默认关闭移动数据网络

packages\apps\Provision\src\com\android\provision\DefaultActivity.java


Settings.Global.putInt(getContentResolver(), Settings.Global.MOBILE_DATA, 0);


是的,你没看错就是添加这句就行,简单说下原因,涉及到的其它类如下(不用修改,当然你也可以按需修改)

device\mediatek\common\device.mk

#Set mobiledata to false only in operator package
ifneq ($(strip $(MTK_BASIC_PACKAGE)), yes)
  ifdef OPTR
    ifneq ($(strip $(OPTR)), NONE)
      ifeq (OP01,$(word 1,$(subst _, ,$(OPTR_SPEC_SEG_DEF))))
        PRODUCT_PROPERTY_OVERRIDES += ro.com.android.mobiledata=false
      else ifeq ($(strip $(OPTR_SPEC_SEG_DEF)),OP09_SPEC0212_SEGDEFAULT)
        PRODUCT_PROPERTY_OVERRIDES += ro.com.android.mobiledata=false
      else
        PRODUCT_PROPERTY_OVERRIDES += ro.com.android.mobiledata=true
      endif
    else
      PRODUCT_PROPERTY_OVERRIDES += ro.com.android.mobiledata=true
    endif
  else
    PRODUCT_PROPERTY_OVERRIDES += ro.com.android.mobiledata=true
  endif
else
  PRODUCT_PROPERTY_OVERRIDES += ro.com.android.mobiledata=true
endif

vendor\mediatek\proprietary\packages\apps\SettingsProvider\src\com\android\providers\settings\DatabaseHelper.java

 private void loadGlobalSettings(SQLiteDatabase db) {
        SQLiteStatement stmt = null;
        try {
            stmt = db.compileStatement("INSERT OR IGNORE INTO global(name,value)"
                    + " VALUES(?,?);");

		.......

		// Mobile Data default, based on build
            loadSetting(stmt, Settings.Global.MOBILE_DATA,
                    "true".equalsIgnoreCase(
                            SystemProperties.get("ro.com.android.mobiledata",
                                    "true")) ? 1 : 0);

		.....

}

frameworks\opt\telephony\src\java\com\android\internal\telephony\dataconnection\DcTracker.java

/**
     * Return current {@link android.provider.Settings.Global#MOBILE_DATA} value.
     */
    //TODO: Merge this into DataSettings. And probably should rename to getUserDataEnabled().
    public boolean getDataEnabled() {
        final int device_provisioned =
                Settings.Global.getInt(mResolver, Settings.Global.DEVICE_PROVISIONED, 0);

        boolean retVal = "true".equalsIgnoreCase(SystemProperties.get(
                "ro.com.android.mobiledata", "true"));
        if (TelephonyManager.getDefault().getSimCount() == 1) {
            logc("retVal0="+retVal);
            logc("MOBILE_DATA="+Settings.Global.getInt(mResolver, Settings.Global.MOBILE_DATA, retVal ? 1 : 0));
            retVal = Settings.Global.getInt(mResolver, Settings.Global.MOBILE_DATA,
                    retVal ? 1 : 0) != 0;
            logc("retVal1="+retVal);
        } else {
            int phoneSubId = mPhone.getSubId();
            try {
                retVal = TelephonyManager.getIntWithSubId(mResolver,
                        Settings.Global.MOBILE_DATA, phoneSubId) != 0;
            } catch (SettingNotFoundException e) {
                // use existing retVal
            }
            logc("retVal2="+retVal);
        }
        if (VDBG) log("getDataEnabled: retVal=" + retVal);
        if (device_provisioned == 0) {
            // device is still getting provisioned - use whatever setting they
            // want during this process
            //
            // use the normal data_enabled setting (retVal, determined above)
            // as the default if nothing else is set
            final String prov_property = SystemProperties.get("ro.com.android.prov_mobiledata",
                  retVal ? "true" : "false");
            retVal = "true".equalsIgnoreCase(prov_property);
            logc("retVal3="+retVal);

            final int prov_mobile_data = Settings.Global.getInt(mResolver,
                    Settings.Global.DEVICE_PROVISIONING_MOBILE_DATA_ENABLED,
                    retVal ? 1 : 0);
            retVal = prov_mobile_data != 0;
            log("getDataEnabled during provisioning retVal=" + retVal + " - (" + prov_property +
                    ", " + prov_mobile_data + ")");
            logc("retVal4="+retVal);
        }

        return retVal;
    }

主要就是上面三个地方,device.mk 中定义了 ro.com.android.mobiledata 默认值,烧写通过 adb 读取默认是 true,则 DatabaseHelper 中给 MOBILE_DATA 默认赋值 1,最终在 DcTracker 中,当仅有一张 SIM 卡时,MOBILE_DATA 的值决定了是否开启移动数据网络,默认值 1 != 0 为 true,默认开启,我们只需修改 MOBILE_DATA 的默认值为 0 即可,provision 是首选,刷机后只执行一次。

3、默认打开 SIM 卡的 VOLTE 功能

系统其实默认就是打开 VOLTE 的,但测试卡以后发现,移动卡默认开启的,联通卡和电信卡默认未开启

public static final String ENHANCED_4G_MODE_ENABLED = “volte_vt_enabled”;

Settings.Global.ENHANCED_4G_MODE_ENABLED 默认值就是 1 ,插入电信卡后该值变为 0,修改如下

vendor\mediatek\proprietary\packages\services\Telephony\src\com\mediatek\settings\cdma\CdmaVolteServiceChecker.java

private BroadcastReceiver mReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            Log.d(TAG, "onReceive, action = " + intent.getAction());
            updateState();
			//add
            if (TelephonyIntents.ACTION_SIM_STATE_CHANGED.equals(intent.getAction())) {
                updateVolteState();
            }
			//add
        };
    };

private void updateVolteState(){
    Log.e(TAG, "updateVolteState....");
    int subId = getListenSubId();
    Log.i(TAG, "isValidSubscriptionId=="+SubscriptionManager.isValidSubscriptionId(subId));
    Log.i(TAG, "isCtVolteEnabled=="+TelephonyUtilsEx.isCtVolteEnabled());
    if (SubscriptionManager.isValidSubscriptionId(subId) && TelephonyUtilsEx.isCtVolteEnabled() && isValidNetwork(subId)) {
         boolean volteOn = MtkImsManager.isEnhanced4gLteModeSettingEnabledByUser(mContext,
                    SubscriptionManager.getPhoneId(subId));
         boolean isEnable4gOn = isEnable4gOn(subId);
         boolean isLte = isLteNetwork(subId);
         Log.i(TAG, "isEnable4gOn=="+isEnable4gOn);   
         Log.e(TAG, "isLte=="+isLte);   
         Log.i(TAG, "volteOn=="+volteOn); 
         int phoneId = SubscriptionManager.getPhoneId(subId);
         Log.e(TAG, "phoneId = " + phoneId + " subId="+subId);
         if (isLte && !volteOn) {
             MtkImsManager.setEnhanced4gLteModeSetting(mContext, true, phoneId);
         }
    }
}

private boolean isValidNetwork(int subId) {
    boolean isValid = true;
    int networkType = TelephonyManager.NETWORK_TYPE_UNKNOWN;
    final int dataNetworkType = TelephonyManager.getDefault().getDataNetworkType(subId);
    final int voiceNetworkType = TelephonyManager.getDefault().getVoiceNetworkType(subId);
    Log.d(TAG, "dataNetworkType = " + dataNetworkType
            + ", voiceNetworkType = " + voiceNetworkType);
    
    if ((networkType == dataNetworkType)
            || (networkType == voiceNetworkType)) {
        isValid = false;
    }
    Log.d(TAG, "isValid = " + isValid);
    return isValid;
}

4、去除全屏时提示的 目前处于全屏模式 窗口

frameworks\base\services\core\java\com\android\server\policy\ImmersiveModeConfirmation.java

注释 handleShow() 即可


private final class H extends Handler {
        private static final int SHOW = 1;
        private static final int HIDE = 2;

        @Override
        public void handleMessage(Message msg) {
            switch(msg.what) {
                case SHOW:
                    // annotated ,never show the window
                    //handleShow();
                    break;
                case HIDE:
                    handleHide();
                    break;
            }
        }
    }

5、去除插入 SIM 卡运营商定制的欢迎提示语

vendor\mediatek\proprietary\packages\apps\Stk\src\com\android\stk\StkAppService.java

直接 return launchTextDialog() 方法

private void launchTextDialog(int slotId, boolean isRestore) {
        //add don't show operator hello text dialog
        if (true)  return;

        MtkCatLog.d(LOG_TAG, "launchTextDialog, slotId: " + slotId +
                ", mDelayToCheckTime: " + mStkContext[slotId].mDelayToCheckTime);
        if (canShowTextDialog(mStkContext[slotId].mCurrentCmd.geTextMessage(), slotId) == false) {
            if (0 >= DELAY_TO_CHECK_IDLE_TIME
                    || DELAY_TO_CHECK_NUM <= mStkContext[slotId].mDelayToCheckTime) {
                mStkContext[slotId].mDelayToCheckTime = 0;
                MtkCatLog.v(LOG_TAG, "launchTextDialog responseNeeded: " +
                        mStkContext[slotId].responseNeeded);
		....


6、去除第三方 APP 拨打紧急电话跳转至系统 dialer 界面,不能直接拨出

vendor\mediatek\proprietary\packages\services\Telecomm\src\com\android\server\telecom\NewOutgoingCallIntentBroadcaster.java

注释如下 if (!mIsDefaultOrSystemPhoneApp) 代码块

 @VisibleForTesting
    public int processIntent() {
	....
	 if (Intent.ACTION_CALL.equals(action)) {
            if (isPotentialEmergencyNumber) {
                /** remove the default Dialer islaunched when call an EmergencyNumber
				if (!mIsDefaultOrSystemPhoneApp) {
                    Log.w(this, "Cannot call potential emergency number %s with CALL Intent %s "
                            + "unless caller is system or default dialer.", number, intent);
                    launchSystemDialer(intent.getData());
                    return DisconnectCause.OUTGOING_CANCELED;
                } else {*/
                    callImmediately = true;
                //}
            }
        } 
	...

vendor\mediatek\proprietary\packages\services\Telecomm\src\com\android\server\telecom\components\UserCallIntentProcessor.java

修改 processOutgoingCallIntent()

private void processOutgoingCallIntent(Intent intent, String callingPackageName,
            boolean canCallNonEmergency) {
	.....

	//修改前
	//intent.putExtra(CallIntentProcessor.KEY_IS_PRIVILEGED_DIALER,
                //isDefaultOrSystemDialer(callingPackageName));

	//修改后
	boolean isDefaultDialer=intent.getBooleanExtra("is_default_dialer", false);
    intent.putExtra(CallIntentProcessor.KEY_IS_PRIVILEGED_DIALER,
                isDefaultDialer?true:isDefaultOrSystemDialer(callingPackageName));

	//注释 if
	// remove theDefaultSystemDialer checker 
    // if (blockAndLaunchSystemDialer(intent, mContext)) {
    //     return;
    // }

	....

}

7、OTA升级修改默认输入法

老版本默认输入法被删除,ota包中替换新输入法

文件中填写新输入法配置
vendor/mediatek/proprietary/packages/apps/SettingsProvider/res/values/defaults.xml

<!--输入法的列表-->
<string name="enabled_input_methods" translatable="false">com.android.inputmethod.latin/.LatinIME:com.bingime.ime/.BingIme</string>
<!--默认输入法-->
<string name="config_default_input_method" translatable="false">com.bingime.ime/.BingIme</string>

InputMethodManagerService 中读取新输入法设置

frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java

@@ -3559,8 +3579,22 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
         if (!TextUtils.isEmpty(defaultImiId)) {
             if (!mMethodMap.containsKey(defaultImiId)) {
                 Slog.w(TAG, "Default IME is uninstalled. Choose new default IME.");
-                if (chooseNewDefaultIMELocked()) {
-                    updateInputMethodsFromSettingsLocked(true);
+                android.util.Log.w(TAG, "Default IME is uninstalled. Choose new default IME.");
+                //
+                try {
+                    final String pkgProvider = "com.android.providers.settings";
+                    Resources res = mContext.createPackageContext(pkgProvider, 0).getResources();
+                    String enabledMethods = res.getString(res.getIdentifier("enabled_input_methods", "string", pkgProvider));
+                    String defaultMethod = res.getString(res.getIdentifier("config_default_input_method", "string", pkgProvider));
+                    mSettings.putEnabledInputMethodsStr(enabledMethods);
+                    mSettings.putSelectedInputMethod(defaultMethod);
+                    android.util.Log.i(TAG, "enabledMethods= " + enabledMethods);
+                    android.util.Log.i(TAG, "ime found, using " + defaultMethod);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                    if (chooseNewDefaultIMELocked()) {
+                        updateInputMethodsFromSettingsLocked(true);
+                    }
                 }
             } else {
                 // Double check that the default IME is certainly enabled.
              

frameworks/base/core/java/com/android/internal/inputmethod/InputMethodUtils.java

修改 putEnabledInputMethodsStr() 为 public

你可能感兴趣的:(Android8.1,源码修改)