Esempio n. 1
0
 private static void checkReceiver(Context context, Set<String> allowedReceivers, String action) {
   PackageManager pm = context.getPackageManager();
   String packageName = context.getPackageName();
   Intent intent = new Intent(action);
   intent.setPackage(packageName);
   List<ResolveInfo> receivers =
       pm.queryBroadcastReceivers(intent, PackageManager.GET_INTENT_FILTERS);
   if (receivers.isEmpty()) {
     throw new IllegalStateException("No receivers for action " + action);
   }
   if (Log.isLoggable(TAG, Log.VERBOSE)) {
     Log.v(TAG, "Found " + receivers.size() + " receivers for action " + action);
   }
   // make sure receivers match
   for (ResolveInfo receiver : receivers) {
     String name = receiver.activityInfo.name;
     if (!allowedReceivers.contains(name)) {
       throw new IllegalStateException(
           "Receiver "
               + name
               + " is not set with permission "
               + GCMConstants.PERMISSION_GCM_INTENTS);
     }
   }
 }
Esempio n. 2
0
  /**
   * Retrieve all dynamic codec plugins available in the platform It will resolve for a given action
   * available sip plugins
   *
   * @param ctxt Context of the application
   * @param action Action of the plugin to be resolved
   * @return a map containing plugins infos and registrered component name as key
   */
  public static Map<String, DynCodecInfos> getDynCodecPlugins(Context ctxt, String action) {
    if (!CACHED_RESOLUTION.containsKey(action)) {
      HashMap<String, DynCodecInfos> plugins = new HashMap<String, DynCodecInfos>();

      PackageManager packageManager = ctxt.getPackageManager();
      Intent it = new Intent(action);

      List<ResolveInfo> availables = packageManager.queryBroadcastReceivers(it, 0);
      for (ResolveInfo resInfo : availables) {
        ActivityInfo actInfos = resInfo.activityInfo;
        if (packageManager.checkPermission(
                SipManager.PERMISSION_CONFIGURE_SIP, actInfos.packageName)
            == PackageManager.PERMISSION_GRANTED) {
          ComponentName cmp = new ComponentName(actInfos.packageName, actInfos.name);
          DynCodecInfos dynInfos;
          try {
            dynInfos = new DynCodecInfos(ctxt, cmp);
            plugins.put(cmp.flattenToString(), dynInfos);
          } catch (NameNotFoundException e) {
            Log.e(THIS_FILE, "Error while retrieving infos from dyn codec ", e);
          }
        }
      }
      CACHED_RESOLUTION.put(action, plugins);
    }

    return CACHED_RESOLUTION.get(action);
  }
 public static void b(Context context, Intent intent) {
   String s = intent.getAction();
   if ("android.intent.action.PACKAGE_ADDED".equals(s)) {
     String s1 = intent.getData().getEncodedSchemeSpecificPart();
     if (it.a) {
       Log.d(
           "ReceiverHelper",
           (new StringBuilder()).append("got an ").append(s).append("for").append(s1).toString());
     }
     PackageManager packagemanager = context.getPackageManager();
     if (packagemanager.checkSignatures(context.getPackageName(), s1) >= 0) {
       Intent intent1 = new Intent("com.dianxinos.appupdate.intent.NOTIFY_INSTALLED");
       intent1.setComponent(
           new ComponentName(s1, "com.dianxinos.appupdate.NotifyInstalledReceiver"));
       if (!packagemanager.queryBroadcastReceivers(intent1, 0).isEmpty()) {
         context.sendBroadcast(intent1);
         if (it.a) {
           Log.d(
               "ReceiverHelper",
               (new StringBuilder())
                   .append("sent an com.dianxinos.appupdate.intent.NOTIFY_INSTALLED ")
                   .append(intent1.getComponent())
                   .toString());
           return;
         }
       }
     }
   }
 }
  /**
   * Gets the list of available media receivers, optionally filtering out ones the user has
   * indicated should be hidden in preferences.
   *
   * @param packageManager The {@code PackageManager} used to retrieve media button receivers.
   * @param filterHidden Whether user-hidden media receivers should be shown.
   * @return The list of {@code ResolveInfo} for different media button receivers.
   */
  public static List<ResolveInfo> getMediaReceivers(
      PackageManager packageManager, boolean filterHidden, Context context) {
    Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);

    List<ResolveInfo> mediaReceivers =
        packageManager.queryBroadcastReceivers(
            mediaButtonIntent,
            PackageManager.GET_INTENT_FILTERS | PackageManager.GET_RESOLVED_FILTER);
    if (filterHidden) {

      String hiddenReceiverIdsString =
          PreferenceManager.getDefaultSharedPreferences(context)
              .getString(Constants.HIDDEN_APPS_KEY, "");
      List<String> hiddenIds = Arrays.asList(hiddenReceiverIdsString.split(","));

      for (int i = mediaReceivers.size() - 1; i >= 0; i--) {
        ResolveInfo mediaReceiverResolveInfo = mediaReceivers.get(i);

        if (hiddenIds.contains(
            getMediaReceiverUniqueID(mediaReceiverResolveInfo, packageManager))) {
          mediaReceivers.remove(i);
        }
      }
    }

    return mediaReceivers;
  }
  private boolean isStkAppInstalled() {
    Intent intent = new Intent(AppInterface.CAT_CMD_ACTION);
    PackageManager pm = mContext.getPackageManager();
    List<ResolveInfo> broadcastReceivers =
        pm.queryBroadcastReceivers(intent, PackageManager.GET_META_DATA);
    int numReceiver = broadcastReceivers == null ? 0 : broadcastReceivers.size();

    return (numReceiver > 0);
  }
 public void toggleState(Context context) {
   PackageManager pm = context.getPackageManager();
   List<ResolveInfo> l =
       pm.queryBroadcastReceivers(new Intent("net.cactii.flash2.TOGGLE_FLASHLIGHT"), 0);
   if (!l.isEmpty()) {
     mContext.sendBroadcast(new Intent("net.cactii.flash2.TOGGLE_FLASHLIGHT"));
   } else {
     Intent intent = new Intent(context, FlashlightActivity.class);
     intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
     intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
     context.startActivity(intent);
   }
 }
 /*
  * Finds a system apk which had a broadcast receiver listening to a particular action.
  * @param action intent action used to find the apk
  * @return a pair of apk package name and the resources.
  */
 static Pair<String, Resources> findSystemApk(String action, PackageManager pm) {
   final Intent intent = new Intent(action);
   for (ResolveInfo info : pm.queryBroadcastReceivers(intent, 0)) {
     if (info.activityInfo != null
         && (info.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
       final String packageName = info.activityInfo.packageName;
       try {
         final Resources res = pm.getResourcesForApplication(packageName);
         return Pair.create(packageName, res);
       } catch (NameNotFoundException e) {
         Log.w(TAG, "Failed to find resources for " + packageName);
       }
     }
   }
   return null;
 }
 private boolean enableVerifierSetting() {
   final ContentResolver cr = getActivity().getContentResolver();
   if (Settings.Global.getInt(cr, Settings.Global.ADB_ENABLED, 0) == 0) {
     return false;
   }
   if (Settings.Global.getInt(cr, Settings.Global.PACKAGE_VERIFIER_ENABLE, 1) == 0) {
     return false;
   } else {
     final PackageManager pm = getActivity().getPackageManager();
     final Intent verification = new Intent(Intent.ACTION_PACKAGE_NEEDS_VERIFICATION);
     verification.setType(PACKAGE_MIME_TYPE);
     verification.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
     final List<ResolveInfo> receivers = pm.queryBroadcastReceivers(verification, 0);
     if (receivers.size() == 0) {
       return false;
     }
   }
   return true;
 }
Esempio n. 9
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    addPreferencesFromResource(R.xml.preferences);

    PackageManager pm = getActivity().getPackageManager();
    Intent mediaIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);

    List<ResolveInfo> mAppsInfo = pm.queryBroadcastReceivers(mediaIntent, 0);
    ListPreference simpleAppListPref = (ListPreference) findPreference("selectapp");
    ListPreference advancedAppListPref = (ListPreference) findPreference("selectadvancedapp");

    ListPreference baudRatePref = (ListPreference) findPreference("baud_rate");

    simpleAppListPref.setOnPreferenceChangeListener(this);
    advancedAppListPref.setOnPreferenceChangeListener(this);

    baudRatePref.setOnPreferenceChangeListener(this);
    baudRatePref.setTitle(baudRatePref.getEntry());

    CharSequence[] mEntries;
    CharSequence[] mEntryValues;

    CharSequence[] mAdvEntries;
    CharSequence[] mAdvEntryValues;

    if (mAppsInfo.size() > 0) {

      mEntries = new CharSequence[mAppsInfo.size()];
      mEntryValues = new CharSequence[mAppsInfo.size()];

      mAdvEntries = new CharSequence[mAppsInfo.size() + 1];
      mAdvEntryValues = new CharSequence[mAppsInfo.size() + 1];

      mAdvEntries[0] = "PodMode";
      mAdvEntryValues[0] = "me.spadival.podmode";

      int i = 0;
      for (ResolveInfo info : mAppsInfo) {
        mEntries[i] = info.activityInfo.applicationInfo.loadLabel(pm);
        mEntryValues[i] = (String) info.activityInfo.packageName;
        mAdvEntries[i + 1] = mEntries[i];
        mAdvEntryValues[i + 1] = mEntryValues[i];
        i++;
      }

      simpleAppListPref.setSelectable(true);
      simpleAppListPref.setEntries(mEntries);
      simpleAppListPref.setEntryValues(mEntryValues);

      advancedAppListPref.setSelectable(true);
      advancedAppListPref.setEntries(mAdvEntries);
      advancedAppListPref.setEntryValues(mAdvEntryValues);

      boolean simpleAppEntryFound = false;

      String simpleAppName = (String) simpleAppListPref.getEntry();

      if (simpleAppName != null) {
        for (i = 0; i < mEntries.length; i++) {
          if (simpleAppName.equals(mEntries[i])) {
            simpleAppEntryFound = true;
          }
        }
      }

      if (!simpleAppEntryFound) simpleAppListPref.setValue((String) mEntryValues[0]);

      simpleAppListPref.setTitle(simpleAppListPref.getEntry());
      try {
        simpleAppListPref.setIcon(pm.getApplicationIcon(simpleAppListPref.getValue()));
      } catch (NameNotFoundException e) {
        e.printStackTrace();
      }

      boolean advancedAppEntryFound = false;
      String advancedAppName = (String) advancedAppListPref.getEntry();

      if (advancedAppName != null) {
        for (i = 0; i < mAdvEntries.length; i++) {
          if (advancedAppName.equals(mAdvEntries[i])) {
            advancedAppEntryFound = true;
          }
        }
      }

      if (!advancedAppEntryFound) advancedAppListPref.setValue((String) mAdvEntryValues[0]);

      advancedAppListPref.setTitle(advancedAppListPref.getEntry());
      try {
        advancedAppListPref.setIcon(pm.getApplicationIcon(advancedAppListPref.getValue()));
      } catch (NameNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

    } else {
      simpleAppListPref.setTitle(R.string.no_media_player);
      simpleAppListPref.setEntries(null);
      simpleAppListPref.setEntryValues(null);
      simpleAppListPref.setEnabled(false);

      mAdvEntries = new CharSequence[1];
      mAdvEntryValues = new CharSequence[1];

      mAdvEntries[0] = "PodMode";
      mAdvEntryValues[0] = "me.spadival.podmode";

      advancedAppListPref.setTitle(mAdvEntries[0]);
      advancedAppListPref.setEntries(mAdvEntries);
      advancedAppListPref.setEntryValues(mAdvEntryValues);
      advancedAppListPref.setEnabled(false);
    }
  }
  /*
   * Handle the result of a sms being sent
   */
  private void handleSmsSent(Intent intent) {
    if (Log.DEBUG) Log.v("SMSReceiver: Handle SMS sent");

    PackageManager pm = getPackageManager();
    Intent sysIntent = null;
    Intent tempIntent;
    List<ResolveInfo> receiverList;
    boolean forwardToSystemApp = true;

    // Search for system messaging app that will receive our "message sent complete" type intent
    tempIntent =
        intent.setClassName(
            SmsMessageSender.MESSAGING_PACKAGE_NAME,
            SmsMessageSender.MESSAGING_RECEIVER_CLASS_NAME);

    tempIntent.setAction(SmsReceiverService.MESSAGE_SENT_ACTION);

    receiverList = pm.queryBroadcastReceivers(tempIntent, 0);

    if (receiverList.size() > 0) {
      if (Log.DEBUG)
        Log.v("SMSReceiver: Found system messaging app - " + receiverList.get(0).toString());
      sysIntent = tempIntent;
    }

    /*
     * No system messaging app was found to forward this intent to, therefore we will need to do
     * the final piece of this ourselves which is basically moving the message to the correct
     * folder depending on the result.
     */
    if (sysIntent == null) {
      forwardToSystemApp = false;
      if (Log.DEBUG)
        Log.v("SMSReceiver: Did not find system messaging app, moving messages directly");

      Uri uri = intent.getData();

      if (mResultCode == Activity.RESULT_OK) {
        SmsMessageSender.moveMessageToFolder(this, uri, SmsMessageSender.MESSAGE_TYPE_SENT);
      } else if ((mResultCode == SmsManager.RESULT_ERROR_RADIO_OFF)
          || (mResultCode == SmsManager.RESULT_ERROR_NO_SERVICE)) {
        SmsMessageSender.moveMessageToFolder(this, uri, SmsMessageSender.MESSAGE_TYPE_QUEUED);
      } else {
        SmsMessageSender.moveMessageToFolder(this, uri, SmsMessageSender.MESSAGE_TYPE_FAILED);
      }
    }

    // Check the result and notify the user using a toast
    if (mResultCode == Activity.RESULT_OK) {
      if (Log.DEBUG) Log.v("SMSReceiver: Message was sent");
      mToastHandler.sendEmptyMessage(TOAST_HANDLER_MESSAGE_SENT);

    } else if ((mResultCode == SmsManager.RESULT_ERROR_RADIO_OFF)
        || (mResultCode == SmsManager.RESULT_ERROR_NO_SERVICE)) {
      if (Log.DEBUG) Log.v("SMSReceiver: Error sending message (will send later)");
      // The system shows a Toast here so no need to show one
      // mToastHandler.sendEmptyMessage(TOAST_HANDLER_MESSAGE_SEND_LATER);

    } else {
      if (Log.DEBUG) Log.v("SMSReceiver: Error sending message");
      // ManageNotification.notifySendFailed(this);
      mToastHandler.sendEmptyMessage(TOAST_HANDLER_MESSAGE_FAILED);
    }

    /*
     * Now let's forward the same intent onto the system app to make sure
     * things there are processed correctly
     */
    //    sysIntent = intent.setClassName(
    //        SmsMessageSender.MMS_PACKAGE_NAME,
    //        SmsMessageSender.MMS_SENT_CLASS_NAME);

    //    Log.v("sysIntent = " + sysIntent.toString());
    //    Log.v("bundle = " + sysIntent.getExtras().toString());

    /*
     * Start the broadcast via PendingIntent so result code is passed over correctly
     */
    if (forwardToSystemApp) {
      try {
        Log.v("SMSReceiver: Broadcasting send complete to system messaging app");
        PendingIntent.getBroadcast(this, 0, sysIntent, 0).send(mResultCode);
      } catch (CanceledException e) {
        e.printStackTrace();
      }
    }
  }
Esempio n. 11
0
  public ApplicationList(Context context) {
    // Get all packages
    PackageManager manager = context.getPackageManager();
    Intent intent = new Intent();

    packages = manager.getInstalledPackages(PackageManager.GET_PERMISSIONS);
    for (int i = 0; i < packages.size(); i++) {
      // actually processed package
      PackageInfo pack = packages.get(i);
      if (pack.applicationInfo.sourceDir.startsWith("/data/app/")
          && !(pack.applicationInfo.packageName.contains("com.google")
              || pack.applicationInfo.packageName.contains(
                  "com.android"))) { // dodawaj tylko jeżeli aplikacja niesystemowa

        // arrays of packages permissions
        String[] permissions = pack.requestedPermissions;
        // application uID
        int uid = pack.applicationInfo.uid;
        // packages Name
        String appName = pack.applicationInfo.packageName;
        // MALWARE PERMISSIONS DETECTION
        if (manager.checkPermission("android.permission.SYSTEM_ALERT_WINDOW", appName)
            == PackageManager.PERMISSION_GRANTED) {
          Log.i("APPLICATION LIST", "WIRUS REGULA NR 7: " + appName);
          AddMalware(appName, context);
        } else if ((manager.checkPermission("android.permission.WRITE_SMS", appName)
                == PackageManager.PERMISSION_GRANTED)
            || (manager.checkPermission("android.permission.SEND_SMS", appName)
                == PackageManager.PERMISSION_GRANTED)) {
          Log.i("APPLICATION LIST", "WIRUS REGULA NR 3: " + appName);
          AddMalware(appName, context);
        }
        // total data sent by the app
        Long sent = TrafficStats.getUidTxBytes(uid) / 1024;
        // total data received by the app
        Long received = TrafficStats.getUidRxBytes(uid) / 1024;
        // apps Icon
        Drawable icon = null;
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
          icon = context.getDrawable(R.drawable.no_image);
        }
        try {
          icon = context.getPackageManager().getApplicationIcon(appName);
        } catch (PackageManager.NameNotFoundException e) {
          e.printStackTrace();
        }
        // get app Broadcast Receivers
        ArrayList<String> broadcastReceivers = new ArrayList<String>();
        intent.setPackage(appName);
        List<ResolveInfo> infos =
            manager.queryBroadcastReceivers(intent, PackageManager.GET_RESOLVED_FILTER);
        for (ResolveInfo info : infos) {
          broadcastReceivers.add(info.filter.getAction(0));
          Log.i(LOG, "BR: " + info.filter.getAction(0));
          if (info.filter.getAction(0).compareTo("android.app.action.DEVICE_ADMIN_ENABLED") == 0) {
            Log.i("APPLICATION LIST", "WIRUS REGULA NR 6: " + appName);
            AddMalware(appName, context);
          }
        }
        // usuwanie duplikatów
        HashSet hs = new HashSet();
        hs.addAll(broadcastReceivers);
        broadcastReceivers.clear();
        broadcastReceivers.addAll(hs);

        ApplicationInfo appInfo =
            new ApplicationInfo(
                uid, appName, sent, received, icon, permissions, broadcastReceivers);
        try {
          applicationInfoList.add(appInfo);
        } catch (NullPointerException e) {
          // Toast.makeText(context, "" + icon, Toast.LENGTH_SHORT).show();
        }

        Collections.sort(
            applicationInfoList,
            new Comparator<ApplicationInfo>() {
              public int compare(ApplicationInfo app1, ApplicationInfo app2) {
                return app2.getTotalDataSent().compareTo(app1.getTotalDataSent());
              }
            });
      }
    }
  }