From 4771db6210ddf4b43138abd1b3010c07a2c05a91 Mon Sep 17 00:00:00 2001 From: Jude Date: Sun, 7 Apr 2019 23:42:22 +0530 Subject: [PATCH] * updated dependencies * updated bintray config + kotlin goodness --- app/build.gradle | 20 +- .../autostarterexample/MainActivity.java | 8 +- autostarter/build.gradle | 29 ++- .../AutoStartPermissionHelper.java | 193 ------------------ .../autostarter/AutoStartPermissionHelper.kt | 185 +++++++++++++++++ build.gradle | 8 +- gradle/wrapper/gradle-wrapper.properties | 4 +- 7 files changed, 228 insertions(+), 219 deletions(-) delete mode 100644 autostarter/src/main/java/com/judemanutd/autostarter/AutoStartPermissionHelper.java create mode 100644 autostarter/src/main/java/com/judemanutd/autostarter/AutoStartPermissionHelper.kt diff --git a/app/build.gradle b/app/build.gradle index 00719df..7c16ac8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,13 +1,15 @@ apply plugin: 'com.android.application' +apply plugin: 'kotlin-android-extensions' +apply plugin: 'kotlin-android' android { - compileSdkVersion 27 + compileSdkVersion 28 defaultConfig { applicationId "com.judemanutd.autostarterexample" minSdkVersion 14 - targetSdkVersion 27 - versionCode 1 - versionName "1.0" + targetSdkVersion 28 + versionCode 2 + versionName "1.0.1" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } @@ -27,8 +29,12 @@ android { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') testImplementation 'junit:junit:4.12' - androidTestImplementation 'com.android.support.test:runner:1.0.1' - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' - implementation 'com.android.support:appcompat-v7:27.1.0' + 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' implementation project(':autostarter') + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" +} +repositories { + mavenCentral() } diff --git a/app/src/main/java/com/judemanutd/autostarterexample/MainActivity.java b/app/src/main/java/com/judemanutd/autostarterexample/MainActivity.java index a0bae8d..7ce3987 100644 --- a/app/src/main/java/com/judemanutd/autostarterexample/MainActivity.java +++ b/app/src/main/java/com/judemanutd/autostarterexample/MainActivity.java @@ -1,7 +1,7 @@ package com.judemanutd.autostarterexample; -import android.support.v7.app.AppCompatActivity; import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; import android.widget.Button; import com.judemanutd.autostarter.AutoStartPermissionHelper; @@ -13,7 +13,9 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - final Button button = findViewById(R.id.button); - button.setOnClickListener(v -> AutoStartPermissionHelper.getInstance().getAutoStartPermission(this)); + Button button = findViewById(R.id.button); + button.setOnClickListener(v -> AutoStartPermissionHelper.getInstance().getAutoStartPermission(MainActivity.this)); + + } } diff --git a/autostarter/build.gradle b/autostarter/build.gradle index e2fc46c..941d3cf 100644 --- a/autostarter/build.gradle +++ b/autostarter/build.gradle @@ -1,10 +1,12 @@ apply plugin: 'com.android.library' +apply plugin: 'kotlin-android-extensions' +apply plugin: 'kotlin-android' ext { - bintrayRepo = 'Maven' + bintrayRepo = 'maven' bintrayName = 'autostarter' - publishedGroupId = 'com.judemanutd' + publishedGroupId = 'com.github.judemanutd' libraryName = 'Autostarter' artifact = 'autostarter' @@ -13,7 +15,7 @@ ext { siteUrl = 'https://github.com/judemanutd/AutoStarter' gitUrl = 'https://github.com/judemanutd/AutoStarter.git' - libraryVersion = '1.0.0' + libraryVersion = '1.0.1' developerId = 'judemanutd' developerName = 'Jude Fernandes' @@ -25,12 +27,12 @@ ext { } android { - compileSdkVersion 27 + compileSdkVersion 28 defaultConfig { minSdkVersion 14 - targetSdkVersion 27 - versionCode 1 - versionName "1.0.0" + targetSdkVersion 28 + versionCode 2 + versionName "1.0.1" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" @@ -49,9 +51,14 @@ dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) testImplementation 'junit:junit:4.12' - androidTestImplementation 'com.android.support.test:runner:1.0.1' - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.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" } -apply from: '../install.gradle' -apply from: '../bintray.gradle' \ No newline at end of file +repositories { + mavenCentral() +} + +apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle' +apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle' diff --git a/autostarter/src/main/java/com/judemanutd/autostarter/AutoStartPermissionHelper.java b/autostarter/src/main/java/com/judemanutd/autostarter/AutoStartPermissionHelper.java deleted file mode 100644 index bbfb956..0000000 --- a/autostarter/src/main/java/com/judemanutd/autostarter/AutoStartPermissionHelper.java +++ /dev/null @@ -1,193 +0,0 @@ -package com.judemanutd.autostarter; - -import android.content.ComponentName; -import android.content.Context; -import android.content.Intent; -import android.content.pm.ApplicationInfo; -import android.content.pm.PackageManager; -import android.os.Build; - -import java.util.List; - -public final class AutoStartPermissionHelper { - - private static AutoStartPermissionHelper instance; - - /*** - * Xiaomi - */ - private final String BRAND_XIAOMI = "xiaomi"; - private final String PACKAGE_XIAOMI_MAIN = "com.miui.securitycenter"; - private final String PACKAGE_XIAOMI_COMPONENT = "com.miui.permcenter.autostart.AutoStartManagementActivity"; - - /*** - * Letv - */ - private final String BRAND_LETV = "letv"; - private final String PACKAGE_LETV_MAIN = "com.letv.android.letvsafe"; - private final String PACKAGE_LETV_COMPONENT = "com.letv.android.letvsafe.AutobootManageActivity"; - - /*** - * Honor - */ - private final String BRAND_HONOR = "honor"; - private final String PACKAGE_HONOR_MAIN = "com.huawei.systemmanager"; - private final String PACKAGE_HONOR_COMPONENT = "com.huawei.systemmanager.optimize.process.ProtectActivity"; - - /** - * Oppo - */ - private final String BRAND_OPPO = "oppo"; - private final String PACKAGE_OPPO_MAIN = "com.coloros.safecenter"; - private final String PACKAGE_OPPO_FALLBACK = "com.oppo.safe"; - private final String PACKAGE_OPPO_COMPONENT = "com.coloros.safecenter.permission.startup.StartupAppListActivity"; - private final String PACKAGE_OPPO_COMPONENT_FALLBACK = "com.oppo.safe.permission.startup.StartupAppListActivity"; - private final String PACKAGE_OPPO_COMPONENT_FALLBACK_A = "com.coloros.safecenter.startupapp.StartupAppListActivity"; - - /** - * Vivo - */ - - private final String BRAND_VIVO = "vivo"; - private final String PACKAGE_VIVO_MAIN = "com.iqoo.secure"; - private final String PACKAGE_VIVO_FALLBACK = "com.vivo.permissionmanager"; - private final String PACKAGE_VIVO_COMPONENT = "com.iqoo.secure.ui.phoneoptimize.AddWhiteListActivity"; - private final String PACKAGE_VIVO_COMPONENT_FALLBACK = "com.vivo.permissionmanager.activity.BgStartUpManagerActivity"; - private final String PACKAGE_VIVO_COMPONENT_FALLBACK_A = "com.iqoo.secure.ui.phoneoptimize.BgStartUpManager"; - - private AutoStartPermissionHelper() { - } - - public static AutoStartPermissionHelper getInstance() { - if (instance == null) { - synchronized (AutoStartPermissionHelper.class) { - if (instance == null) { - instance = new AutoStartPermissionHelper(); - } - } - } - return instance; - } - - public void getAutoStartPermission(Context context) { - - final String build_info = Build.BRAND.toLowerCase(); - - switch (build_info) { - - case BRAND_XIAOMI: - autoStartXiaomi(context); - break; - - case BRAND_LETV: - autoStartLetv(context); - break; - - case BRAND_HONOR: - autoStartHonor(context); - break; - - case BRAND_OPPO: - autoStartOppo(context); - break; - - case BRAND_VIVO: - autoStartVivo(context); - break; - } - - } - - private void autoStartXiaomi(Context context) { - if (isPackageExists(context, PACKAGE_XIAOMI_MAIN)) { - try { - startIntent(context, PACKAGE_XIAOMI_MAIN, PACKAGE_XIAOMI_COMPONENT); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - - private void autoStartLetv(Context context) { - if (isPackageExists(context, PACKAGE_LETV_MAIN)) { - try { - startIntent(context, PACKAGE_LETV_MAIN, PACKAGE_LETV_COMPONENT); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - - private void autoStartHonor(Context context) { - if (isPackageExists(context, PACKAGE_HONOR_MAIN)) { - try { - startIntent(context, PACKAGE_HONOR_MAIN, PACKAGE_HONOR_COMPONENT); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - - private void autoStartOppo(Context context) { - if (isPackageExists(context, PACKAGE_OPPO_MAIN) || isPackageExists(context, PACKAGE_OPPO_FALLBACK)) { - try { - startIntent(context, PACKAGE_OPPO_MAIN, PACKAGE_OPPO_COMPONENT); - } catch (Exception e) { - e.printStackTrace(); - try { - startIntent(context, PACKAGE_OPPO_FALLBACK, PACKAGE_OPPO_COMPONENT_FALLBACK); - } catch (Exception ex) { - ex.printStackTrace(); - try { - startIntent(context, PACKAGE_OPPO_MAIN, PACKAGE_OPPO_COMPONENT_FALLBACK_A); - } catch (Exception exx) { - exx.printStackTrace(); - } - } - } - } - } - - private void autoStartVivo(Context context) { - if (isPackageExists(context, PACKAGE_VIVO_MAIN) || isPackageExists(context, PACKAGE_VIVO_FALLBACK)) { - try { - startIntent(context, PACKAGE_VIVO_MAIN, PACKAGE_VIVO_COMPONENT); - } catch (Exception e) { - e.printStackTrace(); - try { - startIntent(context, PACKAGE_VIVO_FALLBACK, PACKAGE_VIVO_COMPONENT_FALLBACK); - } catch (Exception ex) { - ex.printStackTrace(); - try { - startIntent(context, PACKAGE_VIVO_MAIN, PACKAGE_VIVO_COMPONENT_FALLBACK_A); - } catch (Exception exx) { - exx.printStackTrace(); - } - } - } - } - } - - private void startIntent(Context context, String packageName, String componentName) throws Exception { - try { - Intent intent = new Intent(); - intent.setComponent(new ComponentName(packageName, componentName)); - context.startActivity(intent); - } catch (Exception exception) { - exception.printStackTrace(); - throw exception; - } - } - - private static boolean isPackageExists(Context context, String targetPackage) { - List packages; - PackageManager pm = context.getPackageManager(); - packages = pm.getInstalledApplications(0); - for (ApplicationInfo packageInfo : packages) { - if (packageInfo.packageName.equals(targetPackage)) { - return true; - } - } - return false; - } -} \ No newline at end of file diff --git a/autostarter/src/main/java/com/judemanutd/autostarter/AutoStartPermissionHelper.kt b/autostarter/src/main/java/com/judemanutd/autostarter/AutoStartPermissionHelper.kt new file mode 100644 index 0000000..e08204d --- /dev/null +++ b/autostarter/src/main/java/com/judemanutd/autostarter/AutoStartPermissionHelper.kt @@ -0,0 +1,185 @@ +package com.judemanutd.autostarter + +import android.content.ComponentName +import android.content.Context +import android.content.Intent +import android.content.pm.ApplicationInfo +import android.os.Build + +class AutoStartPermissionHelper private constructor() { + + /*** + * Xiaomi + */ + private val BRAND_XIAOMI = "xiaomi" + private val PACKAGE_XIAOMI_MAIN = "com.miui.securitycenter" + private val PACKAGE_XIAOMI_COMPONENT = "com.miui.permcenter.autostart.AutoStartManagementActivity" + + /*** + * Letv + */ + private val BRAND_LETV = "letv" + private val PACKAGE_LETV_MAIN = "com.letv.android.letvsafe" + private val PACKAGE_LETV_COMPONENT = "com.letv.android.letvsafe.AutobootManageActivity" + + /*** + * 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" + + /** + * Oppo + */ + 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" + + /** + * Vivo + */ + + private val BRAND_VIVO = "vivo" + 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" + + fun getAutoStartPermission(context: Context) { + + val build_info = Build.BRAND.toLowerCase() + + when (build_info) { + + BRAND_XIAOMI -> autoStartXiaomi(context) + + BRAND_LETV -> autoStartLetv(context) + + BRAND_HONOR -> autoStartHonor(context) + + BRAND_OPPO -> autoStartOppo(context) + + BRAND_VIVO -> autoStartVivo(context) + } + + } + + private fun autoStartXiaomi(context: Context) { + if (isPackageExists(context, PACKAGE_XIAOMI_MAIN)) { + try { + startIntent(context, PACKAGE_XIAOMI_MAIN, PACKAGE_XIAOMI_COMPONENT) + } catch (e: Exception) { + e.printStackTrace() + } + + } + } + + private fun autoStartLetv(context: Context) { + if (isPackageExists(context, PACKAGE_LETV_MAIN)) { + try { + startIntent(context, PACKAGE_LETV_MAIN, PACKAGE_LETV_COMPONENT) + } catch (e: Exception) { + e.printStackTrace() + } + + } + } + + private fun autoStartHonor(context: Context) { + if (isPackageExists(context, PACKAGE_HONOR_MAIN)) { + try { + startIntent(context, PACKAGE_HONOR_MAIN, PACKAGE_HONOR_COMPONENT) + } catch (e: Exception) { + e.printStackTrace() + } + + } + } + + private fun autoStartOppo(context: Context) { + if (isPackageExists(context, PACKAGE_OPPO_MAIN) || isPackageExists(context, PACKAGE_OPPO_FALLBACK)) { + try { + startIntent(context, PACKAGE_OPPO_MAIN, PACKAGE_OPPO_COMPONENT) + } catch (e: Exception) { + e.printStackTrace() + try { + startIntent(context, PACKAGE_OPPO_FALLBACK, PACKAGE_OPPO_COMPONENT_FALLBACK) + } catch (ex: Exception) { + ex.printStackTrace() + try { + startIntent(context, PACKAGE_OPPO_MAIN, PACKAGE_OPPO_COMPONENT_FALLBACK_A) + } catch (exx: Exception) { + exx.printStackTrace() + } + + } + + } + + } + } + + private fun autoStartVivo(context: Context) { + if (isPackageExists(context, PACKAGE_VIVO_MAIN) || isPackageExists(context, PACKAGE_VIVO_FALLBACK)) { + try { + startIntent(context, PACKAGE_VIVO_MAIN, PACKAGE_VIVO_COMPONENT) + } catch (e: Exception) { + e.printStackTrace() + try { + startIntent(context, PACKAGE_VIVO_FALLBACK, PACKAGE_VIVO_COMPONENT_FALLBACK) + } catch (ex: Exception) { + ex.printStackTrace() + try { + startIntent(context, PACKAGE_VIVO_MAIN, PACKAGE_VIVO_COMPONENT_FALLBACK_A) + } catch (exx: Exception) { + exx.printStackTrace() + } + + } + + } + + } + } + + @Throws(Exception::class) + private fun startIntent(context: Context, packageName: String, componentName: String) { + try { + val intent = Intent() + intent.component = ComponentName(packageName, componentName) + context.startActivity(intent) + } catch (exception: Exception) { + exception.printStackTrace() + throw exception + } + + } + + private fun isPackageExists(context: Context, targetPackage: String): Boolean { + val packages: List + val pm = context.packageManager + packages = pm.getInstalledApplications(0) + for (packageInfo in packages) { + if (packageInfo.packageName == targetPackage) { + return true + } + } + return false + } + + companion object { + val obj = AutoStartPermissionHelper() + + @JvmStatic + fun getInstance(): AutoStartPermissionHelper { + return obj + } + + } +} \ No newline at end of file diff --git a/build.gradle b/build.gradle index af198ea..6f3c74f 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { + ext.kotlin_version = '1.3.21' repositories { google() @@ -9,9 +10,10 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.2.0-alpha14' - classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3' - classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0' + classpath 'com.android.tools.build:gradle:3.3.2' + classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4' + classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index b98a327..f2dafb6 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed May 09 23:32:07 IST 2018 +#Sun Apr 07 23:03:04 IST 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip