diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java index c256f5c8c9c..25adef1ba25 100644 --- a/src/com/android/settings/SettingsActivity.java +++ b/src/com/android/settings/SettingsActivity.java @@ -39,10 +39,7 @@ import android.content.res.XmlResourceParser; import android.nfc.NfcAdapter; import android.os.Bundle; import android.os.Handler; -import android.os.INetworkManagementService; import android.os.Message; -import android.os.RemoteException; -import android.os.ServiceManager; import android.os.UserHandle; import android.os.UserManager; import android.preference.Preference; @@ -1248,14 +1245,8 @@ public class SettingsActivity extends Activity } } else if (id == R.id.data_usage_settings) { // Remove data usage when kernel module not enabled - final INetworkManagementService netManager = INetworkManagementService.Stub - .asInterface(ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE)); - try { - if (!netManager.isBandwidthControlEnabled()) { - removeTile = true; - } - } catch (RemoteException e) { - // ignored + if (!Utils.isBandwidthControlEnabled()) { + removeTile = true; } } else if (id == R.id.battery_settings) { // Remove battery settings when battery is not available. (e.g. TV) diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java index 4ddba80522b..d3d515e5189 100644 --- a/src/com/android/settings/Utils.java +++ b/src/com/android/settings/Utils.java @@ -55,7 +55,9 @@ import android.net.Uri; import android.os.BatteryManager; import android.os.Bundle; import android.os.IBinder; +import android.os.INetworkManagementService; import android.os.RemoteException; +import android.os.ServiceManager; import android.os.UserHandle; import android.os.UserManager; import android.os.storage.StorageManager; @@ -1179,4 +1181,14 @@ public final class Utils { return null; } } + + public static boolean isBandwidthControlEnabled() { + final INetworkManagementService netManager = INetworkManagementService.Stub + .asInterface(ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE)); + try { + return netManager.isBandwidthControlEnabled(); + } catch (RemoteException e) { + return false; + } + } } \ No newline at end of file diff --git a/src/com/android/settings/applications/InstalledAppDetails.java b/src/com/android/settings/applications/InstalledAppDetails.java index 4eb86a90791..e625a979b0c 100755 --- a/src/com/android/settings/applications/InstalledAppDetails.java +++ b/src/com/android/settings/applications/InstalledAppDetails.java @@ -226,12 +226,16 @@ public class InstalledAppDetails extends AppInfoBase setHasOptionsMenu(true); addPreferencesFromResource(R.xml.installed_app_details); - INetworkStatsService statsService = INetworkStatsService.Stub.asInterface( - ServiceManager.getService(Context.NETWORK_STATS_SERVICE)); - try { - mStatsSession = statsService.openSession(); - } catch (RemoteException e) { - throw new RuntimeException(e); + if (Utils.isBandwidthControlEnabled()) { + INetworkStatsService statsService = INetworkStatsService.Stub.asInterface( + ServiceManager.getService(Context.NETWORK_STATS_SERVICE)); + try { + mStatsSession = statsService.openSession(); + } catch (RemoteException e) { + throw new RuntimeException(e); + } + } else { + removePreference(KEY_DATA); } mBatteryHelper = new BatteryStatsHelper(getActivity(), true); } @@ -249,9 +253,11 @@ public class InstalledAppDetails extends AppInfoBase } AppItem app = new AppItem(mAppEntry.info.uid); app.addUid(mAppEntry.info.uid); - getLoaderManager().restartLoader(LOADER_CHART_DATA, - ChartDataLoader.buildArgs(getTemplate(getContext()), app), - mDataCallbacks); + if (mStatsSession != null) { + getLoaderManager().restartLoader(LOADER_CHART_DATA, + ChartDataLoader.buildArgs(getTemplate(getContext()), app), + mDataCallbacks); + } new BatteryUpdater().execute(); } @@ -282,7 +288,9 @@ public class InstalledAppDetails extends AppInfoBase mPermissionsPreference = findPreference(KEY_PERMISSION); mPermissionsPreference.setOnPreferenceClickListener(this); mDataPreference = findPreference(KEY_DATA); - mDataPreference.setOnPreferenceClickListener(this); + if (mDataPreference != null) { + mDataPreference.setOnPreferenceClickListener(this); + } mBatteryPreference = findPreference(KEY_BATTERY); mBatteryPreference.setEnabled(false); mBatteryPreference.setOnPreferenceClickListener(this); @@ -458,7 +466,9 @@ public class InstalledAppDetails extends AppInfoBase mPm, context)); mNotificationPreference.setSummary(getNotificationSummary(mAppEntry, context, mBackend)); - mDataPreference.setSummary(getDataSummary()); + if (mDataPreference != null) { + mDataPreference.setSummary(getDataSummary()); + } updateBattery();