Skip to content

Commit

Permalink
wifi: Confirm user permission before toggling wifi.
Browse files Browse the repository at this point in the history
Check user permissions before enabling/disabling wifi.

Change-Id: I1ddae6e47f42b6d3fc831c2c135ece75cf9e935d
  • Loading branch information
Shashank Mittal authored and sam3000 committed Nov 10, 2013
1 parent 6a12d12 commit 10af37e
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions cmds/svc/src/com/android/commands/svc/WifiCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void run(String[] args) {
IWifiManager wifiMgr
= IWifiManager.Stub.asInterface(ServiceManager.getService(Context.WIFI_SERVICE));
try {
wifiMgr.setWifiEnabled(flag);
wifiMgr.setWifiEnabled("com.android.commands.svc", flag);
}
catch (RemoteException e) {
System.err.println("Wi-Fi operation failed: " + e);
Expand All @@ -75,4 +75,4 @@ public void run(String[] args) {
}
System.err.println(longHelp());
}
}
}
7 changes: 6 additions & 1 deletion core/java/android/app/AppOpsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ public class AppOpsManager {
public static final int OP_READ_CLIPBOARD = 29;
public static final int OP_WRITE_CLIPBOARD = 30;
/** @hide */
public static final int _NUM_OP = 31;
public static final int OP_WIFI_CHANGE = 31;
public static final int _NUM_OP = 32;

/**
* Map to check if each operation is strict or not, to determine default
Expand Down Expand Up @@ -141,6 +142,7 @@ public class AppOpsManager {
true, //OP_PLAY_AUDIO
false, //OP_READ_CLIPBOARD
false, //OP_WRITE_CLIPBOARD
true, //OP_WIFI_CHANGE
};

/**
Expand Down Expand Up @@ -183,6 +185,7 @@ public class AppOpsManager {
OP_PLAY_AUDIO,
OP_READ_CLIPBOARD,
OP_WRITE_CLIPBOARD,
OP_WIFI_CHANGE,
};

/**
Expand Down Expand Up @@ -221,6 +224,7 @@ public class AppOpsManager {
"PLAY_AUDIO",
"READ_CLIPBOARD",
"WRITE_CLIPBOARD",
"WIFI_CHANGE",
};

/**
Expand Down Expand Up @@ -259,6 +263,7 @@ public class AppOpsManager {
null, // no permission for playing audio
null, // no permission for reading clipboard
null, // no permission for writing clipboard
android.Manifest.permission.CHANGE_WIFI_STATE,
};

/**
Expand Down
1 change: 1 addition & 0 deletions core/res/res/values/cm_arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,6 @@
<item>Trying to play audio</item>
<item>Trying to read clipboard</item>
<item>Trying to modify clipboard</item>
<item>Trying to turn on/off Wifi</item>
</string-array>
</resources>
10 changes: 8 additions & 2 deletions services/java/com/android/server/wifi/WifiService.java
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public void checkAndStartWifi() {

// If we are already disabled (could be due to airplane mode), avoid changing persist
// state here
if (wifiEnabled) setWifiEnabled(wifiEnabled);
if (wifiEnabled) setWifiEnabled(mContext.getBasePackageName(), wifiEnabled);

mWifiWatchdogStateMachine = WifiWatchdogStateMachine.
makeWifiWatchdogStateMachine(mContext);
Expand Down Expand Up @@ -332,8 +332,14 @@ private void enforceConnectivityInternalPermission() {
* @return {@code true} if the enable/disable operation was
* started or is already in the queue.
*/
public synchronized boolean setWifiEnabled(boolean enable) {
public synchronized boolean setWifiEnabled(String callingPackage, boolean enable) {
enforceChangePermission();

int uid = Binder.getCallingUid();
if (mAppOps.noteOp(AppOpsManager.OP_WIFI_CHANGE, uid, callingPackage)
!= AppOpsManager.MODE_ALLOWED)
return false;

Slog.d(TAG, "setWifiEnabled: " + enable + " pid=" + Binder.getCallingPid()
+ ", uid=" + Binder.getCallingUid());
if (DBG) {
Expand Down
2 changes: 1 addition & 1 deletion wifi/java/android/net/wifi/IWifiManager.aidl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ interface IWifiManager

WifiInfo getConnectionInfo();

boolean setWifiEnabled(boolean enable);
boolean setWifiEnabled(String callingPackage, boolean enable);

int getWifiEnabledState();

Expand Down
2 changes: 1 addition & 1 deletion wifi/java/android/net/wifi/WifiManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ public DhcpInfo getDhcpInfo() {
*/
public boolean setWifiEnabled(boolean enabled) {
try {
return mService.setWifiEnabled(enabled);
return mService.setWifiEnabled(mContext.getBasePackageName(), enabled);
} catch (RemoteException e) {
return false;
}
Expand Down

0 comments on commit 10af37e

Please sign in to comment.