am 7bb89cf1: Merge changes I2c09abaa,I9d8406e1 into jb-mr1-dev

* commit '7bb89cf1632da6dc236e6603c4245301500eeb39':
  Cure narcolepsy.
  Allow applications to connect to known wifi displays.
This commit is contained in:
Jeff Brown
2012-09-26 20:22:38 -07:00
committed by Android Git Automerger
5 changed files with 53 additions and 42 deletions

View File

@@ -46,9 +46,7 @@ public final class DisplayManager {
* The status is provided as a {@link WifiDisplayStatus} object in the * The status is provided as a {@link WifiDisplayStatus} object in the
* {@link #EXTRA_WIFI_DISPLAY_STATUS} extra. * {@link #EXTRA_WIFI_DISPLAY_STATUS} extra.
* </p><p> * </p><p>
* This broadcast is only sent to registered receivers with the * This broadcast is only sent to registered receivers and can only be sent by the system.
* {@link android.Manifest.permission#CONFIGURE_WIFI_DISPLAY} permission and can
* only be sent by the system.
* </p> * </p>
* @hide * @hide
*/ */
@@ -163,6 +161,9 @@ public final class DisplayManager {
* <p> * <p>
* Automatically remembers the display after a successful connection, if not * Automatically remembers the display after a successful connection, if not
* already remembered. * already remembered.
* </p><p>
* Requires {@link android.Manifest.permission#CONFIGURE_WIFI_DISPLAY} to connect
* to unknown displays. No permissions are required to connect to already known displays.
* </p> * </p>
* *
* @param deviceAddress The MAC address of the device to which we should connect. * @param deviceAddress The MAC address of the device to which we should connect.
@@ -187,6 +188,8 @@ public final class DisplayManager {
* The display must already be remembered for this call to succeed. In other words, * The display must already be remembered for this call to succeed. In other words,
* we must already have successfully connected to the display at least once and then * we must already have successfully connected to the display at least once and then
* not forgotten it. * not forgotten it.
* </p><p>
* Requires {@link android.Manifest.permission#CONFIGURE_WIFI_DISPLAY}.
* </p> * </p>
* *
* @param deviceAddress The MAC address of the device to rename. * @param deviceAddress The MAC address of the device to rename.
@@ -202,6 +205,8 @@ public final class DisplayManager {
* Forgets a previously remembered Wifi display. * Forgets a previously remembered Wifi display.
* <p> * <p>
* Automatically disconnects from the display if currently connected to it. * Automatically disconnects from the display if currently connected to it.
* </p><p>
* Requires {@link android.Manifest.permission#CONFIGURE_WIFI_DISPLAY}.
* </p> * </p>
* *
* @param deviceAddress The MAC address of the device to forget. * @param deviceAddress The MAC address of the device to forget.

View File

@@ -28,13 +28,14 @@ interface IDisplayManager {
void registerCallback(in IDisplayManagerCallback callback); void registerCallback(in IDisplayManagerCallback callback);
// Requires CONFIGURE_WIFI_DISPLAY permission. // No permissions required.
void scanWifiDisplays(); void scanWifiDisplays();
// Requires CONFIGURE_WIFI_DISPLAY permission. // Requires CONFIGURE_WIFI_DISPLAY permission to connect to an unknown device.
// No permissions required to connect to a known device.
void connectWifiDisplay(String address); void connectWifiDisplay(String address);
// Requires CONFIGURE_WIFI_DISPLAY permission. // No permissions required.
void disconnectWifiDisplay(); void disconnectWifiDisplay();
// Requires CONFIGURE_WIFI_DISPLAY permission. // Requires CONFIGURE_WIFI_DISPLAY permission.
@@ -43,6 +44,6 @@ interface IDisplayManager {
// Requires CONFIGURE_WIFI_DISPLAY permission. // Requires CONFIGURE_WIFI_DISPLAY permission.
void forgetWifiDisplay(String address); void forgetWifiDisplay(String address);
// Requires CONFIGURE_WIFI_DISPLAY permission. // No permissions required.
WifiDisplayStatus getWifiDisplayStatus(); WifiDisplayStatus getWifiDisplayStatus();
} }

View File

@@ -25,7 +25,6 @@ import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.app.StatusBarManager; import android.app.StatusBarManager;
import android.app.UiModeManager; import android.app.UiModeManager;
import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@@ -497,7 +496,8 @@ class UiModeManagerService extends IUiModeManager.Stub {
sendConfigurationLocked(); sendConfigurationLocked();
// If we did not start a dock app, then start dreaming if supported. // If we did not start a dock app, then start dreaming if supported.
if (!dockAppStarted && isScreenSaverEnabled() && isScreenSaverActivatedOnDock()) { if (category != null && !dockAppStarted
&& isScreenSaverEnabled() && isScreenSaverActivatedOnDock()) {
Slog.i(TAG, "Activating dream while docked."); Slog.i(TAG, "Activating dream while docked.");
try { try {
IDreamManager dreamManagerService = IDreamManager.Stub.asInterface( IDreamManager dreamManagerService = IDreamManager.Stub.asInterface(

View File

@@ -352,11 +352,6 @@ public final class DisplayManagerService extends IDisplayManager.Stub {
@Override // Binder call @Override // Binder call
public void scanWifiDisplays() { public void scanWifiDisplays() {
if (mContext.checkCallingPermission(android.Manifest.permission.CONFIGURE_WIFI_DISPLAY)
!= PackageManager.PERMISSION_GRANTED) {
throw new SecurityException("Requires CONFIGURE_WIFI_DISPLAY permission");
}
final long token = Binder.clearCallingIdentity(); final long token = Binder.clearCallingIdentity();
try { try {
synchronized (mSyncRoot) { synchronized (mSyncRoot) {
@@ -371,19 +366,16 @@ public final class DisplayManagerService extends IDisplayManager.Stub {
@Override // Binder call @Override // Binder call
public void connectWifiDisplay(String address) { public void connectWifiDisplay(String address) {
if (mContext.checkCallingPermission(android.Manifest.permission.CONFIGURE_WIFI_DISPLAY)
!= PackageManager.PERMISSION_GRANTED) {
throw new SecurityException("Requires CONFIGURE_WIFI_DISPLAY permission");
}
if (address == null) { if (address == null) {
throw new IllegalArgumentException("address must not be null"); throw new IllegalArgumentException("address must not be null");
} }
final boolean trusted = canCallerConfigureWifiDisplay();
final long token = Binder.clearCallingIdentity(); final long token = Binder.clearCallingIdentity();
try { try {
synchronized (mSyncRoot) { synchronized (mSyncRoot) {
if (mWifiDisplayAdapter != null) { if (mWifiDisplayAdapter != null) {
mWifiDisplayAdapter.requestConnectLocked(address); mWifiDisplayAdapter.requestConnectLocked(address, trusted);
} }
} }
} finally { } finally {
@@ -393,11 +385,6 @@ public final class DisplayManagerService extends IDisplayManager.Stub {
@Override // Binder call @Override // Binder call
public void disconnectWifiDisplay() { public void disconnectWifiDisplay() {
if (mContext.checkCallingPermission(android.Manifest.permission.CONFIGURE_WIFI_DISPLAY)
!= PackageManager.PERMISSION_GRANTED) {
throw new SecurityException("Requires CONFIGURE_WIFI_DISPLAY permission");
}
final long token = Binder.clearCallingIdentity(); final long token = Binder.clearCallingIdentity();
try { try {
synchronized (mSyncRoot) { synchronized (mSyncRoot) {
@@ -412,13 +399,13 @@ public final class DisplayManagerService extends IDisplayManager.Stub {
@Override // Binder call @Override // Binder call
public void renameWifiDisplay(String address, String alias) { public void renameWifiDisplay(String address, String alias) {
if (mContext.checkCallingPermission(android.Manifest.permission.CONFIGURE_WIFI_DISPLAY)
!= PackageManager.PERMISSION_GRANTED) {
throw new SecurityException("Requires CONFIGURE_WIFI_DISPLAY permission");
}
if (address == null) { if (address == null) {
throw new IllegalArgumentException("address must not be null"); throw new IllegalArgumentException("address must not be null");
} }
if (!canCallerConfigureWifiDisplay()) {
throw new SecurityException("Requires CONFIGURE_WIFI_DISPLAY permission to "
+ "rename a wifi display.");
}
final long token = Binder.clearCallingIdentity(); final long token = Binder.clearCallingIdentity();
try { try {
@@ -434,13 +421,13 @@ public final class DisplayManagerService extends IDisplayManager.Stub {
@Override // Binder call @Override // Binder call
public void forgetWifiDisplay(String address) { public void forgetWifiDisplay(String address) {
if (mContext.checkCallingPermission(android.Manifest.permission.CONFIGURE_WIFI_DISPLAY)
!= PackageManager.PERMISSION_GRANTED) {
throw new SecurityException("Requires CONFIGURE_WIFI_DISPLAY permission");
}
if (address == null) { if (address == null) {
throw new IllegalArgumentException("address must not be null"); throw new IllegalArgumentException("address must not be null");
} }
if (!canCallerConfigureWifiDisplay()) {
throw new SecurityException("Requires CONFIGURE_WIFI_DISPLAY permission to "
+ "forget a wifi display.");
}
final long token = Binder.clearCallingIdentity(); final long token = Binder.clearCallingIdentity();
try { try {
@@ -456,11 +443,6 @@ public final class DisplayManagerService extends IDisplayManager.Stub {
@Override // Binder call @Override // Binder call
public WifiDisplayStatus getWifiDisplayStatus() { public WifiDisplayStatus getWifiDisplayStatus() {
if (mContext.checkCallingPermission(android.Manifest.permission.CONFIGURE_WIFI_DISPLAY)
!= PackageManager.PERMISSION_GRANTED) {
throw new SecurityException("Requires CONFIGURE_WIFI_DISPLAY permission");
}
final long token = Binder.clearCallingIdentity(); final long token = Binder.clearCallingIdentity();
try { try {
synchronized (mSyncRoot) { synchronized (mSyncRoot) {
@@ -475,6 +457,11 @@ public final class DisplayManagerService extends IDisplayManager.Stub {
} }
} }
private boolean canCallerConfigureWifiDisplay() {
return mContext.checkCallingPermission(android.Manifest.permission.CONFIGURE_WIFI_DISPLAY)
== PackageManager.PERMISSION_GRANTED;
}
private void registerDefaultDisplayAdapter() { private void registerDefaultDisplayAdapter() {
// Register default display adapter. // Register default display adapter.
synchronized (mSyncRoot) { synchronized (mSyncRoot) {

View File

@@ -27,6 +27,7 @@ import android.hardware.display.WifiDisplayStatus;
import android.media.RemoteDisplay; import android.media.RemoteDisplay;
import android.os.Handler; import android.os.Handler;
import android.os.IBinder; import android.os.IBinder;
import android.util.Slog;
import android.view.Surface; import android.view.Surface;
import java.io.PrintWriter; import java.io.PrintWriter;
@@ -121,7 +122,17 @@ final class WifiDisplayAdapter extends DisplayAdapter {
}); });
} }
public void requestConnectLocked(final String address) { public void requestConnectLocked(final String address, final boolean trusted) {
if (!trusted) {
synchronized (getSyncRoot()) {
if (!isRememberedDisplayLocked(address)) {
Slog.w(TAG, "Ignoring request by an untrusted client to connect to "
+ "an unknown wifi display: " + address);
return;
}
}
}
getHandler().post(new Runnable() { getHandler().post(new Runnable() {
@Override @Override
public void run() { public void run() {
@@ -132,6 +143,15 @@ final class WifiDisplayAdapter extends DisplayAdapter {
}); });
} }
private boolean isRememberedDisplayLocked(String address) {
for (WifiDisplay display : mRememberedDisplays) {
if (display.getDeviceAddress().equals(address)) {
return true;
}
}
return false;
}
public void requestDisconnectLocked() { public void requestDisconnectLocked() {
getHandler().post(new Runnable() { getHandler().post(new Runnable() {
@Override @Override
@@ -241,10 +261,8 @@ final class WifiDisplayAdapter extends DisplayAdapter {
getWifiDisplayStatusLocked()); getWifiDisplayStatusLocked());
} }
// Send protected broadcast about wifi display status to receivers that // Send protected broadcast about wifi display status to registered receivers.
// have the required permission. getContext().sendBroadcast(intent);
getContext().sendBroadcast(intent,
android.Manifest.permission.CONFIGURE_WIFI_DISPLAY);
} }
}; };