Android-x86
Fork
Faire un don

  • R/O
  • HTTP
  • SSH
  • HTTPS

packages-services-Analytics: Commit

packages/services/Analytics


Commit MetaInfo

Révisiona9c4d5074a7b72e436033d4d93fe2fdff733f3f1 (tree)
l'heure2017-10-19 12:12:00
AuteurChih-Wei Huang <cwhuang@linu...>
CommiterChih-Wei Huang

Message de Log

AnalyticsService: get rid of getBaseContext()

According to Dianne Hackborn, the Google chief engineer working on
the Android framework:

"Don't use getBaseContext(), just use the Context you have."

Refer to http://stackoverflow.com/questions/1026973 for the usages
of various Contexts.

Change Summary

Modification

--- a/Service/src/org/android_x86/analytics/AnalyticsService.java
+++ b/Service/src/org/android_x86/analytics/AnalyticsService.java
@@ -89,13 +89,13 @@ public class AnalyticsService extends ImmortalIntentService {
8989 Log.d(TAG, "Receive Intent: " + Util.toString(intent));
9090 }
9191 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
92- AnalyticsHelper.screenOff(getBaseContext());
92+ AnalyticsHelper.screenOff(context);
9393 PowerStats.onScreenOff(context);
9494 } else if (Intent.ACTION_SCREEN_ON.equals(action)) {
95- AnalyticsHelper.screenOn(getBaseContext());
95+ AnalyticsHelper.screenOn(context);
9696 PowerStats.onScreenOn(context);
9797 } else if (Intent.ACTION_SHUTDOWN.equals(action)) {
98- AnalyticsHelper.onShutdown(getBaseContext());
98+ AnalyticsHelper.onShutdown(context);
9999 PowerStats.onScreenOff(context);
100100 } else if (Intent.ACTION_POWER_CONNECTED.equals(action)) {
101101 PowerStats.onPowerConnected(context);
@@ -114,20 +114,20 @@ public class AnalyticsService extends ImmortalIntentService {
114114 filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
115115 filter.addAction(Intent.ACTION_POWER_CONNECTED);
116116 filter.addAction(Intent.ACTION_POWER_DISCONNECTED);
117- getBaseContext().registerReceiver(mReceiver, filter);
117+ registerReceiver(mReceiver, filter);
118118
119119 mLogHelper = new LogHelper(this);
120120 }
121121
122122 @Override
123123 protected void onHandleIntent(Intent intent) {
124- String action = intent.getAction();
125124 if (!mEnable){
126125 if (LOG) {
127126 Log.d(TAG, "USAGE STATISTICS not enable");
128127 }
129128 return;
130129 }
130+ String action = intent.getAction();
131131 EventHandler eventHandler = mStaticEventHandlers.get(action);
132132 if (eventHandler != null){
133133 eventHandler.onEvent(intent);
@@ -137,7 +137,7 @@ public class AnalyticsService extends ImmortalIntentService {
137137 // save boot completed time
138138 saveScreenChangeTime(getCurrentTimeInSeconds());
139139 onBootCompleted(intent);
140- PowerStats.onScreenOn(getBaseContext());
140+ PowerStats.onScreenOn(this);
141141 }
142142 if (LOG) {
143143 Log.d(TAG, "Handle Intent: " + Util.toString(intent));
Afficher sur ancien navigateur de dépôt.