diff options
author | Kamaljeet Maini <kmaini@cyngn.com> | 2016-03-29 15:46:54 -0700 |
---|---|---|
committer | Kamaljeet Maini <kmaini@cyngn.com> | 2016-04-01 13:02:18 -0700 |
commit | bae22333f9a241e14c8dda5532d8dbda1c5c79eb (patch) | |
tree | f32f12b0b1261829c910c4a84153e01349852881 /src/com/android/settings/DataUsageUtils.java | |
parent | c932de51d42a70989a9c93b5e6fd0fb7fcc82333 (diff) | |
download | packages_apps_Settings-bae22333f9a241e14c8dda5532d8dbda1c5c79eb.zip packages_apps_Settings-bae22333f9a241e14c8dda5532d8dbda1c5c79eb.tar.gz packages_apps_Settings-bae22333f9a241e14c8dda5532d8dbda1c5c79eb.tar.bz2 |
Settings app Data Usage UI enhancements
Modified Settings app to support following new features in
Data Usage Summary screen:
1) Added two items to overflow menu
a) Enable/disable data usage alerts: to enable/disable global
switch for data alerts. Shown only when DataUsage provider
is installed.
b) Reset data statistics: to reset data stats for current tab
2) Added a new per app switch "Mobile Data Alert"
3) Added a new per app switch "Restrict cellular data access"
4) Modified per app background data access feature to support
three options
a) Over mobile and WiFi
b) Only over WiFi
c) No access
DataUsage provider, service and notification receivers have been
refactored into a standalone package to minimize the changes to the
Settings App.
Change-Id: Ic0e42e57d04dc8e164ebfdab4531cced31c4e6eb
Issue-Id: SETTINGS-75
Issue-Id: SETTINGS-76
Issue-Id: SETTINGS-77
Issue-Id: SETTINGS-76
Diffstat (limited to 'src/com/android/settings/DataUsageUtils.java')
-rw-r--r-- | src/com/android/settings/DataUsageUtils.java | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/src/com/android/settings/DataUsageUtils.java b/src/com/android/settings/DataUsageUtils.java new file mode 100644 index 0000000..5f08067 --- /dev/null +++ b/src/com/android/settings/DataUsageUtils.java @@ -0,0 +1,121 @@ +package com.android.settings; + + +import android.app.AlarmManager; +import android.app.PendingIntent; +import android.content.ContentValues; +import android.content.Context; +import android.content.Intent; +import android.database.Cursor; +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 int DATAUSAGE_SERVICE_ALARM_ID = 0x102030; + private static boolean DEBUG = true; + + public static void addApp(Context context, int uid, String label) { + if (DEBUG) { + Log.v(TAG, "addApp: uid:" + uid + " label:" + label); + } + + ContentValues values = new ContentValues(); + + values.put(DataUsageContract.UID, uid); + values.put(DataUsageContract.LABEL, label); + + context.getContentResolver().insert( + DataUsageContract.CONTENT_URI, + values + ); + } + + public static void removeApp(Context context, int uid) { + if (DEBUG) { + Log.v(TAG, "removeApp: uid:" + uid); + } + context.getContentResolver().delete( + DataUsageContract.CONTENT_URI, + DataUsageContract.UID + " = ? ", + new String [] { String.valueOf(uid)} + ); + } + + public static void enableApp(Context context, int uid, boolean enable) { + enableApp(context, uid, enable, null); + } + + public static void enableApp(Context context, int uid, boolean enable, String label) { + if (DEBUG) { + Log.v(TAG, "enableApp: uid:" + uid + " enable:" + enable + + (label == null ? "" : " label:" + label)); + } + ContentValues values = new ContentValues(); + + values.put(DataUsageContract.ENABLE, enable); + values.put(DataUsageContract.ACTIVE, 0); + if (label != null) { + values.put(DataUsageContract.LABEL, label); + } + context.getContentResolver().update( + DataUsageContract.CONTENT_URI, + values, + DataUsageContract.UID + " = ? ", + new String [] { String.valueOf(uid)} + ); + } + + public static boolean isDbEnabled(Context context) { + boolean dbEnabled = false; + Cursor cursor = context.getContentResolver().query( + DataUsageContract.CONTENT_URI, + null, + DataUsageContract.UID + " = ? ", + new String [] { String.valueOf("0") }, + null + ); + + if (cursor != null) { + cursor.close(); + dbEnabled = true; + } + return dbEnabled; + } + + + public static boolean isAppEnabled(Context context, int uid) { + boolean appEnabled = false; + Cursor cursor = context.getContentResolver().query( + DataUsageContract.CONTENT_URI, + null, + DataUsageContract.UID + " = ? ", + new String [] { String.valueOf(uid) }, + null + ); + if (cursor != null) { + if (cursor.moveToFirst()) { + appEnabled = cursor.getInt(DataUsageContract.COLUMN_OF_ENABLE) == 1; + } + cursor.close(); + } + + if (DEBUG) { + Log.v(TAG, "isAppEnabled: uid:" + uid + " enabled:" + appEnabled); + } + + return appEnabled; + } + + public static void enableDataUsageService(Context context, boolean enable) { + Intent intent = new Intent(); + intent.setAction("org.cyanogenmod.providers.datausage.enable"); + intent.putExtra("enable", enable); + context.sendBroadcast(intent); + } +} |