diff options
Diffstat (limited to 'core')
41 files changed, 2124 insertions, 943 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 491c73a..b541ec3 100644 --- a/core/java/android/net/ConnectivityManager.java +++ b/core/java/android/net/ConnectivityManager.java @@ -221,12 +221,32 @@ public class ConnectivityManager /** {@hide} */ public static final int TYPE_DUMMY = 8; + /** {@hide} */ 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 new file mode 100644 index 0000000..eaf087f --- /dev/null +++ b/core/java/android/net/DhcpStateMachine.java @@ -0,0 +1,353 @@ +/* + * 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 com.android.internal.util.Protocol; +import com.android.internal.util.State; +import com.android.internal.util.StateMachine; + +import android.app.AlarmManager; +import android.app.PendingIntent; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.net.DhcpInfoInternal; +import android.net.NetworkUtils; +import android.os.Message; +import android.os.PowerManager; +import android.os.SystemClock; +import android.util.Log; + +/** + * StateMachine that interacts with the native DHCP client and can talk to + * a controller that also needs to be a StateMachine + * + * The Dhcp state machine provides the following features: + * - Wakeup and renewal using the native DHCP client (which will not renew + * on its own when the device is in suspend state and this can lead to device + * holding IP address beyond expiry) + * - A notification right before DHCP request or renewal is started. This + * can be used for any additional setup before DHCP. For example, wifi sets + * BT-Wifi coex settings right before DHCP is initiated + * + * @hide + */ +public class DhcpStateMachine extends StateMachine { + + private static final String TAG = "DhcpStateMachine"; + private static final boolean DBG = false; + + + /* A StateMachine that controls the DhcpStateMachine */ + private StateMachine mController; + + private Context mContext; + private BroadcastReceiver mBroadcastReceiver; + private AlarmManager mAlarmManager; + private PendingIntent mDhcpRenewalIntent; + private PowerManager.WakeLock mDhcpRenewWakeLock; + private static final String WAKELOCK_TAG = "DHCP"; + + private static final int DHCP_RENEW = 0; + private static final String ACTION_DHCP_RENEW = "android.net.wifi.DHCP_RENEW"; + + private enum DhcpAction { + START, + RENEW + }; + + private String mInterfaceName; + private boolean mRegisteredForPreDhcpNotification = false; + + private static final int BASE = Protocol.BASE_DHCP; + + /* Commands from controller to start/stop DHCP */ + public static final int CMD_START_DHCP = BASE + 1; + public static final int CMD_STOP_DHCP = BASE + 2; + public static final int CMD_RENEW_DHCP = BASE + 3; + + /* Notification from DHCP state machine prior to DHCP discovery/renewal */ + public static final int CMD_PRE_DHCP_ACTION = BASE + 4; + /* Notification from DHCP state machine post DHCP discovery/renewal. Indicates + * success/failure */ + public static final int CMD_POST_DHCP_ACTION = BASE + 5; + + /* Command from controller to indicate DHCP discovery/renewal can continue + * after pre DHCP action is complete */ + public static final int CMD_PRE_DHCP_ACTION_COMPLETE = BASE + 6; + + /* Message.arg1 arguments to CMD_POST_DHCP notification */ + public static final int DHCP_SUCCESS = 1; + public static final int DHCP_FAILURE = 2; + + 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, StateMachine controller, String intf) { + super(TAG); + + mContext = context; + mController = controller; + mInterfaceName = intf; + + mAlarmManager = (AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE); + Intent dhcpRenewalIntent = new Intent(ACTION_DHCP_RENEW, null); + mDhcpRenewalIntent = PendingIntent.getBroadcast(mContext, DHCP_RENEW, dhcpRenewalIntent, 0); + + PowerManager powerManager = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE); + mDhcpRenewWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKELOCK_TAG); + + mBroadcastReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + //DHCP renew + if (DBG) Log.d(TAG, "Sending a DHCP renewal " + this); + //acquire a 40s wakelock to finish DHCP renewal + mDhcpRenewWakeLock.acquire(40000); + sendMessage(CMD_RENEW_DHCP); + } + }; + mContext.registerReceiver(mBroadcastReceiver, new IntentFilter(ACTION_DHCP_RENEW)); + + addState(mDefaultState); + addState(mStoppedState, mDefaultState); + addState(mWaitBeforeStartState, mDefaultState); + addState(mRunningState, mDefaultState); + addState(mWaitBeforeRenewalState, mDefaultState); + + setInitialState(mStoppedState); + } + + public static DhcpStateMachine makeDhcpStateMachine(Context context, StateMachine controller, + String intf) { + DhcpStateMachine dsm = new DhcpStateMachine(context, controller, intf); + dsm.start(); + return dsm; + } + + /** + * This sends a notification right before DHCP request/renewal so that the + * controller can do certain actions before DHCP packets are sent out. + * When the controller is ready, it sends a CMD_PRE_DHCP_ACTION_COMPLETE message + * to indicate DHCP can continue + * + * This is used by Wifi at this time for the purpose of doing BT-Wifi coex + * handling during Dhcp + */ + public void registerForPreDhcpNotification() { + mRegisteredForPreDhcpNotification = true; + } + + class DefaultState extends State { + @Override + public boolean processMessage(Message message) { + if (DBG) Log.d(TAG, getName() + message.toString() + "\n"); + switch (message.what) { + case CMD_RENEW_DHCP: + Log.e(TAG, "Error! Failed to handle a DHCP renewal on " + mInterfaceName); + break; + case SM_QUIT_CMD: + mContext.unregisterReceiver(mBroadcastReceiver); + //let parent kill the state machine + return NOT_HANDLED; + default: + Log.e(TAG, "Error! unhandled message " + message); + break; + } + return HANDLED; + } + } + + + class StoppedState extends State { + @Override + public void enter() { + if (DBG) Log.d(TAG, getName() + "\n"); + } + + @Override + public boolean processMessage(Message message) { + boolean retValue = HANDLED; + if (DBG) Log.d(TAG, getName() + message.toString() + "\n"); + switch (message.what) { + case CMD_START_DHCP: + if (mRegisteredForPreDhcpNotification) { + /* Notify controller before starting DHCP */ + mController.sendMessage(CMD_PRE_DHCP_ACTION); + transitionTo(mWaitBeforeStartState); + } else { + if (runDhcp(DhcpAction.START)) { + transitionTo(mRunningState); + } + } + break; + case CMD_STOP_DHCP: + //ignore + break; + default: + retValue = NOT_HANDLED; + break; + } + return retValue; + } + } + + class WaitBeforeStartState extends State { + @Override + public void enter() { + if (DBG) Log.d(TAG, getName() + "\n"); + } + + @Override + public boolean processMessage(Message message) { + boolean retValue = HANDLED; + if (DBG) Log.d(TAG, getName() + message.toString() + "\n"); + switch (message.what) { + case CMD_PRE_DHCP_ACTION_COMPLETE: + if (runDhcp(DhcpAction.START)) { + transitionTo(mRunningState); + } else { + transitionTo(mStoppedState); + } + break; + case CMD_STOP_DHCP: + transitionTo(mStoppedState); + break; + case CMD_START_DHCP: + //ignore + break; + default: + retValue = NOT_HANDLED; + break; + } + return retValue; + } + } + + class RunningState extends State { + @Override + public void enter() { + if (DBG) Log.d(TAG, getName() + "\n"); + } + + @Override + public boolean processMessage(Message message) { + boolean retValue = HANDLED; + if (DBG) Log.d(TAG, getName() + message.toString() + "\n"); + switch (message.what) { + case CMD_STOP_DHCP: + mAlarmManager.cancel(mDhcpRenewalIntent); + if (!NetworkUtils.stopDhcp(mInterfaceName)) { + Log.e(TAG, "Failed to stop Dhcp on " + mInterfaceName); + } + transitionTo(mStoppedState); + break; + case CMD_RENEW_DHCP: + if (mRegisteredForPreDhcpNotification) { + /* Notify controller before starting DHCP */ + mController.sendMessage(CMD_PRE_DHCP_ACTION); + transitionTo(mWaitBeforeRenewalState); + } else { + if (!runDhcp(DhcpAction.RENEW)) { + transitionTo(mStoppedState); + } + } + break; + case CMD_START_DHCP: + //ignore + break; + default: + retValue = NOT_HANDLED; + } + return retValue; + } + } + + class WaitBeforeRenewalState extends State { + @Override + public void enter() { + if (DBG) Log.d(TAG, getName() + "\n"); + } + + @Override + public boolean processMessage(Message message) { + boolean retValue = HANDLED; + if (DBG) Log.d(TAG, getName() + message.toString() + "\n"); + switch (message.what) { + case CMD_STOP_DHCP: + mAlarmManager.cancel(mDhcpRenewalIntent); + if (!NetworkUtils.stopDhcp(mInterfaceName)) { + Log.e(TAG, "Failed to stop Dhcp on " + mInterfaceName); + } + transitionTo(mStoppedState); + break; + case CMD_PRE_DHCP_ACTION_COMPLETE: + if (runDhcp(DhcpAction.RENEW)) { + transitionTo(mRunningState); + } else { + transitionTo(mStoppedState); + } + break; + case CMD_START_DHCP: + //ignore + break; + default: + retValue = NOT_HANDLED; + break; + } + return retValue; + } + } + + private boolean runDhcp(DhcpAction dhcpAction) { + boolean success = false; + DhcpInfoInternal dhcpInfoInternal = new DhcpInfoInternal(); + + if (dhcpAction == DhcpAction.START) { + Log.d(TAG, "DHCP request on " + mInterfaceName); + success = NetworkUtils.runDhcp(mInterfaceName, dhcpInfoInternal); + } else if (dhcpAction == DhcpAction.RENEW) { + Log.d(TAG, "DHCP renewal on " + mInterfaceName); + success = NetworkUtils.runDhcpRenew(mInterfaceName, dhcpInfoInternal); + } + + if (success) { + Log.d(TAG, "DHCP succeeded on " + mInterfaceName); + //Do it a bit earlier than half the lease duration time + //to beat the native DHCP client and avoid extra packets + //48% for one hour lease time = 29 minutes + mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, + SystemClock.elapsedRealtime() + + dhcpInfoInternal.leaseDuration * 480, //in milliseconds + mDhcpRenewalIntent); + + mController.obtainMessage(CMD_POST_DHCP_ACTION, DHCP_SUCCESS, 0, dhcpInfoInternal) + .sendToTarget(); + } else { + Log.d(TAG, "DHCP failed on " + mInterfaceName + ": " + + NetworkUtils.getDhcpError()); + NetworkUtils.stopDhcp(mInterfaceName); + mController.obtainMessage(CMD_POST_DHCP_ACTION, DHCP_FAILURE, 0) + .sendToTarget(); + } + return success; + } +} 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..61acf2b 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,7 +67,7 @@ public class LinkProperties implements Parcelable { mIfaceName = source.getInterfaceName(); mLinkAddresses = source.getLinkAddresses(); mDnses = source.getDnses(); - mGateways = source.getGateways(); + mRoutes = source.getRoutes(); mHttpProxy = new ProxyProperties(source.getHttpProxy()); } } @@ -91,7 +89,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 +97,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 +122,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 +139,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 +231,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 +272,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..bb6ee0f 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; @@ -437,7 +438,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 +494,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 +567,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 b3f3988..823d10f 100644 --- a/core/java/android/net/NetworkUtils.java +++ b/core/java/android/net/NetworkUtils.java @@ -80,6 +80,16 @@ public class NetworkUtils { public native static boolean runDhcp(String interfaceName, DhcpInfoInternal ipInfo); /** + * Initiate renewal on the Dhcp client daemon. This call blocks until it obtains + * a result (either success or failure) from the daemon. + * @param interfaceName the name of the interface to configure + * @param ipInfo if the request succeeds, this object is filled in with + * the IP address information. + * @return {@code true} for success, {@code false} for failure + */ + public native static boolean runDhcpRenew(String interfaceName, DhcpInfoInternal ipInfo); + + /** * Shut down the DHCP client daemon. * @param interfaceName the name of the interface for which the daemon * should be stopped 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..5b10531 --- /dev/null +++ b/core/java/android/net/RouteInfo.java @@ -0,0 +1,162 @@ +/* + * 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; +/** + * 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) { + try { + if ((gateway != null) && (gateway instanceof Inet4Address)) { + destination = new LinkAddress(InetAddress.getByName("0.0.0.0"), 32); + } else { + destination = new LinkAddress(InetAddress.getByName("::0"), 128); + } + } catch (Exception e) {} + } + mDestination = destination; + mGateway = gateway; + mIsDefault = isDefault(); + } + + public RouteInfo(InetAddress gateway) { + LinkAddress destination = null; + try { + if ((gateway != null) && (gateway instanceof Inet4Address)) { + destination = new LinkAddress(InetAddress.getByName("0.0.0.0"), 32); + } else { + destination = new LinkAddress(InetAddress.getByName("::0"), 128); + } + } catch (Exception e) {} + mDestination = destination; + mGateway = gateway; + mIsDefault = isDefault(); + } + + private boolean isDefault() { + boolean val = false; + if (mGateway != null) { + if (mGateway instanceof Inet4Address) { + val = (mDestination == null || mDestination.getNetworkPrefixLength() == 32); + } else { + val = (mDestination == null || mDestination.getNetworkPrefixLength() == 128); + } + } + 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()); + } + } + + 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]; + } + }; +} 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/provider/Settings.java b/core/java/android/provider/Settings.java index 6deb5a0..b09b44e 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -3688,6 +3688,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 a53c6d0..7d6e18f 100644 --- a/core/java/android/view/ViewRoot.java +++ b/core/java/android/view/ViewRoot.java @@ -1175,10 +1175,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 new file mode 100644 index 0000000..2e7ec58 --- /dev/null +++ b/core/java/com/android/internal/util/Protocol.java @@ -0,0 +1,46 @@ +/* + * 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 com.android.internal.util; + +/** + * This class defines Message.what base addresses for various protocols that are recognized + * to be unique by any {@link com.android.internal.util.Statemachine} implementation. This + * allows for interaction between different StateMachine implementations without a conflict + * of message codes. + * + * As an example, all messages in {@link android.net.wifi.WifiStateMachine} will have message + * codes with Message.what starting at Protocol.WIFI + 1 and less than or equal to Protocol.WIFI + + * Protocol.MAX_MESSAGE + * + * {@hide} + */ +public class Protocol { + 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; + + //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); } diff --git a/core/jni/android_net_NetUtils.cpp b/core/jni/android_net_NetUtils.cpp index 3adf770..904eaf9 100644 --- a/core/jni/android_net_NetUtils.cpp +++ b/core/jni/android_net_NetUtils.cpp @@ -40,6 +40,16 @@ int dhcp_do_request(const char *ifname, const char *dns2, const char *server, uint32_t *lease); + +int dhcp_do_request_renew(const char *ifname, + const char *ipaddr, + const char *gateway, + uint32_t *prefixLength, + const char *dns1, + const char *dns2, + const char *server, + uint32_t *lease); + int dhcp_stop(const char *ifname); int dhcp_release_lease(const char *ifname); char *dhcp_get_errmsg(); @@ -58,7 +68,6 @@ static struct fieldIds { jclass dhcpInfoInternalClass; jmethodID constructorId; jfieldID ipaddress; - jfieldID gateway; jfieldID prefixLength; jfieldID dns1; jfieldID dns2; @@ -146,7 +155,8 @@ static jint android_net_utils_resetConnections(JNIEnv* env, jobject clazz, jstri return (jint)result; } -static jboolean android_net_utils_runDhcp(JNIEnv* env, jobject clazz, jstring ifname, jobject info) +static jboolean android_net_utils_runDhcpCommon(JNIEnv* env, jobject clazz, jstring ifname, + jobject info, bool renew) { int result; char ipaddr[PROPERTY_VALUE_MAX]; @@ -160,12 +170,41 @@ static jboolean android_net_utils_runDhcp(JNIEnv* env, jobject clazz, jstring if const char *nameStr = env->GetStringUTFChars(ifname, NULL); if (nameStr == NULL) return (jboolean)false; - result = ::dhcp_do_request(nameStr, ipaddr, gateway, &prefixLength, - dns1, dns2, server, &lease); + if (renew) { + result = ::dhcp_do_request_renew(nameStr, ipaddr, gateway, &prefixLength, + dns1, dns2, server, &lease); + } else { + result = ::dhcp_do_request(nameStr, ipaddr, gateway, &prefixLength, + dns1, dns2, server, &lease); + } + env->ReleaseStringUTFChars(ifname, nameStr); if (result == 0 && dhcpInfoInternalFieldIds.dhcpInfoInternalClass != NULL) { env->SetObjectField(info, dhcpInfoInternalFieldIds.ipaddress, env->NewStringUTF(ipaddr)); - env->SetObjectField(info, dhcpInfoInternalFieldIds.gateway, env->NewStringUTF(gateway)); + + // set the gateway + jclass cls = env->FindClass("java/net/InetAddress"); + jmethodID method = env->GetStaticMethodID(cls, "getByName", + "(Ljava/lang/String;)Ljava/net/InetAddress;"); + jvalue args[1]; + args[0].l = env->NewStringUTF(gateway); + jobject inetAddressObject = env->CallStaticObjectMethodA(cls, method, args); + + if (!env->ExceptionOccurred()) { + cls = env->FindClass("android/net/RouteInfo"); + method = env->GetMethodID(cls, "<init>", "(Ljava/net/InetAddress;)V"); + args[0].l = inetAddressObject; + jobject routeInfoObject = env->NewObjectA(cls, method, args); + + cls = env->FindClass("android/net/DhcpInfoInternal"); + method = env->GetMethodID(cls, "addRoute", "(Landroid/net/RouteInfo;)V"); + args[0].l = routeInfoObject; + env->CallVoidMethodA(info, method, args); + } else { + // if we have an exception (host not found perhaps), just don't add the route + env->ExceptionClear(); + } + env->SetIntField(info, dhcpInfoInternalFieldIds.prefixLength, prefixLength); env->SetObjectField(info, dhcpInfoInternalFieldIds.dns1, env->NewStringUTF(dns1)); env->SetObjectField(info, dhcpInfoInternalFieldIds.dns2, env->NewStringUTF(dns2)); @@ -176,6 +215,17 @@ static jboolean android_net_utils_runDhcp(JNIEnv* env, jobject clazz, jstring if return (jboolean)(result == 0); } +static jboolean android_net_utils_runDhcp(JNIEnv* env, jobject clazz, jstring ifname, jobject info) +{ + return android_net_utils_runDhcpCommon(env, clazz, ifname, info, false); +} + +static jboolean android_net_utils_runDhcpRenew(JNIEnv* env, jobject clazz, jstring ifname, jobject info) +{ + return android_net_utils_runDhcpCommon(env, clazz, ifname, info, true); +} + + static jboolean android_net_utils_stopDhcp(JNIEnv* env, jobject clazz, jstring ifname) { int result; @@ -219,6 +269,7 @@ static JNINativeMethod gNetworkUtilMethods[] = { { "removeDefaultRoute", "(Ljava/lang/String;)I", (void *)android_net_utils_removeDefaultRoute }, { "resetConnections", "(Ljava/lang/String;)I", (void *)android_net_utils_resetConnections }, { "runDhcp", "(Ljava/lang/String;Landroid/net/DhcpInfoInternal;)Z", (void *)android_net_utils_runDhcp }, + { "runDhcpRenew", "(Ljava/lang/String;Landroid/net/DhcpInfoInternal;)Z", (void *)android_net_utils_runDhcpRenew }, { "stopDhcp", "(Ljava/lang/String;)Z", (void *)android_net_utils_stopDhcp }, { "releaseDhcpLease", "(Ljava/lang/String;)Z", (void *)android_net_utils_releaseDhcpLease }, { "getDhcpError", "()Ljava/lang/String;", (void*) android_net_utils_getDhcpError }, @@ -233,7 +284,6 @@ int register_android_net_NetworkUtils(JNIEnv* env) if (dhcpInfoInternalFieldIds.dhcpInfoInternalClass != NULL) { dhcpInfoInternalFieldIds.constructorId = env->GetMethodID(dhcpInfoInternalFieldIds.dhcpInfoInternalClass, "<init>", "()V"); dhcpInfoInternalFieldIds.ipaddress = env->GetFieldID(dhcpInfoInternalFieldIds.dhcpInfoInternalClass, "ipAddress", "Ljava/lang/String;"); - dhcpInfoInternalFieldIds.gateway = env->GetFieldID(dhcpInfoInternalFieldIds.dhcpInfoInternalClass, "gateway", "Ljava/lang/String;"); dhcpInfoInternalFieldIds.prefixLength = env->GetFieldID(dhcpInfoInternalFieldIds.dhcpInfoInternalClass, "prefixLength", "I"); dhcpInfoInternalFieldIds.dns1 = env->GetFieldID(dhcpInfoInternalFieldIds.dhcpInfoInternalClass, "dns1", "Ljava/lang/String;"); dhcpInfoInternalFieldIds.dns2 = env->GetFieldID(dhcpInfoInternalFieldIds.dhcpInfoInternalClass, "dns2", "Ljava/lang/String;"); diff --git a/core/jni/android_util_Binder.cpp b/core/jni/android_util_Binder.cpp index 9e00a7d..09a5fd4 100644 --- a/core/jni/android_util_Binder.cpp +++ b/core/jni/android_util_Binder.cpp @@ -680,6 +680,15 @@ static jlong android_os_Binder_clearCallingIdentity(JNIEnv* env, jobject clazz) static void android_os_Binder_restoreCallingIdentity(JNIEnv* env, jobject clazz, jlong token) { + // XXX temporary sanity check to debug crashes. + int uid = (int)(token>>32); + if (uid > 0 && uid < 999) { + // In Android currently there are no uids in this range. + char buf[128]; + sprintf(buf, "Restoring bad calling ident: 0x%Lx", token); + jniThrowException(env, "java/lang/IllegalStateException", buf); + return; + } IPCThreadState::self()->restoreCallingIdentity(token); } diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index 2f431c4..bb31347 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -91,10 +91,15 @@ <protected-broadcast android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" /> <protected-broadcast android:name="android.nfc.action.LLCP_LINK_STATE_CHANGED" /> + <protected-broadcast android:name="com.android.nfc_extras.action.RF_FIELD_ON_DETECTED" /> + <protected-broadcast android:name="com.android.nfc_extras.action.RF_FIELD_OFF_DETECTED" /> + <protected-broadcast android:name="com.android.nfc_extras.action.AID_SELECTED" /> + <protected-broadcast android:name="android.nfc.action.TRANSACTION_DETECTED" /> <protected-broadcast android:name="android.intent.action.CLEAR_DNS_CACHE" /> <protected-broadcast android:name="android.intent.action.PROXY_CHANGE" /> + <!-- ====================================== --> <!-- Permissions for things that cost money --> <!-- ====================================== --> @@ -490,6 +495,12 @@ android:label="@string/permlab_hardware_test" android:description="@string/permdesc_hardware_test" /> + <!-- Allows access to configure network interfaces, configure/use IPSec, etc. + @hide --> + <permission android:name="android.permission.NET_ADMIN" + android:permissionGroup="android.permission-group.SYSTEM_TOOLS" + android:protectionLevel="signature" /> + <!-- =========================================== --> <!-- Permissions associated with telephony state --> <!-- =========================================== --> diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index 27c7a4d..3224973 100644..100755 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -51,6 +51,11 @@ manager will disable alpha trasformation in animations where not strictly needed. --> <bool name="config_sf_limitedAlpha">false</bool> + + <!-- Default value used to block data calls if ims is not + connected. If you use the ims apn DCT will block + any other apn from connecting until ims apn is connected--> + <bool name="ImsConnectedDefaultValue">false</bool> <!-- Flag indicating whether the surface flinger is inefficient at performing a blur. Used by parts of the UI to turn off @@ -143,13 +148,20 @@ attributes. This is used by the connectivity manager to decide which networks can coexist based on the hardware --> <!-- An Array of "[Connection name],[ConnectivityManager connection type], - [associated radio-type],[priority] --> + [associated radio-type],[priority],[restoral-timer(ms)],[dependencyMet] --> + <!-- the 5th element "resore-time" indicates the number of milliseconds to delay + before automatically restore the default connection. Set -1 if the connection + does not require auto-restore. --> + <!-- the 6th element indicates boot-time dependency-met value. --> <string-array translatable="false" name="networkAttributes"> - <item>"wifi,1,1,1"</item> - <item>"mobile,0,0,0"</item> - <item>"mobile_mms,2,0,2"</item> - <item>"mobile_supl,3,0,2"</item> - <item>"mobile_hipri,5,0,3"</item> + <item>"wifi,1,1,1,-1,true"</item> + <item>"mobile,0,0,0,-1,true"</item> + <item>"mobile_mms,2,0,2,60000,true"</item> + <item>"mobile_supl,3,0,2,60000,true"</item> + <item>"mobile_hipri,5,0,3,60000,true"</item> + <item>"mobile_fota,10,0,2,60000,true"</item> + <item>"mobile_ims,11,0,2,60000,true"</item> + <item>"mobile_cbs,12,0,2,60000,true"</item> </string-array> <!-- This string array should be overridden by the device to present a list of radio @@ -580,4 +592,27 @@ <!-- The VoiceMail default value is displayed to my own number if it is true --> <bool name="config_telephony_use_own_number_for_voicemail">false</bool> + + <!-- If this value is true, Sms encoded as octet is decoded by utf8 decoder. + If false, decoded by Latin decoder. --> + <bool name="config_sms_utf8_support">false</bool> + + <!-- If this value is true, The mms content-disposition field is supported correctly. + If false, Content-disposition fragments are ignored --> + <bool name="config_mms_content_disposition_support">true</bool> + + <!-- If this value is true, the carrier supports sms delivery reports. + If false, sms delivery reports are not supported and the preference + option to enable/disable delivery reports is removed in the Messaging app. --> + <bool name="config_sms_delivery_reports_support">true</bool> + + <!-- If this value is true, the carrier supports mms delivery reports. + If false, mms delivery reports are not supported and the preference + option to enable/disable delivery reports is removed in the Messaging app. --> + <bool name="config_mms_delivery_reports_support">true</bool> + + <!-- If this value is true, the carrier supports mms read reports. + If false, mms read reports are not supported and the preference + option to enable/disable read reports is removed in the Messaging app. --> + <bool name="config_mms_read_reports_support">true</bool> </resources> diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/AccessPointParserHelper.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/AccessPointParserHelper.java index d22356d..27363e8 100644 --- a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/AccessPointParserHelper.java +++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/AccessPointParserHelper.java @@ -30,6 +30,7 @@ import android.net.wifi.WifiConfiguration.KeyMgmt; import android.net.wifi.WifiConfiguration.ProxySettings; import android.net.LinkAddress; import android.net.LinkProperties; +import android.net.RouteInfo; import android.util.Log; import java.io.InputStream; @@ -301,7 +302,7 @@ public class AccessPointParserHelper { if (!InetAddress.isNumeric(gwAddr)) { throw new SAXException(); } - mLinkProperties.addGateway(InetAddress.getByName(gwAddr)); + mLinkProperties.addRoute(new RouteInfo(InetAddress.getByName(gwAddr))); } catch (UnknownHostException e) { throw new SAXException(); } diff --git a/core/tests/coretests/src/android/net/LinkPropertiesTest.java b/core/tests/coretests/src/android/net/LinkPropertiesTest.java new file mode 100644 index 0000000..e3b6b5f --- /dev/null +++ b/core/tests/coretests/src/android/net/LinkPropertiesTest.java @@ -0,0 +1,200 @@ +/* + * 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.net.LinkProperties; +import android.net.RouteInfo; +import android.test.suitebuilder.annotation.SmallTest; +import junit.framework.TestCase; + +import java.net.InetAddress; + +public class LinkPropertiesTest extends TestCase { + private static String ADDRV4 = "75.208.6.1"; + private static String ADDRV6 = "2001:0db8:85a3:0000:0000:8a2e:0370:7334"; + private static String DNS1 = "75.208.7.1"; + private static String DNS2 = "69.78.7.1"; + private static String GATEWAY1 = "75.208.8.1"; + private static String GATEWAY2 = "69.78.8.1"; + private static String NAME = "qmi0"; + + @SmallTest + public void testEqualsNull() { + LinkProperties source = new LinkProperties(); + LinkProperties target = new LinkProperties(); + + assertFalse(source == target); + assertTrue(source.equals(target)); + assertTrue(source.hashCode() == target.hashCode()); + } + + @SmallTest + public void testEqualsSameOrder() { + try { + LinkProperties source = new LinkProperties(); + source.setInterfaceName(NAME); + // set 2 link addresses + source.addLinkAddress(new LinkAddress( + NetworkUtils.numericToInetAddress(ADDRV4), 32)); + source.addLinkAddress(new LinkAddress( + NetworkUtils.numericToInetAddress(ADDRV6), 128)); + // set 2 dnses + source.addDns(NetworkUtils.numericToInetAddress(DNS1)); + source.addDns(NetworkUtils.numericToInetAddress(DNS2)); + // set 2 gateways + source.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1))); + source.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2))); + + LinkProperties target = new LinkProperties(); + + // All fields are same + target.setInterfaceName(NAME); + target.addLinkAddress(new LinkAddress( + NetworkUtils.numericToInetAddress(ADDRV4), 32)); + target.addLinkAddress(new LinkAddress( + NetworkUtils.numericToInetAddress(ADDRV6), 128)); + target.addDns(NetworkUtils.numericToInetAddress(DNS1)); + target.addDns(NetworkUtils.numericToInetAddress(DNS2)); + target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1))); + target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2))); + + assertTrue(source.equals(target)); + assertTrue(source.hashCode() == target.hashCode()); + + target.clear(); + // change Interface Name + target.setInterfaceName("qmi1"); + target.addLinkAddress(new LinkAddress( + NetworkUtils.numericToInetAddress(ADDRV4), 32)); + target.addLinkAddress(new LinkAddress( + NetworkUtils.numericToInetAddress(ADDRV6), 128)); + target.addDns(NetworkUtils.numericToInetAddress(DNS1)); + target.addDns(NetworkUtils.numericToInetAddress(DNS2)); + target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1))); + target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2))); + assertFalse(source.equals(target)); + + target.clear(); + target.setInterfaceName(NAME); + // change link addresses + target.addLinkAddress(new LinkAddress( + NetworkUtils.numericToInetAddress("75.208.6.2"), 32)); + target.addLinkAddress(new LinkAddress( + NetworkUtils.numericToInetAddress(ADDRV6), 128)); + target.addDns(NetworkUtils.numericToInetAddress(DNS1)); + target.addDns(NetworkUtils.numericToInetAddress(DNS2)); + target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1))); + target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2))); + assertFalse(source.equals(target)); + + target.clear(); + target.setInterfaceName(NAME); + target.addLinkAddress(new LinkAddress( + NetworkUtils.numericToInetAddress(ADDRV4), 32)); + target.addLinkAddress(new LinkAddress( + NetworkUtils.numericToInetAddress(ADDRV6), 128)); + // change dnses + target.addDns(NetworkUtils.numericToInetAddress("75.208.7.2")); + target.addDns(NetworkUtils.numericToInetAddress(DNS2)); + target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1))); + target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2))); + assertFalse(source.equals(target)); + + target.clear(); + target.setInterfaceName(NAME); + target.addLinkAddress(new LinkAddress( + NetworkUtils.numericToInetAddress(ADDRV4), 32)); + target.addLinkAddress(new LinkAddress( + NetworkUtils.numericToInetAddress(ADDRV6), 128)); + target.addDns(NetworkUtils.numericToInetAddress(DNS1)); + target.addDns(NetworkUtils.numericToInetAddress(DNS2)); + // change gateway + target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress("75.208.8.2"))); + target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2))); + assertFalse(source.equals(target)); + + } catch (Exception e) { + throw new RuntimeException(e.toString()); + //fail(); + } + } + + @SmallTest + public void testEqualsDifferentOrder() { + try { + LinkProperties source = new LinkProperties(); + source.setInterfaceName(NAME); + // set 2 link addresses + source.addLinkAddress(new LinkAddress( + NetworkUtils.numericToInetAddress(ADDRV4), 32)); + source.addLinkAddress(new LinkAddress( + NetworkUtils.numericToInetAddress(ADDRV6), 128)); + // set 2 dnses + source.addDns(NetworkUtils.numericToInetAddress(DNS1)); + source.addDns(NetworkUtils.numericToInetAddress(DNS2)); + // set 2 gateways + source.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1))); + source.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2))); + + LinkProperties target = new LinkProperties(); + // Exchange order + target.setInterfaceName(NAME); + target.addLinkAddress(new LinkAddress( + NetworkUtils.numericToInetAddress(ADDRV6), 128)); + target.addLinkAddress(new LinkAddress( + NetworkUtils.numericToInetAddress(ADDRV4), 32)); + target.addDns(NetworkUtils.numericToInetAddress(DNS2)); + target.addDns(NetworkUtils.numericToInetAddress(DNS1)); + target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2))); + target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1))); + + assertTrue(source.equals(target)); + assertTrue(source.hashCode() == target.hashCode()); + } catch (Exception e) { + fail(); + } + } + + @SmallTest + public void testEqualsDuplicated() { + try { + LinkProperties source = new LinkProperties(); + // set 3 link addresses, eg, [A, A, B] + source.addLinkAddress(new LinkAddress( + NetworkUtils.numericToInetAddress(ADDRV4), 32)); + source.addLinkAddress(new LinkAddress( + NetworkUtils.numericToInetAddress(ADDRV4), 32)); + source.addLinkAddress(new LinkAddress( + NetworkUtils.numericToInetAddress(ADDRV6), 128)); + + LinkProperties target = new LinkProperties(); + // set 3 link addresses, eg, [A, B, B] + target.addLinkAddress(new LinkAddress( + NetworkUtils.numericToInetAddress(ADDRV4), 32)); + target.addLinkAddress(new LinkAddress( + NetworkUtils.numericToInetAddress(ADDRV6), 128)); + target.addLinkAddress(new LinkAddress( + NetworkUtils.numericToInetAddress(ADDRV6), 128)); + + assertTrue(source.equals(target)); + assertTrue(source.hashCode() == target.hashCode()); + } catch (Exception e) { + fail(); + } + } + +} diff --git a/core/tests/coretests/src/com/android/internal/util/HierarchicalStateMachineTest.java b/core/tests/coretests/src/com/android/internal/util/StateMachineTest.java index 36666c4..ab6b2b6 100644 --- a/core/tests/coretests/src/com/android/internal/util/HierarchicalStateMachineTest.java +++ b/core/tests/coretests/src/com/android/internal/util/StateMachineTest.java @@ -22,9 +22,9 @@ import android.os.Looper; import android.os.Message; import android.os.SystemClock; -import com.android.internal.util.HierarchicalState; -import com.android.internal.util.HierarchicalStateMachine; -import com.android.internal.util.ProcessedMessages; +import com.android.internal.util.State; +import com.android.internal.util.StateMachine; +import com.android.internal.util.StateMachine.ProcessedMessageInfo; import android.test.suitebuilder.annotation.MediumTest; import android.test.suitebuilder.annotation.SmallTest; @@ -33,9 +33,9 @@ import android.util.Log; import junit.framework.TestCase; /** - * Test for HierarchicalStateMachine. + * Test for StateMachine. */ -public class HierarchicalStateMachineTest extends TestCase { +public class StateMachineTest extends TestCase { private static final int TEST_CMD_1 = 1; private static final int TEST_CMD_2 = 2; private static final int TEST_CMD_3 = 3; @@ -45,12 +45,12 @@ public class HierarchicalStateMachineTest extends TestCase { private static final boolean DBG = true; private static final boolean WAIT_FOR_DEBUGGER = false; - private static final String TAG = "HierarchicalStateMachineTest"; + private static final String TAG = "StateMachineTest"; /** * Tests that we can quit the state machine. */ - class StateMachineQuitTest extends HierarchicalStateMachine { + class StateMachineQuitTest extends StateMachine { private int mQuitCount = 0; StateMachineQuitTest(String name) { @@ -65,8 +65,9 @@ public class HierarchicalStateMachineTest extends TestCase { setInitialState(mS1); } - class S1 extends HierarchicalState { - @Override protected boolean processMessage(Message message) { + class S1 extends State { + @Override + public boolean processMessage(Message message) { if (isQuit(message)) { mQuitCount += 1; if (mQuitCount > 2) { @@ -125,22 +126,22 @@ public class HierarchicalStateMachineTest extends TestCase { assertTrue(smQuitTest.getProcessedMessagesCount() == 9); - ProcessedMessages.Info pmi; + ProcessedMessageInfo pmi; // The first two message didn't quit and were handled by mS1 - pmi = smQuitTest.getProcessedMessage(6); - assertEquals(HierarchicalStateMachine.HSM_QUIT_CMD, pmi.getWhat()); + pmi = smQuitTest.getProcessedMessageInfo(6); + assertEquals(StateMachine.SM_QUIT_CMD, pmi.getWhat()); assertEquals(smQuitTest.mS1, pmi.getState()); assertEquals(smQuitTest.mS1, pmi.getOriginalState()); - pmi = smQuitTest.getProcessedMessage(7); - assertEquals(HierarchicalStateMachine.HSM_QUIT_CMD, pmi.getWhat()); + pmi = smQuitTest.getProcessedMessageInfo(7); + assertEquals(StateMachine.SM_QUIT_CMD, pmi.getWhat()); assertEquals(smQuitTest.mS1, pmi.getState()); assertEquals(smQuitTest.mS1, pmi.getOriginalState()); // The last message was never handled so the states are null - pmi = smQuitTest.getProcessedMessage(8); - assertEquals(HierarchicalStateMachine.HSM_QUIT_CMD, pmi.getWhat()); + pmi = smQuitTest.getProcessedMessageInfo(8); + assertEquals(StateMachine.SM_QUIT_CMD, pmi.getWhat()); assertEquals(null, pmi.getState()); assertEquals(null, pmi.getOriginalState()); @@ -150,7 +151,7 @@ public class HierarchicalStateMachineTest extends TestCase { /** * Test enter/exit can use transitionTo */ - class StateMachineEnterExitTransitionToTest extends HierarchicalStateMachine { + class StateMachineEnterExitTransitionToTest extends StateMachine { StateMachineEnterExitTransitionToTest(String name) { super(name); mThisSm = this; @@ -166,34 +167,38 @@ public class HierarchicalStateMachineTest extends TestCase { setInitialState(mS1); } - class S1 extends HierarchicalState { - @Override protected void enter() { + class S1 extends State { + @Override + public void enter() { // Test that message is HSM_INIT_CMD - assertEquals(HSM_INIT_CMD, getCurrentMessage().what); + assertEquals(SM_INIT_CMD, getCurrentMessage().what); // Test that a transition in enter and the initial state works mS1EnterCount += 1; transitionTo(mS2); Log.d(TAG, "S1.enter"); } - @Override protected void exit() { + @Override + public void exit() { // Test that message is HSM_INIT_CMD - assertEquals(HSM_INIT_CMD, getCurrentMessage().what); + assertEquals(SM_INIT_CMD, getCurrentMessage().what); mS1ExitCount += 1; Log.d(TAG, "S1.exit"); } } - class S2 extends HierarchicalState { - @Override protected void enter() { + class S2 extends State { + @Override + public void enter() { // Test that message is HSM_INIT_CMD - assertEquals(HSM_INIT_CMD, getCurrentMessage().what); + assertEquals(SM_INIT_CMD, getCurrentMessage().what); mS2EnterCount += 1; Log.d(TAG, "S2.enter"); } - @Override protected void exit() { + @Override + public void exit() { // Test that message is TEST_CMD_1 assertEquals(TEST_CMD_1, getCurrentMessage().what); @@ -202,7 +207,8 @@ public class HierarchicalStateMachineTest extends TestCase { transitionTo(mS4); Log.d(TAG, "S2.exit"); } - @Override protected boolean processMessage(Message message) { + @Override + public boolean processMessage(Message message) { // Start a transition to S3 but it will be // changed to a transition to S4 in exit transitionTo(mS3); @@ -211,28 +217,32 @@ public class HierarchicalStateMachineTest extends TestCase { } } - class S3 extends HierarchicalState { - @Override protected void enter() { + class S3 extends State { + @Override + public void enter() { // Test that we can do halting in an enter/exit transitionToHaltingState(); mS3EnterCount += 1; Log.d(TAG, "S3.enter"); } - @Override protected void exit() { + @Override + public void exit() { mS3ExitCount += 1; Log.d(TAG, "S3.exit"); } } - class S4 extends HierarchicalState { - @Override protected void enter() { + class S4 extends State { + @Override + public void enter() { // Test that we can do halting in an enter/exit transitionToHaltingState(); mS4EnterCount += 1; Log.d(TAG, "S4.enter"); } - @Override protected void exit() { + @Override + public void exit() { mS4ExitCount += 1; Log.d(TAG, "S4.exit"); } @@ -285,10 +295,10 @@ public class HierarchicalStateMachineTest extends TestCase { assertTrue(smEnterExitTranstionToTest.getProcessedMessagesCount() == 1); - ProcessedMessages.Info pmi; + ProcessedMessageInfo pmi; // Message should be handled by mS2. - pmi = smEnterExitTranstionToTest.getProcessedMessage(0); + pmi = smEnterExitTranstionToTest.getProcessedMessageInfo(0); assertEquals(TEST_CMD_1, pmi.getWhat()); assertEquals(smEnterExitTranstionToTest.mS2, pmi.getState()); assertEquals(smEnterExitTranstionToTest.mS2, pmi.getOriginalState()); @@ -310,7 +320,7 @@ public class HierarchicalStateMachineTest extends TestCase { /** * Tests that ProcessedMessage works as a circular buffer. */ - class StateMachine0 extends HierarchicalStateMachine { + class StateMachine0 extends StateMachine { StateMachine0(String name) { super(name); mThisSm = this; @@ -324,8 +334,9 @@ public class HierarchicalStateMachineTest extends TestCase { setInitialState(mS1); } - class S1 extends HierarchicalState { - @Override protected boolean processMessage(Message message) { + class S1 extends State { + @Override + public boolean processMessage(Message message) { if (message.what == TEST_CMD_6) { transitionToHaltingState(); } @@ -369,18 +380,18 @@ public class HierarchicalStateMachineTest extends TestCase { assertTrue(sm0.getProcessedMessagesCount() == 6); assertTrue(sm0.getProcessedMessagesSize() == 3); - ProcessedMessages.Info pmi; - pmi = sm0.getProcessedMessage(0); + ProcessedMessageInfo pmi; + pmi = sm0.getProcessedMessageInfo(0); assertEquals(TEST_CMD_4, pmi.getWhat()); assertEquals(sm0.mS1, pmi.getState()); assertEquals(sm0.mS1, pmi.getOriginalState()); - pmi = sm0.getProcessedMessage(1); + pmi = sm0.getProcessedMessageInfo(1); assertEquals(TEST_CMD_5, pmi.getWhat()); assertEquals(sm0.mS1, pmi.getState()); assertEquals(sm0.mS1, pmi.getOriginalState()); - pmi = sm0.getProcessedMessage(2); + pmi = sm0.getProcessedMessageInfo(2); assertEquals(TEST_CMD_6, pmi.getWhat()); assertEquals(sm0.mS1, pmi.getState()); assertEquals(sm0.mS1, pmi.getOriginalState()); @@ -394,7 +405,7 @@ public class HierarchicalStateMachineTest extends TestCase { * in state mS1. With the first message it transitions to * itself which causes it to be exited and reentered. */ - class StateMachine1 extends HierarchicalStateMachine { + class StateMachine1 extends StateMachine { StateMachine1(String name) { super(name); mThisSm = this; @@ -408,12 +419,17 @@ public class HierarchicalStateMachineTest extends TestCase { if (DBG) Log.d(TAG, "StateMachine1: ctor X"); } - class S1 extends HierarchicalState { - @Override protected void enter() { + class S1 extends State { + @Override + public void enter() { mEnterCount++; } - - @Override protected boolean processMessage(Message message) { + @Override + public void exit() { + mExitCount++; + } + @Override + public boolean processMessage(Message message) { if (message.what == TEST_CMD_1) { assertEquals(1, mEnterCount); assertEquals(0, mExitCount); @@ -425,10 +441,6 @@ public class HierarchicalStateMachineTest extends TestCase { } return HANDLED; } - - @Override protected void exit() { - mExitCount++; - } } @Override @@ -469,13 +481,13 @@ public class HierarchicalStateMachineTest extends TestCase { assertTrue(sm1.getProcessedMessagesSize() == 2); - ProcessedMessages.Info pmi; - pmi = sm1.getProcessedMessage(0); + ProcessedMessageInfo pmi; + pmi = sm1.getProcessedMessageInfo(0); assertEquals(TEST_CMD_1, pmi.getWhat()); assertEquals(sm1.mS1, pmi.getState()); assertEquals(sm1.mS1, pmi.getOriginalState()); - pmi = sm1.getProcessedMessage(1); + pmi = sm1.getProcessedMessageInfo(1); assertEquals(TEST_CMD_2, pmi.getWhat()); assertEquals(sm1.mS1, pmi.getState()); assertEquals(sm1.mS1, pmi.getOriginalState()); @@ -493,7 +505,7 @@ public class HierarchicalStateMachineTest extends TestCase { * mS2 then receives both of the deferred messages first TEST_CMD_1 and * then TEST_CMD_2. */ - class StateMachine2 extends HierarchicalStateMachine { + class StateMachine2 extends StateMachine { StateMachine2(String name) { super(name); mThisSm = this; @@ -508,26 +520,28 @@ public class HierarchicalStateMachineTest extends TestCase { if (DBG) Log.d(TAG, "StateMachine2: ctor X"); } - class S1 extends HierarchicalState { - @Override protected void enter() { + class S1 extends State { + @Override + public void enter() { mDidEnter = true; } - - @Override protected boolean processMessage(Message message) { + @Override + public void exit() { + mDidExit = true; + } + @Override + public boolean processMessage(Message message) { deferMessage(message); if (message.what == TEST_CMD_2) { transitionTo(mS2); } return HANDLED; } - - @Override protected void exit() { - mDidExit = true; - } } - class S2 extends HierarchicalState { - @Override protected boolean processMessage(Message message) { + class S2 extends State { + @Override + public boolean processMessage(Message message) { if (message.what == TEST_CMD_2) { transitionToHaltingState(); } @@ -571,20 +585,20 @@ public class HierarchicalStateMachineTest extends TestCase { assertTrue(sm2.getProcessedMessagesSize() == 4); - ProcessedMessages.Info pmi; - pmi = sm2.getProcessedMessage(0); + ProcessedMessageInfo pmi; + pmi = sm2.getProcessedMessageInfo(0); assertEquals(TEST_CMD_1, pmi.getWhat()); assertEquals(sm2.mS1, pmi.getState()); - pmi = sm2.getProcessedMessage(1); + pmi = sm2.getProcessedMessageInfo(1); assertEquals(TEST_CMD_2, pmi.getWhat()); assertEquals(sm2.mS1, pmi.getState()); - pmi = sm2.getProcessedMessage(2); + pmi = sm2.getProcessedMessageInfo(2); assertEquals(TEST_CMD_1, pmi.getWhat()); assertEquals(sm2.mS2, pmi.getState()); - pmi = sm2.getProcessedMessage(3); + pmi = sm2.getProcessedMessageInfo(3); assertEquals(TEST_CMD_2, pmi.getWhat()); assertEquals(sm2.mS2, pmi.getState()); @@ -598,7 +612,7 @@ public class HierarchicalStateMachineTest extends TestCase { * Test that unhandled messages in a child are handled by the parent. * When TEST_CMD_2 is received. */ - class StateMachine3 extends HierarchicalStateMachine { + class StateMachine3 extends StateMachine { StateMachine3(String name) { super(name); mThisSm = this; @@ -615,8 +629,9 @@ public class HierarchicalStateMachineTest extends TestCase { if (DBG) Log.d(TAG, "StateMachine3: ctor X"); } - class ParentState extends HierarchicalState { - @Override protected boolean processMessage(Message message) { + class ParentState extends State { + @Override + public boolean processMessage(Message message) { if (message.what == TEST_CMD_2) { transitionToHaltingState(); } @@ -624,8 +639,9 @@ public class HierarchicalStateMachineTest extends TestCase { } } - class ChildState extends HierarchicalState { - @Override protected boolean processMessage(Message message) { + class ChildState extends State { + @Override + public boolean processMessage(Message message) { return NOT_HANDLED; } } @@ -663,13 +679,13 @@ public class HierarchicalStateMachineTest extends TestCase { assertTrue(sm3.getProcessedMessagesSize() == 2); - ProcessedMessages.Info pmi; - pmi = sm3.getProcessedMessage(0); + ProcessedMessageInfo pmi; + pmi = sm3.getProcessedMessageInfo(0); assertEquals(TEST_CMD_1, pmi.getWhat()); assertEquals(sm3.mParentState, pmi.getState()); assertEquals(sm3.mChildState, pmi.getOriginalState()); - pmi = sm3.getProcessedMessage(1); + pmi = sm3.getProcessedMessageInfo(1); assertEquals(TEST_CMD_2, pmi.getWhat()); assertEquals(sm3.mParentState, pmi.getState()); assertEquals(sm3.mChildState, pmi.getOriginalState()); @@ -682,7 +698,7 @@ public class HierarchicalStateMachineTest extends TestCase { * with transition from child 1 to child 2 and child 2 * lets the parent handle the messages. */ - class StateMachine4 extends HierarchicalStateMachine { + class StateMachine4 extends StateMachine { StateMachine4(String name) { super(name); mThisSm = this; @@ -700,8 +716,9 @@ public class HierarchicalStateMachineTest extends TestCase { if (DBG) Log.d(TAG, "StateMachine4: ctor X"); } - class ParentState extends HierarchicalState { - @Override protected boolean processMessage(Message message) { + class ParentState extends State { + @Override + public boolean processMessage(Message message) { if (message.what == TEST_CMD_2) { transitionToHaltingState(); } @@ -709,15 +726,17 @@ public class HierarchicalStateMachineTest extends TestCase { } } - class ChildState1 extends HierarchicalState { - @Override protected boolean processMessage(Message message) { + class ChildState1 extends State { + @Override + public boolean processMessage(Message message) { transitionTo(mChildState2); return HANDLED; } } - class ChildState2 extends HierarchicalState { - @Override protected boolean processMessage(Message message) { + class ChildState2 extends State { + @Override + public boolean processMessage(Message message) { return NOT_HANDLED; } } @@ -757,13 +776,13 @@ public class HierarchicalStateMachineTest extends TestCase { assertTrue(sm4.getProcessedMessagesSize() == 2); - ProcessedMessages.Info pmi; - pmi = sm4.getProcessedMessage(0); + ProcessedMessageInfo pmi; + pmi = sm4.getProcessedMessageInfo(0); assertEquals(TEST_CMD_1, pmi.getWhat()); assertEquals(sm4.mChildState1, pmi.getState()); assertEquals(sm4.mChildState1, pmi.getOriginalState()); - pmi = sm4.getProcessedMessage(1); + pmi = sm4.getProcessedMessageInfo(1); assertEquals(TEST_CMD_2, pmi.getWhat()); assertEquals(sm4.mParentState, pmi.getState()); assertEquals(sm4.mChildState2, pmi.getOriginalState()); @@ -775,7 +794,7 @@ public class HierarchicalStateMachineTest extends TestCase { * Test transition from one child to another of a "complex" * hierarchy with two parents and multiple children. */ - class StateMachine5 extends HierarchicalStateMachine { + class StateMachine5 extends StateMachine { StateMachine5(String name) { super(name); mThisSm = this; @@ -797,23 +816,32 @@ public class HierarchicalStateMachineTest extends TestCase { if (DBG) Log.d(TAG, "StateMachine5: ctor X"); } - class ParentState1 extends HierarchicalState { - @Override protected void enter() { + class ParentState1 extends State { + @Override + public void enter() { mParentState1EnterCount += 1; } - @Override protected boolean processMessage(Message message) { - return HANDLED; - } - @Override protected void exit() { + @Override + public void exit() { mParentState1ExitCount += 1; } + @Override + public boolean processMessage(Message message) { + return HANDLED; + } } - class ChildState1 extends HierarchicalState { - @Override protected void enter() { + class ChildState1 extends State { + @Override + public void enter() { mChildState1EnterCount += 1; } - @Override protected boolean processMessage(Message message) { + @Override + public void exit() { + mChildState1ExitCount += 1; + } + @Override + public boolean processMessage(Message message) { assertEquals(1, mParentState1EnterCount); assertEquals(0, mParentState1ExitCount); assertEquals(1, mChildState1EnterCount); @@ -832,16 +860,19 @@ public class HierarchicalStateMachineTest extends TestCase { transitionTo(mChildState2); return HANDLED; } - @Override protected void exit() { - mChildState1ExitCount += 1; - } } - class ChildState2 extends HierarchicalState { - @Override protected void enter() { + class ChildState2 extends State { + @Override + public void enter() { mChildState2EnterCount += 1; } - @Override protected boolean processMessage(Message message) { + @Override + public void exit() { + mChildState2ExitCount += 1; + } + @Override + public boolean processMessage(Message message) { assertEquals(1, mParentState1EnterCount); assertEquals(0, mParentState1ExitCount); assertEquals(1, mChildState1EnterCount); @@ -860,16 +891,19 @@ public class HierarchicalStateMachineTest extends TestCase { transitionTo(mChildState5); return HANDLED; } - @Override protected void exit() { - mChildState2ExitCount += 1; - } } - class ParentState2 extends HierarchicalState { - @Override protected void enter() { + class ParentState2 extends State { + @Override + public void enter() { mParentState2EnterCount += 1; } - @Override protected boolean processMessage(Message message) { + @Override + public void exit() { + mParentState2ExitCount += 1; + } + @Override + public boolean processMessage(Message message) { assertEquals(1, mParentState1EnterCount); assertEquals(1, mParentState1ExitCount); assertEquals(1, mChildState1EnterCount); @@ -888,16 +922,19 @@ public class HierarchicalStateMachineTest extends TestCase { transitionToHaltingState(); return HANDLED; } - @Override protected void exit() { - mParentState2ExitCount += 1; - } } - class ChildState3 extends HierarchicalState { - @Override protected void enter() { + class ChildState3 extends State { + @Override + public void enter() { mChildState3EnterCount += 1; } - @Override protected boolean processMessage(Message message) { + @Override + public void exit() { + mChildState3ExitCount += 1; + } + @Override + public boolean processMessage(Message message) { assertEquals(1, mParentState1EnterCount); assertEquals(1, mParentState1ExitCount); assertEquals(1, mChildState1EnterCount); @@ -916,16 +953,19 @@ public class HierarchicalStateMachineTest extends TestCase { transitionTo(mChildState4); return HANDLED; } - @Override protected void exit() { - mChildState3ExitCount += 1; - } } - class ChildState4 extends HierarchicalState { - @Override protected void enter() { + class ChildState4 extends State { + @Override + public void enter() { mChildState4EnterCount += 1; } - @Override protected boolean processMessage(Message message) { + @Override + public void exit() { + mChildState4ExitCount += 1; + } + @Override + public boolean processMessage(Message message) { assertEquals(1, mParentState1EnterCount); assertEquals(1, mParentState1ExitCount); assertEquals(1, mChildState1EnterCount); @@ -944,16 +984,19 @@ public class HierarchicalStateMachineTest extends TestCase { transitionTo(mParentState2); return HANDLED; } - @Override protected void exit() { - mChildState4ExitCount += 1; - } } - class ChildState5 extends HierarchicalState { - @Override protected void enter() { + class ChildState5 extends State { + @Override + public void enter() { mChildState5EnterCount += 1; } - @Override protected boolean processMessage(Message message) { + @Override + public void exit() { + mChildState5ExitCount += 1; + } + @Override + public boolean processMessage(Message message) { assertEquals(1, mParentState1EnterCount); assertEquals(1, mParentState1ExitCount); assertEquals(1, mChildState1EnterCount); @@ -972,9 +1015,6 @@ public class HierarchicalStateMachineTest extends TestCase { transitionTo(mChildState3); return HANDLED; } - @Override protected void exit() { - mChildState5ExitCount += 1; - } } @Override @@ -1050,33 +1090,33 @@ public class HierarchicalStateMachineTest extends TestCase { assertEquals(1, sm5.mChildState5EnterCount); assertEquals(1, sm5.mChildState5ExitCount); - ProcessedMessages.Info pmi; - pmi = sm5.getProcessedMessage(0); + ProcessedMessageInfo pmi; + pmi = sm5.getProcessedMessageInfo(0); assertEquals(TEST_CMD_1, pmi.getWhat()); assertEquals(sm5.mChildState1, pmi.getState()); assertEquals(sm5.mChildState1, pmi.getOriginalState()); - pmi = sm5.getProcessedMessage(1); + pmi = sm5.getProcessedMessageInfo(1); assertEquals(TEST_CMD_2, pmi.getWhat()); assertEquals(sm5.mChildState2, pmi.getState()); assertEquals(sm5.mChildState2, pmi.getOriginalState()); - pmi = sm5.getProcessedMessage(2); + pmi = sm5.getProcessedMessageInfo(2); assertEquals(TEST_CMD_3, pmi.getWhat()); assertEquals(sm5.mChildState5, pmi.getState()); assertEquals(sm5.mChildState5, pmi.getOriginalState()); - pmi = sm5.getProcessedMessage(3); + pmi = sm5.getProcessedMessageInfo(3); assertEquals(TEST_CMD_4, pmi.getWhat()); assertEquals(sm5.mChildState3, pmi.getState()); assertEquals(sm5.mChildState3, pmi.getOriginalState()); - pmi = sm5.getProcessedMessage(4); + pmi = sm5.getProcessedMessageInfo(4); assertEquals(TEST_CMD_5, pmi.getWhat()); assertEquals(sm5.mChildState4, pmi.getState()); assertEquals(sm5.mChildState4, pmi.getOriginalState()); - pmi = sm5.getProcessedMessage(5); + pmi = sm5.getProcessedMessageInfo(5); assertEquals(TEST_CMD_6, pmi.getWhat()); assertEquals(sm5.mParentState2, pmi.getState()); assertEquals(sm5.mParentState2, pmi.getOriginalState()); @@ -1089,7 +1129,7 @@ public class HierarchicalStateMachineTest extends TestCase { * after construction and before any other messages arrive and that * sendMessageDelayed works. */ - class StateMachine6 extends HierarchicalStateMachine { + class StateMachine6 extends StateMachine { StateMachine6(String name) { super(name); mThisSm = this; @@ -1103,13 +1143,13 @@ public class HierarchicalStateMachineTest extends TestCase { if (DBG) Log.d(TAG, "StateMachine6: ctor X"); } - class S1 extends HierarchicalState { - - @Override protected void enter() { + class S1 extends State { + @Override + public void enter() { sendMessage(TEST_CMD_1); } - - @Override protected boolean processMessage(Message message) { + @Override + public boolean processMessage(Message message) { if (message.what == TEST_CMD_1) { mArrivalTimeMsg1 = SystemClock.elapsedRealtime(); } else if (message.what == TEST_CMD_2) { @@ -1118,9 +1158,6 @@ public class HierarchicalStateMachineTest extends TestCase { } return HANDLED; } - - @Override protected void exit() { - } } @Override @@ -1178,7 +1215,7 @@ public class HierarchicalStateMachineTest extends TestCase { * Test that enter is invoked immediately after exit. This validates * that enter can be used to send a watch dog message for its state. */ - class StateMachine7 extends HierarchicalStateMachine { + class StateMachine7 extends StateMachine { private final int SM7_DELAY_TIME = 250; StateMachine7(String name) { @@ -1195,24 +1232,26 @@ public class HierarchicalStateMachineTest extends TestCase { if (DBG) Log.d(TAG, "StateMachine7: ctor X"); } - class S1 extends HierarchicalState { - @Override protected boolean processMessage(Message message) { + class S1 extends State { + @Override + public void exit() { + sendMessage(TEST_CMD_2); + } + @Override + public boolean processMessage(Message message) { transitionTo(mS2); return HANDLED; } - @Override protected void exit() { - sendMessage(TEST_CMD_2); - } } - class S2 extends HierarchicalState { - - @Override protected void enter() { + class S2 extends State { + @Override + public void enter() { // Send a delayed message as a watch dog sendMessageDelayed(TEST_CMD_3, SM7_DELAY_TIME); } - - @Override protected boolean processMessage(Message message) { + @Override + public boolean processMessage(Message message) { if (message.what == TEST_CMD_2) { mMsgCount += 1; mArrivalTimeMsg2 = SystemClock.elapsedRealtime(); @@ -1226,9 +1265,6 @@ public class HierarchicalStateMachineTest extends TestCase { } return HANDLED; } - - @Override protected void exit() { - } } @Override @@ -1286,7 +1322,7 @@ public class HierarchicalStateMachineTest extends TestCase { /** * Test unhandledMessage. */ - class StateMachineUnhandledMessage extends HierarchicalStateMachine { + class StateMachineUnhandledMessage extends StateMachine { StateMachineUnhandledMessage(String name) { super(name); mThisSm = this; @@ -1298,13 +1334,14 @@ public class HierarchicalStateMachineTest extends TestCase { // Set the initial state setInitialState(mS1); } - - @Override protected void unhandledMessage(Message message) { + @Override + public void unhandledMessage(Message message) { mUnhandledMessageCount += 1; } - class S1 extends HierarchicalState { - @Override protected boolean processMessage(Message message) { + class S1 extends State { + @Override + public boolean processMessage(Message message) { if (message.what == TEST_CMD_2) { transitionToHaltingState(); } @@ -1359,7 +1396,7 @@ public class HierarchicalStateMachineTest extends TestCase { * will be used to notify testStateMachineSharedThread that the test is * complete. */ - class StateMachineSharedThread extends HierarchicalStateMachine { + class StateMachineSharedThread extends StateMachine { StateMachineSharedThread(String name, Looper looper, int maxCount) { super(name, looper); mMaxCount = maxCount; @@ -1372,8 +1409,9 @@ public class HierarchicalStateMachineTest extends TestCase { setInitialState(mS1); } - class S1 extends HierarchicalState { - @Override protected boolean processMessage(Message message) { + class S1 extends State { + @Override + public boolean processMessage(Message message) { if (message.what == TEST_CMD_4) { transitionToHaltingState(); } @@ -1434,7 +1472,7 @@ public class HierarchicalStateMachineTest extends TestCase { for (StateMachineSharedThread sm : sms) { assertTrue(sm.getProcessedMessagesCount() == 4); for (int i = 0; i < sm.getProcessedMessagesCount(); i++) { - ProcessedMessages.Info pmi = sm.getProcessedMessage(i); + ProcessedMessageInfo pmi = sm.getProcessedMessageInfo(i); assertEquals(i+1, pmi.getWhat()); assertEquals(sm.mS1, pmi.getState()); assertEquals(sm.mS1, pmi.getOriginalState()); @@ -1464,37 +1502,37 @@ public class HierarchicalStateMachineTest extends TestCase { } assertEquals(7, sm.getProcessedMessagesCount()); - ProcessedMessages.Info pmi = sm.getProcessedMessage(0); + ProcessedMessageInfo pmi = sm.getProcessedMessageInfo(0); assertEquals(Hsm1.CMD_1, pmi.getWhat()); assertEquals(sm.mS1, pmi.getState()); assertEquals(sm.mS1, pmi.getOriginalState()); - pmi = sm.getProcessedMessage(1); + pmi = sm.getProcessedMessageInfo(1); assertEquals(Hsm1.CMD_2, pmi.getWhat()); assertEquals(sm.mP1, pmi.getState()); assertEquals(sm.mS1, pmi.getOriginalState()); - pmi = sm.getProcessedMessage(2); + pmi = sm.getProcessedMessageInfo(2); assertEquals(Hsm1.CMD_2, pmi.getWhat()); assertEquals(sm.mS2, pmi.getState()); assertEquals(sm.mS2, pmi.getOriginalState()); - pmi = sm.getProcessedMessage(3); + pmi = sm.getProcessedMessageInfo(3); assertEquals(Hsm1.CMD_3, pmi.getWhat()); assertEquals(sm.mS2, pmi.getState()); assertEquals(sm.mS2, pmi.getOriginalState()); - pmi = sm.getProcessedMessage(4); + pmi = sm.getProcessedMessageInfo(4); assertEquals(Hsm1.CMD_3, pmi.getWhat()); assertEquals(sm.mP2, pmi.getState()); assertEquals(sm.mP2, pmi.getOriginalState()); - pmi = sm.getProcessedMessage(5); + pmi = sm.getProcessedMessageInfo(5); assertEquals(Hsm1.CMD_4, pmi.getWhat()); assertEquals(sm.mP2, pmi.getState()); assertEquals(sm.mP2, pmi.getOriginalState()); - pmi = sm.getProcessedMessage(6); + pmi = sm.getProcessedMessageInfo(6); assertEquals(Hsm1.CMD_5, pmi.getWhat()); assertEquals(sm.mP2, pmi.getState()); assertEquals(sm.mP2, pmi.getOriginalState()); @@ -1503,7 +1541,7 @@ public class HierarchicalStateMachineTest extends TestCase { } } -class Hsm1 extends HierarchicalStateMachine { +class Hsm1 extends StateMachine { private static final String TAG = "hsm1"; public static final int CMD_1 = 1; @@ -1535,11 +1573,17 @@ class Hsm1 extends HierarchicalStateMachine { Log.d(TAG, "ctor X"); } - class P1 extends HierarchicalState { - @Override protected void enter() { + class P1 extends State { + @Override + public void enter() { Log.d(TAG, "P1.enter"); } - @Override protected boolean processMessage(Message message) { + @Override + public void exit() { + Log.d(TAG, "P1.exit"); + } + @Override + public boolean processMessage(Message message) { boolean retVal; Log.d(TAG, "P1.processMessage what=" + message.what); switch(message.what) { @@ -1557,16 +1601,19 @@ class Hsm1 extends HierarchicalStateMachine { } return retVal; } - @Override protected void exit() { - Log.d(TAG, "P1.exit"); - } } - class S1 extends HierarchicalState { - @Override protected void enter() { + class S1 extends State { + @Override + public void enter() { Log.d(TAG, "S1.enter"); } - @Override protected boolean processMessage(Message message) { + @Override + public void exit() { + Log.d(TAG, "S1.exit"); + } + @Override + public boolean processMessage(Message message) { Log.d(TAG, "S1.processMessage what=" + message.what); if (message.what == CMD_1) { // Transition to ourself to show that enter/exit is called @@ -1577,16 +1624,19 @@ class Hsm1 extends HierarchicalStateMachine { return NOT_HANDLED; } } - @Override protected void exit() { - Log.d(TAG, "S1.exit"); - } } - class S2 extends HierarchicalState { - @Override protected void enter() { + class S2 extends State { + @Override + public void enter() { Log.d(TAG, "S2.enter"); } - @Override protected boolean processMessage(Message message) { + @Override + public void exit() { + Log.d(TAG, "S2.exit"); + } + @Override + public boolean processMessage(Message message) { boolean retVal; Log.d(TAG, "S2.processMessage what=" + message.what); switch(message.what) { @@ -1605,17 +1655,20 @@ class Hsm1 extends HierarchicalStateMachine { } return retVal; } - @Override protected void exit() { - Log.d(TAG, "S2.exit"); - } } - class P2 extends HierarchicalState { - @Override protected void enter() { + class P2 extends State { + @Override + public void enter() { Log.d(TAG, "P2.enter"); sendMessage(CMD_5); } - @Override protected boolean processMessage(Message message) { + @Override + public void exit() { + Log.d(TAG, "P2.exit"); + } + @Override + public boolean processMessage(Message message) { Log.d(TAG, "P2.processMessage what=" + message.what); switch(message.what) { case(CMD_3): @@ -1628,9 +1681,6 @@ class Hsm1 extends HierarchicalStateMachine { } return HANDLED; } - @Override protected void exit() { - Log.d(TAG, "P2.exit"); - } } @Override |