am 2d93a116: Merge change 23187 into eclair
Merge commit '2d93a11663d1d872bc7e9d6512a445fa84148583' into eclair-plus-aosp * commit '2d93a11663d1d872bc7e9d6512a445fa84148583': Do not send dock state changed broadcasts until the system has finished booting.
This commit is contained in:
@@ -36,17 +36,15 @@ class DockObserver extends UEventObserver {
|
|||||||
private static final String DOCK_UEVENT_MATCH = "DEVPATH=/devices/virtual/switch/dock";
|
private static final String DOCK_UEVENT_MATCH = "DEVPATH=/devices/virtual/switch/dock";
|
||||||
private static final String DOCK_STATE_PATH = "/sys/class/switch/dock/state";
|
private static final String DOCK_STATE_PATH = "/sys/class/switch/dock/state";
|
||||||
|
|
||||||
private int mDockState;
|
private int mDockState = Intent.EXTRA_DOCK_STATE_UNDOCKED;
|
||||||
private boolean mPendingIntent;
|
private boolean mSystemReady;
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
|
|
||||||
public DockObserver(Context context) {
|
public DockObserver(Context context) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
|
|
||||||
startObserving(DOCK_UEVENT_MATCH);
|
|
||||||
|
|
||||||
init(); // set initial status
|
init(); // set initial status
|
||||||
|
startObserving(DOCK_UEVENT_MATCH);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -55,55 +53,59 @@ class DockObserver extends UEventObserver {
|
|||||||
Log.v(TAG, "Dock UEVENT: " + event.toString());
|
Log.v(TAG, "Dock UEVENT: " + event.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
synchronized (this) {
|
||||||
update(Integer.parseInt(event.get("SWITCH_STATE")));
|
try {
|
||||||
} catch (NumberFormatException e) {
|
int newState = Integer.parseInt(event.get("SWITCH_STATE"));
|
||||||
Log.e(TAG, "Could not parse switch state from event " + event);
|
if (newState != mDockState) {
|
||||||
|
mDockState = newState;
|
||||||
|
if (mSystemReady) {
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
Log.e(TAG, "Could not parse switch state from event " + event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized final void init() {
|
private final void init() {
|
||||||
char[] buffer = new char[1024];
|
char[] buffer = new char[1024];
|
||||||
|
|
||||||
int newState = mDockState;
|
|
||||||
try {
|
try {
|
||||||
FileReader file = new FileReader(DOCK_STATE_PATH);
|
FileReader file = new FileReader(DOCK_STATE_PATH);
|
||||||
int len = file.read(buffer, 0, 1024);
|
int len = file.read(buffer, 0, 1024);
|
||||||
newState = Integer.valueOf((new String(buffer, 0, len)).trim());
|
mDockState = Integer.valueOf((new String(buffer, 0, len)).trim());
|
||||||
|
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
Log.w(TAG, "This kernel does not have dock station support");
|
Log.w(TAG, "This kernel does not have dock station support");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(TAG, "" , e);
|
Log.e(TAG, "" , e);
|
||||||
}
|
}
|
||||||
|
|
||||||
update(newState);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized final void update(int newState) {
|
void systemReady() {
|
||||||
if (newState != mDockState) {
|
synchronized (this) {
|
||||||
mDockState = newState;
|
// don't bother broadcasting undocked here
|
||||||
|
if (mDockState != Intent.EXTRA_DOCK_STATE_UNDOCKED) {
|
||||||
mPendingIntent = true;
|
update();
|
||||||
mHandler.sendEmptyMessage(0);
|
}
|
||||||
|
mSystemReady = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized final void sendIntent() {
|
private final void update() {
|
||||||
Log.d(TAG, "Broadcasting dock state " + mDockState);
|
mHandler.sendEmptyMessage(0);
|
||||||
|
|
||||||
// Pack up the values and broadcast them to everyone
|
|
||||||
Intent intent = new Intent(Intent.ACTION_DOCK_EVENT);
|
|
||||||
intent.putExtra(Intent.EXTRA_DOCK_STATE, mDockState);
|
|
||||||
mContext.sendStickyBroadcast(intent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Handler mHandler = new Handler() {
|
private final Handler mHandler = new Handler() {
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message msg) {
|
public void handleMessage(Message msg) {
|
||||||
if (mPendingIntent) {
|
synchronized (this) {
|
||||||
sendIntent();
|
Log.d(TAG, "Broadcasting dock state " + mDockState);
|
||||||
mPendingIntent = false;
|
// Pack up the values and broadcast them to everyone
|
||||||
|
Intent intent = new Intent(Intent.ACTION_DOCK_EVENT);
|
||||||
|
intent.putExtra(Intent.EXTRA_DOCK_STATE, mDockState);
|
||||||
|
mContext.sendStickyBroadcast(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -392,6 +392,7 @@ class ServerThread extends Thread {
|
|||||||
if (wallpaper != null) wallpaper.systemReady();
|
if (wallpaper != null) wallpaper.systemReady();
|
||||||
if (battery != null) battery.systemReady();
|
if (battery != null) battery.systemReady();
|
||||||
if (connectivity != null) connectivity.systemReady();
|
if (connectivity != null) connectivity.systemReady();
|
||||||
|
if (dock != null) dock.systemReady();
|
||||||
Watchdog.getInstance().start();
|
Watchdog.getInstance().start();
|
||||||
|
|
||||||
Looper.loop();
|
Looper.loop();
|
||||||
|
|||||||
Reference in New Issue
Block a user