Java Code Examples for android.content.Intent#ACTION_PACKAGE_REMOVED

The following examples show how to use android.content.Intent#ACTION_PACKAGE_REMOVED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeviceIdleController.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override public void onReceive(Context context, Intent intent) {
    switch (intent.getAction()) {
        case ConnectivityManager.CONNECTIVITY_ACTION: {
            updateConnectivityState(intent);
        } break;
        case Intent.ACTION_BATTERY_CHANGED: {
            synchronized (DeviceIdleController.this) {
                int plugged = intent.getIntExtra("plugged", 0);
                updateChargingLocked(plugged != 0);
            }
        } break;
        case Intent.ACTION_PACKAGE_REMOVED: {
            if (!intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
                Uri data = intent.getData();
                String ssp;
                if (data != null && (ssp = data.getSchemeSpecificPart()) != null) {
                    removePowerSaveWhitelistAppInternal(ssp);
                }
            }
        } break;
    }
}
 
Example 2
Source File: SliceManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    final int userId  = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL);
    if (userId == UserHandle.USER_NULL) {
        Slog.w(TAG, "Intent broadcast does not contain user handle: " + intent);
        return;
    }
    Uri data = intent.getData();
    String pkg = data != null ? data.getSchemeSpecificPart() : null;
    if (pkg == null) {
        Slog.w(TAG, "Intent broadcast does not contain package name: " + intent);
        return;
    }
    switch (intent.getAction()) {
        case Intent.ACTION_PACKAGE_REMOVED:
            final boolean replacing =
                    intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
            if (!replacing) {
                mPermissions.removePkg(pkg, userId);
            }
            break;
        case Intent.ACTION_PACKAGE_DATA_CLEARED:
            mPermissions.removePkg(pkg, userId);
            break;
    }
}
 
Example 3
Source File: WeChatDecorator.java    From decorator-wechat with Apache License 2.0 6 votes vote down vote up
@Override public void onCreate() {
	super.onCreate();
	final Context context = SDK_INT >= N ? createDeviceProtectedStorageContext() : this;
	//noinspection deprecation
	mPreferences = context.getSharedPreferences(PREFERENCES_NAME, MODE_MULTI_PROCESS);
	migrateFromLegacyPreferences();		// TODO: Remove this IO-blocking migration code (created in Aug, 2019).
	mPrefKeyWear = getString(R.string.pref_wear);

	mMessagingBuilder = new MessagingBuilder(this, new MessagingBuilder.Controller() {
		@Override public void recastNotification(final String key, final Bundle addition) {
			WeChatDecorator.this.recastNotification(key, addition);
		}
		@Override public Conversation getConversation(final int id) {
			return mConversationManager.getConversation(id);
		}
	});	// Must be called after loadPreferences().
	final IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_REMOVED); filter.addDataScheme("package");
	registerReceiver(mPackageEventReceiver, filter);
	registerReceiver(mSettingsChangedReceiver, new IntentFilter(ACTION_SETTINGS_CHANGED));
}
 
Example 4
Source File: GlobalInstallReceiver.java    From YalpStore with GNU General Public License v2.0 6 votes vote down vote up
static private ChangelogTask getEventTask(Context context, String packageName, String action) {
    App app = YalpStoreApplication.installedPackages.get(packageName);
    if (null == app) {
        app = new App();
        app.setPackageInfo(new PackageInfo());
        app.getPackageInfo().packageName = packageName;
    }
    ChangelogTask task = new ChangelogTask();
    task.setContext(context);
    task.setApp(app);
    switch (action) {
        case ACTION_PACKAGE_INSTALLATION_FAILED:
            task.setEventType(Event.TYPE.INSTALLATION, false);
            break;
        case Intent.ACTION_PACKAGE_FULLY_REMOVED:
        case Intent.ACTION_PACKAGE_REMOVED:
            task.setEventType(Event.TYPE.REMOVAL, true);
            break;
        case Intent.ACTION_PACKAGE_INSTALL:
        case Intent.ACTION_PACKAGE_ADDED:
        case Intent.ACTION_PACKAGE_REPLACED:
            task.setEventType(app.getInstalledVersionCode() > 0 ? Event.TYPE.UPDATE : Event.TYPE.INSTALLATION, true);
            break;
    }
    return task;
}
 
Example 5
Source File: InstalledIntentService.java    From aptoide-client-v8 with GNU General Public License v3.0 6 votes vote down vote up
@Override protected void onHandleIntent(Intent intent) {
  if (intent != null) {
    final String action = intent.getAction();
    final String packageName = intent.getData()
        .getEncodedSchemeSpecificPart();

    if (!TextUtils.equals(action, Intent.ACTION_PACKAGE_REPLACED) && intent.getBooleanExtra(
        Intent.EXTRA_REPLACING, false)) {
      // do nothing if its a replacement ongoing. we are only interested in
      // already replaced apps
      return;
    }

    switch (action) {
      case Intent.ACTION_PACKAGE_ADDED:
        onPackageAdded(packageName);
        break;
      case Intent.ACTION_PACKAGE_REPLACED:
        onPackageReplaced(packageName);
        break;
      case Intent.ACTION_PACKAGE_REMOVED:
        onPackageRemoved(packageName);
        break;
    }
  }
}
 
Example 6
Source File: KeyChainSystemService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void onStart() {
    IntentFilter packageFilter = new IntentFilter(Intent.ACTION_PACKAGE_REMOVED);
    packageFilter.addDataScheme("package");
    try {
        getContext().registerReceiverAsUser(mPackageReceiver, UserHandle.ALL,
                packageFilter, null /*broadcastPermission*/, null /*handler*/);
    } catch (RuntimeException e) {
        Slog.w(TAG, "Unable to register for package removed broadcast", e);
    }
}
 
Example 7
Source File: MediaUpdateService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void registerBroadcastReceiver() {
    BroadcastReceiver updateReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                if (intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_SYSTEM)
                        != UserHandle.USER_SYSTEM) {
                    // Ignore broadcast for non system users. We don't want to update system
                    // service multiple times.
                    return;
                }
                switch (intent.getAction()) {
                    case Intent.ACTION_PACKAGE_REMOVED:
                        if (intent.getExtras().getBoolean(Intent.EXTRA_REPLACING)) {
                            // The existing package is updated. Will be handled with the
                            // following ACTION_PACKAGE_ADDED case.
                            return;
                        }
                        packageStateChanged();
                        break;
                    case Intent.ACTION_PACKAGE_CHANGED:
                        packageStateChanged();
                        break;
                    case Intent.ACTION_PACKAGE_ADDED:
                        packageStateChanged();
                        break;
                }
            }
    };
    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_PACKAGE_ADDED);
    filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
    filter.addDataScheme("package");
    filter.addDataSchemeSpecificPart(MEDIA_UPDATE_PACKAGE_NAME, PatternMatcher.PATTERN_LITERAL);

    getContext().registerReceiverAsUser(updateReceiver, UserHandle.ALL, filter,
            null /* broadcast permission */, null /* handler */);
}
 
Example 8
Source File: Vpn.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    final Uri data = intent.getData();
    final String packageName = data == null ? null : data.getSchemeSpecificPart();
    if (packageName == null) {
        return;
    }

    synchronized (Vpn.this) {
        // Avoid race where always-on package has been unset
        if (!packageName.equals(getAlwaysOnPackage())) {
            return;
        }

        final String action = intent.getAction();
        Log.i(TAG, "Received broadcast " + action + " for always-on VPN package "
                + packageName + " in user " + mUserHandle);

        switch(action) {
            case Intent.ACTION_PACKAGE_REPLACED:
                // Start vpn after app upgrade
                startAlwaysOnVpn();
                break;
            case Intent.ACTION_PACKAGE_REMOVED:
                final boolean isPackageRemoved = !intent.getBooleanExtra(
                        Intent.EXTRA_REPLACING, false);
                if (isPackageRemoved) {
                    setAlwaysOnPackage(null, false);
                }
                break;
        }
    }
}
 
Example 9
Source File: AppStateReceiver.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
@Override
    public void onReceive(Context context, Intent intent) {
        try {
            String action = intent.getAction();
            // 打印当前触发的广播
            LogPrintUtils.dTag(TAG, "onReceive Action: " + action);
            // 被操作应用包名
            String packageName = null;
            Uri uri = intent.getData();
            if (uri != null) {
//                packageName = uri.toString();
                packageName = uri.getEncodedSchemeSpecificPart();
            }
            // 判断类型
            switch (action) {
                case Intent.ACTION_PACKAGE_ADDED: // 应用安装
                    if (sListener != null) {
                        sListener.onAdded(packageName);
                    }
                    break;
                case Intent.ACTION_PACKAGE_REPLACED: // 应用更新
                    if (sListener != null) {
                        sListener.onReplaced(packageName);
                    }
                    break;
                case Intent.ACTION_PACKAGE_REMOVED: // 应用卸载
                    if (sListener != null) {
                        sListener.onRemoved(packageName);
                    }
                    break;
            }
        } catch (Exception e) {
            LogPrintUtils.eTag(TAG, e, "onReceive");
        }
    }
 
Example 10
Source File: ApplicationStateListener.java    From product-emm with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, final Intent intent) {
    String status = null;
    ApplicationStatus applicationState;
    switch (intent.getAction()) {
        case Intent.ACTION_PACKAGE_ADDED:
            status = "added";
            break;
        case Intent.ACTION_PACKAGE_REMOVED:
            status = "removed";
            break;
        case Intent.ACTION_PACKAGE_REPLACED:
            status = "upgraded";
            break;
        case Intent.ACTION_PACKAGE_DATA_CLEARED:
            status = "dataCleared";
            break;
        default:
            Log.i(TAG, "Invalid intent received");
    }
    if (status != null) {
        String packageName = intent.getData().getEncodedSchemeSpecificPart();
        applicationState = new ApplicationStatus();
        applicationState.setState(status);
        applicationState.setPackageName(packageName);
        try {
            String appState = CommonUtils.toJSON(applicationState);
            publishEvent(appState, Constants.EventListeners.APPLICATION_STATE);
            if (Constants.DEBUG_MODE_ENABLED) {
                Log.d(TAG, appState);
            }
        } catch (AndroidAgentException e) {
            Log.e(TAG, "Could not convert to JSON");
        }
    }
}
 
Example 11
Source File: WebViewUpdateService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public void onStart() {
    mWebViewUpdatedReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL);
                switch (intent.getAction()) {
                    case Intent.ACTION_PACKAGE_REMOVED:
                        // When a package is replaced we will receive two intents, one
                        // representing the removal of the old package and one representing the
                        // addition of the new package.
                        // In the case where we receive an intent to remove the old version of
                        // the package that is being replaced we early-out here so that we don't
                        // run the update-logic twice.
                        if (intent.getExtras().getBoolean(Intent.EXTRA_REPLACING)) return;
                        mImpl.packageStateChanged(packageNameFromIntent(intent),
                                PACKAGE_REMOVED, userId);
                        break;
                    case Intent.ACTION_PACKAGE_CHANGED:
                        // Ensure that we only heed PACKAGE_CHANGED intents if they change an
                        // entire package, not just a component
                        if (entirePackageChanged(intent)) {
                            mImpl.packageStateChanged(packageNameFromIntent(intent),
                                    PACKAGE_CHANGED, userId);
                        }
                        break;
                    case Intent.ACTION_PACKAGE_ADDED:
                        mImpl.packageStateChanged(packageNameFromIntent(intent),
                                (intent.getExtras().getBoolean(Intent.EXTRA_REPLACING)
                                 ? PACKAGE_ADDED_REPLACED : PACKAGE_ADDED), userId);
                        break;
                    case Intent.ACTION_USER_STARTED:
                        mImpl.handleNewUser(userId);
                        break;
                    case Intent.ACTION_USER_REMOVED:
                        mImpl.handleUserRemoved(userId);
                        break;
                }
            }
    };
    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_PACKAGE_ADDED);
    filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
    filter.addDataScheme("package");
    // Make sure we only receive intents for WebView packages from our config file.
    for (WebViewProviderInfo provider : mImpl.getWebViewPackages()) {
        filter.addDataSchemeSpecificPart(provider.packageName, PatternMatcher.PATTERN_LITERAL);
    }

    getContext().registerReceiverAsUser(mWebViewUpdatedReceiver, UserHandle.ALL, filter,
            null /* broadcast permission */, null /* handler */);

    IntentFilter userAddedFilter = new IntentFilter();
    userAddedFilter.addAction(Intent.ACTION_USER_STARTED);
    userAddedFilter.addAction(Intent.ACTION_USER_REMOVED);
    getContext().registerReceiverAsUser(mWebViewUpdatedReceiver, UserHandle.ALL,
            userAddedFilter, null /* broadcast permission */, null /* handler */);

    publishBinderService("webviewupdate", new BinderService(), true /*allowIsolated*/);
}
 
Example 12
Source File: ShortcutService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    final int userId  = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL);
    if (userId == UserHandle.USER_NULL) {
        Slog.w(TAG, "Intent broadcast does not contain user handle: " + intent);
        return;
    }

    final String action = intent.getAction();

    // This is normally called on Handler, so clearCallingIdentity() isn't needed,
    // but we still check it in unit tests.
    final long token = injectClearCallingIdentity();
    try {
        synchronized (mLock) {
            if (!isUserUnlockedL(userId)) {
                if (DEBUG) {
                    Slog.d(TAG, "Ignoring package broadcast " + action
                            + " for locked/stopped user " + userId);
                }
                return;
            }

            // Whenever we get one of those package broadcasts, or get
            // ACTION_PREFERRED_ACTIVITY_CHANGED, we purge the default launcher cache.
            final ShortcutUser user = getUserShortcutsLocked(userId);
            user.clearLauncher();
        }
        if (Intent.ACTION_PREFERRED_ACTIVITY_CHANGED.equals(action)) {
            // Nothing farther to do.
            return;
        }

        final Uri intentUri = intent.getData();
        final String packageName = (intentUri != null) ? intentUri.getSchemeSpecificPart()
                : null;
        if (packageName == null) {
            Slog.w(TAG, "Intent broadcast does not contain package name: " + intent);
            return;
        }

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

        switch (action) {
            case Intent.ACTION_PACKAGE_ADDED:
                if (replacing) {
                    handlePackageUpdateFinished(packageName, userId);
                } else {
                    handlePackageAdded(packageName, userId);
                }
                break;
            case Intent.ACTION_PACKAGE_REMOVED:
                if (!replacing) {
                    handlePackageRemoved(packageName, userId);
                }
                break;
            case Intent.ACTION_PACKAGE_CHANGED:
                handlePackageChanged(packageName, userId);

                break;
            case Intent.ACTION_PACKAGE_DATA_CLEARED:
                handlePackageDataCleared(packageName, userId);
                break;
        }
    } catch (Exception e) {
        wtf("Exception in mPackageMonitor.onReceive", e);
    } finally {
        injectRestoreCallingIdentity(token);
    }
}
 
Example 13
Source File: AppOperationReceiver.java    From TvLauncher with Apache License 2.0 4 votes vote down vote up
public void register(Context ctx) {
    IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_REMOVED);
    filter.addDataScheme("package");
    ctx.registerReceiver(this, filter);
    Log.d(TAG, "============注册广播===================owner---" + ctx);
}