Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
audaciouscode committed Dec 4, 2016
2 parents f2e7035 + dd1499d commit a67a29f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
11 changes: 6 additions & 5 deletions build.gradle
@@ -1,18 +1,19 @@
repositories {
jcenter()
maven { url "https://oss.sonatype.org/content/groups/public/" }
}

buildscript {
repositories {
jcenter()
maven { url "https://oss.sonatype.org/content/groups/public/" }
}

dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
}
}

repositories {
jcenter()
maven { url "https://oss.sonatype.org/content/groups/public/" }
}

apply plugin: 'com.android.library'

android {
Expand Down
1 change: 1 addition & 0 deletions lint.xml
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<lint>
<issue id="MissingPermission" severity="warning" />
<issue id="InvalidPackage" severity="warning" />
</lint>

7 changes: 4 additions & 3 deletions src/edu/northwestern/cbits/anthracite/Logger.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, Object> payload)
{
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this._context);
Expand Down Expand Up @@ -202,7 +203,7 @@ public boolean log(String event, Map<String, Object> 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);

Expand Down Expand Up @@ -804,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");

Expand Down
8 changes: 7 additions & 1 deletion src/edu/northwestern/cbits/anthracite/PowerHelper.java
Expand Up @@ -4,6 +4,7 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.os.BatteryManager;
import android.os.Build;

public class PowerHelper
{
Expand All @@ -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;
}
}

0 comments on commit a67a29f

Please sign in to comment.