Defer opening a stats session until first use.

Bug:16174801
Change-Id: Ia70f9a01bd348809db4ab2992e5e1265778cfcfa
This commit is contained in:
John Spurlock
2014-07-09 14:26:00 -04:00
parent 99bd4eabd1
commit cfa39d269b

View File

@@ -63,13 +63,19 @@ public class MobileDataController {
mStatsService = INetworkStatsService.Stub.asInterface(
ServiceManager.getService(Context.NETWORK_STATS_SERVICE));
mPolicyManager = NetworkPolicyManager.from(mContext);
}
try {
mSession = mStatsService.openSession();
} catch (RemoteException e) {
Log.w(TAG, "Failed to open stats session");
mSession = null;
private INetworkStatsSession getSession() {
if (mSession == null) {
try {
mSession = mStatsService.openSession();
} catch (RemoteException e) {
Log.w(TAG, "Failed to open stats session", e);
} catch (RuntimeException e) {
Log.w(TAG, "Failed to open stats session", e);
}
}
return mSession;
}
public void setCallback(Callback callback) {
@@ -86,7 +92,8 @@ public class MobileDataController {
if (subscriberId == null) {
return warn("no subscriber id");
}
if (mSession == null) {
final INetworkStatsSession session = getSession();
if (session == null) {
return warn("no stats session");
}
final NetworkTemplate template = NetworkTemplate.buildTemplateMobileAll(subscriberId);