Example usage for android.content.pm PackageManager PERMISSION_GRANTED

List of usage examples for android.content.pm PackageManager PERMISSION_GRANTED

Introduction

In this page you can find the example usage for android.content.pm PackageManager PERMISSION_GRANTED.

Prototype

int PERMISSION_GRANTED

To view the source code for android.content.pm PackageManager PERMISSION_GRANTED.

Click Source Link

Document

Permission check result: this is returned by #checkPermission if the permission has been granted to the given package.

Usage

From source file:Main.java

public static int isPackageMalicious(Context context, PackageInfo packageInfo) {
    // If the package being checked is this one, it's not malicious
    if (packageInfo.packageName.equals(context.getPackageName())) {
        return MALICIOUS_NOT;
    }/*ww  w.  jav a 2 s  .c o  m*/

    // If the package being checked shares a UID with Superuser, it's
    // probably malicious
    if (packageInfo.applicationInfo.uid == context.getApplicationInfo().uid) {
        return MALICIOUS_UID;
    }

    // Finally we check for any permissions that other apps should not have.
    if (packageInfo.requestedPermissions != null) {
        String[] bannedPermissions = new String[] { "com.noshufou.android.su.RESPOND",
                "com.noshufou.android.su.provider.WRITE" };
        for (String s : packageInfo.requestedPermissions) {
            for (int i = 0; i < 2; i++) {
                if (s.equals(bannedPermissions[i])
                        && context.getPackageManager().checkPermission(bannedPermissions[i],
                                packageInfo.packageName) == PackageManager.PERMISSION_GRANTED) {
                    return i + 2;
                }
            }
        }
    }

    return MALICIOUS_NOT;
}

From source file:cn.studyjams.s2.sj0132.bowenyan.mygirlfriend.nononsenseapps.notepad.util.PermissionsHelper.java

/**
 *
 * @param permissions that were requested
 * @param grantResults of the request/*from w  w w . j a  va  2  s  . c  om*/
 * @return true if all results were granted, false otherwise
 */
public static boolean permissionsGranted(@NonNull String[] permissions, @NonNull int[] grantResults) {
    return permissions.length > 0 && allEqual(PackageManager.PERMISSION_GRANTED, grantResults);
}

From source file:cat.mvmike.minimalcalendarwidget.activity.PermissionsActivity.java

@Override
public void onRequestPermissionsResult(final int requestCode, final @NonNull String[] permissions,
        final @NonNull int[] grantResults) {

    if (requestCode == READ_CALENDAR_PERM && grantResults.length == 1
            && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
        setResult(Activity.RESULT_OK);//from   w w  w  .  jav  a  2s. c  om
        MonthWidget.forceRedraw(this);
    }

    this.finish();
}

From source file:com.wbtech.common.CommonUtil.java

/**
 * ??/*from w  ww .  j  a  va 2s .  c om*/
 * @param context
 * @param permission  ??
 * @return true ??  false??
 */
public static boolean checkPermissions(Context context, String permission) {
    PackageManager localPackageManager = context.getPackageManager();
    return localPackageManager.checkPermission(permission,
            context.getPackageName()) == PackageManager.PERMISSION_GRANTED;
}

From source file:cn.qqjlbsc.shopseller.utlis.EasyPermissions.java

/**
        //  w w w.  j a va  2  s.  c o m
 */
public static boolean hasPermissions(Context context, String... perms) {
    // Always return true for SDK < M, let the system deal with the permissions
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        return true;
    }

    for (String perm : perms) {
        boolean hasPerm = (ContextCompat.checkSelfPermission(context,
                perm) == PackageManager.PERMISSION_GRANTED);
        if (!hasPerm) {
            return false;
        }
    }

    return true;
}

From source file:cn.finalteam.galleryfinal.permission.EasyPermissions.java

/**
 * Check if the calling context has a set of permissions.
 *
 * @param context the calling context./*from  w ww.  jav a 2s  .c o  m*/
 * @param perms   one ore more permissions, such as {@code android.Manifest.permission.CAMERA}.
 * @return true if all permissions are already granted, false if at least one permission
 * is not yet granted.
 */
public static boolean hasPermissions(Context context, String... perms) {
    for (String perm : perms) {
        boolean hasPerm = (ContextCompat.checkSelfPermission(context,
                perm) == PackageManager.PERMISSION_GRANTED);
        if (!hasPerm) {
            return false;
        }
    }

    return true;
}

From source file:com.acrr.base.permissions.RuntimePermissions.java

/**
 * @return {@code true} if the app has this permission given,
 * {@code false} otherwise./*from w  w  w  .j a v  a2  s. c o m*/
 * @see #allowed(Context, String)
 */
@SuppressLint("NewApi")
public static boolean has(@NonNull Context context, @NonNull String permission) {
    if (allowed(context, permission)) {
    } else
        return false;

    switch (permission) {
    case Manifest.permission.SYSTEM_ALERT_WINDOW:
        return !Device.hasMarshmallowApi() || Settings.canDrawOverlays(context);
    case Manifest.permission.WRITE_SETTINGS:
        return !Device.hasMarshmallowApi() || Settings.System.canWrite(context);
    }

    final int r = ContextCompat.checkSelfPermission(context, permission);
    return r == PackageManager.PERMISSION_GRANTED;
}

From source file:at.bitfire.davdroid.ui.PermissionsActivity.java

protected void refresh() {
    boolean noCalendarPermissions = ActivityCompat.checkSelfPermission(this,
            Manifest.permission.READ_CALENDAR) != PackageManager.PERMISSION_GRANTED
            || ActivityCompat.checkSelfPermission(this,
                    Manifest.permission.WRITE_CALENDAR) != PackageManager.PERMISSION_GRANTED;
    findViewById(R.id.calendar_permissions).setVisibility(noCalendarPermissions ? View.VISIBLE : View.GONE);

    boolean noContactsPermissions = ActivityCompat.checkSelfPermission(this,
            Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED
            || ActivityCompat.checkSelfPermission(this,
                    Manifest.permission.WRITE_CONTACTS) != PackageManager.PERMISSION_GRANTED;
    findViewById(R.id.contacts_permissions).setVisibility(noContactsPermissions ? View.VISIBLE : View.GONE);

    boolean noTaskPermissions;
    if (LocalTaskList.tasksProviderAvailable(this)) {
        noTaskPermissions = ActivityCompat.checkSelfPermission(this,
                PERMISSION_READ_TASKS) != PackageManager.PERMISSION_GRANTED
                || ActivityCompat.checkSelfPermission(this,
                        PERMISSION_WRITE_TASKS) != PackageManager.PERMISSION_GRANTED;
        findViewById(R.id.opentasks_permissions).setVisibility(noTaskPermissions ? View.VISIBLE : View.GONE);
    } else {//  w w w  .j a va 2 s.  co  m
        findViewById(R.id.opentasks_permissions).setVisibility(View.GONE);
        noTaskPermissions = false;
    }

    if (!noCalendarPermissions && !noContactsPermissions && !noTaskPermissions) {
        NotificationManagerCompat nm = NotificationManagerCompat.from(this);
        nm.cancel(Constants.NOTIFICATION_PERMISSIONS);

        finish();
    }
}

From source file:com.andremion.louvre.StoragePermissionActivity.java

public void askForPermission() {

    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {

        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                Manifest.permission.READ_EXTERNAL_STORAGE)) {

            // Show an explanation to the user *asynchronously*
            showExplanation();/*from w  ww  . j av a  2  s.  c  o  m*/

        } else {

            // No explanation needed, we can request the permission.
            ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.READ_EXTERNAL_STORAGE },
                    REQUEST_READ_EXTERNAL_STORAGE);
        }

    } else {

        onPermissionGranted();
    }

}

From source file:MainActivity.java

private boolean checkCallPermission() {
    String permission = "android.permission.CALL_PHONE";
    int res = checkCallingOrSelfPermission(permission);
    return (res == PackageManager.PERMISSION_GRANTED);
}