From 50509026820601abec0f7f826cebcadb74c746dd Mon Sep 17 00:00:00 2001 From: "Chris J. Karr" Date: Sun, 13 Nov 2016 12:25:30 -0600 Subject: [PATCH 1/3] Cleaning up build.gradle and fixing code/config to pass lint tests --- build.gradle | 11 ++++++----- lint.xml | 1 + src/edu/northwestern/cbits/anthracite/Logger.java | 3 ++- .../northwestern/cbits/anthracite/PowerHelper.java | 8 +++++++- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index bbbbaa8..7e52021 100755 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,12 @@ +repositories { + jcenter() + maven { url "https://oss.sonatype.org/content/groups/public/" } +} + buildscript { repositories { jcenter() + maven { url "https://oss.sonatype.org/content/groups/public/" } } dependencies { @@ -8,11 +14,6 @@ buildscript { } } -repositories { - jcenter() - maven { url "https://oss.sonatype.org/content/groups/public/" } -} - apply plugin: 'com.android.library' android { diff --git a/lint.xml b/lint.xml index b4037be..0cad0cd 100644 --- a/lint.xml +++ b/lint.xml @@ -1,5 +1,6 @@ + diff --git a/src/edu/northwestern/cbits/anthracite/Logger.java b/src/edu/northwestern/cbits/anthracite/Logger.java index c3f1f19..44708c9 100755 --- a/src/edu/northwestern/cbits/anthracite/Logger.java +++ b/src/edu/northwestern/cbits/anthracite/Logger.java @@ -20,6 +20,7 @@ import android.Manifest; import android.accounts.Account; import android.accounts.AccountManager; +import android.annotation.SuppressLint; import android.app.AlarmManager; import android.app.PendingIntent; import android.content.ContentValues; @@ -162,7 +163,7 @@ public static Logger getInstance(Context context, String userId) return Logger._sharedInstance; } - @SuppressWarnings("unchecked") + @SuppressLint({"BadHostnameVerifier", "TrustAllX509TrustManager", "MissingPermission"}) public boolean log(String event, Map payload) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this._context); diff --git a/src/edu/northwestern/cbits/anthracite/PowerHelper.java b/src/edu/northwestern/cbits/anthracite/PowerHelper.java index 9fc839a..dc612da 100755 --- a/src/edu/northwestern/cbits/anthracite/PowerHelper.java +++ b/src/edu/northwestern/cbits/anthracite/PowerHelper.java @@ -4,6 +4,7 @@ import android.content.Intent; import android.content.IntentFilter; import android.os.BatteryManager; +import android.os.Build; public class PowerHelper { @@ -12,6 +13,11 @@ public static boolean isPluggedIn(Context context) Intent intent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1); - return plugged == BatteryManager.BATTERY_PLUGGED_AC || plugged == BatteryManager.BATTERY_PLUGGED_USB || plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS; + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + return plugged == BatteryManager.BATTERY_PLUGGED_AC || plugged == BatteryManager.BATTERY_PLUGGED_USB || plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS; + } + + return plugged == BatteryManager.BATTERY_PLUGGED_AC || plugged == BatteryManager.BATTERY_PLUGGED_USB; } } From 1c75d4a14249664fe31973603103a0226ed2189f Mon Sep 17 00:00:00 2001 From: "Chris J. Karr" Date: Tue, 15 Nov 2016 17:48:09 -0600 Subject: [PATCH 2/3] Addressing potential issue in ContextCompat.checkSelfPermissions observed elsewhere --- src/edu/northwestern/cbits/anthracite/Logger.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/edu/northwestern/cbits/anthracite/Logger.java b/src/edu/northwestern/cbits/anthracite/Logger.java index 44708c9..f96869b 100755 --- a/src/edu/northwestern/cbits/anthracite/Logger.java +++ b/src/edu/northwestern/cbits/anthracite/Logger.java @@ -203,7 +203,7 @@ public boolean log(String event, Map payload) { if (prefs.getBoolean(Logger.LOGGER_LOCATION_ENABLED, Logger.LOGGER_LOCATION_ENABLED_DEFAULT)) { - if (ContextCompat.checkSelfPermission(this._context, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(this._context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || (ContextCompat.checkSelfPermission(this._context, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(this._context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED)) { LocationManager lm = (LocationManager) this._context.getSystemService(Context.LOCATION_SERVICE); @@ -805,7 +805,7 @@ public static String getSystemUserId(Context context) { String userId = null; - if (ContextCompat.checkSelfPermission(context, "android.permissions.GET_ACCOUNTS") == PackageManager.PERMISSION_GRANTED) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || (ContextCompat.checkSelfPermission(context, "android.permissions.GET_ACCOUNTS") == PackageManager.PERMISSION_GRANTED)) { AccountManager manager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE); Account[] list = manager.getAccountsByType("com.google"); From dd1499d2b0fa7354cc24bad81bd5ad993315497d Mon Sep 17 00:00:00 2001 From: "Chris J. Karr" Date: Thu, 17 Nov 2016 12:59:24 -0600 Subject: [PATCH 3/3] Updating build requirements --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 7e52021..6b87ca1 100755 --- a/build.gradle +++ b/build.gradle @@ -34,7 +34,7 @@ android { buildToolsVersion '25.0.0' dependencies { - compile 'com.android.support:appcompat-v7:25.0.0' + compile 'com.android.support:appcompat-v7:25.0.1' compile 'com.squareup.okhttp3:okhttp:3.4.2' }