diff options
21 files changed, 910 insertions, 200 deletions
diff --git a/core/java/android/app/Dialog.java b/core/java/android/app/Dialog.java index 087753b..82186dd 100644 --- a/core/java/android/app/Dialog.java +++ b/core/java/android/app/Dialog.java @@ -931,7 +931,7 @@ public class Dialog implements DialogInterface, Window.Callback, // associate search with owner activity final ComponentName appName = getAssociatedActivity(); - if (appName != null) { + if (appName != null && searchManager.getSearchableInfo(appName) != null) { searchManager.startSearch(null, false, appName, null, false); dismiss(); return true; 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/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/text/TextUtils.java b/core/java/android/text/TextUtils.java index ac5db62..6741059 100644 --- a/core/java/android/text/TextUtils.java +++ b/core/java/android/text/TextUtils.java @@ -629,10 +629,16 @@ public class TextUtils { public CharSequence createFromParcel(Parcel p) { int kind = p.readInt(); - if (kind == 1) - return p.readString(); + String string = p.readString(); + if (string == null) { + return null; + } + + if (kind == 1) { + return string; + } - SpannableString sp = new SpannableString(p.readString()); + SpannableString sp = new SpannableString(string); while (true) { kind = p.readInt(); diff --git a/core/java/android/widget/ScrollView.java b/core/java/android/widget/ScrollView.java index 4b4f5f2..ade3a0a 100644 --- a/core/java/android/widget/ScrollView.java +++ b/core/java/android/widget/ScrollView.java @@ -873,7 +873,7 @@ public class ScrollView extends FrameLayout { int count = getChildCount(); if (count > 0) { View view = getChildAt(count - 1); - mTempRect.bottom = view.getBottom(); + mTempRect.bottom = view.getBottom() + mPaddingBottom; mTempRect.top = mTempRect.bottom - height; } } @@ -949,9 +949,7 @@ public class ScrollView extends FrameLayout { } else if (direction == View.FOCUS_DOWN) { if (getChildCount() > 0) { int daBottom = getChildAt(0).getBottom(); - - int screenBottom = getScrollY() + getHeight(); - + int screenBottom = getScrollY() + getHeight() - mPaddingBottom; if (daBottom - screenBottom < maxJump) { scrollDelta = daBottom - screenBottom; } diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java index 7cf33fc..12687a1 100644 --- a/core/java/com/android/internal/os/BatteryStatsImpl.java +++ b/core/java/com/android/internal/os/BatteryStatsImpl.java @@ -4904,7 +4904,7 @@ public final class BatteryStatsImpl extends BatteryStats { void readOldHistory(Parcel in) { mHistory = mHistoryEnd = mHistoryCache = null; long time; - while ((time=in.readLong()) >= 0) { + while (in.dataAvail() > 0 && (time=in.readLong()) >= 0) { HistoryItem rec = new HistoryItem(time, in); addHistoryRecordLocked(rec); } diff --git a/core/java/com/android/internal/util/AsyncChannel.java b/core/java/com/android/internal/util/AsyncChannel.java index 4d656c0..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,20 +122,20 @@ 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 @@ -141,7 +148,7 @@ public class AsyncChannel { * 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; @@ -152,6 +159,9 @@ public class AsyncChannel { /** 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; @@ -174,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 @@ -184,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"); @@ -207,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; } /** @@ -246,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); } } @@ -286,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; @@ -294,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 @@ -336,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; @@ -346,7 +423,7 @@ public class AsyncChannel { * Disconnect */ public void disconnect() { - if (mConnection != null) { + if ((mConnection != null) && (mSrcContext != null)) { mSrcContext.unbindService(mConnection); } if (mSrcHandler != null) { @@ -445,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); @@ -695,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; @@ -747,11 +829,13 @@ public class AsyncChannel { AsyncChannelConnection() { } + @Override public void onServiceConnected(ComponentName className, IBinder service) { mDstMessenger = new Messenger(service); replyHalfConnected(STATUS_SUCCESSFUL); } + @Override public void onServiceDisconnected(ComponentName className) { replyDisconnected(STATUS_SUCCESSFUL); } diff --git a/core/java/com/android/internal/util/Protocol.java b/core/java/com/android/internal/util/Protocol.java index 2689f09..b35f615 100644 --- a/core/java/com/android/internal/util/Protocol.java +++ b/core/java/com/android/internal/util/Protocol.java @@ -29,9 +29,17 @@ package com.android.internal.util; * {@hide} */ public class Protocol { - public static final int MAX_MESSAGE = 0x0000FFFF; + public static final int MAX_MESSAGE = 0x0000FFFF; + + /** Base reserved for system */ + public static final int BASE_SYSTEM_RESERVED = 0x00010000; + public static final int BASE_SYSTEM_ASYNC_CHANNEL = 0x00011000; + + /** Non system protocols */ + public static final int BASE_WIFI = 0x00020000; + public static final int BASE_DHCP = 0x00030000; + public static final int BASE_DATA_CONNECTION = 0x00040000; + public static final int BASE_DATA_CONNECTION_TRACKER = 0x00050000; - public static final int BASE_WIFI = 0x00010000; - public static final int BASE_DHCP = 0x00020000; //TODO: define all used protocols } diff --git a/core/jni/android/graphics/Movie.cpp b/core/jni/android/graphics/Movie.cpp index c112423..c1acaa3 100644 --- a/core/jni/android/graphics/Movie.cpp +++ b/core/jni/android/graphics/Movie.cpp @@ -112,6 +112,10 @@ static jobject movie_decodeByteArray(JNIEnv* env, jobject clazz, return create_jmovie(env, moov); } +static void movie_destructor(JNIEnv* env, jobject, SkMovie* movie) { + delete movie; +} + ////////////////////////////////////////////////////////////////////////////////////////////// #include <android_runtime/AndroidRuntime.h> @@ -126,6 +130,7 @@ static JNINativeMethod gMethods[] = { (void*)movie_draw }, { "decodeStream", "(Ljava/io/InputStream;)Landroid/graphics/Movie;", (void*)movie_decodeStream }, + { "nativeDestructor","(I)V", (void*)movie_destructor }, { "decodeByteArray", "([BII)Landroid/graphics/Movie;", (void*)movie_decodeByteArray }, }; diff --git a/core/jni/android_net_NetUtils.cpp b/core/jni/android_net_NetUtils.cpp index 4a0e68e..9f675a2 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(); @@ -145,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]; @@ -159,8 +170,14 @@ 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) { env->SetObjectField(info, dhcpInfoInternalFieldIds.ipaddress, env->NewStringUTF(ipaddr)); @@ -175,6 +192,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; @@ -218,6 +246,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 }, diff --git a/core/tests/coretests/AndroidManifest.xml b/core/tests/coretests/AndroidManifest.xml index 010e3c3..fadf1ec 100644 --- a/core/tests/coretests/AndroidManifest.xml +++ b/core/tests/coretests/AndroidManifest.xml @@ -421,6 +421,13 @@ </intent-filter> </activity> + <activity android:name="android.widget.scroll.arrowscroll.MultiPageTextWithPadding" android:label="arrowscrollMultiPageTextWithPadding"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST" /> + </intent-filter> + </activity> + <activity android:name="android.view.Include" android:label="IncludeTag"> <intent-filter> <action android:name="android.intent.action.MAIN" /> diff --git a/core/tests/coretests/src/android/text/TextUtilsTest.java b/core/tests/coretests/src/android/text/TextUtilsTest.java index c82962d..d494c5d 100644 --- a/core/tests/coretests/src/android/text/TextUtilsTest.java +++ b/core/tests/coretests/src/android/text/TextUtilsTest.java @@ -19,6 +19,7 @@ package android.text; import com.google.android.collect.Lists; import android.test.MoreAsserts; +import android.os.Parcel; import android.test.suitebuilder.annotation.LargeTest; import android.test.suitebuilder.annotation.SmallTest; import android.text.style.StyleSpan; @@ -344,6 +345,51 @@ public class TextUtilsTest extends TestCase { assertFalse(TextUtils.delimitedStringContains("network,mock,gpsx", ',', "gps")); } + @SmallTest + public void testCharSequenceCreator() { + Parcel p = Parcel.obtain(); + TextUtils.writeToParcel(null, p, 0); + CharSequence text = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(p); + assertNull("null CharSequence should generate null from parcel", text); + p = Parcel.obtain(); + TextUtils.writeToParcel("test", p, 0); + text = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(p); + assertEquals("conversion to/from parcel failed", "test", text); + } + + @SmallTest + public void testCharSequenceCreatorNull() { + Parcel p; + CharSequence text; + p = Parcel.obtain(); + TextUtils.writeToParcel(null, p, 0); + p.setDataPosition(0); + text = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(p); + assertNull("null CharSequence should generate null from parcel", text); + } + + @SmallTest + public void testCharSequenceCreatorSpannable() { + Parcel p; + CharSequence text; + p = Parcel.obtain(); + TextUtils.writeToParcel(new SpannableString("test"), p, 0); + p.setDataPosition(0); + text = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(p); + assertEquals("conversion to/from parcel failed", "test", text.toString()); + } + + @SmallTest + public void testCharSequenceCreatorString() { + Parcel p; + CharSequence text; + p = Parcel.obtain(); + TextUtils.writeToParcel("test", p, 0); + p.setDataPosition(0); + text = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(p); + assertEquals("conversion to/from parcel failed", "test", text.toString()); + } + /** * CharSequence wrapper for testing the cases where text is copied into * a char array instead of working from a String or a Spanned. diff --git a/core/tests/coretests/src/android/util/ScrollViewScenario.java b/core/tests/coretests/src/android/util/ScrollViewScenario.java index 83afe06..db3d9d0 100644 --- a/core/tests/coretests/src/android/util/ScrollViewScenario.java +++ b/core/tests/coretests/src/android/util/ScrollViewScenario.java @@ -61,6 +61,7 @@ public abstract class ScrollViewScenario extends Activity { /** * Partially implement ViewFactory given a height ratio. + * A negative height ratio means that WRAP_CONTENT will be used as height */ private static abstract class ViewFactoryBase implements ViewFactory { @@ -87,6 +88,9 @@ public abstract class ScrollViewScenario extends Activity { List<ViewFactory> mViewFactories = Lists.newArrayList(); + int mTopPadding = 0; + int mBottomPadding = 0; + /** * Add a text view. * @param text The text of the text view. @@ -186,6 +190,13 @@ public abstract class ScrollViewScenario extends Activity { }); return this; } + + public Params addPaddingToScrollView(int topPadding, int bottomPadding) { + mTopPadding = topPadding; + mBottomPadding = bottomPadding; + + return this; + } } /** @@ -239,13 +250,17 @@ public abstract class ScrollViewScenario extends Activity { // create views specified by params for (ViewFactory viewFactory : params.mViewFactories) { + int height = ViewGroup.LayoutParams.WRAP_CONTENT; + if (viewFactory.getHeightRatio() >= 0) { + height = (int) (viewFactory.getHeightRatio() * screenHeight); + } final LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - (int) (viewFactory.getHeightRatio() * screenHeight)); + ViewGroup.LayoutParams.MATCH_PARENT, height); mLinearLayout.addView(viewFactory.create(this), lp); } mScrollView = createScrollView(); + mScrollView.setPadding(0, params.mTopPadding, 0, params.mBottomPadding); mScrollView.addView(mLinearLayout, new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); diff --git a/core/tests/coretests/src/android/widget/scroll/arrowscroll/MultiPageTextWithPadding.java b/core/tests/coretests/src/android/widget/scroll/arrowscroll/MultiPageTextWithPadding.java new file mode 100644 index 0000000..7d5a8d8 --- /dev/null +++ b/core/tests/coretests/src/android/widget/scroll/arrowscroll/MultiPageTextWithPadding.java @@ -0,0 +1,38 @@ +/* + * 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.widget.scroll.arrowscroll; + +import android.util.ScrollViewScenario; + +/** + * One TextView with a text covering several pages. Padding is added + * above and below the ScrollView. + */ +public class MultiPageTextWithPadding extends ScrollViewScenario { + + @Override + protected void init(Params params) { + + String text = "This is a long text."; + String longText = "First text."; + for (int i = 0; i < 300; i++) { + longText = longText + " " + text; + } + longText = longText + " Last text."; + params.addTextView(longText, -1.0f).addPaddingToScrollView(50, 50); + } +} diff --git a/core/tests/coretests/src/android/widget/scroll/arrowscroll/MultiPageTextWithPaddingTest.java b/core/tests/coretests/src/android/widget/scroll/arrowscroll/MultiPageTextWithPaddingTest.java new file mode 100644 index 0000000..ddde48f --- /dev/null +++ b/core/tests/coretests/src/android/widget/scroll/arrowscroll/MultiPageTextWithPaddingTest.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2011 Sony Ericsson Mobile Communications AB. + * + * 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.widget.scroll.arrowscroll; + +import android.widget.scroll.arrowscroll.MultiPageTextWithPadding; +import android.test.ActivityInstrumentationTestCase; +import android.test.suitebuilder.annotation.LargeTest; +import android.test.suitebuilder.annotation.MediumTest; +import android.view.KeyEvent; +import android.widget.TextView; +import android.widget.ScrollView; + +public class MultiPageTextWithPaddingTest extends + ActivityInstrumentationTestCase<MultiPageTextWithPadding> { + + private ScrollView mScrollView; + + private TextView mTextView; + + public MultiPageTextWithPaddingTest() { + super("com.android.frameworks.coretests", MultiPageTextWithPadding.class); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + + mScrollView = getActivity().getScrollView(); + mTextView = getActivity().getContentChildAt(0); + } + + @MediumTest + public void testPreconditions() { + assertTrue("text should not fit on screen", + mTextView.getHeight() > mScrollView.getHeight()); + } + + @LargeTest + public void testScrollDownToBottom() throws Exception { + // Calculate the number of arrow scrolls needed to reach the bottom + int scrollsNeeded = (int)Math.ceil(Math.max(0.0f, + (mTextView.getHeight() - mScrollView.getHeight())) + / mScrollView.getMaxScrollAmount()); + for (int i = 0; i < scrollsNeeded; i++) { + sendKeys(KeyEvent.KEYCODE_DPAD_DOWN); + } + + assertEquals( + "should be fully scrolled to bottom", + getActivity().getLinearLayout().getHeight() + - (mScrollView.getHeight() - mScrollView.getPaddingTop() - mScrollView + .getPaddingBottom()), mScrollView.getScrollY()); + } +} diff --git a/graphics/java/android/graphics/Movie.java b/graphics/java/android/graphics/Movie.java index 95e9946..4a33453 100644 --- a/graphics/java/android/graphics/Movie.java +++ b/graphics/java/android/graphics/Movie.java @@ -46,6 +46,8 @@ public class Movie { public static native Movie decodeByteArray(byte[] data, int offset, int length); + private static native void nativeDestructor(int nativeMovie); + public static Movie decodeFile(String pathName) { InputStream is; try { @@ -57,6 +59,15 @@ public class Movie { return decodeTempStream(is); } + @Override + protected void finalize() throws Throwable { + try { + nativeDestructor(mNativeMovie); + } finally { + super.finalize(); + } + } + private static Movie decodeTempStream(InputStream is) { Movie moov = null; try { diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java index 31b7f86..da34644 100644 --- a/services/java/com/android/server/am/ActivityManagerService.java +++ b/services/java/com/android/server/am/ActivityManagerService.java @@ -7091,18 +7091,25 @@ public final class ActivityManagerService extends ActivityManagerNative * to append various headers to the dropbox log text. */ private void appendDropBoxProcessHeaders(ProcessRecord process, StringBuilder sb) { + // Watchdog thread ends up invoking this function (with + // a null ProcessRecord) to add the stack file to dropbox. + // Do not acquire a lock on this (am) in such cases, as it + // could cause a potential deadlock, if and when watchdog + // is invoked due to unavailability of lock on am and it + // would prevent watchdog from killing system_server. + if (process == null) { + sb.append("Process: system_server\n"); + return; + } // Note: ProcessRecord 'process' is guarded by the service // instance. (notably process.pkgList, which could otherwise change // concurrently during execution of this method) synchronized (this) { - if (process == null || process.pid == MY_PID) { + if (process.pid == MY_PID) { sb.append("Process: system_server\n"); } else { sb.append("Process: ").append(process.processName).append("\n"); } - if (process == null) { - return; - } int flags = process.info.flags; IPackageManager pm = AppGlobals.getPackageManager(); sb.append("Flags: 0x").append(Integer.toString(flags, 16)).append("\n"); diff --git a/services/surfaceflinger/TextureManager.cpp b/services/surfaceflinger/TextureManager.cpp index c9a15f5..9e24f90 100644 --- a/services/surfaceflinger/TextureManager.cpp +++ b/services/surfaceflinger/TextureManager.cpp @@ -186,7 +186,7 @@ status_t TextureManager::loadTexture(Texture* texture, if (texture->name == -1UL) { status_t err = initTexture(texture); LOGE_IF(err, "loadTexture failed in initTexture (%s)", strerror(err)); - return err; + if (err != NO_ERROR) return err; } if (texture->target != Texture::TEXTURE_2D) diff --git a/telephony/java/android/telephony/JapanesePhoneNumberFormatter.java b/telephony/java/android/telephony/JapanesePhoneNumberFormatter.java index 6390d8e..f5e53ef 100644 --- a/telephony/java/android/telephony/JapanesePhoneNumberFormatter.java +++ b/telephony/java/android/telephony/JapanesePhoneNumberFormatter.java @@ -24,6 +24,7 @@ import android.text.Editable; * * 022-229-1234 0223-23-1234 022-301-9876 015-482-7849 0154-91-3478 * 01547-5-4534 090-1234-1234 080-0123-6789 + * 050-0000-0000 060-0000-0000 * 0800-000-9999 0570-000-000 0276-00-0000 * * As you can see, there is no straight-forward rule here. @@ -31,7 +32,7 @@ import android.text.Editable; */ /* package */ class JapanesePhoneNumberFormatter { private static short FORMAT_MAP[] = { - -100, 10, 220, -15, 410, 530, -15, 670, 780, 1060, + -100, 10, 220, -15, 410, 530, 1200, 670, 780, 1060, -100, -25, 20, 40, 70, 100, 150, 190, 200, 210, -36, -100, -100, -35, -35, -35, 30, -100, -100, -100, -35, -35, -35, -35, -35, -35, -35, -45, -35, -35, @@ -84,7 +85,7 @@ import android.text.Editable; -35, -25, -25, -25, -25, -25, -25, -25, -25, -25, -25, -25, -25, -35, -35, -35, -25, -25, -25, 520, -100, -100, -45, -100, -45, -100, -45, -100, -45, -100, - -25, -100, -25, 540, 580, 590, 600, 610, 630, 640, + -26, -100, -25, 540, 580, 590, 600, 610, 630, 640, -25, -35, -35, -35, -25, -25, -35, -35, -35, 550, -35, -35, -25, -25, -25, -25, 560, 570, -25, -35, -35, -35, -35, -35, -25, -25, -25, -25, -25, -25, @@ -150,7 +151,8 @@ import android.text.Editable; -35, 1170, -25, -35, 1180, -35, 1190, -35, -25, -25, -100, -100, -45, -45, -100, -100, -100, -100, -100, -100, -25, -35, -35, -35, -35, -35, -35, -25, -25, -35, - -35, -35, -35, -35, -35, -35, -35, -35, -35, -45}; + -35, -35, -35, -35, -35, -35, -35, -35, -35, -45, + -26, -15, -15, -15, -15, -15, -15, -15, -15, -15}; public static void format(Editable text) { // Here, "root" means the position of "'": diff --git a/telephony/java/com/android/internal/telephony/RIL.java b/telephony/java/com/android/internal/telephony/RIL.java index c052e51..490051d 100644 --- a/telephony/java/com/android/internal/telephony/RIL.java +++ b/telephony/java/com/android/internal/telephony/RIL.java @@ -3024,7 +3024,7 @@ public final class RIL extends BaseCommands implements CommandsInterface { dataCall.active = p.readInt(); dataCall.type = p.readString(); String addresses = p.readString(); - if (TextUtils.isEmpty(addresses)) { + if (!TextUtils.isEmpty(addresses)) { dataCall.addresses = addresses.split(" "); } } else { @@ -3033,7 +3033,8 @@ public final class RIL extends BaseCommands implements CommandsInterface { dataCall.active = p.readInt(); dataCall.type = p.readString(); dataCall.ifname = p.readString(); - if (TextUtils.isEmpty(dataCall.ifname)) { + if ((dataCall.status == DataConnection.FailCause.NONE.getErrorCode()) && + TextUtils.isEmpty(dataCall.ifname)) { throw new RuntimeException("getDataCallState, no ifname"); } String addresses = p.readString(); diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java index 33d4e1f..9125037 100644 --- a/wifi/java/android/net/wifi/WifiStateMachine.java +++ b/wifi/java/android/net/wifi/WifiStateMachine.java @@ -48,6 +48,7 @@ import android.content.IntentFilter; import android.net.ConnectivityManager; import android.net.DhcpInfo; import android.net.DhcpInfoInternal; +import android.net.DhcpStateMachine; import android.net.InterfaceConfiguration; import android.net.LinkAddress; import android.net.LinkProperties; @@ -152,6 +153,7 @@ public class WifiStateMachine extends StateMachine { private NetworkInfo mNetworkInfo; private SupplicantStateTracker mSupplicantStateTracker; private WpsStateMachine mWpsStateMachine; + private DhcpStateMachine mDhcpStateMachine; private AlarmManager mAlarmManager; private PendingIntent mScanIntent; @@ -189,10 +191,10 @@ public class WifiStateMachine extends StateMachine { static final int CMD_START_DRIVER = BASE + 13; /* Start the driver */ static final int CMD_STOP_DRIVER = BASE + 14; - /* Indicates DHCP succeded */ - static final int CMD_IP_CONFIG_SUCCESS = BASE + 15; - /* Indicates DHCP failed */ - static final int CMD_IP_CONFIG_FAILURE = BASE + 16; + /* Indicates Static IP succeded */ + static final int CMD_STATIC_IP_SUCCESS = BASE + 15; + /* Indicates Static IP failed */ + static final int CMD_STATIC_IP_FAILURE = BASE + 16; /* Start the soft access point */ static final int CMD_START_AP = BASE + 21; @@ -338,8 +340,11 @@ public class WifiStateMachine extends StateMachine { */ private static final int DEFAULT_MAX_DHCP_RETRIES = 9; - private static final int POWER_MODE_ACTIVE = 1; - private static final int POWER_MODE_AUTO = 0; + static final int POWER_MODE_ACTIVE = 1; + static final int POWER_MODE_AUTO = 0; + + /* Tracks the power mode for restoration after a DHCP request/renewal goes through */ + private int mPowerMode = POWER_MODE_AUTO; /** * Default framework scan interval in milliseconds. This is used in the scenario in which @@ -1408,8 +1413,10 @@ public class WifiStateMachine extends StateMachine { */ NetworkUtils.resetConnections(mInterfaceName); - if (!NetworkUtils.stopDhcp(mInterfaceName)) { - Log.e(TAG, "Could not stop DHCP"); + if (mDhcpStateMachine != null) { + mDhcpStateMachine.sendMessage(DhcpStateMachine.CMD_STOP_DHCP); + mDhcpStateMachine.quit(); + mDhcpStateMachine = null; } /* Disable interface */ @@ -1435,6 +1442,100 @@ public class WifiStateMachine extends StateMachine { } + void handlePreDhcpSetup() { + if (!mBluetoothConnectionActive) { + /* + * There are problems setting the Wi-Fi driver's power + * mode to active when bluetooth coexistence mode is + * enabled or sense. + * <p> + * We set Wi-Fi to active mode when + * obtaining an IP address because we've found + * compatibility issues with some routers with low power + * mode. + * <p> + * In order for this active power mode to properly be set, + * we disable coexistence mode until we're done with + * obtaining an IP address. One exception is if we + * are currently connected to a headset, since disabling + * coexistence would interrupt that connection. + */ + // Disable the coexistence mode + WifiNative.setBluetoothCoexistenceModeCommand( + WifiNative.BLUETOOTH_COEXISTENCE_MODE_DISABLED); + } + + mPowerMode = WifiNative.getPowerModeCommand(); + if (mPowerMode < 0) { + // Handle the case where supplicant driver does not support + // getPowerModeCommand. + mPowerMode = WifiStateMachine.POWER_MODE_AUTO; + } + if (mPowerMode != WifiStateMachine.POWER_MODE_ACTIVE) { + WifiNative.setPowerModeCommand(WifiStateMachine.POWER_MODE_ACTIVE); + } + } + + + void handlePostDhcpSetup() { + /* restore power mode */ + WifiNative.setPowerModeCommand(mPowerMode); + + // Set the coexistence mode back to its default value + WifiNative.setBluetoothCoexistenceModeCommand( + WifiNative.BLUETOOTH_COEXISTENCE_MODE_SENSE); + } + + private void handleSuccessfulIpConfiguration(DhcpInfoInternal dhcpInfoInternal) { + synchronized (mDhcpInfoInternal) { + mDhcpInfoInternal = dhcpInfoInternal; + } + mLastSignalLevel = -1; // force update of signal strength + WifiConfigStore.setIpConfiguration(mLastNetworkId, dhcpInfoInternal); + InetAddress addr = NetworkUtils.numericToInetAddress(dhcpInfoInternal.ipAddress); + mWifiInfo.setInetAddress(addr); + if (getNetworkDetailedState() == DetailedState.CONNECTED) { + //DHCP renewal in connected state + LinkProperties linkProperties = dhcpInfoInternal.makeLinkProperties(); + linkProperties.setHttpProxy(WifiConfigStore.getProxyProperties(mLastNetworkId)); + linkProperties.setInterfaceName(mInterfaceName); + if (!linkProperties.equals(mLinkProperties)) { + Log.d(TAG, "Link configuration changed for netId: " + mLastNetworkId + + " old: " + mLinkProperties + "new: " + linkProperties); + NetworkUtils.resetConnections(mInterfaceName); + mLinkProperties = linkProperties; + sendLinkConfigurationChangedBroadcast(); + } + } else { + configureLinkProperties(); + setNetworkDetailedState(DetailedState.CONNECTED); + sendNetworkStateChangeBroadcast(mLastBssid); + } + } + + private void handleFailedIpConfiguration() { + Log.e(TAG, "IP configuration failed"); + + mWifiInfo.setInetAddress(null); + /** + * If we've exceeded the maximum number of retries for DHCP + * to a given network, disable the network + */ + if (++mReconnectCount > getMaxDhcpRetries()) { + Log.e(TAG, "Failed " + + mReconnectCount + " times, Disabling " + mLastNetworkId); + WifiConfigStore.disableNetwork(mLastNetworkId); + mReconnectCount = 0; + } + + /* DHCP times out after about 30 seconds, we do a + * disconnect and an immediate reconnect to try again + */ + WifiNative.disconnectCommand(); + WifiNative.reconnectCommand(); + + } + /********************************************************* * Notifications from WifiMonitor @@ -1606,6 +1707,8 @@ public class WifiStateMachine extends StateMachine { case CMD_FORGET_NETWORK: case CMD_RSSI_POLL: case CMD_ENABLE_ALL_NETWORKS: + case DhcpStateMachine.CMD_PRE_DHCP_ACTION: + case DhcpStateMachine.CMD_POST_DHCP_ACTION: break; case CMD_START_WPS: /* Return failure when the state machine cannot handle WPS initiation*/ @@ -2483,74 +2586,18 @@ public class WifiStateMachine extends StateMachine { } class ConnectingState extends State { - boolean mModifiedBluetoothCoexistenceMode; - int mPowerMode; - boolean mUseStaticIp; - Thread mDhcpThread; @Override public void enter() { if (DBG) Log.d(TAG, getName() + "\n"); EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName()); - mUseStaticIp = WifiConfigStore.isUsingStaticIp(mLastNetworkId); - if (!mUseStaticIp) { - mDhcpThread = null; - mModifiedBluetoothCoexistenceMode = false; - mPowerMode = POWER_MODE_AUTO; - - if (!mBluetoothConnectionActive) { - /* - * There are problems setting the Wi-Fi driver's power - * mode to active when bluetooth coexistence mode is - * enabled or sense. - * <p> - * We set Wi-Fi to active mode when - * obtaining an IP address because we've found - * compatibility issues with some routers with low power - * mode. - * <p> - * In order for this active power mode to properly be set, - * we disable coexistence mode until we're done with - * obtaining an IP address. One exception is if we - * are currently connected to a headset, since disabling - * coexistence would interrupt that connection. - */ - mModifiedBluetoothCoexistenceMode = true; - - // Disable the coexistence mode - WifiNative.setBluetoothCoexistenceModeCommand( - WifiNative.BLUETOOTH_COEXISTENCE_MODE_DISABLED); - } - - mPowerMode = WifiNative.getPowerModeCommand(); - if (mPowerMode < 0) { - // Handle the case where supplicant driver does not support - // getPowerModeCommand. - mPowerMode = POWER_MODE_AUTO; - } - if (mPowerMode != POWER_MODE_ACTIVE) { - WifiNative.setPowerModeCommand(POWER_MODE_ACTIVE); - } - Log.d(TAG, "DHCP request started"); - mDhcpThread = new Thread(new Runnable() { - public void run() { - DhcpInfoInternal dhcpInfoInternal = new DhcpInfoInternal(); - if (NetworkUtils.runDhcp(mInterfaceName, dhcpInfoInternal)) { - Log.d(TAG, "DHCP request succeeded"); - synchronized (mDhcpInfoInternal) { - mDhcpInfoInternal = dhcpInfoInternal; - } - WifiConfigStore.setIpConfiguration(mLastNetworkId, dhcpInfoInternal); - sendMessage(CMD_IP_CONFIG_SUCCESS); - } else { - Log.d(TAG, "DHCP request failed: " + - NetworkUtils.getDhcpError()); - sendMessage(CMD_IP_CONFIG_FAILURE); - } - } - }); - mDhcpThread.start(); + if (!WifiConfigStore.isUsingStaticIp(mLastNetworkId)) { + //start DHCP + mDhcpStateMachine = DhcpStateMachine.makeDhcpStateMachine( + mContext, WifiStateMachine.this, mInterfaceName); + mDhcpStateMachine.registerForPreDhcpNotification(); + mDhcpStateMachine.sendMessage(DhcpStateMachine.CMD_START_DHCP); } else { DhcpInfoInternal dhcpInfoInternal = WifiConfigStore.getIpConfiguration( mLastNetworkId); @@ -2562,16 +2609,13 @@ public class WifiStateMachine extends StateMachine { try { netd.setInterfaceConfig(mInterfaceName, ifcg); Log.v(TAG, "Static IP configuration succeeded"); - synchronized (mDhcpInfoInternal) { - mDhcpInfoInternal = dhcpInfoInternal; - } - sendMessage(CMD_IP_CONFIG_SUCCESS); + sendMessage(CMD_STATIC_IP_SUCCESS, dhcpInfoInternal); } catch (RemoteException re) { Log.v(TAG, "Static IP configuration failed: " + re); - sendMessage(CMD_IP_CONFIG_FAILURE); + sendMessage(CMD_STATIC_IP_FAILURE); } catch (IllegalStateException e) { Log.v(TAG, "Static IP configuration failed: " + e); - sendMessage(CMD_IP_CONFIG_FAILURE); + sendMessage(CMD_STATIC_IP_FAILURE); } } } @@ -2580,44 +2624,26 @@ public class WifiStateMachine extends StateMachine { if (DBG) Log.d(TAG, getName() + message.toString() + "\n"); switch(message.what) { - case CMD_IP_CONFIG_SUCCESS: - mLastSignalLevel = -1; // force update of signal strength - InetAddress addr; - synchronized (mDhcpInfoInternal) { - addr = NetworkUtils.numericToInetAddress(mDhcpInfoInternal.ipAddress); - } - mWifiInfo.setInetAddress(addr); - configureLinkProperties(); - if (getNetworkDetailedState() == DetailedState.CONNECTED) { - sendLinkConfigurationChangedBroadcast(); - } else { - setNetworkDetailedState(DetailedState.CONNECTED); - sendNetworkStateChangeBroadcast(mLastBssid); + case DhcpStateMachine.CMD_PRE_DHCP_ACTION: + handlePreDhcpSetup(); + mDhcpStateMachine.sendMessage(DhcpStateMachine.CMD_PRE_DHCP_ACTION_COMPLETE); + break; + case DhcpStateMachine.CMD_POST_DHCP_ACTION: + handlePostDhcpSetup(); + if (message.arg1 == DhcpStateMachine.DHCP_SUCCESS) { + handleSuccessfulIpConfiguration((DhcpInfoInternal) message.obj); + transitionTo(mConnectedState); + } else if (message.arg1 == DhcpStateMachine.DHCP_FAILURE) { + handleFailedIpConfiguration(); + transitionTo(mDisconnectingState); } - //TODO: The framework is not detecting a DHCP renewal and a possible - //IP change. we should detect this and send out a config change broadcast + break; + case CMD_STATIC_IP_SUCCESS: + handleSuccessfulIpConfiguration((DhcpInfoInternal) message.obj); transitionTo(mConnectedState); break; - case CMD_IP_CONFIG_FAILURE: - mWifiInfo.setInetAddress(null); - - Log.e(TAG, "IP configuration failed"); - /** - * If we've exceeded the maximum number of retries for DHCP - * to a given network, disable the network - */ - if (++mReconnectCount > getMaxDhcpRetries()) { - Log.e(TAG, "Failed " + - mReconnectCount + " times, Disabling " + mLastNetworkId); - WifiConfigStore.disableNetwork(mLastNetworkId); - mReconnectCount = 0; - } - - /* DHCP times out after about 30 seconds, we do a - * disconnect and an immediate reconnect to try again - */ - WifiNative.disconnectCommand(); - WifiNative.reconnectCommand(); + case CMD_STATIC_IP_FAILURE: + handleFailedIpConfiguration(); transitionTo(mDisconnectingState); break; case CMD_DISCONNECT: @@ -2661,23 +2687,6 @@ public class WifiStateMachine extends StateMachine { EventLog.writeEvent(EVENTLOG_WIFI_EVENT_HANDLED, message.what); return HANDLED; } - - @Override - public void exit() { - /* reset power state & bluetooth coexistence if on DHCP */ - if (!mUseStaticIp) { - if (mPowerMode != POWER_MODE_ACTIVE) { - WifiNative.setPowerModeCommand(mPowerMode); - } - - if (mModifiedBluetoothCoexistenceMode) { - // Set the coexistence mode back to its default value - WifiNative.setBluetoothCoexistenceModeCommand( - WifiNative.BLUETOOTH_COEXISTENCE_MODE_SENSE); - } - } - - } } class ConnectedState extends State { @@ -2695,6 +2704,19 @@ public class WifiStateMachine extends StateMachine { if (DBG) Log.d(TAG, getName() + message.toString() + "\n"); boolean eventLoggingEnabled = true; switch (message.what) { + case DhcpStateMachine.CMD_PRE_DHCP_ACTION: + handlePreDhcpSetup(); + mDhcpStateMachine.sendMessage(DhcpStateMachine.CMD_PRE_DHCP_ACTION_COMPLETE); + break; + case DhcpStateMachine.CMD_POST_DHCP_ACTION: + handlePostDhcpSetup(); + if (message.arg1 == DhcpStateMachine.DHCP_SUCCESS) { + handleSuccessfulIpConfiguration((DhcpInfoInternal) message.obj); + } else if (message.arg1 == DhcpStateMachine.DHCP_FAILURE) { + handleFailedIpConfiguration(); + transitionTo(mDisconnectingState); + } + break; case CMD_DISCONNECT: WifiNative.disconnectCommand(); transitionTo(mDisconnectingState); |