Search in sources :

Example 56 with BroadcastReceiver

use of android.content.BroadcastReceiver in project KISS by Neamar.

the class AppProvider method onCreate.

@Override
public void onCreate() {
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        // Package installation/uninstallation events for the main
        // profile are still handled using PackageAddedRemovedHandler itself
        final UserManager manager = (UserManager) this.getSystemService(Context.USER_SERVICE);
        final LauncherApps launcher = (LauncherApps) this.getSystemService(Context.LAUNCHER_APPS_SERVICE);
        launcher.registerCallback(new LauncherApps.Callback() {

            @Override
            public void onPackageAdded(String packageName, android.os.UserHandle user) {
                if (!Process.myUserHandle().equals(user)) {
                    PackageAddedRemovedHandler.handleEvent(AppProvider.this, "android.intent.action.PACKAGE_ADDED", packageName, new UserHandle(manager.getSerialNumberForUser(user), user), false);
                }
            }

            @Override
            public void onPackageChanged(String packageName, android.os.UserHandle user) {
                if (!Process.myUserHandle().equals(user)) {
                    PackageAddedRemovedHandler.handleEvent(AppProvider.this, "android.intent.action.PACKAGE_ADDED", packageName, new UserHandle(manager.getSerialNumberForUser(user), user), true);
                }
            }

            @Override
            public void onPackageRemoved(String packageName, android.os.UserHandle user) {
                if (!Process.myUserHandle().equals(user)) {
                    PackageAddedRemovedHandler.handleEvent(AppProvider.this, "android.intent.action.PACKAGE_REMOVED", packageName, new UserHandle(manager.getSerialNumberForUser(user), user), false);
                }
            }

            @Override
            public void onPackagesAvailable(String[] packageNames, android.os.UserHandle user, boolean replacing) {
                if (!Process.myUserHandle().equals(user)) {
                    PackageAddedRemovedHandler.handleEvent(AppProvider.this, "android.intent.action.MEDIA_MOUNTED", null, new UserHandle(manager.getSerialNumberForUser(user), user), false);
                }
            }

            @Override
            public void onPackagesUnavailable(String[] packageNames, android.os.UserHandle user, boolean replacing) {
                if (!Process.myUserHandle().equals(user)) {
                    PackageAddedRemovedHandler.handleEvent(AppProvider.this, "android.intent.action.MEDIA_UNMOUNTED", null, new UserHandle(manager.getSerialNumberForUser(user), user), false);
                }
            }
        });
        // Try to clean up app-related data when profile is removed
        IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_MANAGED_PROFILE_ADDED);
        filter.addAction(Intent.ACTION_MANAGED_PROFILE_REMOVED);
        this.registerReceiver(new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                if (intent.getAction().equals(Intent.ACTION_MANAGED_PROFILE_ADDED)) {
                    AppProvider.this.reload();
                } else if (intent.getAction().equals(Intent.ACTION_MANAGED_PROFILE_REMOVED)) {
                    android.os.UserHandle profile = (android.os.UserHandle) intent.getParcelableExtra(Intent.EXTRA_USER);
                    UserHandle user = new UserHandle(manager.getSerialNumberForUser(profile), profile);
                    KissApplication.getDataHandler(context).removeFromExcluded(user);
                    KissApplication.getDataHandler(context).removeFromFavorites(user);
                    AppProvider.this.reload();
                }
            }
        }, filter);
    }
    super.onCreate();
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) LoadAppPojos(fr.neamar.kiss.loader.LoadAppPojos) LauncherApps(android.content.pm.LauncherApps) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) UserManager(android.os.UserManager) UserHandle(fr.neamar.kiss.utils.UserHandle)

Example 57 with BroadcastReceiver

use of android.content.BroadcastReceiver in project android_frameworks_base by DirtyUnicorns.

the class UserManagerService method finishRemoveUser.

void finishRemoveUser(final int userHandle) {
    if (DBG)
        Slog.i(LOG_TAG, "finishRemoveUser " + userHandle);
    // Let other services shutdown any activity and clean up their state before completely
    // wiping the user's system directory and removing from the user list
    long ident = Binder.clearCallingIdentity();
    try {
        Intent addedIntent = new Intent(Intent.ACTION_USER_REMOVED);
        addedIntent.putExtra(Intent.EXTRA_USER_HANDLE, userHandle);
        mContext.sendOrderedBroadcastAsUser(addedIntent, UserHandle.ALL, android.Manifest.permission.MANAGE_USERS, new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                if (DBG) {
                    Slog.i(LOG_TAG, "USER_REMOVED broadcast sent, cleaning up user data " + userHandle);
                }
                new Thread() {

                    @Override
                    public void run() {
                        // Clean up any ActivityManager state
                        LocalServices.getService(ActivityManagerInternal.class).onUserRemoved(userHandle);
                        removeUserState(userHandle);
                    }
                }.start();
            }
        }, null, Activity.RESULT_OK, null, null);
    } finally {
        Binder.restoreCallingIdentity(ident);
    }
}
Also used : Context(android.content.Context) ActivityManagerInternal(android.app.ActivityManagerInternal) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Example 58 with BroadcastReceiver

use of android.content.BroadcastReceiver in project android_frameworks_base by DirtyUnicorns.

the class SettingsProvider method registerBroadcastReceivers.

private void registerBroadcastReceivers() {
    IntentFilter userFilter = new IntentFilter();
    userFilter.addAction(Intent.ACTION_USER_REMOVED);
    userFilter.addAction(Intent.ACTION_USER_STOPPED);
    getContext().registerReceiver(new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_SYSTEM);
            switch(intent.getAction()) {
                case Intent.ACTION_USER_REMOVED:
                    {
                        synchronized (mLock) {
                            mSettingsRegistry.removeUserStateLocked(userId, true);
                        }
                    }
                    break;
                case Intent.ACTION_USER_STOPPED:
                    {
                        synchronized (mLock) {
                            mSettingsRegistry.removeUserStateLocked(userId, false);
                        }
                    }
                    break;
            }
        }
    }, userFilter);
    PackageMonitor monitor = new PackageMonitor() {

        @Override
        public void onPackageRemoved(String packageName, int uid) {
            synchronized (mLock) {
                mSettingsRegistry.onPackageRemovedLocked(packageName, UserHandle.getUserId(uid));
            }
        }
    };
    // package changes
    monitor.register(getContext(), BackgroundThread.getHandler().getLooper(), UserHandle.ALL, true);
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) PackageMonitor(com.android.internal.content.PackageMonitor)

Example 59 with BroadcastReceiver

use of android.content.BroadcastReceiver in project android_frameworks_base by DirtyUnicorns.

the class RecoverySystem method rebootWipeUserData.

/**
     * Reboots the device and wipes the user data and cache
     * partitions.  This is sometimes called a "factory reset", which
     * is something of a misnomer because the system partition is not
     * restored to its factory state.  Requires the
     * {@link android.Manifest.permission#REBOOT} permission.
     *
     * @param context   the Context to use
     * @param shutdown  if true, the device will be powered down after
     *                  the wipe completes, rather than being rebooted
     *                  back to the regular system.
     * @param reason    the reason for the wipe that is visible in the logs
     * @param force     whether the {@link UserManager.DISALLOW_FACTORY_RESET} user restriction
     *                  should be ignored
     *
     * @throws IOException  if writing the recovery command file
     * fails, or if the reboot itself fails.
     * @throws SecurityException if the current user is not allowed to wipe data.
     *
     * @hide
     */
public static void rebootWipeUserData(Context context, boolean shutdown, String reason, boolean force) throws IOException {
    UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
    if (!force && um.hasUserRestriction(UserManager.DISALLOW_FACTORY_RESET)) {
        throw new SecurityException("Wiping data is not allowed for this user.");
    }
    final ConditionVariable condition = new ConditionVariable();
    Intent intent = new Intent("android.intent.action.MASTER_CLEAR_NOTIFICATION");
    intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    context.sendOrderedBroadcastAsUser(intent, UserHandle.SYSTEM, android.Manifest.permission.MASTER_CLEAR, new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            condition.open();
        }
    }, null, 0, null, null);
    // Block until the ordered broadcast has completed.
    condition.block();
    String shutdownArg = null;
    if (shutdown) {
        shutdownArg = "--shutdown_after";
    }
    String reasonArg = null;
    if (!TextUtils.isEmpty(reason)) {
        reasonArg = "--reason=" + sanitizeArg(reason);
    }
    final String localeArg = "--locale=" + Locale.getDefault().toString();
    bootCommand(context, shutdownArg, "--wipe_data", reasonArg, localeArg);
}
Also used : Context(android.content.Context) UserManager(android.os.UserManager) GeneralSecurityException(java.security.GeneralSecurityException) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Example 60 with BroadcastReceiver

use of android.content.BroadcastReceiver in project android_frameworks_base by DirtyUnicorns.

the class UserManagerTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    mUserManager = UserManager.get(getContext());
    IntentFilter filter = new IntentFilter(Intent.ACTION_USER_REMOVED);
    getContext().registerReceiver(new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            synchronized (mUserLock) {
                mUserLock.notifyAll();
            }
        }
    }, filter);
    removeExistingUsers();
    usersToRemove = new ArrayList<>();
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Aggregations

BroadcastReceiver (android.content.BroadcastReceiver)637 Intent (android.content.Intent)564 Context (android.content.Context)493 IntentFilter (android.content.IntentFilter)441 PendingIntent (android.app.PendingIntent)120 Test (org.junit.Test)109 ArrayList (java.util.ArrayList)34 RemoteException (android.os.RemoteException)29 Bundle (android.os.Bundle)24 IOException (java.io.IOException)23 Point (android.graphics.Point)20 Semaphore (java.util.concurrent.Semaphore)20 View (android.view.View)19 Handler (android.os.Handler)18 LocalBroadcastManager (android.support.v4.content.LocalBroadcastManager)17 ComponentName (android.content.ComponentName)16 TextView (android.widget.TextView)16 PackageMonitor (com.android.internal.content.PackageMonitor)15 ApplicationInfo (android.content.pm.ApplicationInfo)14 AndroidRuntimeException (android.util.AndroidRuntimeException)14