Ejemplo n.º 1
0
  @Override
  public void onCreate() {
    super.onCreate();
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "My Tag");
    mWakeLock.acquire();
    File logf =
        new File(Environment.getExternalStorageDirectory() + File.separator + "DemoLog.txt");

    try {
      mLogWriter = LogWriter.open(logf.getAbsolutePath());
    } catch (IOException e) {
      // TODO Auto-generatedo catch block
      log(e.getMessage());
    }
    log("onCreate()");
    // 测试杀掉teamview再打开功能
    try {
      Runtime.getRuntime().exec(new String[] {"/system/bin/su", "-c", "ls -al"});
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    if (!isAppInstalled(WatchService.this, paName)) {
      Log.d("DemoLog", "no install");
      ApkController apkController = new ApkController(WatchService.this);
      apkController.install();
      handler.removeMessages(UPDATE_BEGIN_ZHUANGTAI);
      handler.sendEmptyMessage(UPDATE_BEGIN_ZHUANGTAI);
    } else {
      try {
        startTeamView();
      } catch (Exception e) {

      }
    }
    // 亮度调节
    settingUtils = new SettingUtils(WatchService.this);
    settingUtils.setBrightness(0);
  }
Ejemplo n.º 2
0
  @Override
  public void onDestroy() {
    super.onDestroy();
    if (mWakeLock != null) {
      mWakeLock.release();
    }
    if (!TextUtils.isEmpty(mTeamViewData.mIdText) && !TextUtils.isEmpty(mTeamViewData.mPCIDTEXT)) {
      RequestParams params = new RequestParams(UrlData.URL_SHUT_DOWN_OWN);
      params.addBodyParameter("授权用户", UrlData.ADMIN_UID);
      params.addBodyParameter("密码", UrlData.ADMIN_PASSWORD);
      params.addBodyParameter("设备ID", mTeamViewData.mIdText);
      params.addBodyParameter("用户ID", mTeamViewData.mPCIDTEXT);
      log("违例结束   设备ID=" + mTeamViewData.mIdText + "用户id=" + mTeamViewData.mPCIDTEXT);
      x.http()
          .post(
              params,
              new CommonCallback<String>() {
                @Override
                public void onSuccess(String result) {
                  InputStream sbs = new ByteArrayInputStream(result.getBytes());
                  String response = "";
                  try {
                    response = XMLParse.parseResponseCheck(sbs);
                    log("违例结束=" + response);
                  } catch (Exception e) {

                  }
                }

                @Override
                public void onError(Throwable ex, boolean isOnCallback) {
                  log("违例结束   error" + ex.getMessage());
                }

                @Override
                public void onCancelled(CancelledException cex) {}

                @Override
                public void onFinished() {}
              });
    }
    if (handler != null) {
      handler.removeCallbacksAndMessages(null);
    }
    try {
      Process suProcess = Runtime.getRuntime().exec("su");
      DataOutputStream os = new DataOutputStream(suProcess.getOutputStream());
      os.writeBytes("adb shell" + "\n");
      os.flush();
      os.writeBytes("am force-stop " + paName + "\n");
      os.flush();
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      log(e.getMessage());
    }
    if (processWatcher != null) {
      processWatcher.stop();
    }
    if (settingUtils != null) {
      settingUtils.reset();
    }
  }