use of android.net.NetworkTemplate in project platform_frameworks_base by android.
the class NetworkStatsManager method queryDetails.
/**
* Query network usage statistics details. Result filtered to include only uids belonging to
* calling user. Result is aggregated over state but not aggregated over time, uid, tag,
* metered, nor roaming. This means buckets' start and end timestamps are going to be between
* 'startTime' and 'endTime' parameters. State is going to be
* {@link NetworkStats.Bucket#STATE_ALL}, uid will vary,
* tag {@link NetworkStats.Bucket#TAG_NONE}, metered is going to be
* {@link NetworkStats.Bucket#METERED_ALL}, and roaming is going to be
* {@link NetworkStats.Bucket#ROAMING_ALL}.
* <p>Only includes buckets that atomically occur in the inclusive time range. Doesn't
* interpolate across partial buckets. Since bucket length is in the order of hours, this
* method cannot be used to measure data usage on a fine grained time scale.
*
* @param networkType As defined in {@link ConnectivityManager}, e.g.
* {@link ConnectivityManager#TYPE_MOBILE}, {@link ConnectivityManager#TYPE_WIFI}
* etc.
* @param subscriberId If applicable, the subscriber id of the network interface.
* @param startTime Start of period. Defined in terms of "Unix time", see
* {@link java.lang.System#currentTimeMillis}.
* @param endTime End of period. Defined in terms of "Unix time", see
* {@link java.lang.System#currentTimeMillis}.
* @return Statistics object or null if permissions are insufficient or error happened during
* statistics collection.
*/
public NetworkStats queryDetails(int networkType, String subscriberId, long startTime, long endTime) throws SecurityException, RemoteException {
NetworkTemplate template;
try {
template = createTemplate(networkType, subscriberId);
} catch (IllegalArgumentException e) {
if (DBG)
Log.e(TAG, "Cannot create template", e);
return null;
}
NetworkStats result;
result = new NetworkStats(mContext, template, startTime, endTime);
result.startUserUidEnumeration();
return result;
}
use of android.net.NetworkTemplate in project platform_frameworks_base by android.
the class ChartDataLoader method loadInBackground.
@Override
public ChartData loadInBackground() {
final NetworkTemplate template = mArgs.getParcelable(KEY_TEMPLATE);
final AppItem app = mArgs.getParcelable(KEY_APP);
final int fields = mArgs.getInt(KEY_FIELDS);
try {
return loadInBackground(template, app, fields);
} catch (RemoteException e) {
// leave with half-baked UI, we bail hard.
throw new RuntimeException("problem reading network stats", e);
}
}
use of android.net.NetworkTemplate in project platform_frameworks_base by android.
the class SummaryForAllUidLoader method loadInBackground.
@Override
public NetworkStats loadInBackground() {
final NetworkTemplate template = mArgs.getParcelable(KEY_TEMPLATE);
final long start = mArgs.getLong(KEY_START);
final long end = mArgs.getLong(KEY_END);
try {
return mSession.getSummaryForAllUid(template, start, end, false);
} catch (RemoteException e) {
return null;
}
}
use of android.net.NetworkTemplate in project platform_frameworks_base by android.
the class NetworkPolicyEditor method setPolicyMetered.
public void setPolicyMetered(NetworkTemplate template, boolean metered) {
boolean modified = false;
NetworkPolicy policy = getPolicy(template);
if (metered) {
if (policy == null) {
policy = buildDefaultPolicy(template);
policy.metered = true;
policy.inferred = false;
mPolicies.add(policy);
modified = true;
} else if (!policy.metered) {
policy.metered = true;
policy.inferred = false;
modified = true;
}
} else {
if (policy == null) {
// ignore when policy doesn't exist
} else if (policy.metered) {
policy.metered = false;
policy.inferred = false;
modified = true;
}
}
// Remove legacy unquoted policies while we're here
final NetworkTemplate unquoted = buildUnquotedNetworkTemplate(template);
final NetworkPolicy unquotedPolicy = getPolicy(unquoted);
if (unquotedPolicy != null) {
mPolicies.remove(unquotedPolicy);
modified = true;
}
if (modified)
writeAsync();
}
use of android.net.NetworkTemplate in project platform_frameworks_base by android.
the class NetworkOverLimitActivity method onCreate.
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
final NetworkTemplate template = getIntent().getParcelableExtra(EXTRA_NETWORK_TEMPLATE);
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getLimitedDialogTitleForTemplate(template));
builder.setMessage(R.string.data_usage_disabled_dialog);
builder.setPositiveButton(android.R.string.ok, null);
builder.setNegativeButton(R.string.data_usage_disabled_dialog_enable, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
snoozePolicy(template);
}
});
final Dialog dialog = builder.create();
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
public void onDismiss(DialogInterface dialog) {
finish();
}
});
dialog.show();
}
Aggregations