コード例 #1
0
  @Override
  public void onDestroy() {
    super.onDestroy();
    if (timer != null) {
      timer.cancel();
      timer.purge();
    }
    Log.d("Aptoide-RabbitMqService", "RabbitMqService Destroyed!");

    try {

      isRunning = false;

      if (channel != null && channel.isOpen()) {
        channel.close();
      }

      if (connection != null && connection.isOpen()) {
        connection.close();
      }

    } catch (IOException e) {
      e.printStackTrace();
    } catch (ShutdownSignalException e) {
      e.printStackTrace();
    } catch (TimeoutException e) {
      e.printStackTrace();
    }

    Aptoide.setWebInstallServiceRunning(false);
  }
コード例 #2
0
  @Override
  public int onStartCommand(final Intent intent, int flags, int startId) {

    if (!isRunning) {
      // Toast.makeText(getApplicationContext(), "Starting amqp service", Toast.LENGTH_LONG).show();
      Aptoide.setWebInstallServiceRunning(true);
      //            new Thread(new Runnable() {
      //                @Override
      //                public void run() {
      //
      //
      //                    try {
      //
      //                        AccountManager manager =
      // AccountManager.get(getApplicationContext());
      //
      //                        if
      // (manager.getAccountsByType(Aptoide.getConfiguration().getAccountType()).length > 0) {
      //
      //                            final Account account =
      // AccountManager.get(getApplicationContext()).getAccountsByType(Aptoide.getConfiguration().getAccountType())[0];
      //
      //                            SharedPreferences sharedPreferences =
      // PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
      //                            String queueName = sharedPreferences.getString("queueName",
      // null);
      //                            ContentResolver.setIsSyncable(account,
      // Constants.WEBINSTALL_SYNC_AUTHORITY, 1);
      //                            ContentResolver.setSyncAutomatically(account,
      // Constants.WEBINSTALL_SYNC_AUTHORITY, true);
      //
      //                            if (Build.VERSION.SDK_INT >= 8) {
      //                                ContentResolver.addPeriodicSync(account,
      // Constants.WEBINSTALL_SYNC_AUTHORITY, new Bundle(),
      // Constants.WEBINSTALL_SYNC_POLL_FREQUENCY);
      //                            }
      //
      //                            String host = Constants.WEBINSTALL_HOST;
      //                            isRunning = true;
      //                            try {
      //                                ConnectionFactory factory = new ConnectionFactory();
      //                                factory.setHost(host);
      //                                factory.setUsername("public");
      //                                factory.setPassword("public");
      //                                factory.setConnectionTimeout(20000);
      //
      //                                factory.setVirtualHost("webinstall");
      //                                connection = (AMQConnection) factory.newConnection();
      //                                newChannel(queueName, new AMQHandler() {
      //                                    @Override
      //                                    void handleMessage(String body) {
      //
      //                                        try {
      //                                            JSONObject object = new JSONObject(body);
      //
      //                                            Intent i = new Intent(getApplicationContext(),
      // appViewClass);
      //                                            SharedPreferences securePreferences =
      // SecurePreferences.getInstance();
      //                                            String authToken =
      // securePreferences.getString("devtoken", "");
      //                                            String repo = object.getString("repo");
      //                                            long id = object.getLong("id");
      //                                            String md5sum = object.getString("md5sum");
      //                                            i.putExtra("fromMyapp", true);
      //                                            i.putExtra("repoName", repo);
      //                                            i.putExtra("id", id);
      //                                            i.putExtra("download_from", "webinstall");
      //                                            i.putExtra("md5sum", md5sum);
      //
      //                                            String deviceId =
      // Settings.Secure.getString(getApplicationContext().getContentResolver(),
      // Settings.Secure.ANDROID_ID);
      //
      //                                            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      //                                            String hmac = object.getString("hmac");
      //                                            String calculatedHmac =
      // AptoideUtils.Algorithms.computeHmacSha1(repo + id + md5sum, authToken + deviceId);
      //                                            if (hmac.equals(calculatedHmac)) {
      //                                                getApplicationContext().startActivity(i);
      //                                            } else {
      //                                                Log.d("Aptoide-WebInstall", "Error
      // validating message: received: " + hmac + " calculated:" + calculatedHmac);
      //                                            }
      //
      //                                        } catch (Exception e) {
      //                                            e.printStackTrace();
      //                                        }
      //
      //
      //                                    }
      //                                });
      //                            } catch (IOException e) {
      //
      // PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putBoolean(Constants.WEBINSTALL_QUEUE_EXCLUDED, true).commit();
      //                                e.printStackTrace();
      //                                try {
      //                                    if (channel != null && channel.isOpen()) {
      //                                        channel.close();
      //                                    }
      //
      //                                    if (connection != null && connection.isOpen()) {
      //                                        connection.close();
      //                                    }
      //                                } catch (IOException e1) {
      //                                    e1.printStackTrace();
      //                                } catch (ShutdownSignalException e1) {
      //                                    e1.printStackTrace();
      //                                }
      //                                isRunning = false;
      //
      //                            }
      //                        }
      //                    }catch (Exception e){
      //                        e.printStackTrace();
      //                    }
      //                }
      //            }).start();
    }

    return START_STICKY;
  }