Java Code Examples for com.android.launcher3.compat.UserHandleCompat

The following are top voted examples for showing how to use com.android.launcher3.compat.UserHandleCompat. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: FlickLauncher   File: Launcher.java   Source Code and License 6 votes vote down vote up
private void showBrokenAppInstallDialog(final String packageName,
        DialogInterface.OnClickListener onSearchClickListener) {
    new AlertDialog.Builder(this)
        .setTitle(R.string.abandoned_promises_title)
        .setMessage(R.string.abandoned_promise_explanation)
        .setPositiveButton(R.string.abandoned_search, onSearchClickListener)
        .setNeutralButton(R.string.abandoned_clean_this,
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    final UserHandleCompat user = UserHandleCompat.myUserHandle();
                    mWorkspace.removeAbandonedPromise(packageName, user);
                }
            })
        .create().show();
    return;
}
 
Example 2
Project: SimpleUILauncher   File: LauncherAppWidgetInfo.java   Source Code and License 6 votes vote down vote up
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 = UserHandleCompat.myUserHandle();
    restoreStatus = RESTORE_COMPLETED;
}
 
Example 3
Project: SimpleUILauncher   File: LauncherModel.java   Source Code and License 6 votes vote down vote up
/**
 * Returns true if the shortcuts already exists on the workspace. This must be called after
 * the workspace has been loaded. We identify a shortcut by its intent.
 */
@Thunk boolean shortcutExists(Context context, Intent intent, UserHandleCompat user) {
    assertWorkspaceLoaded();
    final String intentWithPkg, intentWithoutPkg;
    if (intent.getComponent() != null) {
        // If component is not null, an intent with null package will produce
        // the same result and should also be a match.
        String packageName = intent.getComponent().getPackageName();
        if (intent.getPackage() != null) {
            intentWithPkg = intent.toUri(0);
            intentWithoutPkg = new Intent(intent).setPackage(null).toUri(0);
        } else {
            intentWithPkg = new Intent(intent).setPackage(packageName).toUri(0);
            intentWithoutPkg = intent.toUri(0);
        }
    } else {
        intentWithPkg = intent.toUri(0);
        intentWithoutPkg = intent.toUri(0);
    }

    synchronized (sBgLock) {
        for (ItemInfo item : sBgItemsIdMap) {
            if (item instanceof ShortcutInfo) {
                ShortcutInfo info = (ShortcutInfo) item;
                Intent targetIntent = info.promisedIntent == null
                        ? info.intent : info.promisedIntent;
                if (targetIntent != null && info.user.equals(user)) {
                    Intent copyIntent = new Intent(targetIntent);
                    copyIntent.setSourceBounds(intent.getSourceBounds());
                    String s = copyIntent.toUri(0);
                    if (intentWithPkg.equals(s) || intentWithoutPkg.equals(s)) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
 
Example 4
Project: FlickLauncher   File: IconCache.java   Source Code and License 6 votes vote down vote up
public void updateDbIcons(Set<String> ignorePackagesForMainUser) {
    // Remove all active icon update tasks.
    mWorkerHandler.removeCallbacksAndMessages(ICON_UPDATE_TOKEN);

    mIconProvider.updateSystemStateString();
    for (UserHandleCompat user : mUserManager.getUserProfiles()) {
        // Query for the set of apps
        final List<LauncherActivityInfoCompat> apps = mLauncherApps.getActivityList(null, user);
        // Fail if we don't have any apps
        // TODO: Fix this. Only fail for the current user.
        if (apps == null || apps.isEmpty()) {
            return;
        }

        // Update icon cache. This happens in segments and {@link #onPackageIconsUpdated}
        // is called by the icon cache when the job is complete.
        updateDBIcons(user, apps, UserHandleCompat.myUserHandle().equals(user)
                ? ignorePackagesForMainUser : Collections.<String>emptySet());
    }
}
 
Example 5
Project: SimpleUILauncher   File: IconCache.java   Source Code and License 6 votes vote down vote up
public void updateDbIcons(Set<String> ignorePackagesForMainUser) {
    // Remove all active icon update tasks.
    mWorkerHandler.removeCallbacksAndMessages(ICON_UPDATE_TOKEN);

    mIconProvider.updateSystemStateString();
    for (UserHandleCompat user : mUserManager.getUserProfiles()) {
        // Query for the set of apps
        final List<LauncherActivityInfoCompat> apps = mLauncherApps.getActivityList(null, user);
        // Fail if we don't have any apps
        // TODO: Fix this. Only fail for the current user.
        if (apps == null || apps.isEmpty()) {
            return;
        }

        // Update icon cache. This happens in segments and {@link #onPackageIconsUpdated}
        // is called by the icon cache when the job is complete.
        updateDBIcons(user, apps, UserHandleCompat.myUserHandle().equals(user)
                ? ignorePackagesForMainUser : Collections.<String>emptySet());
    }
}
 
Example 6
Project: SimpleUILauncher   File: ComponentKey.java   Source Code and License 6 votes vote down vote up
/**
 * Creates a new component key from an encoded component key string in the form of
 * [flattenedComponentString#userId].  If the userId is not present, then it defaults
 * to the current user.
 */
public ComponentKey(Context context, String componentKeyStr) {
    int userDelimiterIndex = componentKeyStr.indexOf("#");
    if (userDelimiterIndex != -1) {
        String componentStr = componentKeyStr.substring(0, userDelimiterIndex);
        Long componentUser = Long.valueOf(componentKeyStr.substring(userDelimiterIndex + 1));
        componentName = ComponentName.unflattenFromString(componentStr);
        user = UserManagerCompat.getInstance(context)
                .getUserForSerialNumber(componentUser.longValue());
    } else {
        // No user provided, default to the current user
        componentName = ComponentName.unflattenFromString(componentKeyStr);
        user = UserHandleCompat.myUserHandle();
    }
    Preconditions.assertNotNull(componentName);
    Preconditions.assertNotNull(user);
    mHashCode = Arrays.hashCode(new Object[] {componentName, user});
}
 
Example 7
Project: SimpleUILauncher   File: ManagedProfileHeuristic.java   Source Code and License 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);
    UserHandleCompat myUser = UserHandleCompat.myUserHandle();

    SharedPreferences prefs = null;
    for (UserHandleCompat 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 8
Project: FlickLauncher   File: AppInfo.java   Source Code and License 6 votes vote down vote up
public AppInfo(Context context, LauncherActivityInfoCompat info, UserHandleCompat user,
        IconCache iconCache, boolean quietModeEnabled) {
    this.componentName = info.getComponentName();
    this.container = ItemInfo.NO_ID;
    flags = initFlags(info);
    if (PackageManagerHelper.isAppSuspended(info.getApplicationInfo())) {
        isDisabled |= ShortcutInfo.FLAG_DISABLED_SUSPENDED;
    }
    if (quietModeEnabled) {
        isDisabled |= ShortcutInfo.FLAG_DISABLED_QUIET_USER;
    }

    iconCache.getTitleAndIcon(this, info, true /* useLowResIcon */);
    intent = makeLaunchIntent(context, info, user);
    this.user = user;
}
 
Example 9
Project: SimpleUILauncher   File: LauncherModel.java   Source Code and License 6 votes vote down vote up
/**
 * Clear all the shortcuts for the given package, and re-add the new shortcuts.
 */
private void updateDeepShortcutMap(
        String packageName, UserHandleCompat user, List<ShortcutInfoCompat> shortcuts) {
    if (packageName != null) {
        Iterator<ComponentKey> keysIter = mBgDeepShortcutMap.keySet().iterator();
        while (keysIter.hasNext()) {
            ComponentKey next = keysIter.next();
            if (next.componentName.getPackageName().equals(packageName)
                    && next.user.equals(user)) {
                keysIter.remove();
            }
        }
    }

    // Now add the new shortcuts to the map.
    for (ShortcutInfoCompat shortcut : shortcuts) {
        boolean shouldShowInContainer = shortcut.isEnabled()
                && (shortcut.isDeclaredInManifest() || shortcut.isDynamic());
        if (shouldShowInContainer) {
            ComponentKey targetComponent
                    = new ComponentKey(shortcut.getActivity(), shortcut.getUserHandle());
            mBgDeepShortcutMap.addToList(targetComponent, shortcut.getId());
        }
    }
}
 
Example 10
Project: FlickLauncher   File: LauncherModel.java   Source Code and License 6 votes vote down vote up
/**
 * Clear all the shortcuts for the given package, and re-add the new shortcuts.
 */
private void updateDeepShortcutMap(
        String packageName, UserHandleCompat user, List<ShortcutInfoCompat> shortcuts) {
    if (packageName != null) {
        Iterator<ComponentKey> keysIter = mBgDeepShortcutMap.keySet().iterator();
        while (keysIter.hasNext()) {
            ComponentKey next = keysIter.next();
            if (next.componentName.getPackageName().equals(packageName)
                    && next.user.equals(user)) {
                keysIter.remove();
            }
        }
    }

    // Now add the new shortcuts to the map.
    for (ShortcutInfoCompat shortcut : shortcuts) {
        boolean shouldShowInContainer = shortcut.isEnabled()
                && (shortcut.isDeclaredInManifest() || shortcut.isDynamic());
        if (shouldShowInContainer) {
            ComponentKey targetComponent
                    = new ComponentKey(shortcut.getActivity(), shortcut.getUserHandle());
            mBgDeepShortcutMap.addToList(targetComponent, shortcut.getId());
        }
    }
}
 
Example 11
Project: FlickLauncher   File: LauncherModel.java   Source Code and License 6 votes vote down vote up
private void bindUpdatedShortcuts(
        final ArrayList<ShortcutInfo> updatedShortcuts,
        final ArrayList<ShortcutInfo> removedShortcuts,
        final UserHandleCompat user) {
    if (!updatedShortcuts.isEmpty() || !removedShortcuts.isEmpty()) {
        final Callbacks callbacks = getCallback();
        mHandler.post(new Runnable() {

            public void run() {
                Callbacks cb = getCallback();
                if (cb != null && callbacks == cb) {
                    cb.bindShortcutsChanged(updatedShortcuts, removedShortcuts, user);
                }
            }
        });
    }
}
 
Example 12
Project: SimpleUILauncher   File: ManagedProfileHeuristic.java   Source Code and License 6 votes vote down vote up
/**
 * Verifies that entries corresponding to {@param users} exist and removes all invalid entries.
 */
public static void processAllUsers(List<UserHandleCompat> users, Context context) {
    if (!Utilities.ATLEAST_LOLLIPOP) {
        return;
    }
    UserManagerCompat userManager = UserManagerCompat.getInstance(context);
    HashSet<String> validKeys = new HashSet<String>();
    for (UserHandleCompat user : users) {
        addAllUserKeys(userManager.getSerialNumberForUser(user), validKeys);
    }

    SharedPreferences prefs = context.getSharedPreferences(
            LauncherFiles.MANAGED_USER_PREFERENCES_KEY,
            Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = prefs.edit();
    for (String key : prefs.getAll().keySet()) {
        if (!validKeys.contains(key)) {
            editor.remove(key);
        }
    }
    editor.apply();
}
 
Example 13
Project: SimpleUILauncher   File: LauncherModel.java   Source Code and License 6 votes vote down vote up
private void loadAndBindDeepShortcuts() {
    if (DEBUG_LOADERS) {
        Log.d(TAG, "loadAndBindDeepShortcuts mDeepShortcutsLoaded=" + mDeepShortcutsLoaded);
    }
    if (!mDeepShortcutsLoaded) {
        mBgDeepShortcutMap.clear();
        mHasShortcutHostPermission = mDeepShortcutManager.hasHostPermission();
        if (mHasShortcutHostPermission) {
            for (UserHandleCompat user : mUserManager.getUserProfiles()) {
                if (mUserManager.isUserUnlocked(user)) {
                    List<ShortcutInfoCompat> shortcuts = mDeepShortcutManager
                            .queryForAllShortcuts(user);
                    updateDeepShortcutMap(null, user, shortcuts);
                }
            }
        }
        synchronized (LoaderTask.this) {
            if (mStopped) {
                return;
            }
            mDeepShortcutsLoaded = true;
        }
    }
    bindDeepShortcuts();
}
 
Example 14
Project: FlickLauncher   File: CachedPackageTracker.java   Source Code and License 6 votes vote down vote up
@Override
public void onPackageAdded(String packageName, UserHandleCompat user) {
    String prefKey = INSTALLED_PACKAGES_PREFIX + mUserManager.getSerialNumberForUser(user);
    HashSet<String> packageSet = new HashSet<>();
    final boolean userAppsExisted = getUserApps(packageSet, prefKey);
    if (!packageSet.contains(packageName)) {
        List<LauncherActivityInfoCompat> activities =
                mLauncherApps.getActivityList(packageName, user);
        if (!activities.isEmpty()) {
            LauncherActivityInfoCompat activityInfo = activities.get(0);

            packageSet.add(packageName);
            mPrefs.edit().putStringSet(prefKey, packageSet).apply();
            onLauncherAppsAdded(Arrays.asList(
                    new LauncherActivityInstallInfo(activityInfo, System.currentTimeMillis())),
                    user, userAppsExisted);
        }
    }
}
 
Example 15
Project: SimpleUILauncher   File: AppInfo.java   Source Code and License 6 votes vote down vote up
public AppInfo(Context context, LauncherActivityInfoCompat info, UserHandleCompat user,
        IconCache iconCache, boolean quietModeEnabled) {
    this.componentName = info.getComponentName();
    this.container = ItemInfo.NO_ID;
    flags = initFlags(info);
    if (PackageManagerHelper.isAppSuspended(info.getApplicationInfo())) {
        isDisabled |= ShortcutInfo.FLAG_DISABLED_SUSPENDED;
    }
    if (quietModeEnabled) {
        isDisabled |= ShortcutInfo.FLAG_DISABLED_QUIET_USER;
    }

    iconCache.getTitleAndIcon(this, info, true /* useLowResIcon */);
    intent = makeLaunchIntent(context, info, user);
    this.user = user;
}
 
Example 16
Project: FlickLauncher   File: ManagedProfileHeuristic.java   Source Code and License 6 votes vote down vote up
protected void onLauncherAppsAdded(
        List<LauncherActivityInstallInfo> apps, UserHandleCompat user, boolean userAppsExisted) {
    ArrayList<ShortcutInfo> workFolderApps = new ArrayList<>();
    ArrayList<ShortcutInfo> homescreenApps = new ArrayList<>();

    int count = apps.size();
    long folderCreationTime =
            mUserManager.getUserCreationTime(user) + AUTO_ADD_TO_FOLDER_DURATION;

    for (int i = 0; i < count; i++) {
        LauncherActivityInstallInfo info = apps.get(i);

        ShortcutInfo si = new ShortcutInfo(info.info, mContext);
        ((info.installTime <= folderCreationTime) ? workFolderApps : homescreenApps).add(si);
    }

    finalizeWorkFolder(user, workFolderApps, homescreenApps);

    // Do not add shortcuts on the homescreen for the first time. This prevents the launcher
    // getting filled with the managed user apps, when it start with a fresh DB (or after
    // a very long time).
    if (userAppsExisted && !homescreenApps.isEmpty()) {
        mModel.addAndBindAddedWorkspaceItems(mContext, homescreenApps);
    }
}
 
Example 17
Project: SimpleUILauncher   File: ManagedProfileHeuristic.java   Source Code and License 6 votes vote down vote up
protected void onLauncherAppsAdded(
        List<LauncherActivityInstallInfo> apps, UserHandleCompat user, boolean userAppsExisted) {
    ArrayList<ShortcutInfo> workFolderApps = new ArrayList<>();
    ArrayList<ShortcutInfo> homescreenApps = new ArrayList<>();

    int count = apps.size();
    long folderCreationTime =
            mUserManager.getUserCreationTime(user) + AUTO_ADD_TO_FOLDER_DURATION;

    for (int i = 0; i < count; i++) {
        LauncherActivityInstallInfo info = apps.get(i);

        ShortcutInfo si = new ShortcutInfo(info.info, mContext);
        ((info.installTime <= folderCreationTime) ? workFolderApps : homescreenApps).add(si);
    }

    finalizeWorkFolder(user, workFolderApps, homescreenApps);

    // Do not add shortcuts on the homescreen for the first time. This prevents the launcher
    // getting filled with the managed user apps, when it start with a fresh DB (or after
    // a very long time).
    if (userAppsExisted && !homescreenApps.isEmpty()) {
        mModel.addAndBindAddedWorkspaceItems(mContext, homescreenApps);
    }
}
 
Example 18
Project: FlickLauncher   File: Utilities.java   Source Code and License 5 votes vote down vote up
/**
 * Returns a bitmap suitable for the all apps view. The icon is badged for {@param user}.
 * The bitmap is also visually normalized with other icons.
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static Bitmap createBadgedIconBitmap(
        Drawable icon, UserHandleCompat user, Context context) {
    float scale = FeatureFlags.LAUNCHER3_DISABLE_ICON_NORMALIZATION ?
            1 : IconNormalizer.getInstance().getScale(icon, null);
    Bitmap bitmap = createIconBitmap(icon, context, scale);
    return badgeIconForUser(bitmap, user, context);
}
 
Example 19
Project: FlickLauncher   File: Launcher.java   Source Code and License 5 votes vote down vote up
public ItemInfo createAppDragInfo(Intent intent, UserHandleCompat user) {
    if (user == null) {
        user = UserHandleCompat.myUserHandle();
    }

    // Called from search suggestion, add the profile extra to the intent to ensure that we
    // can launch it correctly
    LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
    LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(intent, user);
    if (activityInfo == null) {
        return null;
    }
    return new AppInfo(this, activityInfo, user, mIconCache);
}
 
Example 20
Project: FlickLauncher   File: WidgetItem.java   Source Code and License 5 votes vote down vote up
public WidgetItem(ResolveInfo info, PackageManager pm) {
    super(new ComponentName(info.activityInfo.packageName, info.activityInfo.name),
            UserHandleCompat.myUserHandle());
    label = Utilities.trim(info.loadLabel(pm));
    widgetInfo = null;
    activityInfo = info.activityInfo;
    spanX = spanY = 1;
}
 
Example 21
Project: FlickLauncher   File: WidgetItem.java   Source Code and License 5 votes vote down vote up
@Override
public int compareTo(WidgetItem another) {
    if (sMyUserHandle == null) {
        // Delay these object creation until required.
        sMyUserHandle = UserHandleCompat.myUserHandle();
        sCollator = Collator.getInstance();
    }

    // Independent of how the labels compare, if only one of the two widget info belongs to
    // work profile, put that one in the back.
    boolean thisWorkProfile = !sMyUserHandle.equals(user);
    boolean otherWorkProfile = !sMyUserHandle.equals(another.user);
    if (thisWorkProfile ^ otherWorkProfile) {
        return thisWorkProfile ? 1 : -1;
    }

    int labelCompare = sCollator.compare(label, another.label);
    if (labelCompare != 0) {
        return labelCompare;
    }

    // If the label is same, put the smaller widget before the larger widget. If the area is
    // also same, put the widget with smaller height before.
    int thisArea = spanX * spanY;
    int otherArea = another.spanX * another.spanY;
    return thisArea == otherArea
            ? Integer.compare(spanY, another.spanY)
            : Integer.compare(thisArea, otherArea);
}
 
Example 22
Project: FlickLauncher   File: IconCache.java   Source Code and License 5 votes vote down vote up
/**
 * Remove any records for the supplied package name from memory.
 */
private void removeFromMemCacheLocked(String packageName, UserHandleCompat user) {
    HashSet<ComponentKey> forDeletion = new HashSet<ComponentKey>();
    for (ComponentKey key: mCache.keySet()) {
        if (key.componentName.getPackageName().equals(packageName)
                && key.user.equals(user)) {
            forDeletion.add(key);
        }
    }
    for (ComponentKey condemned: forDeletion) {
        mCache.remove(condemned);
    }
}
 
Example 23
Project: FlickLauncher   File: IconCache.java   Source Code and License 5 votes vote down vote up
/**
 * Removes the entries related to the given package in memory and persistent DB.
 */
public synchronized void removeIconsForPkg(String packageName, UserHandleCompat user) {
    removeFromMemCacheLocked(packageName, user);
    long userSerial = mUserManager.getSerialNumberForUser(user);
    mIconDb.delete(
            IconDB.COLUMN_COMPONENT + " LIKE ? AND " + IconDB.COLUMN_USER + " = ?",
            new String[]{packageName + "/%", Long.toString(userSerial)});
}
 
Example 24
Project: FlickLauncher   File: IconCache.java   Source Code and License 5 votes vote down vote up
/**
 * Fill in "application" with the icon and label for "info."
 */
public synchronized void getTitleAndIcon(AppInfo application,
        LauncherActivityInfoCompat info, boolean useLowResIcon) {
    UserHandleCompat user = info == null ? application.user : info.getUser();
    CacheEntry entry = cacheLocked(application.componentName, info, user,
            false, useLowResIcon);
    application.title = Utilities.trim(entry.title);
    application.contentDescription = entry.contentDescription;
    application.iconBitmap = getNonNullIcon(entry, user);
    application.usingLowResIcon = entry.isLowResIcon;
}
 
Example 25
Project: FlickLauncher   File: IconCache.java   Source Code and License 5 votes vote down vote up
/**
 * Returns a high res icon for the given intent and user
 */
public synchronized Bitmap getIcon(Intent intent, UserHandleCompat user) {
    ComponentName component = intent.getComponent();
    // null info means not installed, but if we have a component from the intent then
    // we should still look in the cache for restored app icons.
    if (component == null) {
        return getDefaultIcon(user);
    }

    LauncherActivityInfoCompat launcherActInfo = mLauncherApps.resolveActivity(intent, user);
    CacheEntry entry = cacheLocked(component, launcherActInfo, user, true, false /* useLowRes */);
    return entry.icon;
}
 
Example 26
Project: FlickLauncher   File: IconCache.java   Source Code and License 5 votes vote down vote up
/**
 * Fill in {@param shortcutInfo} with the icon and label for {@param info}
 */
public synchronized void getTitleAndIcon(
        ShortcutInfo shortcutInfo, ComponentName component, LauncherActivityInfoCompat info,
        UserHandleCompat user, boolean usePkgIcon, boolean useLowResIcon) {
    CacheEntry entry = cacheLocked(component, info, user, usePkgIcon, useLowResIcon);
    shortcutInfo.setIcon(getNonNullIcon(entry, user));
    shortcutInfo.title = Utilities.trim(entry.title);
    shortcutInfo.contentDescription = entry.contentDescription;
    shortcutInfo.usingFallbackIcon = isDefaultIcon(entry.icon, user);
    shortcutInfo.usingLowResIcon = entry.isLowResIcon;
}
 
Example 27
Project: FlickLauncher   File: AllAppsIconToHomeTest.java   Source Code and License 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();

    mSettingsApp = LauncherAppsCompat.getInstance(mTargetContext)
            .getActivityList("com.android.settings", UserHandleCompat.myUserHandle()).get(0);
}
 
Example 28
Project: FlickLauncher   File: AllAppsList.java   Source Code and License 5 votes vote down vote up
/**
 * Remove the apps for the given apk identified by packageName.
 */
public void removePackage(String packageName, UserHandleCompat user) {
    final List<AppInfo> data = this.data;
    for (int i = data.size() - 1; i >= 0; i--) {
        AppInfo info = data.get(i);
        final ComponentName component = info.intent.getComponent();
        if (info.user.equals(user) && packageName.equals(component.getPackageName())) {
            removed.add(info);
            data.remove(i);
        }
    }
}
 
Example 29
Project: SimpleUILauncher   File: DeepShortcutManager.java   Source Code and License 5 votes vote down vote up
/**
 * Query the system server for all the shortcuts matching the given parameters.
 * If packageName == null, we query for all shortcuts with the passed flags, regardless of app.
 *
 * TODO: Use the cache to optimize this so we don't make an RPC every time.
 */
@TargetApi(25)
private List<ShortcutInfoCompat> query(int flags, String packageName,
        ComponentName activity, List<String> shortcutIds, UserHandleCompat user) {
    if (Utilities.isNycMR1OrAbove()) {
        ShortcutQuery q = new ShortcutQuery();
        q.setQueryFlags(flags);
        if (packageName != null) {
            q.setPackage(packageName);
            q.setActivity(activity);
            q.setShortcutIds(shortcutIds);
        }
        List<ShortcutInfo> shortcutInfos = null;
        try {
            shortcutInfos = mLauncherApps.getShortcuts(q, user.getUser());
            mWasLastCallSuccess = true;
        } catch (SecurityException|IllegalStateException e) {
            Log.e(TAG, "Failed to query for shortcuts", e);
            mWasLastCallSuccess = false;
        }
        if (shortcutInfos == null) {
            return Collections.EMPTY_LIST;
        }
        List<ShortcutInfoCompat> shortcutInfoCompats = new ArrayList<>(shortcutInfos.size());
        for (ShortcutInfo shortcutInfo : shortcutInfos) {
            shortcutInfoCompats.add(new ShortcutInfoCompat(shortcutInfo));
        }
        return shortcutInfoCompats;
    } else {
        return Collections.EMPTY_LIST;
    }
}
 
Example 30
Project: FlickLauncher   File: AllAppsAppLaunchTest.java   Source Code and License 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();

    mSettingsApp = LauncherAppsCompat.getInstance(mTargetContext)
            .getActivityList("com.android.settings", UserHandleCompat.myUserHandle()).get(0);
}
 
Example 31
Project: FlickLauncher   File: AllAppsList.java   Source Code and License 5 votes vote down vote up
/**
 * Returns whether <em>apps</em> contains <em>component</em>.
 */
private static boolean findActivity(ArrayList<AppInfo> apps, ComponentName component,
        UserHandleCompat user) {
    final int N = apps.size();
    for (int i = 0; i < N; i++) {
        final AppInfo info = apps.get(i);
        if (info.user.equals(user) && info.componentName.equals(component)) {
            return true;
        }
    }
    return false;
}
 
Example 32
Project: SimpleUILauncher   File: InstallShortcutReceiver.java   Source Code and License 5 votes vote down vote up
/**
 * Initializes a PendingInstallShortcutInfo received from a different app.
 */
public PendingInstallShortcutInfo(Intent data, Context context) {
    this.data = data;
    mContext = context;

    launchIntent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    label = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
    user = UserHandleCompat.myUserHandle();
    activityInfo = null;
}
 
Example 33
Project: FlickLauncher   File: LauncherModel.java   Source Code and License 5 votes vote down vote up
/**
 * Updates the icons and label of all pending icons for the provided package name.
 */
public void updateSessionDisplayInfo(final String packageName) {
    Runnable updateRunnable = new Runnable() {

        @Override
        public void run() {
            synchronized (sBgLock) {
                ArrayList<ShortcutInfo> updates = new ArrayList<>();
                UserHandleCompat user = UserHandleCompat.myUserHandle();

                for (ItemInfo info : sBgItemsIdMap) {
                    if (info instanceof ShortcutInfo) {
                        ShortcutInfo si = (ShortcutInfo) info;
                        ComponentName cn = si.getTargetComponent();
                        if (si.isPromise() && (cn != null)
                                && packageName.equals(cn.getPackageName())) {
                            if (si.hasStatusFlag(ShortcutInfo.FLAG_AUTOINTALL_ICON)) {
                                // For auto install apps update the icon as well as label.
                                mIconCache.getTitleAndIcon(si,
                                        si.promisedIntent, user,
                                        si.shouldUseLowResIcon());
                            } else {
                                // Only update the icon for restored apps.
                                si.updateIcon(mIconCache);
                            }
                            updates.add(si);
                        }
                    }
                }

                bindUpdatedShortcuts(updates, user);
            }
        }
    };
    runOnWorkerThread(updateRunnable);
}
 
Example 34
Project: FlickLauncher   File: InstallShortcutReceiver.java   Source Code and License 5 votes vote down vote up
static void flushInstallQueue(Context context) {
    SharedPreferences sp = Utilities.getPrefs(context);
    ArrayList<PendingInstallShortcutInfo> installQueue = getAndClearInstallQueue(sp, context);
    if (!installQueue.isEmpty()) {
        Iterator<PendingInstallShortcutInfo> iter = installQueue.iterator();
        ArrayList<ItemInfo> addShortcuts = new ArrayList<ItemInfo>();
        while (iter.hasNext()) {
            final PendingInstallShortcutInfo pendingInfo = iter.next();

            // If the intent specifies a package, make sure the package exists
            String packageName = pendingInfo.getTargetPackage();
            if (!TextUtils.isEmpty(packageName)) {
                UserHandleCompat myUserHandle = UserHandleCompat.myUserHandle();
                if (!LauncherModel.isValidPackage(context, packageName, myUserHandle)) {
                    if (DBG) Log.d(TAG, "Ignoring shortcut for absent package: "
                            + pendingInfo.launchIntent);
                    continue;
                }
            }

            // Generate a shortcut info to add into the model
            addShortcuts.add(pendingInfo.getShortcutInfo());
        }

        // Add the new apps to the model and bind them
        if (!addShortcuts.isEmpty()) {
            LauncherAppState app = LauncherAppState.getInstance();
            app.getModel().addAndBindAddedWorkspaceItems(context, addShortcuts);
        }
    }
}
 
Example 35
Project: SimpleUILauncher   File: AllAppsIconToHomeTest.java   Source Code and License 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();

    mSettingsApp = LauncherAppsCompat.getInstance(mTargetContext)
            .getActivityList("com.android.settings", UserHandleCompat.myUserHandle()).get(0);
}
 
Example 36
Project: SimpleUILauncher   File: AllAppsList.java   Source Code and License 5 votes vote down vote up
/**
 * Find an ApplicationInfo object for the given packageName and className.
 */
private AppInfo findApplicationInfoLocked(String packageName, UserHandleCompat user,
        String className) {
    for (AppInfo info: data) {
        final ComponentName component = info.intent.getComponent();
        if (user.equals(info.user) && packageName.equals(component.getPackageName())
                && className.equals(component.getClassName())) {
            return info;
        }
    }
    return null;
}
 
Example 37
Project: SimpleUILauncher   File: ShortcutInfo.java   Source Code and License 5 votes vote down vote up
ShortcutInfo(Intent intent, CharSequence title, CharSequence contentDescription,
        Bitmap icon, UserHandleCompat user) {
    this();
    this.intent = intent;
    this.title = Utilities.trim(title);
    this.contentDescription = contentDescription;
    mIcon = icon;
    this.user = user;
}
 
Example 38
Project: FlickLauncher   File: LauncherModel.java   Source Code and License 5 votes vote down vote up
/**
 * Call from the handler for ACTION_PACKAGE_ADDED, ACTION_PACKAGE_REMOVED and
 * ACTION_PACKAGE_CHANGED.
 */
@Override
public void onReceive(Context context, Intent intent) {
    if (DEBUG_RECEIVER) Log.d(TAG, "onReceive intent=" + intent);

    final String action = intent.getAction();
    if (Intent.ACTION_LOCALE_CHANGED.equals(action)) {
        // If we have changed locale we need to clear out the labels in all apps/workspace.
        forceReload();
    } else if (Intent.ACTION_MANAGED_PROFILE_ADDED.equals(action)
            || Intent.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) {
        UserManagerCompat.getInstance(context).enableAndResetCache();
        forceReload();
    } else if (Intent.ACTION_MANAGED_PROFILE_AVAILABLE.equals(action) ||
            Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE.equals(action) ||
            Intent.ACTION_MANAGED_PROFILE_UNLOCKED.equals(action)) {
        UserHandleCompat user = UserHandleCompat.fromIntent(intent);
        if (user != null) {
            if (Intent.ACTION_MANAGED_PROFILE_AVAILABLE.equals(action) ||
                    Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE.equals(action)) {
                enqueueItemUpdatedTask(new PackageUpdatedTask(
                        PackageUpdatedTask.OP_USER_AVAILABILITY_CHANGE,
                        new String[0], user));
            }

            // ACTION_MANAGED_PROFILE_UNAVAILABLE sends the profile back to locked mode, so
            // we need to run the state change task again.
            if (Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE.equals(action) ||
                    Intent.ACTION_MANAGED_PROFILE_UNLOCKED.equals(action)) {
                enqueueItemUpdatedTask(new UserLockStateChangedTask(user));
            }
        }
    } else if (Intent.ACTION_WALLPAPER_CHANGED.equals(action)) {
        ExtractionUtils.startColorExtractionServiceIfNecessary(context);
    }
}
 
Example 39
Project: SimpleUILauncher   File: LauncherModel.java   Source Code and License 5 votes vote down vote up
/**
 * Called when the icons for packages have been updated in the icon cache.
 */
public void onPackageIconsUpdated(HashSet<String> updatedPackages, UserHandleCompat user) {
    final Callbacks callbacks = getCallback();
    final ArrayList<AppInfo> updatedApps = new ArrayList<>();
    final ArrayList<ShortcutInfo> updatedShortcuts = new ArrayList<>();

    // If any package icon has changed (app was updated while launcher was dead),
    // update the corresponding shortcuts.
    synchronized (sBgLock) {
        for (ItemInfo info : sBgItemsIdMap) {
            if (info instanceof ShortcutInfo && user.equals(info.user)
                    && info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
                ShortcutInfo si = (ShortcutInfo) info;
                ComponentName cn = si.getTargetComponent();
                if (cn != null && updatedPackages.contains(cn.getPackageName())) {
                    si.updateIcon(mIconCache);
                    updatedShortcuts.add(si);
                }
            }
        }
        mBgAllAppsList.updateIconsAndLabels(updatedPackages, user, updatedApps);
    }

    bindUpdatedShortcuts(updatedShortcuts, user);

    if (!updatedApps.isEmpty()) {
        mHandler.post(new Runnable() {

            public void run() {
                Callbacks cb = getCallback();
                if (cb != null && callbacks == cb) {
                    cb.bindAppsUpdated(updatedApps);
                }
            }
        });
    }
}
 
Example 40
Project: SimpleUILauncher   File: IconCache.java   Source Code and License 5 votes vote down vote up
/**
 * Fill in "application" with the icon and label for "info."
 * 获取应用的title和icon等
 */
public synchronized void getTitleAndIcon(AppInfo application,
        LauncherActivityInfoCompat info, boolean useLowResIcon) {
    UserHandleCompat user = info == null ? application.user : info.getUser();
    CacheEntry entry = cacheLocked(application.componentName, info, user,
            false, useLowResIcon);
    application.title = Utilities.trim(entry.title);
    application.contentDescription = entry.contentDescription;
    application.iconBitmap = getNonNullIcon(entry, user);
    application.usingLowResIcon = entry.isLowResIcon;
}