public void onReceive(Context context, Intent intent) {
          String action = intent.getAction();
          if (Intent.ACTION_PACKAGE_CHANGED.equals(action)
              || Intent.ACTION_PACKAGE_ADDED.equals(action)
              || Intent.ACTION_PACKAGE_REMOVED.equals(action)) {
            // Get the package name from the intent.
            Uri uri = intent.getData();
            final String packageName = uri != null ? uri.getSchemeSpecificPart() : null;
            if (packageName == null) {
              return;
            }

            // Check if icons from the searched package are present.
            // If yes remove them.
            final ArrayList<String> keysToRemove = new ArrayList<String>();
            for (String key : mKeys) {
              if (key.toLowerCase().contains(packageName.toLowerCase())) {
                keysToRemove.add(key);
              }
            }
            for (String key : keysToRemove) {
              Log.d(TAG, "application icon removed for uri= " + key);
              setKeyExcludeRecycle(key);
              removeBitmapFromMemCache(key);
            }
            if (Intent.ACTION_PACKAGE_REMOVED.equals(action)) {
              mayBeRemoveFavoriteEntry(packageName);
            }
          }
        }
Ejemplo n.º 2
0
 @Override
 public void onReceive(Context context, Intent intent) {
   final String action = intent.getAction();
   if (Intent.ACTION_PACKAGE_CHANGED.equals(action)
       || Intent.ACTION_PACKAGE_REMOVED.equals(action)
       || Intent.ACTION_PACKAGE_ADDED.equals(action)) {
     Log.i(TAG, "action: " + action);
     final String packageName = intent.getData().getSchemeSpecificPart();
     final boolean replacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
     int op = PackageUpdatedTask.OP_NONE;
     if (packageName == null || packageName.length() == 0) {
       // they sent us a bad intent
       return;
     }
     if (Intent.ACTION_PACKAGE_CHANGED.equals(action)) {
       op = PackageUpdatedTask.OP_UPDATE;
     } else if (Intent.ACTION_PACKAGE_REMOVED.equals(action)) {
       if (!replacing) {
         op = PackageUpdatedTask.OP_REMOVE;
       }
     } else if (Intent.ACTION_PACKAGE_ADDED.equals(action)) {
       if (!replacing) {
         op = PackageUpdatedTask.OP_ADD;
       } else {
         op = PackageUpdatedTask.OP_UPDATE;
       }
     }
     mHandler.post(new PackageUpdatedTask(op, new String[] {packageName}));
   } else if (Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE.equals(action)) {
     Log.i(TAG, "ACTION_EXTERNAL_APPLICATIONS_AVAILABLE");
     String[] packages = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
     int op = PackageUpdatedTask.OP_ADD;
     mHandler.post(new PackageUpdatedTask(op, packages));
   } else if (Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE.equals(action)) {
     Log.i(TAG, "ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE");
     String[] packages = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
     int op = PackageUpdatedTask.OP_REMOVE;
     mHandler.post(new PackageUpdatedTask(op, packages));
   } else if (Intent.ACTION_TIME_TICK.equals(action)
       || Intent.ACTION_TIME_CHANGED.equals(action)
       || Intent.ACTION_TIMEZONE_CHANGED.equals(action)) {
     timeChanged();
   } else if (FavoritesModel.ACTION_FAVOTITE_UPDATE.equals(action)) {
     Log.i(TAG, "ACTION_FAVOTITE_UPDATE");
     FavoritesData.saveFavoritesToDatabase(mContext);
     FavoritesData.sort();
   }
 }
    @Override
    public void onReceive(Context context, Intent intent) {
      String action = intent.getAction();
      if (Intent.ACTION_PACKAGE_REMOVED.equals(action)) {
        String packageName = intent.getData().getSchemeSpecificPart();
        removeHistoricalRecordsForPackage(packageName);
      }

      mReloadActivities = true;
    }
  @Override
  public void onReceive(@NonNull final Context context, @NonNull final Intent intent) {
    OPFLog.logMethod(context, OPFUtils.toString(intent));

    final OPFPushHelper helper = OPFPush.getHelper();
    final String action = intent.getAction();
    if (Intent.ACTION_PACKAGE_REMOVED.equals(action)) {
      final String providerName = helper.getProviderNameByHostApp(getAppPackage(intent));
      if (providerName == null) {
        return;
      }
      checkCurrentProvider(context, providerName);
    } else if (Intent.ACTION_PACKAGE_REPLACED.equals(action)
        && context.getPackageName().equals(getAppPackage(intent))) {
      OPFLog.d("Application updated.");
      helper.onNeedRetryRegistration();
    }
  }
        @Override
        public void onReceive(Context context, Intent intent) {
          String action = intent.getAction();
          Log.i(TAG, "action = " + action);
          if (DreamConstant.SEND_FILE_ACTION.equals(action)) {
            handleSendFileRequest(intent);
          } else if (Intent.ACTION_PACKAGE_ADDED.equals(action)) {
            AppManager appManager = new AppManager(FileTransferService.this);
            // get install or uninstall app package name
            String packageName = intent.getData().getSchemeSpecificPart();

            // get installed app
            AppInfo appInfo = null;
            try {
              ApplicationInfo info = pm.getApplicationInfo(packageName, 0);
              appInfo = new AppInfo(FileTransferService.this, info);
              appInfo.setPackageName(packageName);
              appInfo.setAppIcon(info.loadIcon(pm));
              appInfo.loadLabel();
              appInfo.loadVersion();
              if (appManager.isMyApp(packageName)) {
                appInfo.setType(AppManager.ZHAOYAN_APP);
              } else if (appManager.isGameApp(packageName)) {
                appInfo.setType(AppManager.GAME_APP);
              } else {
                appInfo.setType(AppManager.NORMAL_APP);
              }
              ContentValues values = appManager.getValuesByAppInfo(appInfo);
              getContentResolver().insert(AppData.App.CONTENT_URI, values);
            } catch (NameNotFoundException e) {
              e.printStackTrace();
            }

          } else if (Intent.ACTION_PACKAGE_REMOVED.equals(action)) {
            // get install or uninstall app package name
            String packageName = intent.getData().getSchemeSpecificPart();
            Uri uri = Uri.parse(AppData.App.CONTENT_URI + "/" + packageName);
            getContentResolver().delete(uri, null, null);
          }
        }
Ejemplo n.º 6
0
  @Override
  public void onReceive(Context context, Intent intent) {
    if (Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())) {
      // Ignore application updates
      final boolean replacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
      if (!replacing) {
        // Update the Firewall if necessary
        final int uid = intent.getIntExtra(Intent.EXTRA_UID, -123);
        Api.applicationRemoved(context, uid);
        // Force app list reload next time
        Api.applications = null;
      }
    } else if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) {
      final boolean appExists = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);

      if (appExists) {
        // do nothing
      } else {
        // Force app list reload next time
        Api.applications = null;
        // check to see if Notifications are enabled
        SharedPreferences prefs = context.getSharedPreferences(Api.PREFS_NAME, 0);
        boolean NotifyEnabled = prefs.getBoolean(Api.PREF_NOTIFY, false);
        if (NotifyEnabled) {
          String new_app_installed = intent.getData().getSchemeSpecificPart();
          if (PackageManager.PERMISSION_GRANTED
              == context
                  .getPackageManager()
                  .checkPermission(Manifest.permission.INTERNET, new_app_installed)) {
            // notify the User that a new app has been installed
            notifyUserOfAppInstall(context, new_app_installed);
          }
        }
      }
    }
  }
Ejemplo n.º 7
0
  @Override
  public void onReceive(Context context, Intent intent) {
    mChangeUserId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL);
    if (mChangeUserId == UserHandle.USER_NULL) {
      throw new IllegalArgumentException(
          "Intent broadcast does not contain user handle: " + intent);
    }
    onBeginPackageChanges();

    mDisappearingPackages = mAppearingPackages = null;
    mSomePackagesChanged = false;

    String action = intent.getAction();
    if (Intent.ACTION_PACKAGE_ADDED.equals(action)) {
      String pkg = getPackageName(intent);
      int uid = intent.getIntExtra(Intent.EXTRA_UID, 0);
      // We consider something to have changed regardless of whether
      // this is just an update, because the update is now finished
      // and the contents of the package may have changed.
      mSomePackagesChanged = true;
      if (pkg != null) {
        mAppearingPackages = mTempArray;
        mTempArray[0] = pkg;
        if (intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
          mModifiedPackages = mTempArray;
          mChangeType = PACKAGE_UPDATING;
          onPackageUpdateFinished(pkg, uid);
          onPackageModified(pkg);
        } else {
          mChangeType = PACKAGE_PERMANENT_CHANGE;
          onPackageAdded(pkg, uid);
        }
        onPackageAppeared(pkg, mChangeType);
        if (mChangeType == PACKAGE_UPDATING) {
          synchronized (mUpdatingPackages) {
            mUpdatingPackages.remove(pkg);
          }
        }
      }
    } else if (Intent.ACTION_PACKAGE_REMOVED.equals(action)) {
      String pkg = getPackageName(intent);
      int uid = intent.getIntExtra(Intent.EXTRA_UID, 0);
      if (pkg != null) {
        mDisappearingPackages = mTempArray;
        mTempArray[0] = pkg;
        if (intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
          mChangeType = PACKAGE_UPDATING;
          synchronized (mUpdatingPackages) {
            // not used for now
            // mUpdatingPackages.add(pkg);
          }
          onPackageUpdateStarted(pkg, uid);
        } else {
          mChangeType = PACKAGE_PERMANENT_CHANGE;
          // We only consider something to have changed if this is
          // not a replace; for a replace, we just need to consider
          // it when it is re-added.
          mSomePackagesChanged = true;
          onPackageRemoved(pkg, uid);
          if (intent.getBooleanExtra(Intent.EXTRA_REMOVED_FOR_ALL_USERS, false)) {
            onPackageRemovedAllUsers(pkg, uid);
          }
        }
        onPackageDisappeared(pkg, mChangeType);
      }
    } else if (Intent.ACTION_PACKAGE_CHANGED.equals(action)) {
      String pkg = getPackageName(intent);
      int uid = intent.getIntExtra(Intent.EXTRA_UID, 0);
      String[] components = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_COMPONENT_NAME_LIST);
      if (pkg != null) {
        mModifiedPackages = mTempArray;
        mTempArray[0] = pkg;
        mChangeType = PACKAGE_PERMANENT_CHANGE;
        if (onPackageChanged(pkg, uid, components)) {
          mSomePackagesChanged = true;
        }
        onPackageModified(pkg);
      }
    } else if (Intent.ACTION_QUERY_PACKAGE_RESTART.equals(action)) {
      mDisappearingPackages = intent.getStringArrayExtra(Intent.EXTRA_PACKAGES);
      mChangeType = PACKAGE_TEMPORARY_CHANGE;
      boolean canRestart =
          onHandleForceStop(
              intent, mDisappearingPackages, intent.getIntExtra(Intent.EXTRA_UID, 0), false);
      if (canRestart) setResultCode(Activity.RESULT_OK);
    } else if (Intent.ACTION_PACKAGE_RESTARTED.equals(action)) {
      mDisappearingPackages = new String[] {getPackageName(intent)};
      mChangeType = PACKAGE_TEMPORARY_CHANGE;
      onHandleForceStop(
          intent, mDisappearingPackages, intent.getIntExtra(Intent.EXTRA_UID, 0), true);
    } else if (Intent.ACTION_UID_REMOVED.equals(action)) {
      onUidRemoved(intent.getIntExtra(Intent.EXTRA_UID, 0));
    } else if (Intent.ACTION_USER_STOPPED.equals(action)) {
      if (intent.hasExtra(Intent.EXTRA_USER_HANDLE)) {
        onHandleUserStop(intent, intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0));
      }
    } else if (Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE.equals(action)) {
      String[] pkgList = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
      mAppearingPackages = pkgList;
      mChangeType = PACKAGE_TEMPORARY_CHANGE;
      mSomePackagesChanged = true;
      if (pkgList != null) {
        onPackagesAvailable(pkgList);
        for (int i = 0; i < pkgList.length; i++) {
          onPackageAppeared(pkgList[i], PACKAGE_TEMPORARY_CHANGE);
        }
      }
    } else if (Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE.equals(action)) {
      String[] pkgList = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
      mDisappearingPackages = pkgList;
      mChangeType = PACKAGE_TEMPORARY_CHANGE;
      mSomePackagesChanged = true;
      if (pkgList != null) {
        onPackagesUnavailable(pkgList);
        for (int i = 0; i < pkgList.length; i++) {
          onPackageDisappeared(pkgList[i], PACKAGE_TEMPORARY_CHANGE);
        }
      }
    }

    if (mSomePackagesChanged) {
      onSomePackagesChanged();
    }

    onFinishPackageChanges();
    mChangeUserId = UserHandle.USER_NULL;
  }
  @Override
  public void onReceive(Context context, Intent intent) {

    PreferencesProviderWrapper prefWrapper = new PreferencesProviderWrapper(context);
    String intentAction = intent.getAction();

    //
    // ACTION_DATA_STATE_CHANGED
    // Data state change is used to detect changes in the mobile
    // network such as a switch of network type (GPRS, EDGE, 3G)
    // which are not detected by the Connectivity changed broadcast.
    //
    //
    // ACTION_CONNECTIVITY_CHANGED
    // Connectivity change is used to detect changes in the overall
    // data network status as well as a switch between wifi and mobile
    // networks.
    //
    if (
    /*intentAction.equals(ACTION_DATA_STATE_CHANGED) ||*/
    intentAction.equals(ConnectivityManager.CONNECTIVITY_ACTION)
        || intentAction.equals(Intent.ACTION_BOOT_COMPLETED)) {

      if (prefWrapper.isValidConnectionForIncoming()
          && !prefWrapper.getPreferenceBooleanValue(PreferencesProviderWrapper.HAS_BEEN_QUIT)) {
        Log.d(THIS_FILE, "Try to start service if not already started");
        Intent sip_service_intent = new Intent(context, SipService.class);
        context.startService(sip_service_intent);
      }

    } else if (intentAction.equals(SipManager.INTENT_SIP_ACCOUNT_ACTIVATE)) {
      context.enforceCallingOrSelfPermission(SipManager.PERMISSION_CONFIGURE_SIP, null);

      long accId;
      accId = intent.getLongExtra(SipProfile.FIELD_ID, SipProfile.INVALID_ID);

      if (accId == SipProfile.INVALID_ID) {
        // allow remote side to send us integers.
        // previous call will warn, but that's fine, no worries
        accId = intent.getIntExtra(SipProfile.FIELD_ID, (int) SipProfile.INVALID_ID);
      }

      if (accId != SipProfile.INVALID_ID) {
        boolean active = intent.getBooleanExtra(SipProfile.FIELD_ACTIVE, true);
        ContentValues cv = new ContentValues();
        cv.put(SipProfile.FIELD_ACTIVE, active);
        int done =
            context
                .getContentResolver()
                .update(
                    ContentUris.withAppendedId(SipProfile.ACCOUNT_ID_URI_BASE, accId),
                    cv,
                    null,
                    null);
        if (done > 0) {
          if (prefWrapper.isValidConnectionForIncoming()) {
            Intent sipServiceIntent = new Intent(context, SipService.class);
            context.startService(sipServiceIntent);
          }
        }
      }
    } else if (Intent.ACTION_PACKAGE_ADDED.equalsIgnoreCase(intentAction)
        || Intent.ACTION_PACKAGE_REMOVED.equalsIgnoreCase(intentAction)) {
      CallHandlerPlugin.clearAvailableCallHandlers();
      RewriterPlugin.clearAvailableRewriters();
      ExtraPlugins.clearDynPlugins();
      PhoneCapabilityTester.deinit();
    } else if (APPLY_NIGHTLY_UPLOAD.equals(intentAction)) {
      NightlyUpdater nu = new NightlyUpdater(context);
      nu.applyUpdate(intent);
    }
  }
    public void onReceive(Context context, Intent intent) {
      final String action = intent.getAction();
      final UserHandleCompat user = UserHandleCompat.myUserHandle();

      if (Intent.ACTION_PACKAGE_CHANGED.equals(action)
          || Intent.ACTION_PACKAGE_REMOVED.equals(action)
          || Intent.ACTION_PACKAGE_ADDED.equals(action)) {
        final String packageName = intent.getData().getSchemeSpecificPart();
        final boolean replacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);

        if (packageName == null || packageName.length() == 0) {
          // they sent us a bad intent
          return;
        }
        if (Intent.ACTION_PACKAGE_CHANGED.equals(action)) {
          for (OnAppsChangedCallbackCompat callback : getCallbacks()) {
            callback.onPackageChanged(packageName, user);
          }
        } else if (Intent.ACTION_PACKAGE_REMOVED.equals(action)) {
          if (!replacing) {
            for (OnAppsChangedCallbackCompat callback : getCallbacks()) {
              callback.onPackageRemoved(packageName, user);
            }
          }
          // else, we are replacing the package, so a PACKAGE_ADDED will be sent
          // later, we will update the package at this time
        } else if (Intent.ACTION_PACKAGE_ADDED.equals(action)) {
          if (!replacing) {
            for (OnAppsChangedCallbackCompat callback : getCallbacks()) {
              callback.onPackageAdded(packageName, user);
            }
          } else {
            for (OnAppsChangedCallbackCompat callback : getCallbacks()) {
              callback.onPackageChanged(packageName, user);
            }
          }
        }
      } else if (Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE.equals(action)) {
        // EXTRA_REPLACING is available Kitkat onwards. For lower devices, it is broadcasted
        // when moving a package or mounting/un-mounting external storage. Assume that
        // it is a replacing operation.
        final boolean replacing =
            intent.getBooleanExtra(
                Intent.EXTRA_REPLACING, Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT);
        String[] packages = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
        for (OnAppsChangedCallbackCompat callback : getCallbacks()) {
          callback.onPackagesAvailable(packages, user, replacing);
        }
      } else if (Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE.equals(action)) {
        // This intent is broadcasted when moving a package or mounting/un-mounting
        // external storage.
        // However on Kitkat this is also sent when a package is being updated, and
        // contains an extra Intent.EXTRA_REPLACING=true for that case.
        // Using false as default for Intent.EXTRA_REPLACING gives correct value on
        // lower devices as the intent is not sent when the app is updating/replacing.
        final boolean replacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
        String[] packages = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
        for (OnAppsChangedCallbackCompat callback : getCallbacks()) {
          callback.onPackagesUnavailable(packages, user, replacing);
        }
      }
    }