From d101ec8f87df5c129a30b60b6327e68aabb5f842 Mon Sep 17 00:00:00 2001 From: Aaron Huang Date: Tue, 2 Feb 2021 18:27:39 +0800 Subject: [PATCH] Use NetworkCallback in BatteryStatsService to get connectivity change Currently, battery stats service uses noteConnectivityChanged in connectivity service(CS) to pass connection state and the type of connection for BatteryStats. However, CS is going to be a mainline module which can only access formal API. noteConnectivityChanged is a hidden API and it pass LegacyNetworkType which has been deprecated years ago, so it should avoid to expose this API with a deprecated argument. Thus, register a NetworkCallback in BattyeryStatsService to listen the network capabilities changed to remove the noteConnectivityChanged from connectivity service. Besides, let noteConnectivityChanged take display transport instead of legacy network type. Bug: 171686421 Test: atest FrameworksNetTests atest FrameworksCoreTests:BatteryStatsTests Change-Id: I3dac94ec06f673aa719e124f1ef3d8169f68f9fb --- .../core/java/com/android/server/ConnectivityService.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java index d1cd3be35a..0cd7f64b38 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -2384,13 +2384,6 @@ public class ConnectivityService extends IConnectivityManager.Stub final BroadcastOptions opts = BroadcastOptions.makeBasic(); opts.setMaxManifestReceiverApiLevel(Build.VERSION_CODES.M); options = opts.toBundle(); - final IBatteryStats bs = mDeps.getBatteryStatsService(); - try { - bs.noteConnectivityChanged(intent.getIntExtra( - ConnectivityManager.EXTRA_NETWORK_TYPE, ConnectivityManager.TYPE_NONE), - ni.getState().toString()); - } catch (RemoteException e) { - } intent.addFlags(Intent.FLAG_RECEIVER_VISIBLE_TO_INSTANT_APPS); } try {