resolved conflicts for merge of 53686433 to master

Change-Id: I27004dc464f5771d3205ae5757c6eccc5b16854d
This commit is contained in:
Dianne Hackborn
2010-09-13 16:02:57 -07:00
27 changed files with 963 additions and 91 deletions

View File

@@ -50,6 +50,7 @@ import android.os.INetworkManagementService;
import android.os.Message;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.WorkSource;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Slog;
@@ -1035,8 +1036,8 @@ public class WifiService extends IWifiManager.Stub {
}
private class WifiLock extends DeathRecipient {
WifiLock(int lockMode, String tag, IBinder binder) {
super(lockMode, tag, binder);
WifiLock(int lockMode, String tag, IBinder binder, WorkSource ws) {
super(lockMode, tag, binder, ws);
}
public void binderDied() {
@@ -1106,33 +1107,70 @@ public class WifiService extends IWifiManager.Stub {
}
}
public boolean acquireWifiLock(IBinder binder, int lockMode, String tag) {
void enforceWakeSourcePermission(int uid, int pid) {
if (uid == android.os.Process.myUid()) {
return;
}
mContext.enforcePermission(android.Manifest.permission.UPDATE_DEVICE_STATS,
pid, uid, null);
}
public boolean acquireWifiLock(IBinder binder, int lockMode, String tag, WorkSource ws) {
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.WAKE_LOCK, null);
if (lockMode != WifiManager.WIFI_MODE_FULL && lockMode != WifiManager.WIFI_MODE_SCAN_ONLY) {
return false;
}
WifiLock wifiLock = new WifiLock(lockMode, tag, binder);
if (ws != null) {
enforceWakeSourcePermission(Binder.getCallingUid(), Binder.getCallingPid());
}
if (ws != null && ws.size() == 0) {
ws = null;
}
if (ws == null) {
ws = new WorkSource(Binder.getCallingUid());
}
WifiLock wifiLock = new WifiLock(lockMode, tag, binder, ws);
synchronized (mLocks) {
return acquireWifiLockLocked(wifiLock);
}
}
private void noteAcquireWifiLock(WifiLock wifiLock) throws RemoteException {
switch(wifiLock.mMode) {
case WifiManager.WIFI_MODE_FULL:
mBatteryStats.noteFullWifiLockAcquiredFromSource(wifiLock.mWorkSource);
break;
case WifiManager.WIFI_MODE_SCAN_ONLY:
mBatteryStats.noteScanWifiLockAcquiredFromSource(wifiLock.mWorkSource);
break;
}
}
private void noteReleaseWifiLock(WifiLock wifiLock) throws RemoteException {
switch(wifiLock.mMode) {
case WifiManager.WIFI_MODE_FULL:
mBatteryStats.noteFullWifiLockReleasedFromSource(wifiLock.mWorkSource);
break;
case WifiManager.WIFI_MODE_SCAN_ONLY:
mBatteryStats.noteScanWifiLockReleasedFromSource(wifiLock.mWorkSource);
break;
}
}
private boolean acquireWifiLockLocked(WifiLock wifiLock) {
Slog.d(TAG, "acquireWifiLockLocked: " + wifiLock);
mLocks.addLock(wifiLock);
int uid = Binder.getCallingUid();
long ident = Binder.clearCallingIdentity();
try {
noteAcquireWifiLock(wifiLock);
switch(wifiLock.mMode) {
case WifiManager.WIFI_MODE_FULL:
++mFullLocksAcquired;
mBatteryStats.noteFullWifiLockAcquired(uid);
break;
case WifiManager.WIFI_MODE_SCAN_ONLY:
++mScanLocksAcquired;
mBatteryStats.noteScanWifiLockAcquired(uid);
break;
}
} catch (RemoteException e) {
@@ -1144,6 +1182,33 @@ public class WifiService extends IWifiManager.Stub {
return true;
}
public void updateWifiLockWorkSource(IBinder lock, WorkSource ws) {
int uid = Binder.getCallingUid();
int pid = Binder.getCallingPid();
if (ws != null && ws.size() == 0) {
ws = null;
}
if (ws != null) {
enforceWakeSourcePermission(uid, pid);
}
long ident = Binder.clearCallingIdentity();
try {
synchronized (mLocks) {
int index = mLocks.findLockByBinder(lock);
if (index < 0) {
throw new IllegalArgumentException("Wifi lock not active");
}
WifiLock wl = mLocks.mList.get(index);
noteReleaseWifiLock(wl);
wl.mWorkSource = ws != null ? new WorkSource(ws) : new WorkSource(uid);
noteAcquireWifiLock(wl);
}
} catch (RemoteException e) {
} finally {
Binder.restoreCallingIdentity(ident);
}
}
public boolean releaseWifiLock(IBinder lock) {
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.WAKE_LOCK, null);
synchronized (mLocks) {
@@ -1161,17 +1226,15 @@ public class WifiService extends IWifiManager.Stub {
hadLock = (wifiLock != null);
if (hadLock) {
int uid = Binder.getCallingUid();
long ident = Binder.clearCallingIdentity();
try {
noteAcquireWifiLock(wifiLock);
switch(wifiLock.mMode) {
case WifiManager.WIFI_MODE_FULL:
++mFullLocksReleased;
mBatteryStats.noteFullWifiLockReleased(uid);
break;
case WifiManager.WIFI_MODE_SCAN_ONLY:
++mScanLocksReleased;
mBatteryStats.noteScanWifiLockReleased(uid);
break;
}
} catch (RemoteException e) {
@@ -1189,12 +1252,14 @@ public class WifiService extends IWifiManager.Stub {
String mTag;
int mMode;
IBinder mBinder;
WorkSource mWorkSource;
DeathRecipient(int mode, String tag, IBinder binder) {
DeathRecipient(int mode, String tag, IBinder binder, WorkSource ws) {
super();
mTag = tag;
mMode = mode;
mBinder = binder;
mWorkSource = ws;
try {
mBinder.linkToDeath(this, 0);
} catch (RemoteException e) {
@@ -1209,7 +1274,7 @@ public class WifiService extends IWifiManager.Stub {
private class Multicaster extends DeathRecipient {
Multicaster(String tag, IBinder binder) {
super(Binder.getCallingUid(), tag, binder);
super(Binder.getCallingUid(), tag, binder, null);
}
public void binderDied() {