From 8931f36bdacb129a04609661c63bca81019fa1bd Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Mon, 19 Feb 2018 11:34:35 +0100 Subject: [PATCH] Push work Signed-off-by: Mario Danic --- .gitignore | 4 +- app/gplay.gradle | 2 + .../com/nextcloud/talk/utils/DeviceUtils.java | 38 +++++-------------- app/src/main/res/values/setup.xml | 10 ----- build.gradle | 3 ++ 5 files changed, 17 insertions(+), 40 deletions(-) diff --git a/.gitignore b/.gitignore index aa9a01a6a..2b7ad87b7 100644 --- a/.gitignore +++ b/.gitignore @@ -47,8 +47,8 @@ captures/ .externalNativeBuild # Google Services (e.g. APIs or Firebase) -google-services.json -app/google-services.json +#google-services.json +#app/google-services.json # Freeline freeline.py diff --git a/app/gplay.gradle b/app/gplay.gradle index 9af8ded79..4f449f644 100644 --- a/app/gplay.gradle +++ b/app/gplay.gradle @@ -6,3 +6,5 @@ dependencies { implementation "com.google.android.gms:play-services-gcm:${googleLibraryVersion}" implementation "com.google.firebase:firebase-messaging:${googleLibraryVersion}" } + +apply plugin: 'com.google.gms.google-services' diff --git a/app/src/main/java/com/nextcloud/talk/utils/DeviceUtils.java b/app/src/main/java/com/nextcloud/talk/utils/DeviceUtils.java index c42deb134..d58c3acd9 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/DeviceUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/DeviceUtils.java @@ -40,21 +40,12 @@ public class DeviceUtils { try { @SuppressLint("PrivateApi") Class appOpsUtilsClass = Class.forName("android.miui.AppOpsUtils"); if (appOpsUtilsClass != null) { - Method getApplicationAutoStart = appOpsUtilsClass.getDeclaredMethod("getApplicationAutoStart", Context.class, String.class); - if (getApplicationAutoStart != null) { + Method setApplicationAutoStartMethod = appOpsUtilsClass.getDeclaredMethod("setApplicationAutoStart", Context.class, String + .class, Boolean.TYPE); + if (setApplicationAutoStartMethod != null) { Context applicationContext = NextcloudTalkApplication.getSharedApplication().getApplicationContext(); - Object result = getApplicationAutoStart.invoke(appOpsUtilsClass, applicationContext, applicationContext.getPackageName()); - if (result instanceof Integer) { - Integer integerResult = (Integer) result; - if (integerResult == 0) { - Method setApplicationAutoStartMethod = appOpsUtilsClass.getDeclaredMethod("setApplicationAutoStart", - Context.class, String.class, Boolean.TYPE); - if (setApplicationAutoStartMethod != null) { - setApplicationAutoStartMethod.invoke(appOpsUtilsClass, applicationContext, applicationContext.getPackageName(), - Boolean.TRUE); - } - } - } + setApplicationAutoStartMethod.invoke(appOpsUtilsClass, applicationContext, applicationContext + .getPackageName(), Boolean.TRUE); } } } catch (ClassNotFoundException e) { @@ -78,20 +69,11 @@ public class DeviceUtils { if (getInstanceMethod != null) { Object protectAppControlInstance = getInstanceMethod.invoke(null, applicationContext); - Method isProtectedMethod = protectAppControlClass.getDeclaredMethod("isProtect", String.class); - if (isProtectedMethod != null) { - Object result = isProtectedMethod.invoke(protectAppControlInstance, applicationContext.getPackageName()); - if (result instanceof Boolean) { - boolean booleanResult = (boolean) result; - if (!booleanResult) { - Method setProtectMethod = protectAppControlClass.getDeclaredMethod("setProtect", List.class); - if (setProtectMethod != null) { - List appsList = new ArrayList<>(); - appsList.add(applicationContext.getPackageName()); - setProtectMethod.invoke(protectAppControlInstance, appsList); - } - } - } + Method setProtectMethod = protectAppControlClass.getDeclaredMethod("setProtect", List.class); + if (setProtectMethod != null) { + List appsList = new ArrayList<>(); + appsList.add(applicationContext.getPackageName()); + setProtectMethod.invoke(protectAppControlInstance, appsList); } } } diff --git a/app/src/main/res/values/setup.xml b/app/src/main/res/values/setup.xml index 7d5742111..0b55f7efd 100644 --- a/app/src/main/res/values/setup.xml +++ b/app/src/main/res/values/setup.xml @@ -19,14 +19,4 @@ com.nextcloud.client nextcloud - - 829118773643-cq33cmhv7mnv7iq8mjv6rt7t15afc70k.apps.googleusercontent.com - https://nextcloud-a7dea.firebaseio.com - 829118773643 - AIzaSyAWIyOcLafaFp8PFL61h64cy1NNZW2cU_s - 1:829118773643:android:54b65087c544d819 - AIzaSyAWIyOcLafaFp8PFL61h64cy1NNZW2cU_s - nextcloud-a7dea.appspot.com - nextcloud-a7dea - diff --git a/build.gradle b/build.gradle index 126dc410d..b3077052d 100644 --- a/build.gradle +++ b/build.gradle @@ -12,6 +12,9 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:3.0.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}" + if (getGradle().getStartParameter().getTaskRequests().toString().contains("GPlay")){ + classpath 'com.google.gms:google-services:3.1.0' + } // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files