public int onStartCommand(Intent intent, int flags, int startId) {
    super.onStartCommand(intent, flags, startId);

    new Thread(svrThreads, new ServiceWorker(), "PecorinerLocationDetect").start();
    // Toast.makeText(this, "start calling", Toast.LENGTH_SHORT).show();
    return START_STICKY;
  }
  /**
   * Se non è già avvenuto in una chiamata precedente, avvia un thread in background e
   * registra il servizio per riceverà gli update della posizione.
   *
   * @author Michele Piccirillo <*****@*****.**>
   */
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    super.onStartCommand(intent, flags, startId);

    // Un servizio puo' essere avviato piu' volte.
    // Avviamo il worker thread e ci registriamo per le posizioni solo la prima volta.
    if (worker == null) {
      Log.i("PositionTrackingService", "Service started");
      worker = new HandlerThread("PositionTrackingService", Process.THREAD_PRIORITY_BACKGROUND);
      worker.start();

      locationManager.requestLocationUpdates(
          LocationManager.GPS_PROVIDER,
          Setup.TRACKING_MIN_TIME,
          Setup.TRACKING_MIN_DISTANCE,
          locationListener,
          worker.getLooper());

      locationManager.requestLocationUpdates(
          LocationManager.NETWORK_PROVIDER,
          Setup.TRACKING_MIN_TIME,
          Setup.TRACKING_MIN_DISTANCE,
          locationListener,
          worker.getLooper());
    }

    return START_STICKY;
  }
  @DSVerified
  @DSBan(DSCat.DROIDSAFE_INTERNAL)
  public static void modelService(android.app.Service service) {
    if (mApplication != null) service.setApplication(mApplication);

    service.droidsafeAttachContext(context);

    service.onCreate();
    for (IntentFilter filter : service.__ds__intentFilters) {

      Intent intent = service.__ds__registerIntentFilter(filter);

      mApplication.__ds__intentsFromFilter.add(intent);

      service.onBind(intent);
      service.onRebind(intent);
      service.onStart(intent, DSUtils.FAKE_INT);
      service.onTaskRemoved(intent);
      service.onStartCommand(intent, DSUtils.FAKE_INT, DSUtils.FAKE_INT);
      service.onUnbind(intent);
      if (service instanceof IntentService) {
        ((IntentService) service).__ds__onHandleIntent(intent);
      }
    }
    service.droidsafeOnSubServiceHook();
    service.onConfigurationChanged(new Configuration());
    service.onLowMemory();
    service.onTrimMemory(0);
    service.stopSelf(0);
    service.onDestroy();
  }
示例#4
0
 @Override
 public int onStartCommand(Intent intent, int flags, int startId) {
   super.onStartCommand(intent, flags, startId);
   Monitor monitor = new Monitor();
   monitor.start();
   return START_STICKY;
 }
  @Override
  public int onStartCommand(final Intent intent, final int flags, final int startId) {
    super.onStartCommand(intent, flags, startId);

    if (intent == null) {
      return START_STICKY;
    }

    String action = intent.getAction();
    mLogger.fine("request action: " + action);
    if (action == null) {
      return START_STICKY;
    }

    Bundle resExtra = new Bundle();

    resExtra.putInt(DConnectMessage.EXTRA_RESULT, DConnectMessage.RESULT_ERROR);
    resExtra.putInt(
        DConnectMessage.EXTRA_REQUEST_CODE,
        intent.getIntExtra(DConnectMessage.EXTRA_REQUEST_CODE, -1));
    Intent response = MessageUtils.createResponseIntent(intent.getExtras(), resExtra);
    if (BuildConfig.DEBUG) {
      response.putExtra("debug", "DevicePlugin");
    }

    if (IntentDConnectMessage.ACTION_GET.equals(action)
        || IntentDConnectMessage.ACTION_POST.equals(action)
        || IntentDConnectMessage.ACTION_PUT.equals(action)
        || IntentDConnectMessage.ACTION_DELETE.equals(action)) {
      onRequest(intent, response);
    }

    return START_STICKY;
  }
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    super.onStartCommand(intent, flags, startId);

    if (!initiated) {
      IntentFilter filter = new IntentFilter();
      filter.addAction(Intent.ACTION_SCREEN_OFF);
      filter.addAction(Intent.ACTION_SCREEN_ON);
      filter.setPriority(1000);
      registerReceiver(new LockscreenManager(), filter);

      IntentFilter filter2 = new IntentFilter();
      filter2.addAction(Intent.ACTION_SCREEN_OFF);
      filter2.setPriority(1000);
      registerReceiver(new UnlocktimeReceiver(), filter2);

      IntentFilter filter3 = new IntentFilter();
      filter3.addAction(Intent.ACTION_SCREEN_ON);
      filter3.setPriority(1000);
      registerReceiver(new ExpositionUnlockReceiver(), filter3);

      // todo refactor this method is depricated
      KeyguardManager keyguardManager =
          (KeyguardManager) getSystemService(Activity.KEYGUARD_SERVICE);
      KeyguardManager.KeyguardLock lock = keyguardManager.newKeyguardLock(Context.KEYGUARD_SERVICE);
      lock.disableKeyguard();

      initiated = true;
    }

    //        stopSelf();

    return Service.START_STICKY;
  }
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    super.onStartCommand(intent, flags, startId);

    Log.i("AudioService", "Called.. onStartCommand.");

    return START_NOT_STICKY;
  }
 @Override
 public int onStartCommand(Intent intent, int flags, int startId) {
   super.onStartCommand(intent, flags, startId);
   now = Long.valueOf(System.currentTimeMillis());
   mLocationClient = new LocationClient(this, this, this);
   mLocationClient.connect();
   return START_STICKY;
 }
 /** onStart creates MessangerManager and starts LimitCheker in a new thread */
 @Override
 public int onStartCommand(Intent intent, int flags, int startId) {
   // TODO Auto-generated method stub
   super.onStartCommand(intent, flags, startId);
   Log.d("Testing", "Service started");
   messagesManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
   Thread t = new Thread(null, new LimitChecker(), "BackgroundService");
   t.start();
   return 0;
 }
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    super.onStartCommand(intent, flags, startId);
    Utility.checkSelfAllPermissions(this);
    if (!Utility.hasPermission(Utility.PERMISSION_COARSE_LOCATION)
        && !Utility.hasPermission(Utility.PERMISSION_FINE_LOCATION)) {
      if (mHandler != null) mHandler.sendEmptyMessage(MSG_STOP_SELF);
      return START_NOT_STICKY;
    }

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);

    if (DEBUG) Log.d(TAG, "Service has received start id " + startId + ": " + intent);
    mReturnAddress = intent.getStringExtra("return_address");
    if (mReturnAddress == null || mReturnAddress.isEmpty()) {
      Log.e(TAG, "Lack return address");
      return START_NOT_STICKY;
    }

    mPrecise = intent.getIntExtra("precise", 10);
    mTrack = intent.getIntExtra("track", 1);

    if (mPrecise <= 0) mPrecise = 1;
    if (mPrecise >= 20) mPrecise = 20;
    if (mTrack <= 0) mTrack = 1;
    else if ((mTrack * mPrecise) > 240) mTrack = 240 / mPrecise;
    if (DEBUG) Log.d(TAG, "Precise " + mPrecise + ", Track " + mTrack);

    mReceiver = new MyReceiver();
    IntentFilter filter = new IntentFilter(Utility.ACTION_STOP_BACKGROUND);
    registerReceiver(mReceiver, filter);

    synchronized (mLock) {
      if (mThread != null) return START_NOT_STICKY;
      mThread = new HandlerThread("H1");
      mThread.start();
      mStartTime = 0;
      if (DEBUG) Log.d(TAG, "thread started");
      mHandler = new Handler(mThread.getLooper(), this);
      mHandler.sendEmptyMessage(MSG_GET_LOCATION);

      // Need keep wake until the location is updated.
      if (Utility.hasPermission(Utility.PERMISSION_WAKE_LOCK)) {
        mWakelock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "WRU");
        mWakelock.acquire();
      }

      doReportStart();
    }
    // We want this service to continue running until it is explicitly
    // stopped, so return sticky.
    return START_STICKY;
  }
示例#11
0
  /**
   * This replaced the old onStart(). It registers the broadcast receiver, sets up system services,
   * builds the initial notification, and processes the incoming intent
   *
   * @param intent The intent the service was created with
   * @param flags Additional data about this start request. Currently either 0,
   *     START_FLAG_REDELIVERY, or START_FLAG_RETRY.
   * @param startId A unique integer representing this specific request to start. Use with
   *     stopSelfResult(int).
   * @return Service.START_REDELIVER_INTENT, if the service is killed, it will be restarted with the
   *     initial intent
   */
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    super.onStartCommand(intent, flags, startId);

    Log.v("MTG", "onStartCommand");
    mGoogleApiClient =
        new GoogleApiClient.Builder(this)
            .addApi(Wearable.API)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();
    mGoogleApiClient.connect();

    /* Register the broadcast receiver */
    registerReceiver(
        mBroadcastReceiver, new IntentFilter(OngoingNotificationListenerService.BROADCAST_ACTION));

    /* Set up system services */
    mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    Intent broadcast = new Intent(OngoingNotificationListenerService.BROADCAST_ACTION);
    broadcast.putExtra(FamiliarConstants.KEY_END_TIME, FamiliarConstants.CANCEL_FROM_WEAR);
    PendingIntent broadcastPendingIntent = PendingIntent.getBroadcast(this, 0, broadcast, 0);

    /* Build the initial notification */
    mNotificationBuilder =
        new Notification.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.mipmap.ic_launcher))
            .setOngoing(true)
            .extend(
                new Notification.WearableExtender()
                    .setBackground(
                        BitmapFactory.decodeResource(this.getResources(), R.drawable.background))
                    .setHintHideIcon(true)
                    .setContentIcon(R.mipmap.ic_launcher)
                    .addAction(
                        new Notification.Action(
                            R.mipmap.ic_launcher,
                            getString(R.string.cancel),
                            broadcastPendingIntent)));

    /* Process the initial intent. This will create the notification */
    processIntent(intent);

    /* Save the start id */
    mStartId = startId;

    /* Return, making sure to restart with the same intent if the service is killed */
    return Service.START_REDELIVER_INTENT;
  }
 @Override
 public int onStartCommand(Intent intent, int flags, int startId) {
   super.onStartCommand(intent, flags, startId);
   Log.v(logTag, "Starting service: " + logTag);
   this.runFlag = true;
   app.rfcxServiceHandler.setRunState(SERVICE_NAME, true);
   try {
     this.serviceObject.start();
   } catch (IllegalThreadStateException e) {
     RfcxLog.logExc(logTag, e);
   }
   return START_STICKY;
 }
  @Override
  public int onStartCommand(final Intent intent, final int flags, final int startId) {
    super.onStartCommand(intent, flags, startId);

    if (null != intent) {
      if (!mIsOnStartCommandCalled) {
        if ((((PowerManager) getSystemService(Context.POWER_SERVICE)).isScreenOn())
            != intent.getBooleanExtra(EXTRA_BOOLEAN_WAS_SCREEN_ON, false))
          sendBroadcast(INTENT_REQUEST_REQUERY);
      }
      ServiceWakeLockManager.releaseLock();
    }
    mIsOnStartCommandCalled = true;
    return START_STICKY;
  }
示例#14
0
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    super.onStartCommand(intent, flags, startId);

    Log.v(getString(R.string.log), "MyAlarmReceiver onStartCommand");

    // インテント設定
    i = intent;

    // スレッドスタート
    Thread thr = new Thread(null, mTask, "MyAlarmServiceThread");
    thr.start();

    Log.v(getString(R.string.log), "MyAlarmReceiver スレッド開始");

    return START_NOT_STICKY;
  }
示例#15
0
  // Create thread for connection and run it
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    super.onStartCommand(intent, flags, startId);
    // Get the location manager
    // System.out.println("Update Service");
    LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    LocationListener locationListener = new MyLocationListener();
    locationManager.requestSingleUpdate(
        // locationManager.requestLocationUpdates(
        LocationManager.NETWORK_PROVIDER, locationListener, null);

    // requestSingleUpdate(Criteria criteria, LocationListener listener, Looper looper);
    // Runnable connect = new connectSocket();
    // new Thread(connect).start();
    this.stopSelf();
    return START_NOT_STICKY;
  }
示例#16
0
 @Override
 public int onStartCommand(Intent intent, int flags, int startId) {
   super.onStartCommand(intent, flags, startId);
   String action = intent.getAction();
   if (action.equals(ACTION_PLAY)) {
     filename = intent.getStringExtra("filename");
     title = intent.getStringExtra("title");
     title2 = intent.getStringExtra("title2");
     Log.d(TAG, "onStart(): " + filename);
     startSong(filename);
   } else if (action.equals(ACTION_PAUSE)) {
     pauseSong();
   } else if (action.equals(ACTION_RESUME)) {
     resumeSong();
   } else if (action.equals(ACTION_STOP)) {
     stopSong();
   }
   return START_STICKY;
 }
示例#17
0
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    super.onStartCommand(intent, flags, startId);
    String action = intent.getAction();
    if (ACTION_START.equals(action)) {
      if (!started) {
        Log.i(TAG, "Starting service");

        String socketName = intent.getStringExtra(EXTRA_SOCKET);
        if (socketName == null) {
          socketName = DEFAULT_SOCKET;
        }

        try {
          acceptor = new LocalServerSocket(socketName);

          addMonitor(new BatteryMonitor(this, writers));
          addMonitor(new ConnectivityMonitor(this, writers));
          addMonitor(new PhoneStateMonitor(this, writers));
          addMonitor(new RotationMonitor(this, writers));
          addMonitor(new AirplaneModeMonitor(this, writers));
          addMonitor(new BrowserPackageMonitor(this, writers));

          executor.submit(new Server(acceptor));

          started = true;
        } catch (UnknownHostException e) {
          Log.e(TAG, e.getMessage());
        } catch (IOException e) {
          e.printStackTrace();
        }
      } else {
        Log.w(TAG, "Service is already running");
      }
    } else if (ACTION_STOP.equals(action)) {
      stopSelf();
    } else {
      Log.e(TAG, "Unknown action " + action);
    }

    return START_NOT_STICKY;
  }
  @Override
  public int onStartCommand(final Intent intent, final int flags, final int startId) {
    super.onStartCommand(intent, flags, startId);

    if (intent == null) {
      mLogger.warning("request intent is null.");
      return START_STICKY;
    }

    String action = intent.getAction();
    if (action == null) {
      mLogger.warning("request action is null. ");
      return START_STICKY;
    }

    if (checkRequestAction(action)) {
      onRequest(intent, MessageUtils.createResponseIntent(intent));
    }

    return START_STICKY;
  }
  @Override
  public int onStartCommand(Intent i, int j, int k) {
    super.onStartCommand(i, j, k);
    if (i == null) {
      return -1;
    }

    if (!i.hasExtra(ACCOUNT_NAME) || !i.hasExtra(AUTH_TOKEN_TYPE)) {
      stopSelf();
      return -1;
    }

    mUserId = i.getStringExtra(ACCOUNT_NAME);
    mAuthToken = i.getStringExtra(AUTH_TOKEN_TYPE);

    mCollectionUpdateHandlerThread = new HandlerThread(TAG, Process.THREAD_PRIORITY_BACKGROUND);
    mCollectionUpdateHandlerThread.start();
    mHandler = new Handler(mCollectionUpdateHandlerThread.getLooper());

    mHandler.postDelayed(mStartupConnectionRunnable, 1);

    return START_STICKY;
  }
示例#20
0
  // 2.0 and up, older API use onStart which is now deprecated
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    super.onStartCommand(intent, flags, startId);

    if (initialized) {
      onRestartCommand();

      return 1; // don't proceed - the rest of the start command is initialization code
    }

    Log.v("first-start", "boot handler & rcvrs");

    activate(); // registers to receive the screen broadcasts

    // register with the telephony mgr to make sure we can read call state
    final TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    assert (tm != null);
    tm.listen(Detector, PhoneStateListener.LISTEN_CALL_STATE);

    onFirstStart(); // The subclass will place init actions in an override here

    initialized = true;
    return 1;
  }
 @Override
 public int onStartCommand(Intent intent, int flags, int startId) {
   super.onStartCommand(intent, flags, startId);
   Log.d(TAG, "onStarted");
   return START_STICKY;
 }
示例#22
0
 @Override
 public int onStartCommand(final Intent intent, final int flags, final int startId) {
   super.onStartCommand(intent, flags, startId);
   return START_NOT_STICKY;
 }
 public int onStartCommand(android.content.Intent intent, int flags, int startId) {
   if (ScriptLoader.isCalledFromJRuby()) return super.onStartCommand(intent, flags, startId);
   if (JRubyAdapter.isInitialized()) {
     if (scriptInfo.getCallbackProcs() != null
         && scriptInfo.getCallbackProcs()[CB_START_COMMAND] != null) {
       super.onStartCommand(intent, flags, startId);
       return (Integer)
           JRubyAdapter.runRubyMethod(
               Integer.class,
               scriptInfo.getCallbackProcs()[CB_START_COMMAND],
               "call",
               new Object[] {intent, flags, startId});
     } else {
       String rubyClassName = scriptInfo.getRubyClassName();
       if ((Boolean)
           JRubyAdapter.runScriptlet(
               "defined?("
                   + rubyClassName
                   + ") == 'constant' && "
                   + rubyClassName
                   + ".instance_methods(false).any?{|m| m.to_sym == :on_start_command}")) {
         // FIXME(uwe): Simplify when we stop support for RubotoCore 0.4.7
         if (JRubyAdapter.isJRubyPreOneSeven()) {
           JRubyAdapter.put("$arg_intent", intent);
           JRubyAdapter.put("$arg_flags", flags);
           JRubyAdapter.put("$arg_startId", startId);
           JRubyAdapter.put("$ruby_instance", scriptInfo.getRubyInstance());
           return (Integer)
               ((Number)
                       JRubyAdapter.runScriptlet(
                           "$ruby_instance.on_start_command($arg_intent, $arg_flags, $arg_startId)"))
                   .intValue();
         } else {
           if (JRubyAdapter.isJRubyOneSeven()) {
             return (Integer)
                 JRubyAdapter.runRubyMethod(
                     Integer.class,
                     scriptInfo.getRubyInstance(),
                     "on_start_command",
                     new Object[] {intent, flags, startId});
           } else {
             throw new RuntimeException(
                 "Unknown JRuby version: " + JRubyAdapter.get("JRUBY_VERSION"));
           }
         }
       } else {
         if ((Boolean)
             JRubyAdapter.runScriptlet(
                 "defined?("
                     + rubyClassName
                     + ") == 'constant' && "
                     + rubyClassName
                     + ".instance_methods(false).any?{|m| m.to_sym == :onStartCommand}")) {
           // FIXME(uwe): Simplify when we stop support for RubotoCore 0.4.7
           if (JRubyAdapter.isJRubyPreOneSeven()) {
             JRubyAdapter.put("$arg_intent", intent);
             JRubyAdapter.put("$arg_flags", flags);
             JRubyAdapter.put("$arg_startId", startId);
             JRubyAdapter.put("$ruby_instance", scriptInfo.getRubyInstance());
             return (Integer)
                 ((Number)
                         JRubyAdapter.runScriptlet(
                             "$ruby_instance.onStartCommand($arg_intent, $arg_flags, $arg_startId)"))
                     .intValue();
           } else {
             if (JRubyAdapter.isJRubyOneSeven()) {
               return (Integer)
                   JRubyAdapter.runRubyMethod(
                       Integer.class,
                       scriptInfo.getRubyInstance(),
                       "onStartCommand",
                       new Object[] {intent, flags, startId});
             } else {
               throw new RuntimeException(
                   "Unknown JRuby version: " + JRubyAdapter.get("JRUBY_VERSION"));
             }
           }
         } else {
           return super.onStartCommand(intent, flags, startId);
         }
       }
     }
   } else {
     Log.i("Method called before JRuby runtime was initialized: RubotoService#onStartCommand");
     return super.onStartCommand(intent, flags, startId);
   }
 }
 @Override
 public int onStartCommand(Intent intent, int flags, int startId) {
   super.onStartCommand(intent, flags, startId);
   // Log.d(TAG, "ClockWorkService onStartCommand()");
   return START_STICKY;
 }
 @Override
 public int onStartCommand(Intent intent, int flags, int startId) {
   LogUtils.d(TAG, "onStartCommand...");
   super.onStartCommand(intent, flags, startId);
   return START_NOT_STICKY;
 }