Loading core/java/android/appwidget/AppWidgetHost.java +43 −11 Original line number Diff line number Diff line Loading @@ -16,15 +16,13 @@ package android.appwidget; import java.lang.ref.WeakReference; import java.util.List; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.Activity; import android.content.ActivityNotFoundException; import android.content.Context; import android.content.IntentSender; import android.content.pm.PackageManager; import android.os.Binder; import android.os.Bundle; import android.os.Handler; Loading @@ -42,6 +40,9 @@ import android.widget.RemoteViews.OnClickHandler; import com.android.internal.appwidget.IAppWidgetHost; import com.android.internal.appwidget.IAppWidgetService; import java.lang.ref.WeakReference; import java.util.List; /** * AppWidgetHost provides the interaction with the AppWidget service for apps, * like the home screen, that want to embed AppWidgets in their UI. Loading @@ -55,6 +56,7 @@ public class AppWidgetHost { final static Object sServiceLock = new Object(); static IAppWidgetService sService; static boolean sServiceInitialized = false; private DisplayMetrics mDisplayMetrics; private String mContextOpPackageName; Loading Loading @@ -160,23 +162,32 @@ public class AppWidgetHost { mHandler = new UpdateHandler(looper); mCallbacks = new Callbacks(mHandler); mDisplayMetrics = context.getResources().getDisplayMetrics(); bindService(); bindService(context); } private static void bindService() { private static void bindService(Context context) { synchronized (sServiceLock) { if (sService == null) { if (sServiceInitialized) { return; } sServiceInitialized = true; if (!context.getPackageManager().hasSystemFeature( PackageManager.FEATURE_APP_WIDGETS)) { return; } IBinder b = ServiceManager.getService(Context.APPWIDGET_SERVICE); sService = IAppWidgetService.Stub.asInterface(b); } } } /** * Start receiving onAppWidgetChanged calls for your AppWidgets. Call this when your activity * becomes visible, i.e. from onStart() in your Activity. */ public void startListening() { if (sService == null) { return; } final int[] idsToUpdate; synchronized (mViews) { int N = mViews.size(); Loading Loading @@ -215,6 +226,9 @@ public class AppWidgetHost { * no longer visible, i.e. from onStop() in your Activity. */ public void stopListening() { if (sService == null) { return; } try { sService.stopListening(mContextOpPackageName, mHostId); } Loading @@ -229,6 +243,9 @@ public class AppWidgetHost { * @return a appWidgetId */ public int allocateAppWidgetId() { if (sService == null) { return -1; } try { return sService.allocateAppWidgetId(mContextOpPackageName, mHostId); } Loading Loading @@ -258,6 +275,9 @@ public class AppWidgetHost { */ public final void startAppWidgetConfigureActivityForResult(@NonNull Activity activity, int appWidgetId, int intentFlags, int requestCode, @Nullable Bundle options) { if (sService == null) { return; } try { IntentSender intentSender = sService.createAppWidgetConfigIntentSender( mContextOpPackageName, appWidgetId, intentFlags); Loading @@ -278,10 +298,10 @@ public class AppWidgetHost { * Gets a list of all the appWidgetIds that are bound to the current host */ public int[] getAppWidgetIds() { try { if (sService == null) { bindService(); return new int[0]; } try { return sService.getAppWidgetIdsForHost(mContextOpPackageName, mHostId); } catch (RemoteException e) { throw new RuntimeException("system server dead?", e); Loading @@ -292,6 +312,9 @@ public class AppWidgetHost { * Stop listening to changes for this AppWidget. */ public void deleteAppWidgetId(int appWidgetId) { if (sService == null) { return; } synchronized (mViews) { mViews.remove(appWidgetId); try { Loading @@ -312,6 +335,9 @@ public class AppWidgetHost { * </ul> */ public void deleteHost() { if (sService == null) { return; } try { sService.deleteHost(mContextOpPackageName, mHostId); } Loading @@ -329,6 +355,9 @@ public class AppWidgetHost { * </ul> */ public static void deleteAllHosts() { if (sService == null) { return; } try { sService.deleteAllHosts(); } Loading @@ -343,6 +372,9 @@ public class AppWidgetHost { */ public final AppWidgetHostView createView(Context context, int appWidgetId, AppWidgetProviderInfo appWidget) { if (sService == null) { return null; } AppWidgetHostView view = onCreateView(context, appWidgetId, appWidget); view.setOnClickHandler(mOnClickHandler); view.setAppWidget(appWidgetId, appWidget); Loading Loading
core/java/android/appwidget/AppWidgetHost.java +43 −11 Original line number Diff line number Diff line Loading @@ -16,15 +16,13 @@ package android.appwidget; import java.lang.ref.WeakReference; import java.util.List; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.Activity; import android.content.ActivityNotFoundException; import android.content.Context; import android.content.IntentSender; import android.content.pm.PackageManager; import android.os.Binder; import android.os.Bundle; import android.os.Handler; Loading @@ -42,6 +40,9 @@ import android.widget.RemoteViews.OnClickHandler; import com.android.internal.appwidget.IAppWidgetHost; import com.android.internal.appwidget.IAppWidgetService; import java.lang.ref.WeakReference; import java.util.List; /** * AppWidgetHost provides the interaction with the AppWidget service for apps, * like the home screen, that want to embed AppWidgets in their UI. Loading @@ -55,6 +56,7 @@ public class AppWidgetHost { final static Object sServiceLock = new Object(); static IAppWidgetService sService; static boolean sServiceInitialized = false; private DisplayMetrics mDisplayMetrics; private String mContextOpPackageName; Loading Loading @@ -160,23 +162,32 @@ public class AppWidgetHost { mHandler = new UpdateHandler(looper); mCallbacks = new Callbacks(mHandler); mDisplayMetrics = context.getResources().getDisplayMetrics(); bindService(); bindService(context); } private static void bindService() { private static void bindService(Context context) { synchronized (sServiceLock) { if (sService == null) { if (sServiceInitialized) { return; } sServiceInitialized = true; if (!context.getPackageManager().hasSystemFeature( PackageManager.FEATURE_APP_WIDGETS)) { return; } IBinder b = ServiceManager.getService(Context.APPWIDGET_SERVICE); sService = IAppWidgetService.Stub.asInterface(b); } } } /** * Start receiving onAppWidgetChanged calls for your AppWidgets. Call this when your activity * becomes visible, i.e. from onStart() in your Activity. */ public void startListening() { if (sService == null) { return; } final int[] idsToUpdate; synchronized (mViews) { int N = mViews.size(); Loading Loading @@ -215,6 +226,9 @@ public class AppWidgetHost { * no longer visible, i.e. from onStop() in your Activity. */ public void stopListening() { if (sService == null) { return; } try { sService.stopListening(mContextOpPackageName, mHostId); } Loading @@ -229,6 +243,9 @@ public class AppWidgetHost { * @return a appWidgetId */ public int allocateAppWidgetId() { if (sService == null) { return -1; } try { return sService.allocateAppWidgetId(mContextOpPackageName, mHostId); } Loading Loading @@ -258,6 +275,9 @@ public class AppWidgetHost { */ public final void startAppWidgetConfigureActivityForResult(@NonNull Activity activity, int appWidgetId, int intentFlags, int requestCode, @Nullable Bundle options) { if (sService == null) { return; } try { IntentSender intentSender = sService.createAppWidgetConfigIntentSender( mContextOpPackageName, appWidgetId, intentFlags); Loading @@ -278,10 +298,10 @@ public class AppWidgetHost { * Gets a list of all the appWidgetIds that are bound to the current host */ public int[] getAppWidgetIds() { try { if (sService == null) { bindService(); return new int[0]; } try { return sService.getAppWidgetIdsForHost(mContextOpPackageName, mHostId); } catch (RemoteException e) { throw new RuntimeException("system server dead?", e); Loading @@ -292,6 +312,9 @@ public class AppWidgetHost { * Stop listening to changes for this AppWidget. */ public void deleteAppWidgetId(int appWidgetId) { if (sService == null) { return; } synchronized (mViews) { mViews.remove(appWidgetId); try { Loading @@ -312,6 +335,9 @@ public class AppWidgetHost { * </ul> */ public void deleteHost() { if (sService == null) { return; } try { sService.deleteHost(mContextOpPackageName, mHostId); } Loading @@ -329,6 +355,9 @@ public class AppWidgetHost { * </ul> */ public static void deleteAllHosts() { if (sService == null) { return; } try { sService.deleteAllHosts(); } Loading @@ -343,6 +372,9 @@ public class AppWidgetHost { */ public final AppWidgetHostView createView(Context context, int appWidgetId, AppWidgetProviderInfo appWidget) { if (sService == null) { return null; } AppWidgetHostView view = onCreateView(context, appWidgetId, appWidget); view.setOnClickHandler(mOnClickHandler); view.setAppWidget(appWidgetId, appWidget); Loading