Example usage for android.content Intent EXTRA_REPLACING

List of usage examples for android.content Intent EXTRA_REPLACING

Introduction

In this page you can find the example usage for android.content Intent EXTRA_REPLACING.

Prototype

String EXTRA_REPLACING

To view the source code for android.content Intent EXTRA_REPLACING.

Click Source Link

Document

Used as a boolean extra field in android.content.Intent#ACTION_PACKAGE_REMOVED intents to indicate that this is a replacement of the package, so this broadcast will immediately be followed by an add broadcast for a different version of the same package.

Usage

From source file:eu.faircode.adblocker.Receiver.java

@Override
public void onReceive(final Context context, Intent intent) {
    Log.i(TAG, "Received " + intent);
    Util.logExtras(intent);//from w  ww.  jav  a 2  s .co m

    if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) {
        // Application added
        if (!intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
            // Show notification
            if (IAB.isPurchased(ActivityPro.SKU_NOTIFY, context)) {
                int uid = intent.getIntExtra(Intent.EXTRA_UID, -1);
                notifyNewApplication(uid, context);
            }
        }

    } else if (Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())) {
        // Application removed
        Rule.clearCache(context);

        if (intent.getBooleanExtra(Intent.EXTRA_DATA_REMOVED, false)) {
            // Remove settings
            String packageName = intent.getData().getSchemeSpecificPart();
            Log.i(TAG, "Deleting settings package=" + packageName);
            context.getSharedPreferences("wifi", Context.MODE_PRIVATE).edit().remove(packageName).apply();
            context.getSharedPreferences("other", Context.MODE_PRIVATE).edit().remove(packageName).apply();
            context.getSharedPreferences("apply", Context.MODE_PRIVATE).edit().remove(packageName).apply();
            context.getSharedPreferences("screen_wifi", Context.MODE_PRIVATE).edit().remove(packageName)
                    .apply();
            context.getSharedPreferences("screen_other", Context.MODE_PRIVATE).edit().remove(packageName)
                    .apply();
            context.getSharedPreferences("roaming", Context.MODE_PRIVATE).edit().remove(packageName).apply();
            context.getSharedPreferences("notify", Context.MODE_PRIVATE).edit().remove(packageName).apply();

            int uid = intent.getIntExtra(Intent.EXTRA_UID, 0);
            if (uid > 0) {
                NotificationManagerCompat.from(context).cancel(uid); // installed notification
                NotificationManagerCompat.from(context).cancel(uid + 10000); // access notification
            }
        }

    } else {
        // Upgrade settings
        upgrade(true, context);

        // Start service
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        try {
            if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
                if (prefs.getBoolean("enabled", false) || prefs.getBoolean("show_stats", false))
                    ServiceSinkhole.start("receiver", context);

            } else if (Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction())) {
                if (prefs.getBoolean("enabled", false))
                    ServiceSinkhole.start("receiver", context);
                else if (prefs.getBoolean("show_stats", false))
                    ServiceSinkhole.run("receiver", context);
            }
        } catch (Throwable ex) {
            Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
            Util.sendCrashReport(ex, context);
        }

        if (Util.isInteractive(context))
            ServiceSinkhole.reloadStats("receiver", context);
    }
}

From source file:com.zhengde163.netguard.Receiver.java

@Override
public void onReceive(final Context context, Intent intent) {
    Log.i(TAG, "Received " + intent);
    Util.logExtras(intent);/*  w w w.  j a  v  a  2s.  c  om*/

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

    if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) {
        // Application added
        if (!intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
            // Show notification
            if (prefs.getBoolean("install", true)) {
                int uid = intent.getIntExtra(Intent.EXTRA_UID, -1);
                notifyNewApplication(uid, context);
            }
        }

    } else if (Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())) {
        // Application removed
        Rule.clearCache(context);

        if (intent.getBooleanExtra(Intent.EXTRA_DATA_REMOVED, false)) {
            // Remove settings
            String packageName = intent.getData().getSchemeSpecificPart();
            Log.i(TAG, "Deleting settings package=" + packageName);
            context.getSharedPreferences("wifi", Context.MODE_PRIVATE).edit().remove(packageName).apply();
            context.getSharedPreferences("other", Context.MODE_PRIVATE).edit().remove(packageName).apply();
            context.getSharedPreferences("apply", Context.MODE_PRIVATE).edit().remove(packageName).apply();
            context.getSharedPreferences("screen_wifi", Context.MODE_PRIVATE).edit().remove(packageName)
                    .apply();
            context.getSharedPreferences("screen_other", Context.MODE_PRIVATE).edit().remove(packageName)
                    .apply();
            context.getSharedPreferences("roaming", Context.MODE_PRIVATE).edit().remove(packageName).apply();
            context.getSharedPreferences("notify", Context.MODE_PRIVATE).edit().remove(packageName).apply();

            int uid = intent.getIntExtra(Intent.EXTRA_UID, 0);
            if (uid > 0) {
                DatabaseHelper.getInstance(context).clearAccess(uid, false);

                NotificationManagerCompat.from(context).cancel(uid); // installed notification
                NotificationManagerCompat.from(context).cancel(uid + 10000); // access notification
            }
        }

    } else {
        // Upgrade settings
        upgrade(true, context);

        // Start service
        try {
            if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
                if (prefs.getBoolean("enabled", false) || prefs.getBoolean("show_stats", false))
                    ServiceSinkhole.start("receiver", context);

            } else if (Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction())) {
                if (prefs.getBoolean("enabled", false))
                    ServiceSinkhole.start("receiver", context);
                else if (prefs.getBoolean("show_stats", false))
                    ServiceSinkhole.run("receiver", context);
            }
        } catch (Throwable ex) {
            Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
            Util.sendCrashReport(ex, context);
        }

        if (Util.isInteractive(context))
            ServiceSinkhole.reloadStats("receiver", context);
    }
}

From source file:eu.faircode.netguard.Receiver.java

@Override
public void onReceive(final Context context, Intent intent) {
    Log.i(TAG, "Received " + intent);
    Util.logExtras(intent);/*from w  ww .jav a2s .c  o  m*/

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

    if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) {
        // Application added
        if (!intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
            // Show notification
            if (IAB.isPurchased(ActivityPro.SKU_NOTIFY, context) && prefs.getBoolean("install", true)) {
                int uid = intent.getIntExtra(Intent.EXTRA_UID, -1);
                notifyNewApplication(uid, context);
            }
        }

    } else if (Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())) {
        // Application removed
        Rule.clearCache(context);

        if (intent.getBooleanExtra(Intent.EXTRA_DATA_REMOVED, false)) {
            // Remove settings
            String packageName = intent.getData().getSchemeSpecificPart();
            Log.i(TAG, "Deleting settings package=" + packageName);
            context.getSharedPreferences("wifi", Context.MODE_PRIVATE).edit().remove(packageName).apply();
            context.getSharedPreferences("other", Context.MODE_PRIVATE).edit().remove(packageName).apply();
            context.getSharedPreferences("apply", Context.MODE_PRIVATE).edit().remove(packageName).apply();
            context.getSharedPreferences("screen_wifi", Context.MODE_PRIVATE).edit().remove(packageName)
                    .apply();
            context.getSharedPreferences("screen_other", Context.MODE_PRIVATE).edit().remove(packageName)
                    .apply();
            context.getSharedPreferences("roaming", Context.MODE_PRIVATE).edit().remove(packageName).apply();
            context.getSharedPreferences("notify", Context.MODE_PRIVATE).edit().remove(packageName).apply();

            int uid = intent.getIntExtra(Intent.EXTRA_UID, 0);
            if (uid > 0) {
                DatabaseHelper.getInstance(context).clearAccess(uid, false);

                NotificationManagerCompat.from(context).cancel(uid); // installed notification
                NotificationManagerCompat.from(context).cancel(uid + 10000); // access notification
            }
        }

    } else {
        // Upgrade settings
        upgrade(true, context);

        // Start service
        try {
            if (prefs.getBoolean("enabled", false))
                ServiceSinkhole.start("receiver", context);
            else if (prefs.getBoolean("show_stats", false))
                ServiceSinkhole.run("receiver", context);
        } catch (Throwable ex) {
            Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
        }

        if (Util.isInteractive(context))
            ServiceSinkhole.reloadStats("receiver", context);
    }
}

From source file:com.master.metehan.filtereagle.Receiver.java

@Override
public void onReceive(final Context context, Intent intent) {
    Log.i(TAG, "Received " + intent);
    Util.logExtras(intent);//from  ww w . ja v a2  s.  c o  m

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

    if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) {
        // Application added
        if (!intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
            // Show notification
            if (IAB.isPurchased(ActivityPro.SKU_NOTIFY, context) && prefs.getBoolean("install", true)) {
                int uid = intent.getIntExtra(Intent.EXTRA_UID, -1);
                notifyNewApplication(uid, context);
            }
        }

    } else if (Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())) {
        // Application removed
        Rule.clearCache(context);

        if (intent.getBooleanExtra(Intent.EXTRA_DATA_REMOVED, false)) {
            // Remove settings
            String packageName = intent.getData().getSchemeSpecificPart();
            Log.i(TAG, "Deleting settings package=" + packageName);
            context.getSharedPreferences("wifi", Context.MODE_PRIVATE).edit().remove(packageName).apply();
            context.getSharedPreferences("other", Context.MODE_PRIVATE).edit().remove(packageName).apply();
            context.getSharedPreferences("apply", Context.MODE_PRIVATE).edit().remove(packageName).apply();
            context.getSharedPreferences("screen_wifi", Context.MODE_PRIVATE).edit().remove(packageName)
                    .apply();
            context.getSharedPreferences("screen_other", Context.MODE_PRIVATE).edit().remove(packageName)
                    .apply();
            context.getSharedPreferences("roaming", Context.MODE_PRIVATE).edit().remove(packageName).apply();
            context.getSharedPreferences("notify", Context.MODE_PRIVATE).edit().remove(packageName).apply();

            int uid = intent.getIntExtra(Intent.EXTRA_UID, 0);
            if (uid > 0) {
                DatabaseHelper.getInstance(context).clearAccess(uid, false);

                NotificationManagerCompat.from(context).cancel(uid); // installed notification
                NotificationManagerCompat.from(context).cancel(uid + 10000); // access notification
            }
        }

    } else {
        // Upgrade settings
        upgrade(true, context);

        // Start service
        try {
            if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
                if (prefs.getBoolean("enabled", false) || prefs.getBoolean("show_stats", false))
                    ServiceSinkhole.start("receiver", context);

            } else if (Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction())) {
                if (prefs.getBoolean("enabled", false))
                    ServiceSinkhole.start("receiver", context);
                else if (prefs.getBoolean("show_stats", false))
                    ServiceSinkhole.run("receiver", context);
            }
        } catch (Throwable ex) {
            Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
            Util.sendCrashReport(ex, context);
        }

        if (Util.isInteractive(context))
            ServiceSinkhole.reloadStats("receiver", context);
    }
}

From source file:android_network.hetnet.vpn_service.Receiver.java

@Override
public void onReceive(final Context context, Intent intent) {
    Log.i(TAG, "Received " + intent);
    Util.logExtras(intent);//from w w  w . j  av a 2s .  c o  m

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

    if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) {
        // Application added
        if (!intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
            // Show notification
            if (true) {
                int uid = intent.getIntExtra(Intent.EXTRA_UID, -1);
                notifyNewApplication(uid, context);
            }
        }

    } else if (Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())) {
        // Application removed
        Rule.clearCache(context);

        if (intent.getBooleanExtra(Intent.EXTRA_DATA_REMOVED, false)) {
            // Remove settings
            String packageName = intent.getData().getSchemeSpecificPart();
            Log.i(TAG, "Deleting settings package=" + packageName);
            context.getSharedPreferences("wifi", Context.MODE_PRIVATE).edit().remove(packageName).apply();
            context.getSharedPreferences("other", Context.MODE_PRIVATE).edit().remove(packageName).apply();
            context.getSharedPreferences("apply", Context.MODE_PRIVATE).edit().remove(packageName).apply();
            context.getSharedPreferences("screen_wifi", Context.MODE_PRIVATE).edit().remove(packageName)
                    .apply();
            context.getSharedPreferences("screen_other", Context.MODE_PRIVATE).edit().remove(packageName)
                    .apply();
            context.getSharedPreferences("roaming", Context.MODE_PRIVATE).edit().remove(packageName).apply();
            context.getSharedPreferences("notify", Context.MODE_PRIVATE).edit().remove(packageName).apply();

            int uid = intent.getIntExtra(Intent.EXTRA_UID, 0);
            if (uid > 0) {
                DatabaseHelper.getInstance(context).clearAccess(uid, false);

                NotificationManagerCompat.from(context).cancel(uid); // installed notification
                NotificationManagerCompat.from(context).cancel(uid + 10000); // access notification
            }
        }

    } else {
        // Upgrade settings
        upgrade(true, context);

        // Start service
        try {
            if (prefs.getBoolean("enabled", false))
                ServiceSinkhole.start("receiver", context);
            else if (prefs.getBoolean("show_stats", false))
                ServiceSinkhole.run("receiver", context);
        } catch (Throwable ex) {
            Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
        }

        if (Util.isInteractive(context))
            ServiceSinkhole.reloadStats("receiver", context);
    }
}

From source file:dev.ukanth.ufirewall.PackageBroadcast.java

@Override
public void onReceive(Context context, Intent intent) {

    Uri inputUri = Uri.parse(intent.getDataString());

    if (!inputUri.getScheme().equals("package")) {
        Log.d("AFWall+", "Intent scheme was not 'package'");
        return;/*from  ww  w.  j a v  a  2s .c  o  m*/
    }

    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);
            /*Api.applicationRemoved(context,
             inputUri.getSchemeSpecificPart());*/
            // Force app list reload next time
            Api.applications = null;
        }
    } else if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) {

        final boolean updateApp = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);

        if (updateApp) {
            // dont do anything
            //1 check the package already added in firewall

        } else {
            // Force app list reload next time
            Api.applications = null;
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
            boolean isNotify = prefs.getBoolean("notifyAppInstall", false);
            if (isNotify && Api.isEnabled(context)) {
                String added_package = intent.getData().getSchemeSpecificPart();
                if (PackageManager.PERMISSION_GRANTED == context.getPackageManager()
                        .checkPermission(Manifest.permission.INTERNET, added_package)) {
                    notifyApp(context, intent, added_package);
                }
            }
        }

    }
}

From source file:dev.ukanth.ufirewall.broadcast.PackageBroadcast.java

@Override
public void onReceive(Context context, Intent intent) {

    Uri inputUri = Uri.parse(intent.getDataString());

    if (!inputUri.getScheme().equals("package")) {
        Log.d("AFWall+", "Intent scheme was not 'package'");
        return;//w  w w  . ja v a 2  s. c om
    }

    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);
            Api.removeCacheLabel(intent.getData().getSchemeSpecificPart(), context);
            // Force app list reload next time
            Api.applications = null;
        }
    } else if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) {

        final boolean updateApp = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);

        if (updateApp) {
            // dont do anything
            //1 check the package already added in firewall

        } else {
            // Force app list reload next time
            Api.applications = null;
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
            boolean isNotify = prefs.getBoolean("notifyAppInstall", false);
            if (isNotify && Api.isEnabled(context)) {
                String added_package = intent.getData().getSchemeSpecificPart();
                final PackageManager pkgmanager = context.getPackageManager();
                String label = null;
                try {
                    label = pkgmanager.getApplicationLabel(pkgmanager.getApplicationInfo(added_package, 0))
                            .toString();
                } catch (NameNotFoundException e) {
                }
                if (PackageManager.PERMISSION_GRANTED == pkgmanager
                        .checkPermission(Manifest.permission.INTERNET, added_package)) {
                    notifyApp(context, intent, label);
                }
            }
        }
    }
}

From source file:net.digitalfeed.pdroidalternative.intenthandler.PackageChangeHandler.java

@Override
public void onReceive(Context context, Intent intent) {
    Log.d("PDroidAlternative", "PackageChangeHandler event received");
    //Get the package name. If this fails, then the intent didn't contain the
    //essential data and should be ignored
    String packageName;/*from w  ww .  j  a  v a  2 s  .co  m*/
    Uri inputUri = Uri.parse(intent.getDataString());
    if (!inputUri.getScheme().equals("package")) {
        Log.d("PDroidAlternative", "Intent scheme was not 'package'");
        return;
    }
    packageName = inputUri.getSchemeSpecificPart();

    //If a package is being removed, we only want to delete the related
    //info it is not being updated/replaced by a newer version
    if (intent.getAction().equals(Intent.ACTION_PACKAGE_REMOVED)) {
        if (!intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
            Log.d("PDroidAlternative", "Triggering application deletion for package:" + packageName);
            DBInterface.getInstance(context).deleteApplicationRecord(packageName);
        }
    } else if (intent.getAction().equals(Intent.ACTION_PACKAGE_ADDED)) {
        //If the package is just getting updated, then we only need to notify the user
        //if the permissions have changed

        if (intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
            //TODO: check if the permissions have changed
            Log.d("PDroidAlternative", "PackageChangeHandler: App being replaced: " + packageName);
            Application oldApp = Application.fromDatabase(context, packageName);
            Application newApp = Application.fromPackageName(context, packageName);
            if (havePermissionsChanged(context, oldApp, newApp)) {
                //TODO: Handle permission change
                /*
                 * This is an app for which the permissions have been updated, 
                 * so we need to update the database to include only correct permissions.
                 * Maybe we should have some way of flagging new ones?
                 */
                newApp.setStatusFlags(
                        (newApp.getStatusFlags() | oldApp.getStatusFlags() | Application.STATUS_FLAG_UPDATED)
                                & ~Application.STATUS_FLAG_NEW);
                DBInterface.getInstance(context).updateApplicationRecord(newApp);
                displayNotification(context, NotificationType.update, packageName,
                        DBInterface.getInstance(context).getApplicationLabel(packageName));
            }
        } else {
            /*
             * This is a new app, not an app being replaced. We need to add it to the
             * database, then display a notification for it
             */
            Log.d("PDroidAlternative", "PackageChangeHandler: New app added: " + packageName);
            /*
             * I'm not sure if we really want to be doing all this processing here, but
             * we do need to record a list of new/updated apps to write to the database
             * when the app next starts, or the intent is executed - or we do it now
             */
            //get the application from the system, not from the database
            Application app = Application.fromPackageName(context, packageName);
            app.setStatusFlags(app.getStatusFlags() | Application.STATUS_FLAG_NEW);
            DBInterface.getInstance(context).addApplicationRecord(app);
            Log.d("PDroidAlternative", "PackageChangeHandler: New app record added: " + packageName);
            displayNotification(context, NotificationType.newinstall, packageName, app.getLabel());
            Log.d("PDroidAlternative", "PackageChangeHandler: Notification presented: " + packageName);
        }
    }
}

From source file:me.piebridge.prevent.framework.SystemReceiver.java

protected void onPackageAdded(Intent intent) {
    String packageName = PackageUtils.getPackageName(intent);
    SafeActionUtils.onPackageChanged(packageName);
    if (BuildConfig.APPLICATION_ID.equals(packageName)
            && !intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
        SystemHook.setSupported(true);/*ww  w . j  av a2s . co m*/
        PreventListUtils.getInstance().save(mContext, mPreventPackages.keySet(), false);
        Configuration configuration = new Configuration(new Bundle());
        configuration.setForceStopTimeout(forceStopTimeout);
        configuration.setDestroyProcesses(SystemHook.isDestroyProcesses());
        configuration.setLockSyncSettings(SystemHook.isLockSyncSettings());
        configuration.setAutoPrevent(autoPrevent);
        configuration.setStopSignatureApps(SystemHook.isStopSignatureApps());
        configuration.setUseAppStandby(SystemHook.isUseAppStandby());
        PreventListUtils.getInstance().save(mContext, configuration, false);
    } else if (!intent.getBooleanExtra(Intent.EXTRA_REPLACING, false) && autoPrevent) {
        mPreventPackages.put(packageName, true);
        showUpdated(packageName, mPreventPackages.size());
        PreventListUtils.getInstance().save(mContext, mPreventPackages.keySet(), true);
    }
}

From source file:me.piebridge.prevent.framework.SystemReceiver.java

protected void onPackageRemoved(Intent intent) {
    String packageName = PackageUtils.getPackageName(intent);
    SafeActionUtils.onPackageChanged(packageName);
    onPackageRemoved(packageName);// w  w w.  j  a v a  2s. com
    if (BuildConfig.APPLICATION_ID.equals(packageName)
            && !intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
        SystemHook.setSupported(false);
        PreventListUtils.getInstance().onRemoved(mContext);
    } else if (!intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
        mPreventPackages.remove(packageName);
        PreventListUtils.getInstance().save(mContext, mPreventPackages.keySet(), true);
    }
}