Example usage for android.content.pm ApplicationInfo FLAG_UPDATED_SYSTEM_APP

List of usage examples for android.content.pm ApplicationInfo FLAG_UPDATED_SYSTEM_APP

Introduction

In this page you can find the example usage for android.content.pm ApplicationInfo FLAG_UPDATED_SYSTEM_APP.

Prototype

int FLAG_UPDATED_SYSTEM_APP

To view the source code for android.content.pm ApplicationInfo FLAG_UPDATED_SYSTEM_APP.

Click Source Link

Document

Value for #flags : this is set if this application has been installed as an update to a built-in system application.

Usage

From source file:Main.java

public static boolean filterApp(ApplicationInfo info) {

    if ((info.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0)
        return true;
    else if ((info.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
        return true;
    }//from  w  w w  .  j a v  a2 s  .  co  m
    return false;
}

From source file:Main.java

public static boolean isSystemApp(ApplicationInfo info) {
    if ((info.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
        return true;
    } else if ((info.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
        return true;
    }/*from   w w w  .j  a va 2 s  . com*/
    return false;
}

From source file:Main.java

public static boolean isUserApp(ApplicationInfo info) {
    if (info == null) {
        return false;
    }/*from w  w  w . jav  a 2s .c  o  m*/
    return !((info.flags & ApplicationInfo.FLAG_SYSTEM) != 0
            || (info.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0);
}

From source file:Main.java

public static boolean isSystemApplication(int flags) {
    if ((flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0)
        return true;
    else if ((flags & ApplicationInfo.FLAG_SYSTEM) != 0)
        return true;

    return false;
}

From source file:Main.java

public static boolean isSystem(String packageName, Context context) {
    try {/* w  w w  .j a va 2  s  . c  o  m*/
        PackageManager pm = context.getPackageManager();
        PackageInfo info = pm.getPackageInfo(packageName, 0);
        return ((info.applicationInfo.flags
                & (ApplicationInfo.FLAG_SYSTEM | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP)) != 0);
        /*
        PackageInfo pkg = pm.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
        PackageInfo sys = pm.getPackageInfo("android", PackageManager.GET_SIGNATURES);
        return (pkg != null && pkg.signatures != null && pkg.signatures.length > 0 &&
            sys.signatures.length > 0 && sys.signatures[0].equals(pkg.signatures[0]));
         */
    } catch (PackageManager.NameNotFoundException ignore) {
        return false;
    }
}

From source file:Main.java

public static String getNativeLibraryDirectory(Context appContext) {
    ApplicationInfo ai = context.getApplicationInfo();

    Log.w("NDKHelper", "ai.nativeLibraryDir:" + ai.nativeLibraryDir);

    if ((ai.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0
            || (ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
        return ai.nativeLibraryDir;
    }/*  w  w  w .  j  a  v  a2s  .  c  om*/
    return "/system/lib/";
}

From source file:Main.java

public static boolean isSysApp(Context context, String pkgName) {
    if (context == null || TextUtils.isEmpty(pkgName)) {
        return false;
    }/*from  w  w w .j  a  v  a2  s . c  om*/

    try {
        PackageManager packageManager = context.getPackageManager();
        ApplicationInfo applicationInfo = packageManager.getPackageInfo(pkgName, 0).applicationInfo;
        //            return (applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == ApplicationInfo.FLAG_SYSTEM;
        return ((ApplicationInfo.FLAG_SYSTEM | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP)
                & applicationInfo.flags) != 0;
    } catch (Exception e) {
        e.printStackTrace();
    }

    return false;
}

From source file:Main.java

public static void send(Context context, String path) {

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    PackageManager pm = context.getPackageManager();
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setType("*/*");
    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(path)));
    List<ResolveInfo> list = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    boolean flag = false;
    for (ResolveInfo info : list) {
        if (info.activityInfo.packageName.toLowerCase().contains("bluetooth")
                || info.activityInfo.name.toLowerCase().contains("bluetooth")) {
            ApplicationInfo appInfo = null;
            try {
                appInfo = pm.getApplicationInfo(info.activityInfo.packageName, PackageManager.GET_META_DATA);
            } catch (PackageManager.NameNotFoundException e) {

            }//from  ww  w .  ja  v  a  2s .c  o m
            if (appInfo != null && (appInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 0
                    && (appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
                intent.setClassName(info.activityInfo.packageName, info.activityInfo.name);
                flag = true;
                break;
            }
        }
    }
    if (!flag) {
        return;
    }
    context.startActivity(intent);
}

From source file:Main.java

/**
 * Returns {@code true} if the application is system.
 *
 * @param context    The instance of {@link android.content.Context}.
 * @param appPackage The package of the checked application.
 * @return {@code true} if the application is system, {@code false} otherwise.
 *//* w ww.  j  a  v  a2 s .  c  o  m*/
public static boolean isSystemApp(@NonNull final Context context, @NonNull final String appPackage) {
    try {
        final ApplicationInfo appInfo = context.getPackageManager().getApplicationInfo(appPackage, 0);
        return (appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0
                || (appInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0;
    } catch (PackageManager.NameNotFoundException ignore) {
        // ignore
    }
    return false;
}

From source file:org.fdroid.fdroid.privileged.views.UninstallDialogActivity.java

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final Intent intent = getIntent();
    final String packageName = intent.getStringExtra(Installer.EXTRA_PACKAGE_NAME);

    PackageManager pm = getPackageManager();

    ApplicationInfo appInfo;/*from  w ww  .  j  a va 2  s . c  o  m*/
    try {
        //noinspection WrongConstant (lint is actually wrong here!)
        appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES);
    } catch (PackageManager.NameNotFoundException e) {
        throw new RuntimeException("Failed to get ApplicationInfo for uninstalling");
    }

    final boolean isSystem = (appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
    final boolean isUpdate = (appInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0;

    if (isSystem && !isUpdate) {
        // Cannot remove system apps unless we're uninstalling updates
        throw new RuntimeException("Cannot remove system apps unless we're uninstalling updates");
    }

    int messageId;
    if (isUpdate) {
        messageId = R.string.uninstall_update_confirm;
    } else {
        messageId = R.string.uninstall_confirm;
    }

    // hack to get theme applied (which is not automatically applied due to activity's Theme.NoDisplay
    ContextThemeWrapper theme = new ContextThemeWrapper(this, FDroidApp.getCurThemeResId());

    final AlertDialog.Builder builder = new AlertDialog.Builder(theme);
    builder.setTitle(appInfo.loadLabel(pm));
    builder.setIcon(appInfo.loadIcon(pm));
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Intent data = new Intent();
            data.putExtra(Installer.EXTRA_PACKAGE_NAME, packageName);
            setResult(Activity.RESULT_OK, intent);
            finish();
        }
    });
    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            setResult(Activity.RESULT_CANCELED);
            finish();
        }
    });
    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            setResult(Activity.RESULT_CANCELED);
            finish();
        }
    });
    builder.setMessage(messageId);
    builder.create().show();
}