Android6.0 源码修改之屏蔽系统邮件功能和来电功能

电脑杂谈  发布时间:2019-09-05 06:02:55  来源:网络整理

短信拦截_cc短信拦截_cc短信拦截

android 4.2 短信群发流程剖析可参考这篇 戳这

源码位置 vendor\mediatek\proprietary\packages\apps\Mms\src\com\android\mms\transaction\SmsReceiverService.java

private void handleSmsReceived(Intent intent, int error) {
        //2018-10-09 cczheng  add for intercept mms notifications  start
        if (true) {
            Log.i("SmsReceived", "handleSmsReceived");
            return;
        }
        //2018-10-09 cczheng add for intercept mms notifications  end
        SmsMessage[] msgs = Intents.getMessagesFromIntent(intent);
        /// M:Code analyze 022, check null @{
        if (msgs == null) {
            MmsLog.e(MmsApp.TXN_TAG, "getMessagesFromIntent return null.");
            return;
        }
        MmsLog.d(MmsApp.TXN_TAG, "handleSmsReceived SmsReceiverService");
        /// 
		......
}

在handleSmsReceived()方法中直接return即可,不去解析和分发短信消息,同时这种操作 短信将不会记录到邮件中,插入短信消息到的方式见下文insertMessage()方法。

源码位置同上

private void handleSmsReceived(Intent intent, int error) {
       SmsMessage[] msgs = Intents.getMessagesFromIntent(intent);
        .....
        /// M:Code analyze 024, print log @{
        SmsMessage tmpsms = msgs[0];
        MmsLog.d(MmsApp.TXN_TAG, "handleSmsReceived" + (tmpsms.isReplace() ? "(replace)" : "")
            + " messageUri: " + messageUri
            + ", address: " + tmpsms.getOriginatingAddress()
            + ", body: " + tmpsms.getMessageBody());
        /// @
		//2018-10-09 cczheng add for intercept mms notifications  start
        if ("10010".equals(tmpsms.getOriginatingAddress()) || "话费".contains(tmpsms.getMessageBody())) {
            Log.i("SmsReceived", "handleSmsReceived");
            return;
        }
        //2018-10-09 cczheng  add for intercept mms notifications  end
		....
}

cc短信拦截_短信拦截_cc短信拦截

是否插入短信消息到,insertMessage()方法在handleSmsReceived()中调用

private Uri insertMessage(Context context, SmsMessage[] msgs, int error, String format) {
       // Build the helper classes to parse the messages.
       if (msgs == null) {
           MmsLog.e(MmsApp.TXN_TAG, "insertMessage:getMessagesFromIntent return null.");
           return null;
       }
       /// @}
       SmsMessage sms = msgs[0];
       if (sms.getMessageClass() == SmsMessage.MessageClass.CLASS_0) {
           MmsLog.d(MmsApp.TXN_TAG, "insertMessage: display class 0 message!");
           displayClassZeroMessage(context, msgs, format);
           return null;
       } else if (sms.isReplace()) {
           MmsLog.d(MmsApp.TXN_TAG, "insertMessage: is replace message!");
           return replaceMessage(context, msgs, error);
       } else {
           MmsLog.d(MmsApp.TXN_TAG, "insertMessage: stored directly!");
           return storeMessage(context, msgs, error);
       }
   }

需要添加SmsReceiver,MmsReceiver,ComposeSmsActivity,HeadlessSmsSendService这几个类,并在AndroidManifest中进行相应配置,具体步骤可参考这篇 戳这

屏蔽系统来电可分为三个步骤

1.来电静音,不响铃

2.来电挂断,不出现IncallActivity

cc短信拦截_短信拦截_cc短信拦截

3、拦截未接来电通知,不显示在状态栏StatusBar中

ps:此种修改方法的弊病在于来电时网络数据会离线2s左右

好,现在我们起初按这三个步骤来设置源码

源码位置 packages/services/Telecomm/src/com/android/server/telecom/Ringer.java

private void updateRinging(Call call) {
       if (mRingingCalls.isEmpty()) {
           stopRinging(call, "No more ringing calls found");
           stopCallWaiting(call);
       } else {
           //2018-10-10 cczheng add  anotation function startRingingOrCallWaiting() for silent call start
           Log.d("callRinging", "silent call, will not play ringtone");
           // startRingingOrCallWaiting(call);
           //2018-10-10 cczheng add  anotation function startRingingOrCallWaiting() for silent call end
       }
   }

是的,注释掉startRingingOrCallWaiting(call);方法就ok啦

cc短信拦截_cc短信拦截_短信拦截

思路:PhoneStatecc短信拦截,当到响铃时,直接借助反射调用endcall方法挂断电话。PhoneStateListener可以提到广播中,当收到开机广播时,开始phoneState,这样和平台保持同步。以下是参考代码

public class PhoneStartReceiver extends BroadcastReceiver {
	private static final String TAG = "PhoneStartReceiver";
	private PhoneCallListener mPhoneCallListener;
    private TelephonyManager mTelephonyManager;
	@Override
	public void onReceive(final Context context, final Intent intent) {
		String action = intent.getAction();
		if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
			// endCall when CALL_STATE_RINGING
			initPhoneCallListener(context);
		} 
	}
	private void initPhoneCallListener(Context context){
		mPhoneCallListener = new PhoneCallListener();
        mTelephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
        mTelephonyManager.listen(mPhoneCallListener, PhoneCallListener.LISTEN_CALL_STATE);
	}
	public class PhoneCallListener extends PhoneStateListener {
        @Override
        public void onCallStateChanged(int state, String incomingNumber) {
            Log.v(TAG, "onCallStateChanged-state: " + state);
            Log.v(TAG, "onCallStateChanged-incomingNumber: " + incomingNumber);
            switch (state)  {
                case TelephonyManager.CALL_STATE_RINGING:
                     endCall();
                    break;
                default:
                    break;
            }
            super.onCallStateChanged(state, incomingNumber);
        }
    }
	private void endCall() {
        try {
            Method m1 = mTelephonyManager.getClass().getDeclaredMethod("getITelephony");
            if (m1 != null) {
                m1.setAccessible(true);
                Object iTelephony = m1.invoke(mTelephonyManager);
                if (iTelephony != null) {
                    Method m2 = iTelephony.getClass().getDeclaredMethod("silenceRinger");
                    if (m2 != null) {
                        m2.invoke(iTelephony);
                        Log.v(TAG, "silenceRinger......");
                    }
                    Method m3 = iTelephony.getClass().getDeclaredMethod("endCall");
                    if (m3 != null) {
                        m3.invoke(iTelephony);
                        Log.v(TAG, "endCall......");
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            Log.e(TAG, "endCallError", e);
        }
    }
}


本文来自电脑杂谈,转载请注明本文网址:
http://xinshanjie.com/a/tongxinshuyu/article-121760-1.html

相关阅读
发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

  • 李炳晓
    李炳晓

    你信不信到时候美国会毫不犹豫的第三次揍你

  • 陶素耜
    陶素耜

    更惶论与倭相较了

  • 张南
    张南

    表明美国的死党已经不听他的话了

热点图片
拼命载入中...