Skip to content

Commit f9dc24d

Browse files
Robert GreenwaltAndroid (Google) Code Review
authored andcommitted
Merge "Fix ThrottleService wifi interaction" into froyo
2 parents 11505b4 + fee4683 commit f9dc24d

File tree

1 file changed

+61
-1
lines changed

1 file changed

+61
-1
lines changed

services/java/com/android/server/ThrottleService.java

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import android.content.pm.PackageManager;
2929
import android.content.res.Resources;
3030
import android.database.ContentObserver;
31+
import android.net.INetworkManagementEventObserver;
3132
import android.net.IThrottleManager;
3233
import android.net.SntpClient;
3334
import android.net.ThrottleManager;
@@ -45,6 +46,7 @@
4546
import android.os.SystemProperties;
4647
import android.provider.Settings;
4748
import android.telephony.TelephonyManager;
49+
import android.text.TextUtils;
4850
import android.util.Slog;
4951

5052
import com.android.internal.R;
@@ -109,6 +111,7 @@ public class ThrottleService extends IThrottleManager.Stub {
109111
private Notification mThrottlingNotification;
110112
private boolean mWarningNotificationSent = false;
111113

114+
private InterfaceObserver mInterfaceObserver;
112115
private SettingsObserver mSettingsObserver;
113116

114117
private int mThrottleIndex; // 0 for none, 1 for first throttle val, 2 for next, etc
@@ -125,6 +128,7 @@ public ThrottleService(Context context) {
125128

126129
mNtpActive = false;
127130

131+
mIface = mContext.getResources().getString(R.string.config_datause_iface);
128132
mAlarmManager = (AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE);
129133
Intent pollIntent = new Intent(ACTION_POLL, null);
130134
mPendingPollIntent = PendingIntent.getBroadcast(mContext, POLL_REQUEST, pollIntent, 0);
@@ -138,6 +142,38 @@ public ThrottleService(Context context) {
138142
Context.NOTIFICATION_SERVICE);
139143
}
140144

145+
private static class InterfaceObserver extends INetworkManagementEventObserver.Stub {
146+
private int mMsg;
147+
private Handler mHandler;
148+
private String mIface;
149+
150+
InterfaceObserver(Handler handler, int msg, String iface) {
151+
super();
152+
mHandler = handler;
153+
mMsg = msg;
154+
mIface = iface;
155+
}
156+
157+
public void interfaceLinkStatusChanged(String iface, boolean link) {
158+
if (link) {
159+
if (TextUtils.equals(iface, mIface)) {
160+
mHandler.obtainMessage(mMsg).sendToTarget();
161+
}
162+
}
163+
}
164+
165+
public void interfaceAdded(String iface) {
166+
// TODO - an interface added in the UP state should also trigger a StatusChanged
167+
// notification..
168+
if (TextUtils.equals(iface, mIface)) {
169+
mHandler.obtainMessage(mMsg).sendToTarget();
170+
}
171+
}
172+
173+
public void interfaceRemoved(String iface) {}
174+
}
175+
176+
141177
private static class SettingsObserver extends ContentObserver {
142178
private int mMsg;
143179
private Handler mHandler;
@@ -273,6 +309,13 @@ public void onReceive(Context context, Intent intent) {
273309
mHandler = new MyHandler(mThread.getLooper());
274310
mHandler.obtainMessage(EVENT_REBOOT_RECOVERY).sendToTarget();
275311

312+
mInterfaceObserver = new InterfaceObserver(mHandler, EVENT_IFACE_UP, mIface);
313+
try {
314+
mNMService.registerObserver(mInterfaceObserver);
315+
} catch (RemoteException e) {
316+
Slog.e(TAG, "Could not register InterfaceObserver " + e);
317+
}
318+
276319
mSettingsObserver = new SettingsObserver(mHandler, EVENT_POLICY_CHANGED);
277320
mSettingsObserver.observe(mContext);
278321

@@ -299,6 +342,7 @@ public void onReceive(Context context, Intent intent) {
299342
private static final int EVENT_POLICY_CHANGED = 1;
300343
private static final int EVENT_POLL_ALARM = 2;
301344
private static final int EVENT_RESET_ALARM = 3;
345+
private static final int EVENT_IFACE_UP = 4;
302346
private class MyHandler extends Handler {
303347
public MyHandler(Looper l) {
304348
super(l);
@@ -318,6 +362,9 @@ public void handleMessage(Message msg) {
318362
break;
319363
case EVENT_RESET_ALARM:
320364
onResetAlarm();
365+
break;
366+
case EVENT_IFACE_UP:
367+
onIfaceUp();
321368
}
322369
}
323370

@@ -374,7 +421,6 @@ private void onPolicyChanged() {
374421
Settings.Secure.putInt(mContext.getContentResolver(),
375422
Settings.Secure.THROTTLE_RESET_DAY, mPolicyResetDay);
376423
}
377-
mIface = mContext.getResources().getString(R.string.config_datause_iface);
378424
synchronized (ThrottleService.this) {
379425
if (mIface == null) {
380426
mPolicyThreshold = 0;
@@ -454,6 +500,20 @@ private void onPollAlarm() {
454500
mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, next, mPendingPollIntent);
455501
}
456502

503+
private void onIfaceUp() {
504+
// if we were throttled before, be sure and set it again - the iface went down
505+
// (and may have disappeared all together) and these settings were lost
506+
if (mThrottleIndex == 1) {
507+
try {
508+
mNMService.setInterfaceThrottle(mIface, -1, -1);
509+
mNMService.setInterfaceThrottle(mIface,
510+
mPolicyThrottleValue, mPolicyThrottleValue);
511+
} catch (Exception e) {
512+
Slog.e(TAG, "error setting Throttle: " + e);
513+
}
514+
}
515+
}
516+
457517
private void checkThrottleAndPostNotification(long currentTotal) {
458518
// is throttling enabled?
459519
if (mPolicyThreshold == 0) {

0 commit comments

Comments
 (0)