android.os.UserHandle#equals ( )源码实例Demo

下面列出了android.os.UserHandle#equals ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: LaunchEnr   文件: ManagedProfileHeuristic.java
/**
 * 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();
        }
    }
}
 
源代码2 项目: delion   文件: ChromeBrowserProvider.java
@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);
}
 
源代码3 项目: AndroidChromium   文件: ChromeBrowserProvider.java
@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);
}
 
源代码4 项目: island   文件: IslandAppListProvider.java
@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));
		}
	});
}
 
源代码5 项目: 365browser   文件: ChromeBrowserProvider.java
@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);
}
 
源代码6 项目: LaunchEnr   文件: Launcher.java
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;
}
 
源代码7 项目: LaunchEnr   文件: LauncherAppsCompatVO.java
@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;
}
 
源代码8 项目: LaunchEnr   文件: AllAppsList.java
/**
 * 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;
}
 
源代码9 项目: LaunchEnr   文件: InstallShortcutReceiver.java
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();
    }
}