From f229e4d3eb8f910c181f96416c6798f6f305a395 Mon Sep 17 00:00:00 2001 From: Jim Miller Date: Wed, 12 Sep 2012 20:32:50 -0700 Subject: [PATCH] Add support for settings for lock widgets Change-Id: Iade094c6f32a7653bdbbd4921d345d68f2443ff4 --- .../java/android/appwidget/AppWidgetHost.java | 54 +++++++++++++++++-- .../android/appwidget/AppWidgetManager.java | 12 ++++- core/java/android/provider/Settings.java | 14 +++++ .../internal/widget/LockPatternUtils.java | 11 ++++ .../impl/keyguard/KeyguardHostView.java | 26 ++++----- .../android/server/AppWidgetServiceImpl.java | 12 ++++- 6 files changed, 108 insertions(+), 21 deletions(-) diff --git a/core/java/android/appwidget/AppWidgetHost.java b/core/java/android/appwidget/AppWidgetHost.java index c76bf91fcae72..51a81c5caf41b 100644 --- a/core/java/android/appwidget/AppWidgetHost.java +++ b/core/java/android/appwidget/AppWidgetHost.java @@ -24,8 +24,10 @@ import android.os.Handler; import android.os.IBinder; import android.os.Looper; import android.os.Message; +import android.os.Process; import android.os.RemoteException; import android.os.ServiceManager; +import android.os.UserHandle; import android.util.DisplayMetrics; import android.util.TypedValue; import android.widget.RemoteViews; @@ -115,18 +117,22 @@ public class AppWidgetHost { private OnClickHandler mOnClickHandler; public AppWidgetHost(Context context, int hostId) { - this(context, hostId, null); + this(context, hostId, null, Looper.getMainLooper()); } /** * @hide */ - public AppWidgetHost(Context context, int hostId, OnClickHandler handler) { + public AppWidgetHost(Context context, int hostId, OnClickHandler handler, Looper looper) { mContext = context; mHostId = hostId; mOnClickHandler = handler; - mHandler = new UpdateHandler(context.getMainLooper()); + mHandler = new UpdateHandler(looper); mDisplayMetrics = context.getResources().getDisplayMetrics(); + bindService(); + } + + private static void bindService() { synchronized (sServiceLock) { if (sService == null) { IBinder b = ServiceManager.getService(Context.APPWIDGET_SERVICE); @@ -189,6 +195,32 @@ public class AppWidgetHost { } } + /** + * Get a appWidgetId for a host in the calling process. + * + * @return a appWidgetId + * @hide + */ + public static int allocateAppWidgetIdForHost(String packageName, int hostId) { + checkCallerIsSystem(); + try { + if (sService == null) { + bindService(); + } + return sService.allocateAppWidgetId(packageName, hostId); + } catch (RemoteException e) { + throw new RuntimeException("system server dead?", e); + } + } + + private static void checkCallerIsSystem() { + int uid = Process.myUid(); + if (UserHandle.getAppId(uid) == Process.SYSTEM_UID || uid == 0) { + return; + } + throw new SecurityException("Disallowed call for uid " + uid); + } + /** * Stop listening to changes for this AppWidget. */ @@ -204,6 +236,22 @@ public class AppWidgetHost { } } + /** + * Stop listening to changes for this AppWidget. + * @hide + */ + public static void deleteAppWidgetIdForHost(int appWidgetId) { + checkCallerIsSystem(); + try { + if (sService == null) { + bindService(); + } + sService.deleteAppWidgetId(appWidgetId); + } catch (RemoteException e) { + throw new RuntimeException("system server dead?", e); + } + } + /** * Remove all records about this host from the AppWidget manager. *