2011-07-27 47 views
1

我創建了一個安全應用程序,就像Mcafee wave secure一樣。
我的應用程序正在偵聽SMS命令並在命令匹配時執行一些操作,因此我使用另一個服務創建了一個表單來偵聽SMS。如何在Android中創建無法被高級任務殺死的服務殺手

這裏的主要形式有:

public static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED"; 
ArrayList<String> messageList; 
ArrayAdapter< String> adapter; 


@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    //untuk mendisable notification area 
    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
          WindowManager.LayoutParams.FLAG_FULLSCREEN); 

    setContentView(R.layout.main); 
    MainButtonAbout=(Button) findViewById(R.id.MainbuttonAbout); 
    MainButtonHelp=(Button) findViewById(R.id.MainbuttonHelp); 
    MainButtonWizard=(Button) findViewById(R.id.MainbuttonWizard); 
    MainButtonOption=(Button) findViewById(R.id.MainbuttonOption); 
    MainCheckBoxActive=(CheckBox)findViewById(R.id.MaincheckBoxActive); 

    MainButtonAbout.setOnClickListener(this); 
    MainButtonHelp.setOnClickListener(this); 
    MainButtonWizard.setOnClickListener(this); 
    MainButtonOption.setOnClickListener(this); 

    startService(new Intent(MainForm.this, ListenSMSservice.class)); 

    MainCheckBoxActive.setOnCheckedChangeListener(new OnCheckedChangeListener() { 
     public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 
      // TODO Auto-generated method stub 
      if (buttonView.isChecked()) 
      { 
       Toast.makeText(MainForm.this, "Your Device is Protected Now!!", 1).show();    
       startService(new Intent(MainForm.this, ListenSMSservice.class)); 
      } 
      else 
      { 
       Toast.makeText(MainForm.this, "Your Device is not Protected Now!!", 1).show(); 
       stopService(new Intent(MainForm.this, ListenSMSservice.class)); 
      } 
     } 
    }); 

} 

public void onClick(View v) { 
    // TODO Auto-generated method stub 
    switch (v.getId()) { 
    case R.id.MainbuttonAbout: 
     Intent GoToAbout= new Intent(this,AboutForm.class); 
     startActivity(GoToAbout); 
     break; 
    case R.id.MainbuttonHelp: 
     Intent GoToHelp= new Intent(this,HelpForm.class); 
     startActivity(GoToHelp); 
     break; 
    case R.id.MainbuttonWizard: 
     Intent GoToWizard1= new Intent(this,WizardForm1.class); 
     startActivity(GoToWizard1); 
     break; 
    case R.id.MainbuttonOption: 
     Intent GoToOption= new Intent(this,OptionForm.class); 
     startActivity(GoToOption); 
     break; 
    default: 
     break; 
    } 
} 

,這是服務形式:

@Override 
public IBinder onBind(Intent intent) { 
    return null; 
} 

@Override 
public void onCreate() { 
    Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show(); 

} 

/*@Override 
public void onStart(Intent intent, int startid) { 
    Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG).show(); 
    ListenSMS(); 
}*/ 

@Override 
public int onStartCommand(Intent intent, int flags, int startId) { 
    ListenSMS(); 
    // We want this service to continue running until it is explicitly 
    // stopped, so return sticky. 
    return START_STICKY; 
} 

private void ListenSMS() { 
    // TODO Auto-generated method stub 
    messageList = new ArrayList<String>(); 
    adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, messageList); 

    //Toast.makeText(this, "Masuk bagian sini sudah", 1).show(); 

    IntentFilter filter = new IntentFilter(SMS_RECEIVED); 
    registerReceiver(receiver_SMS, filter); 
} 

BroadcastReceiver receiver_SMS = new BroadcastReceiver() 
{ 
    public void onReceive(Context context, Intent intent) 
    { 
     if (intent.getAction().equals(SMS_RECEIVED)) 
     { 
       Bundle bundle = intent.getExtras(); 
       if (bundle != null) 
       { 
        Object[] pdus = (Object[]) bundle.get("pdus"); 
        SmsMessage[] messages = new SmsMessage[pdus.length]; 

        for (int i = 0; i < pdus.length; i++) 
        messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]); 

        for (SmsMessage message : messages) 
        { 
         Toast.makeText(ListenSMSservice.this, "isi pesan >> "+message.getDisplayMessageBody(), Toast.LENGTH_LONG).show(); 
         receivedMessage(message.getDisplayOriginatingAddress()); 
         if (message.getDisplayMessageBody().toString().equalsIgnoreCase("aaaa")) 
         { 
          Toast.makeText(ListenSMSservice.this, "messegenya aaaa", 1).show(); 
         } 
        } 
       } 
       } 
    } 
}; 
private void receivedMessage(String message) 
{ 
    messageList.add(message); 
    adapter.notifyDataSetChanged(); 
} 

@Override 
public void onDestroy() { 
    Toast.makeText(this, "My Service Stopped", Toast.LENGTH_LONG).show(); 
} 

不幸的是,我的服務可以通過高級任務的殺手被停止,所以我不能監聽SMS命令。

我正在使用start_sticky選項,但它不適用於我。
有沒有人有一個想法如何處理這個問題,所以我可以聽SMS(自動啓動服務),即使當任務殺手被用來殺死我的應用程序?

+6

如果用戶通過第三方工具或設置菜單強制停止您的應用程序,那麼他們希望它停止。 –

+0

是的,當然..但我做了一個安全應用程序。如果設備被盜或丟失,我的應用程序應該可以正常工作。我的應用程序可以鎖定android設備,使小偷無法訪問手機。如果我的服務可以停止,如何防止丟失的電話被竊賊訪問?任何解決方案謝謝.. –

+2

您聲稱正在製作「安全服務」。您正在創建惡意軟件的可能性很大,因爲惡意軟件可能具有您描述的功能。 Android捍衛用戶抵禦惡意軟件的能力,這意味着它會爲用戶抵禦「安全服務」。有更好的解決方案來保護用戶免遭丟失/被盜/佔用的手機(例如整盤加密),這些手機是(或可能)是操作系統的一部分。 – CommonsWare

回答

10

任何人都知道如何處理這個問題將開始您的應用程序,這樣我就可以聽SMS(自動啓動的服務),而任務殺手已經殺死我的應用程序

如果用戶強制通過設置或任務殺手程序停止您的應用程序,用戶說你的應用程序不應該運行。請尊重並尊重該決定。

從Android 3.1開始,您的應用程序在強制停止後不會再運行,直到用戶再次從活動啓動它。

+0

**「如果用戶通過設置或任務殺手強制停止您的應用程序,用戶說您的應用程序不應該運行,請尊重並尊重該決定。」** >>我製作一個安全應用程序可以鎖定一個android手機,當它丟失或被盜,所以小偷不能訪問該手機..如果我的應用程序可以停止,那麼我怎麼可以安全的android手機?任何解決方案 –

+0

@CommonsWare你可以請添加來自android網站的鏈接引用:「從Android 3.1開始,你的應用程序在被強制停止後不會再運行,直到用戶從一個活動再次啓動它」 – NguyenDat

+0

http://commonsware.com /blog/2011/07/13/boot-completed-regression-confirmed.html – CommonsWare

4

註冊清單中的一個<reciver>,當你收到短信

<receiver android:name=".YourBroadCastReciver" android:enabled="true"> 
    <intent-filter> 
    <action android:name="android.provider.Telephony.SMS_RECEIVED" /> 
    </intent-filter> 
</receiver> 
+4

從Android 3.1開始,這無助於OP的問題。在用戶啓動活動之前,強制停止的應用程序不會響應廣播。 – CommonsWare

+0

@CommonsWare活動第一次啓動後,廣播將被正常接收? – opc0de

+0

@ opc0de:是的,除非用戶進入設置並點擊應用程序的「強制停止」。然後,您將回到與首次安裝應用程序時相同的狀態。 – CommonsWare