From 033e4dfdd2ac62c80c08c7a39685faf397c4fc6c Mon Sep 17 00:00:00 2001 From: Fredrik Fornwall Date: Tue, 28 Aug 2018 03:00:48 +0200 Subject: [PATCH] Cleanup some Android Studio lint warnings --- app/src/main/AndroidManifest.xml | 3 ++- .../java/com/termux/api/DialogActivity.java | 16 -------------- .../main/java/com/termux/api/DownloadAPI.java | 2 +- .../java/com/termux/api/FingerprintAPI.java | 21 ------------------- .../java/com/termux/api/MediaPlayerAPI.java | 16 +------------- .../java/com/termux/api/MicRecorderAPI.java | 3 --- .../java/com/termux/api/NotificationAPI.java | 5 ++--- .../com/termux/api/NotificationService.java | 3 +-- .../main/java/com/termux/api/PhotoAPI.java | 2 +- .../main/java/com/termux/api/SensorAPI.java | 11 +--------- .../main/java/com/termux/api/ShareAPI.java | 4 ++-- .../main/java/com/termux/api/SmsSendAPI.java | 2 +- .../java/com/termux/api/StorageGetAPI.java | 2 +- .../java/com/termux/api/TelephonyAPI.java | 2 ++ .../java/com/termux/api/TextToSpeechAPI.java | 2 +- .../main/java/com/termux/api/ToastAPI.java | 8 +++---- .../main/java/com/termux/api/VolumeAPI.java | 20 +----------------- app/src/main/java/com/termux/api/WifiAPI.java | 4 +++- 18 files changed, 24 insertions(+), 102 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ef049326..497e51d4 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -48,7 +48,8 @@ android:roundIcon="@mipmap/ic_launcher_round" android:label="@string/app_name" android:supportsRtl="true" - android:theme="@android:style/Theme.Material.Light" > + android:theme="@android:style/Theme.Material.Light" + tools:ignore="GoogleAppIndexingWarning"> getSensorsToListenTo(SensorManager sensorManager, String[] requestedSensors, Intent intent) { List availableSensors = sensorManager.getSensorList(Sensor.TYPE_ALL); @@ -320,8 +313,6 @@ protected static void clearSensorValues() { /** * Creates SensorOutputWriter to write sensor values to stdout - * @param intent - * @return */ protected static SensorOutputWriter createSensorOutputWriter(Intent intent) { String socketAddress = intent.getStringExtra("socket_output"); diff --git a/app/src/main/java/com/termux/api/ShareAPI.java b/app/src/main/java/com/termux/api/ShareAPI.java index 808b9da9..de111174 100644 --- a/app/src/main/java/com/termux/api/ShareAPI.java +++ b/app/src/main/java/com/termux/api/ShareAPI.java @@ -52,7 +52,7 @@ static void onReceive(TermuxApiReceiver apiReceiver, final Context context, fina // Read text to share from stdin. ResultReturner.returnData(apiReceiver, intent, new ResultReturner.WithStringInput() { @Override - public void writeResult(PrintWriter out) throws Exception { + public void writeResult(PrintWriter out) { if (TextUtils.isEmpty(inputString)) { out.println("Error: Nothing to share"); return; @@ -74,7 +74,7 @@ public void writeResult(PrintWriter out) throws Exception { // Share specified file. ResultReturner.returnData(apiReceiver, intent, new ResultReturner.ResultWriter() { @Override - public void writeResult(PrintWriter out) throws Exception { + public void writeResult(PrintWriter out) { final File fileToShare = new File(fileExtra); if (!(fileToShare.isFile() && fileToShare.canRead())) { out.println("ERROR: Not a readable file: '" + fileToShare.getAbsolutePath() + "'"); diff --git a/app/src/main/java/com/termux/api/SmsSendAPI.java b/app/src/main/java/com/termux/api/SmsSendAPI.java index cf1f5d00..0b5bf246 100644 --- a/app/src/main/java/com/termux/api/SmsSendAPI.java +++ b/app/src/main/java/com/termux/api/SmsSendAPI.java @@ -14,7 +14,7 @@ public class SmsSendAPI { static void onReceive(TermuxApiReceiver apiReceiver, final Intent intent) { ResultReturner.returnData(apiReceiver, intent, new ResultReturner.WithStringInput() { @Override - public void writeResult(PrintWriter out) throws Exception { + public void writeResult(PrintWriter out) { final SmsManager smsManager = SmsManager.getDefault(); String[] recipients = intent.getStringArrayExtra("recipients"); diff --git a/app/src/main/java/com/termux/api/StorageGetAPI.java b/app/src/main/java/com/termux/api/StorageGetAPI.java index b139bbb0..b9c182db 100644 --- a/app/src/main/java/com/termux/api/StorageGetAPI.java +++ b/app/src/main/java/com/termux/api/StorageGetAPI.java @@ -22,7 +22,7 @@ public class StorageGetAPI { static void onReceive(TermuxApiReceiver apiReceiver, final Context context, final Intent intent) { ResultReturner.returnData(apiReceiver, intent, new ResultReturner.ResultWriter() { @Override - public void writeResult(PrintWriter out) throws Exception { + public void writeResult(PrintWriter out) { final String fileExtra = intent.getStringExtra("file"); if (fileExtra == null || !new File(fileExtra).getParentFile().canWrite()) { out.println("ERROR: Not a writable folder: " + fileExtra); diff --git a/app/src/main/java/com/termux/api/TelephonyAPI.java b/app/src/main/java/com/termux/api/TelephonyAPI.java index 17677590..6a998c32 100644 --- a/app/src/main/java/com/termux/api/TelephonyAPI.java +++ b/app/src/main/java/com/termux/api/TelephonyAPI.java @@ -1,5 +1,6 @@ package com.termux.api; +import android.annotation.SuppressLint; import android.content.Context; import android.content.Intent; import android.net.Uri; @@ -110,6 +111,7 @@ public void writeJson(JsonWriter out) throws Exception { static void onReceiveTelephonyDeviceInfo(TermuxApiReceiver apiReceiver, final Context context, final Intent intent) { ResultReturner.returnData(apiReceiver, intent, new ResultReturner.ResultJsonWriter() { + @SuppressLint("HardwareIds") @Override public void writeJson(JsonWriter out) throws Exception { TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); diff --git a/app/src/main/java/com/termux/api/TextToSpeechAPI.java b/app/src/main/java/com/termux/api/TextToSpeechAPI.java index 03fed9aa..452eb529 100644 --- a/app/src/main/java/com/termux/api/TextToSpeechAPI.java +++ b/app/src/main/java/com/termux/api/TextToSpeechAPI.java @@ -94,7 +94,7 @@ public void onInit(int status) { ResultReturner.returnData(this, intent, new ResultReturner.WithInput() { @Override - public void writeResult(PrintWriter out) throws Exception { + public void writeResult(PrintWriter out) { try { try { diff --git a/app/src/main/java/com/termux/api/ToastAPI.java b/app/src/main/java/com/termux/api/ToastAPI.java index 5ea81c06..6b149410 100644 --- a/app/src/main/java/com/termux/api/ToastAPI.java +++ b/app/src/main/java/com/termux/api/ToastAPI.java @@ -21,13 +21,13 @@ public static void onReceive(final Context context, Intent intent) { final int durationExtra = intent.getBooleanExtra("short", false) ? Toast.LENGTH_SHORT : Toast.LENGTH_LONG; final int backgroundColor = getColorExtra(intent, "background", Color.GRAY); final int textColor = getColorExtra(intent, "text_color", Color.WHITE); - final int gravity = getGravityExtra(intent, Gravity.CENTER); + final int gravity = getGravityExtra(intent); final Handler handler = new Handler(); ResultReturner.returnData(context, intent, new ResultReturner.WithStringInput() { @Override - public void writeResult(PrintWriter out) throws Exception { + public void writeResult(PrintWriter out) { handler.post(new Runnable() { @Override public void run() { @@ -63,14 +63,14 @@ protected static int getColorExtra(Intent intent, String extra, int defaultColor return color; } - protected static int getGravityExtra(Intent intent, int defaultGravity) { + protected static int getGravityExtra(Intent intent) { String extraGravity = intent.getStringExtra("gravity"); switch (extraGravity == null ? "" : extraGravity) { case "top": return Gravity.TOP; case "middle": return Gravity.CENTER; case "bottom": return Gravity.BOTTOM; - default: return defaultGravity; + default: return Gravity.CENTER; } } diff --git a/app/src/main/java/com/termux/api/VolumeAPI.java b/app/src/main/java/com/termux/api/VolumeAPI.java index b0903c43..a9a4bec9 100644 --- a/app/src/main/java/com/termux/api/VolumeAPI.java +++ b/app/src/main/java/com/termux/api/VolumeAPI.java @@ -48,14 +48,11 @@ static void onReceive(final TermuxApiReceiver receiver, final Context context, f /** * Prints error to console - * @param context - * @param intent - * @param error */ private static void printError(Context context, Intent intent, final String error) { ResultReturner.returnData(context, intent, new ResultReturner.ResultWriter() { @Override - public void writeResult(PrintWriter out) throws Exception { + public void writeResult(PrintWriter out) { out.append(error + "\n"); out.flush(); out.close(); @@ -65,9 +62,6 @@ public void writeResult(PrintWriter out) throws Exception { /** * Set volume for the specified audio stream - * @param intent - * @param audioManager - * @param stream */ private static void setStreamVolume(Intent intent, AudioManager audioManager, int stream) { int volume = intent.getIntExtra("volume", audioManager.getStreamVolume(stream)); @@ -83,9 +77,6 @@ private static void setStreamVolume(Intent intent, AudioManager audioManager, in /** * Print information about all available audio streams - * @param context - * @param intent - * @param audioManager */ private static void printAllStreamInfo(Context context, Intent intent, final AudioManager audioManager) { ResultReturner.returnData(context, intent, new ResultReturner.ResultJsonWriter() { @@ -99,9 +90,6 @@ public void writeJson(JsonWriter out) throws Exception { /** * Get info for all streams - * @param audioManager - * @param out - * @throws IOException */ private static void getStreamsInfo(AudioManager audioManager, JsonWriter out) throws IOException { out.beginArray(); @@ -115,10 +103,6 @@ private static void getStreamsInfo(AudioManager audioManager, JsonWriter out) th /** * Get info for specific stream - * @param audioManager - * @param out - * @param stream - * @throws IOException */ protected static void getStreamInfo(AudioManager audioManager, JsonWriter out, int stream) throws IOException { out.beginObject(); @@ -132,8 +116,6 @@ protected static void getStreamInfo(AudioManager audioManager, JsonWriter out, i /** * Get proper audio stream based on String type - * @param type - * @return */ protected static int getAudioStream(String type) { switch (type == null ? "" : type) { diff --git a/app/src/main/java/com/termux/api/WifiAPI.java b/app/src/main/java/com/termux/api/WifiAPI.java index 37c77436..8efe3dfa 100644 --- a/app/src/main/java/com/termux/api/WifiAPI.java +++ b/app/src/main/java/com/termux/api/WifiAPI.java @@ -1,5 +1,6 @@ package com.termux.api; +import android.annotation.SuppressLint; import android.content.Context; import android.content.Intent; import android.location.LocationManager; @@ -19,6 +20,7 @@ public class WifiAPI { static void onReceiveWifiConnectionInfo(TermuxApiReceiver apiReceiver, final Context context, final Intent intent) { ResultReturner.returnData(apiReceiver, intent, new ResultReturner.ResultJsonWriter() { + @SuppressLint("HardwareIds") @Override public void writeJson(JsonWriter out) throws Exception { WifiManager manager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE); @@ -35,7 +37,7 @@ public void writeJson(JsonWriter out) throws Exception { out.name("mac_address").value(info.getMacAddress()); out.name("network_id").value(info.getNetworkId()); out.name("rssi").value(info.getRssi()); - out.name("ssid").value(info.getSSID().replaceAll("\\\"", "")); + out.name("ssid").value(info.getSSID().replaceAll("\"", "")); out.name("ssid_hidden").value(info.getHiddenSSID()); out.name("supplicant_state").value(info.getSupplicantState().toString()); }