summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTyler Dunn <ireallylikeshrek@gmail.com>2016-10-31 23:37:36 -0400
committerTyler Dunn <ireallylikeshrek@gmail.com>2016-11-24 22:47:04 -0800
commit630dfa8a5381368b50bca48a87b8b422c02074c8 (patch)
tree20cd20824cc58e2db38570196357066a251c2a2a
parentc2da9ad6a331c6a6f5b8c56ecf5c716ab08f4d21 (diff)
downloadpackages_apps_Settings-630dfa8a5381368b50bca48a87b8b422c02074c8.zip
packages_apps_Settings-630dfa8a5381368b50bca48a87b8b422c02074c8.tar.gz
packages_apps_Settings-630dfa8a5381368b50bca48a87b8b422c02074c8.tar.bz2
DataUsageUtils: Clean up based on code review
* Add missing header * Extract DataUsageContract.UID + " = ? " into a string * Simplify "0" string * Use try-with-resource block to ensure cursor is closed This commit is based on the post-merge feedback of Kamaljeet Maini, Fabrice Di Meglio and Danny Baumann. Change-Id: I774948ba119e3e4a2dd438e1ed1588bfb9fefae2
-rw-r--r--src/com/android/settings/DataUsageUtils.java50
1 files changed, 29 insertions, 21 deletions
diff --git a/src/com/android/settings/DataUsageUtils.java b/src/com/android/settings/DataUsageUtils.java
index 5f08067..09b6b10 100644
--- a/src/com/android/settings/DataUsageUtils.java
+++ b/src/com/android/settings/DataUsageUtils.java
@@ -1,5 +1,20 @@
-package com.android.settings;
+/*
+ * Copyright (C) 2016 The CyanogenMod project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings;
import android.app.AlarmManager;
import android.app.PendingIntent;
@@ -11,12 +26,12 @@ import android.util.Log;
import cyanogenmod.providers.DataUsageContract;
-
/**
* This class contains utility helper functions for accessing DataUsageProvider
*/
public class DataUsageUtils {
private static final String TAG = DataUsageUtils.class.getSimpleName();
+ private static final String WHERE_CLAUSE = DataUsageContract.UID + " = ? ";
private static final int DATAUSAGE_SERVICE_ALARM_ID = 0x102030;
private static boolean DEBUG = true;
@@ -42,8 +57,8 @@ public class DataUsageUtils {
}
context.getContentResolver().delete(
DataUsageContract.CONTENT_URI,
- DataUsageContract.UID + " = ? ",
- new String [] { String.valueOf(uid)}
+ WHERE_CLAUSE,
+ new String [] { String.valueOf(uid) }
);
}
@@ -66,43 +81,36 @@ public class DataUsageUtils {
context.getContentResolver().update(
DataUsageContract.CONTENT_URI,
values,
- DataUsageContract.UID + " = ? ",
- new String [] { String.valueOf(uid)}
+ WHERE_CLAUSE,
+ new String [] { String.valueOf(uid) }
);
}
public static boolean isDbEnabled(Context context) {
boolean dbEnabled = false;
- Cursor cursor = context.getContentResolver().query(
+ try (Cursor cursor = context.getContentResolver().query(
DataUsageContract.CONTENT_URI,
null,
- DataUsageContract.UID + " = ? ",
- new String [] { String.valueOf("0") },
- null
- );
-
- if (cursor != null) {
- cursor.close();
+ WHERE_CLAUSE,
+ new String [] { "0" },
+ null)) {
dbEnabled = true;
}
return dbEnabled;
}
-
public static boolean isAppEnabled(Context context, int uid) {
boolean appEnabled = false;
- Cursor cursor = context.getContentResolver().query(
+
+ try (Cursor cursor = context.getContentResolver().query(
DataUsageContract.CONTENT_URI,
null,
- DataUsageContract.UID + " = ? ",
+ WHERE_CLAUSE,
new String [] { String.valueOf(uid) },
- null
- );
- if (cursor != null) {
+ null)) {
if (cursor.moveToFirst()) {
appEnabled = cursor.getInt(DataUsageContract.COLUMN_OF_ENABLE) == 1;
}
- cursor.close();
}
if (DEBUG) {