/**
   * Forwards {@code keyCode} to receiver specified as two key events, one for up and one for down.
   * Optionally launches the application for the receiver.
   *
   * @param context
   * @param selectedReceiver
   * @param launch
   * @param keyCode
   * @param cleanUpReceiver
   */
  public static void forwardKeyCodeToComponent(
      Context context,
      ComponentName selectedReceiver,
      boolean launch,
      int keyCode,
      BroadcastReceiver cleanUpReceiver) {

    Intent mediaButtonDownIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
    KeyEvent downKe =
        new KeyEvent(
            SystemClock.uptimeMillis(),
            SystemClock.uptimeMillis(),
            KeyEvent.ACTION_DOWN,
            keyCode,
            0);
    mediaButtonDownIntent.putExtra(Intent.EXTRA_KEY_EVENT, downKe);

    Intent mediaButtonUpIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
    KeyEvent upKe =
        new KeyEvent(
            SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), KeyEvent.ACTION_UP, keyCode, 0);
    mediaButtonUpIntent.putExtra(Intent.EXTRA_KEY_EVENT, upKe);

    mediaButtonDownIntent.setComponent(selectedReceiver);
    mediaButtonUpIntent.setComponent(selectedReceiver);

    /* COMMENTED OUT FOR MARKET RELEASE Log.i(TAG, "Forwarding Down and Up intent events to " + selectedReceiver + " Down Intent: "
    + mediaButtonDownIntent + " Down key:" + downKe + " Up Intent: " + mediaButtonUpIntent + " Up key:"
    + upKe); */
    // We start the selected application because some apps broadcast
    // receivers won't do anything with the intents unless the
    // application is open. (This this is only if the app isn't
    // playing music and you want it to play music now)
    // XXX Is that true? recheck..
    // Another reason to launch the app is that if the app does
    // AudioManager#registerMediaButtonEventReceiver
    // on load, and we are unable to tell when this app is playing music,
    // android's default behavior should be correct.
    if (launch) {
      Intent launchIntent =
          context.getPackageManager().getLaunchIntentForPackage(selectedReceiver.getPackageName());
      if (launchIntent != null) {
        context.startActivity(launchIntent);
      }
    }

    context.sendOrderedBroadcast(
        mediaButtonDownIntent, null, cleanUpReceiver, null, Activity.RESULT_OK, null, null);
    context.sendOrderedBroadcast(
        mediaButtonUpIntent, null, cleanUpReceiver, null, Activity.RESULT_OK, null, null);
  }
Esempio n. 2
0
  static void answerfix(Context context) {
    try {
      Intent buttonDown = new Intent(Intent.ACTION_MEDIA_BUTTON);
      buttonDown.putExtra(
          Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HEADSETHOOK));
      context.sendOrderedBroadcast(buttonDown, "android.permission.CALL_PRIVILEGED");

      // froyo and beyond trigger on buttonUp instead of buttonDown
      Intent buttonUp = new Intent(Intent.ACTION_MEDIA_BUTTON);
      buttonUp.putExtra(
          Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK));
      context.sendOrderedBroadcast(buttonUp, "android.permission.CALL_PRIVILEGED");

      Intent headSetUnPluggedintent = new Intent(Intent.ACTION_HEADSET_PLUG);
      headSetUnPluggedintent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
      headSetUnPluggedintent.putExtra("state", 1); // 0 = unplugged 1 =
      // Headset with
      // microphone 2 =
      // Headset without
      // microphone
      headSetUnPluggedintent.putExtra("name", "Headset");
      // TODO: Should we require a permission?
      context.sendOrderedBroadcast(headSetUnPluggedintent, null);

    } catch (Exception e) {

    }
  }
  @Override
  public void onReceive(Context context, Intent intent) {
    ContextManager.setContext(context);
    DependencyInjectionService.getInstance().inject(this);
    long taskId = intent.getLongExtra(AstridApiConstants.EXTRAS_TASK_ID, -1);
    if (taskId == -1) return;

    Task task = PluginServices.getTaskService().fetchById(taskId, Task.PROPERTIES);
    if (task == null || !task.isCompleted()) return;

    String recurrence = task.getValue(Task.RECURRENCE);
    if (recurrence != null && recurrence.length() > 0) {
      long newDueDate;
      try {
        newDueDate = computeNextDueDate(task, recurrence);
        if (newDueDate == -1) return;
      } catch (ParseException e) {
        PluginServices.getExceptionService().reportError("repeat-parse", e); // $NON-NLS-1$
        return;
      }

      StatisticsService.reportEvent(StatisticsConstants.V2_TASK_REPEAT);

      long oldDueDate = task.getValue(Task.DUE_DATE);
      long repeatUntil = task.getValue(Task.REPEAT_UNTIL);

      boolean repeatFinished = repeatUntil > 0 && newDueDate >= repeatUntil;
      if (repeatFinished) {
        Intent repeatFinishedIntent =
            new Intent(AstridApiConstants.BROADCAST_EVENT_TASK_REPEAT_FINISHED);
        repeatFinishedIntent.putExtra(AstridApiConstants.EXTRAS_TASK_ID, task.getId());
        repeatFinishedIntent.putExtra(AstridApiConstants.EXTRAS_OLD_DUE_DATE, oldDueDate);
        repeatFinishedIntent.putExtra(AstridApiConstants.EXTRAS_NEW_DUE_DATE, newDueDate);
        context.sendOrderedBroadcast(repeatFinishedIntent, null);
        return;
      }

      rescheduleTask(task, newDueDate);

      // send a broadcast
      Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_EVENT_TASK_REPEATED);
      broadcastIntent.putExtra(AstridApiConstants.EXTRAS_TASK_ID, task.getId());
      broadcastIntent.putExtra(AstridApiConstants.EXTRAS_OLD_DUE_DATE, oldDueDate);
      broadcastIntent.putExtra(AstridApiConstants.EXTRAS_NEW_DUE_DATE, newDueDate);
      context.sendOrderedBroadcast(broadcastIntent, null);
      Flags.set(Flags.REFRESH);
      return;
    }
  }
Esempio n. 4
0
  public static void answerPhoneHeadsethook(Context context) {
    answerfix(context);

    // Simulate a press of the headset button to pick up the call
    // SettingsClass.logMe(tag, "Simulating headset button");
    Intent buttonDown = new Intent(Intent.ACTION_MEDIA_BUTTON);
    buttonDown.putExtra(
        Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HEADSETHOOK));
    context.sendOrderedBroadcast(buttonDown, "android.permission.CALL_PRIVILEGED");

    // froyo and beyond trigger on buttonUp instead of buttonDown
    Intent buttonUp = new Intent(Intent.ACTION_MEDIA_BUTTON);
    buttonUp.putExtra(
        Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK));
    context.sendOrderedBroadcast(buttonUp, "android.permission.CALL_PRIVILEGED");
  }
 public void stopThread(int threadID) {
   Intent intentStart = new Intent(C.FILTER_FOR_CLIENTS);
   intentStart.putExtra(C.MESSAGE_TYPE, C.THREAD_STOP);
   intentStart.putExtra(C.THREAD_ID, threadID);
   Log.i(TAG, "Sending Thread Stop with ID: " + threadID);
   context.sendOrderedBroadcast(intentStart, null);
 }
Esempio n. 6
0
  private void deswift(String tempTrackName, String result) throws Throwable {
    if (result.toLowerCase().contains("taylor swift") && !trackName.equals(tempTrackName)) {
      ctx =
          AndroidAppHelper.currentApplication()
              .createPackageContext("de.havefuninsi.noswift", Context.CONTEXT_IGNORE_SECURITY);
      trackName = tempTrackName;
      XposedBridge.log("NoSwift: " + result);
      Intent i = new Intent(Intent.ACTION_MEDIA_BUTTON);
      synchronized (this) {
        i.putExtra(
            Intent.EXTRA_KEY_EVENT,
            new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT));
        ctx.sendOrderedBroadcast(i, null);

        i.putExtra(
            Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_NEXT));
        ctx.sendOrderedBroadcast(i, null);
      }
    }
  }
  public void broadcastLocation(Location location) {
    final LocationProxy bgLocation = LocationProxy.fromAndroidLocation(location);
    bgLocation.setServiceProvider(config.getServiceProvider());

    if (config.isDebugging()) {
      bgLocation.setDebug(true);
      persistLocation(bgLocation);
    }

    Log.d(TAG, "Broadcasting update message: " + bgLocation.toString());
    try {
      String locStr = bgLocation.toJSONObject().toString();
      Intent intent = new Intent(Constant.ACTION_FILTER);
      intent.putExtra(Constant.ACTION, Constant.ACTION_LOCATION_UPDATE);
      intent.putExtra(Constant.DATA, locStr);
      if (config.getUrl() != null) {
        Log.i(TAG, "Sending URL detail");
        intent.putExtra("url", config.getUrl());
        intent.putExtra("method", config.getMethod());
        intent.putExtra("headers", config.getHeaders());
        intent.putExtra("params", config.getParams());
      } else {
        Log.i(TAG, "No URL defined");
      }
      context.sendOrderedBroadcast(
          intent,
          null,
          new BroadcastReceiver() {
            // @SuppressLint("NewApi")
            @Override
            public void onReceive(Context context, Intent intent) {
              Log.d(TAG, "Final Result Receiver");
              Bundle results = getResultExtras(true);
              if (results.getString(Constant.LOCATION_SENT_INDICATOR) == null) {
                Log.w(TAG, "Main activity seems to be killed");
                if (config.getStopOnTerminate() == false) {
                  bgLocation.setDebug(false);
                  persistLocation(bgLocation);
                  Log.d(TAG, "Persisting location. Reason: Main activity was killed.");
                }
              }
            }
          },
          null,
          Activity.RESULT_OK,
          null,
          null);
    } catch (JSONException e) {
      Log.w(TAG, "Failed to broadcast location");
    }
  }
  @Override
  public void onReceive(Context context, Intent intent) {
    super.onReceive(context, intent);

    long taskId = intent.getLongExtra(AstridApiConstants.EXTRAS_TASK_ID, -1);
    if (taskId == -1) {
      return;
    }

    Task task = taskService.fetchById(taskId, Task.PROPERTIES);
    if (task == null || !task.isCompleted()) {
      return;
    }

    String recurrence = task.sanitizedRecurrence();
    boolean repeatAfterCompletion = task.repeatAfterCompletion();

    if (recurrence != null && recurrence.length() > 0) {
      long newDueDate;
      try {
        newDueDate = computeNextDueDate(task, recurrence, repeatAfterCompletion);
        if (newDueDate == -1) {
          return;
        }
      } catch (ParseException e) {
        log.error(e.getMessage(), e);
        return;
      }

      long oldDueDate = task.getDueDate();
      long repeatUntil = task.getRepeatUntil();

      if (repeatFinished(newDueDate, repeatUntil)) {
        return;
      }

      rescheduleTask(context, gcalHelper, taskService, task, newDueDate);

      // send a broadcast
      Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_EVENT_TASK_REPEATED);
      broadcastIntent.putExtra(AstridApiConstants.EXTRAS_TASK_ID, task.getId());
      broadcastIntent.putExtra(AstridApiConstants.EXTRAS_OLD_DUE_DATE, oldDueDate);
      broadcastIntent.putExtra(AstridApiConstants.EXTRAS_NEW_DUE_DATE, newDueDate);
      context.sendOrderedBroadcast(broadcastIntent, null);
      Flags.set(Flags.REFRESH);
    }
  }
 BroadcastReceiver launchServiceMode(Intent activityIntent, final String certMessage) {
   BroadcastReceiver launchNotifReceiver =
       new BroadcastReceiver() {
         public void onReceive(Context ctx, Intent i) {
           Log.i(TAG, "Interception not done by the application. Send notification");
           PendingIntent pi = i.getParcelableExtra(INTERCEPT_DECISION_INTENT_LAUNCH);
           startActivityNotification(pi, certMessage);
         }
       };
   master.registerReceiver(
       launchNotifReceiver,
       new IntentFilter(INTERCEPT_DECISION_INTENT + "/" + master.getPackageName()));
   PendingIntent call = PendingIntent.getActivity(master, 0, activityIntent, 0);
   Intent ni = new Intent(INTERCEPT_DECISION_INTENT + "/" + master.getPackageName());
   ni.putExtra(INTERCEPT_DECISION_INTENT_LAUNCH, call);
   master.sendOrderedBroadcast(ni, null);
   return launchNotifReceiver;
 }
Esempio n. 10
0
 public static boolean sendMessageIntent(
     Context context,
     int messageType,
     int messageState,
     int id,
     int type,
     String content,
     boolean isMeSay,
     Person person) {
   Intent intent = new Intent(IvyMessages.INTENT_MESSAGE);
   intent.putExtra(IvyMessages.PARAMETER_MESSAGE_TYPE, messageType);
   intent.putExtra(IvyMessages.PARAMETER_MESSAGE_ID, id);
   intent.putExtra(IvyMessages.PARAMETER_MESSGAE_STATE, messageState);
   intent.putExtra(IvyMessages.PARAMETER_MESSAGE_FILE_TYPE, type);
   intent.putExtra(IvyMessages.PARAMETER_MESSAGE_FILE_VALUE, content);
   intent.putExtra(IvyMessages.PARAMETER_MESSAGE_SELF, isMeSay);
   intent.putExtra(IvyMessages.PARAMETER_MESSAGE_PERSON, PersonManager.getPersonKey(person));
   context.sendOrderedBroadcast(intent, null);
   return true;
 }
Esempio n. 11
0
  public static void sendGroupMessageIntent(
      Context context,
      int messageType,
      int messageState,
      int id,
      int type,
      String content,
      boolean isBroadcast,
      String groupName,
      boolean isMeSay) {
    Intent intent = new Intent(IvyMessages.INTENT_GROUP_MESSAGE);
    intent.putExtra(IvyMessages.PARAMETER_GROUP_MESSAGE_TYPE, messageType);
    intent.putExtra(IvyMessages.PARAMETER_GROUP_MESSAGE_ID, id);
    intent.putExtra(IvyMessages.PARAMETER_GROUP_MESSAGE_STATE, messageState);
    intent.putExtra(IvyMessages.PARAMETER_GROUP_MESSAGE_FILE_TYPE, type);
    intent.putExtra(IvyMessages.PARAMETER_GROUP_MESSAGE_FILE_VALUE, content);
    intent.putExtra(IvyMessages.PARAMETER_GROUP_MESSAGE_BROADCAST, isBroadcast);
    intent.putExtra(IvyMessages.PARAMETER_GROUP_MESSAGE_GROUPNAME, groupName);
    intent.putExtra(IvyMessages.PARAMETER_GROUP_MESSAGE_SELF, isMeSay);

    context.sendOrderedBroadcast(intent, null);
  }
Esempio n. 12
0
 public Stt(final Context context, final OnInitListener listener) {
   if (SpeechRecognizer.isRecognitionAvailable(context)) {
     recognizer = SpeechRecognizer.createSpeechRecognizer(context);
     recognizer.setRecognitionListener(recognitionListener);
     context.sendOrderedBroadcast(
         new Intent(RecognizerIntent.ACTION_GET_LANGUAGE_DETAILS),
         null,
         new BroadcastReceiver() {
           @Override
           public void onReceive(Context context, Intent intent) {
             supportedLanguages = new ArrayList<Locale>();
             final Bundle results = getResultExtras(true);
             if (results.containsKey(RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES)) {
               for (String language :
                   results.getStringArrayList(RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES)) {
                 final String tags[] = language.split("-");
                 if (tags.length == 1) supportedLanguages.add(new Locale(tags[0]));
                 else if (tags.length == 2) supportedLanguages.add(new Locale(tags[0], tags[1]));
                 else if (tags.length == 3)
                   supportedLanguages.add(new Locale(tags[0], tags[1], tags[2]));
               }
               loaded = true;
               listener.onInit(true);
             } else {
               listener.onInit(false);
             }
           }
         },
         null,
         Activity.RESULT_OK,
         null,
         null);
   } else {
     listener.onInit(false);
   }
 }
  /**
   * Makes sure we handle the shutdown gracefully. Shuts off power regardless of radio and bluetooth
   * state if the alloted time has passed.
   */
  public void run() {
    boolean bluetoothOff;
    boolean radioOff;

    BroadcastReceiver br =
        new BroadcastReceiver() {
          @Override
          public void onReceive(Context context, Intent intent) {
            // We don't allow apps to cancel this, so ignore the result.
            broadcastDone();
          }
        };

    Log.i(TAG, "Sending shutdown broadcast...");

    // First send the high-level shut down broadcast.
    mBroadcastDone = false;
    mContext.sendOrderedBroadcast(
        new Intent(Intent.ACTION_SHUTDOWN), null, br, mHandler, 0, null, null);

    final long endTime = System.currentTimeMillis() + MAX_BROADCAST_TIME;
    synchronized (mBroadcastDoneSync) {
      while (!mBroadcastDone) {
        long delay = endTime - System.currentTimeMillis();
        if (delay <= 0) {
          Log.w(TAG, "Shutdown broadcast timed out");
          break;
        }
        try {
          mBroadcastDoneSync.wait(delay);
        } catch (InterruptedException e) {
        }
      }
    }

    Log.i(TAG, "Shutting down activity manager...");

    final IActivityManager am =
        ActivityManagerNative.asInterface(ServiceManager.checkService("activity"));
    if (am != null) {
      try {
        am.shutdown(MAX_BROADCAST_TIME);
      } catch (RemoteException e) {
      }
    }

    final ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.checkService("phone"));
    final IBluetooth bluetooth =
        IBluetooth.Stub.asInterface(
            ServiceManager.checkService(BluetoothAdapter.BLUETOOTH_SERVICE));

    final IMountService mount =
        IMountService.Stub.asInterface(ServiceManager.checkService("mount"));

    try {
      bluetoothOff =
          bluetooth == null || bluetooth.getBluetoothState() == BluetoothAdapter.STATE_OFF;
      if (!bluetoothOff) {
        Log.w(TAG, "Disabling Bluetooth...");
        bluetooth.disable(false); // disable but don't persist new state
      }
    } catch (RemoteException ex) {
      Log.e(TAG, "RemoteException during bluetooth shutdown", ex);
      bluetoothOff = true;
    }

    try {
      radioOff = phone == null || !phone.isRadioOn();
      if (!radioOff) {
        Log.w(TAG, "Turning off radio...");
        phone.setRadio(false);
      }
    } catch (RemoteException ex) {
      Log.e(TAG, "RemoteException during radio shutdown", ex);
      radioOff = true;
    }

    Log.i(TAG, "Waiting for Bluetooth and Radio...");

    // Wait a max of 32 seconds for clean shutdown
    for (int i = 0; i < MAX_NUM_PHONE_STATE_READS; i++) {
      if (!bluetoothOff) {
        try {
          bluetoothOff = bluetooth.getBluetoothState() == BluetoothAdapter.STATE_OFF;
        } catch (RemoteException ex) {
          Log.e(TAG, "RemoteException during bluetooth shutdown", ex);
          bluetoothOff = true;
        }
      }
      if (!radioOff) {
        try {
          radioOff = !phone.isRadioOn();
        } catch (RemoteException ex) {
          Log.e(TAG, "RemoteException during radio shutdown", ex);
          radioOff = true;
        }
      }
      if (radioOff && bluetoothOff) {
        Log.i(TAG, "Radio and Bluetooth shutdown complete.");
        break;
      }
      SystemClock.sleep(PHONE_STATE_POLL_SLEEP_MSEC);
    }

    // Shutdown MountService to ensure media is in a safe state
    try {
      if (mount != null) {
        mount.shutdown();
      } else {
        Log.w(TAG, "MountService unavailable for shutdown");
      }
    } catch (Exception e) {
      Log.e(TAG, "Exception during MountService shutdown", e);
    }

    // shutdown power
    Log.i(TAG, "Performing low-level shutdown...");
    Power.shutdown();
  }
 public void PutHeader() {
   final Intent intent = new Intent();
   intent.setAction(C.SEND_FLUSHBUFFER_REQUEST_TO_SERVICE);
   intent.putExtra(C.MESSAGE_TYPE, C.REQUEST_PUT_HEADER);
   context.sendOrderedBroadcast(intent, null);
 }