Java Code Examples for android.os.Process#myUserHandle()

The following examples show how to use android.os.Process#myUserHandle() . 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: LauncherAppWidgetInfo.java    From LaunchEnr with GNU General Public License v3.0 6 votes vote down vote up
public LauncherAppWidgetInfo(int appWidgetId, ComponentName providerName) {
    if (appWidgetId == CUSTOM_WIDGET_ID) {
        itemType = LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET;
    } else {
        itemType = LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET;
    }

    this.appWidgetId = appWidgetId;
    this.providerName = providerName;

    // Since the widget isn't instantiated yet, we don't know these values. Set them to -1
    // to indicate that they should be calculated based on the layout and minWidth/minHeight
    spanX = -1;
    spanY = -1;
    // We only support app widgets on current user.
    user = Process.myUserHandle();
    restoreStatus = RESTORE_COMPLETED;
}
 
Example 2
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 3
Source File: InstallShortcutReceiver.java    From LaunchEnr with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Verifies the intent and creates a {@link PendingInstallShortcutInfo}
 */
private static PendingInstallShortcutInfo createPendingInfo(Context context, Intent data) {
    if (!isValidExtraType(data, Intent.EXTRA_SHORTCUT_INTENT, Intent.class) ||
            !(isValidExtraType(data, Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                    Intent.ShortcutIconResource.class)) ||
            !(isValidExtraType(data, Intent.EXTRA_SHORTCUT_ICON, Bitmap.class))) {
        return null;
    }

    PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(
            data, Process.myUserHandle(), context);
    if (info.launchIntent == null || info.label == null) {
        return null;
    }

    return convertToLauncherActivityIfPossible(info);
}
 
Example 4
Source File: Util.java    From XPrivacyLua with GNU General Public License v3.0 5 votes vote down vote up
static UserHandle getUserHandle(int userid) {
    try {
        // public UserHandle(int h)
        Constructor ctor = UserHandle.class.getConstructor(int.class);
        return (UserHandle) ctor.newInstance(userid);
    } catch (Throwable ex) {
        Log.e(TAG, Log.getStackTraceString(ex));
        return Process.myUserHandle();
    }
}
 
Example 5
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 6
Source File: InstallShortcutReceiver.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
private Decoder(String encoded, Context context) throws JSONException, URISyntaxException {
    super(encoded);
    launcherIntent = Intent.parseUri(getString(LAUNCH_INTENT_KEY), 0);
    user = has(USER_HANDLE_KEY) ? UserManagerCompat.getInstance(context)
            .getUserForSerialNumber(getLong(USER_HANDLE_KEY))
            : Process.myUserHandle();
    if (user == null) {
        throw new JSONException("Invalid user");
    }
}
 
Example 7
Source File: WeChatDecorator.java    From decorator-wechat with Apache License 2.0 5 votes vote down vote up
private static UserHandle userHandleOf(final int user) {
	final UserHandle current_user = Process.myUserHandle();
	if (user == current_user.hashCode()) return current_user;
	if (SDK_INT >= N) UserHandle.getUserHandleForUid(user * 100000 + 1);
	final Parcel parcel = Parcel.obtain();
	try {
		parcel.writeInt(user);
		parcel.setDataPosition(0);
		return new UserHandle(parcel);
	} finally {
		parcel.recycle();
	}
}
 
Example 8
Source File: WeChatDecorator.java    From decorator-wechat with Apache License 2.0 5 votes vote down vote up
private static UserHandle getUser(final String key) {
	final int pos_pipe = key.indexOf('|');
	if (pos_pipe > 0) try {
		return userHandleOf(Integer.parseInt(key.substring(0, pos_pipe)));
	} catch (final NumberFormatException ignored) {}
	Log.e(TAG, "Invalid key: " + key);
	return Process.myUserHandle();		// Only correct for single user.
}
 
Example 9
Source File: UserUtils.java    From HgLauncher with GNU General Public License v3.0 5 votes vote down vote up
public UserHandle getCurrentUser() {
    if (Utils.sdkIsAround(17)) {
        return Process.myUserHandle();
    } else {
        return null;
    }
}
 
Example 10
Source File: UserUtils.java    From HgLauncher with GNU General Public License v3.0 5 votes vote down vote up
public UserHandle getCurrentUser() {
    if (Utils.sdkIsAround(17)) {
        return Process.myUserHandle();
    } else {
        return null;
    }
}
 
Example 11
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
private ContextImpl(ContextImpl container, ActivityThread mainThread,
        LoadedApk packageInfo, IBinder activityToken, UserHandle user, boolean restricted,
        Display display, Configuration overrideConfiguration) {
    mOuterContext = this;

    mMainThread = mainThread;
    mActivityToken = activityToken;
    mRestricted = restricted;

    if (user == null) {
        user = Process.myUserHandle();
    }
    mUser = user;

    mPackageInfo = packageInfo;
    mResourcesManager = ResourcesManager.getInstance();
    mDisplay = display;
    mOverrideConfiguration = overrideConfiguration;

    final int displayId = getDisplayId();
    CompatibilityInfo compatInfo = null;
    if (container != null) {
        compatInfo = container.getDisplayAdjustments(displayId).getCompatibilityInfo();
    }
    if (compatInfo == null && displayId == Display.DEFAULT_DISPLAY) {
        compatInfo = packageInfo.getCompatibilityInfo();
    }
    mDisplayAdjustments.setCompatibilityInfo(compatInfo);
    mDisplayAdjustments.setActivityToken(activityToken);

    Resources resources = packageInfo.getResources(mainThread);
    if (resources != null) {
        if (activityToken != null
                || displayId != Display.DEFAULT_DISPLAY
                || overrideConfiguration != null
                || (compatInfo != null && compatInfo.applicationScale
                        != resources.getCompatibilityInfo().applicationScale)) {
            resources = mResourcesManager.getTopLevelResources(packageInfo.getResDir(),
                    packageInfo.getSplitResDirs(), packageInfo.getOverlayDirs(),
                    packageInfo.getApplicationInfo().sharedLibraryFiles, displayId,
                    overrideConfiguration, compatInfo, activityToken);
        }
    }
    mResources = resources;

    if (container != null) {
        mBasePackageName = container.mBasePackageName;
        mOpPackageName = container.mOpPackageName;
    } else {
        mBasePackageName = packageInfo.mPackageName;
        ApplicationInfo ainfo = packageInfo.getApplicationInfo();
        if (ainfo.uid == Process.SYSTEM_UID && ainfo.uid != Process.myUid()) {
            // Special case: system components allow themselves to be loaded in to other
            // processes.  For purposes of app ops, we must then consider the context as
            // belonging to the package of this process, not the system itself, otherwise
            // the package+uid verifications in app ops will fail.
            mOpPackageName = ActivityThread.currentPackageName();
        } else {
            mOpPackageName = mBasePackageName;
        }
    }

    mContentResolver = new ApplicationContentResolver(this, mainThread, user);
}
 
Example 12
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
private ContextImpl(@Nullable ContextImpl container, @NonNull ActivityThread mainThread,
        @NonNull LoadedApk packageInfo, @Nullable String splitName,
        @Nullable IBinder activityToken, @Nullable UserHandle user, int flags,
        @Nullable ClassLoader classLoader) {
    mOuterContext = this;

    // If creator didn't specify which storage to use, use the default
    // location for application.
    if ((flags & (Context.CONTEXT_CREDENTIAL_PROTECTED_STORAGE
            | Context.CONTEXT_DEVICE_PROTECTED_STORAGE)) == 0) {
        final File dataDir = packageInfo.getDataDirFile();
        if (Objects.equals(dataDir, packageInfo.getCredentialProtectedDataDirFile())) {
            flags |= Context.CONTEXT_CREDENTIAL_PROTECTED_STORAGE;
        } else if (Objects.equals(dataDir, packageInfo.getDeviceProtectedDataDirFile())) {
            flags |= Context.CONTEXT_DEVICE_PROTECTED_STORAGE;
        }
    }

    mMainThread = mainThread;
    mActivityToken = activityToken;
    mFlags = flags;

    if (user == null) {
        user = Process.myUserHandle();
    }
    mUser = user;

    mPackageInfo = packageInfo;
    mSplitName = splitName;
    mClassLoader = classLoader;
    mResourcesManager = ResourcesManager.getInstance();

    if (container != null) {
        mBasePackageName = container.mBasePackageName;
        mOpPackageName = container.mOpPackageName;
        setResources(container.mResources);
        mDisplay = container.mDisplay;
    } else {
        mBasePackageName = packageInfo.mPackageName;
        ApplicationInfo ainfo = packageInfo.getApplicationInfo();
        if (ainfo.uid == Process.SYSTEM_UID && ainfo.uid != Process.myUid()) {
            // Special case: system components allow themselves to be loaded in to other
            // processes.  For purposes of app ops, we must then consider the context as
            // belonging to the package of this process, not the system itself, otherwise
            // the package+uid verifications in app ops will fail.
            mOpPackageName = ActivityThread.currentPackageName();
        } else {
            mOpPackageName = mBasePackageName;
        }
    }

    mContentResolver = new ApplicationContentResolver(this, mainThread, user);
}
 
Example 13
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
private ContextImpl(@Nullable ContextImpl container, @NonNull ActivityThread mainThread,
        @NonNull LoadedApk packageInfo, @Nullable String splitName,
        @Nullable IBinder activityToken, @Nullable UserHandle user, int flags,
        @Nullable ClassLoader classLoader, @Nullable String overrideOpPackageName) {
    mOuterContext = this;

    // If creator didn't specify which storage to use, use the default
    // location for application.
    if ((flags & (Context.CONTEXT_CREDENTIAL_PROTECTED_STORAGE
            | Context.CONTEXT_DEVICE_PROTECTED_STORAGE)) == 0) {
        final File dataDir = packageInfo.getDataDirFile();
        if (Objects.equals(dataDir, packageInfo.getCredentialProtectedDataDirFile())) {
            flags |= Context.CONTEXT_CREDENTIAL_PROTECTED_STORAGE;
        } else if (Objects.equals(dataDir, packageInfo.getDeviceProtectedDataDirFile())) {
            flags |= Context.CONTEXT_DEVICE_PROTECTED_STORAGE;
        }
    }

    mMainThread = mainThread;
    mActivityToken = activityToken;
    mFlags = flags;

    if (user == null) {
        user = Process.myUserHandle();
    }
    mUser = user;

    mPackageInfo = packageInfo;
    mSplitName = splitName;
    mClassLoader = classLoader;
    mResourcesManager = ResourcesManager.getInstance();

    String opPackageName;

    if (container != null) {
        mBasePackageName = container.mBasePackageName;
        opPackageName = container.mOpPackageName;
        setResources(container.mResources);
        mDisplay = container.mDisplay;
    } else {
        mBasePackageName = packageInfo.mPackageName;
        ApplicationInfo ainfo = packageInfo.getApplicationInfo();
        if (ainfo.uid == Process.SYSTEM_UID && ainfo.uid != Process.myUid()) {
            // Special case: system components allow themselves to be loaded in to other
            // processes.  For purposes of app ops, we must then consider the context as
            // belonging to the package of this process, not the system itself, otherwise
            // the package+uid verifications in app ops will fail.
            opPackageName = ActivityThread.currentPackageName();
        } else {
            opPackageName = mBasePackageName;
        }
    }

    mOpPackageName = overrideOpPackageName != null ? overrideOpPackageName : opPackageName;

    mContentResolver = new ApplicationContentResolver(this, mainThread);
}
 
Example 14
Source File: ItemInfo.java    From LaunchEnr with GNU General Public License v3.0 4 votes vote down vote up
public ItemInfo() {
    user = Process.myUserHandle();
}
 
Example 15
Source File: LauncherAppWidgetProviderInfo.java    From LaunchEnr with GNU General Public License v3.0 4 votes vote down vote up
public UserHandle getUser() {
    return isCustomWidget ? Process.myUserHandle() : getProfile();
}
 
Example 16
Source File: FolderInfo.java    From LaunchEnr with GNU General Public License v3.0 4 votes vote down vote up
public FolderInfo() {
    itemType = LauncherSettings.Favorites.ITEM_TYPE_FOLDER;
    user = Process.myUserHandle();
}
 
Example 17
Source File: ShortcutConfigActivityInfo.java    From LaunchEnr with GNU General Public License v3.0 4 votes vote down vote up
ShortcutConfigActivityInfoVL(ActivityInfo info, PackageManager pm) {
    super(new ComponentName(info.packageName, info.name), Process.myUserHandle());
    mInfo = info;
    mPm = pm;
}
 
Example 18
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
private ContextImpl(@Nullable ContextImpl container, @NonNull ActivityThread mainThread,
        @NonNull LoadedApk packageInfo, @Nullable String splitName,
        @Nullable IBinder activityToken, @Nullable UserHandle user, int flags,
        @Nullable ClassLoader classLoader) {
    mOuterContext = this;

    // If creator didn't specify which storage to use, use the default
    // location for application.
    if ((flags & (Context.CONTEXT_CREDENTIAL_PROTECTED_STORAGE
            | Context.CONTEXT_DEVICE_PROTECTED_STORAGE)) == 0) {
        final File dataDir = packageInfo.getDataDirFile();
        if (Objects.equals(dataDir, packageInfo.getCredentialProtectedDataDirFile())) {
            flags |= Context.CONTEXT_CREDENTIAL_PROTECTED_STORAGE;
        } else if (Objects.equals(dataDir, packageInfo.getDeviceProtectedDataDirFile())) {
            flags |= Context.CONTEXT_DEVICE_PROTECTED_STORAGE;
        }
    }

    mMainThread = mainThread;
    mActivityToken = activityToken;
    mFlags = flags;

    if (user == null) {
        user = Process.myUserHandle();
    }
    mUser = user;

    mPackageInfo = packageInfo;
    mSplitName = splitName;
    mClassLoader = classLoader;
    mResourcesManager = ResourcesManager.getInstance();

    if (container != null) {
        mBasePackageName = container.mBasePackageName;
        mOpPackageName = container.mOpPackageName;
        setResources(container.mResources);
        mDisplay = container.mDisplay;
    } else {
        mBasePackageName = packageInfo.mPackageName;
        ApplicationInfo ainfo = packageInfo.getApplicationInfo();
        if (ainfo.uid == Process.SYSTEM_UID && ainfo.uid != Process.myUid()) {
            // Special case: system components allow themselves to be loaded in to other
            // processes.  For purposes of app ops, we must then consider the context as
            // belonging to the package of this process, not the system itself, otherwise
            // the package+uid verifications in app ops will fail.
            mOpPackageName = ActivityThread.currentPackageName();
        } else {
            mOpPackageName = mBasePackageName;
        }
    }

    mContentResolver = new ApplicationContentResolver(this, mainThread);
}
 
Example 19
Source File: AppInfoComparator.java    From LaunchEnr with GNU General Public License v3.0 4 votes vote down vote up
AppInfoComparator(Context context) {
    mUserManager = UserManagerCompat.getInstance(context);
    mMyUser = Process.myUserHandle();
    mLabelComparator = new LabelComparator();
}
 
Example 20
Source File: UserUtils.java    From Last-Launcher with GNU General Public License v3.0 2 votes vote down vote up
public UserHandle getCurrentUser() {
    return Process.myUserHandle();

}