Пример #1
0
  SWErrorHandler(String string, String string_0_) throws IOException {

    if (string.equals("CLI_ERROR")) {

      Notify notify = new Notify(string_0_);

      try {
        notify.send();
      } catch (IOException ioexception) {
        ioexception.printStackTrace();
      }
    }

    if (string.equals("SECURITY_EMERGENCY")) {

      Notify notify = new Notify(string_0_);

      try {
        notify.send();
        System.out.println("SECURITY_EMERGENCY: " + string);
      } catch (IOException ioexception) {
        ioexception.printStackTrace();
      }
      System.exit(0);
    }
  }
Пример #2
0
 /**
  * Rigorous Test :-)
  *
  * @throws IOException
  */
 @Test
 public void testInstanceProp() throws IOException {
   App app = App.instance();
   Notify notify = app.getNotify("/notify/test");
   notify.replaceProperty("a".getBytes(), "I Love it.".getBytes());
   byte[] v = notify.getProperty("a".getBytes());
   System.out.println(new String(v));
 }
  /** @see org.eclipse.paho.client.mqttv3.MqttCallback#connectionLost(java.lang.Throwable) */
  @Override
  public void connectionLost(Throwable cause) {

    if (cause != null) {
      Notify.toast(context, "Connection Lost", Toast.LENGTH_LONG);
    }
  }
Пример #4
0
  /**
   * A publish action has been successfully completed, update connection object associated with the
   * client this action belongs to, then notify the user of success
   */
  private void publish() {

    Connection c = Connection.getInstance();
    String actionTaken = context.getString(R.string.toast_pub_success, (Object[]) additionalArgs);

    Notify.toast(context, actionTaken, Toast.LENGTH_SHORT);
  }
Пример #5
0
  /**
   * A connection action has been successfully completed, update the connection object associated
   * with the client this action belongs to and then notify the user of success.
   */
  private void connect() {

    Connection c = Connection.getInstance();
    c.changeConnectionStatus(Connection.ConnectionStatus.CONNECTED);

    Notify.toast(context, "Connected", Toast.LENGTH_LONG);
  }
  private void setParcelData() {

    try {
      pNotify.notify_active = mNotification.isChecked();
      pNotify.notify_icon = mNotifyIcon.getValue();
      pNotify.led_active = mLed.isChecked();
      pNotify.led_color = mLedColor.getValue();
      pNotify.led_pat = mLedPattern.getValue();
      pNotify.ringer_active = mRinger.isChecked();
      pNotify.ringtone = mRingtone.getRingtone();
      pNotify.ringer_vol = mRingVolume.getVolume();
      pNotify.vibrate_active = mVibrate.isChecked();
      pNotify.vibrate_pat = mVibratePattern.getValue();

      Intent retIntent = new Intent();
      retIntent.putExtra("fac.userdelroot.droidprofiles.Notify", pNotify);
      setResult(RESULT_OK, retIntent);

    } catch (NullPointerException e) {
      if (Log.LOGV) Log.e(TAG + "setParcelData null pointer " + e.getLocalizedMessage().toString());
    }
  }
Пример #7
0
  @Override
  public void viewAccepted(View newView) {
    log.debugf("New view accepted: %s", newView);
    List<org.jgroups.Address> newMembers = newView.getMembers();
    if (newMembers == null || newMembers.isEmpty()) {
      log.debugf("Received null or empty member list from JGroups channel: " + newView);
      return;
    }

    List<Address> oldMembers = members;
    // we need a defensive copy anyway
    members = fromJGroupsAddressList(newMembers);

    // Now that we have a view, figure out if we are the isCoordinator
    coordinator = fromJGroupsAddress(newView.getCreator());
    isCoordinator = coordinator != null && coordinator.equals(getAddress());

    // Wake up any threads that are waiting to know about who the isCoordinator is
    // do it before the notifications, so if a listener throws an exception we can still start
    channelConnectedLatch.countDown();

    // now notify listeners - *after* updating the isCoordinator. - JBCACHE-662
    boolean hasNotifier = notifier != null;
    if (hasNotifier) {
      Notify n;
      if (newView instanceof MergeView) {
        if (log.isInfoEnabled()) log.receivedMergedView(newView);
        n = new NotifyMerge();
      } else {
        if (log.isInfoEnabled()) log.receivedClusterView(newView);
        n = new NotifyViewChange();
      }

      n.emitNotification(oldMembers, newView);
    }
  }
Пример #8
0
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case R.id.offline:
       if (prefs.getBoolean("hideOffline", false)) service.setPreference("hideOffline", false);
       else service.setPreference("hideOffline", true);
       updateMenu();
       updateList();
       break;
     case R.id.status:
       RosterDialogs.changeStatusDialog(this, null, null);
       break;
     case android.R.id.home:
       RosterDialogs.changeStatusDialog(this, null, null);
       break;
     case R.id.add:
       RosterDialogs.addDialog(this, null);
       break;
     case R.id.search:
       menu.removeItem(R.id.chats);
       item.expandActionView();
       break;
     case R.id.bookmarks:
       Intent bIntent = new Intent(this, Bookmarks.class);
       startActivity(bIntent);
       break;
     case R.id.chats:
       ChangeChatDialog.show(this);
       break;
     case R.id.accounts:
       Intent aIntent = new Intent(this, Accounts.class);
       startActivity(aIntent);
       break;
     case R.id.prefs:
       startActivityForResult(new Intent(this, Preferences.class), ACTIVITY_PREFERENCES);
       break;
     case R.id.disco:
       startActivity(new Intent(this, ServiceDiscovery.class));
       break;
     case R.id.notes:
       startActivity(new Intent(this, NotesActivity.class));
       break;
     case R.id.xml:
       startActivity(new Intent(this, XMLConsole.class));
       break;
     case R.id.notify:
       if (prefs.getBoolean("soundDisabled", false)) service.setPreference("soundDisabled", false);
       else service.setPreference("soundDisabled", true);
       updateMenu();
       break;
     case R.id.exit:
       if (prefs.getBoolean("DeleteHistory", false)) {
         getContentResolver().delete(JTalkProvider.CONTENT_URI, null, null);
       }
       Notify.cancelAll(this);
       stopService(new Intent(this, JTalkService.class));
       finish();
       System.exit(0);
       break;
     default:
       return false;
   }
   return true;
 }
 /**
  * @see org.eclipse.paho.client.mqttv3.MqttCallback#messageArrived(java.lang.String,
  *     org.eclipse.paho.client.mqttv3.MqttMessage)
  */
 @Override
 public void messageArrived(String topic, MqttMessage message) throws Exception {
   String msg_payload = new String(message.getPayload());
   String toast_msg = "Message Arrived -> " + topic + " : " + msg_payload;
   Notify.toast(context, toast_msg, Toast.LENGTH_LONG);
 }
Пример #10
0
  /**
   * A subscribe action was unsuccessful, notify user and update client history
   *
   * @param exception This argument is not used
   */
  private void subscribe(Throwable exception) {
    Connection c = Connection.getInstance();
    String action = context.getString(R.string.toast_sub_failed, (Object[]) additionalArgs);

    Notify.toast(context, action, Toast.LENGTH_SHORT);
  }
Пример #11
0
 /**
  * A disconnection action has been successfully completed, update the connection object associated
  * with the client this action belongs to and then notify the user of success.
  */
 private void disconnect() {
   Connection c = Connection.getInstance();
   c.changeConnectionStatus(Connection.ConnectionStatus.DISCONNECTED);
   String actionTaken = context.getString(R.string.toast_disconnected);
   Notify.toast(context, actionTaken, Toast.LENGTH_LONG);
 }
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {

    startAsForeground();
    networkErrorCount = 0;
    retry = true;

    currentDate = new Date();
    Calendar cal = Calendar.getInstance();
    SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss");
    internalCounter = 0;

    if (!isThreadRunning) // thread is not running so start the thread
    {

      counter = 0;
      Log.d(Settings.TAG, "Stats extraction process started.");

      try {
        handler.postDelayed(
            runnable =
                new Runnable() {

                  @Override
                  public void run() {
                    List<Stats> diff = null;
                    try {
                      if (isForeground) {

                        if (android.os.Build.VERSION.SDK_INT
                            <= 19) // below lollipop we need to remove the notification by stop
                                   // foreground and restart the notification
                        {
                          stopForeground(true);
                          updateNotification();
                        } else {
                          stopForeground(false);
                        }
                        isForeground = false;
                      }
                    } catch (Exception ex) {
                      Log.d(Settings.TAG, "Error occurred while stop foreground");
                    }

                    if (compare(currentDate, new Date())
                        != 0) { // this code generates the hash code every midnight.s
                      currentDate = new Date();
                      Log.d(Settings.TAG, "Generating hash code..Date changed");
                      HashGen hashGen = new HashGen();
                      hashGen.getAllAppInfo(context); // creates hashcode file for every app
                    }

                    // scheduler for uploading hashcode
                    File file = new File(Settings.getHashFilePath());

                    boolean isExist = file.exists();
                    // boolean isWifiAvailable = NET.isWifiAvailable(context);

                    // if hash file exist upload it to server..
                    if (isExist
                        && HashFileUploader.isUploading == false
                        && Settings.IS_WIFI_AVAILABLE
                        && HashGen.isGenerating
                            == false) { // if there is hash file available and wifi is on upload the
                                        // file and delete it.
                      HashFileUploader hfUploader = new HashFileUploader(context);
                      hfUploader
                          .execute(); // this method uploads the hash file to server and delete the
                                      // file from device.
                    }

                    isExist = file.exists(); // make sure file does not exist.

                    Log.d("bu-stats", "Upload Size:" + Settings.UploadSize);
                    Log.d("bu-stats", "isUploading:" + FileUploader.isUploading);
                    Log.d("bu-stats", "IS_WIFI_AVAILABLE:" + Settings.IS_WIFI_AVAILABLE);
                    Log.d("bu-stats", "isExist:" + isExist);
                    Log.d("bu-stats", "IsGenerating Hash Code: " + HashGen.isGenerating);

                    // if hash file is uploaded and does not exist and wifi is available and hash
                    // generation process is not working and uploading of stats file is not working
                    // and current file size has surpass the threshold then upload it.
                    if (StatsFileManager.getFileSize(context) >= Settings.UploadSize
                        && FileUploader.isUploading == false
                        && Settings.IS_WIFI_AVAILABLE
                        && isExist == false
                        && HashGen.isGenerating
                            == false) // if hash file exist, info is not uploaded yet. So wait for
                                      // this file to upload before uploading stats.
                    {
                      Log.d("bu-stats", "Uploading File.");
                      FileUploader fileUploader = new FileUploader(context);
                      fileUploader.execute();
                    }

                    // Log.d("test-test", "FileUploader.IsUploading = " + FileUploader.isUploading);
                    if (!FileUploader
                        .isUploading) // if file is not uploading. (file is not in use) then
                                      // calculate the stats and store it in database.
                    {
                      String data = "";
                      // List<Stats> stepDownStats = null;
                      if (internalCounter == 0) // get the stats for the first time.
                      {
                        oldStats = Stats.getStats(context);
                      } else if (internalCounter > Settings.NetInterval) {
                        newStats = Stats.getStats(context);
                        if (newStats == null || oldStats == null) {
                          // can't read network proc file.
                          Log.e(Settings.TAG, "Unable to read network file. Stopping process");
                        }
                        diff = Stats.NETDifference(oldStats, newStats);

                        /*                                Log.d(Settings.TAG,"New Data..--------------------");
                        for(Stats st: newStats)
                        {
                            Log.d(Settings.TAG, st.getStringData());
                        }*/

                        oldStats = newStats;
                        try {
                          startAsForeground();
                        } catch (Exception ex) {
                          Log.d(Settings.TAG, "Error occurred while starting foreground");
                        }

                        boolean error = false;

                        String networkType = getNetworkType();
                        for (Stats stats : diff) {
                          if (stats.NetStats.error) {
                            error = true;
                          }

                          data = data + stats.getStringData() + "|" + networkType + "\n";
                        }
                        //    Log.d(Settings.TAG,"data without
                        // difference...++++++++++++++++++++++++++++++++++++++++++++++");
                        //  Log.d(Settings.TAG,data);
                        if (error) {
                          networkErrorCount++;
                          // retry for network file...but skip this malformed data...

                          if (networkErrorCount >= 3) {
                            retry = false;
                            forceStop = true;
                            ShowMessage.message("Malformed data. Need to restart phone.", context);
                            Log.d(Settings.TAG, "Malformed network file");
                            Notify.showNotification(
                                context,
                                "Malformed data in system file. Please restart the device to clean the file.");
                            isThreadRunning = false;
                            sendMessage();
                            stop_request = true;
                            onDestroy();
                            return;
                          } else retry = true;
                        } else {
                          networkErrorCount = 0;
                        }

                        internalCounter = 1;
                        // stepDownStats = newStats;
                        Log.d(
                            Settings.TAG,
                            "data with network...++++++++++++++++++++++++++++++++++++++");
                        Log.d(Settings.TAG, data);
                        if (retry) new StatsFileManager(context).SaveStats(data);

                      } else {
                        List<Stats> statsWithoutNet = Stats.getStatsWithoutNetowrk(context);

                        String networkType = getNetworkType();
                        for (Stats stats : statsWithoutNet)
                          data = data + stats.getStringData() + "|" + networkType + "\n";
                        // stepDownStats = statsWithoutNet;
                        // Log.d(Settings.TAG,"Data without
                        // netowrk-------------------------------------------");
                        // Log.d(Settings.TAG, data);
                        new StatsFileManager(context).SaveStats(data);
                      }
                      // Log.d("stats-result", "Internal counter: " + internalCounter);
                      internalCounter++;
                      /*


                                                 //Step-down for changing interval begins here;.,..


                                                  boolean isActive= StepDownExtraction.isDeviceActive(context);
                                                  boolean checkNetworkStepdown=false;
                                                  if(!isActive && stepDownStats!=null)
                                                  {
                                                      StepDownExtraction tempStepDown =new StepDownExtraction(stepDownStats);
                                                      if(tempStepDown.cpuTotal >0)
                                                      {
                                                          Settings.interval=Settings.minInterval;
                                                          StepDownExtraction.count=0;
                                                          Log.d(Settings.TAG,"CPU: "+ tempStepDown.cpuTotal);
                                                      }
                                                      else
                                                      {
                                                          StepDownExtraction.count++;
                                                          checkNetworkStepdown=true;
                                                      }
                                                  }
                                                  Log.d(Settings.TAG,"Count: "+StepDownExtraction.count + "  \t Threshold: "+StepDownExtraction.threshold);


                                                  if (!isActive && diff != null && StepDownExtraction.count >= Settings.NetInterval)  //initialize if screen is off or not.)  //device sleeping.  Start step down approach
                                                  {
                                                      StepDownExtraction stepDownExtraction = new StepDownExtraction(diff);
                                                      int totalCpu = stepDownExtraction.cpuTotal;
                                                      int networkUsage=stepDownExtraction.totalNetwork;
                                                      Log.d(Settings.TAG,"Netowork : "+  networkUsage);
                                                      if (totalCpu <= 0 && networkUsage<=0)  //if CPU and memory is not in use then increase the interval;
                                                      {
                                                          Log.d(Settings.TAG,"Going into step down mode");

                                                          StepDownExtraction.count++;
                                                          Log.d(Settings.TAG,"Count: "+StepDownExtraction.count);
                                                          Log.d(Settings.TAG,"threshold: "+StepDownExtraction.threshold);
                                                          if (true)  //cpu was 0 for n (threshold) times. increase the delay
                                                          {
                                                              Log.d(Settings.TAG,"Went to step down");

                                                              if ((Settings.interval * 2) <= Settings.maxInterval)
                                                                  Settings.interval += Settings.interval;
                                                              else
                                                                  Settings.interval = Settings.maxInterval; //set it to max
                                                          }
                                                      }
                                                      else
                                                      {
                                                          Log.d(Settings.TAG, "both are not zero reseting counter");
                                                          Settings.interval = Settings.minInterval;
                                                          StepDownExtraction.count = 0;                             //reset the counter

                                                      }
                                                      Log.d(Settings.TAG,"Interval: "+Settings.interval);
                                                      //Log.d("step-down", "Device sleeping. Interval: " + Settings.interval + " CPU: " + totalCpu);
                                                  }
                                                  else if(isActive)       //device is awake set default interval...
                                                  {
                                                      Log.d(Settings.TAG, "awake reseting counter");
                                                      StepDownExtraction.count = 0;                             //reset the counter
                                                      Settings.interval = Settings.minInterval;//set default interval
                                                  }
                                                  //step down ends here...
                      */
                    }
                    counter++;
                    handler.postDelayed(this, Settings.getInterval() * 1000);
                  }
                },
            Settings.getInterval() * 1000);

      } catch (Exception ex) {
        Log.d(Settings.TAG, "Error occured in stats collector thread. " + ex.toString());
        Notify.showNotification(context, "Error occurred while collecting data.");
      }
    }
    isThreadRunning = !isThreadRunning;

    if (stop_request) return START_NOT_STICKY;
    else return START_STICKY;
  }