FlashNotifier/src/main/java/com/pandanomic/flashnotifier/SMSCallListener.java
private String verifyAPICall(Intent intent) {
            PackageManager pm = getPackageManager();
            String packageName = intent.getStringExtra("calling_application");

            // Check to make sure it included the package name
            if (packageName == null) {
                Toast.makeText(getBaseContext(), "App has malformed API call (missing package name)", Toast.LENGTH_SHORT).show();
                return null;
            }

            // Get the package name
            ApplicationInfo ai;
            try {
                ai = pm.getApplicationInfo(packageName, 0);
            } catch (final PackageManager.NameNotFoundException e) {
                ai = null;
            }
            final String applicationName = (String) (ai != null ? pm.getApplicationLabel(ai) : null);

            // Check the manifest permissions
            if (PackageManager.PERMISSION_DENIED == pm.checkPermission(PERMISSION, packageName)) {
                Toast.makeText(getBaseContext(), applicationName + " hasn't declared the permission in the manifest", Toast.LENGTH_SHORT).show();
                return null;
            }

            return applicationName;
        }
/**
         * Method for verifying that the API call is allowed, based on the calling app's permissions
         * @param intent sending intent to use the API
         * @return String null if it failed, app name if it worked
         */
Method for verifying that the API call is allowed, based on the calling app's permissions
@param intent sending intent to use the API
@return String null if it failed, app name if it worked
Method for verifying that the API call is allowed based on the calling app ' s permissions @param intent sending intent to use the API @return String null if it failed app name if it worked
private String verifyAPICall(Intent intent) {
            PackageManager pm = getPackageManager();
            String packageName = intent.getStringExtra("calling_application");
            if (packageName == null) {
                Toast.makeText(getBaseContext(), "App has malformed API call (missing package name)", Toast.LENGTH_SHORT).show();
                return null;
            }
            ApplicationInfo ai;
            try {
                ai = pm.getApplicationInfo(packageName, 0);
            } catch (final PackageManager.NameNotFoundException e) {
                ai = null;
            }
            final String applicationName = (String) (ai != null ? pm.getApplicationLabel(ai) : null);
            if (PackageManager.PERMISSION_DENIED == pm.checkPermission(PERMISSION, packageName)) {
                Toast.makeText(getBaseContext(), applicationName + " hasn't declared the permission in the manifest", Toast.LENGTH_SHORT).show();
                return null;
            }
            return applicationName;
        }
private String verifyAPICall ( Intent intent ) { PackageManager pm = getPackageManager ( ) ; String packageName = intent . getStringExtra ( "calling_application" ) ; if ( packageName == null ) { Toast . makeText ( getBaseContext ( ) , "App has malformed API call (missing package name)" , Toast . LENGTH_SHORT ) . show ( ) ; return null ; } ApplicationInfo ai ; try { ai = pm . getApplicationInfo ( packageName , 0 ) ; } catch ( final PackageManager . NameNotFoundException e ) { ai = null ; } final String applicationName = ( String ) ( ai != null ? pm . getApplicationLabel ( ai ) : null ) ; if ( PackageManager . PERMISSION_DENIED == pm . checkPermission ( PERMISSION , packageName ) ) { Toast . makeText ( getBaseContext ( ) , applicationName + " hasn't declared the permission in the manifest" , Toast . LENGTH_SHORT ) . show ( ) ; return null ; } return applicationName ; }
Method for verifying that the API call is allowed, based on the calling app's permissions
 @param intent sending intent to use the API
 @return String null if it failed, app name if it worked
Method for verifying that the API call is allowed based on the calling app ' s permissions @param intent sending intent to use the API @return String null if it failed app name if it worked
// Check to make sure it included the package name // Get the package name // Check the manifest permissions