Always initialize local boolean variables when possible

It's currently possible to reference deviceModeChanged in InputReader
while it's in an unknown state. Change the style of initialization
here and a few other places to better prevent this type of error.

(cherry-pick of f583d0dcc6e5c1968c472c844f6c8fbbe036ad78.)

Bug: 11433748
Change-Id: Ic450ca4afe50987b022db9d20bb1cb18ccf060cc
This commit is contained in:
Michael Wright
2013-10-29 13:24:41 -07:00
committed by Elliott Hughes
parent 69920427ea
commit 91c4cd51b4

View File

@@ -2133,12 +2133,11 @@ void KeyboardInputMapper::processKey(nsecs_t when, bool down, int32_t keyCode,
}
}
bool metaStateChanged = false;
int32_t oldMetaState = mMetaState;
int32_t newMetaState = updateMetaState(keyCode, down, oldMetaState);
if (oldMetaState != newMetaState) {
bool metaStateChanged = oldMetaState != newMetaState;
if (metaStateChanged) {
mMetaState = newMetaState;
metaStateChanged = true;
updateLedState(false);
}
@@ -2926,7 +2925,6 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) {
int32_t rawHeight = mRawPointerAxes.y.maxValue - mRawPointerAxes.y.minValue + 1;
// Get associated display dimensions.
bool viewportChanged = false;
DisplayViewport newViewport;
if (mParameters.hasAssociatedDisplay) {
if (!mConfig.getDisplayInfo(mParameters.associatedDisplayIsExternal, &newViewport)) {
@@ -2940,9 +2938,9 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) {
} else {
newViewport.setNonDisplayViewport(rawWidth, rawHeight);
}
if (mViewport != newViewport) {
bool viewportChanged = mViewport != newViewport;
if (viewportChanged) {
mViewport = newViewport;
viewportChanged = true;
if (mDeviceMode == DEVICE_MODE_DIRECT || mDeviceMode == DEVICE_MODE_POINTER) {
// Convert rotated viewport to natural surface coordinates.
@@ -3011,9 +3009,8 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) {
}
// If moving between pointer modes, need to reset some state.
bool deviceModeChanged;
if (mDeviceMode != oldDeviceMode) {
deviceModeChanged = true;
bool deviceModeChanged = mDeviceMode != oldDeviceMode;
if (deviceModeChanged) {
mOrientedRanges.clear();
}