diff options
-rw-r--r-- | src/com/android/launcher3/InstallShortcutReceiver.java | 27 | ||||
-rw-r--r-- | src/com/android/launcher3/Launcher.java | 47 | ||||
-rw-r--r-- | src/com/android/launcher3/LauncherModel.java | 9 |
3 files changed, 28 insertions, 55 deletions
diff --git a/src/com/android/launcher3/InstallShortcutReceiver.java b/src/com/android/launcher3/InstallShortcutReceiver.java index 28cef1346..2edde4fae 100644 --- a/src/com/android/launcher3/InstallShortcutReceiver.java +++ b/src/com/android/launcher3/InstallShortcutReceiver.java @@ -17,6 +17,7 @@ package com.android.launcher3; import android.content.BroadcastReceiver; +import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; @@ -29,6 +30,8 @@ import android.util.Base64; import android.util.Log; import android.widget.Toast; +import com.android.launcher3.compat.UserHandleCompat; + import org.json.JSONObject; import org.json.JSONStringer; import org.json.JSONTokener; @@ -280,19 +283,27 @@ public class InstallShortcutReceiver extends BroadcastReceiver { final boolean exists = LauncherModel.shortcutExists(context, name, intent); //final boolean allowDuplicate = data.getBooleanExtra(Launcher.EXTRA_SHORTCUT_DUPLICATE, true); - // TODO-XXX: Disable duplicates for now - if (!exists /* && allowDuplicate */) { + // If the intent specifies a package, make sure the package exists + String packageName = intent.getPackage(); + if (packageName == null) { + packageName = intent.getComponent() == null ? null : + intent.getComponent().getPackageName(); + } + if (packageName != null && !packageName.isEmpty()) { + UserHandleCompat myUserHandle = UserHandleCompat.myUserHandle(); + if (!LauncherModel.isValidPackage(context, packageName, myUserHandle)) { + if (DBG) Log.d(TAG, "Ignoring shortcut for absent package:" + intent); + continue; + } + } + + if (!exists) { // Generate a shortcut info to add into the model ShortcutInfo info = getShortcutInfo(context, pendingInfo.data, pendingInfo.launchIntent); addShortcuts.add(info); } - /* - else if (exists && !allowDuplicate) { - result = INSTALL_SHORTCUT_IS_DUPLICATE; - duplicateName = name; - } - */ + } // Notify the user once if we weren't able to place any duplicates diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index b02c3c69a..0bd3f210d 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -24,7 +24,6 @@ import android.animation.ObjectAnimator; import android.animation.PropertyValuesHolder; import android.animation.ValueAnimator; import android.animation.ValueAnimator.AnimatorUpdateListener; -import android.annotation.TargetApi; import android.app.Activity; import android.app.ActivityManager; import android.app.ActivityOptions; @@ -80,7 +79,6 @@ import android.view.Menu; import android.view.MotionEvent; import android.view.Surface; import android.view.View; -import android.view.Window; import android.view.View.OnClickListener; import android.view.View.OnLongClickListener; import android.view.ViewGroup; @@ -110,9 +108,6 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintWriter; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.text.DateFormat; import java.util.ArrayList; import java.util.Collection; @@ -1630,52 +1625,10 @@ public class Launcher extends Activity } registerReceiver(mReceiver, filter); FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView()); - setupTransparentSystemBarsForLmp(); mAttached = true; mVisible = true; } - /** - * Sets up transparent navigation and status bars in LMP. - * This method is a no-op for other platform versions. - */ - @TargetApi(19) - private void setupTransparentSystemBarsForLmp() { - // TODO(sansid): use the APIs directly when compiling against L sdk. - // Currently we use reflection to access the flags and the API to set the transparency - // on the System bars. - if (Utilities.isLmp()) { - try { - getWindow().getAttributes().systemUiVisibility |= - (View.SYSTEM_UI_FLAG_LAYOUT_STABLE - | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN - | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); - getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS - | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); - Field drawsSysBackgroundsField = WindowManager.LayoutParams.class.getField( - "FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS"); - getWindow().addFlags(drawsSysBackgroundsField.getInt(null)); - - Method setStatusBarColorMethod = - Window.class.getDeclaredMethod("setStatusBarColor", int.class); - Method setNavigationBarColorMethod = - Window.class.getDeclaredMethod("setNavigationBarColor", int.class); - setStatusBarColorMethod.invoke(getWindow(), Color.TRANSPARENT); - setNavigationBarColorMethod.invoke(getWindow(), Color.TRANSPARENT); - } catch (NoSuchFieldException e) { - Log.w(TAG, "NoSuchFieldException while setting up transparent bars"); - } catch (NoSuchMethodException ex) { - Log.w(TAG, "NoSuchMethodException while setting up transparent bars"); - } catch (IllegalAccessException e) { - Log.w(TAG, "IllegalAccessException while setting up transparent bars"); - } catch (IllegalArgumentException e) { - Log.w(TAG, "IllegalArgumentException while setting up transparent bars"); - } catch (InvocationTargetException e) { - Log.w(TAG, "InvocationTargetException while setting up transparent bars"); - } finally {} - } - } - @Override public void onDetachedFromWindow() { super.onDetachedFromWindow(); diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java index cc87281fc..141368c20 100644 --- a/src/com/android/launcher3/LauncherModel.java +++ b/src/com/android/launcher3/LauncherModel.java @@ -2934,6 +2934,15 @@ public class LauncherModel extends BroadcastReceiver return launcherApps.isActivityEnabledForProfile(cn, user); } + public static boolean isValidPackage(Context context, String packageName, + UserHandleCompat user) { + if (packageName == null) { + return false; + } + final LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(context); + return launcherApps.isPackageEnabledForProfile(packageName, user); + } + /** * Make an ShortcutInfo object for a restored application or shortcut item that points * to a package that is not yet installed on the system. |