diff options
Diffstat (limited to 'core/java')
36 files changed, 1389 insertions, 822 deletions
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index ccd65de..c9351af 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -416,7 +416,7 @@ public class Notification implements Parcelable if (this.largeIcon != null) { that.largeIcon = Bitmap.createBitmap(this.largeIcon); } - that.iconLevel = that.iconLevel; + that.iconLevel = this.iconLevel; that.sound = this.sound; // android.net.Uri is immutable that.audioStreamType = this.audioStreamType; diff --git a/core/java/android/bluetooth/BluetoothDeviceProfileState.java b/core/java/android/bluetooth/BluetoothDeviceProfileState.java index 9855709..6f3a2e7 100644 --- a/core/java/android/bluetooth/BluetoothDeviceProfileState.java +++ b/core/java/android/bluetooth/BluetoothDeviceProfileState.java @@ -26,8 +26,8 @@ import android.server.BluetoothA2dpService; import android.server.BluetoothService; import android.util.Log; -import com.android.internal.util.HierarchicalState; -import com.android.internal.util.HierarchicalStateMachine; +import com.android.internal.util.State; +import com.android.internal.util.StateMachine; import java.util.Set; @@ -57,7 +57,7 @@ import java.util.Set; * Todo(): Write tests for this class, when the Android Mock support is completed. * @hide */ -public final class BluetoothDeviceProfileState extends HierarchicalStateMachine { +public final class BluetoothDeviceProfileState extends StateMachine { private static final String TAG = "BluetoothDeviceProfileState"; private static final boolean DBG = false; @@ -235,16 +235,16 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine } } - private class BondedDevice extends HierarchicalState { + private class BondedDevice extends State { @Override - protected void enter() { + public void enter() { Log.i(TAG, "Entering ACL Connected state with: " + getCurrentMessage().what); Message m = new Message(); m.copyFrom(getCurrentMessage()); sendMessageAtFrontOfQueue(m); } @Override - protected boolean processMessage(Message message) { + public boolean processMessage(Message message) { log("ACL Connected State -> Processing Message: " + message.what); switch(message.what) { case CONNECT_HFP_OUTGOING: @@ -353,12 +353,12 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine } } - private class OutgoingHandsfree extends HierarchicalState { + private class OutgoingHandsfree extends State { private boolean mStatus = false; private int mCommand; @Override - protected void enter() { + public void enter() { Log.i(TAG, "Entering OutgoingHandsfree state with: " + getCurrentMessage().what); mCommand = getCurrentMessage().what; if (mCommand != CONNECT_HFP_OUTGOING && @@ -374,7 +374,7 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine } @Override - protected boolean processMessage(Message message) { + public boolean processMessage(Message message) { log("OutgoingHandsfree State -> Processing Message: " + message.what); Message deferMsg = new Message(); int command = message.what; @@ -466,12 +466,12 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine } } - private class IncomingHandsfree extends HierarchicalState { + private class IncomingHandsfree extends State { private boolean mStatus = false; private int mCommand; @Override - protected void enter() { + public void enter() { Log.i(TAG, "Entering IncomingHandsfree state with: " + getCurrentMessage().what); mCommand = getCurrentMessage().what; if (mCommand != CONNECT_HFP_INCOMING && @@ -487,7 +487,7 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine } @Override - protected boolean processMessage(Message message) { + public boolean processMessage(Message message) { log("IncomingHandsfree State -> Processing Message: " + message.what); switch(message.what) { case CONNECT_HFP_OUTGOING: @@ -546,12 +546,12 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine } } - private class OutgoingA2dp extends HierarchicalState { + private class OutgoingA2dp extends State { private boolean mStatus = false; private int mCommand; @Override - protected void enter() { + public void enter() { Log.i(TAG, "Entering OutgoingA2dp state with: " + getCurrentMessage().what); mCommand = getCurrentMessage().what; if (mCommand != CONNECT_A2DP_OUTGOING && @@ -567,7 +567,7 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine } @Override - protected boolean processMessage(Message message) { + public boolean processMessage(Message message) { log("OutgoingA2dp State->Processing Message: " + message.what); Message deferMsg = new Message(); switch(message.what) { @@ -656,12 +656,12 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine } } - private class IncomingA2dp extends HierarchicalState { + private class IncomingA2dp extends State { private boolean mStatus = false; private int mCommand; @Override - protected void enter() { + public void enter() { Log.i(TAG, "Entering IncomingA2dp state with: " + getCurrentMessage().what); mCommand = getCurrentMessage().what; if (mCommand != CONNECT_A2DP_INCOMING && @@ -677,7 +677,7 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine } @Override - protected boolean processMessage(Message message) { + public boolean processMessage(Message message) { log("IncomingA2dp State->Processing Message: " + message.what); Message deferMsg = new Message(); switch(message.what) { @@ -735,12 +735,12 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine } - private class OutgoingHid extends HierarchicalState { + private class OutgoingHid extends State { private boolean mStatus = false; private int mCommand; @Override - protected void enter() { + public void enter() { log("Entering OutgoingHid state with: " + getCurrentMessage().what); mCommand = getCurrentMessage().what; if (mCommand != CONNECT_HID_OUTGOING && @@ -752,7 +752,7 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine } @Override - protected boolean processMessage(Message message) { + public boolean processMessage(Message message) { log("OutgoingHid State->Processing Message: " + message.what); Message deferMsg = new Message(); switch(message.what) { @@ -816,12 +816,12 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine } } - private class IncomingHid extends HierarchicalState { + private class IncomingHid extends State { private boolean mStatus = false; private int mCommand; @Override - protected void enter() { + public void enter() { log("Entering IncomingHid state with: " + getCurrentMessage().what); mCommand = getCurrentMessage().what; if (mCommand != CONNECT_HID_INCOMING && @@ -833,7 +833,7 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine } @Override - protected boolean processMessage(Message message) { + public boolean processMessage(Message message) { log("IncomingHid State->Processing Message: " + message.what); Message deferMsg = new Message(); switch(message.what) { diff --git a/core/java/android/bluetooth/BluetoothProfileState.java b/core/java/android/bluetooth/BluetoothProfileState.java index 18060a0..98afdb8 100644 --- a/core/java/android/bluetooth/BluetoothProfileState.java +++ b/core/java/android/bluetooth/BluetoothProfileState.java @@ -22,8 +22,8 @@ import android.content.IntentFilter; import android.os.Message; import android.util.Log; -import com.android.internal.util.HierarchicalState; -import com.android.internal.util.HierarchicalStateMachine; +import com.android.internal.util.State; +import com.android.internal.util.StateMachine; /** * This state machine is used to serialize the connections @@ -39,7 +39,7 @@ import com.android.internal.util.HierarchicalStateMachine; * @hide */ -public class BluetoothProfileState extends HierarchicalStateMachine { +public class BluetoothProfileState extends StateMachine { private static final boolean DBG = true; private static final String TAG = "BluetoothProfileState"; @@ -101,15 +101,15 @@ public class BluetoothProfileState extends HierarchicalStateMachine { context.registerReceiver(mBroadcastReceiver, filter); } - private class StableState extends HierarchicalState { + private class StableState extends State { @Override - protected void enter() { + public void enter() { log("Entering Stable State"); mPendingDevice = null; } @Override - protected boolean processMessage(Message msg) { + public boolean processMessage(Message msg) { if (msg.what != TRANSITION_TO_STABLE) { transitionTo(mPendingCommandState); } @@ -117,15 +117,15 @@ public class BluetoothProfileState extends HierarchicalStateMachine { } } - private class PendingCommandState extends HierarchicalState { + private class PendingCommandState extends State { @Override - protected void enter() { + public void enter() { log("Entering PendingCommandState State"); dispatchMessage(getCurrentMessage()); } @Override - protected boolean processMessage(Message msg) { + public boolean processMessage(Message msg) { if (msg.what == TRANSITION_TO_STABLE) { transitionTo(mStableState); } else { diff --git a/core/java/android/bluetooth/BluetoothTetheringDataTracker.java b/core/java/android/bluetooth/BluetoothTetheringDataTracker.java index c08f14f..a7b0037 100644 --- a/core/java/android/bluetooth/BluetoothTetheringDataTracker.java +++ b/core/java/android/bluetooth/BluetoothTetheringDataTracker.java @@ -300,4 +300,8 @@ public class BluetoothTetheringDataTracker implements NetworkStateTracker { msg = mCsHandler.obtainMessage(EVENT_STATE_CHANGED, mNetworkInfo); msg.sendToTarget(); } + + public void setDependencyMet(boolean met) { + // not supported on this network + } } diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java index b305e02..eaf9191 100644 --- a/core/java/android/net/ConnectivityManager.java +++ b/core/java/android/net/ConnectivityManager.java @@ -218,15 +218,35 @@ public class ConnectivityManager /** {@hide} */ public static final int TYPE_DUMMY = 8; + /** * The Default Ethernet data connection. When active, all data traffic * will use this connection by default. */ public static final int TYPE_ETHERNET = 9; - /** {@hide} TODO: Need to adjust this for WiMAX. */ - public static final int MAX_RADIO_TYPE = TYPE_ETHERNET; - /** {@hide} TODO: Need to adjust this for WiMAX. */ - public static final int MAX_NETWORK_TYPE = TYPE_ETHERNET; + /** + * Over the air Adminstration. + * {@hide} + */ + public static final int TYPE_MOBILE_FOTA = 10; + + /** + * IP Multimedia Subsystem + * {@hide} + */ + public static final int TYPE_MOBILE_IMS = 11; + + /** + * Carrier Branded Services + * {@hide} + */ + public static final int TYPE_MOBILE_CBS = 12; + + /** {@hide} */ + public static final int MAX_RADIO_TYPE = TYPE_MOBILE_CBS; + + /** {@hide} */ + public static final int MAX_NETWORK_TYPE = TYPE_MOBILE_CBS; public static final int DEFAULT_NETWORK_PREFERENCE = TYPE_WIFI; @@ -670,4 +690,16 @@ public class ConnectivityManager return null; } } + + /** + * @param networkType The network who's dependence has changed + * @param met Boolean - true if network use is ok, false if not + * {@hide} + */ + public void setDataDependency(int networkType, boolean met) { + try { + mService.setDataDependency(networkType, met); + } catch (RemoteException e) { + } + } } diff --git a/core/java/android/net/DhcpInfoInternal.java b/core/java/android/net/DhcpInfoInternal.java index 7396669..860da0a 100644 --- a/core/java/android/net/DhcpInfoInternal.java +++ b/core/java/android/net/DhcpInfoInternal.java @@ -22,6 +22,8 @@ import android.util.Log; import java.net.InetAddress; import java.net.Inet4Address; import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.Collection; /** * A simple object for retrieving the results of a DHCP request. @@ -31,7 +33,6 @@ import java.net.UnknownHostException; public class DhcpInfoInternal { private final static String TAG = "DhcpInfoInternal"; public String ipAddress; - public String gateway; public int prefixLength; public String dns1; @@ -40,7 +41,14 @@ public class DhcpInfoInternal { public String serverAddress; public int leaseDuration; + private Collection<RouteInfo> routes; + public DhcpInfoInternal() { + routes = new ArrayList<RouteInfo>(); + } + + public void addRoute(RouteInfo routeInfo) { + routes.add(routeInfo); } private int convertToInt(String addr) { @@ -58,7 +66,12 @@ public class DhcpInfoInternal { public DhcpInfo makeDhcpInfo() { DhcpInfo info = new DhcpInfo(); info.ipAddress = convertToInt(ipAddress); - info.gateway = convertToInt(gateway); + for (RouteInfo route : routes) { + if (route.isDefaultRoute()) { + info.gateway = convertToInt(route.getGateway().getHostAddress()); + break; + } + } try { InetAddress inetAddress = NetworkUtils.numericToInetAddress(ipAddress); info.netmask = NetworkUtils.prefixLengthToNetmaskInt(prefixLength); @@ -81,8 +94,8 @@ public class DhcpInfoInternal { public LinkProperties makeLinkProperties() { LinkProperties p = new LinkProperties(); p.addLinkAddress(makeLinkAddress()); - if (TextUtils.isEmpty(gateway) == false) { - p.addGateway(NetworkUtils.numericToInetAddress(gateway)); + for (RouteInfo route : routes) { + p.addRoute(route); } if (TextUtils.isEmpty(dns1) == false) { p.addDns(NetworkUtils.numericToInetAddress(dns1)); @@ -98,8 +111,10 @@ public class DhcpInfoInternal { } public String toString() { + String routeString = ""; + for (RouteInfo route : routes) routeString += route.toString() + " | "; return "addr: " + ipAddress + "/" + prefixLength + - " gateway: " + gateway + + " routes: " + routeString + " dns: " + dns1 + "," + dns2 + " dhcpServer: " + serverAddress + " leaseDuration: " + leaseDuration; diff --git a/core/java/android/net/DhcpStateMachine.java b/core/java/android/net/DhcpStateMachine.java index f5cf14b..eaf087f 100644 --- a/core/java/android/net/DhcpStateMachine.java +++ b/core/java/android/net/DhcpStateMachine.java @@ -17,8 +17,8 @@ package android.net; import com.android.internal.util.Protocol; -import com.android.internal.util.HierarchicalState; -import com.android.internal.util.HierarchicalStateMachine; +import com.android.internal.util.State; +import com.android.internal.util.StateMachine; import android.app.AlarmManager; import android.app.PendingIntent; @@ -47,14 +47,14 @@ import android.util.Log; * * @hide */ -public class DhcpStateMachine extends HierarchicalStateMachine { +public class DhcpStateMachine extends StateMachine { private static final String TAG = "DhcpStateMachine"; private static final boolean DBG = false; /* A StateMachine that controls the DhcpStateMachine */ - private HierarchicalStateMachine mController; + private StateMachine mController; private Context mContext; private BroadcastReceiver mBroadcastReceiver; @@ -95,13 +95,13 @@ public class DhcpStateMachine extends HierarchicalStateMachine { public static final int DHCP_SUCCESS = 1; public static final int DHCP_FAILURE = 2; - private HierarchicalState mDefaultState = new DefaultState(); - private HierarchicalState mStoppedState = new StoppedState(); - private HierarchicalState mWaitBeforeStartState = new WaitBeforeStartState(); - private HierarchicalState mRunningState = new RunningState(); - private HierarchicalState mWaitBeforeRenewalState = new WaitBeforeRenewalState(); + private State mDefaultState = new DefaultState(); + private State mStoppedState = new StoppedState(); + private State mWaitBeforeStartState = new WaitBeforeStartState(); + private State mRunningState = new RunningState(); + private State mWaitBeforeRenewalState = new WaitBeforeRenewalState(); - private DhcpStateMachine(Context context, HierarchicalStateMachine controller, String intf) { + private DhcpStateMachine(Context context, StateMachine controller, String intf) { super(TAG); mContext = context; @@ -136,7 +136,7 @@ public class DhcpStateMachine extends HierarchicalStateMachine { setInitialState(mStoppedState); } - public static DhcpStateMachine makeDhcpStateMachine(Context context, HierarchicalStateMachine controller, + public static DhcpStateMachine makeDhcpStateMachine(Context context, StateMachine controller, String intf) { DhcpStateMachine dsm = new DhcpStateMachine(context, controller, intf); dsm.start(); @@ -156,7 +156,7 @@ public class DhcpStateMachine extends HierarchicalStateMachine { mRegisteredForPreDhcpNotification = true; } - class DefaultState extends HierarchicalState { + class DefaultState extends State { @Override public boolean processMessage(Message message) { if (DBG) Log.d(TAG, getName() + message.toString() + "\n"); @@ -164,7 +164,7 @@ public class DhcpStateMachine extends HierarchicalStateMachine { case CMD_RENEW_DHCP: Log.e(TAG, "Error! Failed to handle a DHCP renewal on " + mInterfaceName); break; - case HSM_QUIT_CMD: + case SM_QUIT_CMD: mContext.unregisterReceiver(mBroadcastReceiver); //let parent kill the state machine return NOT_HANDLED; @@ -177,7 +177,7 @@ public class DhcpStateMachine extends HierarchicalStateMachine { } - class StoppedState extends HierarchicalState { + class StoppedState extends State { @Override public void enter() { if (DBG) Log.d(TAG, getName() + "\n"); @@ -210,7 +210,7 @@ public class DhcpStateMachine extends HierarchicalStateMachine { } } - class WaitBeforeStartState extends HierarchicalState { + class WaitBeforeStartState extends State { @Override public void enter() { if (DBG) Log.d(TAG, getName() + "\n"); @@ -242,7 +242,7 @@ public class DhcpStateMachine extends HierarchicalStateMachine { } } - class RunningState extends HierarchicalState { + class RunningState extends State { @Override public void enter() { if (DBG) Log.d(TAG, getName() + "\n"); @@ -281,7 +281,7 @@ public class DhcpStateMachine extends HierarchicalStateMachine { } } - class WaitBeforeRenewalState extends HierarchicalState { + class WaitBeforeRenewalState extends State { @Override public void enter() { if (DBG) Log.d(TAG, getName() + "\n"); diff --git a/core/java/android/net/DummyDataStateTracker.java b/core/java/android/net/DummyDataStateTracker.java index d0c77cf..e39725a 100644 --- a/core/java/android/net/DummyDataStateTracker.java +++ b/core/java/android/net/DummyDataStateTracker.java @@ -191,6 +191,10 @@ public class DummyDataStateTracker implements NetworkStateTracker { return new LinkCapabilities(mLinkCapabilities); } + public void setDependencyMet(boolean met) { + // not supported on this network + } + static private void log(String s) { Slog.d(TAG, s); } diff --git a/core/java/android/net/EthernetDataTracker.java b/core/java/android/net/EthernetDataTracker.java index df5fdd0..55850c9 100644 --- a/core/java/android/net/EthernetDataTracker.java +++ b/core/java/android/net/EthernetDataTracker.java @@ -330,4 +330,8 @@ public class EthernetDataTracker implements NetworkStateTracker { public String getTcpBufferSizesPropName() { return "net.tcp.buffersize.wifi"; } + + public void setDependencyMet(boolean met) { + // not supported on this network + } } diff --git a/core/java/android/net/IConnectivityManager.aidl b/core/java/android/net/IConnectivityManager.aidl index 70ab4f1..8be492c 100644 --- a/core/java/android/net/IConnectivityManager.aidl +++ b/core/java/android/net/IConnectivityManager.aidl @@ -92,4 +92,6 @@ interface IConnectivityManager void setGlobalProxy(in ProxyProperties p); ProxyProperties getProxy(); + + void setDataDependency(int networkType, boolean met); } diff --git a/core/java/android/net/LinkAddress.java b/core/java/android/net/LinkAddress.java index 9c36b12..f6a114c 100644 --- a/core/java/android/net/LinkAddress.java +++ b/core/java/android/net/LinkAddress.java @@ -78,6 +78,14 @@ public class LinkAddress implements Parcelable { this.prefixLength == linkAddress.prefixLength; } + @Override + /* + * generate hashcode based on significant fields + */ + public int hashCode() { + return ((null == address) ? 0 : address.hashCode()) + prefixLength; + } + /** * Returns the InetAddress for this address. */ diff --git a/core/java/android/net/LinkProperties.java b/core/java/android/net/LinkProperties.java index b6e9751..19894a0 100644 --- a/core/java/android/net/LinkProperties.java +++ b/core/java/android/net/LinkProperties.java @@ -19,11 +19,9 @@ package android.net; import android.net.ProxyProperties; import android.os.Parcelable; import android.os.Parcel; -import android.util.Log; +import android.text.TextUtils; import java.net.InetAddress; -import java.net.NetworkInterface; -import java.net.SocketException; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Collection; @@ -56,7 +54,7 @@ public class LinkProperties implements Parcelable { String mIfaceName; private Collection<LinkAddress> mLinkAddresses; private Collection<InetAddress> mDnses; - private Collection<InetAddress> mGateways; + private Collection<RouteInfo> mRoutes; private ProxyProperties mHttpProxy; public LinkProperties() { @@ -69,8 +67,9 @@ public class LinkProperties implements Parcelable { mIfaceName = source.getInterfaceName(); mLinkAddresses = source.getLinkAddresses(); mDnses = source.getDnses(); - mGateways = source.getGateways(); - mHttpProxy = new ProxyProperties(source.getHttpProxy()); + mRoutes = source.getRoutes(); + mHttpProxy = (source.getHttpProxy() == null) ? + null : new ProxyProperties(source.getHttpProxy()); } } @@ -91,7 +90,7 @@ public class LinkProperties implements Parcelable { } public void addLinkAddress(LinkAddress address) { - mLinkAddresses.add(address); + if (address != null) mLinkAddresses.add(address); } public Collection<LinkAddress> getLinkAddresses() { @@ -99,18 +98,18 @@ public class LinkProperties implements Parcelable { } public void addDns(InetAddress dns) { - mDnses.add(dns); + if (dns != null) mDnses.add(dns); } public Collection<InetAddress> getDnses() { return Collections.unmodifiableCollection(mDnses); } - public void addGateway(InetAddress gateway) { - mGateways.add(gateway); + public void addRoute(RouteInfo route) { + if (route != null) mRoutes.add(route); } - public Collection<InetAddress> getGateways() { - return Collections.unmodifiableCollection(mGateways); + public Collection<RouteInfo> getRoutes() { + return Collections.unmodifiableCollection(mRoutes); } public void setHttpProxy(ProxyProperties proxy) { @@ -124,7 +123,7 @@ public class LinkProperties implements Parcelable { mIfaceName = null; mLinkAddresses = new ArrayList<LinkAddress>(); mDnses = new ArrayList<InetAddress>(); - mGateways = new ArrayList<InetAddress>(); + mRoutes = new ArrayList<RouteInfo>(); mHttpProxy = null; } @@ -141,19 +140,80 @@ public class LinkProperties implements Parcelable { String ifaceName = (mIfaceName == null ? "" : "InterfaceName: " + mIfaceName + " "); String linkAddresses = "LinkAddresses: ["; - for (LinkAddress addr : mLinkAddresses) linkAddresses += addr.toString(); + for (LinkAddress addr : mLinkAddresses) linkAddresses += addr.toString() + ","; linkAddresses += "] "; String dns = "DnsAddresses: ["; for (InetAddress addr : mDnses) dns += addr.getHostAddress() + ","; dns += "] "; - String gateways = "Gateways: ["; - for (InetAddress gw : mGateways) gateways += gw.getHostAddress() + ","; - gateways += "] "; + String routes = "Routes: ["; + for (RouteInfo route : mRoutes) routes += route.toString() + ","; + routes += "] "; String proxy = (mHttpProxy == null ? "" : "HttpProxy: " + mHttpProxy.toString() + " "); - return ifaceName + linkAddresses + gateways + dns + proxy; + return ifaceName + linkAddresses + routes + dns + proxy; + } + + + @Override + /** + * Compares this {@code LinkProperties} instance against the target + * LinkProperties in {@code obj}. Two LinkPropertieses are equal if + * all their fields are equal in values. + * + * For collection fields, such as mDnses, containsAll() is used to check + * if two collections contains the same elements, independent of order. + * There are two thoughts regarding containsAll() + * 1. Duplicated elements. eg, (A, B, B) and (A, A, B) are equal. + * 2. Worst case performance is O(n^2). + * + * @param obj the object to be tested for equality. + * @return {@code true} if both objects are equal, {@code false} otherwise. + */ + public boolean equals(Object obj) { + if (this == obj) return true; + + if (!(obj instanceof LinkProperties)) return false; + + boolean sameAddresses; + boolean sameDnses; + boolean sameRoutes; + + LinkProperties target = (LinkProperties) obj; + + Collection<InetAddress> targetAddresses = target.getAddresses(); + Collection<InetAddress> sourceAddresses = getAddresses(); + sameAddresses = (sourceAddresses.size() == targetAddresses.size()) ? + sourceAddresses.containsAll(targetAddresses) : false; + + Collection<InetAddress> targetDnses = target.getDnses(); + sameDnses = (mDnses.size() == targetDnses.size()) ? + mDnses.containsAll(targetDnses) : false; + + Collection<RouteInfo> targetRoutes = target.getRoutes(); + sameRoutes = (mRoutes.size() == targetRoutes.size()) ? + mRoutes.containsAll(targetRoutes) : false; + + return + sameAddresses && sameDnses && sameRoutes + && TextUtils.equals(getInterfaceName(), target.getInterfaceName()) + && (getHttpProxy() == null ? target.getHttpProxy() == null : + getHttpProxy().equals(target.getHttpProxy())); + } + + @Override + /** + * generate hashcode based on significant fields + * Equal objects must produce the same hash code, while unequal objects + * may have the same hash codes. + */ + public int hashCode() { + return ((null == mIfaceName) ? 0 : mIfaceName.hashCode() + + mLinkAddresses.size() * 31 + + mDnses.size() * 37 + + mRoutes.size() * 41 + + ((null == mHttpProxy) ? 0 : mHttpProxy.hashCode())); } /** @@ -172,9 +232,9 @@ public class LinkProperties implements Parcelable { dest.writeByteArray(d.getAddress()); } - dest.writeInt(mGateways.size()); - for(InetAddress gw : mGateways) { - dest.writeByteArray(gw.getAddress()); + dest.writeInt(mRoutes.size()); + for(RouteInfo route : mRoutes) { + dest.writeParcelable(route, flags); } if (mHttpProxy != null) { @@ -213,9 +273,7 @@ public class LinkProperties implements Parcelable { } addressCount = in.readInt(); for (int i=0; i<addressCount; i++) { - try { - netProp.addGateway(InetAddress.getByAddress(in.createByteArray())); - } catch (UnknownHostException e) { } + netProp.addRoute((RouteInfo)in.readParcelable(null)); } if (in.readByte() == 1) { netProp.setHttpProxy((ProxyProperties)in.readParcelable(null)); diff --git a/core/java/android/net/MobileDataStateTracker.java b/core/java/android/net/MobileDataStateTracker.java index e04964e..770f152 100644 --- a/core/java/android/net/MobileDataStateTracker.java +++ b/core/java/android/net/MobileDataStateTracker.java @@ -20,6 +20,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.os.Bundle; import android.os.HandlerThread; import android.os.Looper; import android.os.Messenger; @@ -275,6 +276,21 @@ public class MobileDataStateTracker implements NetworkStateTracker { setDetailedState(DetailedState.CONNECTED, reason, apnName); break; } + } else { + // There was no state change. Check if LinkProperties has been updated. + if (TextUtils.equals(reason, Phone.REASON_LINK_PROPERTIES_CHANGED)) { + mLinkProperties = intent.getParcelableExtra(Phone.DATA_LINK_PROPERTIES_KEY); + if (mLinkProperties == null) { + log("No link property in LINK_PROPERTIES change event."); + mLinkProperties = new LinkProperties(); + } + // Just update reason field in this NetworkInfo + mNetworkInfo.setDetailedState(mNetworkInfo.getDetailedState(), reason, + mNetworkInfo.getExtraInfo()); + Message msg = mTarget.obtainMessage(EVENT_CONFIGURATION_CHANGED, + mNetworkInfo); + msg.sendToTarget(); + } } } else if (intent.getAction(). equals(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED)) { @@ -437,7 +453,8 @@ public class MobileDataStateTracker implements NetworkStateTracker { retValue = true; break; case Phone.APN_REQUEST_STARTED: - // no need to do anything - we're already due some status update intents + // set IDLE here , avoid the following second FAILED not sent out + mNetworkInfo.setDetailedState(DetailedState.IDLE, null, null); retValue = true; break; case Phone.APN_REQUEST_FAILED: @@ -492,6 +509,25 @@ public class MobileDataStateTracker implements NetworkStateTracker { } } + /** + * carrier dependency is met/unmet + * @param met + */ + public void setDependencyMet(boolean met) { + Bundle bundle = Bundle.forPair(DataConnectionTracker.APN_TYPE_KEY, mApnType); + try { + log("setDependencyMet: E met=" + met); + Message msg = Message.obtain(); + msg.what = DataConnectionTracker.CMD_SET_DEPENDENCY_MET; + msg.arg1 = (met ? DataConnectionTracker.ENABLED : DataConnectionTracker.DISABLED); + msg.setData(bundle); + mDataConnectionTrackerAc.sendMessage(msg); + log("setDependencyMet: X met=" + met); + } catch (NullPointerException e) { + log("setDependencyMet: X mAc was null" + e); + } + } + @Override public String toString() { StringBuffer sb = new StringBuffer("Mobile data state: "); @@ -546,6 +582,12 @@ public class MobileDataStateTracker implements NetworkStateTracker { return Phone.APN_TYPE_DUN; case ConnectivityManager.TYPE_MOBILE_HIPRI: return Phone.APN_TYPE_HIPRI; + case ConnectivityManager.TYPE_MOBILE_FOTA: + return Phone.APN_TYPE_FOTA; + case ConnectivityManager.TYPE_MOBILE_IMS: + return Phone.APN_TYPE_IMS; + case ConnectivityManager.TYPE_MOBILE_CBS: + return Phone.APN_TYPE_CBS; default: sloge("Error mapping networkType " + netType + " to apnType."); return null; diff --git a/core/java/android/net/NetworkConfig.java b/core/java/android/net/NetworkConfig.java new file mode 100644 index 0000000..3cc0bc5 --- /dev/null +++ b/core/java/android/net/NetworkConfig.java @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.net; + +import android.util.Log; + +/** + * Describes the buildtime configuration of a network. + * Holds settings read from resources. + * @hide + */ +public class NetworkConfig { + /** + * Human readable string + */ + public String name; + + /** + * Type from ConnectivityManager + */ + public int type; + + /** + * the radio number from radio attributes config + */ + public int radio; + + /** + * higher number == higher priority when turning off connections + */ + public int priority; + + /** + * indicates the boot time dependencyMet setting + */ + public boolean dependencyMet; + + /** + * indicates the default restoral timer in seconds + * if the network is used as a special network feature + * -1 indicates no restoration of default + */ + public int restoreTime; + + /** + * input string from config.xml resource. Uses the form: + * [Connection name],[ConnectivityManager connection type], + * [associated radio-type],[priority],[dependencyMet] + */ + public NetworkConfig(String init) { + String fragments[] = init.split(","); + name = fragments[0].trim().toLowerCase(); + type = Integer.parseInt(fragments[1]); + radio = Integer.parseInt(fragments[2]); + priority = Integer.parseInt(fragments[3]); + restoreTime = Integer.parseInt(fragments[4]); + dependencyMet = Boolean.parseBoolean(fragments[5]); + } + + /** + * Indicates if this network is supposed to be default-routable + */ + public boolean isDefault() { + return (type == radio); + } +} diff --git a/core/java/android/net/NetworkStateTracker.java b/core/java/android/net/NetworkStateTracker.java index eb97d77..f53063d 100644 --- a/core/java/android/net/NetworkStateTracker.java +++ b/core/java/android/net/NetworkStateTracker.java @@ -176,4 +176,9 @@ public interface NetworkStateTracker { * Indicate tear down requested from connectivity */ public void setTeardownRequested(boolean isRequested); + + /** + * An external dependency has been met/unmet + */ + public void setDependencyMet(boolean met); } diff --git a/core/java/android/net/NetworkUtils.java b/core/java/android/net/NetworkUtils.java index 823d10f..8a678d6 100644 --- a/core/java/android/net/NetworkUtils.java +++ b/core/java/android/net/NetworkUtils.java @@ -38,32 +38,6 @@ public class NetworkUtils { /** Bring the named network interface down. */ public native static int disableInterface(String interfaceName); - /** - * Add a route to the routing table. - * - * @param interfaceName the interface to route through. - * @param dst the network or host to route to. May be IPv4 or IPv6, e.g. - * "0.0.0.0" or "2001:4860::". - * @param prefixLength the prefix length of the route. - * @param gw the gateway to use, e.g., "192.168.251.1". If null, - * indicates a directly-connected route. - */ - public native static int addRoute(String interfaceName, String dst, - int prefixLength, String gw); - - /** Return the gateway address for the default route for the named interface. */ - public static InetAddress getDefaultRoute(String interfaceName) { - int addr = getDefaultRouteNative(interfaceName); - return intToInetAddress(addr); - } - private native static int getDefaultRouteNative(String interfaceName); - - /** Remove host routes that uses the named interface. */ - public native static int removeHostRoutes(String interfaceName); - - /** Remove the default route for the named interface. */ - public native static int removeDefaultRoute(String interfaceName); - /** Reset any sockets that are connected via the named interface. */ public native static int resetConnections(String interfaceName); @@ -160,6 +134,15 @@ public class NetworkUtils { } /** + * Convert a IPv4 netmask integer to a prefix length + * @param netmask as an integer in network byte order + * @return the network prefix length + */ + public static int netmaskIntToPrefixLength(int netmask) { + return Integer.bitCount(netmask); + } + + /** * Create an InetAddress from a string where the string must be a standard * representation of a V4 or V6 address. Avoids doing a DNS lookup on failure * but it will throw an IllegalArgumentException in that case. @@ -173,56 +156,69 @@ public class NetworkUtils { } /** - * Add a default route through the specified gateway. - * @param interfaceName interface on which the route should be added - * @param gw the IP address of the gateway to which the route is desired, - * @return {@code true} on success, {@code false} on failure + * Get InetAddress masked with prefixLength. Will never return null. + * @param IP address which will be masked with specified prefixLength + * @param prefixLength the prefixLength used to mask the IP */ - public static boolean addDefaultRoute(String interfaceName, InetAddress gw) { - String dstStr; - String gwStr = gw.getHostAddress(); - - if (gw instanceof Inet4Address) { - dstStr = "0.0.0.0"; - } else if (gw instanceof Inet6Address) { - dstStr = "::"; - } else { - Log.w(TAG, "addDefaultRoute failure: address is neither IPv4 nor IPv6" + - "(" + gwStr + ")"); - return false; + public static InetAddress getNetworkPart(InetAddress address, int prefixLength) { + if (address == null) { + throw new RuntimeException("getNetworkPart doesn't accept null address"); } - return addRoute(interfaceName, dstStr, 0, gwStr) == 0; + + byte[] array = address.getAddress(); + + if (prefixLength < 0 || prefixLength > array.length * 8) { + throw new RuntimeException("getNetworkPart - bad prefixLength"); + } + + int offset = prefixLength / 8; + int reminder = prefixLength % 8; + byte mask = (byte)(0xFF << (8 - reminder)); + + if (offset < array.length) array[offset] = (byte)(array[offset] & mask); + + offset++; + + for (; offset < array.length; offset++) { + array[offset] = 0; + } + + InetAddress netPart = null; + try { + netPart = InetAddress.getByAddress(array); + } catch (UnknownHostException e) { + throw new RuntimeException("getNetworkPart error - " + e.toString()); + } + return netPart; } /** - * Add a host route. - * @param interfaceName interface on which the route should be added - * @param dst the IP address of the host to which the route is desired, - * this should not be null. - * @param gw the IP address of the gateway to which the route is desired, - * if null, indicates a directly-connected route. - * @return {@code true} on success, {@code false} on failure + * Check if IP address type is consistent between two InetAddress. + * @return true if both are the same type. False otherwise. */ - public static boolean addHostRoute(String interfaceName, InetAddress dst, - InetAddress gw) { - if (dst == null) { - Log.w(TAG, "addHostRoute: dst should not be null"); - return false; - } + public static boolean addressTypeMatches(InetAddress left, InetAddress right) { + return (((left instanceof Inet4Address) && (right instanceof Inet4Address)) || + ((left instanceof Inet6Address) && (right instanceof Inet6Address))); + } - int prefixLength; - String dstStr = dst.getHostAddress(); - String gwStr = (gw != null) ? gw.getHostAddress() : null; - - if (dst instanceof Inet4Address) { - prefixLength = 32; - } else if (dst instanceof Inet6Address) { - prefixLength = 128; - } else { - Log.w(TAG, "addHostRoute failure: address is neither IPv4 nor IPv6" + - "(" + dst + ")"); - return false; + /** + * Convert a 32 char hex string into a Inet6Address. + * throws a runtime exception if the string isn't 32 chars, isn't hex or can't be + * made into an Inet6Address + * @param addrHexString a 32 character hex string representing an IPv6 addr + * @return addr an InetAddress representation for the string + */ + public static InetAddress hexToInet6Address(String addrHexString) + throws IllegalArgumentException { + try { + return numericToInetAddress(String.format("%s:%s:%s:%s:%s:%s:%s:%s", + addrHexString.substring(0,4), addrHexString.substring(4,8), + addrHexString.substring(8,12), addrHexString.substring(12,16), + addrHexString.substring(16,20), addrHexString.substring(20,24), + addrHexString.substring(24,28), addrHexString.substring(28,32))); + } catch (Exception e) { + Log.e("NetworkUtils", "error in hexToInet6Address(" + addrHexString + "): " + e); + throw new IllegalArgumentException(e); } - return addRoute(interfaceName, dstStr, prefixLength, gwStr) == 0; } } diff --git a/core/java/android/net/ProxyProperties.java b/core/java/android/net/ProxyProperties.java index cbe4445..44dbec1 100644 --- a/core/java/android/net/ProxyProperties.java +++ b/core/java/android/net/ProxyProperties.java @@ -163,6 +163,16 @@ public class ProxyProperties implements Parcelable { return 0; } + @Override + /* + * generate hashcode based on significant fields + */ + public int hashCode() { + return ((null == mHost) ? 0 : mHost.hashCode()) + + ((null == mExclusionList) ? 0 : mExclusionList.hashCode()) + + mPort; + } + /** * Implement the Parcelable interface. * @hide diff --git a/core/java/android/net/RouteInfo.aidl b/core/java/android/net/RouteInfo.aidl new file mode 100644 index 0000000..2296a57 --- /dev/null +++ b/core/java/android/net/RouteInfo.aidl @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.net; + +parcelable RouteInfo; diff --git a/core/java/android/net/RouteInfo.java b/core/java/android/net/RouteInfo.java new file mode 100644 index 0000000..8e5ddda --- /dev/null +++ b/core/java/android/net/RouteInfo.java @@ -0,0 +1,246 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.net; + +import android.os.Parcel; +import android.os.Parcelable; + +import java.net.UnknownHostException; +import java.net.InetAddress; +import java.net.Inet4Address; +import java.net.Inet6Address; + +import java.util.Collection; + +/** + * A simple container for route information. + * + * @hide + */ +public class RouteInfo implements Parcelable { + /** + * The IP destination address for this route. + */ + private final LinkAddress mDestination; + + /** + * The gateway address for this route. + */ + private final InetAddress mGateway; + + private final boolean mIsDefault; + + public RouteInfo(LinkAddress destination, InetAddress gateway) { + if (destination == null) { + if (gateway != null) { + if (gateway instanceof Inet4Address) { + destination = new LinkAddress(Inet4Address.ANY, 0); + } else { + destination = new LinkAddress(Inet6Address.ANY, 0); + } + } else { + // no destination, no gateway. invalid. + throw new RuntimeException("Invalid arguments passed in."); + } + } + if (gateway == null) { + if (destination.getAddress() instanceof Inet4Address) { + gateway = Inet4Address.ANY; + } else { + gateway = Inet6Address.ANY; + } + } + mDestination = new LinkAddress(NetworkUtils.getNetworkPart(destination.getAddress(), + destination.getNetworkPrefixLength()), destination.getNetworkPrefixLength()); + mGateway = gateway; + mIsDefault = isDefault(); + } + + public RouteInfo(InetAddress gateway) { + this(null, gateway); + } + + public static RouteInfo makeHostRoute(InetAddress host) { + return makeHostRoute(host, null); + } + + public static RouteInfo makeHostRoute(InetAddress host, InetAddress gateway) { + if (host == null) return null; + + if (host instanceof Inet4Address) { + return new RouteInfo(new LinkAddress(host, 32), gateway); + } else { + return new RouteInfo(new LinkAddress(host, 128), gateway); + } + } + + private boolean isDefault() { + boolean val = false; + if (mGateway != null) { + if (mGateway instanceof Inet4Address) { + val = (mDestination == null || mDestination.getNetworkPrefixLength() == 0); + } else { + val = (mDestination == null || mDestination.getNetworkPrefixLength() == 0); + } + } + return val; + } + + public LinkAddress getDestination() { + return mDestination; + } + + public InetAddress getGateway() { + return mGateway; + } + + public boolean isDefaultRoute() { + return mIsDefault; + } + + public String toString() { + String val = ""; + if (mDestination != null) val = mDestination.toString(); + if (mGateway != null) val += " -> " + mGateway.getHostAddress(); + return val; + } + + public int describeContents() { + return 0; + } + + public void writeToParcel(Parcel dest, int flags) { + if (mDestination == null) { + dest.writeByte((byte) 0); + } else { + dest.writeByte((byte) 1); + dest.writeByteArray(mDestination.getAddress().getAddress()); + dest.writeInt(mDestination.getNetworkPrefixLength()); + } + + if (mGateway == null) { + dest.writeByte((byte) 0); + } else { + dest.writeByte((byte) 1); + dest.writeByteArray(mGateway.getAddress()); + } + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + + if (!(obj instanceof RouteInfo)) return false; + + RouteInfo target = (RouteInfo) obj; + + boolean sameDestination = ( mDestination == null) ? + target.getDestination() == null + : mDestination.equals(target.getDestination()); + + boolean sameAddress = (mGateway == null) ? + target.getGateway() == null + : mGateway.equals(target.getGateway()); + + return sameDestination && sameAddress + && mIsDefault == target.mIsDefault; + } + + @Override + public int hashCode() { + return (mDestination == null ? 0 : mDestination.hashCode()) + + (mGateway == null ? 0 :mGateway.hashCode()) + + (mIsDefault ? 3 : 7); + } + + public static final Creator<RouteInfo> CREATOR = + new Creator<RouteInfo>() { + public RouteInfo createFromParcel(Parcel in) { + InetAddress destAddr = null; + int prefix = 0; + InetAddress gateway = null; + + if (in.readByte() == 1) { + byte[] addr = in.createByteArray(); + prefix = in.readInt(); + + try { + destAddr = InetAddress.getByAddress(addr); + } catch (UnknownHostException e) {} + } + + if (in.readByte() == 1) { + byte[] addr = in.createByteArray(); + + try { + gateway = InetAddress.getByAddress(addr); + } catch (UnknownHostException e) {} + } + + LinkAddress dest = null; + + if (destAddr != null) { + dest = new LinkAddress(destAddr, prefix); + } + + return new RouteInfo(dest, gateway); + } + + public RouteInfo[] newArray(int size) { + return new RouteInfo[size]; + } + }; + + private boolean matches(InetAddress destination) { + if (destination == null) return false; + + // if the destination is present and the route is default. + // return true + if (isDefault()) return true; + + // match the route destination and destination with prefix length + InetAddress dstNet = NetworkUtils.getNetworkPart(destination, + mDestination.getNetworkPrefixLength()); + + return mDestination.getAddress().equals(dstNet); + } + + /** + * Find the route from a Collection of routes that best matches a given address. + * May return null if no routes are applicable. + * @param routes a Collection of RouteInfos to chose from + * @param dest the InetAddress your trying to get to + * @return the RouteInfo from the Collection that best fits the given address + */ + public static RouteInfo selectBestRoute(Collection<RouteInfo> routes, InetAddress dest) { + if ((routes == null) || (dest == null)) return null; + + RouteInfo bestRoute = null; + // pick a longest prefix match under same address type + for (RouteInfo route : routes) { + if (NetworkUtils.addressTypeMatches(route.mDestination.getAddress(), dest)) { + if ((bestRoute != null) && + (bestRoute.mDestination.getNetworkPrefixLength() >= + route.mDestination.getNetworkPrefixLength())) { + continue; + } + if (route.matches(dest)) bestRoute = route; + } + } + return bestRoute; + } +} diff --git a/core/java/android/nfc/INfcAdapter.aidl b/core/java/android/nfc/INfcAdapter.aidl index d439a48..870127c 100644 --- a/core/java/android/nfc/INfcAdapter.aidl +++ b/core/java/android/nfc/INfcAdapter.aidl @@ -28,7 +28,7 @@ import android.nfc.ILlcpConnectionlessSocket; import android.nfc.INfcTag; import android.nfc.IP2pTarget; import android.nfc.IP2pInitiator; -import android.nfc.INfcSecureElement; +import android.nfc.INfcAdapterExtras; /** * @hide @@ -41,13 +41,12 @@ interface INfcAdapter INfcTag getNfcTagInterface(); IP2pTarget getP2pTargetInterface(); IP2pInitiator getP2pInitiatorInterface(); - INfcSecureElement getNfcSecureElementInterface(); + INfcAdapterExtras getNfcAdapterExtrasInterface(); // NfcAdapter-class related methods boolean isEnabled(); NdefMessage localGet(); void localSet(in NdefMessage message); - void openTagConnection(in Tag tag); void enableForegroundDispatch(in ComponentName activity, in PendingIntent intent, in IntentFilter[] filters, in TechListParcel techLists); void disableForegroundDispatch(in ComponentName activity); @@ -59,12 +58,8 @@ interface INfcAdapter int createLlcpConnectionlessSocket(int sap); int createLlcpServiceSocket(int sap, String sn, int miu, int rw, int linearBufferLength); int createLlcpSocket(int sap, int miu, int rw, int linearBufferLength); - int deselectSecureElement(); boolean disable(); boolean enable(); String getProperties(String param); - int[] getSecureElementList(); - int getSelectedSecureElement(); - int selectSecureElement(int seId); int setProperties(String param, String value); -}
\ No newline at end of file +} diff --git a/core/java/android/nfc/INfcSecureElement.aidl b/core/java/android/nfc/INfcAdapterExtras.aidl index aa98dd2..ab5c1a6 100755 --- a/core/java/android/nfc/INfcSecureElement.aidl +++ b/core/java/android/nfc/INfcAdapterExtras.aidl @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 The Android Open Source Project + * Copyright (C) 2011 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,13 +16,15 @@ package android.nfc; +import android.os.Bundle; + /** * {@hide} */ -interface INfcSecureElement { - int openSecureElementConnection(); - int closeSecureElementConnection(int nativeHandle); - byte[] exchangeAPDU(int nativeHandle, in byte[] data); - int[] getSecureElementTechList(int nativeHandle); - byte[] getSecureElementUid(int nativeHandle); -}
\ No newline at end of file +interface INfcAdapterExtras { + Bundle open(IBinder b); + Bundle close(); + Bundle transceive(in byte[] data_in); + int getCardEmulationRoute(); + void setCardEmulationRoute(int route); +} diff --git a/core/java/android/nfc/NfcAdapter.java b/core/java/android/nfc/NfcAdapter.java index 8c56fda..4689804 100644 --- a/core/java/android/nfc/NfcAdapter.java +++ b/core/java/android/nfc/NfcAdapter.java @@ -157,31 +157,6 @@ public final class NfcAdapter { public static final String EXTRA_ID = "android.nfc.extra.ID"; /** - * Broadcast Action: a transaction with a secure element has been detected. - * <p> - * Always contains the extra field - * {@link android.nfc.NfcAdapter#EXTRA_AID} - * @hide - */ - @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) - public static final String ACTION_TRANSACTION_DETECTED = - "android.nfc.action.TRANSACTION_DETECTED"; - - /** - * Broadcast Action: an RF field ON has been detected. - * @hide - */ - public static final String ACTION_RF_FIELD_ON_DETECTED = - "android.nfc.action.RF_FIELD_ON_DETECTED"; - - /** - * Broadcast Action: an RF Field OFF has been detected. - * @hide - */ - public static final String ACTION_RF_FIELD_OFF_DETECTED = - "android.nfc.action.RF_FIELD_OFF_DETECTED"; - - /** * Broadcast Action: an adapter's state changed between enabled and disabled. * * The new value is stored in the extra EXTRA_NEW_BOOLEAN_STATE and just contains @@ -201,15 +176,6 @@ public final class NfcAdapter { public static final String EXTRA_NEW_BOOLEAN_STATE = "android.nfc.isEnabled"; /** - * Mandatory byte array extra field in - * {@link android.nfc.NfcAdapter#ACTION_TRANSACTION_DETECTED}. - * <p> - * Contains the AID of the applet involved in the transaction. - * @hide - */ - public static final String EXTRA_AID = "android.nfc.extra.AID"; - - /** * LLCP link status: The LLCP link is activated. * @hide */ @@ -691,39 +657,14 @@ public final class NfcAdapter { } /** - * Create an Nfc Secure Element Connection * @hide */ - public NfcSecureElement createNfcSecureElementConnection() { + public INfcAdapterExtras getNfcAdapterExtrasInterface() { try { - return new NfcSecureElement(sService.getNfcSecureElementInterface()); + return sService.getNfcAdapterExtrasInterface(); } catch (RemoteException e) { - Log.e(TAG, "createNfcSecureElementConnection failed", e); + attemptDeadServiceRecovery(e); return null; } } - - /** - * To change the Secure Element Card Emulation state (ON/OFF) - * @hide - */ - public void changeNfcSecureElementCardEmulationState(boolean state) - { - int seId = 11259375; - if(state){ - /* Enable card emulation */ - try { - sService.selectSecureElement(seId); - } catch (RemoteException e) { - Log.e(TAG, "Enable card emulation failed", e); - } - }else{ - /* Disable card emulation */ - try { - sService.deselectSecureElement(); - } catch (RemoteException e) { - Log.e(TAG, " card emulation failed", e); - } - } - } } diff --git a/core/java/android/nfc/NfcSecureElement.java b/core/java/android/nfc/NfcSecureElement.java deleted file mode 100755 index 3b5f39e..0000000 --- a/core/java/android/nfc/NfcSecureElement.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.nfc; - -import android.nfc.tech.TagTechnology; -import android.os.RemoteException; -import android.util.Log; - -import java.io.IOException; - -//import android.util.Log; - -/** - * This class provides the primary API for managing all aspects Secure Element. - * Get an instance of this class by calling - * Context.getSystemService(Context.NFC_SERVICE). - * @hide - */ -public final class NfcSecureElement { - - private static final String TAG = "NfcSecureElement"; - - private INfcSecureElement mService; - - - /** - * @hide - */ - public NfcSecureElement(INfcSecureElement mSecureElementService) { - mService = mSecureElementService; - } - - public int openSecureElementConnection(String seType) throws IOException { - if (seType.equals("SmartMX")) { - try { - int handle = mService.openSecureElementConnection(); - // Handle potential errors - if (handle != 0) { - return handle; - } else { - throw new IOException("SmartMX connection not allowed"); - } - } catch (RemoteException e) { - Log.e(TAG, "RemoteException in openSecureElementConnection(): ", e); - return 0; - } - - } else if (seType.equals("UICC")) { - return 0; - } else { - throw new IOException("Wrong Secure Element type"); - } - } - - - public byte [] exchangeAPDU(int handle,byte [] data) throws IOException { - - - // Perform exchange APDU - try { - byte[] response = mService.exchangeAPDU(handle, data); - // Handle potential errors - if (response == null) { - throw new IOException("Exchange APDU failed"); - } - return response; - } catch (RemoteException e) { - Log.e(TAG, "RemoteException in exchangeAPDU(): ", e); - return null; - } - } - - public void closeSecureElementConnection(int handle) throws IOException { - - try { - int status = mService.closeSecureElementConnection(handle); - // Handle potential errors - if (ErrorCodes.isError(status)) { - throw new IOException("Error during the conection close"); - }; - } catch (RemoteException e) { - Log.e(TAG, "RemoteException in closeSecureElement(): ", e); - } - } - - - /** - * Returns target type. constants. - * - * @return Secure Element technology type. The possible values are defined in - * {@link TagTechnology} - * - */ - public int[] getSecureElementTechList(int handle) throws IOException { - try { - return mService.getSecureElementTechList(handle); - } catch (RemoteException e) { - Log.e(TAG, "RemoteException in getType(): ", e); - return null; - } - } - - /** - * Returns Secure Element UID. - * - * @return Secure Element UID. - */ - public byte[] getSecureElementUid(int handle) throws IOException { - - byte[] uid = null; - try { - uid = mService.getSecureElementUid(handle); - // Handle potential errors - if (uid == null) { - throw new IOException("Get Secure Element UID failed"); - } - return uid; - } catch (RemoteException e) { - Log.e(TAG, "RemoteException in getType(): ", e); - return null; - } - } - -} diff --git a/core/java/android/os/FileUtils.java b/core/java/android/os/FileUtils.java index f56f6a9..632daa1 100644 --- a/core/java/android/os/FileUtils.java +++ b/core/java/android/os/FileUtils.java @@ -19,19 +19,20 @@ package android.os; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; import java.util.regex.Pattern; +import java.util.zip.CRC32; +import java.util.zip.CheckedInputStream; /** * Tools for managing files. Not for public consumption. * @hide */ -public class FileUtils -{ +public class FileUtils { public static final int S_IRWXU = 00700; public static final int S_IRUSR = 00400; public static final int S_IWUSR = 00200; @@ -94,7 +95,7 @@ public class FileUtils /** returns the FAT file system volume ID for the volume mounted * at the given mount point, or -1 for failure - * @param mount point for FAT volume + * @param mountPoint point for FAT volume * @return volume ID or -1 */ public static native int getFatVolumeId(String mountPoint); @@ -226,4 +227,32 @@ public class FileUtils input.close(); } } + + /** + * Computes the checksum of a file using the CRC32 checksum routine. + * The value of the checksum is returned. + * + * @param file the file to checksum, must not be null + * @return the checksum value or an exception is thrown. + */ + public static long checksumCrc32(File file) throws FileNotFoundException, IOException { + CRC32 checkSummer = new CRC32(); + CheckedInputStream cis = null; + + try { + cis = new CheckedInputStream( new FileInputStream(file), checkSummer); + byte[] buf = new byte[128]; + while(cis.read(buf) >= 0) { + // Just read for checksum to get calculated. + } + return checkSummer.getValue(); + } finally { + if (cis != null) { + try { + cis.close(); + } catch (IOException e) { + } + } + } + } } diff --git a/core/java/android/os/INetworkManagementService.aidl b/core/java/android/os/INetworkManagementService.aidl index 212c5fb..5a245f8 100644 --- a/core/java/android/os/INetworkManagementService.aidl +++ b/core/java/android/os/INetworkManagementService.aidl @@ -19,6 +19,7 @@ package android.os; import android.net.InterfaceConfiguration; import android.net.INetworkManagementEventObserver; +import android.net.RouteInfo; import android.net.wifi.WifiConfiguration; /** @@ -57,6 +58,22 @@ interface INetworkManagementService void setInterfaceConfig(String iface, in InterfaceConfiguration cfg); /** + * Retrieves the network routes currently configured on the specified + * interface + */ + RouteInfo[] getRoutes(String iface); + + /** + * Add the specified route to the interface. + */ + void addRoute(String iface, in RouteInfo route); + + /** + * Remove the specified route from the interface. + */ + void removeRoute(String iface, in RouteInfo route); + + /** * Shuts down the service */ void shutdown(); diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index 58d9952..eb9eb03 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -3706,6 +3706,29 @@ public final class Settings { "inet_condition_debounce_down_delay"; /** + * URL to open browser on to allow user to manage a prepay account + * @hide + */ + public static final String SETUP_PREPAID_DATA_SERVICE_URL = + "setup_prepaid_data_service_url"; + + /** + * URL to attempt a GET on to see if this is a prepay device + * @hide + */ + public static final String SETUP_PREPAID_DETECTION_TARGET_URL = + "setup_prepaid_detection_target_url"; + + /** + * Host to check for a redirect to after an attempt to GET + * SETUP_PREPAID_DETECTION_TARGET_URL. (If we redirected there, + * this is a prepaid device with zero balance.) + * @hide + */ + public static final String SETUP_PREPAID_DETECTION_REDIR_HOST = + "setup_prepaid_detection_redir_host"; + + /** * @hide */ public static final String[] SETTINGS_TO_BACKUP = { diff --git a/core/java/android/provider/Telephony.java b/core/java/android/provider/Telephony.java index 62f66b6..d2d2557 100644 --- a/core/java/android/provider/Telephony.java +++ b/core/java/android/provider/Telephony.java @@ -1723,6 +1723,14 @@ public final class Telephony { public static final String TYPE = "type"; + public static final String INACTIVE_TIMER = "inactivetimer"; + + // Only if enabled try Data Connection. + public static final String ENABLED = "enabled"; + + // Rules apply based on class. + public static final String CLASS = "class"; + /** * The protocol to be used to connect to this APN. * diff --git a/core/java/android/view/ViewRoot.java b/core/java/android/view/ViewRoot.java index 2098955..3c6b634 100644 --- a/core/java/android/view/ViewRoot.java +++ b/core/java/android/view/ViewRoot.java @@ -1187,10 +1187,11 @@ public final class ViewRoot extends Handler implements ViewParent, } } mSurfaceHolder.mSurfaceLock.lock(); - // Make surface invalid. - //mSurfaceHolder.mSurface.copyFrom(mSurface); - mSurfaceHolder.mSurface = new Surface(); - mSurfaceHolder.mSurfaceLock.unlock(); + try { + mSurfaceHolder.mSurface = new Surface(); + } finally { + mSurfaceHolder.mSurfaceLock.unlock(); + } } } diff --git a/core/java/com/android/internal/util/AsyncChannel.java b/core/java/com/android/internal/util/AsyncChannel.java index 101dd91..3973344 100644 --- a/core/java/com/android/internal/util/AsyncChannel.java +++ b/core/java/com/android/internal/util/AsyncChannel.java @@ -44,16 +44,16 @@ import java.util.Stack; * In this usage model there is no need for the destination to * use the connect methods. The typical sequence of operations is:</p> *<ol> - * <li>Client calls AsyncChannel#connect</li> - * <li>Client receives CMD_CHANNEL_HALF_CONNECTED from AsyncChannel</li> + * <li>Client calls AsyncChannel#connectSync or Asynchronously:</li> + * <ol>For an asynchronous half connection client calls AsyncChannel#connect.</ol> + * <li>Client receives CMD_CHANNEL_HALF_CONNECTED from AsyncChannel</li> + * </ol> * <li><code>comm-loop:</code></li> - * <li>Client calls AsyncChannel#sendMessage(msgX)</li> - * <li>Server receives and processes msgX</li> - * <li>Server optionally calls AsyncChannel#replyToMessage(msgY) - * and if sent Client receives and processes msgY</li> + * <li>Client calls AsyncChannel#sendMessage</li> + * <li>Server processes messages and optionally replies using AsyncChannel#replyToMessage * <li>Loop to <code>comm-loop</code> until done</li> - * <li>When done Client calls {@link AsyncChannel#disconnect(int)}</li> - * <li>Client receives CMD_CHANNEL_DISCONNECTED from AsyncChannel</li> + * <li>When done Client calls {@link AsyncChannel#disconnect}</li> + * <li>Client/Server receives CMD_CHANNEL_DISCONNECTED from AsyncChannel</li> *</ol> *<br/> * <p>A second usage model is where the server/destination needs to know @@ -62,21 +62,26 @@ import java.util.Stack; * different state for each client. In this model the server will also * use the connect methods. The typical sequence of operation is:</p> *<ol> - * <li>Client calls AsyncChannel#connect</li> - * <li>Client receives CMD_CHANNEL_HALF_CONNECTED from AsyncChannel</li> - * <li>Client calls AsyncChannel#sendMessage(CMD_CHANNEL_FULL_CONNECTION)</li> + * <li>Client calls AsyncChannel#fullyConnectSync or Asynchronously:<li> + * <ol>For an asynchronous full connection it calls AsyncChannel#connect</li> + * <li>Client receives CMD_CHANNEL_HALF_CONNECTED from AsyncChannel</li> + * <li>Client calls AsyncChannel#sendMessage(CMD_CHANNEL_FULL_CONNECTION)</li> + * </ol> * <li>Server receives CMD_CHANNEL_FULL_CONNECTION</li> - * <li>Server calls AsyncChannel#connect</li> - * <li>Server receives CMD_CHANNEL_HALF_CONNECTED from AsyncChannel</li> + * <li>Server calls AsyncChannel#connected</li> * <li>Server sends AsyncChannel#sendMessage(CMD_CHANNEL_FULLY_CONNECTED)</li> * <li>Client receives CMD_CHANNEL_FULLY_CONNECTED</li> * <li><code>comm-loop:</code></li> * <li>Client/Server uses AsyncChannel#sendMessage/replyToMessage * to communicate and perform work</li> * <li>Loop to <code>comm-loop</code> until done</li> - * <li>When done Client/Server calls {@link AsyncChannel#disconnect(int)}</li> + * <li>When done Client/Server calls {@link AsyncChannel#disconnect}</li> * <li>Client/Server receives CMD_CHANNEL_DISCONNECTED from AsyncChannel</li> *</ol> + * + * TODO: Consider simplifying where we have connect and fullyConnect with only one response + * message RSP_CHANNEL_CONNECT instead of two, CMD_CHANNEL_HALF_CONNECTED and + * CMD_CHANNEL_FULLY_CONNECTED. We'd also change CMD_CHANNEL_FULL_CONNECTION to REQ_CHANNEL_CONNECT. */ public class AsyncChannel { /** Log tag */ @@ -85,6 +90,8 @@ public class AsyncChannel { /** Enable to turn on debugging */ private static final boolean DBG = false; + private static final int BASE = Protocol.BASE_SYSTEM_ASYNC_CHANNEL; + /** * Command sent when the channel is half connected. Half connected * means that the channel can be used to send commends to the destination @@ -98,7 +105,7 @@ public class AsyncChannel { * msg.obj == the AsyncChannel * msg.replyTo == dstMessenger if successful */ - public static final int CMD_CHANNEL_HALF_CONNECTED = -1; + public static final int CMD_CHANNEL_HALF_CONNECTED = BASE + 0; /** * Command typically sent when after receiving the CMD_CHANNEL_HALF_CONNECTED. @@ -107,7 +114,7 @@ public class AsyncChannel { * * msg.replyTo = srcMessenger. */ - public static final int CMD_CHANNEL_FULL_CONNECTION = -2; + public static final int CMD_CHANNEL_FULL_CONNECTION = BASE + 1; /** * Command typically sent after the destination receives a CMD_CHANNEL_FULL_CONNECTION. @@ -115,31 +122,33 @@ public class AsyncChannel { * * msg.arg1 == 0 : Accept connection * : All other values signify the destination rejected the connection - * and {@link AsyncChannel#disconnect(int)} would typically be called. + * and {@link AsyncChannel#disconnect} would typically be called. */ - public static final int CMD_CHANNEL_FULLY_CONNECTED = -3; + public static final int CMD_CHANNEL_FULLY_CONNECTED = BASE + 2; /** * Command sent when one side or the other wishes to disconnect. The sender * may or may not be able to receive a reply depending upon the protocol and - * the state of the connection. The receiver should call {@link AsyncChannel#disconnect(int)} + * the state of the connection. The receiver should call {@link AsyncChannel#disconnect} * to close its side of the channel and it will receive a CMD_CHANNEL_DISCONNECTED * when the channel is closed. * * msg.replyTo = messenger that is disconnecting */ - public static final int CMD_CHANNEL_DISCONNECT = -4; + public static final int CMD_CHANNEL_DISCONNECT = BASE + 3; /** * Command sent when the channel becomes disconnected. This is sent when the * channel is forcibly disconnected by the system or as a reply to CMD_CHANNEL_DISCONNECT. * * msg.arg1 == 0 : STATUS_SUCCESSFUL + * 1 : STATUS_BINDING_UNSUCCESSFUL + * 2 : STATUS_SEND_UNSUCCESSFUL * : All other values signify failure and the channel state is indeterminate * msg.obj == the AsyncChannel * msg.replyTo = messenger disconnecting or null if it was never connected. */ - public static final int CMD_CHANNEL_DISCONNECTED = -5; + public static final int CMD_CHANNEL_DISCONNECTED = BASE + 4; /** Successful status always 0, !0 is an unsuccessful status */ public static final int STATUS_SUCCESSFUL = 0; @@ -147,6 +156,12 @@ public class AsyncChannel { /** Error attempting to bind on a connect */ public static final int STATUS_BINDING_UNSUCCESSFUL = 1; + /** Error attempting to send a message */ + public static final int STATUS_SEND_UNSUCCESSFUL = 2; + + /** CMD_FULLY_CONNECTED refused because a connection already exists*/ + public static final int STATUS_FULL_CONNECTION_REFUSED_ALREADY_CONNECTED = 3; + /** Service connection */ private AsyncChannelConnection mConnection; @@ -169,9 +184,7 @@ public class AsyncChannel { } /** - * Connect handler to named package/class. - * - * Sends a CMD_CHANNEL_HALF_CONNECTED message to srcHandler when complete. + * Connect handler to named package/class synchronously. * * @param srcContext is the context of the source * @param srcHandler is the hander to receive CONNECTED & DISCONNECTED @@ -179,8 +192,10 @@ public class AsyncChannel { * @param dstPackageName is the destination package name * @param dstClassName is the fully qualified class name (i.e. contains * package name) + * + * @return STATUS_SUCCESSFUL on success any other value is an error. */ - private void connectSrcHandlerToPackage( + public int connectSrcHandlerToPackageSync( Context srcContext, Handler srcHandler, String dstPackageName, String dstClassName) { if (DBG) log("connect srcHandler to dst Package & class E"); @@ -202,11 +217,61 @@ public class AsyncChannel { Intent intent = new Intent(Intent.ACTION_MAIN); intent.setClassName(dstPackageName, dstClassName); boolean result = srcContext.bindService(intent, mConnection, Context.BIND_AUTO_CREATE); - if (!result) { - replyHalfConnected(STATUS_BINDING_UNSUCCESSFUL); - } - if (DBG) log("connect srcHandler to dst Package & class X result=" + result); + return result ? STATUS_SUCCESSFUL : STATUS_BINDING_UNSUCCESSFUL; + } + + /** + * Connect a handler to Messenger synchronously. + * + * @param srcContext is the context of the source + * @param srcHandler is the hander to receive CONNECTED & DISCONNECTED + * messages + * @param dstMessenger is the hander to send messages to. + * + * @return STATUS_SUCCESSFUL on success any other value is an error. + */ + public int connectSync(Context srcContext, Handler srcHandler, Messenger dstMessenger) { + if (DBG) log("halfConnectSync srcHandler to the dstMessenger E"); + + // We are connected + connected(srcContext, srcHandler, dstMessenger); + + if (DBG) log("halfConnectSync srcHandler to the dstMessenger X"); + return STATUS_SUCCESSFUL; + } + + /** + * connect two local Handlers synchronously. + * + * @param srcContext is the context of the source + * @param srcHandler is the hander to receive CONNECTED & DISCONNECTED + * messages + * @param dstHandler is the hander to send messages to. + * + * @return STATUS_SUCCESSFUL on success any other value is an error. + */ + public int connectSync(Context srcContext, Handler srcHandler, Handler dstHandler) { + return connectSync(srcContext, srcHandler, new Messenger(dstHandler)); + } + + /** + * Fully connect two local Handlers synchronously. + * + * @param srcContext is the context of the source + * @param srcHandler is the hander to receive CONNECTED & DISCONNECTED + * messages + * @param dstHandler is the hander to send messages to. + * + * @return STATUS_SUCCESSFUL on success any other value is an error. + */ + public int fullyConnectSync(Context srcContext, Handler srcHandler, Handler dstHandler) { + int status = connectSync(srcContext, srcHandler, dstHandler); + if (status == STATUS_SUCCESSFUL) { + Message response = sendMessageSynchronously(CMD_CHANNEL_FULL_CONNECTION); + status = response.arg1; + } + return status; } /** @@ -241,8 +306,11 @@ public class AsyncChannel { mDstClassName = dstClassName; } + @Override public void run() { - connectSrcHandlerToPackage(mSrcCtx, mSrcHdlr, mDstPackageName, mDstClassName); + int result = connectSrcHandlerToPackageSync(mSrcCtx, mSrcHdlr, mDstPackageName, + mDstClassName); + replyHalfConnected(result); } } @@ -281,6 +349,28 @@ public class AsyncChannel { public void connect(Context srcContext, Handler srcHandler, Messenger dstMessenger) { if (DBG) log("connect srcHandler to the dstMessenger E"); + // We are connected + connected(srcContext, srcHandler, dstMessenger); + + // Tell source we are half connected + replyHalfConnected(STATUS_SUCCESSFUL); + + if (DBG) log("connect srcHandler to the dstMessenger X"); + } + + /** + * Connect handler to messenger. This method is typically called + * when a server receives a CMD_CHANNEL_FULL_CONNECTION request + * and initializes the internal instance variables to allow communication + * with the dstMessenger. + * + * @param srcContext + * @param srcHandler + * @param dstMessenger + */ + public void connected(Context srcContext, Handler srcHandler, Messenger dstMessenger) { + if (DBG) log("connected srcHandler to the dstMessenger E"); + // Initialize source fields mSrcContext = srcContext; mSrcHandler = srcHandler; @@ -289,21 +379,12 @@ public class AsyncChannel { // Initialize destination fields mDstMessenger = dstMessenger; - if (DBG) log("tell source we are half connected"); - - // Tell source we are half connected - replyHalfConnected(STATUS_SUCCESSFUL); - - if (DBG) log("connect srcHandler to the dstMessenger X"); + if (DBG) log("connected srcHandler to the dstMessenger X"); } /** * Connect two local Handlers. * - * Sends a CMD_CHANNEL_HALF_CONNECTED message to srcHandler when complete. - * msg.arg1 = status - * msg.obj = the AsyncChannel - * * @param srcContext is the context of the source * @param srcHandler is the hander to receive CONNECTED & DISCONNECTED * messages @@ -331,6 +412,7 @@ public class AsyncChannel { * To close the connection call when handler receives CMD_CHANNEL_DISCONNECTED */ public void disconnected() { + mSrcContext = null; mSrcHandler = null; mSrcMessenger = null; mDstMessenger = null; @@ -341,15 +423,11 @@ public class AsyncChannel { * Disconnect */ public void disconnect() { - if (mConnection != null) { + if ((mConnection != null) && (mSrcContext != null)) { mSrcContext.unbindService(mConnection); } if (mSrcHandler != null) { - Message msg = mSrcHandler.obtainMessage(CMD_CHANNEL_DISCONNECTED); - msg.arg1 = STATUS_SUCCESSFUL; - msg.obj = this; - msg.replyTo = mDstMessenger; - mSrcHandler.sendMessage(msg); + replyDisconnected(STATUS_SUCCESSFUL); } } @@ -363,7 +441,7 @@ public class AsyncChannel { try { mDstMessenger.send(msg); } catch (RemoteException e) { - log("TODO: handle sendMessage RemoteException" + e); + replyDisconnected(STATUS_SEND_UNSUCCESSFUL); } } @@ -444,6 +522,7 @@ public class AsyncChannel { */ public void replyToMessage(Message srcMsg, Message dstMsg) { try { + dstMsg.replyTo = mSrcMessenger; srcMsg.replyTo.send(dstMsg); } catch (RemoteException e) { log("TODO: handle replyToMessage RemoteException" + e); @@ -694,10 +773,14 @@ public class AsyncChannel { private static Message sendMessageSynchronously(Messenger dstMessenger, Message msg) { SyncMessenger sm = SyncMessenger.obtain(); try { - msg.replyTo = sm.mMessenger; - dstMessenger.send(msg); - synchronized (sm.mHandler.mLockObject) { - sm.mHandler.mLockObject.wait(); + if (dstMessenger != null && msg != null) { + msg.replyTo = sm.mMessenger; + synchronized (sm.mHandler.mLockObject) { + dstMessenger.send(msg); + sm.mHandler.mLockObject.wait(); + } + } else { + sm.mHandler.mResultMsg = null; } } catch (InterruptedException e) { sm.mHandler.mResultMsg = null; @@ -712,6 +795,7 @@ public class AsyncChannel { /** * Reply to the src handler that we're half connected. + * see: CMD_CHANNEL_HALF_CONNECTED for message contents * * @param status to be stored in msg.arg1 */ @@ -724,23 +808,36 @@ public class AsyncChannel { } /** + * Reply to the src handler that we are disconnected + * see: CMD_CHANNEL_DISCONNECTED for message contents + * + * @param status to be stored in msg.arg1 + */ + private void replyDisconnected(int status) { + Message msg = mSrcHandler.obtainMessage(CMD_CHANNEL_DISCONNECTED); + msg.arg1 = status; + msg.obj = this; + msg.replyTo = mDstMessenger; + mSrcHandler.sendMessage(msg); + } + + + /** * ServiceConnection to receive call backs. */ class AsyncChannelConnection implements ServiceConnection { AsyncChannelConnection() { } + @Override public void onServiceConnected(ComponentName className, IBinder service) { mDstMessenger = new Messenger(service); replyHalfConnected(STATUS_SUCCESSFUL); } + @Override public void onServiceDisconnected(ComponentName className) { - Message msg = mSrcHandler.obtainMessage(CMD_CHANNEL_DISCONNECTED); - msg.arg1 = STATUS_SUCCESSFUL; - msg.obj = AsyncChannel.this; - msg.replyTo = mDstMessenger; - mSrcHandler.sendMessage(msg); + replyDisconnected(STATUS_SUCCESSFUL); } } diff --git a/core/java/com/android/internal/util/HierarchicalState.java b/core/java/com/android/internal/util/IState.java index b37f46c..056f8e9 100644 --- a/core/java/com/android/internal/util/HierarchicalState.java +++ b/core/java/com/android/internal/util/IState.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2009 The Android Open Source Project + * Copyright (C) 2011 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,21 +21,29 @@ import android.os.Message; /** * {@hide} * - * The class for implementing states in a HierarchicalStateMachine + * The interface for implementing states in a {@link StateMachine} */ -public class HierarchicalState { +public interface IState { /** - * Constructor + * Returned by processMessage to indicate the the message was processed. */ - protected HierarchicalState() { - } + static final boolean HANDLED = true; + + /** + * Returned by processMessage to indicate the the message was NOT processed. + */ + static final boolean NOT_HANDLED = false; /** * Called when a state is entered. */ - protected void enter() { - } + void enter(); + + /** + * Called when a state is exited. + */ + void exit(); /** * Called when a message is to be processed by the @@ -49,28 +57,15 @@ public class HierarchicalState { * be processed until this routine returns. * * @param msg to process - * @return true if processing has completed and false - * if the parent state's processMessage should - * be invoked. - */ - protected boolean processMessage(Message msg) { - return false; - } - - /** - * Called when a state is exited. + * @return HANDLED if processing has completed and NOT_HANDLED + * if the message wasn't processed. */ - protected void exit() { - } + boolean processMessage(Message msg); /** - * @return name of state, but default returns the states - * class name. An instance name would be better but requiring - * it seems unnecessary. + * Name of State for debugging purposes. + * + * @return name of state. */ - public String getName() { - String name = getClass().getName(); - int lastDollar = name.lastIndexOf('$'); - return name.substring(lastDollar + 1); - } + String getName(); } diff --git a/core/java/com/android/internal/util/ProcessedMessages.java b/core/java/com/android/internal/util/ProcessedMessages.java deleted file mode 100644 index 244474e..0000000 --- a/core/java/com/android/internal/util/ProcessedMessages.java +++ /dev/null @@ -1,198 +0,0 @@ -/** - * Copyright (C) 2009 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.internal.util; - -import android.os.Message; - -import java.util.Vector; - -/** - * {@hide} - * - * A list of messages recently processed by the state machine. - * - * The class maintains a list of messages that have been most - * recently processed. The list is finite and may be set in the - * constructor or by calling setSize. The public interface also - * includes size which returns the number of recent messages, - * count which is the number of message processed since the - * the last setSize, get which returns a processed message and - * add which adds a processed messaged. - */ -public class ProcessedMessages { - - public static final int DEFAULT_SIZE = 20; - - /** - * The information maintained for a processed message. - */ - public class Info { - private int what; - private HierarchicalState state; - private HierarchicalState orgState; - - /** - * Constructor - * @param message - * @param state that handled the message - * @param orgState is the first state the received the message but - * did not processes the message. - */ - Info(Message message, HierarchicalState state, HierarchicalState orgState) { - update(message, state, orgState); - } - - /** - * Update the information in the record. - * @param state that handled the message - * @param orgState is the first state the received the message but - * did not processes the message. - */ - public void update(Message message, HierarchicalState state, HierarchicalState orgState) { - this.what = message.what; - this.state = state; - this.orgState = orgState; - } - - /** - * @return the command that was executing - */ - public int getWhat() { - return what; - } - - /** - * @return the state that handled this message - */ - public HierarchicalState getState() { - return state; - } - - /** - * @return the original state that received the message. - */ - public HierarchicalState getOriginalState() { - return orgState; - } - - /** - * @return as string - */ - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("what="); - sb.append(what); - sb.append(" state="); - sb.append(cn(state)); - sb.append(" orgState="); - sb.append(cn(orgState)); - return sb.toString(); - } - - /** - * @return an objects class name - */ - private String cn(Object n) { - if (n == null) { - return "null"; - } else { - String name = n.getClass().getName(); - int lastDollar = name.lastIndexOf('$'); - return name.substring(lastDollar + 1); - } - } - } - - private Vector<Info> mMessages = new Vector<Info>(); - private int mMaxSize = DEFAULT_SIZE; - private int mOldestIndex = 0; - private int mCount = 0; - - /** - * Constructor - */ - ProcessedMessages() { - } - - ProcessedMessages(int maxSize) { - setSize(maxSize); - } - - /** - * Set size of messages to maintain and clears all current messages. - * - * @param maxSize number of messages to maintain at anyone time. - */ - void setSize(int maxSize) { - mMaxSize = maxSize; - mCount = 0; - mMessages.clear(); - } - - /** - * @return the number of recent messages. - */ - int size() { - return mMessages.size(); - } - - /** - * @return the total number of messages processed since size was set. - */ - int count() { - return mCount; - } - - /** - * @return the information on a particular record. 0 is the oldest - * record and size()-1 is the newest record. If the index is to - * large null is returned. - */ - Info get(int index) { - int nextIndex = mOldestIndex + index; - if (nextIndex >= mMaxSize) { - nextIndex -= mMaxSize; - } - if (nextIndex >= size()) { - return null; - } else { - return mMessages.get(nextIndex); - } - } - - /** - * Add a processed message. - * - * @param message - * @param state that handled the message - * @param orgState is the first state the received the message but - * did not processes the message. - */ - void add(Message message, HierarchicalState state, HierarchicalState orgState) { - mCount += 1; - if (mMessages.size() < mMaxSize) { - mMessages.add(new Info(message, state, orgState)); - } else { - Info info = mMessages.get(mOldestIndex); - mOldestIndex += 1; - if (mOldestIndex >= mMaxSize) { - mOldestIndex = 0; - } - info.update(message, state, orgState); - } - } -} diff --git a/core/java/com/android/internal/util/Protocol.java b/core/java/com/android/internal/util/Protocol.java index 2689f09..2e7ec58 100644 --- a/core/java/com/android/internal/util/Protocol.java +++ b/core/java/com/android/internal/util/Protocol.java @@ -29,9 +29,18 @@ package com.android.internal.util; * {@hide} */ public class Protocol { - public static final int MAX_MESSAGE = 0x0000FFFF; + public static final int MAX_MESSAGE = 0x0000FFFF; + + /** Base reserved for system */ + public static final int BASE_SYSTEM_RESERVED = 0x00010000; + public static final int BASE_SYSTEM_ASYNC_CHANNEL = 0x00011000; + + /** Non system protocols */ + public static final int BASE_WIFI = 0x00020000; + public static final int BASE_DHCP = 0x00030000; + public static final int BASE_DATA_CONNECTION = 0x00040000; + public static final int BASE_DATA_CONNECTION_AC = 0x00041000; + public static final int BASE_DATA_CONNECTION_TRACKER = 0x00050000; - public static final int BASE_WIFI = 0x00010000; - public static final int BASE_DHCP = 0x00020000; //TODO: define all used protocols } diff --git a/core/java/com/android/internal/util/State.java b/core/java/com/android/internal/util/State.java new file mode 100644 index 0000000..3eadff5 --- /dev/null +++ b/core/java/com/android/internal/util/State.java @@ -0,0 +1,74 @@ +/** + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.internal.util; + +import android.os.Message; + +/** + * {@hide} + * + * The class for implementing states in a StateMachine + */ +public class State implements IState { + + /** + * Constructor + */ + protected State() { + } + + /* (non-Javadoc) + * @see com.android.internal.util.IState#enter() + */ + @Override + public void enter() { + } + + /* (non-Javadoc) + * @see com.android.internal.util.IState#exit() + */ + @Override + public void exit() { + } + + /* (non-Javadoc) + * @see com.android.internal.util.IState#processMessage(android.os.Message) + */ + @Override + public boolean processMessage(Message msg) { + return false; + } + + /** + * Name of State for debugging purposes. + * + * This default implementation returns the class name, returning + * the instance name would better in cases where a State class + * is used for multiple states. But normally there is one class per + * state and the class name is sufficient and easy to get. You may + * want to provide a setName or some other mechanism for setting + * another name if the class name is not appropriate. + * + * @see com.android.internal.util.IState#processMessage(android.os.Message) + */ + @Override + public String getName() { + String name = getClass().getName(); + int lastDollar = name.lastIndexOf('$'); + return name.substring(lastDollar + 1); + } +} diff --git a/core/java/com/android/internal/util/HierarchicalStateMachine.java b/core/java/com/android/internal/util/StateMachine.java index f43f459..cbe72dd 100644 --- a/core/java/com/android/internal/util/HierarchicalStateMachine.java +++ b/core/java/com/android/internal/util/StateMachine.java @@ -24,14 +24,15 @@ import android.util.Log; import java.util.ArrayList; import java.util.HashMap; +import java.util.Vector; /** * {@hide} * - * <p>A hierarchical state machine is a state machine which processes messages + * <p>The state machine defined here is a hierarchical state machine which processes messages * and can have states arranged hierarchically.</p> * - * <p>A state is a <code>HierarchicalState</code> object and must implement + * <p>A state is a <code>State</code> object and must implement * <code>processMessage</code> and optionally <code>enter/exit/getName</code>. * The enter/exit methods are equivalent to the construction and destruction * in Object Oriented programming and are used to perform initialization and @@ -75,7 +76,7 @@ import java.util.HashMap; * will exit the current state and its parent and then exit from the controlling thread * and no further messages will be processed.</p> * - * <p>In addition to <code>processMessage</code> each <code>HierarchicalState</code> has + * <p>In addition to <code>processMessage</code> each <code>State</code> has * an <code>enter</code> method and <code>exit</exit> method which may be overridden.</p> * * <p>Since the states are arranged in a hierarchy transitioning to a new state @@ -121,11 +122,11 @@ import java.util.HashMap; * mS4.enter. The new list of active states is mP0, mP1, mS2 and mS4. So * when the next message is received mS4.processMessage will be invoked.</p> * - * <p>Now for some concrete examples, here is the canonical HelloWorld as an HSM. + * <p>Now for some concrete examples, here is the canonical HelloWorld as a state machine. * It responds with "Hello World" being printed to the log for every message.</p> <code> -class HelloWorld extends HierarchicalStateMachine { - Hsm1(String name) { +class HelloWorld extends StateMachine { + HelloWorld(String name) { super(name); addState(mState1); setInitialState(mState1); @@ -137,7 +138,7 @@ class HelloWorld extends HierarchicalStateMachine { return hw; } - class State1 extends HierarchicalState { + class State1 extends State { @Override public boolean processMessage(Message message) { Log.d(TAG, "Hello World"); return HANDLED; @@ -220,9 +221,9 @@ state mP2 { } } </code> - * <p>The implementation is below and also in HierarchicalStateMachineTest:</p> + * <p>The implementation is below and also in StateMachineTest:</p> <code> -class Hsm1 extends HierarchicalStateMachine { +class Hsm1 extends StateMachine { private static final String TAG = "hsm1"; public static final int CMD_1 = 1; @@ -254,7 +255,7 @@ class Hsm1 extends HierarchicalStateMachine { Log.d(TAG, "ctor X"); } - class P1 extends HierarchicalState { + class P1 extends State { @Override public void enter() { Log.d(TAG, "mP1.enter"); } @@ -281,7 +282,7 @@ class Hsm1 extends HierarchicalStateMachine { } } - class S1 extends HierarchicalState { + class S1 extends State { @Override public void enter() { Log.d(TAG, "mS1.enter"); } @@ -301,7 +302,7 @@ class Hsm1 extends HierarchicalStateMachine { } } - class S2 extends HierarchicalState { + class S2 extends State { @Override public void enter() { Log.d(TAG, "mS2.enter"); } @@ -329,7 +330,7 @@ class Hsm1 extends HierarchicalStateMachine { } } - class P2 extends HierarchicalState { + class P2 extends State { @Override public void enter() { Log.d(TAG, "mP2.enter"); sendMessage(obtainMessage(CMD_5)); @@ -408,16 +409,16 @@ D/hsm1 ( 1999): mP2.exit D/hsm1 ( 1999): halting </code> */ -public class HierarchicalStateMachine { +public class StateMachine { - private static final String TAG = "HierarchicalStateMachine"; + private static final String TAG = "StateMachine"; private String mName; /** Message.what value when quitting */ - public static final int HSM_QUIT_CMD = -1; + public static final int SM_QUIT_CMD = -1; /** Message.what value when initializing */ - public static final int HSM_INIT_CMD = -1; + public static final int SM_INIT_CMD = -1; /** * Convenience constant that maybe returned by processMessage @@ -433,7 +434,181 @@ public class HierarchicalStateMachine { */ public static final boolean NOT_HANDLED = false; - private static class HsmHandler extends Handler { + /** + * {@hide} + * + * The information maintained for a processed message. + */ + public static class ProcessedMessageInfo { + private int what; + private State state; + private State orgState; + + /** + * Constructor + * @param message + * @param state that handled the message + * @param orgState is the first state the received the message but + * did not processes the message. + */ + ProcessedMessageInfo(Message message, State state, State orgState) { + update(message, state, orgState); + } + + /** + * Update the information in the record. + * @param state that handled the message + * @param orgState is the first state the received the message but + * did not processes the message. + */ + public void update(Message message, State state, State orgState) { + this.what = message.what; + this.state = state; + this.orgState = orgState; + } + + /** + * @return the command that was executing + */ + public int getWhat() { + return what; + } + + /** + * @return the state that handled this message + */ + public State getState() { + return state; + } + + /** + * @return the original state that received the message. + */ + public State getOriginalState() { + return orgState; + } + + /** + * @return as string + */ + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("what="); + sb.append(what); + sb.append(" state="); + sb.append(cn(state)); + sb.append(" orgState="); + sb.append(cn(orgState)); + return sb.toString(); + } + + /** + * @return an objects class name + */ + private String cn(Object n) { + if (n == null) { + return "null"; + } else { + String name = n.getClass().getName(); + int lastDollar = name.lastIndexOf('$'); + return name.substring(lastDollar + 1); + } + } + } + + /** + * A list of messages recently processed by the state machine. + * + * The class maintains a list of messages that have been most + * recently processed. The list is finite and may be set in the + * constructor or by calling setSize. The public interface also + * includes size which returns the number of recent messages, + * count which is the number of message processed since the + * the last setSize, get which returns a processed message and + * add which adds a processed messaged. + */ + private static class ProcessedMessages { + + private static final int DEFAULT_SIZE = 20; + + private Vector<ProcessedMessageInfo> mMessages = new Vector<ProcessedMessageInfo>(); + private int mMaxSize = DEFAULT_SIZE; + private int mOldestIndex = 0; + private int mCount = 0; + + /** + * Constructor + */ + ProcessedMessages() { + } + + /** + * Set size of messages to maintain and clears all current messages. + * + * @param maxSize number of messages to maintain at anyone time. + */ + void setSize(int maxSize) { + mMaxSize = maxSize; + mCount = 0; + mMessages.clear(); + } + + /** + * @return the number of recent messages. + */ + int size() { + return mMessages.size(); + } + + /** + * @return the total number of messages processed since size was set. + */ + int count() { + return mCount; + } + + /** + * @return the information on a particular record. 0 is the oldest + * record and size()-1 is the newest record. If the index is to + * large null is returned. + */ + ProcessedMessageInfo get(int index) { + int nextIndex = mOldestIndex + index; + if (nextIndex >= mMaxSize) { + nextIndex -= mMaxSize; + } + if (nextIndex >= size()) { + return null; + } else { + return mMessages.get(nextIndex); + } + } + + /** + * Add a processed message. + * + * @param message + * @param state that handled the message + * @param orgState is the first state the received the message but + * did not processes the message. + */ + void add(Message message, State state, State orgState) { + mCount += 1; + if (mMessages.size() < mMaxSize) { + mMessages.add(new ProcessedMessageInfo(message, state, orgState)); + } else { + ProcessedMessageInfo pmi = mMessages.get(mOldestIndex); + mOldestIndex += 1; + if (mOldestIndex >= mMaxSize) { + mOldestIndex = 0; + } + pmi.update(message, state, orgState); + } + } + } + + private static class SmHandler extends Handler { /** The debug flag */ private boolean mDbg = false; @@ -441,9 +616,6 @@ public class HierarchicalStateMachine { /** The quit object */ private static final Object mQuitObj = new Object(); - /** The initialization message */ - private static final Message mInitMsg = null; - /** The current message */ private Message mMsg; @@ -471,8 +643,8 @@ public class HierarchicalStateMachine { /** State used when state machine is quitting */ private QuittingState mQuittingState = new QuittingState(); - /** Reference to the HierarchicalStateMachine */ - private HierarchicalStateMachine mHsm; + /** Reference to the StateMachine */ + private StateMachine mSm; /** * Information about a state. @@ -480,7 +652,7 @@ public class HierarchicalStateMachine { */ private class StateInfo { /** The state */ - HierarchicalState state; + State state; /** The parent of this state, null if there is no parent */ StateInfo parentStateInfo; @@ -500,14 +672,14 @@ public class HierarchicalStateMachine { } /** The map of all of the states in the state machine */ - private HashMap<HierarchicalState, StateInfo> mStateInfo = - new HashMap<HierarchicalState, StateInfo>(); + private HashMap<State, StateInfo> mStateInfo = + new HashMap<State, StateInfo>(); /** The initial state that will process the first message */ - private HierarchicalState mInitialState; + private State mInitialState; /** The destination state when transitionTo has been invoked */ - private HierarchicalState mDestState; + private State mDestState; /** The list of deferred messages */ private ArrayList<Message> mDeferredMessages = new ArrayList<Message>(); @@ -515,10 +687,10 @@ public class HierarchicalStateMachine { /** * State entered when transitionToHaltingState is called. */ - private class HaltingState extends HierarchicalState { + private class HaltingState extends State { @Override public boolean processMessage(Message msg) { - mHsm.haltedProcessMessage(msg); + mSm.haltedProcessMessage(msg); return true; } } @@ -526,7 +698,7 @@ public class HierarchicalStateMachine { /** * State entered when a valid quit message is handled. */ - private class QuittingState extends HierarchicalState { + private class QuittingState extends State { @Override public boolean processMessage(Message msg) { return NOT_HANDLED; @@ -573,7 +745,7 @@ public class HierarchicalStateMachine { * the appropriate states. We loop on this to allow * enter and exit methods to use transitionTo. */ - HierarchicalState destState = null; + State destState = null; while (mDestState != null) { if (mDbg) Log.d(TAG, "handleMessage: new destination call exit"); @@ -613,10 +785,11 @@ public class HierarchicalStateMachine { /** * We are quitting so ignore all messages. */ - mHsm.quitting(); - if (mHsm.mHsmThread != null) { - // If we made the thread then quit looper + mSm.quitting(); + if (mSm.mSmThread != null) { + // If we made the thread then quit looper which stops the thread. getLooper().quit(); + mSm.mSmThread = null; } } else if (destState == mHaltingState) { /** @@ -624,7 +797,7 @@ public class HierarchicalStateMachine { * state. All subsequent messages will be processed in * in the halting state which invokes haltedProcessMessage(msg); */ - mHsm.halting(); + mSm.halting(); } } } @@ -660,7 +833,7 @@ public class HierarchicalStateMachine { * starting at the first entry. */ mIsConstructionCompleted = true; - mMsg = obtainMessage(HSM_INIT_CMD); + mMsg = obtainMessage(SM_INIT_CMD); invokeEnterMethods(0); /** @@ -690,7 +863,7 @@ public class HierarchicalStateMachine { /** * No parents left so it's not handled */ - mHsm.unhandledMessage(msg); + mSm.unhandledMessage(msg); if (isQuit(msg)) { transitionTo(mQuittingState); } @@ -705,7 +878,7 @@ public class HierarchicalStateMachine { * Record that we processed the message */ if (curStateInfo != null) { - HierarchicalState orgState = mStateStack[mStateStackTopIndex].state; + State orgState = mStateStack[mStateStackTopIndex].state; mProcessedMessages.add(msg, curStateInfo.state, orgState); } else { mProcessedMessages.add(msg, null, null); @@ -719,7 +892,7 @@ public class HierarchicalStateMachine { private final void invokeExitMethods(StateInfo commonStateInfo) { while ((mStateStackTopIndex >= 0) && (mStateStack[mStateStackTopIndex] != commonStateInfo)) { - HierarchicalState curState = mStateStack[mStateStackTopIndex].state; + State curState = mStateStack[mStateStackTopIndex].state; if (mDbg) Log.d(TAG, "invokeExitMethods: " + curState.getName()); curState.exit(); mStateStack[mStateStackTopIndex].active = false; @@ -761,7 +934,7 @@ public class HierarchicalStateMachine { * reversing the order of the items on the temporary stack as * they are moved. * - * @return index into mStateState where entering needs to start + * @return index into mStateStack where entering needs to start */ private final int moveTempStateStackToStateStack() { int startingIndex = mStateStackTopIndex + 1; @@ -794,7 +967,7 @@ public class HierarchicalStateMachine { * @return StateInfo of the common ancestor for the destState and * current state or null if there is no common parent. */ - private final StateInfo setupTempStateStackWithStatesToEnter(HierarchicalState destState) { + private final StateInfo setupTempStateStackWithStatesToEnter(State destState) { /** * Search up the parent list of the destination state for an active * state. Use a do while() loop as the destState must always be entered @@ -846,7 +1019,7 @@ public class HierarchicalStateMachine { /** * @return current state */ - private final HierarchicalState getCurrentState() { + private final IState getCurrentState() { return mStateStack[mStateStackTopIndex].state; } @@ -859,7 +1032,7 @@ public class HierarchicalStateMachine { * @param parent the parent of state * @return stateInfo for this state */ - private final StateInfo addState(HierarchicalState state, HierarchicalState parent) { + private final StateInfo addState(State state, State parent) { if (mDbg) { Log.d(TAG, "addStateInternal: E state=" + state.getName() + ",parent=" + ((parent == null) ? "" : parent.getName())); @@ -894,29 +1067,29 @@ public class HierarchicalStateMachine { * Constructor * * @param looper for dispatching messages - * @param hsm the hierarchical state machine + * @param sm the hierarchical state machine */ - private HsmHandler(Looper looper, HierarchicalStateMachine hsm) { + private SmHandler(Looper looper, StateMachine sm) { super(looper); - mHsm = hsm; + mSm = sm; addState(mHaltingState, null); addState(mQuittingState, null); } - /** @see HierarchicalStateMachine#setInitialState(HierarchicalState) */ - private final void setInitialState(HierarchicalState initialState) { + /** @see StateMachine#setInitialState(State) */ + private final void setInitialState(State initialState) { if (mDbg) Log.d(TAG, "setInitialState: initialState" + initialState.getName()); mInitialState = initialState; } - /** @see HierarchicalStateMachine#transitionTo(HierarchicalState) */ - private final void transitionTo(HierarchicalState destState) { - if (mDbg) Log.d(TAG, "StateMachine.transitionTo EX destState" + destState.getName()); - mDestState = destState; + /** @see StateMachine#transitionTo(IState) */ + private final void transitionTo(IState destState) { + mDestState = (State) destState; + if (mDbg) Log.d(TAG, "StateMachine.transitionTo EX destState" + mDestState.getName()); } - /** @see HierarchicalStateMachine#deferMessage(Message) */ + /** @see StateMachine#deferMessage(Message) */ private final void deferMessage(Message msg) { if (mDbg) Log.d(TAG, "deferMessage: msg=" + msg.what); @@ -927,51 +1100,51 @@ public class HierarchicalStateMachine { mDeferredMessages.add(newMsg); } - /** @see HierarchicalStateMachine#deferMessage(Message) */ + /** @see StateMachine#deferMessage(Message) */ private final void quit() { if (mDbg) Log.d(TAG, "quit:"); - sendMessage(obtainMessage(HSM_QUIT_CMD, mQuitObj)); + sendMessage(obtainMessage(SM_QUIT_CMD, mQuitObj)); } - /** @see HierarchicalStateMachine#isQuit(Message) */ + /** @see StateMachine#isQuit(Message) */ private final boolean isQuit(Message msg) { - return (msg.what == HSM_QUIT_CMD) && (msg.obj == mQuitObj); + return (msg.what == SM_QUIT_CMD) && (msg.obj == mQuitObj); } - /** @see HierarchicalStateMachine#isDbg() */ + /** @see StateMachine#isDbg() */ private final boolean isDbg() { return mDbg; } - /** @see HierarchicalStateMachine#setDbg(boolean) */ + /** @see StateMachine#setDbg(boolean) */ private final void setDbg(boolean dbg) { mDbg = dbg; } - /** @see HierarchicalStateMachine#setProcessedMessagesSize(int) */ + /** @see StateMachine#setProcessedMessagesSize(int) */ private final void setProcessedMessagesSize(int maxSize) { mProcessedMessages.setSize(maxSize); } - /** @see HierarchicalStateMachine#getProcessedMessagesSize() */ + /** @see StateMachine#getProcessedMessagesSize() */ private final int getProcessedMessagesSize() { return mProcessedMessages.size(); } - /** @see HierarchicalStateMachine#getProcessedMessagesCount() */ + /** @see StateMachine#getProcessedMessagesCount() */ private final int getProcessedMessagesCount() { return mProcessedMessages.count(); } - /** @see HierarchicalStateMachine#getProcessedMessage(int) */ - private final ProcessedMessages.Info getProcessedMessage(int index) { + /** @see StateMachine#getProcessedMessageInfo(int) */ + private final ProcessedMessageInfo getProcessedMessageInfo(int index) { return mProcessedMessages.get(index); } } - private HsmHandler mHsmHandler; - private HandlerThread mHsmThread; + private SmHandler mSmHandler; + private HandlerThread mSmThread; /** * Initialize. @@ -981,28 +1154,28 @@ public class HierarchicalStateMachine { */ private void initStateMachine(String name, Looper looper) { mName = name; - mHsmHandler = new HsmHandler(looper, this); + mSmHandler = new SmHandler(looper, this); } /** - * Constructor creates an HSM with its own thread. + * Constructor creates a StateMachine with its own thread. * * @param name of the state machine */ - protected HierarchicalStateMachine(String name) { - mHsmThread = new HandlerThread(name); - mHsmThread.start(); - Looper looper = mHsmThread.getLooper(); + protected StateMachine(String name) { + mSmThread = new HandlerThread(name); + mSmThread.start(); + Looper looper = mSmThread.getLooper(); initStateMachine(name, looper); } /** - * Constructor creates an HSMStateMachine using the looper. + * Constructor creates an StateMachine using the looper. * * @param name of the state machine */ - protected HierarchicalStateMachine(String name, Looper looper) { + protected StateMachine(String name, Looper looper) { initStateMachine(name, looper); } @@ -1011,30 +1184,30 @@ public class HierarchicalStateMachine { * @param state the state to add * @param parent the parent of state */ - protected final void addState(HierarchicalState state, HierarchicalState parent) { - mHsmHandler.addState(state, parent); + protected final void addState(State state, State parent) { + mSmHandler.addState(state, parent); } /** * @return current message */ protected final Message getCurrentMessage() { - return mHsmHandler.getCurrentMessage(); + return mSmHandler.getCurrentMessage(); } /** * @return current state */ - protected final HierarchicalState getCurrentState() { - return mHsmHandler.getCurrentState(); + protected final IState getCurrentState() { + return mSmHandler.getCurrentState(); } /** * Add a new state to the state machine, parent will be null * @param state to add */ - protected final void addState(HierarchicalState state) { - mHsmHandler.addState(state, null); + protected final void addState(State state) { + mSmHandler.addState(state, null); } /** @@ -1043,8 +1216,8 @@ public class HierarchicalStateMachine { * * @param initialState is the state which will receive the first message. */ - protected final void setInitialState(HierarchicalState initialState) { - mHsmHandler.setInitialState(initialState); + protected final void setInitialState(State initialState) { + mSmHandler.setInitialState(initialState); } /** @@ -1055,8 +1228,8 @@ public class HierarchicalStateMachine { * * @param destState will be the state that receives the next message. */ - protected final void transitionTo(HierarchicalState destState) { - mHsmHandler.transitionTo(destState); + protected final void transitionTo(IState destState) { + mSmHandler.transitionTo(destState); } /** @@ -1067,7 +1240,7 @@ public class HierarchicalStateMachine { * will be called. */ protected final void transitionToHaltingState() { - mHsmHandler.transitionTo(mHsmHandler.mHaltingState); + mSmHandler.transitionTo(mSmHandler.mHaltingState); } /** @@ -1080,7 +1253,7 @@ public class HierarchicalStateMachine { * @param msg is deferred until the next transition. */ protected final void deferMessage(Message msg) { - mHsmHandler.deferMessage(msg); + mSmHandler.deferMessage(msg); } @@ -1090,9 +1263,7 @@ public class HierarchicalStateMachine { * @param msg that couldn't be handled. */ protected void unhandledMessage(Message msg) { - if (false) { - Log.e(TAG, mName + " - unhandledMessage: msg.what=" + msg.what); - } + if (mSmHandler.mDbg) Log.e(TAG, mName + " - unhandledMessage: msg.what=" + msg.what); } /** @@ -1103,16 +1274,18 @@ public class HierarchicalStateMachine { } /** - * Called after the message that called transitionToHalting - * is called and should be overridden by StateMachine's that - * call transitionToHalting. + * This will be called once after handling a message that called + * transitionToHalting. All subsequent messages will invoke + * {@link StateMachine#haltedProcessMessage(Message)} */ protected void halting() { } /** - * Called after the quitting message was NOT handled and - * just before the quit actually occurs. + * This will be called once after a quit message that was NOT handled by + * the derived StateMachine. The StateMachine will stop and any subsequent messages will be + * ignored. In addition, if this StateMachine created the thread, the thread will + * be stopped after this method returns. */ protected void quitting() { } @@ -1130,35 +1303,35 @@ public class HierarchicalStateMachine { * @param maxSize number of messages to maintain at anyone time. */ public final void setProcessedMessagesSize(int maxSize) { - mHsmHandler.setProcessedMessagesSize(maxSize); + mSmHandler.setProcessedMessagesSize(maxSize); } /** * @return number of messages processed */ public final int getProcessedMessagesSize() { - return mHsmHandler.getProcessedMessagesSize(); + return mSmHandler.getProcessedMessagesSize(); } /** * @return the total number of messages processed */ public final int getProcessedMessagesCount() { - return mHsmHandler.getProcessedMessagesCount(); + return mSmHandler.getProcessedMessagesCount(); } /** - * @return a processed message + * @return a processed message information */ - public final ProcessedMessages.Info getProcessedMessage(int index) { - return mHsmHandler.getProcessedMessage(index); + public final ProcessedMessageInfo getProcessedMessageInfo(int index) { + return mSmHandler.getProcessedMessageInfo(index); } /** * @return Handler */ public final Handler getHandler() { - return mHsmHandler; + return mSmHandler; } /** @@ -1168,7 +1341,7 @@ public class HierarchicalStateMachine { */ public final Message obtainMessage() { - return Message.obtain(mHsmHandler); + return Message.obtain(mSmHandler); } /** @@ -1178,7 +1351,7 @@ public class HierarchicalStateMachine { * @return message */ public final Message obtainMessage(int what) { - return Message.obtain(mHsmHandler, what); + return Message.obtain(mSmHandler, what); } /** @@ -1191,7 +1364,7 @@ public class HierarchicalStateMachine { */ public final Message obtainMessage(int what, Object obj) { - return Message.obtain(mHsmHandler, what, obj); + return Message.obtain(mSmHandler, what, obj); } /** @@ -1205,7 +1378,7 @@ public class HierarchicalStateMachine { */ public final Message obtainMessage(int what, int arg1, int arg2) { - return Message.obtain(mHsmHandler, what, arg1, arg2); + return Message.obtain(mSmHandler, what, arg1, arg2); } /** @@ -1220,107 +1393,107 @@ public class HierarchicalStateMachine { */ public final Message obtainMessage(int what, int arg1, int arg2, Object obj) { - return Message.obtain(mHsmHandler, what, arg1, arg2, obj); + return Message.obtain(mSmHandler, what, arg1, arg2, obj); } /** * Enqueue a message to this state machine. */ public final void sendMessage(int what) { - mHsmHandler.sendMessage(obtainMessage(what)); + mSmHandler.sendMessage(obtainMessage(what)); } /** * Enqueue a message to this state machine. */ public final void sendMessage(int what, Object obj) { - mHsmHandler.sendMessage(obtainMessage(what,obj)); + mSmHandler.sendMessage(obtainMessage(what,obj)); } /** * Enqueue a message to this state machine. */ public final void sendMessage(Message msg) { - mHsmHandler.sendMessage(msg); + mSmHandler.sendMessage(msg); } /** * Enqueue a message to this state machine after a delay. */ public final void sendMessageDelayed(int what, long delayMillis) { - mHsmHandler.sendMessageDelayed(obtainMessage(what), delayMillis); + mSmHandler.sendMessageDelayed(obtainMessage(what), delayMillis); } /** * Enqueue a message to this state machine after a delay. */ public final void sendMessageDelayed(int what, Object obj, long delayMillis) { - mHsmHandler.sendMessageDelayed(obtainMessage(what, obj), delayMillis); + mSmHandler.sendMessageDelayed(obtainMessage(what, obj), delayMillis); } /** * Enqueue a message to this state machine after a delay. */ public final void sendMessageDelayed(Message msg, long delayMillis) { - mHsmHandler.sendMessageDelayed(msg, delayMillis); + mSmHandler.sendMessageDelayed(msg, delayMillis); } /** * Enqueue a message to the front of the queue for this state machine. - * Protected, may only be called by instances of HierarchicalStateMachine. + * Protected, may only be called by instances of StateMachine. */ protected final void sendMessageAtFrontOfQueue(int what, Object obj) { - mHsmHandler.sendMessageAtFrontOfQueue(obtainMessage(what, obj)); + mSmHandler.sendMessageAtFrontOfQueue(obtainMessage(what, obj)); } /** * Enqueue a message to the front of the queue for this state machine. - * Protected, may only be called by instances of HierarchicalStateMachine. + * Protected, may only be called by instances of StateMachine. */ protected final void sendMessageAtFrontOfQueue(int what) { - mHsmHandler.sendMessageAtFrontOfQueue(obtainMessage(what)); + mSmHandler.sendMessageAtFrontOfQueue(obtainMessage(what)); } /** * Enqueue a message to the front of the queue for this state machine. - * Protected, may only be called by instances of HierarchicalStateMachine. + * Protected, may only be called by instances of StateMachine. */ protected final void sendMessageAtFrontOfQueue(Message msg) { - mHsmHandler.sendMessageAtFrontOfQueue(msg); + mSmHandler.sendMessageAtFrontOfQueue(msg); } /** * Removes a message from the message queue. - * Protected, may only be called by instances of HierarchicalStateMachine. + * Protected, may only be called by instances of StateMachine. */ protected final void removeMessages(int what) { - mHsmHandler.removeMessages(what); + mSmHandler.removeMessages(what); } /** * Conditionally quit the looper and stop execution. * - * This sends the HSM_QUIT_MSG to the state machine and + * This sends the SM_QUIT_MSG to the state machine and * if not handled by any state's processMessage then the * state machine will be stopped and no further messages * will be processed. */ public final void quit() { - mHsmHandler.quit(); + mSmHandler.quit(); } /** * @return ture if msg is quit */ protected final boolean isQuit(Message msg) { - return mHsmHandler.isQuit(msg); + return mSmHandler.isQuit(msg); } /** * @return if debugging is enabled */ public boolean isDbg() { - return mHsmHandler.isDbg(); + return mSmHandler.isDbg(); } /** @@ -1329,7 +1502,7 @@ public class HierarchicalStateMachine { * @param dbg is true to enable debugging. */ public void setDbg(boolean dbg) { - mHsmHandler.setDbg(dbg); + mSmHandler.setDbg(dbg); } /** @@ -1337,6 +1510,6 @@ public class HierarchicalStateMachine { */ public void start() { /** Send the complete construction message */ - mHsmHandler.completeConstruction(); + mSmHandler.completeConstruction(); } } diff --git a/core/java/com/google/android/mms/pdu/PduParser.java b/core/java/com/google/android/mms/pdu/PduParser.java index 8edfe52..3f185aa 100644..100755 --- a/core/java/com/google/android/mms/pdu/PduParser.java +++ b/core/java/com/google/android/mms/pdu/PduParser.java @@ -29,6 +29,8 @@ import java.io.UnsupportedEncodingException; import java.util.Arrays; import java.util.HashMap; +import android.content.res.Resources; + public class PduParser { /** * The next are WAP values defined in WSP specification. @@ -1557,43 +1559,55 @@ public class PduParser { * Attachment = <Octet 129> * Inline = <Octet 130> */ - int len = parseValueLength(pduDataStream); - pduDataStream.mark(1); - int thisStartPos = pduDataStream.available(); - int thisEndPos = 0; - int value = pduDataStream.read(); - - if (value == PduPart.P_DISPOSITION_FROM_DATA ) { - part.setContentDisposition(PduPart.DISPOSITION_FROM_DATA); - } else if (value == PduPart.P_DISPOSITION_ATTACHMENT) { - part.setContentDisposition(PduPart.DISPOSITION_ATTACHMENT); - } else if (value == PduPart.P_DISPOSITION_INLINE) { - part.setContentDisposition(PduPart.DISPOSITION_INLINE); - } else { - pduDataStream.reset(); - /* Token-text */ - part.setContentDisposition(parseWapString(pduDataStream, TYPE_TEXT_STRING)); - } - /* get filename parameter and skip other parameters */ - thisEndPos = pduDataStream.available(); - if (thisStartPos - thisEndPos < len) { - value = pduDataStream.read(); - if (value == PduPart.P_FILENAME) { //filename is text-string - part.setFilename(parseWapString(pduDataStream, TYPE_TEXT_STRING)); + /* + * some carrier mmsc servers do not support content_disposition + * field correctly + */ + boolean contentDisposition = Resources.getSystem().getBoolean(com + .android.internal.R.bool.config_mms_content_disposition_support); + + if (contentDisposition) { + int len = parseValueLength(pduDataStream); + pduDataStream.mark(1); + int thisStartPos = pduDataStream.available(); + int thisEndPos = 0; + int value = pduDataStream.read(); + + if (value == PduPart.P_DISPOSITION_FROM_DATA ) { + part.setContentDisposition(PduPart.DISPOSITION_FROM_DATA); + } else if (value == PduPart.P_DISPOSITION_ATTACHMENT) { + part.setContentDisposition(PduPart.DISPOSITION_ATTACHMENT); + } else if (value == PduPart.P_DISPOSITION_INLINE) { + part.setContentDisposition(PduPart.DISPOSITION_INLINE); + } else { + pduDataStream.reset(); + /* Token-text */ + part.setContentDisposition(parseWapString(pduDataStream + , TYPE_TEXT_STRING)); } - /* skip other parameters */ + /* get filename parameter and skip other parameters */ thisEndPos = pduDataStream.available(); if (thisStartPos - thisEndPos < len) { - int last = len - (thisStartPos - thisEndPos); - byte[] temp = new byte[last]; - pduDataStream.read(temp, 0, last); + value = pduDataStream.read(); + if (value == PduPart.P_FILENAME) { //filename is text-string + part.setFilename(parseWapString(pduDataStream + , TYPE_TEXT_STRING)); + } + + /* skip other parameters */ + thisEndPos = pduDataStream.available(); + if (thisStartPos - thisEndPos < len) { + int last = len - (thisStartPos - thisEndPos); + byte[] temp = new byte[last]; + pduDataStream.read(temp, 0, last); + } } - } - tempPos = pduDataStream.available(); - lastLen = length - (startPos - tempPos); + tempPos = pduDataStream.available(); + lastLen = length - (startPos - tempPos); + } break; default: if (LOCAL_LOGV) { diff --git a/core/java/com/google/android/mms/util/PduCache.java b/core/java/com/google/android/mms/util/PduCache.java index 7c3fad7..866ca1e 100644 --- a/core/java/com/google/android/mms/util/PduCache.java +++ b/core/java/com/google/android/mms/util/PduCache.java @@ -235,7 +235,7 @@ public final class PduCache extends AbstractCache<Uri, PduCacheEntry> { } private void removeFromMessageBoxes(Uri key, PduCacheEntry entry) { - HashSet<Uri> msgBox = mThreads.get(entry.getMessageBox()); + HashSet<Uri> msgBox = mThreads.get(Long.valueOf(entry.getMessageBox())); if (msgBox != null) { msgBox.remove(key); } |