summaryrefslogtreecommitdiffstats
path: root/wifi
diff options
context:
space:
mode:
authorIrfan Sheriff <isheriff@google.com>2012-12-06 13:31:36 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-12-06 13:31:36 -0800
commit42b1b564b63fa9c93df894ac8eca8db68fd5c435 (patch)
tree55eb5a30ae19292957f71f03527caacebd928acf /wifi
parente1a2c9f9447cd61168da874c6bc5a594f5b4a6d5 (diff)
parentef96a43a3c9277a2b63cce5ead0618281ac263b1 (diff)
downloadframeworks_base-42b1b564b63fa9c93df894ac8eca8db68fd5c435.zip
frameworks_base-42b1b564b63fa9c93df894ac8eca8db68fd5c435.tar.gz
frameworks_base-42b1b564b63fa9c93df894ac8eca8db68fd5c435.tar.bz2
Merge "Remove exposing dialog handling to apps"
Diffstat (limited to 'wifi')
-rw-r--r--wifi/java/android/net/wifi/p2p/WifiP2pManager.java183
-rw-r--r--wifi/java/android/net/wifi/p2p/WifiP2pService.java253
2 files changed, 34 insertions, 402 deletions
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pManager.java b/wifi/java/android/net/wifi/p2p/WifiP2pManager.java
index 6edc232..d79421f 100644
--- a/wifi/java/android/net/wifi/p2p/WifiP2pManager.java
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pManager.java
@@ -29,7 +29,6 @@ import android.net.wifi.p2p.nsd.WifiP2pServiceResponse;
import android.net.wifi.p2p.nsd.WifiP2pUpnpServiceInfo;
import android.net.wifi.p2p.nsd.WifiP2pUpnpServiceResponse;
import android.os.Binder;
-import android.os.Bundle;
import android.os.IBinder;
import android.os.Handler;
import android.os.Looper;
@@ -273,41 +272,6 @@ public class WifiP2pManager {
public static final String WIFI_P2P_PERSISTENT_GROUPS_CHANGED_ACTION =
"android.net.wifi.p2p.PERSISTENT_GROUPS_CHANGED";
- /**
- * The lookup key for a {@link #String} object.
- * Retrieve with {@link android.os.Bundle#getString(String)}.
- * @hide
- */
- public static final String APP_PKG_BUNDLE_KEY = "appPkgName";
-
- /**
- * The lookup key for a {@link #Boolean} object.
- * Retrieve with {@link android.os.Bundle#getBoolean(String)}.
- * @hide
- */
- public static final String RESET_DIALOG_LISTENER_BUNDLE_KEY = "dialogResetFlag";
-
- /**
- * The lookup key for a {@link #String} object.
- * Retrieve with {@link android.os.Bundle#getString(String)}.
- * @hide
- */
- public static final String WPS_PIN_BUNDLE_KEY = "wpsPin";
-
- /**
- * The lookup key for a {@link android.net.wifi.p2p.WifiP2pDevice} object
- * Retrieve with {@link android.os.Bundle#getParcelable(String)}.
- * @hide
- */
- public static final String P2P_DEV_BUNDLE_KEY = "wifiP2pDevice";
-
- /**
- * The lookup key for a {@link android.net.wifi.p2p.WifiP2pConfig} object
- * Retrieve with {@link android.os.Bundle#getParcelable(String)}.
- * @hide
- */
- public static final String P2P_CONFIG_BUNDLE_KEY = "wifiP2pConfig";
-
IWifiP2pManager mService;
private static final int BASE = Protocol.BASE_WIFI_P2P_MANAGER;
@@ -432,35 +396,23 @@ public class WifiP2pManager {
public static final int SET_DEVICE_NAME_SUCCEEDED = BASE + 53;
/** @hide */
- public static final int SET_DIALOG_LISTENER = BASE + 54;
- /** @hide */
- public static final int DIALOG_LISTENER_DETACHED = BASE + 55;
- /** @hide */
- public static final int DIALOG_LISTENER_ATTACHED = BASE + 56;
-
- /** @hide */
- public static final int CONNECTION_REQUESTED = BASE + 57;
- /** @hide */
- public static final int SHOW_PIN_REQUESTED = BASE + 58;
-
+ public static final int DELETE_PERSISTENT_GROUP = BASE + 54;
/** @hide */
- public static final int DELETE_PERSISTENT_GROUP = BASE + 59;
+ public static final int DELETE_PERSISTENT_GROUP_FAILED = BASE + 55;
/** @hide */
- public static final int DELETE_PERSISTENT_GROUP_FAILED = BASE + 60;
- /** @hide */
- public static final int DELETE_PERSISTENT_GROUP_SUCCEEDED = BASE + 61;
+ public static final int DELETE_PERSISTENT_GROUP_SUCCEEDED = BASE + 56;
/** @hide */
- public static final int REQUEST_PERSISTENT_GROUP_INFO = BASE + 62;
+ public static final int REQUEST_PERSISTENT_GROUP_INFO = BASE + 57;
/** @hide */
- public static final int RESPONSE_PERSISTENT_GROUP_INFO = BASE + 63;
+ public static final int RESPONSE_PERSISTENT_GROUP_INFO = BASE + 58;
/** @hide */
- public static final int SET_WFD_INFO = BASE + 64;
+ public static final int SET_WFD_INFO = BASE + 59;
/** @hide */
- public static final int SET_WFD_INFO_FAILED = BASE + 65;
+ public static final int SET_WFD_INFO_FAILED = BASE + 60;
/** @hide */
- public static final int SET_WFD_INFO_SUCCEEDED = BASE + 66;
+ public static final int SET_WFD_INFO_SUCCEEDED = BASE + 61;
/**
* Create a new WifiP2pManager instance. Applications use
@@ -501,14 +453,6 @@ public class WifiP2pManager {
*/
public static final int NO_SERVICE_REQUESTS = 3;
- /**
- * Passed with {@link DialogListener#onDetached}.
- * Indicates that the registered listener was detached from the system because
- * the application went into background.
- * @hide
- */
- public static final int NOT_IN_FOREGROUND = 4;
-
/** Interface for callback invocation when framework channel is lost */
public interface ChannelListener {
/**
@@ -640,49 +584,6 @@ public class WifiP2pManager {
}
- /**
- * Interface for callback invocation when dialog events are received.
- * see {@link #setDialogListener}.
- * @hide
- */
- public interface DialogListener {
-
- /**
- * Called by the system when a request to show WPS pin is received.
- *
- * @param pin WPS pin.
- */
- public void onShowPinRequested(String pin);
-
- /**
- * Called by the system when a request to establish the connection is received.
- *
- * Application can then call {@link #connect} with the given config if the request
- * is acceptable.
- *
- * @param device the source device.
- * @param config p2p configuration.
- */
- public void onConnectionRequested(WifiP2pDevice device, WifiP2pConfig config);
-
- /**
- * Called by the system when this listener was attached to the system.
- */
- public void onAttached();
-
- /**
- * Called by the system when this listener was detached from the system or
- * failed to attach.
- *
- * Application can request again using {@link #setDialogListener} when it is
- * in the foreground.
- *
- * @param reason The reason for failure could be one of {@link #ERROR},
- * {@link #BUSY}, {@link #P2P_UNSUPPORTED} or {@link #NOT_IN_FOREGROUND}
- */
- public void onDetached(int reason);
- }
-
/** Interface for callback invocation when stored group info list is available {@hide}*/
public interface PersistentGroupInfoListener {
/**
@@ -713,7 +614,6 @@ public class WifiP2pManager {
private HashMap<Integer, Object> mListenerMap = new HashMap<Integer, Object>();
private Object mListenerMapLock = new Object();
private int mListenerKey = 0;
- private DialogListener mDialogListener;
private AsyncChannel mAsyncChannel;
private P2pHandler mHandler;
@@ -797,34 +697,6 @@ public class WifiP2pManager {
WifiP2pServiceResponse resp = (WifiP2pServiceResponse) message.obj;
handleServiceResponse(resp);
break;
- case WifiP2pManager.CONNECTION_REQUESTED:
- if (mDialogListener != null) {
- Bundle bundle = message.getData();
- mDialogListener.onConnectionRequested(
- (WifiP2pDevice)bundle.getParcelable(
- P2P_DEV_BUNDLE_KEY),
- (WifiP2pConfig)bundle.getParcelable(
- P2P_CONFIG_BUNDLE_KEY));
- }
- break;
- case WifiP2pManager.SHOW_PIN_REQUESTED:
- if (mDialogListener != null) {
- Bundle bundle = message.getData();
- mDialogListener.onShowPinRequested(
- bundle.getString(WPS_PIN_BUNDLE_KEY));
- }
- break;
- case WifiP2pManager.DIALOG_LISTENER_ATTACHED:
- if (mDialogListener != null) {
- mDialogListener.onAttached();
- }
- break;
- case WifiP2pManager.DIALOG_LISTENER_DETACHED:
- if (mDialogListener != null) {
- mDialogListener.onDetached(message.arg1);
- mDialogListener = null;
- }
- break;
case WifiP2pManager.RESPONSE_PERSISTENT_GROUP_INFO:
WifiP2pGroupList groups = (WifiP2pGroupList) message.obj;
if (listener != null) {
@@ -897,10 +769,6 @@ public class WifiP2pManager {
return mListenerMap.remove(key);
}
}
-
- private void setDialogListener(DialogListener listener) {
- mDialogListener = listener;
- }
}
private static void checkChannel(Channel c) {
@@ -1314,41 +1182,6 @@ public class WifiP2pManager {
c.mAsyncChannel.sendMessage(SET_WFD_INFO, 0, c.putListener(listener), wfdInfo);
}
- /**
- * Set dialog listener to over-ride system dialogs on p2p events. This function
- * allows an application to receive notifications on connection requests from
- * peers so that it can customize the user experience for connection with
- * peers.
- *
- * <p> The function call immediately returns after sending a request
- * to the framework. The application is notified of a success or failure to attach
- * to the system through listener callbacks {@link DialogListener#onAttached} or
- * {@link DialogListener#onDetached}.
- *
- * <p> Note that only foreground application will be successful in overriding the
- * system dialogs.
- * @hide
- *
- * @param c is the channel created at {@link #initialize}
- * @param listener for callback on a dialog event.
- */
- public void setDialogListener(Channel c, DialogListener listener) {
- checkChannel(c);
- c.setDialogListener(listener);
-
- /**
- * mAsyncChannel should always stay private and inaccessible from the app
- * to prevent an app from sending a message with a fake app name to gain
- * control over the dialogs
- */
- Message msg = Message.obtain();
- Bundle bundle = new Bundle();
- bundle.putString(APP_PKG_BUNDLE_KEY, c.mContext.getPackageName());
- bundle.putBoolean(RESET_DIALOG_LISTENER_BUNDLE_KEY, listener == null);
- msg.what = SET_DIALOG_LISTENER;
- msg.setData(bundle);
- c.mAsyncChannel.sendMessage(msg);
- }
/**
* Delete a stored persistent group from the system settings.
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pService.java b/wifi/java/android/net/wifi/p2p/WifiP2pService.java
index 30764fb..ccd983d 100644
--- a/wifi/java/android/net/wifi/p2p/WifiP2pService.java
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pService.java
@@ -16,13 +16,10 @@
package android.net.wifi.p2p;
-import android.app.Activity;
-import android.app.ActivityManager;
import android.app.AlertDialog;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
-import android.app.ActivityManager.RunningTaskInfo;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
@@ -51,20 +48,16 @@ import android.net.wifi.p2p.nsd.WifiP2pServiceInfo;
import android.net.wifi.p2p.nsd.WifiP2pServiceRequest;
import android.net.wifi.p2p.nsd.WifiP2pServiceResponse;
import android.os.Binder;
-import android.os.Bundle;
import android.os.IBinder;
import android.os.INetworkManagementService;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import android.os.Messenger;
-import android.os.Parcel;
-import android.os.Parcelable;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemProperties;
import android.os.UserHandle;
-import android.os.Parcelable.Creator;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Slog;
@@ -114,8 +107,6 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
INetworkManagementService mNwService;
private DhcpStateMachine mDhcpStateMachine;
- private ActivityManager mActivityMgr;
-
private P2pStateMachine mP2pStateMachine;
private AsyncChannel mReplyChannel = new AsyncChannel();
private AsyncChannel mWifiChannel;
@@ -211,13 +202,6 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
/* clients(application) information list. */
private HashMap<Messenger, ClientInfo> mClientInfoList = new HashMap<Messenger, ClientInfo>();
- /* The foreground application's messenger.
- * The connection request is notified only to foreground application */
- private Messenger mForegroundAppMessenger;
-
- /* the package name of foreground application. */
- private String mForegroundAppPkgName;
-
/* Is chosen as a unique range to avoid conflict with
the range defined in Tethering.java */
private static final String[] DHCP_RANGE = {"192.168.49.2", "192.168.49.254"};
@@ -306,8 +290,6 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
//STOPSHIP: get this from native side
mInterface = "p2p0";
- mActivityMgr = (ActivityManager)context.getSystemService(Activity.ACTIVITY_SERVICE);
-
mNetworkInfo = new NetworkInfo(ConnectivityManager.TYPE_WIFI_P2P, 0, NETWORKTYPE, "");
mP2pSupported = mContext.getPackageManager().hasSystemFeature(
@@ -421,9 +403,6 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
// Saved WifiP2pGroup from invitation request
private WifiP2pGroup mSavedP2pGroup;
- // Saved WifiP2pDevice from provisioning request
- private WifiP2pDevice mSavedProvDiscDevice;
-
P2pStateMachine(String name, boolean p2pSupported) {
super(name);
@@ -562,18 +541,6 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
replyToMessage(message, WifiP2pManager.RESPONSE_PERSISTENT_GROUP_INFO,
new WifiP2pGroupList(mGroups, null));
break;
- case WifiP2pManager.SET_DIALOG_LISTENER:
- String appPkgName = (String)message.getData().getString(
- WifiP2pManager.APP_PKG_BUNDLE_KEY);
- boolean isReset = message.getData().getBoolean(
- WifiP2pManager.RESET_DIALOG_LISTENER_BUNDLE_KEY);
- if (setDialogListenerApp(message.replyTo, appPkgName, isReset)) {
- replyToMessage(message, WifiP2pManager.DIALOG_LISTENER_ATTACHED);
- } else {
- replyToMessage(message, WifiP2pManager.DIALOG_LISTENER_DETACHED,
- WifiP2pManager.NOT_IN_FOREGROUND);
- }
- break;
// Ignore
case WifiMonitor.P2P_INVITATION_RESULT_EVENT:
case WifiMonitor.SCAN_RESULTS_EVENT:
@@ -666,10 +633,6 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
replyToMessage(message, WifiP2pManager.ADD_LOCAL_SERVICE_FAILED,
WifiP2pManager.P2P_UNSUPPORTED);
break;
- case WifiP2pManager.SET_DIALOG_LISTENER:
- replyToMessage(message, WifiP2pManager.DIALOG_LISTENER_DETACHED,
- WifiP2pManager.P2P_UNSUPPORTED);
- break;
case WifiP2pManager.REMOVE_LOCAL_SERVICE:
replyToMessage(message, WifiP2pManager.REMOVE_LOCAL_SERVICE_FAILED,
WifiP2pManager.P2P_UNSUPPORTED);
@@ -1022,10 +985,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
mSavedPeerConfig = (WifiP2pConfig) message.obj;
mAutonomousGroup = false;
mJoinExistingGroup = false;
- if (!sendConnectNoticeToApp(mPeers.get(mSavedPeerConfig.deviceAddress),
- mSavedPeerConfig)) {
- transitionTo(mUserAuthorizingInvitationState);
- }
+ transitionTo(mUserAuthorizingInvitationState);
break;
case WifiMonitor.P2P_INVITATION_RECEIVED_EVENT:
WifiP2pGroup group = (WifiP2pGroup) message.obj;
@@ -1053,11 +1013,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
mAutonomousGroup = false;
mJoinExistingGroup = true;
- //TODO In the p2p client case, we should set source address correctly.
- if (!sendConnectNoticeToApp(mPeers.get(mSavedPeerConfig.deviceAddress),
- mSavedPeerConfig)) {
- transitionTo(mUserAuthorizingInvitationState);
- }
+ transitionTo(mUserAuthorizingInvitationState);
break;
case WifiMonitor.P2P_PROV_DISC_PBC_REQ_EVENT:
case WifiMonitor.P2P_PROV_DISC_ENTER_PIN_EVENT:
@@ -1251,10 +1207,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
transitionTo(mGroupNegotiationState);
} else {
mJoinExistingGroup = false;
- if (!sendConnectNoticeToApp(mPeers.get(mSavedPeerConfig.deviceAddress),
- mSavedPeerConfig)) {
- transitionTo(mUserAuthorizingInvitationState);
- }
+ transitionTo(mUserAuthorizingInvitationState);
}
}
break;
@@ -1267,9 +1220,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
if (DBG) logd("Found a match " + mSavedPeerConfig);
mSavedPeerConfig.wps.pin = provDisc.pin;
p2pConnectWithPinDisplay(mSavedPeerConfig);
- if (!sendShowPinReqToFrontApp(provDisc.pin)) {
- notifyInvitationSent(provDisc.pin, device.deviceAddress);
- }
+ notifyInvitationSent(provDisc.pin, device.deviceAddress);
transitionTo(mGroupNegotiationState);
}
break;
@@ -1519,10 +1470,6 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
WifiP2pDevice device = (WifiP2pDevice) message.obj;
String deviceAddress = device.deviceAddress;
if (deviceAddress != null) {
- if (mSavedProvDiscDevice != null &&
- deviceAddress.equals(mSavedProvDiscDevice.deviceAddress)) {
- mSavedProvDiscDevice = null;
- }
if (mPeers.get(deviceAddress) != null) {
mGroup.addClient(mPeers.get(deviceAddress));
} else {
@@ -1622,34 +1569,26 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
break;
case WifiP2pManager.CONNECT:
WifiP2pConfig config = (WifiP2pConfig) message.obj;
- if (config.deviceAddress == null ||
- (mSavedProvDiscDevice != null &&
- mSavedProvDiscDevice.deviceAddress.equals(
- config.deviceAddress))) {
- if (config.wps.setup == WpsInfo.PBC) {
- mWifiNative.startWpsPbc(mGroup.getInterface(), null);
- } else {
- if (config.wps.pin == null) {
- String pin = mWifiNative.startWpsPinDisplay(mGroup.getInterface());
- try {
- Integer.parseInt(pin);
- if (!sendShowPinReqToFrontApp(pin)) {
- notifyInvitationSent(pin,
- config.deviceAddress != null ?
- config.deviceAddress : "any");
- }
- } catch (NumberFormatException ignore) {
- // do nothing if pin is invalid
- }
- } else {
- mWifiNative.startWpsPinKeypad(mGroup.getInterface(),
- config.wps.pin);
- }
- }
- if (config.deviceAddress != null) {
- mPeers.updateStatus(config.deviceAddress, WifiP2pDevice.INVITED);
- sendP2pPeersChangedBroadcast();
- }
+ // This allows any client to join the GO during the
+ // WPS window
+ if (config.deviceAddress == null) {
+ if (config.wps.setup == WpsInfo.PBC) {
+ mWifiNative.startWpsPbc(mGroup.getInterface(), null);
+ } else {
+ if (config.wps.pin == null) {
+ String pin = mWifiNative.startWpsPinDisplay(mGroup.getInterface());
+ try {
+ Integer.parseInt(pin);
+ notifyInvitationSent(pin, config.deviceAddress != null ?
+ config.deviceAddress : "any");
+ } catch (NumberFormatException ignore) {
+ // do nothing if pin is invalid
+ }
+ } else {
+ mWifiNative.startWpsPinKeypad(mGroup.getInterface(),
+ config.wps.pin);
+ }
+ }
replyToMessage(message, WifiP2pManager.CONNECT_SUCCEEDED);
} else {
logd("Inviting device : " + config.deviceAddress);
@@ -1692,7 +1631,6 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
case WifiMonitor.P2P_PROV_DISC_ENTER_PIN_EVENT:
case WifiMonitor.P2P_PROV_DISC_SHOW_PIN_EVENT:
WifiP2pProvDiscEvent provDisc = (WifiP2pProvDiscEvent) message.obj;
- mSavedProvDiscDevice = provDisc.device;
mSavedPeerConfig = new WifiP2pConfig();
mSavedPeerConfig.deviceAddress = provDisc.device.deviceAddress;
if (message.what == WifiMonitor.P2P_PROV_DISC_ENTER_PIN_EVENT) {
@@ -1703,9 +1641,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
} else {
mSavedPeerConfig.wps.setup = WpsInfo.PBC;
}
- if (!sendConnectNoticeToApp(mSavedProvDiscDevice, mSavedPeerConfig)) {
- transitionTo(mUserAuthorizingJoinState);
- }
+ transitionTo(mUserAuthorizingJoinState);
break;
case WifiMonitor.P2P_GROUP_STARTED_EVENT:
Slog.e(TAG, "Duplicate group creation event notice, ignore");
@@ -1717,7 +1653,6 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
}
public void exit() {
- mSavedProvDiscDevice = null;
updateThisDevice(WifiP2pDevice.AVAILABLE);
resetWifiP2pInfo();
mNetworkInfo.setDetailedState(NetworkInfo.DetailedState.DISCONNECTED, null, null);
@@ -1799,7 +1734,6 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
pw.println("mGroup " + mGroup);
pw.println("mSavedPeerConfig " + mSavedPeerConfig);
pw.println("mSavedP2pGroup " + mSavedP2pGroup);
- pw.println("mSavedProvDiscDevice " + mSavedProvDiscDevice);
pw.println();
}
@@ -2285,9 +2219,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
String pin = mWifiNative.p2pConnect(config, dev.isGroupOwner());
try {
Integer.parseInt(pin);
- if (!sendShowPinReqToFrontApp(pin)) {
- notifyInvitationSent(pin, config.deviceAddress);
- }
+ notifyInvitationSent(pin, config.deviceAddress);
} catch (NumberFormatException ignore) {
// do nothing if p2pConnect did not return a pin
}
@@ -2720,139 +2652,6 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
return clientInfo;
}
- /**
- * Send detached message to dialog listener in the foreground application.
- * @param reason
- */
- private void sendDetachedMsg(int reason) {
- if (mForegroundAppMessenger == null) return;
-
- Message msg = Message.obtain();
- msg.what = WifiP2pManager.DIALOG_LISTENER_DETACHED;
- msg.arg1 = reason;
- try {
- mForegroundAppMessenger.send(msg);
- } catch (RemoteException e) {
- }
- mForegroundAppMessenger = null;
- mForegroundAppPkgName = null;
- }
-
- /**
- * Send a request to show wps pin to dialog listener in the foreground application.
- * @param pin WPS pin
- * @return
- */
- private boolean sendShowPinReqToFrontApp(String pin) {
- if (!isForegroundApp(mForegroundAppPkgName)) {
- sendDetachedMsg(WifiP2pManager.NOT_IN_FOREGROUND);
- return false;
- }
- Message msg = Message.obtain();
- msg.what = WifiP2pManager.SHOW_PIN_REQUESTED;
- Bundle bundle = new Bundle();
- bundle.putString(WifiP2pManager.WPS_PIN_BUNDLE_KEY, pin);
- msg.setData(bundle);
- return sendDialogMsgToFrontApp(msg);
- }
-
- /**
- * Send a request to establish the connection to dialog listener in the foreground
- * application.
- * @param dev source device
- * @param config
- * @return
- */
- private boolean sendConnectNoticeToApp(WifiP2pDevice dev, WifiP2pConfig config) {
- if (dev == null) {
- dev = new WifiP2pDevice(config.deviceAddress);
- }
-
- if (!isForegroundApp(mForegroundAppPkgName)) {
- if (DBG) logd("application is NOT foreground");
- sendDetachedMsg(WifiP2pManager.NOT_IN_FOREGROUND);
- return false;
- }
-
- Message msg = Message.obtain();
- msg.what = WifiP2pManager.CONNECTION_REQUESTED;
- Bundle bundle = new Bundle();
- bundle.putParcelable(WifiP2pManager.P2P_DEV_BUNDLE_KEY, dev);
- bundle.putParcelable(WifiP2pManager.P2P_CONFIG_BUNDLE_KEY, config);
- msg.setData(bundle);
- return sendDialogMsgToFrontApp(msg);
- }
-
- /**
- * Send dialog event message to front application's dialog listener.
- * @param msg
- * @return true if success.
- */
- private boolean sendDialogMsgToFrontApp(Message msg) {
- try {
- mForegroundAppMessenger.send(msg);
- } catch (RemoteException e) {
- mForegroundAppMessenger = null;
- mForegroundAppPkgName = null;
- return false;
- }
- return true;
- }
-
- /**
- * Set dialog listener application.
- * @param m
- * @param appPkgName if null, reset the listener.
- * @param isReset if true, try to reset.
- * @return
- */
- private boolean setDialogListenerApp(Messenger m,
- String appPkgName, boolean isReset) {
-
- if (mForegroundAppPkgName != null && !mForegroundAppPkgName.equals(appPkgName)) {
- if (isForegroundApp(mForegroundAppPkgName)) {
- // The current dialog listener is foreground app's.
- if (DBG) logd("application is NOT foreground");
- return false;
- }
- // detach an old listener.
- sendDetachedMsg(WifiP2pManager.NOT_IN_FOREGROUND);
- }
-
- if (isReset) {
- if (DBG) logd("reset dialog listener");
- mForegroundAppMessenger = null;
- mForegroundAppPkgName = null;
- return true;
- }
-
- if (!isForegroundApp(appPkgName)) {
- return false;
- }
-
- mForegroundAppMessenger = m;
- mForegroundAppPkgName = appPkgName;
- if (DBG) logd("set dialog listener. app=" + appPkgName);
- return true;
- }
-
- /**
- * Return true if the specified package name is foreground app's.
- *
- * @param pkgName application package name.
- * @return
- */
- private boolean isForegroundApp(String pkgName) {
- if (pkgName == null) return false;
-
- List<RunningTaskInfo> tasks = mActivityMgr.getRunningTasks(1);
- if (tasks.size() == 0) {
- return false;
- }
-
- return pkgName.equals(tasks.get(0).baseActivity.getPackageName());
- }
-
}
/**