Search in sources :

Example 1 with MainActivity

use of fr.neamar.kiss.MainActivity in project KISS by Neamar.

the class AppResult method buildPopupMenu.

@Override
protected PopupMenu buildPopupMenu(Context context, final RecordAdapter parent, View parentView) {
    PopupMenu menu = inflatePopupMenu(R.menu.menu_item_app, context, parentView);
    if ((context instanceof MainActivity) && (!((MainActivity) context).isOnSearchView())) {
        menu.getMenu().removeItem(R.id.item_remove);
    }
    try {
        // app installed under /system can't be uninstalled
        boolean isSameProfile = true;
        ApplicationInfo ai;
        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            LauncherApps launcher = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE);
            LauncherActivityInfo info = launcher.getActivityList(this.appPojo.packageName, this.appPojo.userHandle.getRealHandle()).get(0);
            ai = info.getApplicationInfo();
            isSameProfile = this.appPojo.userHandle.isCurrentUser();
        } else {
            ai = context.getPackageManager().getApplicationInfo(this.appPojo.packageName, 0);
        }
        // Need to AND the flags with SYSTEM:
        if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0 && isSameProfile) {
            menu.getMenuInflater().inflate(R.menu.menu_item_app_uninstall, menu.getMenu());
        }
    } catch (NameNotFoundException | IndexOutOfBoundsException e) {
    // should not happen
    }
    //append root menu if available
    if (KissApplication.getRootHandler(context).isRootActivated() && KissApplication.getRootHandler(context).isRootAvailable()) {
        menu.getMenuInflater().inflate(R.menu.menu_item_app_root, menu.getMenu());
    }
    return menu;
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ApplicationInfo(android.content.pm.ApplicationInfo) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) LauncherApps(android.content.pm.LauncherApps) MainActivity(fr.neamar.kiss.MainActivity) PopupMenu(android.widget.PopupMenu)

Aggregations

ApplicationInfo (android.content.pm.ApplicationInfo)1 LauncherActivityInfo (android.content.pm.LauncherActivityInfo)1 LauncherApps (android.content.pm.LauncherApps)1 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1 PopupMenu (android.widget.PopupMenu)1 MainActivity (fr.neamar.kiss.MainActivity)1