Java Code Examples for android.os.UserHandle#equals()

The following examples show how to use android.os.UserHandle#equals() . 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: ManagedProfileHeuristic.java    From LaunchEnr with GNU General Public License v3.0 6 votes vote down vote up
/**
 * For each user, if a work folder has not been created, mark it such that the folder will
 * never get created.
 */
public static void markExistingUsersForNoFolderCreation(Context context) {
    UserManagerCompat userManager = UserManagerCompat.getInstance(context);
    UserHandle myUser = Process.myUserHandle();

    SharedPreferences prefs = null;
    for (UserHandle user : userManager.getUserProfiles()) {
        if (myUser.equals(user)) {
            continue;
        }

        if (prefs == null) {
            prefs = context.getSharedPreferences(
                    LauncherFiles.MANAGED_USER_PREFERENCES_KEY,
                    Context.MODE_PRIVATE);
        }
        String folderIdKey = USER_FOLDER_ID_PREFIX + userManager.getSerialNumberForUser(user);
        if (!prefs.contains(folderIdKey)) {
            prefs.edit().putLong(folderIdKey, ItemInfo.NO_ID).apply();
        }
    }
}
 
Example 2
Source File: ChromeBrowserProvider.java    From delion with Apache License 2.0 6 votes vote down vote up
@SuppressLint("NewApi")
private void notifyChange(final Uri uri) {
    // If the calling user is different than current one, we need to post a
    // task to notify change, otherwise, a system level hidden permission
    // INTERACT_ACROSS_USERS_FULL is needed.
    // The related APIs were added in API 17, it should be safe to fallback to
    // normal way for notifying change, because caller can't be other users in
    // devices whose API level is less than API 17.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        UserHandle callingUserHandle = Binder.getCallingUserHandle();
        if (callingUserHandle != null
                && !callingUserHandle.equals(android.os.Process.myUserHandle())) {
            ThreadUtils.postOnUiThread(new Runnable() {
                @Override
                public void run() {
                    getContext().getContentResolver().notifyChange(uri, null);
                }
            });
            return;
        }
    }
    getContext().getContentResolver().notifyChange(uri, null);
}
 
Example 3
Source File: ChromeBrowserProvider.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@SuppressLint("NewApi")
private void notifyChange(final Uri uri) {
    // If the calling user is different than current one, we need to post a
    // task to notify change, otherwise, a system level hidden permission
    // INTERACT_ACROSS_USERS_FULL is needed.
    // The related APIs were added in API 17, it should be safe to fallback to
    // normal way for notifying change, because caller can't be other users in
    // devices whose API level is less than API 17.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        UserHandle callingUserHandle = Binder.getCallingUserHandle();
        if (callingUserHandle != null
                && !callingUserHandle.equals(android.os.Process.myUserHandle())) {
            ThreadUtils.postOnUiThread(new Runnable() {
                @Override
                public void run() {
                    getContext().getContentResolver().notifyChange(uri, null);
                }
            });
            return;
        }
    }
    getContext().getContentResolver().notifyChange(uri, null);
}
 
Example 4
Source File: IslandAppListProvider.java    From island with Apache License 2.0 6 votes vote down vote up
@Override public void onPackageRemoved(final String pkg, final UserHandle user) {
	if (! user.equals(Users.profile)) return;
	final IslandAppInfo app = mIslandAppMap.get().get(pkg);
	if (app == null) {
		Log.e(TAG, "Removed package not found in Island: " + pkg);
		return;
	}
	if (app.isHidden()) return;		// The removal callback is triggered by freezing.
	queryApplicationInfoInProfile(pkg, info -> {
		if (info != null && (info.flags & FLAG_INSTALLED) != 0) {	// Frozen
			final IslandAppInfo new_info = new IslandAppInfo(IslandAppListProvider.this, user, info, mIslandAppMap.get().get(pkg));
			if (! new_info.isHidden()) {
				Log.w(TAG, "Correct the flag for hidden package: " + pkg);
				new_info.setHidden(true);
			}
			mIslandAppMap.get().put(pkg, new_info);
			notifyUpdate(Collections.singleton(new_info));
		} else {	// Uninstalled in profile
			final IslandAppInfo removed_app = mIslandAppMap.get().remove(pkg);
			if (removed_app != null) notifyRemoval(Collections.singleton(removed_app));
		}
	});
}
 
Example 5
Source File: ChromeBrowserProvider.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@SuppressLint("NewApi")
private void notifyChange(final Uri uri) {
    // If the calling user is different than current one, we need to post a
    // task to notify change, otherwise, a system level hidden permission
    // INTERACT_ACROSS_USERS_FULL is needed.
    // The related APIs were added in API 17, it should be safe to fallback to
    // normal way for notifying change, because caller can't be other users in
    // devices whose API level is less than API 17.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        UserHandle callingUserHandle = Binder.getCallingUserHandle();
        if (callingUserHandle != null
                && !callingUserHandle.equals(android.os.Process.myUserHandle())) {
            ThreadUtils.postOnUiThread(new Runnable() {
                @Override
                public void run() {
                    getContext().getContentResolver().notifyChange(uri, null);
                }
            });
            return;
        }
    }
    getContext().getContentResolver().notifyChange(uri, null);
}
 
Example 6
Source File: Launcher.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
public boolean startActivitySafely(View v, Intent intent, ItemInfo item) {
    if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) {
        Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
        return false;
    }
    // Only launch using the new animation if the shortcut has not opted out (this is a
    // private contract between launcher and may be ignored in the future).
    boolean useLaunchAnimation = (v != null) &&
            !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
    Bundle optsBundle = useLaunchAnimation ? getActivityLaunchOptions(v) : null;

    UserHandle user = item == null ? null : item.user;

    // Prepare intent
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    if (v != null) {
        intent.setSourceBounds(getViewBounds(v));
    }
    try {
        if (AndroidVersion.isAtLeastMarshmallow
                && (item instanceof ShortcutInfo)
                && (item.itemType == Favorites.ITEM_TYPE_SHORTCUT
                 || item.itemType == Favorites.ITEM_TYPE_DEEP_SHORTCUT)
                && !((ShortcutInfo) item).isPromise()) {
            // Shortcuts need some special checks due to legacy reasons.
            startShortcutIntentSafely(intent, optsBundle, item);
        } else if (user == null || user.equals(Process.myUserHandle())) {
            // Could be launching some bookkeeping activity
            startActivity(intent, optsBundle);
        } else {
            LauncherAppsCompat.getInstance(this).startActivityForProfile(
                    intent.getComponent(), user, intent.getSourceBounds(), optsBundle);
        }
        return true;
    } catch (ActivityNotFoundException|SecurityException e) {
        Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
        e.printStackTrace();
    }
    return false;
}
 
Example 7
Source File: LauncherAppsCompatVO.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<ShortcutConfigActivityInfo> getCustomShortcutActivityList(
        @Nullable PackageUserKey packageUser) {
    List<ShortcutConfigActivityInfo> result = new ArrayList<>();
    UserHandle myUser = Process.myUserHandle();

    try {
        Method m = LauncherApps.class.getDeclaredMethod("getShortcutConfigActivityList",
                String.class, UserHandle.class);
        final List<UserHandle> users;
        final String packageName;
        if (packageUser == null) {
            users = UserManagerCompat.getInstance(mContext).getUserProfiles();
            packageName = null;
        } else {
            users = new ArrayList<>(1);
            users.add(packageUser.mUser);
            packageName = packageUser.mPackageName;
        }
        for (UserHandle user : users) {
            boolean ignoreTargetSdk = myUser.equals(user);
            List<LauncherActivityInfo> activities =
                    (List<LauncherActivityInfo>) m.invoke(mLauncherApps, packageName, user);
            for (LauncherActivityInfo activityInfo : activities) {
                if (ignoreTargetSdk || activityInfo.getApplicationInfo().targetSdkVersion >=
                        Build.VERSION_CODES.O) {
                    result.add(new ShortcutConfigActivityInfoVO(activityInfo));
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return result;
}
 
Example 8
Source File: AllAppsList.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Find an ApplicationInfo object for the given packageName and className.
 */
private AppInfo findApplicationInfoLocked(String packageName, UserHandle user,
        String className) {
    for (AppInfo info: data) {
        if (user.equals(info.user) && packageName.equals(info.componentName.getPackageName())
                && className.equals(info.componentName.getClassName())) {
            return info;
        }
    }
    return null;
}
 
Example 9
Source File: InstallShortcutReceiver.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
public static void removeFromInstallQueue(Context context, HashSet<String> packageNames,
        UserHandle user) {
    if (packageNames.isEmpty()) {
        return;
    }
    SharedPreferences sp = Utilities.getPrefs(context);
    synchronized(sLock) {
        Set<String> strings = sp.getStringSet(APPS_PENDING_INSTALL, null);

        if (Utilities.isEmpty(strings)) {
            return;
        }
        Set<String> newStrings = new HashSet<>(strings);
        Iterator<String> newStringsIter = newStrings.iterator();
        while (newStringsIter.hasNext()) {
            String encoded = newStringsIter.next();
            try {
                Decoder decoder = new Decoder(encoded, context);
                if (packageNames.contains(getIntentPackage(decoder.launcherIntent)) &&
                        user.equals(decoder.user)) {
                    newStringsIter.remove();
                }
            } catch (JSONException | URISyntaxException e) {
                e.printStackTrace();
                newStringsIter.remove();
            }
        }
        sp.edit().putStringSet(APPS_PENDING_INSTALL, newStrings).apply();
    }
}