From 72f5544fa64239ea35b2f78b5ed663414533854c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20Wr=C3=B3tniak?= Date: Mon, 3 Feb 2020 20:36:49 +0100 Subject: [PATCH] Fix lint errors Bump Gradle to 6.1.1 Bump build tools to 29.0.3 --- app/build.gradle | 3 +- .../stf/monitor/BrowserPackageMonitor.java | 2 +- .../stf/query/GetPropertiesResponder.java | 42 +++++++++++-------- .../stf/query/GetWifiStatusResponder.java | 2 +- .../stf/query/SetKeyguardStateResponder.java | 2 +- .../stf/query/SetWakeLockResponder.java | 2 +- .../cyberagent/stf/query/StringCallable.java | 6 +++ build.gradle | 1 + gradle/wrapper/gradle-wrapper.properties | 2 +- 9 files changed, 39 insertions(+), 23 deletions(-) create mode 100644 app/src/main/java/jp/co/cyberagent/stf/query/StringCallable.java diff --git a/app/build.gradle b/app/build.gradle index 244641e..06fbeaa 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,7 +12,7 @@ buildscript { android { compileSdkVersion 29 - buildToolsVersion "29.0.2" + buildToolsVersion "29.0.3" signingConfigs { debug { @@ -49,6 +49,7 @@ android { dependencies { //TODO consider migrating to androidx + //noinspection GradleCompatible implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.google.protobuf:protobuf-lite:3.0.1' implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar']) diff --git a/app/src/main/java/jp/co/cyberagent/stf/monitor/BrowserPackageMonitor.java b/app/src/main/java/jp/co/cyberagent/stf/monitor/BrowserPackageMonitor.java index 87be2a3..8ed7396 100644 --- a/app/src/main/java/jp/co/cyberagent/stf/monitor/BrowserPackageMonitor.java +++ b/app/src/main/java/jp/co/cyberagent/stf/monitor/BrowserPackageMonitor.java @@ -19,7 +19,7 @@ import jp.co.cyberagent.stf.util.BrowserUtil; public class BrowserPackageMonitor extends AbstractMonitor { - private static final String TAG = "STFBrowserPackageMonitor"; + private static final String TAG = "STFBrowserPkgMonitor"; private Set browsers = new HashSet(); diff --git a/app/src/main/java/jp/co/cyberagent/stf/query/GetPropertiesResponder.java b/app/src/main/java/jp/co/cyberagent/stf/query/GetPropertiesResponder.java index 6cb40f6..8cad2a9 100644 --- a/app/src/main/java/jp/co/cyberagent/stf/query/GetPropertiesResponder.java +++ b/app/src/main/java/jp/co/cyberagent/stf/query/GetPropertiesResponder.java @@ -1,6 +1,7 @@ package jp.co.cyberagent.stf.query; import android.content.Context; +import android.os.Build; import android.telephony.TelephonyManager; import android.text.TextUtils; import android.util.Log; @@ -23,31 +24,31 @@ public GetPropertiesResponder(Context context) { @Override public GeneratedMessageLite respond(Wire.Envelope envelope) throws InvalidProtocolBufferException { Wire.GetPropertiesRequest request = - Wire.GetPropertiesRequest.parseFrom(envelope.getMessage()); + Wire.GetPropertiesRequest.parseFrom(envelope.getMessage()); ArrayList properties = new ArrayList(); TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); for (String name : request.getPropertiesList()) { - String value=null; + String value = null; try { - switch(name) { + switch (name) { case "imei": - value = tm.getDeviceId(); + value = getValueOrNull(tm::getDeviceId); break; case "imsi": - value = tm.getSubscriberId(); + value = getValueOrNull(tm::getSubscriberId); break; case "phonenumber": value = tm.getLine1Number(); break; case "iccid": - value = tm.getSimSerialNumber(); + value = getValueOrNull(tm::getSimSerialNumber); break; case "operator": - if(tm.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA) { + if (tm.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA) { value = tm.getSimOperatorName(); - }else { + } else { value = tm.getNetworkOperatorName(); if (TextUtils.isEmpty(value)) { value = tm.getSimOperatorName(); @@ -63,12 +64,12 @@ public GeneratedMessageLite respond(Wire.Envelope envelope) throws InvalidProtoc } if (!TextUtils.isEmpty(value)) { properties.add(Wire.Property.newBuilder() - .setName(name) - .setValue(value) - .build()); + .setName(name) + .setValue(value) + .build()); } - } catch(SecurityException e ) { - Log.d(TAG,"Security exception trying to retrieve "+name); + } catch (SecurityException e) { + Log.d(TAG, "Security exception trying to retrieve " + name); } } @@ -76,13 +77,20 @@ public GeneratedMessageLite respond(Wire.Envelope envelope) throws InvalidProtoc .setId(envelope.getId()) .setType(Wire.MessageType.GET_PROPERTIES) .setMessage(Wire.GetPropertiesResponse.newBuilder() - .setSuccess(true) - .addAllProperties(properties) - .build() - .toByteString()) + .setSuccess(true) + .addAllProperties(properties) + .build() + .toByteString()) .build(); } + private static String getValueOrNull(StringCallable callable) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + return null; + } + return callable.call(); + } + @Override public void cleanup() { // No-op diff --git a/app/src/main/java/jp/co/cyberagent/stf/query/GetWifiStatusResponder.java b/app/src/main/java/jp/co/cyberagent/stf/query/GetWifiStatusResponder.java index f26c0a4..d9b2141 100644 --- a/app/src/main/java/jp/co/cyberagent/stf/query/GetWifiStatusResponder.java +++ b/app/src/main/java/jp/co/cyberagent/stf/query/GetWifiStatusResponder.java @@ -18,7 +18,7 @@ public GeneratedMessageLite respond(Wire.Envelope envelope) throws InvalidProtoc Wire.GetWifiStatusRequest request = Wire.GetWifiStatusRequest.parseFrom(envelope.getMessage()); - WifiManager wm = (WifiManager)context.getSystemService(Context.WIFI_SERVICE); + WifiManager wm = (WifiManager)context.getApplicationContext().getSystemService(Context.WIFI_SERVICE); return Wire.Envelope.newBuilder() .setId(envelope.getId()) diff --git a/app/src/main/java/jp/co/cyberagent/stf/query/SetKeyguardStateResponder.java b/app/src/main/java/jp/co/cyberagent/stf/query/SetKeyguardStateResponder.java index 7778a93..0b39691 100644 --- a/app/src/main/java/jp/co/cyberagent/stf/query/SetKeyguardStateResponder.java +++ b/app/src/main/java/jp/co/cyberagent/stf/query/SetKeyguardStateResponder.java @@ -10,7 +10,7 @@ import jp.co.cyberagent.stf.proto.Wire; public class SetKeyguardStateResponder extends AbstractResponder { - private static final String TAG = "STFKeyguardStateResponder"; + private static final String TAG = "STFKeyguardStateResp"; private KeyguardManager.KeyguardLock lock; diff --git a/app/src/main/java/jp/co/cyberagent/stf/query/SetWakeLockResponder.java b/app/src/main/java/jp/co/cyberagent/stf/query/SetWakeLockResponder.java index d2457bd..acd7168 100644 --- a/app/src/main/java/jp/co/cyberagent/stf/query/SetWakeLockResponder.java +++ b/app/src/main/java/jp/co/cyberagent/stf/query/SetWakeLockResponder.java @@ -52,7 +52,7 @@ private void acquireWakeLock() { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock( PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, - "STFService" + "STF:STFService" ); wakeLock.acquire(); } diff --git a/app/src/main/java/jp/co/cyberagent/stf/query/StringCallable.java b/app/src/main/java/jp/co/cyberagent/stf/query/StringCallable.java new file mode 100644 index 0000000..e8b3fa4 --- /dev/null +++ b/app/src/main/java/jp/co/cyberagent/stf/query/StringCallable.java @@ -0,0 +1,6 @@ +package jp.co.cyberagent.stf.query; + +@FunctionalInterface +interface StringCallable { + String call(); +} diff --git a/build.gradle b/build.gradle index 4c83eda..a98124b 100644 --- a/build.gradle +++ b/build.gradle @@ -15,6 +15,7 @@ allprojects { repositories { mavenCentral() google() + jcenter() } tasks.withType(JavaCompile) { diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 208e233..7e07a46 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-5.1.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip