am f679d4cb: Merge "Fix FeatureUser leak in ConnectivityService" into honeycomb-LTE
* commit 'f679d4cb92b6d1c193a154abb5ae8fb3a786fc43': Fix FeatureUser leak in ConnectivityService
This commit is contained in:
@@ -220,7 +220,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
|
|
||||||
// list of DeathRecipients used to make sure features are turned off when
|
// list of DeathRecipients used to make sure features are turned off when
|
||||||
// a process dies
|
// a process dies
|
||||||
private List mFeatureUsers;
|
private List<FeatureUser> mFeatureUsers;
|
||||||
|
|
||||||
private boolean mSystemReady;
|
private boolean mSystemReady;
|
||||||
private Intent mInitialBroadcast;
|
private Intent mInitialBroadcast;
|
||||||
@@ -404,7 +404,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
mNetRequestersPids[i] = new ArrayList();
|
mNetRequestersPids[i] = new ArrayList();
|
||||||
}
|
}
|
||||||
|
|
||||||
mFeatureUsers = new ArrayList();
|
mFeatureUsers = new ArrayList<FeatureUser>();
|
||||||
|
|
||||||
mNumDnsEntries = 0;
|
mNumDnsEntries = 0;
|
||||||
|
|
||||||
@@ -677,6 +677,20 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
stopUsingNetworkFeature(this, false);
|
stopUsingNetworkFeature(this, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isSameUser(FeatureUser u) {
|
||||||
|
if (u == null) return false;
|
||||||
|
|
||||||
|
return isSameUser(u.mPid, u.mUid, u.mNetworkType, u.mFeature);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSameUser(int pid, int uid, int networkType, String feature) {
|
||||||
|
if ((mPid == pid) && (mUid == uid) && (mNetworkType == networkType) &&
|
||||||
|
TextUtils.equals(mFeature, feature)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "FeatureUser("+mNetworkType+","+mFeature+","+mPid+","+mUid+"), created " +
|
return "FeatureUser("+mNetworkType+","+mFeature+","+mPid+","+mUid+"), created " +
|
||||||
(System.currentTimeMillis() - mCreateTime) + " mSec ago";
|
(System.currentTimeMillis() - mCreateTime) + " mSec ago";
|
||||||
@@ -727,16 +741,29 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int restoreTimer = getRestoreDefaultNetworkDelay(usedNetworkType);
|
||||||
|
|
||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
mFeatureUsers.add(f);
|
boolean addToList = true;
|
||||||
|
if (restoreTimer < 0) {
|
||||||
|
// In case there is no timer is specified for the feature,
|
||||||
|
// make sure we don't add duplicate entry with the same request.
|
||||||
|
for (FeatureUser u : mFeatureUsers) {
|
||||||
|
if (u.isSameUser(f)) {
|
||||||
|
// Duplicate user is found. Do not add.
|
||||||
|
addToList = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (addToList) mFeatureUsers.add(f);
|
||||||
if (!mNetRequestersPids[usedNetworkType].contains(currentPid)) {
|
if (!mNetRequestersPids[usedNetworkType].contains(currentPid)) {
|
||||||
// this gets used for per-pid dns when connected
|
// this gets used for per-pid dns when connected
|
||||||
mNetRequestersPids[usedNetworkType].add(currentPid);
|
mNetRequestersPids[usedNetworkType].add(currentPid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int restoreTimer = getRestoreDefaultNetworkDelay(usedNetworkType);
|
|
||||||
|
|
||||||
if (restoreTimer >= 0) {
|
if (restoreTimer >= 0) {
|
||||||
mHandler.sendMessageDelayed(
|
mHandler.sendMessageDelayed(
|
||||||
mHandler.obtainMessage(EVENT_RESTORE_DEFAULT_NETWORK, f), restoreTimer);
|
mHandler.obtainMessage(EVENT_RESTORE_DEFAULT_NETWORK, f), restoreTimer);
|
||||||
@@ -786,11 +813,9 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
boolean found = false;
|
boolean found = false;
|
||||||
|
|
||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
for (int i = 0; i < mFeatureUsers.size() ; i++) {
|
for (FeatureUser x : mFeatureUsers) {
|
||||||
u = (FeatureUser)mFeatureUsers.get(i);
|
if (x.isSameUser(pid, uid, networkType, feature)) {
|
||||||
if (uid == u.mUid && pid == u.mPid &&
|
u = x;
|
||||||
networkType == u.mNetworkType &&
|
|
||||||
TextUtils.equals(feature, u.mFeature)) {
|
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -842,11 +867,8 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
// do not pay attention to duplicate requests - in effect the
|
// do not pay attention to duplicate requests - in effect the
|
||||||
// API does not refcount and a single stop will counter multiple starts.
|
// API does not refcount and a single stop will counter multiple starts.
|
||||||
if (ignoreDups == false) {
|
if (ignoreDups == false) {
|
||||||
for (int i = 0; i < mFeatureUsers.size() ; i++) {
|
for (FeatureUser x : mFeatureUsers) {
|
||||||
FeatureUser x = (FeatureUser)mFeatureUsers.get(i);
|
if (x.isSameUser(u)) {
|
||||||
if (x.mUid == u.mUid && x.mPid == u.mPid &&
|
|
||||||
x.mNetworkType == u.mNetworkType &&
|
|
||||||
TextUtils.equals(x.mFeature, u.mFeature)) {
|
|
||||||
if (DBG) log("ignoring stopUsingNetworkFeature as dup is found");
|
if (DBG) log("ignoring stopUsingNetworkFeature as dup is found");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user