Search in sources :

Example 1 with LauncherApps

use of android.content.pm.LauncherApps in project android_frameworks_base by ResurrectionRemix.

the class AppWidgetHostView method updateContentDescription.

private void updateContentDescription(AppWidgetProviderInfo info) {
    if (info != null) {
        LauncherApps launcherApps = getContext().getSystemService(LauncherApps.class);
        ApplicationInfo appInfo = launcherApps.getApplicationInfo(info.provider.getPackageName(), 0, info.getProfile());
        if (appInfo != null && (appInfo.flags & ApplicationInfo.FLAG_SUSPENDED) != 0) {
            setContentDescription(Resources.getSystem().getString(com.android.internal.R.string.suspended_widget_accessibility, info.label));
        } else {
            setContentDescription(info.label);
        }
    }
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) LauncherApps(android.content.pm.LauncherApps)

Example 2 with LauncherApps

use of android.content.pm.LauncherApps in project KISS by Neamar.

the class IconsHandler method getDefaultAppDrawable.

public Drawable getDefaultAppDrawable(ComponentName componentName, UserHandle userHandle) {
    try {
        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            LauncherApps launcher = (LauncherApps) ctx.getSystemService(Context.LAUNCHER_APPS_SERVICE);
            LauncherActivityInfo info = launcher.getActivityList(componentName.getPackageName(), userHandle.getRealHandle()).get(0);
            return info.getBadgedIcon(0);
        } else {
            return pm.getActivityIcon(componentName);
        }
    } catch (NameNotFoundException | IndexOutOfBoundsException e) {
        Log.e(TAG, "Unable to found component " + componentName.toString() + e);
        return null;
    }
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) LauncherApps(android.content.pm.LauncherApps)

Example 3 with LauncherApps

use of android.content.pm.LauncherApps in project KISS by Neamar.

the class LoadAppPojos method doInBackground.

@Override
protected ArrayList<AppPojo> doInBackground(Void... params) {
    long start = System.nanoTime();
    ArrayList<AppPojo> apps = new ArrayList<>();
    String excludedAppList = PreferenceManager.getDefaultSharedPreferences(context).getString("excluded-apps-list", context.getPackageName() + ";");
    List excludedApps = Arrays.asList(excludedAppList.split(";"));
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        UserManager manager = (UserManager) context.getSystemService(Context.USER_SERVICE);
        LauncherApps launcher = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE);
        // Handle multi-profile support introduced in Android 5 (#542)
        for (android.os.UserHandle profile : manager.getUserProfiles()) {
            UserHandle user = new UserHandle(manager.getSerialNumberForUser(profile), profile);
            for (LauncherActivityInfo activityInfo : launcher.getActivityList(null, profile)) {
                ApplicationInfo appInfo = activityInfo.getApplicationInfo();
                String fullPackageName = user.addUserSuffixToString(appInfo.packageName, '#');
                if (!excludedApps.contains(fullPackageName)) {
                    AppPojo app = new AppPojo();
                    app.id = user.addUserSuffixToString(pojoScheme + appInfo.packageName + "/" + activityInfo.getName(), '/');
                    app.setName(activityInfo.getLabel().toString());
                    app.packageName = appInfo.packageName;
                    app.activityName = activityInfo.getName();
                    // Wrap Android user handle in opaque container that will work across
                    // all Android versions
                    app.userHandle = user;
                    app.setTags(tagsHandler.getTags(app.id));
                    apps.add(app);
                }
            }
        }
    } else {
        PackageManager manager = context.getPackageManager();
        Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
        mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        for (ResolveInfo info : manager.queryIntentActivities(mainIntent, 0)) {
            ApplicationInfo appInfo = info.activityInfo.applicationInfo;
            if (!excludedApps.contains(appInfo.packageName)) {
                AppPojo app = new AppPojo();
                app.id = pojoScheme + appInfo.packageName + "/" + info.activityInfo.name;
                app.setName(info.loadLabel(manager).toString());
                app.packageName = appInfo.packageName;
                app.activityName = info.activityInfo.name;
                app.userHandle = new UserHandle();
                app.setTags(tagsHandler.getTags(app.id));
                apps.add(app);
            }
        }
    }
    // Apply app sorting preference
    if (prefs.getString("sort-apps", "alphabetical").equals("invertedAlphabetical")) {
        Collections.sort(apps, Collections.reverseOrder(new AppPojo.NameComparator()));
    } else {
        Collections.sort(apps, new AppPojo.NameComparator());
    }
    long end = System.nanoTime();
    Log.i("time", Long.toString((end - start) / 1000000) + " milliseconds to list apps");
    return apps;
}
Also used : AppPojo(fr.neamar.kiss.pojo.AppPojo) ArrayList(java.util.ArrayList) ApplicationInfo(android.content.pm.ApplicationInfo) LauncherApps(android.content.pm.LauncherApps) Intent(android.content.Intent) ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) UserManager(android.os.UserManager) UserHandle(fr.neamar.kiss.utils.UserHandle) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with LauncherApps

use of android.content.pm.LauncherApps in project KISS by Neamar.

the class AppProvider method onCreate.

@Override
public void onCreate() {
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        // Package installation/uninstallation events for the main
        // profile are still handled using PackageAddedRemovedHandler itself
        final UserManager manager = (UserManager) this.getSystemService(Context.USER_SERVICE);
        final LauncherApps launcher = (LauncherApps) this.getSystemService(Context.LAUNCHER_APPS_SERVICE);
        launcher.registerCallback(new LauncherApps.Callback() {

            @Override
            public void onPackageAdded(String packageName, android.os.UserHandle user) {
                if (!Process.myUserHandle().equals(user)) {
                    PackageAddedRemovedHandler.handleEvent(AppProvider.this, "android.intent.action.PACKAGE_ADDED", packageName, new UserHandle(manager.getSerialNumberForUser(user), user), false);
                }
            }

            @Override
            public void onPackageChanged(String packageName, android.os.UserHandle user) {
                if (!Process.myUserHandle().equals(user)) {
                    PackageAddedRemovedHandler.handleEvent(AppProvider.this, "android.intent.action.PACKAGE_ADDED", packageName, new UserHandle(manager.getSerialNumberForUser(user), user), true);
                }
            }

            @Override
            public void onPackageRemoved(String packageName, android.os.UserHandle user) {
                if (!Process.myUserHandle().equals(user)) {
                    PackageAddedRemovedHandler.handleEvent(AppProvider.this, "android.intent.action.PACKAGE_REMOVED", packageName, new UserHandle(manager.getSerialNumberForUser(user), user), false);
                }
            }

            @Override
            public void onPackagesAvailable(String[] packageNames, android.os.UserHandle user, boolean replacing) {
                if (!Process.myUserHandle().equals(user)) {
                    PackageAddedRemovedHandler.handleEvent(AppProvider.this, "android.intent.action.MEDIA_MOUNTED", null, new UserHandle(manager.getSerialNumberForUser(user), user), false);
                }
            }

            @Override
            public void onPackagesUnavailable(String[] packageNames, android.os.UserHandle user, boolean replacing) {
                if (!Process.myUserHandle().equals(user)) {
                    PackageAddedRemovedHandler.handleEvent(AppProvider.this, "android.intent.action.MEDIA_UNMOUNTED", null, new UserHandle(manager.getSerialNumberForUser(user), user), false);
                }
            }
        });
        // Try to clean up app-related data when profile is removed
        IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_MANAGED_PROFILE_ADDED);
        filter.addAction(Intent.ACTION_MANAGED_PROFILE_REMOVED);
        this.registerReceiver(new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                if (intent.getAction().equals(Intent.ACTION_MANAGED_PROFILE_ADDED)) {
                    AppProvider.this.reload();
                } else if (intent.getAction().equals(Intent.ACTION_MANAGED_PROFILE_REMOVED)) {
                    android.os.UserHandle profile = (android.os.UserHandle) intent.getParcelableExtra(Intent.EXTRA_USER);
                    UserHandle user = new UserHandle(manager.getSerialNumberForUser(profile), profile);
                    KissApplication.getDataHandler(context).removeFromExcluded(user);
                    KissApplication.getDataHandler(context).removeFromFavorites(user);
                    AppProvider.this.reload();
                }
            }
        }, filter);
    }
    super.onCreate();
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) LoadAppPojos(fr.neamar.kiss.loader.LoadAppPojos) LauncherApps(android.content.pm.LauncherApps) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) UserManager(android.os.UserManager) UserHandle(fr.neamar.kiss.utils.UserHandle)

Example 5 with LauncherApps

use of android.content.pm.LauncherApps in project android_frameworks_base by AOSPA.

the class AppWidgetHostView method updateContentDescription.

private void updateContentDescription(AppWidgetProviderInfo info) {
    if (info != null) {
        LauncherApps launcherApps = getContext().getSystemService(LauncherApps.class);
        ApplicationInfo appInfo = launcherApps.getApplicationInfo(info.provider.getPackageName(), 0, info.getProfile());
        if (appInfo != null && (appInfo.flags & ApplicationInfo.FLAG_SUSPENDED) != 0) {
            setContentDescription(Resources.getSystem().getString(com.android.internal.R.string.suspended_widget_accessibility, info.label));
        } else {
            setContentDescription(info.label);
        }
    }
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) LauncherApps(android.content.pm.LauncherApps)

Aggregations

LauncherApps (android.content.pm.LauncherApps)11 ApplicationInfo (android.content.pm.ApplicationInfo)7 Intent (android.content.Intent)4 LauncherActivityInfo (android.content.pm.LauncherActivityInfo)3 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)2 UserManager (android.os.UserManager)2 UserHandle (fr.neamar.kiss.utils.UserHandle)2 ActivityNotFoundException (android.content.ActivityNotFoundException)1 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 IntentFilter (android.content.IntentFilter)1 PackageManager (android.content.pm.PackageManager)1 ResolveInfo (android.content.pm.ResolveInfo)1 PopupMenu (android.widget.PopupMenu)1 MainActivity (fr.neamar.kiss.MainActivity)1 LoadAppPojos (fr.neamar.kiss.loader.LoadAppPojos)1 AppPojo (fr.neamar.kiss.pojo.AppPojo)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1