@SuppressLint("InlinedApi") // Is available in pre 23, but hidden public MobileDataController(Context context) { mContext = context; mStatsService = INetworkStatsService.Stub.asInterface( ServiceManager.getService(Context.NETWORK_STATS_SERVICE)); mPolicyManager = NetworkPolicyManager.from(mContext); }
private NetworkPolicy findNetworkPolicy(NetworkTemplate template) { if (mPolicyManager == null || template == null) return null; final NetworkPolicy[] policies = mPolicyManager.getNetworkPolicies(); if (policies == null) return null; for (final NetworkPolicy policy : policies) { if (policy != null && template.equals(policy.template)) { return policy; } } return null; }
/** * {@hide} */ public static long computeNextCycleBoundary(long currentTime, NetworkPolicy policy) { if (policy.cycleDay == CYCLE_NONE) { throw new IllegalArgumentException("Unable to compute boundary without cycleDay"); } final Time now = new Time(policy.cycleTimezone); now.set(currentTime); // first, find cycle boundary for current month final Time cycle = new Time(now); cycle.hour = cycle.minute = cycle.second = 0; snapToCycleDay(cycle, policy.cycleDay); if (Time.compare(cycle, now) <= 0) { // cycle boundary is before now, use next cycle boundary; start by // pushing ourselves squarely into next month. final Time nextMonth = new Time(now); nextMonth.hour = nextMonth.minute = nextMonth.second = 0; nextMonth.monthDay = 1; nextMonth.month += 1; nextMonth.normalize(true); cycle.set(nextMonth); snapToCycleDay(cycle, policy.cycleDay); } return cycle.toMillis(true); }
snapToCycleDay(cycle, policy.cycleDay); snapToCycleDay(cycle, policy.cycleDay);