Fixing some invalid checks and cleaning some redundant conditions

Change-Id: I770ce2cc2eccbee105958634e81bbc9bc2e4cc48
This commit is contained in:
Sunny Goyal
2015-12-17 23:22:42 -08:00
parent d896ee43cd
commit b740f59c7d
8 changed files with 25 additions and 36 deletions

View File

@@ -348,8 +348,7 @@ public class DragController {
if (rawDragInfo instanceof ShortcutInfo) {
ShortcutInfo dragInfo = (ShortcutInfo) rawDragInfo;
for (ComponentName componentName : cns) {
// Added null checks to prevent NPE we've seen in the wild
if (dragInfo != null && dragInfo.intent != null) {
if (dragInfo.intent != null) {
ComponentName cn = dragInfo.intent.getComponent();
boolean isSameComponent = cn != null && (cn.equals(componentName) ||
packageNames.contains(cn.getPackageName()));

View File

@@ -547,10 +547,7 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
public void onAnimationEnd(Animator animation) {
mState = STATE_OPEN;
if (onCompleteRunnable != null) {
onCompleteRunnable.run();
}
onCompleteRunnable.run();
mContent.setFocusOnFirstChild();
}
});
@@ -1369,10 +1366,12 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
}
public void onFocusChange(View v, boolean hasFocus) {
if (v == mFolderName && hasFocus) {
startEditingFolderName();
} else if (v == mFolderName && !hasFocus) {
dismissEditingName();
if (v == mFolderName) {
if (hasFocus) {
startEditingFolderName();
} else {
dismissEditingName();
}
}
}

View File

@@ -211,14 +211,14 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
ArrayList<ItemInfo> addShortcuts = new ArrayList<ItemInfo>();
while (iter.hasNext()) {
final PendingInstallShortcutInfo pendingInfo = iter.next();
final Intent intent = pendingInfo.launchIntent;
// If the intent specifies a package, make sure the package exists
String packageName = pendingInfo.getTargetPackage();
if (!TextUtils.isEmpty(packageName)) {
UserHandleCompat myUserHandle = UserHandleCompat.myUserHandle();
if (!LauncherModel.isValidPackage(context, packageName, myUserHandle)) {
if (DBG) Log.d(TAG, "Ignoring shortcut for absent package:" + intent);
if (DBG) Log.d(TAG, "Ignoring shortcut for absent package: "
+ pendingInfo.launchIntent);
continue;
}
}
@@ -363,7 +363,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
return packageName;
}
public boolean isLuncherActivity() {
public boolean isLauncherActivity() {
return activityInfo != null;
}
}
@@ -406,9 +406,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
}
return new PendingInstallShortcutInfo(data, context);
} catch (JSONException e) {
Log.d(TAG, "Exception reading shortcut to add: " + e);
} catch (URISyntaxException e) {
} catch (JSONException | URISyntaxException e) {
Log.d(TAG, "Exception reading shortcut to add: " + e);
}
return null;
@@ -421,7 +419,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
*/
private static PendingInstallShortcutInfo convertToLauncherActivityIfPossible(
PendingInstallShortcutInfo original) {
if (original.isLuncherActivity()) {
if (original.isLauncherActivity()) {
// Already an activity target
return original;
}

View File

@@ -4052,8 +4052,7 @@ public class Launcher extends Activity
pendingInfo.spanY = item.spanY;
pendingInfo.minSpanX = item.minSpanX;
pendingInfo.minSpanY = item.minSpanY;
Bundle options = null;
WidgetHostViewLoader.getDefaultOptionsForWidget(this, pendingInfo);
Bundle options = WidgetHostViewLoader.getDefaultOptionsForWidget(this, pendingInfo);
int newWidgetId = mAppWidgetHost.allocateAppWidgetId();
boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(

View File

@@ -768,13 +768,10 @@ public class LauncherBackupHelper implements BackupHelper {
try {
Key key = Key.parseFrom(Base64.decode(backupKey, Base64.DEFAULT));
if (key.checksum != checkKey(key)) {
key = null;
throw new InvalidBackupException("invalid key read from stream" + backupKey);
}
return key;
} catch (InvalidProtocolBufferNanoException e) {
throw new InvalidBackupException(e);
} catch (IllegalArgumentException e) {
} catch (InvalidProtocolBufferNanoException | IllegalArgumentException e) {
throw new InvalidBackupException(e);
}
}
@@ -1137,9 +1134,8 @@ public class LauncherBackupHelper implements BackupHelper {
* @param journal a Journal protocol buffer
*/
private void writeJournal(ParcelFileDescriptor newState, Journal journal) {
FileOutputStream outStream = null;
try {
outStream = new FileOutputStream(newState.getFileDescriptor());
FileOutputStream outStream = new FileOutputStream(newState.getFileDescriptor());
final byte[] journalBytes = writeCheckedBytes(journal);
outStream.write(journalBytes);
outStream.close();

View File

@@ -3553,7 +3553,7 @@ public class LauncherModel extends BroadcastReceiver
ComponentName componentName = intent.getComponent();
if (componentName == null) {
Log.d(TAG, "Missing component found in getShortcutInfo: " + componentName);
Log.d(TAG, "Missing component found in getShortcutInfo");
return null;
}

View File

@@ -2496,7 +2496,7 @@ public class Workspace extends PagedView
boolean willCreateUserFolder(ItemInfo info, View dropOverView, boolean considerTimeout) {
if (dropOverView != null) {
CellLayout.LayoutParams lp = (CellLayout.LayoutParams) dropOverView.getLayoutParams();
if (lp.useTmpCoords && (lp.tmpCellX != lp.cellX || lp.tmpCellY != lp.tmpCellY)) {
if (lp.useTmpCoords && (lp.tmpCellX != lp.cellX || lp.tmpCellY != lp.cellY)) {
return false;
}
}
@@ -2528,7 +2528,7 @@ public class Workspace extends PagedView
boolean willAddToExistingUserFolder(Object dragInfo, View dropOverView) {
if (dropOverView != null) {
CellLayout.LayoutParams lp = (CellLayout.LayoutParams) dropOverView.getLayoutParams();
if (lp.useTmpCoords && (lp.tmpCellX != lp.cellX || lp.tmpCellY != lp.tmpCellY)) {
if (lp.useTmpCoords && (lp.tmpCellX != lp.cellX || lp.tmpCellY != lp.cellY)) {
return false;
}
}
@@ -2557,7 +2557,7 @@ public class Workspace extends PagedView
if (v == null || hasntMoved || !mCreateUserFolderOnDrop) return false;
mCreateUserFolderOnDrop = false;
final long screenId = (targetCell == null) ? mDragInfo.screenId : getIdForScreen(target);
final long screenId = getIdForScreen(target);
boolean aboveShortcut = (v.getTag() instanceof ShortcutInfo);
boolean willBecomeShortcut = (newView.getTag() instanceof ShortcutInfo);
@@ -3514,11 +3514,11 @@ public class Workspace extends PagedView
boolean isWidget = pendingInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET
|| pendingInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET;
View finalView = isWidget ? ((PendingAddWidgetInfo) pendingInfo).boundWidget : null;
AppWidgetHostView finalView = isWidget ?
((PendingAddWidgetInfo) pendingInfo).boundWidget : null;
if (finalView instanceof AppWidgetHostView && updateWidgetSize) {
AppWidgetHostView awhv = (AppWidgetHostView) finalView;
AppWidgetResizeFrame.updateWidgetSizeRanges(awhv, mLauncher, item.spanX,
if (finalView != null && updateWidgetSize) {
AppWidgetResizeFrame.updateWidgetSizeRanges(finalView, mLauncher, item.spanX,
item.spanY);
}

View File

@@ -90,9 +90,7 @@ class AppWidgetManagerCompatVL extends AppWidgetManagerCompat {
AppWidgetHost host, int requestCode) {
try {
host.startAppWidgetConfigureActivityForResult(activity, widgetId, 0, requestCode, null);
} catch (ActivityNotFoundException e) {
Toast.makeText(activity, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
} catch (SecurityException e) {
} catch (ActivityNotFoundException | SecurityException e) {
Toast.makeText(activity, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
}
}