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

The following are top voted examples for showing how to use com.android.launcher3.compat.PackageInstallerCompat. 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: LauncherAppState.java   Source Code and License 5 votes vote down vote up
/**
 * Call from Application.onTerminate(), which is not guaranteed to ever be called.
 */
public void onTerminate() {
    sContext.unregisterReceiver(mModel);
    final LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(sContext);
    launcherApps.removeOnAppsChangedCallback(mModel);
    PackageInstallerCompat.getInstance(sContext).onStop();
}
 
Example 2
Project: FlickLauncher   File: GridSizeMigrationTask.java   Source Code and License 5 votes vote down vote up
protected static HashSet<String> getValidPackages(Context context) {
    // Initialize list of valid packages. This contain all the packages which are already on
    // the device and packages which are being installed. Any item which doesn't belong to
    // this set is removed.
    // Since the loader removes such items anyway, removing these items here doesn't cause
    // any extra data loss and gives us more free space on the grid for better migration.
    HashSet validPackages = new HashSet<>();
    for (PackageInfo info : context.getPackageManager()
            .getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES)) {
        validPackages.add(info.packageName);
    }
    validPackages.addAll(PackageInstallerCompat.getInstance(context)
            .updateAndGetActiveSessionCache().keySet());
    return validPackages;
}
 
Example 3
Project: FlickLauncher   File: BindWidgetTest.java   Source Code and License 5 votes vote down vote up
/**
 * Returns a LauncherAppWidgetInfo with package name which is not present on the device
 */
private LauncherAppWidgetInfo getInvalidWidgetInfo() {
    String invalidPackage = "com.invalidpackage";
    int count = 0;
    String pkg = invalidPackage;

    Set<String> activePackage = getOnUiThread(new Callable<Set<String>>() {
        @Override
        public Set<String> call() throws Exception {
            return PackageInstallerCompat.getInstance(mTargetContext)
                    .updateAndGetActiveSessionCache().keySet();
        }
    });
    while(true) {
        try {
            mTargetContext.getPackageManager().getPackageInfo(
                    pkg, PackageManager.GET_UNINSTALLED_PACKAGES);
        } catch (Exception e) {
            if (!activePackage.contains(pkg)) {
                break;
            }
        }
        pkg = invalidPackage + count;
        count ++;
    }
    LauncherAppWidgetInfo item = new LauncherAppWidgetInfo(10,
            new ComponentName(pkg, "com.test.widgetprovider"));
    item.spanX = 2;
    item.spanY = 2;
    item.minSpanX = 2;
    item.minSpanY = 2;
    item.cellX = 0;
    item.cellY = 1;
    item.container = LauncherSettings.Favorites.CONTAINER_DESKTOP;
    return item;
}
 
Example 4
Project: SimpleUILauncher   File: LauncherAppState.java   Source Code and License 5 votes vote down vote up
/**
 * Call from Application.onTerminate(), which is not guaranteed to ever be called.
 */
public void onTerminate() {
    sContext.unregisterReceiver(mModel);
    final LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(sContext);
    launcherApps.removeOnAppsChangedCallback(mModel);
    PackageInstallerCompat.getInstance(sContext).onStop();
}
 
Example 5
Project: SimpleUILauncher   File: GridSizeMigrationTask.java   Source Code and License 5 votes vote down vote up
protected static HashSet<String> getValidPackages(Context context) {
    // Initialize list of valid packages. This contain all the packages which are already on
    // the device and packages which are being installed. Any item which doesn't belong to
    // this set is removed.
    // Since the loader removes such items anyway, removing these items here doesn't cause
    // any extra data loss and gives us more free space on the grid for better migration.
    HashSet validPackages = new HashSet<>();
    for (PackageInfo info : context.getPackageManager()
            .getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES)) {
        validPackages.add(info.packageName);
    }
    validPackages.addAll(PackageInstallerCompat.getInstance(context)
            .updateAndGetActiveSessionCache().keySet());
    return validPackages;
}
 
Example 6
Project: SimpleUILauncher   File: BindWidgetTest.java   Source Code and License 5 votes vote down vote up
/**
 * Returns a LauncherAppWidgetInfo with package name which is not present on the device
 */
private LauncherAppWidgetInfo getInvalidWidgetInfo() {
    String invalidPackage = "com.invalidpackage";
    int count = 0;
    String pkg = invalidPackage;

    Set<String> activePackage = getOnUiThread(new Callable<Set<String>>() {
        @Override
        public Set<String> call() throws Exception {
            return PackageInstallerCompat.getInstance(mTargetContext)
                    .updateAndGetActiveSessionCache().keySet();
        }
    });
    while(true) {
        try {
            mTargetContext.getPackageManager().getPackageInfo(
                    pkg, PackageManager.GET_UNINSTALLED_PACKAGES);
        } catch (Exception e) {
            if (!activePackage.contains(pkg)) {
                break;
            }
        }
        pkg = invalidPackage + count;
        count ++;
    }
    LauncherAppWidgetInfo item = new LauncherAppWidgetInfo(10,
            new ComponentName(pkg, "com.test.widgetprovider"));
    item.spanX = 2;
    item.spanY = 2;
    item.minSpanX = 2;
    item.minSpanY = 2;
    item.cellX = 0;
    item.cellY = 1;
    item.container = LauncherSettings.Favorites.CONTAINER_DESKTOP;
    return item;
}
 
Example 7
Project: Trebuchet   File: LauncherAppState.java   Source Code and License 5 votes vote down vote up
/**
 * Call from Application.onTerminate(), which is not guaranteed to ever be called.
 */
public void onTerminate() {
    sContext.unregisterReceiver(mModel);
    final LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(sContext);
    launcherApps.removeOnAppsChangedCallback(mModel);
    PackageInstallerCompat.getInstance(sContext).onStop();
}
 
Example 8
Project: FlickLauncher   File: LauncherModel.java   Source Code and License 4 votes vote down vote up
public void setPackageState(final PackageInstallInfo installInfo) {
    Runnable updateRunnable = new Runnable() {

        @Override
        public void run() {
            synchronized (sBgLock) {
                final HashSet<ItemInfo> updates = new HashSet<>();

                if (installInfo.state == PackageInstallerCompat.STATUS_INSTALLED) {
                    // Ignore install success events as they are handled by Package add events.
                    return;
                }

                for (ItemInfo info : sBgItemsIdMap) {
                    if (info instanceof ShortcutInfo) {
                        ShortcutInfo si = (ShortcutInfo) info;
                        ComponentName cn = si.getTargetComponent();
                        if (si.isPromise() && (cn != null)
                                && installInfo.packageName.equals(cn.getPackageName())) {
                            si.setInstallProgress(installInfo.progress);

                            if (installInfo.state == PackageInstallerCompat.STATUS_FAILED) {
                                // Mark this info as broken.
                                si.status &= ~ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE;
                            }
                            updates.add(si);
                        }
                    }
                }

                for (LauncherAppWidgetInfo widget : sBgAppWidgets) {
                    if (widget.providerName.getPackageName().equals(installInfo.packageName)) {
                        widget.installProgress = installInfo.progress;
                        updates.add(widget);
                    }
                }

                if (!updates.isEmpty()) {
                    // Push changes to the callback.
                    Runnable r = new Runnable() {
                        public void run() {
                            Callbacks callbacks = getCallback();
                            if (callbacks != null) {
                                callbacks.bindRestoreItemsChange(updates);
                            }
                        }
                    };
                    mHandler.post(r);
                }
            }
        }
    };
    runOnWorkerThread(updateRunnable);
}
 
Example 9
Project: SimpleUILauncher   File: LauncherModel.java   Source Code and License 4 votes vote down vote up
public void setPackageState(final PackageInstallInfo installInfo) {
    Runnable updateRunnable = new Runnable() {

        @Override
        public void run() {
            synchronized (sBgLock) {
                final HashSet<ItemInfo> updates = new HashSet<>();

                if (installInfo.state == PackageInstallerCompat.STATUS_INSTALLED) {
                    // Ignore install success events as they are handled by Package add events.
                    return;
                }

                for (ItemInfo info : sBgItemsIdMap) {
                    if (info instanceof ShortcutInfo) {
                        ShortcutInfo si = (ShortcutInfo) info;
                        ComponentName cn = si.getTargetComponent();
                        if (si.isPromise() && (cn != null)
                                && installInfo.packageName.equals(cn.getPackageName())) {
                            si.setInstallProgress(installInfo.progress);

                            if (installInfo.state == PackageInstallerCompat.STATUS_FAILED) {
                                // Mark this info as broken.
                                si.status &= ~ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE;
                            }
                            updates.add(si);
                        }
                    }
                }

                for (LauncherAppWidgetInfo widget : sBgAppWidgets) {
                    if (widget.providerName.getPackageName().equals(installInfo.packageName)) {
                        widget.installProgress = installInfo.progress;
                        updates.add(widget);
                    }
                }

                if (!updates.isEmpty()) {
                    // Push changes to the callback.
                    Runnable r = new Runnable() {
                        public void run() {
                            Callbacks callbacks = getCallback();
                            if (callbacks != null) {
                                callbacks.bindRestoreItemsChange(updates);
                            }
                        }
                    };
                    mHandler.post(r);
                }
            }
        }
    };
    runOnWorkerThread(updateRunnable);
}
 
Example 10
Project: Trebuchet   File: LauncherModel.java   Source Code and License 4 votes vote down vote up
public void setPackageState(final PackageInstallInfo installInfo) {
    Runnable updateRunnable = new Runnable() {

        @Override
        public void run() {
            synchronized (sBgLock) {
                final HashSet<ItemInfo> updates = new HashSet<>();

                if (installInfo.state == PackageInstallerCompat.STATUS_INSTALLED) {
                    // Ignore install success events as they are handled by Package add events.
                    return;
                }

                for (ItemInfo info : sBgItemsIdMap) {
                    if (info instanceof ShortcutInfo) {
                        ShortcutInfo si = (ShortcutInfo) info;
                        ComponentName cn = si.getTargetComponent();
                        if (si.isPromise() && (cn != null)
                                && installInfo.packageName.equals(cn.getPackageName())) {
                            si.setInstallProgress(installInfo.progress);

                            if (installInfo.state == PackageInstallerCompat.STATUS_FAILED) {
                                // Mark this info as broken.
                                si.status &= ~ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE;
                            }
                            updates.add(si);
                        }
                    }
                }

                for (LauncherAppWidgetInfo widget : sBgAppWidgets) {
                    if (widget.providerName.getPackageName().equals(installInfo.packageName)) {
                        widget.installProgress = installInfo.progress;
                        updates.add(widget);
                    }
                }

                if (!updates.isEmpty()) {
                    // Push changes to the callback.
                    Runnable r = new Runnable() {
                        public void run() {
                            Callbacks callbacks = getCallback();
                            if (callbacks != null) {
                                callbacks.bindRestoreItemsChange(updates);
                            }
                        }
                    };
                    mHandler.post(r);
                }
            }
        }
    };
    runOnWorkerThread(updateRunnable);
}