测试系统接口

、、、、、、、、、、、、、、、、、、、、、
interface ILianjiaoService{
boolean startCommunication();
boolean stopCommunication();
boolean setProfileModel(int mode);
int getProfileModel();
boolean closeBottomTaskBar();
boolean openBottomTaskBar();
boolean setStatusBarDisable(int state);
boolean shutdownSystem();
boolean installApplication(String packageName, boolean paramBoolean);
boolean uninstallApplication(String packageName);
boolean addUrl(String url);
boolean deleteUrl(String url);
boolean openBackups();
boolean closeBackups();
}

、、、、、、、、、、、、、、、、、、、、、

package com.hp.testlianjian;

import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import android.app.Activity;
import android.app.ActivityManager;
import android.app.ILianjiaoService;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.IServiceManager;
import android.os.Message;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.ServiceManagerNative;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.android.internal.os.BinderInternal;

public class MainActivity extends Activity {

private static final String TAG = "LianJian";
public TextView hideAllKey;
public TextView hideHomeTask;
public TextView showAllkEY;
public TextView shutdown;
public TextView silence;
public TextView noSilence;
public TextView notifyTextView;
public TextView installApkTextView, disablePowerTextView,enablePowerTextView;
public TextView uninstallApkTextView, addUrlTextView, deleteUrlTextView;
public TextView openBackupsTextView,closeBackupsTextview;
public EditText urlEditText;
public ActivityManager mActivityManager;

  private static IServiceManager sServiceManager;
  private static HashMap<String, IBinder> sCache = new HashMap();

  private static IServiceManager getIServiceManager()
  {
    if (sServiceManager != null) {
      return sServiceManager;
    }
    sServiceManager = ServiceManagerNative.asInterface(BinderInternal.getContextObject());
    return sServiceManager;
  }

  public static IBinder getService(String name)
  {
    try
    {
      IBinder service = (IBinder)sCache.get(name);
      if (service != null) {
        return service;
      }
      return getIServiceManager().getService(name);
    }
    catch (RemoteException e)
    {
      Log.e("ServiceManager", "error in getService", e);
    }
    return null;
  }

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mActivityManager = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);

    IBinder b = ServiceManager.getService("LianjiaoService");
    final ILianjiaoService service = ILianjiaoService.Stub.asInterface(b);

    hideAllKey = (TextView) findViewById(R.id.textView1);
    hideHomeTask = (TextView) findViewById(R.id.textView2);
    showAllkEY = (TextView) findViewById(R.id.textView3);
    shutdown = (TextView) findViewById(R.id.shutdown);
    silence = (TextView) findViewById(R.id.silence);
    noSilence = (TextView) findViewById(R.id.noSilence);
    notifyTextView = (TextView) findViewById(R.id.notifyTextView);
    installApkTextView = (TextView) findViewById(R.id.installApkTextView);
    uninstallApkTextView = (TextView) findViewById(R.id.unInstallApkTextView);
    addUrlTextView = (TextView) findViewById(R.id.addUrlTextView);
    deleteUrlTextView = (TextView) findViewById(R.id.deleteUrlTextView);
    disablePowerTextView = (TextView) findViewById(R.id.disablePowerTextView);
    enablePowerTextView = (TextView) findViewById(R.id.enablePowerTextView);
    urlEditText = (EditText) findViewById(R.id.urlEditText);
    openBackupsTextView = (TextView) findViewById(R.id.openBackupsTextview);
    closeBackupsTextview = (TextView) findViewById(R.id.closeBackupsTextview);

    hideAllKey.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            try {
                service.closeBottomTaskBar();
                Toast.makeText(MainActivity.this, hideAllKey.getText(), Toast.LENGTH_SHORT).show();
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        }
    });
    hideHomeTask.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            try {
                service.setStatusBarDisable(1);
                Toast.makeText(MainActivity.this, hideHomeTask.getText(), Toast.LENGTH_SHORT).show();
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        }
    });
    showAllkEY.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            try {
                service.setStatusBarDisable(0);
                Toast.makeText(MainActivity.this, showAllkEY.getText(), Toast.LENGTH_SHORT).show();
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        }
    });
    shutdown.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            try {
                service.shutdownSystem();
                Toast.makeText(MainActivity.this, shutdown.getText(), Toast.LENGTH_SHORT).show();
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        }
    });
    silence.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            try {
                service.setProfileModel(1);
                Toast.makeText(MainActivity.this, silence.getText(), Toast.LENGTH_SHORT).show();
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        }
    });
    noSilence.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            try {
                service.setProfileModel(0);
                Toast.makeText(MainActivity.this, noSilence.getText(), Toast.LENGTH_SHORT).show();
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        }
    });

    notifyTextView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            buildNotify();
            Intent intent = new Intent("android.intent.action.disableSendSms");
            sendBroadcast(intent);
            Toast.makeText(MainActivity.this, notifyTextView.getText(), Toast.LENGTH_SHORT).show();

        }
    });

    installApkTextView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            String filePath = "/mnt/sdcard/DraftPaper.apk";
            boolean result = false;
            try {
                result = service.installApplication(filePath, true);
            } catch (RemoteException e) {
                e.printStackTrace();
            }

            Toast.makeText(MainActivity.this, result ? "安装成功" : "安装失败", Toast.LENGTH_SHORT).show();
        }
    });

    uninstallApkTextView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            String packageName = "com.hp.draftpaper";
            boolean result = false;
            try {
                result = service.uninstallApplication(packageName);
            } catch (RemoteException e) {
                e.printStackTrace();
            }

            Toast.makeText(MainActivity.this, result ? "卸载成功" : "卸载失败", Toast.LENGTH_SHORT).show();
        }
    });

    addUrlTextView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            String url = urlEditText.getText().toString();
            boolean result = false;
            try {
                result = service.addUrl(url);
            } catch (RemoteException e) {
                e.printStackTrace();
            }

            // Intent intent = new Intent("com.hp.intent.action.addUrl");
            // intent.putExtra("url", url);
            // intent.putExtra("isBindBrowser", true);
            // sendBroadcast(intent);
            Toast.makeText(MainActivity.this, result ? "添加成功" : "添加失败", Toast.LENGTH_SHORT).show();
        }
    });

    deleteUrlTextView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            String url = urlEditText.getText().toString();
            boolean result = false;
            try {
                result = service.deleteUrl(url);
            } catch (RemoteException e) {
                e.printStackTrace();
            }
            // Intent intent = new Intent("com.hp.intent.action.deleteUrl");
            // intent.putExtra("url", url);
            // intent.putExtra("isBindBrowser", true);
            // sendBroadcast(intent);
            Toast.makeText(MainActivity.this, result ? "删除成功" : "删除失败", Toast.LENGTH_SHORT).show();
        }
    });

    disablePowerTextView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            ClassMonitorControl.getInstance(MainActivity.this).setPowerKeyStatus(false);
            Toast.makeText(MainActivity.this, "屏蔽POWER键", Toast.LENGTH_SHORT).show();
        }
    });

    enablePowerTextView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            ClassMonitorControl.getInstance(MainActivity.this).setPowerKeyStatus(true);
            Toast.makeText(MainActivity.this, "还原POWER键", Toast.LENGTH_SHORT).show();
        }
    });

    openBackupsTextView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                service.openBackups();
            } catch (RemoteException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            Toast.makeText(MainActivity.this, "openBackupsTextView", Toast.LENGTH_SHORT).show();
        }
    });

    closeBackupsTextview.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                service.closeBackups();
            } catch (RemoteException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            Toast.makeText(MainActivity.this, "closeBackupsTextView", Toast.LENGTH_SHORT).show();
        }
    });
}

public PendingIntent getDefalutIntent(int flags) {
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 1, new Intent(), flags);
    return pendingIntent;
}

protected void buildNotify() {
    // 消息通知栏
    // 定义NotificationManager
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);

    Notification.Builder mBuilder = new Notification.Builder(this);
    mBuilder.setContentTitle("测试标题")
            // 设置通知栏标题
            .setContentText("测试内容").setContentIntent(getDefalutIntent(Notification.FLAG_AUTO_CANCEL))
            .setTicker("测试通知来啦")
            // 通知首次出现在通知栏,带上升动画效果的
            .setWhen(System.currentTimeMillis())
            // 通知产生的时间,会在通知信息里显示,一般是系统获取到的时间
            .setPriority(Notification.PRIORITY_DEFAULT)
            // 设置该通知优先级
            .setOngoing(false).setDefaults(Notification.DEFAULT_VIBRATE)
            .setSmallIcon(android.R.drawable.stat_notify_chat);// 设置通知小ICON
    // .setSmallIcon(android.R.drawable.stat_sys_phone_call);//设置通知小ICON
    mNotificationManager.notify(100, mBuilder.build());
    Toast.makeText(this, "buildNotify", Toast.LENGTH_SHORT).show();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}


///
Handler mHandler = new Handler(){
    @Override
    public void handleMessage(Message msg) {
        super.handleMessage(msg);
    }
};

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值