Merge "Don't send the same PendingIntent more than once." into lmp-mr1-dev

This commit is contained in:
Jeremy Joslin
2014-12-06 02:05:20 +00:00
committed by Android (Google) Code Review

View File

@@ -216,6 +216,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
private static final int SAMPLE_INTERVAL_ELAPSED_REQUEST_CODE = 0; private static final int SAMPLE_INTERVAL_ELAPSED_REQUEST_CODE = 0;
// How long to delay to removal of a pending intent based request.
// See Settings.Secure.CONNECTIVITY_RELEASE_PENDING_INTENT_DELAY_MS
private final int mReleasePendingIntentDelayMs;
private PendingIntent mSampleIntervalElapsedIntent; private PendingIntent mSampleIntervalElapsedIntent;
// Set network sampling interval at 12 minutes, this way, even if the timers get // Set network sampling interval at 12 minutes, this way, even if the timers get
@@ -666,6 +670,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
loge("Error setting defaultDns using " + dns); loge("Error setting defaultDns using " + dns);
} }
mReleasePendingIntentDelayMs = Settings.Secure.getInt(context.getContentResolver(),
Settings.Secure.CONNECTIVITY_RELEASE_PENDING_INTENT_DELAY_MS, 5_000);
mContext = checkNotNull(context, "missing Context"); mContext = checkNotNull(context, "missing Context");
mNetd = checkNotNull(netManager, "missing INetworkManagementService"); mNetd = checkNotNull(netManager, "missing INetworkManagementService");
mPolicyManager = checkNotNull(policyManager, "missing INetworkPolicyManager"); mPolicyManager = checkNotNull(policyManager, "missing INetworkPolicyManager");
@@ -3441,6 +3448,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
final NetworkRequest request; final NetworkRequest request;
final PendingIntent mPendingIntent; final PendingIntent mPendingIntent;
boolean mPendingIntentSent;
private final IBinder mBinder; private final IBinder mBinder;
final int mPid; final int mPid;
final int mUid; final int mUid;
@@ -3562,6 +3570,12 @@ public class ConnectivityService extends IConnectivityManager.Stub
return networkRequest; return networkRequest;
} }
private void releasePendingNetworkRequestWithDelay(PendingIntent operation) {
mHandler.sendMessageDelayed(
mHandler.obtainMessage(EVENT_RELEASE_NETWORK_REQUEST_WITH_INTENT,
getCallingUid(), 0, operation), mReleasePendingIntentDelayMs);
}
@Override @Override
public void releasePendingNetworkRequest(PendingIntent operation) { public void releasePendingNetworkRequest(PendingIntent operation) {
mHandler.sendMessage(mHandler.obtainMessage(EVENT_RELEASE_NETWORK_REQUEST_WITH_INTENT, mHandler.sendMessage(mHandler.obtainMessage(EVENT_RELEASE_NETWORK_REQUEST_WITH_INTENT,
@@ -3875,10 +3889,11 @@ public class ConnectivityService extends IConnectivityManager.Stub
private void sendPendingIntentForRequest(NetworkRequestInfo nri, NetworkAgentInfo networkAgent, private void sendPendingIntentForRequest(NetworkRequestInfo nri, NetworkAgentInfo networkAgent,
int notificationType) { int notificationType) {
if (notificationType == ConnectivityManager.CALLBACK_AVAILABLE) { if (notificationType == ConnectivityManager.CALLBACK_AVAILABLE && !nri.mPendingIntentSent) {
Intent intent = new Intent(); Intent intent = new Intent();
intent.putExtra(ConnectivityManager.EXTRA_NETWORK, networkAgent.network); intent.putExtra(ConnectivityManager.EXTRA_NETWORK, networkAgent.network);
intent.putExtra(ConnectivityManager.EXTRA_NETWORK_REQUEST, nri.request); intent.putExtra(ConnectivityManager.EXTRA_NETWORK_REQUEST, nri.request);
nri.mPendingIntentSent = true;
sendIntent(nri.mPendingIntent, intent); sendIntent(nri.mPendingIntent, intent);
} }
// else not handled // else not handled
@@ -3902,7 +3917,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
String resultData, Bundle resultExtras) { String resultData, Bundle resultExtras) {
if (DBG) log("Finished sending " + pendingIntent); if (DBG) log("Finished sending " + pendingIntent);
mPendingIntentWakeLock.release(); mPendingIntentWakeLock.release();
releasePendingNetworkRequest(pendingIntent); // Release with a delay so the receiving client has an opportunity to put in its
// own request.
releasePendingNetworkRequestWithDelay(pendingIntent);
} }
private void callCallbackForRequest(NetworkRequestInfo nri, private void callCallbackForRequest(NetworkRequestInfo nri,