Search in sources :

Example 86 with NetworkTemplate

use of android.net.NetworkTemplate in project android_frameworks_base by AOSPA.

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();
}
Also used : AlertDialog(android.app.AlertDialog) NetworkTemplate(android.net.NetworkTemplate) DialogInterface(android.content.DialogInterface) Dialog(android.app.Dialog) AlertDialog(android.app.AlertDialog)

Example 87 with NetworkTemplate

use of android.net.NetworkTemplate in project android_frameworks_base by AOSPA.

the class NetworkStatsService method createSession.

private INetworkStatsSession createSession(final String callingPackage, boolean pollOnCreate) {
    assertBandwidthControlEnabled();
    if (pollOnCreate) {
        final long ident = Binder.clearCallingIdentity();
        try {
            performPoll(FLAG_PERSIST_ALL);
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
    }
    return new INetworkStatsSession.Stub() {

        private NetworkStatsCollection mUidComplete;

        private NetworkStatsCollection mUidTagComplete;

        private String mCallingPackage = callingPackage;

        private NetworkStatsCollection getUidComplete() {
            synchronized (mStatsLock) {
                if (mUidComplete == null) {
                    mUidComplete = mUidRecorder.getOrLoadCompleteLocked();
                }
                return mUidComplete;
            }
        }

        private NetworkStatsCollection getUidTagComplete() {
            synchronized (mStatsLock) {
                if (mUidTagComplete == null) {
                    mUidTagComplete = mUidTagRecorder.getOrLoadCompleteLocked();
                }
                return mUidTagComplete;
            }
        }

        @Override
        public int[] getRelevantUids() {
            return getUidComplete().getRelevantUids(checkAccessLevel(mCallingPackage));
        }

        @Override
        public NetworkStats getDeviceSummaryForNetwork(NetworkTemplate template, long start, long end) {
            @NetworkStatsAccess.Level int accessLevel = checkAccessLevel(mCallingPackage);
            if (accessLevel < NetworkStatsAccess.Level.DEVICESUMMARY) {
                throw new SecurityException("Calling package " + mCallingPackage + " cannot access device summary network stats");
            }
            NetworkStats result = new NetworkStats(end - start, 1);
            final long ident = Binder.clearCallingIdentity();
            try {
                // Using access level higher than the one we checked for above.
                // Reason is that we are combining usage data in a way that is not PII
                // anymore.
                result.combineAllValues(internalGetSummaryForNetwork(template, start, end, NetworkStatsAccess.Level.DEVICE));
            } finally {
                Binder.restoreCallingIdentity(ident);
            }
            return result;
        }

        @Override
        public NetworkStats getSummaryForNetwork(NetworkTemplate template, long start, long end) {
            @NetworkStatsAccess.Level int accessLevel = checkAccessLevel(mCallingPackage);
            return internalGetSummaryForNetwork(template, start, end, accessLevel);
        }

        @Override
        public NetworkStatsHistory getHistoryForNetwork(NetworkTemplate template, int fields) {
            @NetworkStatsAccess.Level int accessLevel = checkAccessLevel(mCallingPackage);
            return internalGetHistoryForNetwork(template, fields, accessLevel);
        }

        @Override
        public NetworkStats getSummaryForAllUid(NetworkTemplate template, long start, long end, boolean includeTags) {
            @NetworkStatsAccess.Level int accessLevel = checkAccessLevel(mCallingPackage);
            final NetworkStats stats = getUidComplete().getSummary(template, start, end, accessLevel);
            if (includeTags) {
                final NetworkStats tagStats = getUidTagComplete().getSummary(template, start, end, accessLevel);
                stats.combineAllValues(tagStats);
            }
            return stats;
        }

        @Override
        public NetworkStatsHistory getHistoryForUid(NetworkTemplate template, int uid, int set, int tag, int fields) {
            @NetworkStatsAccess.Level int accessLevel = checkAccessLevel(mCallingPackage);
            if (tag == TAG_NONE) {
                return getUidComplete().getHistory(template, uid, set, tag, fields, accessLevel);
            } else {
                return getUidTagComplete().getHistory(template, uid, set, tag, fields, accessLevel);
            }
        }

        @Override
        public NetworkStatsHistory getHistoryIntervalForUid(NetworkTemplate template, int uid, int set, int tag, int fields, long start, long end) {
            @NetworkStatsAccess.Level int accessLevel = checkAccessLevel(mCallingPackage);
            if (tag == TAG_NONE) {
                return getUidComplete().getHistory(template, uid, set, tag, fields, start, end, accessLevel);
            } else if (uid == Binder.getCallingUid()) {
                return getUidTagComplete().getHistory(template, uid, set, tag, fields, start, end, accessLevel);
            } else {
                throw new SecurityException("Calling package " + mCallingPackage + " cannot access tag information from a different uid");
            }
        }

        @Override
        public void close() {
            mUidComplete = null;
            mUidTagComplete = null;
        }
    };
}
Also used : NetworkTemplate(android.net.NetworkTemplate) NetworkStats(android.net.NetworkStats)

Example 88 with NetworkTemplate

use of android.net.NetworkTemplate in project android_frameworks_base by AOSPA.

the class NetworkStatsManager method querySummaryForUser.

/**
     * Query network usage statistics summaries. Result is summarised data usage for all uids
     * belonging to calling user. Result is a single Bucket aggregated over time, state and uid.
     * This means the bucket's start and end timestamp are going to be the same as the 'startTime'
     * and 'endTime' parameters, state is going to be {@link NetworkStats.Bucket#STATE_ALL} and uid
     * {@link NetworkStats.Bucket#UID_ALL}.
     *
     * @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 Bucket object or null if permissions are insufficient or error happened during
     *         statistics collection.
     */
public Bucket querySummaryForUser(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 stats;
    stats = new NetworkStats(mContext, template, startTime, endTime);
    stats.startSummaryEnumeration();
    stats.close();
    return stats.getSummaryAggregate();
}
Also used : NetworkTemplate(android.net.NetworkTemplate)

Example 89 with NetworkTemplate

use of android.net.NetworkTemplate in project android_frameworks_base by AOSPA.

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 or uid. 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} 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;
}
Also used : NetworkTemplate(android.net.NetworkTemplate)

Example 90 with NetworkTemplate

use of android.net.NetworkTemplate in project android_frameworks_base by AOSPA.

the class NetworkStatsManager method querySummary.

/**
     * Query network usage statistics summaries. Result filtered to include only uids belonging to
     * calling user. Result is aggregated over time, hence all buckets will have the same start and
     * end timestamps. Not aggregated over state or uid. This means buckets' start and end
     * timestamps are going to be the same as the 'startTime' and 'endTime' parameters.
     * State and uid are going to vary, and tag is going to be the same.
     *
     * @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 querySummary(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.startSummaryEnumeration();
    return result;
}
Also used : NetworkTemplate(android.net.NetworkTemplate)

Aggregations

NetworkTemplate (android.net.NetworkTemplate)111 NetworkPolicy (android.net.NetworkPolicy)33 RemoteException (android.os.RemoteException)21 NetworkPolicyManager.uidRulesToString (android.net.NetworkPolicyManager.uidRulesToString)15 NetworkStats (android.net.NetworkStats)12 IOException (java.io.IOException)12 AlertDialog (android.app.AlertDialog)6 Dialog (android.app.Dialog)6 DialogInterface (android.content.DialogInterface)6 NetworkIdentity (android.net.NetworkIdentity)6 Time (android.text.format.Time)6 NtpTrustedTime (android.util.NtpTrustedTime)6 TrustedTime (android.util.TrustedTime)6 FastXmlSerializer (com.android.internal.util.FastXmlSerializer)6 AppItem (com.android.settingslib.AppItem)6 FileInputStream (java.io.FileInputStream)6 FileNotFoundException (java.io.FileNotFoundException)6 FileOutputStream (java.io.FileOutputStream)6 XmlSerializer (org.xmlpull.v1.XmlSerializer)6 Bucket (android.app.usage.NetworkStats.Bucket)5