OSDN Git Service

Fixing some invalid checks and cleaning some redundant conditions
authorSunny Goyal <sunnygoyal@google.com>
Fri, 18 Dec 2015 07:22:42 +0000 (23:22 -0800)
committerSunny Goyal <sunnygoyal@google.com>
Fri, 18 Dec 2015 19:00:14 +0000 (11:00 -0800)
Change-Id: I770ce2cc2eccbee105958634e81bbc9bc2e4cc48

src/com/android/launcher3/DragController.java
src/com/android/launcher3/Folder.java
src/com/android/launcher3/InstallShortcutReceiver.java
src/com/android/launcher3/Launcher.java
src/com/android/launcher3/LauncherBackupHelper.java
src/com/android/launcher3/LauncherModel.java
src/com/android/launcher3/Workspace.java
src/com/android/launcher3/compat/AppWidgetManagerCompatVL.java

index 204dddf..eefb287 100644 (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()));
index da895c6..c5639c4 100644 (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();
+            }
         }
     }
 
index 7f15160..175bad1 100644 (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;
         }
index 0323e23..d676088 100644 (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(
index 2d11d3a..509fbf8 100644 (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();
index a0e287a..a34e001 100644 (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;
         }
 
index a0ecafb..56801ff 100644 (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);
             }
 
index 13712d8..b3c5cc2 100644 (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();
         }
     }