来电阻止代码在实际设备中不起作用

时间:2011-03-26 11:50:09

标签: android

我使用以下代码进行来电阻止 How to reject incoming call programatically in android?
呼叫编程功能于机器人

它完全适用于模拟器但不适用于真实设备请给mw一些解决方案 这是谷歌要求的任何许可。 和telephonyService.endCall()也无法正常工作。

package com.android.MyCellFamily.DAReceiver;
import java.lang.reflect.Method;
import com.android.MyCellFamily.DAService.LocationService;
import com.android.MyCellFamily.DB.ClsDataBaseUtils;
import com.android.internal.telephony.ITelephony;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.Toast;

public class ClsIncomingCallBlocker_DAReceiver extends BroadcastReceiver {
    ClsDataBaseUtils dts=new ClsDataBaseUtils();
    String clsincommingNumber;

    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub

        try
        {

            dts.createDatabse("MyCellFamily",context);
            dts.createTable("tbl_Contacts", context); 
            dts.createBlockedStatusTable("tbl_BlockedContacts", context);

            MyPhoneStateListener myPhoneStateListener = new MyPhoneStateListener();
            ((TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE)).listen(myPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
            TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
            Class c = Class.forName(tm.getClass().getName());
            Method m = c.getDeclaredMethod("getITelephony");
            m.setAccessible(true);
            com.android.internal.telephony.ITelephony telephonyService =(ITelephony)m.invoke(tm);


            Bundle b = intent.getExtras();
            clsincommingNumber = b.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
            Log.d("clsincommingNumber",clsincommingNumber);
            if(dts.checkPreffContactsFrInCall("tbl_Contacts", clsincommingNumber).equals("true"))
            {
            //Answer Ringing Call
            telephonyService.answerRingingCall();
            dts.close();    
            }   
            else if(dts.checkBlockedStatusFrInCall("tbl_BlockedContacts", clsincommingNumber).equals("true"))
            {
            System.out.println("Incoming blocker"+dts.checkBlockedStatusFrInCall("tbl_BlockedContacts", clsincommingNumber));
            //block incoming call
            telephonyService.endCall();
            dts.close();
            }
            else if(LocationService.getStatusOfDriving().equals("block"))
            {
            System.out.println("Your Status Of Driving is"+LocationService.getStatusOfDriving().toString());
            telephonyService.endCall();
            this.setResultData(null);
            }   
            else
            {
            //Answer Ringing Call
            telephonyService.answerRingingCall();
            dts.close();
            }   

        }
        catch(Exception e)
        {

        }
    }
}

1 个答案:

答案 0 :(得分:1)

如果Android(或任何其他手机操作系统)正式支持程序化呼叫阻止,我会感到非常惊讶。你试图这样做的代码基本上是一个hack(它使用反射来抓取和调用私有API方法,这是一个巧妙的技巧但很脆弱),并且不能保证工作。

事实上,我完全希望谷歌在未来的Android更新中刻意破解这些代码,如果还没有的话。他们所要做的就是将getITelephony()重构为somethingThatSoundsLessLikeAnObviousExploitPoint(),然后添加一个不执行任何操作的存根getITelephony()方法(或者只是将其删除,让应用程序处理异常或崩溃)。< / p>

所以可能是这个漏洞已经插在你正在测试的设备上,即使它没有,也许只是时间问题才会有一些未来的更新打破每个使用这个黑客的应用程序。您的开发时间可能会更好地用于更新您的应用程序,以便尽可能优雅地处理被电话中断。

相关问题