[
  {
    "path": ".github/ISSUE_TEMPLATE/bug_report.md",
    "content": "---\nname: Bug report\nabout: 'Create a bug report. '\ntitle: Bug\nlabels: ''\nassignees: ''\n\n---\n\n### Prerequisites\n\n* [] Put an X between the brackets on this line if you have done all of the following:\n    * Read carefully README: https://github.com/tbruyelle/RxPermissions#rxpermissions\n    * Checked that your issue isn't already filed: https://github.com/tbruyelle/RxPermissions/issues\n\n### Issue description\n[A clear and concise description of what the bug is.]\n\n### Actual behavior\n[A clear and concise description of what actually happened.]\n\n### Expected behavior\n[A clear and concise description of what you expected to happen.]\n\n### Steps To Reproduce\nSteps to reproduce the behavior:\n1. [First Step]\n2. [Second Step]\n3. [and so on...]\n\n### RxPermission usage code **(extremely Required)**\nGive a comprehensive example of how exactly RxPermission is used (Use [gists](https://gist.github.com/) or style code with styling markdown). \nProvide all info from the beginning that includes:\n- How and where RxPermission was instantiated. \n- In what lifecycle method. Activity or fragment. Give info about screen view hierarchy if it really complicated and has many nested Fragments.\n- Some additional info or important context if needed. \n\n### Lib Version\nGive info about what lib version do you use\n\n**Screenshots**\nAdd screenshots to help explain your problem only If it will be handy for your use case.\nIf issued only with particular device provide device info \n - Device: [e.g. Nexus 5]\n - OS version: [Android 5.1]\n"
  },
  {
    "path": ".github/ISSUE_TEMPLATE/feature_request.md",
    "content": "---\nname: Feature request\nabout: Suggest an idea\ntitle: ''\nlabels: ''\nassignees: ''\n\n---\n\n**Is your feature request related to a problem? Please describe.**\nA clear and concise description of what the problem is. Ex. I'm always frustrated when [...]\n\n**Describe the solution you'd like**\nA clear and concise description of what you want to happen.\n\n**Describe alternatives you've considered**\nA clear and concise description of any alternative solutions or features you've considered.\n\n**Additional context**\nAdd any other context or screenshots about the feature request here.\n"
  },
  {
    "path": ".gitignore",
    "content": "local.properties\n.idea\n*.iml\n.gradle\nbuild\n\n.DS_STORE"
  },
  {
    "path": ".travis.yml",
    "content": "language: android\ndist: trusty\n\nandroid:\n  components:\n    - tools\n    - build-tools-29.0.3\n    - android-29\n    - extra-android-m2repository\n\njdk: oraclejdk8\n\nnotifications:\n  email: false\n\nsudo: false\n\nbefore_script:\n- mkdir \"$ANDROID_HOME/licenses\" || true\n- echo \"24333f8a63b6825ea9c5514f83c2829b004d1fee\" > \"$ANDROID_HOME/licenses/android-sdk-license\"\n\ncache:\n  directories:\n    - $HOME/.gradle\n\nscript: ./gradlew test\n"
  },
  {
    "path": "LICENSE",
    "content": "                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"{}\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright {yyyy} {name of copyright owner}\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n"
  },
  {
    "path": "README.md",
    "content": "# RxPermissions\n\n[![](https://jitpack.io/v/tbruyelle/RxPermissions.svg)](https://jitpack.io/#tbruyelle/RxPermissions) [![BuildVersion](https://buildstats.info/nuget/RxPermissions)](https://www.nuget.org/packages/RxPermissions/) [![Build Status](https://api.travis-ci.org/tbruyelle/RxPermissions.svg?branch=master)](https://travis-ci.org/tbruyelle/RxPermissions)\n\nThis library allows the usage of RxJava with the new Android M permission model.\n\n## Setup\n\nTo use this library your `minSdkVersion` must be >= 14.\n\n```gradle\nallprojects {\n    repositories {\n        ...\n        maven { url 'https://jitpack.io' }\n    }\n}\n\ndependencies {\n    implementation 'com.github.tbruyelle:rxpermissions:0.12'\n}\n```\n\n## Usage\n\nCreate a `RxPermissions` instance :\n\n```java\nfinal RxPermissions rxPermissions = new RxPermissions(this); // where this is an Activity or Fragment instance\n```\n\n**NOTE:** `new RxPermissions(this)` the `this` parameter can be a FragmentActivity or a Fragment. If you are using `RxPermissions` inside of a fragment you should pass the fragment instance(`new RxPermissions(this)`) as constructor parameter rather than `new RxPermissions(fragment.getActivity())` or you could face a `java.lang.IllegalStateException: FragmentManager is already executing transactions`.  \n\nExample : request the CAMERA permission (with Retrolambda for brevity, but not required)\n\n```java\n// Must be done during an initialization phase like onCreate\nrxPermissions\n    .request(Manifest.permission.CAMERA)\n    .subscribe(granted -> {\n        if (granted) { // Always true pre-M\n           // I can control the camera now\n        } else {\n           // Oups permission denied\n        }\n    });\n```\n\nIf you need to trigger the permission request from a specific event, you need to setup your event\nas an observable inside an initialization phase.\n\nYou can use [JakeWharton/RxBinding](https://github.com/JakeWharton/RxBinding) to turn your view to\nan observable (not included in the library).\n\nExample :\n\n```java\n// Must be done during an initialization phase like onCreate\nRxView.clicks(findViewById(R.id.enableCamera))\n    .compose(rxPermissions.ensure(Manifest.permission.CAMERA))\n    .subscribe(granted -> {\n        // R.id.enableCamera has been clicked\n    });\n```\n\nIf multiple permissions at the same time, the result is combined :\n\n```java\nrxPermissions\n    .request(Manifest.permission.CAMERA,\n             Manifest.permission.READ_PHONE_STATE)\n    .subscribe(granted -> {\n        if (granted) {\n           // All requested permissions are granted\n        } else {\n           // At least one permission is denied\n        }\n    });\n```\n\nYou can also observe a detailed result with `requestEach` or `ensureEach` :\n\n```java\nrxPermissions\n    .requestEach(Manifest.permission.CAMERA,\n             Manifest.permission.READ_PHONE_STATE)\n    .subscribe(permission -> { // will emit 2 Permission objects\n        if (permission.granted) {\n           // `permission.name` is granted !\n        } else if (permission.shouldShowRequestPermissionRationale) {\n           // Denied permission without ask never again\n        } else {\n           // Denied permission with ask never again\n           // Need to go to the settings\n        }\n    });\n```\n\nYou can also get combined detailed result with `requestEachCombined` or `ensureEachCombined` :\n\n```java\nrxPermissions\n    .requestEachCombined(Manifest.permission.CAMERA,\n             Manifest.permission.READ_PHONE_STATE)\n    .subscribe(permission -> { // will emit 1 Permission object\n        if (permission.granted) {\n           // All permissions are granted !\n        } else if (permission.shouldShowRequestPermissionRationale)\n           // At least one denied permission without ask never again\n        } else {\n           // At least one denied permission with ask never again\n           // Need to go to the settings\n        }\n    });\n```\n\nLook at the `sample` app for more.\n\n## Important read\n\n**As mentioned above, because your app may be restarted during the permission request, the request\nmust be done during an initialization phase**. This may be `Activity.onCreate`, or\n`View.onFinishInflate`, but not *pausing* methods like `onResume`, because you'll potentially create an infinite request loop, as your requesting activity is paused by the framework during the permission request.\n\nIf not, and if your app is restarted during the permission request (because of a configuration\nchange for instance), the user's answer will never be emitted to the subscriber.\n\nYou can find more details about that [here](https://github.com/tbruyelle/RxPermissions/issues/69).\n\n## Status\n\nThis library is still beta, so contributions are welcome.\nI'm currently using it in production since months without issue.\n\n## Benefits\n\n- Avoid worrying about the framework version. If the sdk is pre-M, the observer will automatically\nreceive a granted result.\n\n- Prevents you to split your code between the permission request and the result handling.\nCurrently without this library you have to request the permission in one place and handle the result\nin `Activity.onRequestPermissionsResult()`.\n\n- All what RX provides about transformation, filter, chaining...\n\n# License\n\n```\nCopyright (C) 2015 Thomas Bruyelle\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n   http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n"
  },
  {
    "path": "build.gradle",
    "content": "buildscript {\n    repositories {\n        google()\n        jcenter()\n    }\n    dependencies {\n        classpath 'com.android.tools.build:gradle:4.0.0'\n        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.0'\n        classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'\n    }\n}\n\nallprojects {\n    repositories {\n        google()\n        jcenter()\n    }\n}\n\next {\n    minSdkVersion = 14\n    compileSdkVersion = 29\n    targetSdkVersion = compileSdkVersion\n\n    rxJava = 'io.reactivex.rxjava3:rxjava:3.0.4'\n    junit = 'junit:junit:4.13'\n    mockito = 'org.mockito:mockito-core:3.3.3'\n\n    androidXFragment = 'androidx.fragment:fragment:1.2.5'\n    androidXAnnotation = 'androidx.annotation:annotation:1.1.0'\n    androidXAppcompat =  'androidx.appcompat:appcompat:1.1.0'\n\n    robolectricVersion = '4.3.1'\n    robolectric = \"org.robolectric:robolectric:$robolectricVersion\"\n    robolectricShadowsSupport = \"org.robolectric:shadows-support-v4:$robolectricVersion\"\n    // Workaround for https://github.com/robolectric/robolectric/issues/1932\n    khronosOpenGLApi = \"org.khronos:opengl-api:gl1.1-android-2.1_r1\"\n\n    bintrayRepo = 'tbruyelle'\n    bintrayName = 'RxPermissions3'\n\n    publishedGroupId = 'com.tbruyelle.rxpermissions3'\n    artifact = 'rxpermissions'\n    libraryName = 'RxPermissions'\n    libraryVersion = '0.9.5'\n\n    libraryDescription = 'A wrapper for Android 6.0 permissions'\n\n    siteUrl = 'https://github.com/tbruyelle/RxPermissions'\n    gitUrl = 'https://github.com/tbruyelle/RxPermissions.git'\n\n    developerId = 'tbruyelle'\n    developerName = 'Thomas Bruyelle'\n    developerEmail = 'thomas.bruyelle@gmail.com'\n\n    licenseName = 'The Apache Software License, Version 2.0'\n    licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'\n    allLicenses = [\"Apache-2.0\"]\n}\n"
  },
  {
    "path": "gradle/wrapper/gradle-wrapper.properties",
    "content": "#Thu Jul 09 16:45:02 CEST 2020\ndistributionBase=GRADLE_USER_HOME\ndistributionPath=wrapper/dists\nzipStoreBase=GRADLE_USER_HOME\nzipStorePath=wrapper/dists\ndistributionUrl=https\\://services.gradle.org/distributions/gradle-6.5.1-all.zip\n"
  },
  {
    "path": "gradle.properties",
    "content": "# Project-wide Gradle settings.\n\n# IDE (e.g. Android Studio) users:\n# Gradle settings configured through the IDE *will override*\n# any settings specified in this file.\n\n# For more details on how to configure your build environment visit\n# http://www.gradle.org/docs/current/userguide/build_environment.html\n\n# Specifies the JVM arguments used for the daemon process.\n# The setting is particularly useful for tweaking memory settings.\norg.gradle.jvmargs=-Xmx1536m\n\n# When configured, Gradle will run in incubating parallel mode.\n# This option should only be used with decoupled projects. More details, visit\n# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects\n# org.gradle.parallel=true\n\nandroid.useAndroidX = true\nandroid.enableJetifier=true"
  },
  {
    "path": "gradlew",
    "content": "#!/usr/bin/env sh\n\n##############################################################################\n##\n##  Gradle start up script for UN*X\n##\n##############################################################################\n\n# Attempt to set APP_HOME\n# Resolve links: $0 may be a link\nPRG=\"$0\"\n# Need this for relative symlinks.\nwhile [ -h \"$PRG\" ] ; do\n    ls=`ls -ld \"$PRG\"`\n    link=`expr \"$ls\" : '.*-> \\(.*\\)$'`\n    if expr \"$link\" : '/.*' > /dev/null; then\n        PRG=\"$link\"\n    else\n        PRG=`dirname \"$PRG\"`\"/$link\"\n    fi\ndone\nSAVED=\"`pwd`\"\ncd \"`dirname \\\"$PRG\\\"`/\" >/dev/null\nAPP_HOME=\"`pwd -P`\"\ncd \"$SAVED\" >/dev/null\n\nAPP_NAME=\"Gradle\"\nAPP_BASE_NAME=`basename \"$0\"`\n\n# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.\nDEFAULT_JVM_OPTS=\"\"\n\n# Use the maximum available, or set MAX_FD != -1 to use that value.\nMAX_FD=\"maximum\"\n\nwarn ( ) {\n    echo \"$*\"\n}\n\ndie ( ) {\n    echo\n    echo \"$*\"\n    echo\n    exit 1\n}\n\n# OS specific support (must be 'true' or 'false').\ncygwin=false\nmsys=false\ndarwin=false\nnonstop=false\ncase \"`uname`\" in\n  CYGWIN* )\n    cygwin=true\n    ;;\n  Darwin* )\n    darwin=true\n    ;;\n  MINGW* )\n    msys=true\n    ;;\n  NONSTOP* )\n    nonstop=true\n    ;;\nesac\n\nCLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar\n\n# Determine the Java command to use to start the JVM.\nif [ -n \"$JAVA_HOME\" ] ; then\n    if [ -x \"$JAVA_HOME/jre/sh/java\" ] ; then\n        # IBM's JDK on AIX uses strange locations for the executables\n        JAVACMD=\"$JAVA_HOME/jre/sh/java\"\n    else\n        JAVACMD=\"$JAVA_HOME/bin/java\"\n    fi\n    if [ ! -x \"$JAVACMD\" ] ; then\n        die \"ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME\n\nPlease set the JAVA_HOME variable in your environment to match the\nlocation of your Java installation.\"\n    fi\nelse\n    JAVACMD=\"java\"\n    which java >/dev/null 2>&1 || die \"ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.\n\nPlease set the JAVA_HOME variable in your environment to match the\nlocation of your Java installation.\"\nfi\n\n# Increase the maximum file descriptors if we can.\nif [ \"$cygwin\" = \"false\" -a \"$darwin\" = \"false\" -a \"$nonstop\" = \"false\" ] ; then\n    MAX_FD_LIMIT=`ulimit -H -n`\n    if [ $? -eq 0 ] ; then\n        if [ \"$MAX_FD\" = \"maximum\" -o \"$MAX_FD\" = \"max\" ] ; then\n            MAX_FD=\"$MAX_FD_LIMIT\"\n        fi\n        ulimit -n $MAX_FD\n        if [ $? -ne 0 ] ; then\n            warn \"Could not set maximum file descriptor limit: $MAX_FD\"\n        fi\n    else\n        warn \"Could not query maximum file descriptor limit: $MAX_FD_LIMIT\"\n    fi\nfi\n\n# For Darwin, add options to specify how the application appears in the dock\nif $darwin; then\n    GRADLE_OPTS=\"$GRADLE_OPTS \\\"-Xdock:name=$APP_NAME\\\" \\\"-Xdock:icon=$APP_HOME/media/gradle.icns\\\"\"\nfi\n\n# For Cygwin, switch paths to Windows format before running java\nif $cygwin ; then\n    APP_HOME=`cygpath --path --mixed \"$APP_HOME\"`\n    CLASSPATH=`cygpath --path --mixed \"$CLASSPATH\"`\n    JAVACMD=`cygpath --unix \"$JAVACMD\"`\n\n    # We build the pattern for arguments to be converted via cygpath\n    ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`\n    SEP=\"\"\n    for dir in $ROOTDIRSRAW ; do\n        ROOTDIRS=\"$ROOTDIRS$SEP$dir\"\n        SEP=\"|\"\n    done\n    OURCYGPATTERN=\"(^($ROOTDIRS))\"\n    # Add a user-defined pattern to the cygpath arguments\n    if [ \"$GRADLE_CYGPATTERN\" != \"\" ] ; then\n        OURCYGPATTERN=\"$OURCYGPATTERN|($GRADLE_CYGPATTERN)\"\n    fi\n    # Now convert the arguments - kludge to limit ourselves to /bin/sh\n    i=0\n    for arg in \"$@\" ; do\n        CHECK=`echo \"$arg\"|egrep -c \"$OURCYGPATTERN\" -`\n        CHECK2=`echo \"$arg\"|egrep -c \"^-\"`                                 ### Determine if an option\n\n        if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then                    ### Added a condition\n            eval `echo args$i`=`cygpath --path --ignore --mixed \"$arg\"`\n        else\n            eval `echo args$i`=\"\\\"$arg\\\"\"\n        fi\n        i=$((i+1))\n    done\n    case $i in\n        (0) set -- ;;\n        (1) set -- \"$args0\" ;;\n        (2) set -- \"$args0\" \"$args1\" ;;\n        (3) set -- \"$args0\" \"$args1\" \"$args2\" ;;\n        (4) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" ;;\n        (5) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" \"$args4\" ;;\n        (6) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" \"$args4\" \"$args5\" ;;\n        (7) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" \"$args4\" \"$args5\" \"$args6\" ;;\n        (8) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" \"$args4\" \"$args5\" \"$args6\" \"$args7\" ;;\n        (9) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" \"$args4\" \"$args5\" \"$args6\" \"$args7\" \"$args8\" ;;\n    esac\nfi\n\n# Escape application args\nsave ( ) {\n    for i do printf %s\\\\n \"$i\" | sed \"s/'/'\\\\\\\\''/g;1s/^/'/;\\$s/\\$/' \\\\\\\\/\" ; done\n    echo \" \"\n}\nAPP_ARGS=$(save \"$@\")\n\n# Collect all arguments for the java command, following the shell quoting and substitution rules\neval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS \"\\\"-Dorg.gradle.appname=$APP_BASE_NAME\\\"\" -classpath \"\\\"$CLASSPATH\\\"\" org.gradle.wrapper.GradleWrapperMain \"$APP_ARGS\"\n\n# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong\nif [ \"$(uname)\" = \"Darwin\" ] && [ \"$HOME\" = \"$PWD\" ]; then\n  cd \"$(dirname \"$0\")\"\nfi\n\nexec \"$JAVACMD\" \"$@\"\n"
  },
  {
    "path": "gradlew.bat",
    "content": "@if \"%DEBUG%\" == \"\" @echo off\r\n@rem ##########################################################################\r\n@rem\r\n@rem  Gradle startup script for Windows\r\n@rem\r\n@rem ##########################################################################\r\n\r\n@rem Set local scope for the variables with windows NT shell\r\nif \"%OS%\"==\"Windows_NT\" setlocal\r\n\r\nset DIRNAME=%~dp0\r\nif \"%DIRNAME%\" == \"\" set DIRNAME=.\r\nset APP_BASE_NAME=%~n0\r\nset APP_HOME=%DIRNAME%\r\n\r\n@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.\r\nset DEFAULT_JVM_OPTS=\r\n\r\n@rem Find java.exe\r\nif defined JAVA_HOME goto findJavaFromJavaHome\r\n\r\nset JAVA_EXE=java.exe\r\n%JAVA_EXE% -version >NUL 2>&1\r\nif \"%ERRORLEVEL%\" == \"0\" goto init\r\n\r\necho.\r\necho ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.\r\necho.\r\necho Please set the JAVA_HOME variable in your environment to match the\r\necho location of your Java installation.\r\n\r\ngoto fail\r\n\r\n:findJavaFromJavaHome\r\nset JAVA_HOME=%JAVA_HOME:\"=%\r\nset JAVA_EXE=%JAVA_HOME%/bin/java.exe\r\n\r\nif exist \"%JAVA_EXE%\" goto init\r\n\r\necho.\r\necho ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%\r\necho.\r\necho Please set the JAVA_HOME variable in your environment to match the\r\necho location of your Java installation.\r\n\r\ngoto fail\r\n\r\n:init\r\n@rem Get command-line arguments, handling Windows variants\r\n\r\nif not \"%OS%\" == \"Windows_NT\" goto win9xME_args\r\n\r\n:win9xME_args\r\n@rem Slurp the command line arguments.\r\nset CMD_LINE_ARGS=\r\nset _SKIP=2\r\n\r\n:win9xME_args_slurp\r\nif \"x%~1\" == \"x\" goto execute\r\n\r\nset CMD_LINE_ARGS=%*\r\n\r\n:execute\r\n@rem Setup the command line\r\n\r\nset CLASSPATH=%APP_HOME%\\gradle\\wrapper\\gradle-wrapper.jar\r\n\r\n@rem Execute Gradle\r\n\"%JAVA_EXE%\" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% \"-Dorg.gradle.appname=%APP_BASE_NAME%\" -classpath \"%CLASSPATH%\" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%\r\n\r\n:end\r\n@rem End local scope for the variables with windows NT shell\r\nif \"%ERRORLEVEL%\"==\"0\" goto mainEnd\r\n\r\n:fail\r\nrem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of\r\nrem the _cmd.exe /c_ return code!\r\nif  not \"\" == \"%GRADLE_EXIT_CONSOLE%\" exit 1\r\nexit /b 1\r\n\r\n:mainEnd\r\nif \"%OS%\"==\"Windows_NT\" endlocal\r\n\r\n:omega\r\n"
  },
  {
    "path": "lib/bintray.gradle",
    "content": "apply plugin: 'com.jfrog.bintray'\n\nversion = libraryVersion\n\ntask sourcesJar(type: Jar) {\n    from android.sourceSets.main.java.srcDirs\n    classifier = 'sources'\n}\n\ntask javadoc(type: Javadoc) {\n    source = android.sourceSets.main.java.srcDirs\n    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))\n}\n\ntask javadocJar(type: Jar, dependsOn: javadoc) {\n    classifier = 'javadoc'\n    from javadoc.destinationDir\n}\nartifacts {\n    archives javadocJar\n    archives sourcesJar\n}\n\nProperties properties = new Properties()\ntry {\n    properties.load(project.rootProject.file('local.properties').newDataInputStream())\n} catch (FileNotFoundException ignore) {}\n\nbintray {\n    user = properties.getProperty(\"bintray.user\")\n    key = properties.getProperty(\"bintray.apikey\")\n\n    configurations = ['archives']\n    pkg {\n        repo = bintrayRepo\n        name = bintrayName\n        desc = libraryDescription\n        websiteUrl = siteUrl\n        vcsUrl = gitUrl\n        licenses = allLicenses\n        publish = true\n        publicDownloadNumbers = true\n        version {\n            desc = libraryDescription\n            gpg {\n                sign = false\n            }\n        }\n    }\n}\n"
  },
  {
    "path": "lib/build.gradle",
    "content": "apply plugin: 'com.android.library'\napply from: 'jitpack.gradle'\n\nandroid {\n    compileSdkVersion rootProject.ext.compileSdkVersion\n\n    compileOptions {\n        sourceCompatibility JavaVersion.VERSION_1_8\n        targetCompatibility JavaVersion.VERSION_1_8\n    }\n    defaultConfig {\n        minSdkVersion rootProject.ext.minSdkVersion\n        targetSdkVersion rootProject.ext.targetSdkVersion\n    }\n    buildTypes {\n        release {\n            minifyEnabled false\n            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'\n        }\n    }\n    testOptions.unitTests.includeAndroidResources = true\n    testOptions.unitTests.all {\n        // unitTests.returnDefaultValues = true\n        // Always show the result of every unit test, even if it passes.\n        testLogging {\n            events 'passed', 'skipped', 'failed', 'standardOut', 'standardError'\n        }\n    }\n}\n\ndependencies {\n    implementation rootProject.ext.rxJava\n    implementation rootProject.ext.androidXFragment\n    implementation rootProject.ext.androidXAnnotation\n    implementation rootProject.ext.androidXAppcompat\n\n    testImplementation 'junit:junit:4.13'\n    testImplementation rootProject.ext.mockito\n    testImplementation rootProject.ext.robolectric\n    testImplementation rootProject.ext.khronosOpenGLApi\n}\n\n// Commented to use JitPack instead of bintray\n//apply from: 'install.gradle'\n//apply from: 'bintray.gradle'\n"
  },
  {
    "path": "lib/install.gradle",
    "content": "apply plugin: 'com.github.dcendents.android-maven'\n\ngroup = publishedGroupId\n\ninstall {\n    repositories.mavenInstaller {\n        pom {\n            project {\n                packaging 'aar'\n                groupId publishedGroupId\n                artifactId artifact\n\n                name libraryName\n                description libraryDescription\n                url siteUrl\n\n                licenses {\n                    license {\n                        name licenseName\n                        url licenseUrl\n                    }\n                }\n                developers {\n                    developer {\n                        id developerId\n                        name developerName\n                        email developerEmail\n                    }\n                }\n                scm {\n                    connection gitUrl\n                    developerConnection gitUrl\n                    url siteUrl\n\n                }\n            }\n        }\n    }\n}\n"
  },
  {
    "path": "lib/jitpack.gradle",
    "content": "apply plugin: 'com.github.dcendents.android-maven'\n\ngroup = 'com.github.tbruyelle'"
  },
  {
    "path": "lib/proguard-rules.pro",
    "content": "# Add project specific ProGuard rules here.\n# By default, the flags in this file are appended to flags specified\n# in ${sdk.dir}/tools/proguard/proguard-android.txt\n# You can edit the include path and order by changing the proguardFiles\n# directive in build.gradle.\n#\n# For more details, see\n#   http://developer.android.com/guide/developing/tools/proguard.html\n\n# Add any project specific keep options here:\n\n# If your project uses WebView with JS, uncomment the following\n# and specify the fully qualified class name to the JavaScript interface\n# class:\n#-keepclassmembers class fqcn.of.javascript.interface.for.webview {\n#   public *;\n#}\n"
  },
  {
    "path": "lib/src/main/AndroidManifest.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<manifest package=\"com.tbruyelle.rxpermissions3\">\n\n    <application />\n\n</manifest>\n"
  },
  {
    "path": "lib/src/main/java/com/tbruyelle/rxpermissions3/Permission.java",
    "content": "package com.tbruyelle.rxpermissions3;\n\nimport java.util.List;\n\nimport io.reactivex.rxjava3.core.Observable;\nimport io.reactivex.rxjava3.functions.BiConsumer;\nimport io.reactivex.rxjava3.functions.Function;\nimport io.reactivex.rxjava3.functions.Predicate;\n\npublic class Permission {\n    public final String name;\n    public final boolean granted;\n    public final boolean shouldShowRequestPermissionRationale;\n\n    public Permission(String name, boolean granted) {\n        this(name, granted, false);\n    }\n\n    public Permission(String name, boolean granted, boolean shouldShowRequestPermissionRationale) {\n        this.name = name;\n        this.granted = granted;\n        this.shouldShowRequestPermissionRationale = shouldShowRequestPermissionRationale;\n    }\n\n    public Permission(List<Permission> permissions) {\n        name = combineName(permissions);\n        granted = combineGranted(permissions);\n        shouldShowRequestPermissionRationale = combineShouldShowRequestPermissionRationale(permissions);\n    }\n\n    @Override\n    @SuppressWarnings(\"SimplifiableIfStatement\")\n    public boolean equals(final Object o) {\n        if (this == o) return true;\n        if (o == null || getClass() != o.getClass()) return false;\n\n        final Permission that = (Permission) o;\n\n        if (granted != that.granted) return false;\n        if (shouldShowRequestPermissionRationale != that.shouldShowRequestPermissionRationale)\n            return false;\n        return name.equals(that.name);\n    }\n\n    @Override\n    public int hashCode() {\n        int result = name.hashCode();\n        result = 31 * result + (granted ? 1 : 0);\n        result = 31 * result + (shouldShowRequestPermissionRationale ? 1 : 0);\n        return result;\n    }\n\n    @Override\n    public String toString() {\n        return \"Permission{\" +\n                \"name='\" + name + '\\'' +\n                \", granted=\" + granted +\n                \", shouldShowRequestPermissionRationale=\" + shouldShowRequestPermissionRationale +\n                '}';\n    }\n\n    private String combineName(List<Permission> permissions) {\n        return Observable.fromIterable(permissions)\n                .map(new Function<Permission, String>() {\n                    @Override\n                    public String apply(Permission permission) throws Exception {\n                        return permission.name;\n                    }\n                }).collectInto(new StringBuilder(), new BiConsumer<StringBuilder, String>() {\n                    @Override\n                    public void accept(StringBuilder s, String s2) throws Exception {\n                        if (s.length() == 0) {\n                            s.append(s2);\n                        } else {\n                            s.append(\", \").append(s2);\n                        }\n                    }\n                }).blockingGet().toString();\n    }\n\n    private Boolean combineGranted(List<Permission> permissions) {\n        return Observable.fromIterable(permissions)\n                .all(new Predicate<Permission>() {\n                    @Override\n                    public boolean test(Permission permission) throws Exception {\n                        return permission.granted;\n                    }\n                }).blockingGet();\n    }\n\n    private Boolean combineShouldShowRequestPermissionRationale(List<Permission> permissions) {\n        return Observable.fromIterable(permissions)\n                .any(new Predicate<Permission>() {\n                    @Override\n                    public boolean test(Permission permission) throws Exception {\n                        return permission.shouldShowRequestPermissionRationale;\n                    }\n                }).blockingGet();\n    }\n}\n"
  },
  {
    "path": "lib/src/main/java/com/tbruyelle/rxpermissions3/RxPermissions.java",
    "content": "/**\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * <p>\n * http://www.apache.org/licenses/LICENSE-2.0\n * <p>\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.tbruyelle.rxpermissions3;\n\nimport android.annotation.TargetApi;\nimport android.app.Activity;\nimport android.os.Build;\nimport android.text.TextUtils;\n\nimport androidx.annotation.NonNull;\nimport androidx.annotation.VisibleForTesting;\nimport androidx.fragment.app.FragmentActivity;\nimport androidx.fragment.app.Fragment;\nimport androidx.fragment.app.FragmentManager;\n\nimport java.util.ArrayList;\nimport java.util.List;\n\nimport io.reactivex.rxjava3.core.Observable;\nimport io.reactivex.rxjava3.core.ObservableSource;\nimport io.reactivex.rxjava3.core.ObservableTransformer;\nimport io.reactivex.rxjava3.functions.Function;\nimport io.reactivex.rxjava3.subjects.PublishSubject;\n\npublic class RxPermissions {\n\n    static final String TAG = RxPermissions.class.getSimpleName();\n    static final Object TRIGGER = new Object();\n\n    @VisibleForTesting\n    Lazy<RxPermissionsFragment> mRxPermissionsFragment;\n\n    public RxPermissions(@NonNull final FragmentActivity activity) {\n        mRxPermissionsFragment = getLazySingleton(activity.getSupportFragmentManager());\n    }\n\n    public RxPermissions(@NonNull final Fragment fragment) {\n        mRxPermissionsFragment = getLazySingleton(fragment.getChildFragmentManager());\n    }\n\n    @NonNull\n    private Lazy<RxPermissionsFragment> getLazySingleton(@NonNull final FragmentManager fragmentManager) {\n        return new Lazy<RxPermissionsFragment>() {\n\n            private RxPermissionsFragment rxPermissionsFragment;\n\n            @Override\n            public synchronized RxPermissionsFragment get() {\n                if (rxPermissionsFragment == null) {\n                    rxPermissionsFragment = getRxPermissionsFragment(fragmentManager);\n                }\n                return rxPermissionsFragment;\n            }\n\n        };\n    }\n\n    private RxPermissionsFragment getRxPermissionsFragment(@NonNull final FragmentManager fragmentManager) {\n        RxPermissionsFragment rxPermissionsFragment = findRxPermissionsFragment(fragmentManager);\n        boolean isNewInstance = rxPermissionsFragment == null;\n        if (isNewInstance) {\n            rxPermissionsFragment = new RxPermissionsFragment();\n            fragmentManager\n                    .beginTransaction()\n                    .add(rxPermissionsFragment, TAG)\n                    .commitNow();\n        }\n        return rxPermissionsFragment;\n    }\n\n    private RxPermissionsFragment findRxPermissionsFragment(@NonNull final FragmentManager fragmentManager) {\n        return (RxPermissionsFragment) fragmentManager.findFragmentByTag(TAG);\n    }\n\n    public void setLogging(boolean logging) {\n        mRxPermissionsFragment.get().setLogging(logging);\n    }\n\n    /**\n     * Map emitted items from the source observable into {@code true} if permissions in parameters\n     * are granted, or {@code false} if not.\n     * <p>\n     * If one or several permissions have never been requested, invoke the related framework method\n     * to ask the user if he allows the permissions.\n     */\n    @SuppressWarnings(\"WeakerAccess\")\n    public <T> ObservableTransformer<T, Boolean> ensure(final String... permissions) {\n        return new ObservableTransformer<T, Boolean>() {\n            @Override\n            public ObservableSource<Boolean> apply(Observable<T> o) {\n                return request(o, permissions)\n                        // Transform Observable<Permission> to Observable<Boolean>\n                        .buffer(permissions.length)\n                        .flatMap(new Function<List<Permission>, ObservableSource<Boolean>>() {\n                            @Override\n                            public ObservableSource<Boolean> apply(List<Permission> permissions) {\n                                if (permissions.isEmpty()) {\n                                    // Occurs during orientation change, when the subject receives onComplete.\n                                    // In that case we don't want to propagate that empty list to the\n                                    // subscriber, only the onComplete.\n                                    return Observable.empty();\n                                }\n                                // Return true if all permissions are granted.\n                                for (Permission p : permissions) {\n                                    if (!p.granted) {\n                                        return Observable.just(false);\n                                    }\n                                }\n                                return Observable.just(true);\n                            }\n                        });\n            }\n        };\n    }\n\n    /**\n     * Map emitted items from the source observable into {@link Permission} objects for each\n     * permission in parameters.\n     * <p>\n     * If one or several permissions have never been requested, invoke the related framework method\n     * to ask the user if he allows the permissions.\n     */\n    @SuppressWarnings(\"WeakerAccess\")\n    public <T> ObservableTransformer<T, Permission> ensureEach(final String... permissions) {\n        return new ObservableTransformer<T, Permission>() {\n            @Override\n            public ObservableSource<Permission> apply(Observable<T> o) {\n                return request(o, permissions);\n            }\n        };\n    }\n\n    /**\n     * Map emitted items from the source observable into one combined {@link Permission} object. Only if all permissions are granted,\n     * permission also will be granted. If any permission has {@code shouldShowRationale} checked, than result also has it checked.\n     * <p>\n     * If one or several permissions have never been requested, invoke the related framework method\n     * to ask the user if he allows the permissions.\n     */\n    public <T> ObservableTransformer<T, Permission> ensureEachCombined(final String... permissions) {\n        return new ObservableTransformer<T, Permission>() {\n            @Override\n            public ObservableSource<Permission> apply(Observable<T> o) {\n                return request(o, permissions)\n                        .buffer(permissions.length)\n                        .flatMap(new Function<List<Permission>, ObservableSource<Permission>>() {\n                            @Override\n                            public ObservableSource<Permission> apply(List<Permission> permissions) {\n                                if (permissions.isEmpty()) {\n                                    return Observable.empty();\n                                }\n                                return Observable.just(new Permission(permissions));\n                            }\n                        });\n            }\n        };\n    }\n\n    /**\n     * Request permissions immediately, <b>must be invoked during initialization phase\n     * of your application</b>.\n     */\n    @SuppressWarnings({\"WeakerAccess\", \"unused\"})\n    public Observable<Boolean> request(final String... permissions) {\n        return Observable.just(TRIGGER).compose(ensure(permissions));\n    }\n\n    /**\n     * Request permissions immediately, <b>must be invoked during initialization phase\n     * of your application</b>.\n     */\n    @SuppressWarnings({\"WeakerAccess\", \"unused\"})\n    public Observable<Permission> requestEach(final String... permissions) {\n        return Observable.just(TRIGGER).compose(ensureEach(permissions));\n    }\n\n    /**\n     * Request permissions immediately, <b>must be invoked during initialization phase\n     * of your application</b>.\n     */\n    public Observable<Permission> requestEachCombined(final String... permissions) {\n        return Observable.just(TRIGGER).compose(ensureEachCombined(permissions));\n    }\n\n    private Observable<Permission> request(final Observable<?> trigger, final String... permissions) {\n        if (permissions == null || permissions.length == 0) {\n            throw new IllegalArgumentException(\"RxPermissions.request/requestEach requires at least one input permission\");\n        }\n        return trigger.flatMap( o -> requestImplementation(permissions));\n    }\n\n    @TargetApi(Build.VERSION_CODES.M)\n    private Observable<Permission> requestImplementation(final String... permissions) {\n        List<Observable<Permission>> list = new ArrayList<>(permissions.length);\n        List<String> unrequestedPermissions = new ArrayList<>();\n\n        // In case of multiple permissions, we create an Observable for each of them.\n        // At the end, the observables are combined to have a unique response.\n        for (String permission : permissions) {\n            mRxPermissionsFragment.get().log(\"Requesting permission \" + permission);\n            if (isGranted(permission)) {\n                // Already granted, or not Android M\n                // Return a granted Permission object.\n                list.add(Observable.just(new Permission(permission, true, false)));\n                continue;\n            }\n\n            if (isRevoked(permission)) {\n                // Revoked by a policy, return a denied Permission object.\n                list.add(Observable.just(new Permission(permission, false, false)));\n                continue;\n            }\n\n            PublishSubject<Permission> subject = mRxPermissionsFragment.get().getSubjectByPermission(permission);\n            // Create a new subject if not exists\n            if (subject == null) {\n                unrequestedPermissions.add(permission);\n                subject = PublishSubject.create();\n                mRxPermissionsFragment.get().setSubjectForPermission(permission, subject);\n            }\n\n            list.add(subject);\n        }\n\n        if (!unrequestedPermissions.isEmpty()) {\n            String[] unrequestedPermissionsArray = unrequestedPermissions.toArray(new String[unrequestedPermissions.size()]);\n            requestPermissionsFromFragment(unrequestedPermissionsArray);\n        }\n        return Observable.concat(Observable.fromIterable(list));\n    }\n\n    /**\n     * Invokes Activity.shouldShowRequestPermissionRationale and wraps\n     * the returned value in an observable.\n     * <p>\n     * In case of multiple permissions, only emits true if\n     * Activity.shouldShowRequestPermissionRationale returned true for\n     * all revoked permissions.\n     * <p>\n     * You shouldn't call this method if all permissions have been granted.\n     * <p>\n     * For SDK &lt; 23, the observable will always emit false.\n     */\n    @SuppressWarnings(\"WeakerAccess\")\n    public Observable<Boolean> shouldShowRequestPermissionRationale(final Activity activity, final String... permissions) {\n        if (!isMarshmallow()) {\n            return Observable.just(false);\n        }\n        return Observable.just(shouldShowRequestPermissionRationaleImplementation(activity, permissions));\n    }\n\n    @TargetApi(Build.VERSION_CODES.M)\n    private boolean shouldShowRequestPermissionRationaleImplementation(final Activity activity, final String... permissions) {\n        for (String p : permissions) {\n            if (!isGranted(p) && !activity.shouldShowRequestPermissionRationale(p)) {\n                return false;\n            }\n        }\n        return true;\n    }\n\n    @TargetApi(Build.VERSION_CODES.M)\n    void requestPermissionsFromFragment(String[] permissions) {\n        mRxPermissionsFragment.get().log(\"requestPermissionsFromFragment \" + TextUtils.join(\", \", permissions));\n        mRxPermissionsFragment.get().requestPermissions(permissions);\n    }\n\n    /**\n     * Returns true if the permission is already granted.\n     * <p>\n     * Always true if SDK &lt; 23.\n     */\n    @SuppressWarnings(\"WeakerAccess\")\n    public boolean isGranted(String permission) {\n        return !isMarshmallow() || mRxPermissionsFragment.get().isGranted(permission);\n    }\n\n    /**\n     * Returns true if the permission has been revoked by a policy.\n     * <p>\n     * Always false if SDK &lt; 23.\n     */\n    @SuppressWarnings(\"WeakerAccess\")\n    public boolean isRevoked(String permission) {\n        return isMarshmallow() && mRxPermissionsFragment.get().isRevoked(permission);\n    }\n\n    boolean isMarshmallow() {\n        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M;\n    }\n\n    void onRequestPermissionsResult(String[] permissions, int[] grantResults) {\n        mRxPermissionsFragment.get().onRequestPermissionsResult(permissions, grantResults, new boolean[permissions.length]);\n    }\n\n    @FunctionalInterface\n    public interface Lazy<V> {\n        V get();\n    }\n\n}\n"
  },
  {
    "path": "lib/src/main/java/com/tbruyelle/rxpermissions3/RxPermissionsFragment.java",
    "content": "package com.tbruyelle.rxpermissions3;\n\nimport android.annotation.TargetApi;\nimport android.content.pm.PackageManager;\nimport android.os.Build;\nimport android.os.Bundle;\nimport android.util.Log;\n\nimport androidx.annotation.NonNull;\nimport androidx.fragment.app.Fragment;\nimport androidx.fragment.app.FragmentActivity;\n\nimport java.util.HashMap;\nimport java.util.Map;\n\nimport io.reactivex.rxjava3.subjects.PublishSubject;\n\n\npublic class RxPermissionsFragment extends Fragment {\n\n    private static final int PERMISSIONS_REQUEST_CODE = 42;\n\n    // Contains all the current permission requests.\n    // Once granted or denied, they are removed from it.\n    private Map<String, PublishSubject<Permission>> mSubjects = new HashMap<>();\n    private boolean mLogging;\n\n    public RxPermissionsFragment() {\n    }\n\n    @Override\n    public void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        setRetainInstance(true);\n    }\n\n    @TargetApi(Build.VERSION_CODES.M)\n    void requestPermissions(@NonNull String[] permissions) {\n        requestPermissions(permissions, PERMISSIONS_REQUEST_CODE);\n    }\n\n    @TargetApi(Build.VERSION_CODES.M)\n    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {\n        super.onRequestPermissionsResult(requestCode, permissions, grantResults);\n\n        if (requestCode != PERMISSIONS_REQUEST_CODE) return;\n\n        boolean[] shouldShowRequestPermissionRationale = new boolean[permissions.length];\n\n        for (int i = 0; i < permissions.length; i++) {\n            shouldShowRequestPermissionRationale[i] = shouldShowRequestPermissionRationale(permissions[i]);\n        }\n\n        onRequestPermissionsResult(permissions, grantResults, shouldShowRequestPermissionRationale);\n    }\n\n    void onRequestPermissionsResult(String[] permissions, int[] grantResults, boolean[] shouldShowRequestPermissionRationale) {\n        for (int i = 0, size = permissions.length; i < size; i++) {\n            log(\"onRequestPermissionsResult  \" + permissions[i]);\n            // Find the corresponding subject\n            PublishSubject<Permission> subject = mSubjects.get(permissions[i]);\n            if (subject == null) {\n                // No subject found\n                Log.e(RxPermissions.TAG, \"RxPermissions.onRequestPermissionsResult invoked but didn't find the corresponding permission request.\");\n                return;\n            }\n            mSubjects.remove(permissions[i]);\n            boolean granted = grantResults[i] == PackageManager.PERMISSION_GRANTED;\n            subject.onNext(new Permission(permissions[i], granted, shouldShowRequestPermissionRationale[i]));\n            subject.onComplete();\n        }\n    }\n\n    @TargetApi(Build.VERSION_CODES.M)\n    boolean isGranted(String permission) {\n        final FragmentActivity fragmentActivity = getActivity();\n        if (fragmentActivity == null) {\n            throw new IllegalStateException(\"This fragment must be attached to an activity.\");\n        }\n        return fragmentActivity.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED;\n    }\n\n    @TargetApi(Build.VERSION_CODES.M)\n    boolean isRevoked(String permission) {\n        final FragmentActivity fragmentActivity = getActivity();\n        if (fragmentActivity == null) {\n            throw new IllegalStateException(\"This fragment must be attached to an activity.\");\n        }\n        return fragmentActivity.getPackageManager().isPermissionRevokedByPolicy(permission, getActivity().getPackageName());\n    }\n\n    public void setLogging(boolean logging) {\n        mLogging = logging;\n    }\n\n    public PublishSubject<Permission> getSubjectByPermission(@NonNull String permission) {\n        return mSubjects.get(permission);\n    }\n\n    public void setSubjectForPermission(@NonNull String permission, @NonNull PublishSubject<Permission> subject) {\n        mSubjects.put(permission, subject);\n    }\n\n    void log(String message) {\n        if (mLogging) {\n            Log.d(RxPermissions.TAG, message);\n        }\n    }\n\n}\n"
  },
  {
    "path": "lib/src/test/java/com/tbruyelle/rxpermissions3/RxPermissionsTest.java",
    "content": "/**\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * <p>\n * http://www.apache.org/licenses/LICENSE-2.0\n * <p>\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.tbruyelle.rxpermissions3;\n\nimport android.Manifest;\nimport android.annotation.TargetApi;\nimport android.app.Activity;\nimport android.content.pm.PackageManager;\nimport android.os.Build;\n\nimport androidx.fragment.app.FragmentActivity;\n\nimport org.junit.Before;\nimport org.junit.Test;\nimport org.junit.runner.RunWith;\nimport org.mockito.ArgumentCaptor;\nimport org.mockito.ArgumentMatchers;\nimport org.robolectric.Robolectric;\nimport org.robolectric.RobolectricTestRunner;\nimport org.robolectric.android.controller.ActivityController;\nimport org.robolectric.annotation.Config;\n\n\nimport io.reactivex.rxjava3.core.Observable;\nimport io.reactivex.rxjava3.observers.TestObserver;\nimport io.reactivex.rxjava3.subjects.PublishSubject;\n\nimport static org.junit.Assert.assertEquals;\nimport static org.junit.Assert.assertFalse;\nimport static org.junit.Assert.assertTrue;\nimport static org.mockito.Matchers.anyString;\nimport static org.mockito.Matchers.eq;\nimport static org.mockito.Mockito.doCallRealMethod;\nimport static org.mockito.Mockito.doReturn;\nimport static org.mockito.Mockito.mock;\nimport static org.mockito.Mockito.spy;\nimport static org.mockito.Mockito.verify;\nimport static org.mockito.Mockito.when;\n\n@RunWith(RobolectricTestRunner.class)\n@Config(sdk = Build.VERSION_CODES.M)\npublic class RxPermissionsTest {\n\n    private FragmentActivity mActivity;\n\n    private RxPermissions mRxPermissions;\n\n    @Before\n    public void setup() {\n        ActivityController<FragmentActivity> activityController = Robolectric.buildActivity(FragmentActivity.class);\n        mActivity = spy(activityController.setup().get());\n        mRxPermissions = spy(new RxPermissions(mActivity));\n        mRxPermissions.mRxPermissionsFragment = spy(mRxPermissions.mRxPermissionsFragment);\n        final RxPermissionsFragment rxPermissionsFragment = spy(mRxPermissions.mRxPermissionsFragment.get());\n        when(rxPermissionsFragment.getActivity()).thenReturn(mActivity);\n        when(mRxPermissions.mRxPermissionsFragment.get()).thenReturn(rxPermissionsFragment);\n        // Default deny all permissions\n        doReturn(false).when(mRxPermissions).isGranted(anyString());\n        // Default no revoked permissions\n        doReturn(false).when(mRxPermissions).isRevoked(anyString());\n    }\n\n    private Observable<Object> trigger() {\n        return Observable.just(RxPermissions.TRIGGER);\n    }\n\n    @Test\n    @TargetApi(Build.VERSION_CODES.M)\n    public void subscription_preM() {\n        TestObserver<Boolean> sub = new TestObserver<>();\n        String permission = Manifest.permission.READ_PHONE_STATE;\n        when(mRxPermissions.isGranted(permission)).thenReturn(true);\n\n        trigger().compose(mRxPermissions.ensure(permission)).subscribe(sub);\n\n        sub.assertNoErrors();\n        sub.assertValue(true);\n    }\n\n    @Test\n    @TargetApi(Build.VERSION_CODES.M)\n    public void subscription_granted() {\n        TestObserver<Boolean> sub = new TestObserver<>();\n        String permission = Manifest.permission.READ_PHONE_STATE;\n        when(mRxPermissions.isGranted(permission)).thenReturn(false);\n        int[] result = new int[]{PackageManager.PERMISSION_GRANTED};\n\n        trigger().compose(mRxPermissions.ensure(permission)).subscribe(sub);\n        mRxPermissions.onRequestPermissionsResult(new String[]{permission}, result);\n\n        sub.assertNoErrors();\n        sub.assertValue(true);\n    }\n\n    @Test\n    @TargetApi(Build.VERSION_CODES.M)\n    public void eachSubscription_granted() {\n        TestObserver<Permission> sub = new TestObserver<>();\n        String permission = Manifest.permission.READ_PHONE_STATE;\n        when(mRxPermissions.isGranted(permission)).thenReturn(false);\n        int[] result = new int[]{PackageManager.PERMISSION_GRANTED};\n\n        trigger().compose(mRxPermissions.ensureEach(permission)).subscribe(sub);\n        mRxPermissions.onRequestPermissionsResult(new String[]{permission}, result);\n\n        sub.assertNoErrors();\n        sub.assertValue(new Permission(permission, true));\n    }\n\n    @Test\n    @TargetApi(Build.VERSION_CODES.M)\n    public void eachSubscriptionCombined_granted() {\n        TestObserver<Permission> sub = new TestObserver<>();\n        String permission = Manifest.permission.READ_PHONE_STATE;\n        when(mRxPermissions.isGranted(permission)).thenReturn(false);\n        int[] result = new int[]{PackageManager.PERMISSION_GRANTED};\n\n        trigger().compose(mRxPermissions.ensureEachCombined(permission)).subscribe(sub);\n        mRxPermissions.onRequestPermissionsResult(new String[]{permission}, result);\n\n        sub.assertNoErrors();\n        sub.assertValue(new Permission(permission, true));\n    }\n\n    @Test\n    @TargetApi(Build.VERSION_CODES.M)\n    public void eachSubscription_preM() {\n        TestObserver<Permission> sub = new TestObserver<>();\n        String permission = Manifest.permission.READ_PHONE_STATE;\n        when(mRxPermissions.isGranted(permission)).thenReturn(true);\n\n        trigger().compose(mRxPermissions.ensureEach(permission)).subscribe(sub);\n\n        sub.assertNoErrors();\n        sub.assertValue(new Permission(permission, true));\n    }\n\n    @Test\n    @TargetApi(Build.VERSION_CODES.M)\n    public void eachSubscriptionCombined_preM() {\n        TestObserver<Permission> sub = new TestObserver<>();\n        String permission = Manifest.permission.READ_PHONE_STATE;\n        when(mRxPermissions.isGranted(permission)).thenReturn(true);\n\n        trigger().compose(mRxPermissions.ensureEachCombined(permission)).subscribe(sub);\n\n        sub.assertNoErrors();\n        sub.assertValue(new Permission(permission, true));\n    }\n\n    @Test\n    @TargetApi(Build.VERSION_CODES.M)\n    public void subscription_alreadyGranted() {\n        TestObserver<Boolean> sub = new TestObserver<>();\n        String permission = Manifest.permission.READ_PHONE_STATE;\n        when(mRxPermissions.isGranted(permission)).thenReturn(true);\n\n        trigger().compose(mRxPermissions.ensure(permission)).subscribe(sub);\n\n        sub.assertNoErrors();\n        sub.assertValue(true);\n    }\n\n    @Test\n    @TargetApi(Build.VERSION_CODES.M)\n    public void subscription_denied() {\n        TestObserver<Boolean> sub = new TestObserver<>();\n        String permission = Manifest.permission.READ_PHONE_STATE;\n        when(mRxPermissions.isGranted(permission)).thenReturn(false);\n        int[] result = new int[]{PackageManager.PERMISSION_DENIED};\n\n        trigger().compose(mRxPermissions.ensure(permission)).subscribe(sub);\n        mRxPermissions.onRequestPermissionsResult(new String[]{permission}, result);\n\n        sub.assertNoErrors();\n        sub.assertValue(false);\n    }\n\n    @Test\n    @TargetApi(Build.VERSION_CODES.M)\n    public void eachSubscription_denied() {\n        TestObserver<Permission> sub = new TestObserver<>();\n        String permission = Manifest.permission.READ_PHONE_STATE;\n        when(mRxPermissions.isGranted(permission)).thenReturn(false);\n        int[] result = new int[]{PackageManager.PERMISSION_DENIED};\n\n        trigger().compose(mRxPermissions.ensureEach(permission)).subscribe(sub);\n        mRxPermissions.onRequestPermissionsResult(new String[]{permission}, result);\n\n        sub.assertNoErrors();\n        sub.assertValue(new Permission(permission, false));\n    }\n\n    @Test\n    @TargetApi(Build.VERSION_CODES.M)\n    public void eachSubscriptionCombined_denied() {\n        TestObserver<Permission> sub = new TestObserver<>();\n        String permission = Manifest.permission.READ_PHONE_STATE;\n        when(mRxPermissions.isGranted(permission)).thenReturn(false);\n        int[] result = new int[]{PackageManager.PERMISSION_DENIED};\n\n        trigger().compose(mRxPermissions.ensureEachCombined(permission)).subscribe(sub);\n        mRxPermissions.onRequestPermissionsResult(new String[]{permission}, result);\n\n        sub.assertNoErrors();\n        sub.assertValue(new Permission(permission, false));\n    }\n\n    @Test\n    @TargetApi(Build.VERSION_CODES.M)\n    public void subscription_revoked() {\n        TestObserver<Boolean> sub = new TestObserver<>();\n        String permission = Manifest.permission.READ_PHONE_STATE;\n        when(mRxPermissions.isRevoked(permission)).thenReturn(true);\n\n        trigger().compose(mRxPermissions.ensure(permission)).subscribe(sub);\n\n        sub.assertNoErrors();\n        sub.assertValue(false);\n    }\n\n    @Test\n    @TargetApi(Build.VERSION_CODES.M)\n    public void eachSubscription_revoked() {\n        TestObserver<Permission> sub = new TestObserver<>();\n        String permission = Manifest.permission.READ_PHONE_STATE;\n        when(mRxPermissions.isRevoked(permission)).thenReturn(true);\n\n        trigger().compose(mRxPermissions.ensureEach(permission)).subscribe(sub);\n\n        sub.assertNoErrors();\n        sub.assertValue(new Permission(permission, false));\n    }\n\n    @Test\n    @TargetApi(Build.VERSION_CODES.M)\n    public void eachSubscriptionCombined_revoked() {\n        TestObserver<Permission> sub = new TestObserver<>();\n        String permission = Manifest.permission.READ_PHONE_STATE;\n        when(mRxPermissions.isRevoked(permission)).thenReturn(true);\n\n        trigger().compose(mRxPermissions.ensureEachCombined(permission)).subscribe(sub);\n\n        sub.assertNoErrors();\n        sub.assertValue(new Permission(permission, false));\n    }\n\n    @Test\n    @TargetApi(Build.VERSION_CODES.M)\n    public void subscription_severalPermissions_granted() {\n        TestObserver<Boolean> sub = new TestObserver<>();\n        String[] permissions = new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.CAMERA};\n        when(mRxPermissions.isGranted(ArgumentMatchers.anyString())).thenReturn(false);\n        int[] result = new int[]{PackageManager.PERMISSION_GRANTED, PackageManager.PERMISSION_GRANTED};\n\n        trigger().compose(mRxPermissions.ensure(permissions)).subscribe(sub);\n        mRxPermissions.onRequestPermissionsResult(permissions, result);\n\n        sub.assertNoErrors();\n        sub.assertValue(true);\n    }\n\n    @Test\n    @TargetApi(Build.VERSION_CODES.M)\n    public void eachSubscription_severalPermissions_granted() {\n        TestObserver<Permission> sub = new TestObserver<>();\n        String[] permissions = new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.CAMERA};\n        when(mRxPermissions.isGranted(ArgumentMatchers.anyString())).thenReturn(false);\n        int[] result = new int[]{PackageManager.PERMISSION_GRANTED, PackageManager.PERMISSION_GRANTED};\n\n        trigger().compose(mRxPermissions.ensureEach(permissions)).subscribe(sub);\n        mRxPermissions.onRequestPermissionsResult(permissions, result);\n\n        sub.assertNoErrors();\n        sub.assertValues(new Permission(permissions[0], true), new Permission(permissions[1], true));\n    }\n\n    @Test\n    @TargetApi(Build.VERSION_CODES.M)\n    public void eachSubscriptionCombined_severalPermissions_granted() {\n        TestObserver<Permission> sub = new TestObserver<>();\n        String[] permissions = new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.CAMERA};\n        when(mRxPermissions.isGranted(ArgumentMatchers.anyString())).thenReturn(false);\n        int[] result = new int[]{PackageManager.PERMISSION_GRANTED, PackageManager.PERMISSION_GRANTED};\n\n        trigger().compose(mRxPermissions.ensureEachCombined(permissions)).subscribe(sub);\n        mRxPermissions.onRequestPermissionsResult(permissions, result);\n\n        sub.assertNoErrors();\n        sub.assertValues(new Permission(permissions[0] + \", \" + permissions[1], true));\n    }\n\n    @Test\n    @TargetApi(Build.VERSION_CODES.M)\n    public void subscription_severalPermissions_oneDenied() {\n        TestObserver<Boolean> sub = new TestObserver<>();\n        String[] permissions = new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.CAMERA};\n        when(mRxPermissions.isGranted(ArgumentMatchers.anyString())).thenReturn(false);\n        int[] result = new int[]{PackageManager.PERMISSION_GRANTED, PackageManager.PERMISSION_DENIED};\n\n        trigger().compose(mRxPermissions.ensure(permissions)).subscribe(sub);\n        mRxPermissions.onRequestPermissionsResult(permissions, result);\n\n        sub.assertNoErrors();\n        sub.assertValue(false);\n    }\n\n    @Test\n    @TargetApi(Build.VERSION_CODES.M)\n    public void subscription_severalPermissions_oneRevoked() {\n        TestObserver<Boolean> sub = new TestObserver<>();\n        String[] permissions = new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.CAMERA};\n        when(mRxPermissions.isGranted(ArgumentMatchers.anyString())).thenReturn(false);\n        when(mRxPermissions.isRevoked(Manifest.permission.CAMERA)).thenReturn(true);\n\n        trigger().compose(mRxPermissions.ensure(permissions)).subscribe(sub);\n        mRxPermissions.onRequestPermissionsResult(\n                new String[]{Manifest.permission.READ_PHONE_STATE},\n                new int[]{PackageManager.PERMISSION_GRANTED});\n\n        sub.assertNoErrors();\n        sub.assertValue(false);\n    }\n\n    @Test\n    @TargetApi(Build.VERSION_CODES.M)\n    public void eachSubscription_severalPermissions_oneAlreadyGranted() {\n        TestObserver<Permission> sub = new TestObserver<>();\n        String[] permissions = new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.CAMERA};\n        when(mRxPermissions.isGranted(ArgumentMatchers.anyString())).thenReturn(false);\n        when(mRxPermissions.isGranted(Manifest.permission.CAMERA)).thenReturn(true);\n\n        trigger().compose(mRxPermissions.ensureEach(permissions)).subscribe(sub);\n        mRxPermissions.onRequestPermissionsResult(\n                new String[]{Manifest.permission.READ_PHONE_STATE},\n                new int[]{PackageManager.PERMISSION_GRANTED});\n\n        sub.assertNoErrors();\n        sub.assertValues(new Permission(permissions[0], true), new Permission(permissions[1], true));\n        ArgumentCaptor<String[]> requestedPermissions = ArgumentCaptor.forClass(String[].class);\n        verify(mRxPermissions).requestPermissionsFromFragment(requestedPermissions.capture());\n        assertEquals(1, requestedPermissions.getValue().length);\n        assertEquals(Manifest.permission.READ_PHONE_STATE, requestedPermissions.getValue()[0]);\n    }\n\n    @Test\n    @TargetApi(Build.VERSION_CODES.M)\n    public void eachSubscriptionCombined_severalPermissions_oneAlreadyGranted() {\n        TestObserver<Permission> sub = new TestObserver<>();\n        String[] permissions = new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.CAMERA};\n        when(mRxPermissions.isGranted(ArgumentMatchers.anyString())).thenReturn(false);\n        when(mRxPermissions.isGranted(Manifest.permission.CAMERA)).thenReturn(true);\n\n        trigger().compose(mRxPermissions.ensureEachCombined(permissions)).subscribe(sub);\n        mRxPermissions.onRequestPermissionsResult(\n                new String[]{Manifest.permission.READ_PHONE_STATE},\n                new int[]{PackageManager.PERMISSION_GRANTED});\n\n        sub.assertNoErrors();\n        sub.assertValues(new Permission(permissions[0] + \", \" + permissions[1], true));\n        ArgumentCaptor<String[]> requestedPermissions = ArgumentCaptor.forClass(String[].class);\n        verify(mRxPermissions).requestPermissionsFromFragment(requestedPermissions.capture());\n        assertEquals(1, requestedPermissions.getValue().length);\n        assertEquals(Manifest.permission.READ_PHONE_STATE, requestedPermissions.getValue()[0]);\n    }\n\n    @Test\n    @TargetApi(Build.VERSION_CODES.M)\n    public void eachSubscription_severalPermissions_oneDenied() {\n        TestObserver<Permission> sub = new TestObserver<>();\n        String[] permissions = new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.CAMERA};\n        when(mRxPermissions.isGranted(ArgumentMatchers.anyString())).thenReturn(false);\n        int[] result = new int[]{PackageManager.PERMISSION_GRANTED, PackageManager.PERMISSION_DENIED};\n\n        trigger().compose(mRxPermissions.ensureEach(permissions)).subscribe(sub);\n        mRxPermissions.onRequestPermissionsResult(permissions, result);\n\n        sub.assertNoErrors();\n        sub.assertValues(new Permission(permissions[0], true), new Permission(permissions[1], false));\n    }\n\n    @Test\n    @TargetApi(Build.VERSION_CODES.M)\n    public void eachSubscriptionCombined_severalPermissions_oneDenied() {\n        TestObserver<Permission> sub = new TestObserver<>();\n        String[] permissions = new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.CAMERA};\n        when(mRxPermissions.isGranted(ArgumentMatchers.anyString())).thenReturn(false);\n        int[] result = new int[]{PackageManager.PERMISSION_GRANTED, PackageManager.PERMISSION_DENIED};\n\n        trigger().compose(mRxPermissions.ensureEachCombined(permissions)).subscribe(sub);\n        mRxPermissions.onRequestPermissionsResult(permissions, result);\n\n        sub.assertNoErrors();\n        sub.assertValues(new Permission(permissions[0] + \", \" + permissions[1], false));\n    }\n\n    @Test\n    @TargetApi(Build.VERSION_CODES.M)\n    public void eachSubscription_severalPermissions_oneRevoked() {\n        TestObserver<Permission> sub = new TestObserver<>();\n        String[] permissions = new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.CAMERA};\n        when(mRxPermissions.isGranted(ArgumentMatchers.anyString())).thenReturn(false);\n        when(mRxPermissions.isRevoked(Manifest.permission.CAMERA)).thenReturn(true);\n\n        trigger().compose(mRxPermissions.ensureEach(permissions)).subscribe(sub);\n        mRxPermissions.onRequestPermissionsResult(\n                new String[]{Manifest.permission.READ_PHONE_STATE},\n                new int[]{PackageManager.PERMISSION_GRANTED});\n\n        sub.assertNoErrors();\n        sub.assertValues(new Permission(permissions[0], true), new Permission(permissions[1], false));\n    }\n\n    @Test\n    @TargetApi(Build.VERSION_CODES.M)\n    public void eachSubscriptionCombined_severalPermissions_oneRevoked() {\n        TestObserver<Permission> sub = new TestObserver<>();\n        String[] permissions = new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.CAMERA};\n        when(mRxPermissions.isGranted(ArgumentMatchers.anyString())).thenReturn(false);\n        when(mRxPermissions.isRevoked(Manifest.permission.CAMERA)).thenReturn(true);\n\n        trigger().compose(mRxPermissions.ensureEachCombined(permissions)).subscribe(sub);\n        mRxPermissions.onRequestPermissionsResult(\n                new String[]{Manifest.permission.READ_PHONE_STATE},\n                new int[]{PackageManager.PERMISSION_GRANTED});\n\n        sub.assertNoErrors();\n        sub.assertValues(new Permission(permissions[0] + \", \" + permissions[1], false));\n    }\n\n    @Test\n    @TargetApi(Build.VERSION_CODES.M)\n    public void subscription_trigger_granted() {\n        TestObserver<Boolean> sub = new TestObserver<>();\n        String permission = Manifest.permission.READ_PHONE_STATE;\n        when(mRxPermissions.isGranted(permission)).thenReturn(false);\n        int[] result = new int[]{PackageManager.PERMISSION_GRANTED};\n        PublishSubject<Object> trigger = PublishSubject.create();\n\n        trigger.compose(mRxPermissions.ensure(permission)).subscribe(sub);\n        trigger.onNext(1);\n        mRxPermissions.onRequestPermissionsResult(new String[]{permission}, result);\n\n        sub.assertNoErrors();\n        sub.assertValue(true);\n    }\n\n    @Test\n    @TargetApi(Build.VERSION_CODES.M)\n    public void eachSubscription_trigger_granted() {\n        TestObserver<Permission> sub = new TestObserver<>();\n        String permission = Manifest.permission.READ_PHONE_STATE;\n        when(mRxPermissions.isGranted(permission)).thenReturn(false);\n        int[] result = new int[]{PackageManager.PERMISSION_GRANTED};\n        PublishSubject<Object> trigger = PublishSubject.create();\n\n        trigger.compose(mRxPermissions.ensureEach(permission)).subscribe(sub);\n        trigger.onNext(1);\n        mRxPermissions.onRequestPermissionsResult(new String[]{permission}, result);\n\n        sub.assertNoErrors();\n        sub.assertValue(new Permission(permission, true));\n    }\n\n    @Test\n    @TargetApi(Build.VERSION_CODES.M)\n    public void eachSubscriptionCombined_trigger_granted() {\n        TestObserver<Permission> sub = new TestObserver<>();\n        String permission = Manifest.permission.READ_PHONE_STATE;\n        when(mRxPermissions.isGranted(permission)).thenReturn(false);\n        int[] result = new int[]{PackageManager.PERMISSION_GRANTED};\n        PublishSubject<Object> trigger = PublishSubject.create();\n\n        trigger.compose(mRxPermissions.ensureEachCombined(permission)).subscribe(sub);\n        trigger.onNext(1);\n        mRxPermissions.onRequestPermissionsResult(new String[]{permission}, result);\n\n        sub.assertNoErrors();\n        sub.assertValue(new Permission(permission, true));\n    }\n\n    @Test\n    @TargetApi(Build.VERSION_CODES.M)\n    public void shouldShowRequestPermissionRationale_allDenied_allRationale() {\n        when(mRxPermissions.isMarshmallow()).thenReturn(true);\n        Activity activity = mock(Activity.class);\n        when(activity.shouldShowRequestPermissionRationale(anyString())).thenReturn(true);\n\n        TestObserver<Boolean> sub = new TestObserver<>();\n        mRxPermissions.shouldShowRequestPermissionRationale(activity, \"p1\", \"p2\")\n                .subscribe(sub);\n\n        sub.assertComplete();\n        sub.assertNoErrors();\n        sub.assertValue(true);\n    }\n\n    @Test\n    @TargetApi(Build.VERSION_CODES.M)\n    public void shouldShowRequestPermissionRationale_allDenied_oneRationale() {\n        when(mRxPermissions.isMarshmallow()).thenReturn(true);\n        Activity activity = mock(Activity.class);\n        when(activity.shouldShowRequestPermissionRationale(\"p1\")).thenReturn(true);\n\n        TestObserver<Boolean> sub = new TestObserver<>();\n        mRxPermissions.shouldShowRequestPermissionRationale(activity, \"p1\", \"p2\")\n                .subscribe(sub);\n\n        sub.assertComplete();\n        sub.assertNoErrors();\n        sub.assertValue(false);\n    }\n\n    @Test\n    @TargetApi(Build.VERSION_CODES.M)\n    public void shouldShowRequestPermissionRationale_allDenied_noRationale() {\n        when(mRxPermissions.isMarshmallow()).thenReturn(true);\n        Activity activity = mock(Activity.class);\n\n        TestObserver<Boolean> sub = new TestObserver<>();\n        mRxPermissions.shouldShowRequestPermissionRationale(activity, \"p1\", \"p2\")\n                .subscribe(sub);\n\n        sub.assertComplete();\n        sub.assertNoErrors();\n        sub.assertValue(false);\n    }\n\n    @Test\n    @TargetApi(Build.VERSION_CODES.M)\n    public void shouldShowRequestPermissionRationale_oneDeniedRationale() {\n        when(mRxPermissions.isMarshmallow()).thenReturn(true);\n        Activity activity = mock(Activity.class);\n        when(mRxPermissions.isGranted(\"p1\")).thenReturn(true);\n        when(activity.shouldShowRequestPermissionRationale(\"p2\")).thenReturn(true);\n\n        TestObserver<Boolean> sub = new TestObserver<>();\n        mRxPermissions.shouldShowRequestPermissionRationale(activity, \"p1\", \"p2\")\n                .subscribe(sub);\n\n        sub.assertComplete();\n        sub.assertNoErrors();\n        sub.assertValue(true);\n    }\n\n    @Test\n    @TargetApi(Build.VERSION_CODES.M)\n    public void shouldShowRequestPermissionRationale_oneDeniedNotRationale() {\n        when(mRxPermissions.isMarshmallow()).thenReturn(true);\n        Activity activity = mock(Activity.class);\n        when(mRxPermissions.isGranted(\"p2\")).thenReturn(true);\n\n        TestObserver<Boolean> sub = new TestObserver<>();\n        mRxPermissions.shouldShowRequestPermissionRationale(activity, \"p1\", \"p2\")\n                .subscribe(sub);\n\n        sub.assertComplete();\n        sub.assertNoErrors();\n        sub.assertValue(false);\n    }\n\n    @Test\n    public void isGranted_preMarshmallow() {\n        // unmock isGranted\n        doCallRealMethod().when(mRxPermissions).isGranted(anyString());\n        doReturn(false).when(mRxPermissions).isMarshmallow();\n\n        boolean granted = mRxPermissions.isGranted(\"p\");\n\n        assertTrue(granted);\n    }\n\n    @Test\n    @TargetApi(Build.VERSION_CODES.M)\n    public void isGranted_granted() {\n        // unmock isGranted\n        doCallRealMethod().when(mRxPermissions).isGranted(anyString());\n        doReturn(true).when(mRxPermissions).isMarshmallow();\n        when(mActivity.checkSelfPermission(\"p\")).thenReturn(PackageManager.PERMISSION_GRANTED);\n\n        boolean granted = mRxPermissions.isGranted(\"p\");\n\n        assertTrue(granted);\n    }\n\n    @Test\n    @TargetApi(Build.VERSION_CODES.M)\n    public void isGranted_denied() {\n        // unmock isGranted\n        doCallRealMethod().when(mRxPermissions).isGranted(anyString());\n        doReturn(true).when(mRxPermissions).isMarshmallow();\n        when(mActivity.checkSelfPermission(\"p\")).thenReturn(PackageManager.PERMISSION_DENIED);\n\n        boolean granted = mRxPermissions.isGranted(\"p\");\n\n        assertFalse(granted);\n    }\n\n    @Test\n    public void isRevoked_preMarshmallow() {\n        // unmock isRevoked\n        doCallRealMethod().when(mRxPermissions).isRevoked(anyString());\n        doReturn(false).when(mRxPermissions).isMarshmallow();\n\n        boolean revoked = mRxPermissions.isRevoked(\"p\");\n\n        assertFalse(revoked);\n    }\n\n    @Test\n    @TargetApi(Build.VERSION_CODES.M)\n    public void isRevoked_true() {\n        // unmock isRevoked\n        doCallRealMethod().when(mRxPermissions).isRevoked(anyString());\n        doReturn(true).when(mRxPermissions).isMarshmallow();\n        PackageManager pm = mock(PackageManager.class);\n        when(mActivity.getPackageManager()).thenReturn(pm);\n        when(pm.isPermissionRevokedByPolicy(eq(\"p\"), anyString())).thenReturn(true);\n\n        boolean revoked = mRxPermissions.isRevoked(\"p\");\n\n        assertTrue(revoked);\n    }\n\n    @Test\n    @TargetApi(Build.VERSION_CODES.M)\n    public void isGranted_false() {\n        // unmock isRevoked\n        doCallRealMethod().when(mRxPermissions).isRevoked(anyString());\n        doReturn(true).when(mRxPermissions).isMarshmallow();\n        PackageManager pm = mock(PackageManager.class);\n        when(mActivity.getPackageManager()).thenReturn(pm);\n        when(pm.isPermissionRevokedByPolicy(eq(\"p\"), anyString())).thenReturn(false);\n\n        boolean revoked = mRxPermissions.isRevoked(\"p\");\n\n        assertFalse(revoked);\n    }\n}\n"
  },
  {
    "path": "sample/build.gradle",
    "content": "apply plugin: 'com.android.application'\n\nandroid {\n    compileSdkVersion rootProject.ext.compileSdkVersion\n\n    compileOptions {\n        sourceCompatibility JavaVersion.VERSION_1_8\n        targetCompatibility JavaVersion.VERSION_1_8\n    }\n\n    defaultConfig {\n        applicationId \"com.tbruyelle.rxpermissions.sample\"\n        minSdkVersion 14\n\n        targetSdkVersion rootProject.ext.targetSdkVersion\n        versionCode 1\n        versionName \"1.0\"\n    }\n\n    packagingOptions {\n        exclude 'META-INF/rxjava.properties'\n    }\n}\n\ndependencies {\n    implementation project(':rxpermissions')\n\n    implementation 'com.jakewharton.rxbinding4:rxbinding:4.0.0'\n    implementation rootProject.ext.androidXAppcompat\n\n    testImplementation 'junit:junit:4.13'\n    testImplementation rootProject.ext.mockito\n}\n"
  },
  {
    "path": "sample/src/main/AndroidManifest.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<manifest\n    package=\"com.tbruyelle.rxpermissions3.sample\"\n    xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    xmlns:tools=\"http://schemas.android.com/tools\"\n    >\n\n    <uses-permission android:name=\"android.permission.CAMERA\"/>\n\n    <application\n        android:allowBackup=\"true\"\n        android:fullBackupContent=\"false\"\n        android:icon=\"@mipmap/ic_launcher\"\n        android:label=\"@string/app_name\"\n        android:theme=\"@style/Theme.AppCompat.Light.DarkActionBar\"\n        tools:ignore=\"GoogleAppIndexingWarning\"\n        >\n        <activity\n            android:name=\"com.tbruyelle.rxpermissions3.sample.MainActivity\"\n            android:label=\"@string/app_name\"\n            >\n            <intent-filter>\n                <action android:name=\"android.intent.action.MAIN\"/>\n                <category android:name=\"android.intent.category.LAUNCHER\"/>\n            </intent-filter>\n        </activity>\n    </application>\n\n</manifest>\n"
  },
  {
    "path": "sample/src/main/java/com/tbruyelle/rxpermissions3/sample/MainActivity.java",
    "content": "package com.tbruyelle.rxpermissions3.sample;\n\nimport android.Manifest.permission;\nimport android.hardware.Camera;\nimport android.os.Bundle;\nimport android.util.Log;\nimport android.view.SurfaceView;\nimport android.widget.Toast;\n\nimport androidx.appcompat.app.AppCompatActivity;\n\nimport com.jakewharton.rxbinding4.view.RxView;\nimport com.tbruyelle.rxpermissions3.Permission;\nimport com.tbruyelle.rxpermissions3.RxPermissions;\n\nimport java.io.IOException;\n\nimport io.reactivex.rxjava3.disposables.Disposable;\nimport io.reactivex.rxjava3.functions.Action;\nimport io.reactivex.rxjava3.functions.Consumer;\n\n\npublic class MainActivity extends AppCompatActivity {\n\n    private static final String TAG = \"RxPermissionsSample\";\n\n    private Camera camera;\n    private SurfaceView surfaceView;\n    private Disposable disposable;\n\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        RxPermissions rxPermissions = new RxPermissions(this);\n        rxPermissions.setLogging(true);\n\n        setContentView(R.layout.act_main);\n        surfaceView = findViewById(R.id.surfaceView);\n\n        disposable = RxView.clicks(findViewById(R.id.enableCamera))\n                // Ask for permissions when button is clicked\n                .compose(rxPermissions.ensureEach(permission.CAMERA))\n                .subscribe(new Consumer<Permission>() {\n                               @Override\n                               public void accept(Permission permission) {\n                                   Log.i(TAG, \"Permission result \" + permission);\n                                   if (permission.granted) {\n                                       releaseCamera();\n                                       camera = Camera.open(0);\n                                       try {\n                                           camera.setPreviewDisplay(surfaceView.getHolder());\n                                           camera.startPreview();\n                                       } catch (IOException e) {\n                                           Log.e(TAG, \"Error while trying to display the camera preview\", e);\n                                       }\n                                   } else if (permission.shouldShowRequestPermissionRationale) {\n                                       // Denied permission without ask never again\n                                       Toast.makeText(MainActivity.this,\n                                               \"Denied permission without ask never again\",\n                                               Toast.LENGTH_SHORT).show();\n                                   } else {\n                                       // Denied permission with ask never again\n                                       // Need to go to the settings\n                                       Toast.makeText(MainActivity.this,\n                                               \"Permission denied, can't enable the camera\",\n                                               Toast.LENGTH_SHORT).show();\n                                   }\n                               }\n                           },\n                        new Consumer<Throwable>() {\n                            @Override\n                            public void accept(Throwable t) {\n                                Log.e(TAG, \"onError\", t);\n                            }\n                        },\n                        new Action() {\n                            @Override\n                            public void run() {\n                                Log.i(TAG, \"OnComplete\");\n                            }\n                        });\n    }\n\n    @Override\n    protected void onDestroy() {\n        if (disposable != null && !disposable.isDisposed()) {\n            disposable.dispose();\n        }\n        super.onDestroy();\n    }\n\n    @Override\n    protected void onStop() {\n        super.onStop();\n        releaseCamera();\n    }\n\n    private void releaseCamera() {\n        if (camera != null) {\n            camera.release();\n            camera = null;\n        }\n    }\n\n}"
  },
  {
    "path": "sample/src/main/res/layout/act_main.xml",
    "content": "<merge\n    xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    xmlns:tools=\"http://schemas.android.com/tools\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\"\n    tools:context=\".MainActivity\"\n    >\n\n    <SurfaceView\n        android:id=\"@+id/surfaceView\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"match_parent\"\n        />\n\n    <Button\n        android:id=\"@+id/enableCamera\"\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\"\n        android:layout_gravity=\"center_horizontal\"\n        android:layout_marginTop=\"16dp\"\n        android:text=\"@string/enable_camera\"\n        />\n</merge>\n"
  },
  {
    "path": "sample/src/main/res/values/strings.xml",
    "content": "<resources>\n    <string name=\"app_name\">RxPermissions sample</string>\n    <string name=\"enable_camera\">Enable camera</string>\n</resources>\n"
  },
  {
    "path": "sample/src/test/java/com/tbruyelle/rxpermissions/sample/RxPermissionsSampleTest.java",
    "content": "package com.tbruyelle.rxpermissions.sample;\n\nimport android.Manifest;\nimport android.annotation.TargetApi;\nimport android.app.Activity;\nimport android.os.Build;\n\nimport com.tbruyelle.rxpermissions3.Permission;\nimport com.tbruyelle.rxpermissions3.RxPermissions;\n\nimport org.junit.Before;\nimport org.junit.Test;\nimport org.mockito.Mock;\nimport org.mockito.MockitoAnnotations;\n\n\nimport io.reactivex.rxjava3.core.Observable;\n\nimport static org.mockito.Mockito.when;\n\n/**\n * Sample tests for {@link RxPermissions}.\n */\npublic class RxPermissionsSampleTest {\n\n    @Mock\n    private RxPermissions rxPermissions;\n\n    @Before\n    public void setUp() {\n        MockitoAnnotations.initMocks(this);\n    }\n\n    @Test\n    @TargetApi(Build.VERSION_CODES.M)\n    public void test_permission_denied_dont_ask_again() throws Exception {\n        // mocks\n        final String permissionString = Manifest.permission.READ_PHONE_STATE;\n        final boolean granted = false;\n        final boolean shouldShowRequestPermissionRationale = false;\n        final Permission permission = new Permission(permissionString, granted, shouldShowRequestPermissionRationale);\n        when(rxPermissions.requestEach(permissionString)).thenReturn(Observable.just(permission));\n        // test\n        rxPermissions.requestEach(permissionString).test().assertNoErrors().assertValue(permission);\n    }\n\n}\n"
  },
  {
    "path": "settings.gradle",
    "content": "include 'lib'\nproject(':lib').name = 'rxpermissions'\ninclude 'sample'\n"
  }
]