diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..c4b77f3 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,37 @@ +name: Publish + +on: + release: + # We'll run this workflow when a new GitHub release is created + types: [ released ] + +jobs: + publish: + name: Release build and publish + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v2 + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + + # Builds the release artifacts of the library + - name: Release build + run: ./gradlew :autostarter:assembleRelease + + # Generates other artifacts + - name: Source jar + run: ./gradlew androidSourcesJar + + # Runs upload, and then closes & releases the repository + - name: Publish to MavenCentral + run: ./gradlew publishReleasePublicationToSonatypeRepository --max-workers 1 + env: + OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} + OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} + SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }} + SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }} + SIGNING_KEY: ${{ secrets.SIGNING_KEY }} + SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }} \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index ad3cb20..8bab384 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,8 +8,8 @@ android { applicationId "com.judemanutd.autostarterexample" minSdkVersion 14 targetSdkVersion 30 - versionCode 4 - versionName "1.0.4" + versionCode 5 + versionName "1.0.5" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } @@ -28,7 +28,7 @@ android { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') - testImplementation 'junit:junit:4.13' + testImplementation 'junit:junit:4.13.1' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' implementation 'com.android.support:appcompat-v7:28.0.0' diff --git a/autostarter/build.gradle b/autostarter/build.gradle index 1faf699..6980dc3 100644 --- a/autostarter/build.gradle +++ b/autostarter/build.gradle @@ -3,36 +3,34 @@ apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' ext { - bintrayRepo = 'maven' - bintrayName = 'autostarter' - publishedGroupId = 'com.github.judemanutd' - libraryName = 'Autostarter' - artifact = 'autostarter' + PUBLISH_GROUP_ID = "com.github.judemanutd" + PUBLISH_VERSION = "1.1.0" + PUBLISH_ARTIFACT_ID = "autostarter" + PUBLISH_DESCRIPTION = 'A library to help add your app to android autostart' + PUBLISH_URL = 'https://github.com/judemanutd/AutoStarter' + PUBLISH_LICENSE_NAME = 'MIT' + PUBLISH_LICENSE_URL = 'https://opensource.org/licenses/MIT' - libraryDescription = 'A library to help add your app to android autostart' + PUBLISH_DEVELOPER_ID = 'judemanutd' + PUBLISH_DEVELOPER_NAME = 'Jude Fernandes' + PUBLISH_DEVELOPER_EMAIL = 'jude.manutd@gmail.com' - siteUrl = 'https://github.com/judemanutd/AutoStarter' - gitUrl = 'https://github.com/judemanutd/AutoStarter.git' + PUBLISH_SCM_CONNECTION = 'scm:git:github.com/judemanutd/AutoStarter.git' + PUBLISH_SCM_DEVELOPER_CONNECTION = 'scm:git:ssh://github.com/judemanutd/AutoStarter.git' + PUBLISH_SCM_URL = 'https://github.com/judemanutd/AutoStarter/tree/master' - libraryVersion = '1.0.9' - - developerId = 'judemanutd' - developerName = 'Jude Fernandes' - developerEmail = 'jude.manutd@gmail.com' - - licenseName = 'MIT' - licenseUrl = 'https://opensource.org/licenses/MIT' - allLicenses = ["MIT"] } +apply from: "${rootProject.projectDir}/scripts/publish-module.gradle" + android { compileSdkVersion 30 defaultConfig { minSdkVersion 14 targetSdkVersion 30 - versionCode 9 - versionName "1.0.9" + versionCode 10 + versionName "1.1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" @@ -50,7 +48,7 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - testImplementation 'junit:junit:4.13' + testImplementation 'junit:junit:4.13.1' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" @@ -62,7 +60,4 @@ repositories { tasks.withType(Javadoc).all { enabled = false -} - -apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle' -apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle' +} \ No newline at end of file diff --git a/autostarter/src/main/AndroidManifest.xml b/autostarter/src/main/AndroidManifest.xml index f03e6bd..39ac7c8 100644 --- a/autostarter/src/main/AndroidManifest.xml +++ b/autostarter/src/main/AndroidManifest.xml @@ -1,2 +1,35 @@ + xmlns:tools="http://schemas.android.com/tools" + package="com.judemanutd.autostarter"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/autostarter/src/main/java/com/judemanutd/autostarter/AutoStartPermissionHelper.kt b/autostarter/src/main/java/com/judemanutd/autostarter/AutoStartPermissionHelper.kt index eb2cceb..a3f37b1 100644 --- a/autostarter/src/main/java/com/judemanutd/autostarter/AutoStartPermissionHelper.kt +++ b/autostarter/src/main/java/com/judemanutd/autostarter/AutoStartPermissionHelper.kt @@ -19,7 +19,8 @@ class AutoStartPermissionHelper private constructor() { private val BRAND_XIAOMI_POCO = "poco" private val BRAND_XIAOMI_REDMI = "redmi" private val PACKAGE_XIAOMI_MAIN = "com.miui.securitycenter" - private val PACKAGE_XIAOMI_COMPONENT = "com.miui.permcenter.autostart.AutoStartManagementActivity" + private val PACKAGE_XIAOMI_COMPONENT = + "com.miui.permcenter.autostart.AutoStartManagementActivity" /*** * Letv @@ -34,22 +35,26 @@ class AutoStartPermissionHelper private constructor() { private val BRAND_ASUS = "asus" private val PACKAGE_ASUS_MAIN = "com.asus.mobilemanager" private val PACKAGE_ASUS_COMPONENT = "com.asus.mobilemanager.powersaver.PowerSaverSettings" - private val PACKAGE_ASUS_COMPONENT_FALLBACK = "com.asus.mobilemanager.autostart.AutoStartActivity" + private val PACKAGE_ASUS_COMPONENT_FALLBACK = + "com.asus.mobilemanager.autostart.AutoStartActivity" /*** * Honor */ private val BRAND_HONOR = "honor" private val PACKAGE_HONOR_MAIN = "com.huawei.systemmanager" - private val PACKAGE_HONOR_COMPONENT = "com.huawei.systemmanager.optimize.process.ProtectActivity" + private val PACKAGE_HONOR_COMPONENT = + "com.huawei.systemmanager.optimize.process.ProtectActivity" /*** * Huawei */ private val BRAND_HUAWEI = "huawei" private val PACKAGE_HUAWEI_MAIN = "com.huawei.systemmanager" - private val PACKAGE_HUAWEI_COMPONENT = "com.huawei.systemmanager.startupmgr.ui.StartupNormalAppListActivity" - private val PACKAGE_HUAWEI_COMPONENT_FALLBACK = "com.huawei.systemmanager.optimize.process.ProtectActivity" + private val PACKAGE_HUAWEI_COMPONENT = + "com.huawei.systemmanager.startupmgr.ui.StartupNormalAppListActivity" + private val PACKAGE_HUAWEI_COMPONENT_FALLBACK = + "com.huawei.systemmanager.optimize.process.ProtectActivity" /** * Oppo @@ -57,9 +62,12 @@ class AutoStartPermissionHelper private constructor() { private val BRAND_OPPO = "oppo" private val PACKAGE_OPPO_MAIN = "com.coloros.safecenter" private val PACKAGE_OPPO_FALLBACK = "com.oppo.safe" - private val PACKAGE_OPPO_COMPONENT = "com.coloros.safecenter.permission.startup.StartupAppListActivity" - private val PACKAGE_OPPO_COMPONENT_FALLBACK = "com.oppo.safe.permission.startup.StartupAppListActivity" - private val PACKAGE_OPPO_COMPONENT_FALLBACK_A = "com.coloros.safecenter.startupapp.StartupAppListActivity" + private val PACKAGE_OPPO_COMPONENT = + "com.coloros.safecenter.permission.startup.StartupAppListActivity" + private val PACKAGE_OPPO_COMPONENT_FALLBACK = + "com.oppo.safe.permission.startup.StartupAppListActivity" + private val PACKAGE_OPPO_COMPONENT_FALLBACK_A = + "com.coloros.safecenter.startupapp.StartupAppListActivity" /** * Vivo @@ -69,8 +77,10 @@ class AutoStartPermissionHelper private constructor() { private val PACKAGE_VIVO_MAIN = "com.iqoo.secure" private val PACKAGE_VIVO_FALLBACK = "com.vivo.permissionmanager" private val PACKAGE_VIVO_COMPONENT = "com.iqoo.secure.ui.phoneoptimize.AddWhiteListActivity" - private val PACKAGE_VIVO_COMPONENT_FALLBACK = "com.vivo.permissionmanager.activity.BgStartUpManagerActivity" - private val PACKAGE_VIVO_COMPONENT_FALLBACK_A = "com.iqoo.secure.ui.phoneoptimize.BgStartUpManager" + private val PACKAGE_VIVO_COMPONENT_FALLBACK = + "com.vivo.permissionmanager.activity.BgStartUpManagerActivity" + private val PACKAGE_VIVO_COMPONENT_FALLBACK_A = + "com.iqoo.secure.ui.phoneoptimize.BgStartUpManager" /** * Nokia @@ -78,7 +88,8 @@ class AutoStartPermissionHelper private constructor() { private val BRAND_NOKIA = "nokia" private val PACKAGE_NOKIA_MAIN = "com.evenwell.powersaving.g3" - private val PACKAGE_NOKIA_COMPONENT = "com.evenwell.powersaving.g3.exception.PowerSaverExceptionActivity" + private val PACKAGE_NOKIA_COMPONENT = + "com.evenwell.powersaving.g3.exception.PowerSaverExceptionActivity" /*** * Samsung @@ -86,7 +97,8 @@ class AutoStartPermissionHelper private constructor() { private val BRAND_SAMSUNG = "samsung" private val PACKAGE_SAMSUNG_MAIN = "com.samsung.android.lool" private val PACKAGE_SAMSUNG_COMPONENT = "com.samsung.android.sm.ui.battery.BatteryActivity" - private val PACKAGE_SAMSUNG_COMPONENT_2 = "com.samsung.android.sm.battery.ui.usage.CheckableAppListActivity" + private val PACKAGE_SAMSUNG_COMPONENT_2 = + "com.samsung.android.sm.battery.ui.usage.CheckableAppListActivity" private val PACKAGE_SAMSUNG_COMPONENT_3 = "com.samsung.android.sm.battery.ui.BatteryActivity" /*** @@ -94,11 +106,24 @@ class AutoStartPermissionHelper private constructor() { */ private val BRAND_ONE_PLUS = "oneplus" private val PACKAGE_ONE_PLUS_MAIN = "com.oneplus.security" - private val PACKAGE_ONE_PLUS_COMPONENT = "com.oneplus.security.chainlaunch.view.ChainLaunchAppListActivity" + private val PACKAGE_ONE_PLUS_COMPONENT = + "com.oneplus.security.chainlaunch.view.ChainLaunchAppListActivity" private val PACKAGE_ONE_PLUS_ACTION = "com.android.settings.action.BACKGROUND_OPTIMIZE" - private val PACKAGES_TO_CHECK_FOR_PERMISSION = listOf(PACKAGE_ASUS_MAIN, PACKAGE_XIAOMI_MAIN, PACKAGE_LETV_MAIN, PACKAGE_HONOR_MAIN, PACKAGE_OPPO_MAIN, - PACKAGE_OPPO_FALLBACK, PACKAGE_VIVO_MAIN, PACKAGE_VIVO_FALLBACK, PACKAGE_NOKIA_MAIN, PACKAGE_HUAWEI_MAIN, PACKAGE_SAMSUNG_MAIN, PACKAGE_ONE_PLUS_MAIN) + private val PACKAGES_TO_CHECK_FOR_PERMISSION = listOf( + PACKAGE_ASUS_MAIN, + PACKAGE_XIAOMI_MAIN, + PACKAGE_LETV_MAIN, + PACKAGE_HONOR_MAIN, + PACKAGE_OPPO_MAIN, + PACKAGE_OPPO_FALLBACK, + PACKAGE_VIVO_MAIN, + PACKAGE_VIVO_FALLBACK, + PACKAGE_NOKIA_MAIN, + PACKAGE_HUAWEI_MAIN, + PACKAGE_SAMSUNG_MAIN, + PACKAGE_ONE_PLUS_MAIN + ) /** * It will attempt to open the specific manufacturer settings screen with the autostart permission @@ -109,13 +134,21 @@ class AutoStartPermissionHelper private constructor() { * @param newTask, if true when the activity is attempted to be opened it will add FLAG_ACTIVITY_NEW_TASK to the intent * @return true if the activity was opened or is confirmed that it exists (depending on [open]]), false otherwise */ - fun getAutoStartPermission(context: Context, open: Boolean = true, newTask: Boolean = false): Boolean { + fun getAutoStartPermission( + context: Context, + open: Boolean = true, + newTask: Boolean = false + ): Boolean { - when (Build.BRAND.toLowerCase(Locale.ROOT)) { + when (Build.BRAND.lowercase(Locale.ROOT)) { BRAND_ASUS -> return autoStartAsus(context, open, newTask) - BRAND_XIAOMI, BRAND_XIAOMI_POCO, BRAND_XIAOMI_REDMI -> return autoStartXiaomi(context, open, newTask) + BRAND_XIAOMI, BRAND_XIAOMI_POCO, BRAND_XIAOMI_REDMI -> return autoStartXiaomi( + context, + open, + newTask + ) BRAND_LETV -> return autoStartLetv(context, open, newTask) @@ -148,13 +181,16 @@ class AutoStartPermissionHelper private constructor() { * by the library. * @return true if autostart permission is present in the manufacturer and supported by the library, false otherwise */ - fun isAutoStartPermissionAvailable(context: Context, onlyIfSupported: Boolean = false): Boolean { + fun isAutoStartPermissionAvailable( + context: Context, + onlyIfSupported: Boolean = false + ): Boolean { val packages: List val pm = context.packageManager packages = pm.getInstalledApplications(0) for (packageInfo in packages) { if (PACKAGES_TO_CHECK_FOR_PERMISSION.contains(packageInfo.packageName) - && (!onlyIfSupported || getAutoStartPermission(context, open = false)) + && (!onlyIfSupported || getAutoStartPermission(context, open = false)) ) return true } return false @@ -162,66 +198,66 @@ class AutoStartPermissionHelper private constructor() { private fun autoStartXiaomi(context: Context, open: Boolean, newTask: Boolean): Boolean { return autoStart( - context, - listOf(PACKAGE_XIAOMI_MAIN), - listOf(getIntent(PACKAGE_XIAOMI_MAIN, PACKAGE_XIAOMI_COMPONENT, newTask)), - open + context, + listOf(PACKAGE_XIAOMI_MAIN), + listOf(getIntent(PACKAGE_XIAOMI_MAIN, PACKAGE_XIAOMI_COMPONENT, newTask)), + open ) } private fun autoStartAsus(context: Context, open: Boolean, newTask: Boolean): Boolean { return autoStart( - context, - listOf(PACKAGE_ASUS_MAIN), - listOf( - getIntent(PACKAGE_ASUS_MAIN, PACKAGE_ASUS_COMPONENT, newTask), - getIntent(PACKAGE_ASUS_MAIN, PACKAGE_ASUS_COMPONENT_FALLBACK, newTask) - ), - open + context, + listOf(PACKAGE_ASUS_MAIN), + listOf( + getIntent(PACKAGE_ASUS_MAIN, PACKAGE_ASUS_COMPONENT, newTask), + getIntent(PACKAGE_ASUS_MAIN, PACKAGE_ASUS_COMPONENT_FALLBACK, newTask) + ), + open ) } private fun autoStartLetv(context: Context, open: Boolean, newTask: Boolean): Boolean { return autoStart( - context, - listOf(PACKAGE_LETV_MAIN), - listOf(getIntent(PACKAGE_LETV_MAIN, PACKAGE_LETV_COMPONENT, newTask)), - open + context, + listOf(PACKAGE_LETV_MAIN), + listOf(getIntent(PACKAGE_LETV_MAIN, PACKAGE_LETV_COMPONENT, newTask)), + open ) } private fun autoStartHonor(context: Context, open: Boolean, newTask: Boolean): Boolean { return autoStart( - context, - listOf(PACKAGE_HONOR_MAIN), - listOf(getIntent(PACKAGE_HONOR_MAIN, PACKAGE_HONOR_COMPONENT, newTask)), - open + context, + listOf(PACKAGE_HONOR_MAIN), + listOf(getIntent(PACKAGE_HONOR_MAIN, PACKAGE_HONOR_COMPONENT, newTask)), + open ) } private fun autoStartHuawei(context: Context, open: Boolean, newTask: Boolean): Boolean { return autoStart( - context, - listOf(PACKAGE_HUAWEI_MAIN), - listOf( - getIntent(PACKAGE_HUAWEI_MAIN, PACKAGE_HUAWEI_COMPONENT, newTask), - getIntent(PACKAGE_HUAWEI_MAIN, PACKAGE_HUAWEI_COMPONENT_FALLBACK, newTask) - ), - open + context, + listOf(PACKAGE_HUAWEI_MAIN), + listOf( + getIntent(PACKAGE_HUAWEI_MAIN, PACKAGE_HUAWEI_COMPONENT, newTask), + getIntent(PACKAGE_HUAWEI_MAIN, PACKAGE_HUAWEI_COMPONENT_FALLBACK, newTask) + ), + open ) } private fun autoStartOppo(context: Context, open: Boolean, newTask: Boolean): Boolean { return if (autoStart( - context, - listOf(PACKAGE_OPPO_MAIN, PACKAGE_OPPO_FALLBACK), - listOf( - getIntent(PACKAGE_OPPO_MAIN, PACKAGE_OPPO_COMPONENT, newTask), - getIntent(PACKAGE_OPPO_FALLBACK, PACKAGE_OPPO_COMPONENT_FALLBACK, newTask), - getIntent(PACKAGE_OPPO_MAIN, PACKAGE_OPPO_COMPONENT_FALLBACK_A, newTask) - ), - open - ) + context, + listOf(PACKAGE_OPPO_MAIN, PACKAGE_OPPO_FALLBACK), + listOf( + getIntent(PACKAGE_OPPO_MAIN, PACKAGE_OPPO_COMPONENT, newTask), + getIntent(PACKAGE_OPPO_FALLBACK, PACKAGE_OPPO_COMPONENT_FALLBACK, newTask), + getIntent(PACKAGE_OPPO_MAIN, PACKAGE_OPPO_COMPONENT_FALLBACK_A, newTask) + ), + open + ) ) true else launchOppoAppInfo(context, open, newTask) } @@ -245,46 +281,50 @@ class AutoStartPermissionHelper private constructor() { private fun autoStartVivo(context: Context, open: Boolean, newTask: Boolean): Boolean { return autoStart( - context, - listOf(PACKAGE_VIVO_MAIN, PACKAGE_VIVO_FALLBACK), - listOf( - getIntent(PACKAGE_VIVO_MAIN, PACKAGE_VIVO_COMPONENT, newTask), - getIntent(PACKAGE_VIVO_FALLBACK, PACKAGE_VIVO_COMPONENT_FALLBACK, newTask), - getIntent(PACKAGE_VIVO_MAIN, PACKAGE_VIVO_COMPONENT_FALLBACK_A, newTask) - ), - open + context, + listOf(PACKAGE_VIVO_MAIN, PACKAGE_VIVO_FALLBACK), + listOf( + getIntent(PACKAGE_VIVO_MAIN, PACKAGE_VIVO_COMPONENT, newTask), + getIntent(PACKAGE_VIVO_FALLBACK, PACKAGE_VIVO_COMPONENT_FALLBACK, newTask), + getIntent(PACKAGE_VIVO_MAIN, PACKAGE_VIVO_COMPONENT_FALLBACK_A, newTask) + ), + open ) } private fun autoStartNokia(context: Context, open: Boolean, newTask: Boolean): Boolean { return autoStart( - context, - listOf(PACKAGE_NOKIA_MAIN), - listOf(getIntent(PACKAGE_NOKIA_MAIN, PACKAGE_NOKIA_COMPONENT, newTask)), - open + context, + listOf(PACKAGE_NOKIA_MAIN), + listOf(getIntent(PACKAGE_NOKIA_MAIN, PACKAGE_NOKIA_COMPONENT, newTask)), + open ) } private fun autoStartSamsung(context: Context, open: Boolean, newTask: Boolean): Boolean { return autoStart( - context, - listOf(PACKAGE_SAMSUNG_MAIN), - listOf( - getIntent(PACKAGE_SAMSUNG_MAIN, PACKAGE_SAMSUNG_COMPONENT, newTask), - getIntent(PACKAGE_SAMSUNG_MAIN, PACKAGE_SAMSUNG_COMPONENT_2, newTask), - getIntent(PACKAGE_SAMSUNG_MAIN, PACKAGE_SAMSUNG_COMPONENT_3, newTask) - ), - open + context, + listOf(PACKAGE_SAMSUNG_MAIN), + listOf( + getIntent(PACKAGE_SAMSUNG_MAIN, PACKAGE_SAMSUNG_COMPONENT, newTask), + getIntent(PACKAGE_SAMSUNG_MAIN, PACKAGE_SAMSUNG_COMPONENT_2, newTask), + getIntent(PACKAGE_SAMSUNG_MAIN, PACKAGE_SAMSUNG_COMPONENT_3, newTask) + ), + open ) } private fun autoStartOnePlus(context: Context, open: Boolean, newTask: Boolean): Boolean { return autoStart( - context, - listOf(PACKAGE_ONE_PLUS_MAIN), - listOf(getIntent(PACKAGE_ONE_PLUS_MAIN, PACKAGE_ONE_PLUS_COMPONENT, newTask)), - open - ) || autoStartFromAction(context, listOf(getIntentFromAction(PACKAGE_ONE_PLUS_ACTION, newTask)), open) + context, + listOf(PACKAGE_ONE_PLUS_MAIN), + listOf(getIntent(PACKAGE_ONE_PLUS_MAIN, PACKAGE_ONE_PLUS_COMPONENT, newTask)), + open + ) || autoStartFromAction( + context, + listOf(getIntentFromAction(PACKAGE_ONE_PLUS_ACTION, newTask)), + open + ) } @Throws(Exception::class) @@ -357,7 +397,7 @@ class AutoStartPermissionHelper private constructor() { */ private fun isActivityFound(context: Context, intent: Intent): Boolean { return context.packageManager.queryIntentActivities( - intent, PackageManager.MATCH_DEFAULT_ONLY + intent, PackageManager.MATCH_DEFAULT_ONLY ).isNotEmpty() } @@ -402,7 +442,12 @@ class AutoStartPermissionHelper private constructor() { * @param open, if true it will attempt to open the settings screen, otherwise it just check its existence * @return true if the screen was opened or exists, false if it doesn't exist or could not be opened */ - private fun autoStart(context: Context, packages: List, intents: List, open: Boolean): Boolean { + private fun autoStart( + context: Context, + packages: List, + intents: List, + open: Boolean + ): Boolean { return if (packages.any { isPackageExists(context, it) }) { if (open) openAutoStartScreen(context, intents) else areActivitiesFound(context, intents) @@ -418,7 +463,11 @@ class AutoStartPermissionHelper private constructor() { * @param open, if true it will attempt to open the settings screen, otherwise it just check its existence * @return true if the screen was opened or exists, false if it doesn't exist or could not be opened */ - private fun autoStartFromAction(context: Context, intentActions: List, open: Boolean): Boolean { + private fun autoStartFromAction( + context: Context, + intentActions: List, + open: Boolean + ): Boolean { return if (open) openAutoStartScreen(context, intentActions) else areActivitiesFound(context, intentActions) } diff --git a/build.gradle b/build.gradle index 6c25190..c386d0d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,26 +1,29 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.4.31' + ext.kotlin_version = '1.5.20' repositories { google() - jcenter() mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:4.1.3' - classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4' - classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' + classpath 'com.android.tools.build:gradle:4.2.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } +plugins { + id("io.github.gradle-nexus.publish-plugin") version "1.1.0" +} + +apply from: "${rootDir}/scripts/publish-root.gradle" + allprojects { repositories { google() - jcenter() + maven { url 'https://jitpack.io' } } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 564b6e0..f87720a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip diff --git a/scripts/publish-module.gradle b/scripts/publish-module.gradle new file mode 100644 index 0000000..0d06c35 --- /dev/null +++ b/scripts/publish-module.gradle @@ -0,0 +1,76 @@ +apply plugin: 'maven-publish' +apply plugin: 'signing' + +task androidSourcesJar(type: Jar) { + archiveClassifier.set('sources') + if (project.plugins.findPlugin("com.android.library")) { + from android.sourceSets.main.java.srcDirs + } else { + from sourceSets.main.java.srcDirs + } +} + +artifacts { + archives androidSourcesJar +} + +group = PUBLISH_GROUP_ID +version = PUBLISH_VERSION + +afterEvaluate { + publishing { + publications { + release(MavenPublication) { + // The coordinates of the library, being set from variables that + // we'll set up later + groupId PUBLISH_GROUP_ID + artifactId PUBLISH_ARTIFACT_ID + version PUBLISH_VERSION + + // Two artifacts, the `aar` (or `jar`) and the sources + if (project.plugins.findPlugin("com.android.library")) { + from components.release + } else { + artifact("$buildDir/libs/${project.getName()}-${version}.jar") + } + + artifact androidSourcesJar + + // Mostly self-explanatory metadata + pom { + name = PUBLISH_ARTIFACT_ID + description = PUBLISH_DESCRIPTION + url = PUBLISH_URL + licenses { + license { + name = PUBLISH_LICENSE_NAME + url = PUBLISH_LICENSE_URL + } + } + developers { + developer { + id = PUBLISH_DEVELOPER_ID + name = PUBLISH_DEVELOPER_NAME + email = PUBLISH_DEVELOPER_EMAIL + } + } + + scm { + connection = PUBLISH_SCM_CONNECTION + developerConnection = PUBLISH_SCM_DEVELOPER_CONNECTION + url = PUBLISH_SCM_URL + } + } + } + } + } +} + +ext["signing.key"] = rootProject.ext["signing.key"] +ext["signing.keyId"] = rootProject.ext["signing.keyId"] +ext["signing.password"] = rootProject.ext["signing.password"] +// ext["signing.secretKeyRingFile"] = rootProject.ext["signing.secretKeyRingFile"] + +signing { + sign publishing.publications +} \ No newline at end of file diff --git a/scripts/publish-root.gradle b/scripts/publish-root.gradle new file mode 100644 index 0000000..55b9eca --- /dev/null +++ b/scripts/publish-root.gradle @@ -0,0 +1,38 @@ +// Create variables with empty default values +ext["signing.keyId"] = '' +ext["signing.password"] = '' +// ext["signing.secretKeyRingFile"] = '' +ext["signing.key"] = '' +ext["ossrhUsername"] = '' +ext["ossrhPassword"] = '' +ext["sonatypeStagingProfileId"] = '' + +File secretPropsFile = project.rootProject.file('local.properties') +if (secretPropsFile.exists()) { + // Read local.properties file first if it exists + Properties p = new Properties() + new FileInputStream(secretPropsFile).withCloseable { is -> p.load(is) } + p.each { name, value -> ext[name] = value } +} else { + // Use system environment variables + ext["ossrhUsername"] = System.getenv('OSSRH_USERNAME') + ext["ossrhPassword"] = System.getenv('OSSRH_PASSWORD') + ext["sonatypeStagingProfileId"] = System.getenv('SONATYPE_STAGING_PROFILE_ID') + ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID') + ext["signing.password"] = System.getenv('SIGNING_PASSWORD') + ext["signing.key"] = System.getenv('SIGNING_KEY') + // ext["signing.secretKeyRingFile"] = System.getenv('SIGNING_SECRET_KEY_RING_FILE') +} + +// Set up Sonatype repository +nexusPublishing { + repositories { + sonatype { + stagingProfileId = sonatypeStagingProfileId + username = ossrhUsername + password = ossrhPassword + nexusUrl.set(uri("https://oss.sonatype.org/service/local/")) + snapshotRepositoryUrl.set(uri("https://oss.sonatype.org/content/repositories/snapshots/")) + } + } +} \ No newline at end of file