Example usage for android.content.pm PackageManager GET_PERMISSIONS

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

Introduction

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

Prototype

int GET_PERMISSIONS

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

Click Source Link

Document

PackageInfo flag: return information about permissions in the package in PackageInfo#permissions .

Usage

From source file:com.chasetech.pcount.autoupdate.AutoUpdateApk.java

private boolean haveInternetPermissions() {
    Set<String> required_perms = new HashSet<String>();
    required_perms.add("android.permission.INTERNET");
    required_perms.add("android.permission.ACCESS_WIFI_STATE");
    required_perms.add("android.permission.ACCESS_NETWORK_STATE");

    PackageManager pm = context.getPackageManager();
    String packageName = context.getPackageName();
    int flags = PackageManager.GET_PERMISSIONS;
    PackageInfo packageInfo = null;/*  w ww. j a va  2 s  .  c  o m*/

    try {
        packageInfo = pm.getPackageInfo(packageName, flags);
        versionCode = packageInfo.versionCode;
    } catch (NameNotFoundException e) {
        //         e.printStackTrace();
        Log_e(TAG, e.getMessage());
    }
    if (packageInfo.requestedPermissions != null) {
        for (String p : packageInfo.requestedPermissions) {
            //Log_v(TAG, "permission: " + p.toString());
            required_perms.remove(p);
        }
        if (required_perms.size() == 0) {
            return true; // permissions are in order
        }
        // something is missing
        for (String p : required_perms) {
            Log_e(TAG, "required permission missing: " + p);
        }
    }
    Log_e(TAG, "INTERNET/WIFI access required, but no permissions are found in Manifest.xml");
    return false;
}

From source file:android.content.pm.PackageParser.java

public static PackageInfo generatePackageInfo(PackageParser.Package p, int gids[], int flags,
        long firstInstallTime, long lastUpdateTime, Set<String> grantedPermissions, PackageUserState state,
        int userId) {

    if (!checkUseInstalledOrHidden(flags, state)) {
        return null;
    }/*from w ww .  j  av a  2s  . co  m*/
    PackageInfo pi = new PackageInfo();
    pi.packageName = p.packageName;
    pi.splitNames = p.splitNames;
    pi.versionCode = p.mVersionCode;
    pi.baseRevisionCode = p.baseRevisionCode;
    pi.splitRevisionCodes = p.splitRevisionCodes;
    pi.versionName = p.mVersionName;
    pi.sharedUserId = p.mSharedUserId;
    pi.sharedUserLabel = p.mSharedUserLabel;
    pi.applicationInfo = generateApplicationInfo(p, flags, state, userId);
    pi.installLocation = p.installLocation;
    pi.coreApp = p.coreApp;
    if ((pi.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0
            || (pi.applicationInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
        pi.requiredForAllUsers = p.mRequiredForAllUsers;
    }
    pi.restrictedAccountType = p.mRestrictedAccountType;
    pi.requiredAccountType = p.mRequiredAccountType;
    pi.overlayTarget = p.mOverlayTarget;
    pi.firstInstallTime = firstInstallTime;
    pi.lastUpdateTime = lastUpdateTime;
    if ((flags & PackageManager.GET_GIDS) != 0) {
        pi.gids = gids;
    }
    if ((flags & PackageManager.GET_CONFIGURATIONS) != 0) {
        int N = p.configPreferences != null ? p.configPreferences.size() : 0;
        if (N > 0) {
            pi.configPreferences = new ConfigurationInfo[N];
            p.configPreferences.toArray(pi.configPreferences);
        }
        N = p.reqFeatures != null ? p.reqFeatures.size() : 0;
        if (N > 0) {
            pi.reqFeatures = new FeatureInfo[N];
            p.reqFeatures.toArray(pi.reqFeatures);
        }
        N = p.featureGroups != null ? p.featureGroups.size() : 0;
        if (N > 0) {
            pi.featureGroups = new FeatureGroupInfo[N];
            p.featureGroups.toArray(pi.featureGroups);
        }
    }
    if ((flags & PackageManager.GET_ACTIVITIES) != 0) {
        int N = p.activities.size();
        if (N > 0) {
            if ((flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
                pi.activities = new ActivityInfo[N];
            } else {
                int num = 0;
                for (int i = 0; i < N; i++) {
                    if (p.activities.get(i).info.enabled)
                        num++;
                }
                pi.activities = new ActivityInfo[num];
            }
            for (int i = 0, j = 0; i < N; i++) {
                final Activity activity = p.activities.get(i);
                if (activity.info.enabled || (flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
                    pi.activities[j++] = generateActivityInfo(p.activities.get(i), flags, state, userId);
                }
            }
        }
    }
    if ((flags & PackageManager.GET_RECEIVERS) != 0) {
        int N = p.receivers.size();
        if (N > 0) {
            if ((flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
                pi.receivers = new ActivityInfo[N];
            } else {
                int num = 0;
                for (int i = 0; i < N; i++) {
                    if (p.receivers.get(i).info.enabled)
                        num++;
                }
                pi.receivers = new ActivityInfo[num];
            }
            for (int i = 0, j = 0; i < N; i++) {
                final Activity activity = p.receivers.get(i);
                if (activity.info.enabled || (flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
                    pi.receivers[j++] = generateActivityInfo(p.receivers.get(i), flags, state, userId);
                }
            }
        }
    }
    if ((flags & PackageManager.GET_SERVICES) != 0) {
        int N = p.services.size();
        if (N > 0) {
            if ((flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
                pi.services = new ServiceInfo[N];
            } else {
                int num = 0;
                for (int i = 0; i < N; i++) {
                    if (p.services.get(i).info.enabled)
                        num++;
                }
                pi.services = new ServiceInfo[num];
            }
            for (int i = 0, j = 0; i < N; i++) {
                final Service service = p.services.get(i);
                if (service.info.enabled || (flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
                    pi.services[j++] = generateServiceInfo(p.services.get(i), flags, state, userId);
                }
            }
        }
    }
    if ((flags & PackageManager.GET_PROVIDERS) != 0) {
        int N = p.providers.size();
        if (N > 0) {
            if ((flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
                pi.providers = new ProviderInfo[N];
            } else {
                int num = 0;
                for (int i = 0; i < N; i++) {
                    if (p.providers.get(i).info.enabled)
                        num++;
                }
                pi.providers = new ProviderInfo[num];
            }
            for (int i = 0, j = 0; i < N; i++) {
                final Provider provider = p.providers.get(i);
                if (provider.info.enabled || (flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
                    pi.providers[j++] = generateProviderInfo(p.providers.get(i), flags, state, userId);
                }
            }
        }
    }
    if ((flags & PackageManager.GET_INSTRUMENTATION) != 0) {
        int N = p.instrumentation.size();
        if (N > 0) {
            pi.instrumentation = new InstrumentationInfo[N];
            for (int i = 0; i < N; i++) {
                pi.instrumentation[i] = generateInstrumentationInfo(p.instrumentation.get(i), flags);
            }
        }
    }
    if ((flags & PackageManager.GET_PERMISSIONS) != 0) {
        int N = p.permissions.size();
        if (N > 0) {
            pi.permissions = new PermissionInfo[N];
            for (int i = 0; i < N; i++) {
                pi.permissions[i] = generatePermissionInfo(p.permissions.get(i), flags);
            }
        }
        N = p.requestedPermissions.size();
        if (N > 0) {
            pi.requestedPermissions = new String[N];
            pi.requestedPermissionsFlags = new int[N];
            for (int i = 0; i < N; i++) {
                final String perm = p.requestedPermissions.get(i);
                pi.requestedPermissions[i] = perm;
                // The notion of required permissions is deprecated but for compatibility.
                pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_REQUIRED;
                if (grantedPermissions != null && grantedPermissions.contains(perm)) {
                    pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_GRANTED;
                }
            }
        }
    }
    if ((flags & PackageManager.GET_SIGNATURES) != 0) {
        int N = (p.mSignatures != null) ? p.mSignatures.length : 0;
        if (N > 0) {
            pi.signatures = new Signature[N];
            System.arraycopy(p.mSignatures, 0, pi.signatures, 0, N);
        }
    }
    return pi;
}

From source file:com.codename1.impl.android.AndroidImplementation.java

/**
 * Action categories are defined on the Main class by implementing the PushActionsProvider, however
 * the main class may not be available to the push receiver, so we need to save these categories
 * to the file system when the app is installed, then the push receiver can load these actions
 * when it sends a push while the app isn't running.
 * @param provider A reference to the App's main class 
 * @throws IOException //  ww  w.j  a v  a  2 s . c om
 */
public static void installNotificationActionCategories(PushActionsProvider provider) throws IOException {
    // Assume that CN1 is running... this will run when the app starts
    // up
    Context context = getContext();
    boolean requiresUpdate = false;

    File categoriesFile = new File(
            activity.getFilesDir().getAbsolutePath() + "/" + FILE_NAME_NOTIFICATION_CATEGORIES);
    if (!categoriesFile.exists()) {
        requiresUpdate = true;
    }
    if (!requiresUpdate) {
        try {
            PackageInfo packageInfo = context.getPackageManager().getPackageInfo(
                    context.getApplicationContext().getPackageName(), PackageManager.GET_PERMISSIONS);
            if (packageInfo.lastUpdateTime > categoriesFile.lastModified()) {
                requiresUpdate = true;
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    if (!requiresUpdate) {
        return;
    }

    OutputStream os = getContext().openFileOutput(FILE_NAME_NOTIFICATION_CATEGORIES, 0);
    PushActionCategory[] categories = provider.getPushActionCategories();
    javax.xml.parsers.DocumentBuilderFactory docFactory = javax.xml.parsers.DocumentBuilderFactory
            .newInstance();
    javax.xml.parsers.DocumentBuilder docBuilder;
    try {
        docBuilder = docFactory.newDocumentBuilder();
    } catch (ParserConfigurationException ex) {
        Logger.getLogger(AndroidImplementation.class.getName()).log(Level.SEVERE, null, ex);
        throw new IOException(
                "Faield to create document builder for creating notification categories XML document", ex);
    }

    // root elements
    org.w3c.dom.Document doc = docBuilder.newDocument();
    org.w3c.dom.Element root = (org.w3c.dom.Element) doc.createElement("categories");
    doc.appendChild(root);
    for (PushActionCategory category : categories) {
        org.w3c.dom.Element categoryEl = (org.w3c.dom.Element) doc.createElement("category");
        org.w3c.dom.Attr idAttr = doc.createAttribute("id");
        idAttr.setValue(category.getId());
        categoryEl.setAttributeNode(idAttr);

        for (PushAction action : category.getActions()) {
            org.w3c.dom.Element actionEl = (org.w3c.dom.Element) doc.createElement("action");
            org.w3c.dom.Attr actionIdAttr = doc.createAttribute("id");
            actionIdAttr.setValue(action.getId());
            actionEl.setAttributeNode(actionIdAttr);

            org.w3c.dom.Attr actionTitleAttr = doc.createAttribute("title");
            if (action.getTitle() != null) {
                actionTitleAttr.setValue(action.getTitle());
            } else {
                actionTitleAttr.setValue(action.getId());
            }
            actionEl.setAttributeNode(actionTitleAttr);

            if (action.getIcon() != null) {
                org.w3c.dom.Attr actionIconAttr = doc.createAttribute("icon");
                String iconVal = action.getIcon();
                try {
                    // We'll store the resource IDs for the icon
                    // rather than the icon name because that is what
                    // the push notifications require.
                    iconVal = "" + context.getResources().getIdentifier(iconVal, "drawable",
                            context.getPackageName());
                    actionIconAttr.setValue(iconVal);
                    actionEl.setAttributeNode(actionIconAttr);
                } catch (Exception ex) {
                    ex.printStackTrace();

                }

            }

            if (action.getTextInputPlaceholder() != null) {
                org.w3c.dom.Attr textInputPlaceholderAttr = doc.createAttribute("textInputPlaceholder");
                textInputPlaceholderAttr.setValue(action.getTextInputPlaceholder());
                actionEl.setAttributeNode(textInputPlaceholderAttr);
            }
            if (action.getTextInputButtonText() != null) {
                org.w3c.dom.Attr textInputButtonTextAttr = doc.createAttribute("textInputButtonText");
                textInputButtonTextAttr.setValue(action.getTextInputButtonText());
                actionEl.setAttributeNode(textInputButtonTextAttr);
            }
            categoryEl.appendChild(actionEl);
        }
        root.appendChild(categoryEl);

    }
    try {
        javax.xml.transform.TransformerFactory transformerFactory = javax.xml.transform.TransformerFactory
                .newInstance();
        javax.xml.transform.Transformer transformer = transformerFactory.newTransformer();
        javax.xml.transform.dom.DOMSource source = new javax.xml.transform.dom.DOMSource(doc);
        javax.xml.transform.stream.StreamResult result = new javax.xml.transform.stream.StreamResult(os);
        transformer.transform(source, result);

    } catch (Exception ex) {
        throw new IOException("Failed to save notification categories as XML.", ex);
    }

}

From source file:edu.mit.media.funf.probe.Probe.java

private static PackageInfo getPackageInfo(Context context, String packageName) {
    long now = System.currentTimeMillis();
    if (apps == null || now > (appsLastLoadTime + APPS_CACHE_TIME)) {
        apps = context.getPackageManager().getInstalledPackages(PackageManager.GET_PERMISSIONS);
        appsLastLoadTime = now;//  w w  w.  j a v  a 2  s  . c o m
    }
    for (PackageInfo info : apps) {
        if (info.packageName.equals(packageName)) {
            return info;
        }
    }
    return null;
}

From source file:com.landenlabs.all_devtool.PackageFragment.java

/**
 * Load installed (user or system) packages.
 *//*from w  w  w.  j a  v a2  s.  c o  m*/
void loadInstalledPackages() {
    try {
        m_workList = new ArrayList<PackingItem>();
        int flags1 = PackageManager.GET_PERMISSIONS | PackageManager.GET_PROVIDERS // use hides some app, may require permissions
                | PackageManager.GET_ACTIVITIES | PackageManager.GET_RECEIVERS // use hides some app, may require permissions
                | PackageManager.GET_SERVICES;

        int flags2 = PackageManager.GET_PERMISSIONS | PackageManager.GET_ACTIVITIES
                | PackageManager.GET_SERVICES;

        int flags3 = PackageManager.GET_PERMISSIONS;
        int flags4 = 0;
        boolean showSys = (m_show == SHOW_SYS);

        // Some packages will not appear with some flags.
        loadAndAddPackages(showSys, flags1);
        loadAndAddPackages(showSys, flags2);
        loadAndAddPackages(showSys, flags3);
        loadAndAddPackages(showSys, flags4);

        // Sort per settings.
        // TODO *** This does not seem to be working ***
        Message msgObj = m_handler.obtainMessage(MSG_SORT_LIST);
        m_handler.sendMessage(msgObj);

    } catch (Exception ex) {
        m_log.e(ex.getMessage());
    }
}

From source file:self.philbrown.droidQuery.$.java

/**
 * Write a String to file, and execute functions once complete. 
 * @param s the String to write to the file
 * @param path defines the save location of the file
 * @param append {@code true} to append the new String to the end of the file. {@code false} to overwrite any existing file.
 * @param async {@code true} if the operation should be performed asynchronously. Otherwise, {@code false}.
 * @param success Function to invoke on a successful file-write. Parameters received will be:
 * <ol>/*from ww  w.  j a v  a  2s . c o  m*/
 * <li>the String to write
 * <li>the File that was written (to)
 * </ol>
 * @param error Function to invoke on a file I/O error. Parameters received will be:
 * <ol>
 * <li>the String to write
 * <li>the String reason
 * </ol>
 */
public void write(final String s, final FileLocation path, final String fileName, boolean append, boolean async,
        final Function success, Function error) {
    boolean hasWritePermissions = false;
    try {
        PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(),
                PackageManager.GET_PERMISSIONS);
        if (info.requestedPermissions != null) {
            for (String p : info.requestedPermissions) {
                if (p.equals("android.permission.WRITE_EXTERNAL_STORAGE")) {
                    hasWritePermissions = true;
                    break;
                }
            }
        }
    } catch (Exception e) {
        if (error != null) {
            error.invoke(this, s, "Invalid Project Package!");
        }
        return;
    }
    if (!hasWritePermissions) {
        if (error != null) {
            error.invoke(this, s,
                    "You do not have file write privelages. Add the android.permission.WRITE_EXTERNAL_STORAGE permission to your Android Manifest.");
        }
        return;
    }

    File logFile;

    if (path == FileLocation.INTERNAL) {
        if (fileName.contains("\\")) {
            if (error != null) {
                error.invoke(this, s, "Internal file names cannot include a path separator. Aborting.");
            }
            return;
        }
        try {
            if (fileObservers == null) {
                fileObservers = new ArrayList<LogFileObserver>();
            }
            LogFileObserver o = new LogFileObserver(fileName, new Runnable() {
                @Override
                public void run() {
                    if (success != null)
                        success.invoke($.this, s, new File(
                                String.format(Locale.US, "%s/%s", context.getFilesDir().getName(), fileName)));
                }
            });
            fileObservers.add(o);
            o.startWatching();

            FileOutputStream fw = context.openFileOutput(fileName,
                    (append ? Context.MODE_APPEND : Context.MODE_PRIVATE));
            fw.write(s.getBytes());
            fw.close();
        } catch (Throwable t) {
            t.printStackTrace();
        }
        return;
    } else if (path == FileLocation.CACHE) {
        String storageDir = context.getCacheDir().toString();

        logFile = new File(String.format(Locale.US, "%s/%s", storageDir, fileName));
        //make the parent directory if it does not exist
        logFile.getParentFile().mkdirs();
    } else if (path == FileLocation.DATA) {
        String storageDir = Environment.getExternalStorageDirectory().toString();
        String mainDirName = String.format(Locale.US, "%s/Android/data/%s", storageDir,
                context.getPackageName());

        logFile = new File(String.format(Locale.US, "%s/%s", mainDirName, fileName));
        //make the parent directory if it does not exist
        logFile.getParentFile().mkdirs();
    } else if (path == FileLocation.CUSTOM) {
        logFile = new File(fileName);
        //make the parent directory if it does not exist
        logFile.getParentFile().mkdirs();
    } else //external (default)
    {
        String storageDir = Environment.getExternalStorageDirectory().toString();
        String mainDirName = String.format(Locale.US, "%s/%s", storageDir, context.getPackageName());

        logFile = new File(String.format(Locale.US, "%s/%s", mainDirName, fileName));
        //make the parent directory if it does not exist
        logFile.getParentFile().mkdirs();
    }

    try {
        if (fileObservers == null) {
            fileObservers = new ArrayList<LogFileObserver>();
        }
        final File fLogFile = logFile;
        LogFileObserver o = new LogFileObserver(logFile, new Runnable() {
            @Override
            public void run() {
                if (success != null)
                    success.invoke($.this, s, fLogFile);
            }
        });

        fileObservers.add(o);
        o.startWatching();

        FileOutputStream os = new FileOutputStream(logFile, append);
        os.write(s.getBytes());
        os.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:self.philbrown.droidQuery.$.java

/**
 * Write a byte stream to file, and execute functions once complete. 
 * @param s the bytes to write to the file
 * @param path defines the save location of the file
 * @param append {@code true} to append the new bytes to the end of the file. {@code false} to overwrite any existing file.
 * @param async {@code true} if the operation should be performed asynchronously. Otherwise, {@code false}.
 * @param success Function to invoke on a successful file-write. Parameters received will be:
 * <ol>/*from www.  j a  v  a2  s.  c  o m*/
 * <li>the byte[] to write
 * <li>the path to the file
 * </ol>
 * @param error Function to invoke on a file I/O error. Parameters received will be:
 * <ol>
 * <li>the byte[] to write
 * <li>the path to the file
 * </ol>
 */
public void write(final byte[] s, final FileLocation path, String fileName, boolean append, boolean async,
        final Function success, Function error) {
    boolean hasWritePermissions = false;
    try {
        PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(),
                PackageManager.GET_PERMISSIONS);
        if (info.requestedPermissions != null) {
            for (String p : info.requestedPermissions) {
                if (p.equals("android.permission.WRITE_EXTERNAL_STORAGE")) {
                    hasWritePermissions = true;
                    break;
                }
            }
        }
    } catch (Exception e) {
        if (error != null) {
            error.invoke(this, s, path, "Invalid Project Package!");
        }
        return;
    }
    if (!hasWritePermissions) {
        if (error != null) {
            error.invoke(this, s, path,
                    "You do not have file write privelages. Add the android.permission.WRITE_EXTERNAL_STORAGE permission to your Android Manifest.");
        }
        return;
    }

    File logFile;

    if (path == FileLocation.INTERNAL) {
        if (fileName.contains("\\")) {
            if (error != null) {
                error.invoke(this, s, path, "Internal file names cannot include a path separator. Aborting.");
            }
            return;
        }
        try {
            if (fileObservers == null) {
                fileObservers = new ArrayList<LogFileObserver>();
            }
            LogFileObserver o = new LogFileObserver(fileName, new Runnable() {
                @Override
                public void run() {
                    if (success != null)
                        success.invoke($.this, s, path);
                }
            });
            fileObservers.add(o);
            o.startWatching();

            FileOutputStream fw = context.openFileOutput(fileName,
                    (append ? Context.MODE_APPEND : Context.MODE_PRIVATE));
            fw.write(s);
            fw.close();
        } catch (Throwable t) {
            t.printStackTrace();
        }
        return;
    } else if (path == FileLocation.CACHE) {
        String storageDir = context.getCacheDir().toString();

        logFile = new File(String.format(Locale.US, "%s/%s", storageDir, fileName));
        //make the parent directory if it does not exist
        logFile.getParentFile().mkdirs();
    } else if (path == FileLocation.DATA) {
        String storageDir = Environment.getExternalStorageDirectory().toString();
        String mainDirName = String.format(Locale.US, "%s/Android/data/%s", storageDir,
                context.getPackageName());

        logFile = new File(String.format(Locale.US, "%s/%s", mainDirName, fileName));
        //make the parent directory if it does not exist
        logFile.getParentFile().mkdirs();
    } else if (path == FileLocation.CUSTOM) {
        logFile = new File(fileName);
        //make the parent directory if it does not exist
        logFile.getParentFile().mkdirs();
    } else //external (default)
    {
        String storageDir = Environment.getExternalStorageDirectory().toString();
        String mainDirName = String.format(Locale.US, "%s/%s", storageDir, context.getPackageName());

        logFile = new File(String.format(Locale.US, "%s/%s", mainDirName, fileName));
        //make the parent directory if it does not exist
        logFile.getParentFile().mkdirs();
    }

    try {
        if (fileObservers == null) {
            fileObservers = new ArrayList<LogFileObserver>();
        }
        LogFileObserver o = new LogFileObserver(logFile, new Runnable() {
            @Override
            public void run() {
                if (success != null)
                    success.invoke($.this, s, path);
            }
        });

        fileObservers.add(o);
        o.startWatching();

        FileOutputStream os = new FileOutputStream(logFile, append);
        os.write(s);
        os.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.codename1.impl.android.AndroidImplementation.java

/**
 * Return a list of all of the permissions that have been requested by the app (granted or no).
 * This can be used to see which permissions are included in the manifest file.
 * @return //from   w  w  w  .j a  v a 2 s.  c  o  m
 */
public static List<String> getRequestedPermissions() {
    PackageManager pm = getContext().getPackageManager();
    try {
        PackageInfo packageInfo = pm.getPackageInfo(getContext().getPackageName(),
                PackageManager.GET_PERMISSIONS);
        String[] requestedPermissions = null;
        if (packageInfo != null) {
            requestedPermissions = packageInfo.requestedPermissions;
            return Arrays.asList(requestedPermissions);
        }
        return new ArrayList<String>();
    } catch (PackageManager.NameNotFoundException e) {
        com.codename1.io.Log.e(e);
        return new ArrayList<String>();
    }
}