// Path: app/src/main/java/com/livingstoneapp/models/DeclaredPermission.java
// public class DeclaredPermission {
// 
//     private String mName;
//     private String mLabel;
//     private ArrayList<String> mProtectionLevel;
//     private ArrayList<String> mFlags;
// 
//     public DeclaredPermission(String mName, String mLabel, ArrayList<String> mProtectionLevel, ArrayList<String> mFlags) {
//         this.mLabel = mLabel;
//         this.mName = mName;
//         this.mProtectionLevel = mProtectionLevel;
//         this.mFlags = mFlags;
//     }
// 
//     public String getLabel() {
//         return mLabel;
//     }
// 
//     public String getName() {
//         return mName;
//     }
// 
//     public ArrayList<String> getProtectionLevel() {
//         return mProtectionLevel;
//     }
// 
//     public ArrayList<String> getFlags() { return mFlags; }
// }
// 
// Path: app/src/main/java/com/livingstoneapp/models/RequestedPermission.java
// public class RequestedPermission {
//     private String mName;
//     private boolean mGranted;
// 
//     public RequestedPermission(String mName, boolean mGranted) {
//         this.mGranted = mGranted;
//         this.mName = mName;
//     }
// 
//     public boolean isGranted() {
//         return mGranted;
//     }
// 
//     public String getName() {
//         return mName;
//     }
// }
// 
// Path: app/src/main/java/com/livingstoneapp/utils/Utils.java
// public class Utils {
//     public static boolean hasFlag(
//             int flags,
//             int flagToCheck
//     ) {
//         return ((flags & flagToCheck) == flagToCheck);
//     }
// }


import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PermissionInfo;
import android.os.Build;
import java.util.ArrayList;
import rx.Observable;
import com.livingstoneapp.models.DeclaredPermission;
import com.livingstoneapp.models.RequestedPermission;
import com.livingstoneapp.utils.Utils;
                        if (Utils.hasFlag(info.protectionLevel, PermissionInfo.PROTECTION_FLAG_SYSTEM))
                            protectionLevels.add("PROTECTION_FLAG_SYSTEM");
                        if (Utils.hasFlag(info.protectionLevel, PermissionInfo.PROTECTION_SIGNATURE_OR_SYSTEM))
                            protectionLevels.add("PROTECTION_SIGNATURE_OR_SYSTEM");

                        //Flags
                        if (Utils.hasFlag(info.flags, PermissionInfo.FLAG_COSTS_MONEY))
                            flags.add("FLAG_COSTS_MONEY");
                        //hidden - http://developer.android.com/intl/ko/reference/android/R.attr.html#permissionFlags
                        if (Utils.hasFlag(info.flags, 0x2))
                            flags.add("hidden");

                        toReturn.add(new DeclaredPermission(
                                info.name.startsWith(packageName) == true ? info.name.replace(packageName, "") : info.name,
                                String.valueOf(info.loadLabel(packageManager)),
                                protectionLevels,
                                flags));
                    }
                }
                subscriber.onNext(toReturn);
                subscriber.onCompleted();
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
                subscriber.onError(e);
            }

        }));
    }

    @Override
// Path: app/src/main/java/com/livingstoneapp/models/DeclaredPermission.java
// public class DeclaredPermission {
// 
//     private String mName;
//     private String mLabel;
//     private ArrayList<String> mProtectionLevel;
//     private ArrayList<String> mFlags;
// 
//     public DeclaredPermission(String mName, String mLabel, ArrayList<String> mProtectionLevel, ArrayList<String> mFlags) {
//         this.mLabel = mLabel;
//         this.mName = mName;
//         this.mProtectionLevel = mProtectionLevel;
//         this.mFlags = mFlags;
//     }
// 
//     public String getLabel() {
//         return mLabel;
//     }
// 
//     public String getName() {
//         return mName;
//     }
// 
//     public ArrayList<String> getProtectionLevel() {
//         return mProtectionLevel;
//     }
// 
//     public ArrayList<String> getFlags() { return mFlags; }
// }
// 
// Path: app/src/main/java/com/livingstoneapp/models/RequestedPermission.java
// public class RequestedPermission {
//     private String mName;
//     private boolean mGranted;
// 
//     public RequestedPermission(String mName, boolean mGranted) {
//         this.mGranted = mGranted;
//         this.mName = mName;
//     }
// 
//     public boolean isGranted() {
//         return mGranted;
//     }
// 
//     public String getName() {
//         return mName;
//     }
// }
// 
// Path: app/src/main/java/com/livingstoneapp/utils/Utils.java
// public class Utils {
//     public static boolean hasFlag(
//             int flags,
//             int flagToCheck
//     ) {
//         return ((flags & flagToCheck) == flagToCheck);
//     }
// }


// Path: app/src/main/java/com/livingstoneapp/interactors/PermissionsInteractorImpl.java
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PermissionInfo;
import android.os.Build;
import java.util.ArrayList;
import rx.Observable;
import com.livingstoneapp.models.DeclaredPermission;
import com.livingstoneapp.models.RequestedPermission;
import com.livingstoneapp.utils.Utils;

                        if (Utils.hasFlag(info.protectionLevel, PermissionInfo.PROTECTION_FLAG_SYSTEM))
                            protectionLevels.add("PROTECTION_FLAG_SYSTEM");
                        if (Utils.hasFlag(info.protectionLevel, PermissionInfo.PROTECTION_SIGNATURE_OR_SYSTEM))
                            protectionLevels.add("PROTECTION_SIGNATURE_OR_SYSTEM");

                        //Flags
                        if (Utils.hasFlag(info.flags, PermissionInfo.FLAG_COSTS_MONEY))
                            flags.add("FLAG_COSTS_MONEY");
                        //hidden - http://developer.android.com/intl/ko/reference/android/R.attr.html#permissionFlags
                        if (Utils.hasFlag(info.flags, 0x2))
                            flags.add("hidden");

                        toReturn.add(new DeclaredPermission(
                                info.name.startsWith(packageName) == true ? info.name.replace(packageName, "") : info.name,
                                String.valueOf(info.loadLabel(packageManager)),
                                protectionLevels,
                                flags));
                    }
                }
                subscriber.onNext(toReturn);
                subscriber.onCompleted();
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
                subscriber.onError(e);
            }

        }));
    }

    @Override
    public Observable<ArrayList<RequestedPermission>> getRequestedPermissions(String packageName) {