The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.appwidget; |
| 18 | |
Svetoslav | 8e1d299 | 2014-08-08 12:48:06 -0700 | [diff] [blame] | 19 | import android.annotation.Nullable; |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 20 | import android.content.ComponentName; |
| 21 | import android.content.Context; |
Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 22 | import android.content.Intent; |
Hyunyoung Song | ccf6c68 | 2015-06-17 15:23:31 -0700 | [diff] [blame] | 23 | import android.content.pm.ParceledListSlice; |
Adam Cohen | e8724c8 | 2012-04-19 17:11:40 -0700 | [diff] [blame] | 24 | import android.os.Bundle; |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 25 | import android.os.IBinder; |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 26 | import android.os.Process; |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 27 | import android.os.RemoteException; |
Amith Yamasani | c566b43 | 2012-11-30 15:26:21 -0800 | [diff] [blame] | 28 | import android.os.UserHandle; |
Mitsuru Oshima | 8f25c42 | 2009-07-01 00:10:43 -0700 | [diff] [blame] | 29 | import android.util.DisplayMetrics; |
Mitsuru Oshima | 8f25c42 | 2009-07-01 00:10:43 -0700 | [diff] [blame] | 30 | import android.util.TypedValue; |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 31 | import android.widget.RemoteViews; |
| 32 | |
| 33 | import com.android.internal.appwidget.IAppWidgetService; |
| 34 | |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 35 | import java.util.Collections; |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 36 | import java.util.List; |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 37 | |
| 38 | /** |
| 39 | * Updates AppWidget state; gets information about installed AppWidget providers and other |
| 40 | * AppWidget related state. |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 41 | * |
| 42 | * <div class="special reference"> |
| 43 | * <h3>Developer Guides</h3> |
| 44 | * <p>For more information about creating app widgets, read the |
| 45 | * <a href="{@docRoot}guide/topics/appwidgets/index.html">App Widgets</a> developer guide.</p> |
| 46 | * </div> |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 47 | */ |
| 48 | public class AppWidgetManager { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 49 | |
| 50 | /** |
Dianne Hackborn | a40cfeb | 2013-03-25 17:49:36 -0700 | [diff] [blame] | 51 | * Activity action to launch from your {@link AppWidgetHost} activity when you want to |
| 52 | * pick an AppWidget to display. The AppWidget picker activity will be launched. |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 53 | * <p> |
| 54 | * You must supply the following extras: |
| 55 | * <table> |
| 56 | * <tr> |
| 57 | * <td>{@link #EXTRA_APPWIDGET_ID}</td> |
| 58 | * <td>A newly allocated appWidgetId, which will be bound to the AppWidget provider |
| 59 | * once the user has selected one.</td> |
| 60 | * </tr> |
| 61 | * </table> |
| 62 | * |
| 63 | * <p> |
| 64 | * The system will respond with an onActivityResult call with the following extras in |
| 65 | * the intent: |
| 66 | * <table> |
| 67 | * <tr> |
| 68 | * <td>{@link #EXTRA_APPWIDGET_ID}</td> |
| 69 | * <td>The appWidgetId that you supplied in the original intent.</td> |
| 70 | * </tr> |
| 71 | * </table> |
| 72 | * <p> |
| 73 | * When you receive the result from the AppWidget pick activity, if the resultCode is |
| 74 | * {@link android.app.Activity#RESULT_OK}, an AppWidget has been selected. You should then |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 75 | * check the AppWidgetProviderInfo for the returned AppWidget, and if it has one, launch its |
| 76 | * configuration activity. If {@link android.app.Activity#RESULT_CANCELED} is returned, you |
| 77 | * should delete the appWidgetId. |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 78 | * |
| 79 | * @see #ACTION_APPWIDGET_CONFIGURE |
| 80 | */ |
| 81 | public static final String ACTION_APPWIDGET_PICK = "android.appwidget.action.APPWIDGET_PICK"; |
| 82 | |
| 83 | /** |
Michael Jurka | fc753c0 | 2012-10-30 18:30:52 -0700 | [diff] [blame] | 84 | * Similar to ACTION_APPWIDGET_PICK, but used from keyguard |
| 85 | * @hide |
| 86 | */ |
| 87 | public static final String |
| 88 | ACTION_KEYGUARD_APPWIDGET_PICK = "android.appwidget.action.KEYGUARD_APPWIDGET_PICK"; |
| 89 | |
| 90 | /** |
Dianne Hackborn | a40cfeb | 2013-03-25 17:49:36 -0700 | [diff] [blame] | 91 | * Activity action to launch from your {@link AppWidgetHost} activity when you want to bind |
| 92 | * an AppWidget to display and bindAppWidgetIdIfAllowed returns false. |
Michael Jurka | 61a5b01 | 2012-04-13 10:39:45 -0700 | [diff] [blame] | 93 | * <p> |
| 94 | * You must supply the following extras: |
| 95 | * <table> |
| 96 | * <tr> |
| 97 | * <td>{@link #EXTRA_APPWIDGET_ID}</td> |
| 98 | * <td>A newly allocated appWidgetId, which will be bound to the AppWidget provider |
| 99 | * you provide.</td> |
| 100 | * </tr> |
| 101 | * <tr> |
| 102 | * <td>{@link #EXTRA_APPWIDGET_PROVIDER}</td> |
| 103 | * <td>The BroadcastReceiver that will be the AppWidget provider for this AppWidget. |
| 104 | * </td> |
| 105 | * </tr> |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 106 | * <tr> |
| 107 | * <td>{@link #EXTRA_APPWIDGET_PROVIDER_PROFILE}</td> |
| 108 | * <td>An optional handle to a user profile under which runs the provider |
| 109 | * for this AppWidget. |
| 110 | * </td> |
| 111 | * </tr> |
Michael Jurka | 61a5b01 | 2012-04-13 10:39:45 -0700 | [diff] [blame] | 112 | * </table> |
| 113 | * |
| 114 | * <p> |
| 115 | * The system will respond with an onActivityResult call with the following extras in |
| 116 | * the intent: |
| 117 | * <table> |
| 118 | * <tr> |
| 119 | * <td>{@link #EXTRA_APPWIDGET_ID}</td> |
| 120 | * <td>The appWidgetId that you supplied in the original intent.</td> |
| 121 | * </tr> |
| 122 | * </table> |
| 123 | * <p> |
| 124 | * When you receive the result from the AppWidget bind activity, if the resultCode is |
| 125 | * {@link android.app.Activity#RESULT_OK}, the AppWidget has been bound. You should then |
| 126 | * check the AppWidgetProviderInfo for the returned AppWidget, and if it has one, launch its |
| 127 | * configuration activity. If {@link android.app.Activity#RESULT_CANCELED} is returned, you |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 128 | * should delete the appWidgetId. |
Michael Jurka | 61a5b01 | 2012-04-13 10:39:45 -0700 | [diff] [blame] | 129 | * |
| 130 | * @see #ACTION_APPWIDGET_CONFIGURE |
| 131 | * |
| 132 | */ |
| 133 | public static final String ACTION_APPWIDGET_BIND = "android.appwidget.action.APPWIDGET_BIND"; |
| 134 | |
| 135 | /** |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 136 | * Sent when it is time to configure your AppWidget while it is being added to a host. |
| 137 | * This action is not sent as a broadcast to the AppWidget provider, but as a startActivity |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 138 | * to the activity specified in the {@link AppWidgetProviderInfo AppWidgetProviderInfo |
| 139 | * meta-data}. |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 140 | * |
| 141 | * <p> |
| 142 | * The intent will contain the following extras: |
| 143 | * <table> |
| 144 | * <tr> |
| 145 | * <td>{@link #EXTRA_APPWIDGET_ID}</td> |
| 146 | * <td>The appWidgetId to configure.</td> |
| 147 | * </tr> |
| 148 | * </table> |
| 149 | * |
| 150 | * <p>If you return {@link android.app.Activity#RESULT_OK} using |
| 151 | * {@link android.app.Activity#setResult Activity.setResult()}, the AppWidget will be added, |
| 152 | * and you will receive an {@link #ACTION_APPWIDGET_UPDATE} broadcast for this AppWidget. |
| 153 | * If you return {@link android.app.Activity#RESULT_CANCELED}, the host will cancel the add |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 154 | * and not display this AppWidget, and you will receive a {@link #ACTION_APPWIDGET_DELETED} |
| 155 | * broadcast. |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 156 | */ |
| 157 | public static final String ACTION_APPWIDGET_CONFIGURE = "android.appwidget.action.APPWIDGET_CONFIGURE"; |
| 158 | |
| 159 | /** |
| 160 | * An intent extra that contains one appWidgetId. |
| 161 | * <p> |
| 162 | * The value will be an int that can be retrieved like this: |
| 163 | * {@sample frameworks/base/tests/appwidgets/AppWidgetHostTest/src/com/android/tests/appwidgethost/AppWidgetHostActivity.java getExtra_EXTRA_APPWIDGET_ID} |
| 164 | */ |
| 165 | public static final String EXTRA_APPWIDGET_ID = "appWidgetId"; |
| 166 | |
| 167 | /** |
Adam Cohen | 0aa2d42 | 2012-09-07 17:37:26 -0700 | [diff] [blame] | 168 | * A bundle extra that contains the lower bound on the current width, in dips, of a widget instance. |
Adam Cohen | e8724c8 | 2012-04-19 17:11:40 -0700 | [diff] [blame] | 169 | */ |
Adam Cohen | d2097eb | 2012-05-01 18:10:28 -0700 | [diff] [blame] | 170 | public static final String OPTION_APPWIDGET_MIN_WIDTH = "appWidgetMinWidth"; |
Adam Cohen | e8724c8 | 2012-04-19 17:11:40 -0700 | [diff] [blame] | 171 | |
| 172 | /** |
Adam Cohen | 0aa2d42 | 2012-09-07 17:37:26 -0700 | [diff] [blame] | 173 | * A bundle extra that contains the lower bound on the current height, in dips, of a widget instance. |
Adam Cohen | e8724c8 | 2012-04-19 17:11:40 -0700 | [diff] [blame] | 174 | */ |
Adam Cohen | d2097eb | 2012-05-01 18:10:28 -0700 | [diff] [blame] | 175 | public static final String OPTION_APPWIDGET_MIN_HEIGHT = "appWidgetMinHeight"; |
Adam Cohen | e8724c8 | 2012-04-19 17:11:40 -0700 | [diff] [blame] | 176 | |
| 177 | /** |
Adam Cohen | 0aa2d42 | 2012-09-07 17:37:26 -0700 | [diff] [blame] | 178 | * A bundle extra that contains the upper bound on the current width, in dips, of a widget instance. |
Adam Cohen | e8724c8 | 2012-04-19 17:11:40 -0700 | [diff] [blame] | 179 | */ |
Adam Cohen | d2097eb | 2012-05-01 18:10:28 -0700 | [diff] [blame] | 180 | public static final String OPTION_APPWIDGET_MAX_WIDTH = "appWidgetMaxWidth"; |
Adam Cohen | e8724c8 | 2012-04-19 17:11:40 -0700 | [diff] [blame] | 181 | |
| 182 | /** |
Adam Cohen | 0aa2d42 | 2012-09-07 17:37:26 -0700 | [diff] [blame] | 183 | * A bundle extra that contains the upper bound on the current width, in dips, of a widget instance. |
Adam Cohen | e8724c8 | 2012-04-19 17:11:40 -0700 | [diff] [blame] | 184 | */ |
Adam Cohen | d2097eb | 2012-05-01 18:10:28 -0700 | [diff] [blame] | 185 | public static final String OPTION_APPWIDGET_MAX_HEIGHT = "appWidgetMaxHeight"; |
Adam Cohen | e8724c8 | 2012-04-19 17:11:40 -0700 | [diff] [blame] | 186 | |
| 187 | /** |
Adam Cohen | 0aa2d42 | 2012-09-07 17:37:26 -0700 | [diff] [blame] | 188 | * A bundle extra that hints to the AppWidgetProvider the category of host that owns this |
| 189 | * this widget. Can have the value {@link |
| 190 | * AppWidgetProviderInfo#WIDGET_CATEGORY_HOME_SCREEN} or {@link |
Winson Chung | da5b84c | 2014-05-05 12:06:28 -0700 | [diff] [blame] | 191 | * AppWidgetProviderInfo#WIDGET_CATEGORY_KEYGUARD} or {@link |
Winson Chung | ee0b121 | 2014-09-04 16:42:53 +0200 | [diff] [blame] | 192 | * AppWidgetProviderInfo#WIDGET_CATEGORY_SEARCHBOX}. |
Adam Cohen | 0aa2d42 | 2012-09-07 17:37:26 -0700 | [diff] [blame] | 193 | */ |
| 194 | public static final String OPTION_APPWIDGET_HOST_CATEGORY = "appWidgetCategory"; |
| 195 | |
| 196 | /** |
Adam Cohen | e8724c8 | 2012-04-19 17:11:40 -0700 | [diff] [blame] | 197 | * An intent extra which points to a bundle of extra information for a particular widget id. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 198 | * In particular this bundle can contain {@link #OPTION_APPWIDGET_MIN_WIDTH}, |
| 199 | * {@link #OPTION_APPWIDGET_MIN_HEIGHT}, {@link #OPTION_APPWIDGET_MAX_WIDTH}, |
| 200 | * {@link #OPTION_APPWIDGET_MAX_HEIGHT}. |
Adam Cohen | e8724c8 | 2012-04-19 17:11:40 -0700 | [diff] [blame] | 201 | */ |
Adam Cohen | d2097eb | 2012-05-01 18:10:28 -0700 | [diff] [blame] | 202 | public static final String EXTRA_APPWIDGET_OPTIONS = "appWidgetOptions"; |
Adam Cohen | e8724c8 | 2012-04-19 17:11:40 -0700 | [diff] [blame] | 203 | |
| 204 | /** |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 205 | * An intent extra that contains multiple appWidgetIds. |
| 206 | * <p> |
| 207 | * The value will be an int array that can be retrieved like this: |
| 208 | * {@sample frameworks/base/tests/appwidgets/AppWidgetHostTest/src/com/android/tests/appwidgethost/TestAppWidgetProvider.java getExtra_EXTRA_APPWIDGET_IDS} |
| 209 | */ |
| 210 | public static final String EXTRA_APPWIDGET_IDS = "appWidgetIds"; |
| 211 | |
| 212 | /** |
Michael Jurka | 61a5b01 | 2012-04-13 10:39:45 -0700 | [diff] [blame] | 213 | * An intent extra that contains the component name of a AppWidget provider. |
| 214 | * <p> |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 215 | * The value will be an {@link android.content.ComponentName}. |
Michael Jurka | 61a5b01 | 2012-04-13 10:39:45 -0700 | [diff] [blame] | 216 | */ |
| 217 | public static final String EXTRA_APPWIDGET_PROVIDER = "appWidgetProvider"; |
| 218 | |
| 219 | /** |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 220 | * An intent extra that contains the user handle of the profile under |
| 221 | * which an AppWidget provider is registered. |
| 222 | * <p> |
| 223 | * The value will be a {@link android.os.UserHandle}. |
| 224 | */ |
| 225 | public static final String EXTRA_APPWIDGET_PROVIDER_PROFILE = "appWidgetProviderProfile"; |
| 226 | |
| 227 | /** |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 228 | * An intent extra to pass to the AppWidget picker containing a {@link java.util.List} of |
| 229 | * {@link AppWidgetProviderInfo} objects to mix in to the list of AppWidgets that are |
| 230 | * installed. (This is how the launcher shows the search widget). |
| 231 | */ |
| 232 | public static final String EXTRA_CUSTOM_INFO = "customInfo"; |
| 233 | |
| 234 | /** |
Christopher Tate | adfe8b8 | 2014-02-04 16:23:32 -0800 | [diff] [blame] | 235 | * An intent extra attached to the {@link #ACTION_APPWIDGET_HOST_RESTORED} broadcast, |
| 236 | * indicating the integer ID of the host whose widgets have just been restored. |
| 237 | */ |
| 238 | public static final String EXTRA_HOST_ID = "hostId"; |
| 239 | |
| 240 | /** |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 241 | * An intent extra to pass to the AppWidget picker containing a {@link java.util.List} of |
| 242 | * {@link android.os.Bundle} objects to mix in to the list of AppWidgets that are |
| 243 | * installed. It will be added to the extras object on the {@link android.content.Intent} |
| 244 | * that is returned from the picker activity. |
| 245 | * |
| 246 | * {@more} |
| 247 | */ |
| 248 | public static final String EXTRA_CUSTOM_EXTRAS = "customExtras"; |
| 249 | |
| 250 | /** |
Adam Cohen | 8c09f63 | 2012-09-11 18:23:35 -0700 | [diff] [blame] | 251 | * An intent extra to pass to the AppWidget picker which allows the picker to filter |
| 252 | * the list based on the {@link AppWidgetProviderInfo#widgetCategory}. |
Jim Miller | f229e4d | 2012-09-12 20:32:50 -0700 | [diff] [blame] | 253 | * |
| 254 | * @hide |
Adam Cohen | 8c09f63 | 2012-09-11 18:23:35 -0700 | [diff] [blame] | 255 | */ |
Adam Cohen | 8c09f63 | 2012-09-11 18:23:35 -0700 | [diff] [blame] | 256 | public static final String EXTRA_CATEGORY_FILTER = "categoryFilter"; |
| 257 | |
| 258 | /** |
Jim Miller | f229e4d | 2012-09-12 20:32:50 -0700 | [diff] [blame] | 259 | * An intent extra to pass to the AppWidget picker to specify whether or not to sort |
| 260 | * the list of caller-specified extra AppWidgets along with the rest of the AppWidgets |
| 261 | * @hide |
| 262 | */ |
| 263 | public static final String EXTRA_CUSTOM_SORT = "customSort"; |
| 264 | |
| 265 | /** |
Scott Main | 6aad995 | 2013-01-07 18:51:49 -0800 | [diff] [blame] | 266 | * A sentinel value that the AppWidget manager will never return as a appWidgetId. |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 267 | */ |
| 268 | public static final int INVALID_APPWIDGET_ID = 0; |
| 269 | |
| 270 | /** |
| 271 | * Sent when it is time to update your AppWidget. |
| 272 | * |
| 273 | * <p>This may be sent in response to a new instance for this AppWidget provider having |
| 274 | * been instantiated, the requested {@link AppWidgetProviderInfo#updatePeriodMillis update interval} |
| 275 | * having lapsed, or the system booting. |
| 276 | * |
| 277 | * <p> |
| 278 | * The intent will contain the following extras: |
| 279 | * <table> |
| 280 | * <tr> |
| 281 | * <td>{@link #EXTRA_APPWIDGET_IDS}</td> |
| 282 | * <td>The appWidgetIds to update. This may be all of the AppWidgets created for this |
| 283 | * provider, or just a subset. The system tries to send updates for as few AppWidget |
| 284 | * instances as possible.</td> |
| 285 | * </tr> |
| 286 | * </table> |
Christian Mehlmauer | 10c543d | 2010-06-25 19:27:04 +0200 | [diff] [blame] | 287 | * |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 288 | * @see AppWidgetProvider#onUpdate AppWidgetProvider.onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) |
| 289 | */ |
| 290 | public static final String ACTION_APPWIDGET_UPDATE = "android.appwidget.action.APPWIDGET_UPDATE"; |
| 291 | |
| 292 | /** |
Adam Cohen | e8724c8 | 2012-04-19 17:11:40 -0700 | [diff] [blame] | 293 | * Sent when the custom extras for an AppWidget change. |
| 294 | * |
Dianne Hackborn | a40cfeb | 2013-03-25 17:49:36 -0700 | [diff] [blame] | 295 | * <p class="note">This is a protected intent that can only be sent |
| 296 | * by the system. |
| 297 | * |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 298 | * @see AppWidgetProvider#onAppWidgetOptionsChanged |
| 299 | * AppWidgetProvider.onAppWidgetOptionsChanged(Context context, |
Katie McCormick | 0e9f34b | 2012-09-10 15:32:46 -0700 | [diff] [blame] | 300 | * AppWidgetManager appWidgetManager, int appWidgetId, Bundle newExtras) |
Adam Cohen | e8724c8 | 2012-04-19 17:11:40 -0700 | [diff] [blame] | 301 | */ |
Adam Cohen | d2097eb | 2012-05-01 18:10:28 -0700 | [diff] [blame] | 302 | public static final String ACTION_APPWIDGET_OPTIONS_CHANGED = "android.appwidget.action.APPWIDGET_UPDATE_OPTIONS"; |
Adam Cohen | e8724c8 | 2012-04-19 17:11:40 -0700 | [diff] [blame] | 303 | |
| 304 | /** |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 305 | * Sent when an instance of an AppWidget is deleted from its host. |
| 306 | * |
Dianne Hackborn | a40cfeb | 2013-03-25 17:49:36 -0700 | [diff] [blame] | 307 | * <p class="note">This is a protected intent that can only be sent |
| 308 | * by the system. |
| 309 | * |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 310 | * @see AppWidgetProvider#onDeleted AppWidgetProvider.onDeleted(Context context, int[] appWidgetIds) |
| 311 | */ |
| 312 | public static final String ACTION_APPWIDGET_DELETED = "android.appwidget.action.APPWIDGET_DELETED"; |
| 313 | |
| 314 | /** |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 315 | * Sent when the last AppWidget of this provider is removed from the last host. |
Christian Mehlmauer | 10c543d | 2010-06-25 19:27:04 +0200 | [diff] [blame] | 316 | * |
Dianne Hackborn | a40cfeb | 2013-03-25 17:49:36 -0700 | [diff] [blame] | 317 | * <p class="note">This is a protected intent that can only be sent |
| 318 | * by the system. |
| 319 | * |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 320 | * @see AppWidgetProvider#onEnabled AppWidgetProvider.onDisabled(Context context) |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 321 | */ |
| 322 | public static final String ACTION_APPWIDGET_DISABLED = "android.appwidget.action.APPWIDGET_DISABLED"; |
| 323 | |
| 324 | /** |
| 325 | * Sent when an instance of an AppWidget is added to a host for the first time. |
| 326 | * This broadcast is sent at boot time if there is a AppWidgetHost installed with |
| 327 | * an instance for this provider. |
Christian Mehlmauer | 10c543d | 2010-06-25 19:27:04 +0200 | [diff] [blame] | 328 | * |
Dianne Hackborn | a40cfeb | 2013-03-25 17:49:36 -0700 | [diff] [blame] | 329 | * <p class="note">This is a protected intent that can only be sent |
| 330 | * by the system. |
| 331 | * |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 332 | * @see AppWidgetProvider#onEnabled AppWidgetProvider.onEnabled(Context context) |
| 333 | */ |
| 334 | public static final String ACTION_APPWIDGET_ENABLED = "android.appwidget.action.APPWIDGET_ENABLED"; |
| 335 | |
| 336 | /** |
Christopher Tate | c04e9aa | 2014-05-28 17:56:53 -0700 | [diff] [blame] | 337 | * Sent to an {@link AppWidgetProvider} after AppWidget state related to that provider has |
| 338 | * been restored from backup. The intent contains information about how to translate AppWidget |
| 339 | * ids from the restored data to their new equivalents. |
Christopher Tate | adfe8b8 | 2014-02-04 16:23:32 -0800 | [diff] [blame] | 340 | * |
| 341 | * <p>The intent will contain the following extras: |
| 342 | * |
| 343 | * <table> |
| 344 | * <tr> |
| 345 | * <td>{@link #EXTRA_APPWIDGET_OLD_IDS}</td> |
| 346 | * <td>The set of appWidgetIds represented in a restored backup that have been successfully |
| 347 | * incorporated into the current environment. This may be all of the AppWidgets known |
| 348 | * to this application, or just a subset. Each entry in this array of appWidgetIds has |
| 349 | * a corresponding entry in the {@link #EXTRA_APPWIDGET_IDS} extra.</td> |
| 350 | * </tr> |
| 351 | * <tr> |
| 352 | * <td>{@link #EXTRA_APPWIDGET_IDS}</td> |
| 353 | * <td>The set of appWidgetIds now valid for this application. The app should look at |
| 354 | * its restored widget configuration and translate each appWidgetId in the |
| 355 | * {@link #EXTRA_APPWIDGET_OLD_IDS} array to its new value found at the corresponding |
| 356 | * index within this array.</td> |
| 357 | * </tr> |
| 358 | * </table> |
| 359 | * |
| 360 | * <p class="note">This is a protected intent that can only be sent |
| 361 | * by the system. |
| 362 | * |
Christopher Tate | c04e9aa | 2014-05-28 17:56:53 -0700 | [diff] [blame] | 363 | * @see #ACTION_APPWIDGET_HOST_RESTORED |
Christopher Tate | adfe8b8 | 2014-02-04 16:23:32 -0800 | [diff] [blame] | 364 | */ |
| 365 | public static final String ACTION_APPWIDGET_RESTORED |
| 366 | = "android.appwidget.action.APPWIDGET_RESTORED"; |
| 367 | |
| 368 | /** |
| 369 | * Sent to widget hosts after AppWidget state related to the host has been restored from |
| 370 | * backup. The intent contains information about how to translate AppWidget ids from the |
| 371 | * restored data to their new equivalents. If an application maintains multiple separate |
Christopher Tate | c04e9aa | 2014-05-28 17:56:53 -0700 | [diff] [blame] | 372 | * widget host instances, it will receive this broadcast separately for each one. |
Christopher Tate | adfe8b8 | 2014-02-04 16:23:32 -0800 | [diff] [blame] | 373 | * |
| 374 | * <p>The intent will contain the following extras: |
| 375 | * |
| 376 | * <table> |
| 377 | * <tr> |
| 378 | * <td>{@link #EXTRA_APPWIDGET_OLD_IDS}</td> |
| 379 | * <td>The set of appWidgetIds represented in a restored backup that have been successfully |
| 380 | * incorporated into the current environment. This may be all of the AppWidgets known |
| 381 | * to this application, or just a subset. Each entry in this array of appWidgetIds has |
| 382 | * a corresponding entry in the {@link #EXTRA_APPWIDGET_IDS} extra.</td> |
| 383 | * </tr> |
| 384 | * <tr> |
| 385 | * <td>{@link #EXTRA_APPWIDGET_IDS}</td> |
| 386 | * <td>The set of appWidgetIds now valid for this application. The app should look at |
| 387 | * its restored widget configuration and translate each appWidgetId in the |
| 388 | * {@link #EXTRA_APPWIDGET_OLD_IDS} array to its new value found at the corresponding |
| 389 | * index within this array.</td> |
| 390 | * </tr> |
| 391 | * <tr> |
| 392 | * <td>{@link #EXTRA_HOST_ID}</td> |
| 393 | * <td>The integer ID of the widget host instance whose state has just been restored.</td> |
| 394 | * </tr> |
| 395 | * </table> |
| 396 | * |
| 397 | * <p class="note">This is a protected intent that can only be sent |
| 398 | * by the system. |
| 399 | * |
Christopher Tate | c04e9aa | 2014-05-28 17:56:53 -0700 | [diff] [blame] | 400 | * @see #ACTION_APPWIDGET_RESTORED |
Christopher Tate | adfe8b8 | 2014-02-04 16:23:32 -0800 | [diff] [blame] | 401 | */ |
| 402 | public static final String ACTION_APPWIDGET_HOST_RESTORED |
| 403 | = "android.appwidget.action.APPWIDGET_HOST_RESTORED"; |
| 404 | |
| 405 | /** |
| 406 | * An intent extra that contains multiple appWidgetIds. These are id values as |
| 407 | * they were provided to the application during a recent restore from backup. It is |
| 408 | * attached to the {@link #ACTION_APPWIDGET_RESTORED} broadcast intent. |
| 409 | * |
| 410 | * <p> |
| 411 | * The value will be an int array that can be retrieved like this: |
| 412 | * {@sample frameworks/base/tests/appwidgets/AppWidgetHostTest/src/com/android/tests/appwidgethost/TestAppWidgetProvider.java getExtra_EXTRA_APPWIDGET_IDS} |
| 413 | */ |
| 414 | public static final String EXTRA_APPWIDGET_OLD_IDS = "appWidgetOldIds"; |
| 415 | |
| 416 | /** |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 417 | * Field for the manifest meta-data tag. |
| 418 | * |
| 419 | * @see AppWidgetProviderInfo |
| 420 | */ |
| 421 | public static final String META_DATA_APPWIDGET_PROVIDER = "android.appwidget.provider"; |
Christian Mehlmauer | 10c543d | 2010-06-25 19:27:04 +0200 | [diff] [blame] | 422 | |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 423 | private final String mPackageName; |
Christian Mehlmauer | 10c543d | 2010-06-25 19:27:04 +0200 | [diff] [blame] | 424 | |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 425 | private final IAppWidgetService mService; |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 426 | |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 427 | private final DisplayMetrics mDisplayMetrics; |
Mitsuru Oshima | 8f25c42 | 2009-07-01 00:10:43 -0700 | [diff] [blame] | 428 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 429 | /** |
| 430 | * Get the AppWidgetManager instance to use for the supplied {@link android.content.Context |
| 431 | * Context} object. |
| 432 | */ |
| 433 | public static AppWidgetManager getInstance(Context context) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 434 | return (AppWidgetManager) context.getSystemService(Context.APPWIDGET_SERVICE); |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 435 | } |
| 436 | |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 437 | /** |
| 438 | * Creates a new instance. |
| 439 | * |
| 440 | * @param context The current context in which to operate. |
| 441 | * @param service The backing system service. |
| 442 | * @hide |
| 443 | */ |
| 444 | public AppWidgetManager(Context context, IAppWidgetService service) { |
Svet Ganov | 5771ad7 | 2014-08-23 21:10:29 -0700 | [diff] [blame] | 445 | mPackageName = context.getOpPackageName(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 446 | mService = service; |
Mitsuru Oshima | 8f25c42 | 2009-07-01 00:10:43 -0700 | [diff] [blame] | 447 | mDisplayMetrics = context.getResources().getDisplayMetrics(); |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | /** |
| 451 | * Set the RemoteViews to use for the specified appWidgetIds. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 452 | * <p> |
Adam Cohen | 2dd2197 | 2010-08-15 18:20:04 -0700 | [diff] [blame] | 453 | * Note that the RemoteViews parameter will be cached by the AppWidgetService, and hence should |
| 454 | * contain a complete representation of the widget. For performing partial widget updates, see |
| 455 | * {@link #partiallyUpdateAppWidget(int[], RemoteViews)}. |
| 456 | * |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 457 | * <p> |
| 458 | * It is okay to call this method both inside an {@link #ACTION_APPWIDGET_UPDATE} broadcast, |
| 459 | * and outside of the handler. |
| 460 | * This method will only work when called from the uid that owns the AppWidget provider. |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 461 | * |
Adam Cohen | 311c79c | 2012-05-10 14:44:38 -0700 | [diff] [blame] | 462 | * <p> |
| 463 | * The total Bitmap memory used by the RemoteViews object cannot exceed that required to |
Michael Jurka | f25ab44 | 2012-06-25 15:11:21 -0700 | [diff] [blame] | 464 | * fill the screen 1.5 times, ie. (screen width x screen height x 4 x 1.5) bytes. |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 465 | * |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 466 | * @param appWidgetIds The AppWidget instances for which to set the RemoteViews. |
| 467 | * @param views The RemoteViews object to show. |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 468 | */ |
| 469 | public void updateAppWidget(int[] appWidgetIds, RemoteViews views) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 470 | if (mService == null) { |
| 471 | return; |
| 472 | } |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 473 | try { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 474 | mService.updateAppWidgetIds(mPackageName, appWidgetIds, views); |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 475 | } catch (RemoteException e) { |
| 476 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 477 | } |
| 478 | } |
| 479 | |
| 480 | /** |
Adam Cohen | e8724c8 | 2012-04-19 17:11:40 -0700 | [diff] [blame] | 481 | * Update the extras for a given widget instance. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 482 | * <p> |
Adam Cohen | e8724c8 | 2012-04-19 17:11:40 -0700 | [diff] [blame] | 483 | * The extras can be used to embed additional information about this widget to be accessed |
| 484 | * by the associated widget's AppWidgetProvider. |
| 485 | * |
Adam Cohen | d2097eb | 2012-05-01 18:10:28 -0700 | [diff] [blame] | 486 | * @see #getAppWidgetOptions(int) |
Adam Cohen | e8724c8 | 2012-04-19 17:11:40 -0700 | [diff] [blame] | 487 | * |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 488 | * @param appWidgetId The AppWidget instances for which to set the RemoteViews. |
| 489 | * @param options The options to associate with this widget |
Adam Cohen | e8724c8 | 2012-04-19 17:11:40 -0700 | [diff] [blame] | 490 | */ |
Adam Cohen | d2097eb | 2012-05-01 18:10:28 -0700 | [diff] [blame] | 491 | public void updateAppWidgetOptions(int appWidgetId, Bundle options) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 492 | if (mService == null) { |
| 493 | return; |
| 494 | } |
Adam Cohen | e8724c8 | 2012-04-19 17:11:40 -0700 | [diff] [blame] | 495 | try { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 496 | mService.updateAppWidgetOptions(mPackageName, appWidgetId, options); |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 497 | } catch (RemoteException e) { |
| 498 | throw e.rethrowFromSystemServer(); |
Adam Cohen | e8724c8 | 2012-04-19 17:11:40 -0700 | [diff] [blame] | 499 | } |
| 500 | } |
| 501 | |
| 502 | /** |
| 503 | * Get the extras associated with a given widget instance. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 504 | * <p> |
Adam Cohen | e8724c8 | 2012-04-19 17:11:40 -0700 | [diff] [blame] | 505 | * The extras can be used to embed additional information about this widget to be accessed |
| 506 | * by the associated widget's AppWidgetProvider. |
| 507 | * |
Adam Cohen | d2097eb | 2012-05-01 18:10:28 -0700 | [diff] [blame] | 508 | * @see #updateAppWidgetOptions(int, Bundle) |
Adam Cohen | e8724c8 | 2012-04-19 17:11:40 -0700 | [diff] [blame] | 509 | * |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 510 | * @param appWidgetId The AppWidget instances for which to set the RemoteViews. |
| 511 | * @return The options associated with the given widget instance. |
Adam Cohen | e8724c8 | 2012-04-19 17:11:40 -0700 | [diff] [blame] | 512 | */ |
Adam Cohen | d2097eb | 2012-05-01 18:10:28 -0700 | [diff] [blame] | 513 | public Bundle getAppWidgetOptions(int appWidgetId) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 514 | if (mService == null) { |
| 515 | return Bundle.EMPTY; |
| 516 | } |
Adam Cohen | e8724c8 | 2012-04-19 17:11:40 -0700 | [diff] [blame] | 517 | try { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 518 | return mService.getAppWidgetOptions(mPackageName, appWidgetId); |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 519 | } catch (RemoteException e) { |
| 520 | throw e.rethrowFromSystemServer(); |
Adam Cohen | e8724c8 | 2012-04-19 17:11:40 -0700 | [diff] [blame] | 521 | } |
| 522 | } |
| 523 | |
| 524 | /** |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 525 | * Set the RemoteViews to use for the specified appWidgetId. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 526 | * <p> |
Adam Cohen | 2dd2197 | 2010-08-15 18:20:04 -0700 | [diff] [blame] | 527 | * Note that the RemoteViews parameter will be cached by the AppWidgetService, and hence should |
| 528 | * contain a complete representation of the widget. For performing partial widget updates, see |
| 529 | * {@link #partiallyUpdateAppWidget(int, RemoteViews)}. |
| 530 | * |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 531 | * <p> |
| 532 | * It is okay to call this method both inside an {@link #ACTION_APPWIDGET_UPDATE} broadcast, |
| 533 | * and outside of the handler. |
| 534 | * This method will only work when called from the uid that owns the AppWidget provider. |
| 535 | * |
Adam Cohen | 311c79c | 2012-05-10 14:44:38 -0700 | [diff] [blame] | 536 | * <p> |
| 537 | * The total Bitmap memory used by the RemoteViews object cannot exceed that required to |
Michael Jurka | f25ab44 | 2012-06-25 15:11:21 -0700 | [diff] [blame] | 538 | * fill the screen 1.5 times, ie. (screen width x screen height x 4 x 1.5) bytes. |
Adam Cohen | 311c79c | 2012-05-10 14:44:38 -0700 | [diff] [blame] | 539 | * |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 540 | * @param appWidgetId The AppWidget instance for which to set the RemoteViews. |
| 541 | * @param views The RemoteViews object to show. |
| 542 | */ |
| 543 | public void updateAppWidget(int appWidgetId, RemoteViews views) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 544 | if (mService == null) { |
| 545 | return; |
| 546 | } |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 547 | updateAppWidget(new int[] { appWidgetId }, views); |
| 548 | } |
| 549 | |
| 550 | /** |
Adam Cohen | 2dd2197 | 2010-08-15 18:20:04 -0700 | [diff] [blame] | 551 | * Perform an incremental update or command on the widget(s) specified by appWidgetIds. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 552 | * <p> |
Adam Cohen | 2dd2197 | 2010-08-15 18:20:04 -0700 | [diff] [blame] | 553 | * This update differs from {@link #updateAppWidget(int[], RemoteViews)} in that the |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 554 | * RemoteViews object which is passed is understood to be an incomplete representation of the |
Adam Cohen | fbe44b7 | 2012-09-19 20:36:23 -0700 | [diff] [blame] | 555 | * widget, and hence does not replace the cached representation of the widget. As of API |
| 556 | * level 17, the new properties set within the views objects will be appended to the cached |
| 557 | * representation of the widget, and hence will persist. |
Adam Cohen | 2dd2197 | 2010-08-15 18:20:04 -0700 | [diff] [blame] | 558 | * |
| 559 | * Use with {@link RemoteViews#showNext(int)}, {@link RemoteViews#showPrevious(int)}, |
| 560 | * {@link RemoteViews#setScrollPosition(int, int)} and similar commands. |
| 561 | * |
| 562 | * <p> |
| 563 | * It is okay to call this method both inside an {@link #ACTION_APPWIDGET_UPDATE} broadcast, |
| 564 | * and outside of the handler. |
| 565 | * This method will only work when called from the uid that owns the AppWidget provider. |
| 566 | * |
Winson Chung | 6611988 | 2012-10-11 14:26:25 -0700 | [diff] [blame] | 567 | * <p> |
| 568 | * This method will be ignored if a widget has not received a full update via |
| 569 | * {@link #updateAppWidget(int[], RemoteViews)}. |
| 570 | * |
Adam Cohen | 2dd2197 | 2010-08-15 18:20:04 -0700 | [diff] [blame] | 571 | * @param appWidgetIds The AppWidget instances for which to set the RemoteViews. |
| 572 | * @param views The RemoteViews object containing the incremental update / command. |
| 573 | */ |
| 574 | public void partiallyUpdateAppWidget(int[] appWidgetIds, RemoteViews views) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 575 | if (mService == null) { |
| 576 | return; |
| 577 | } |
Adam Cohen | 2dd2197 | 2010-08-15 18:20:04 -0700 | [diff] [blame] | 578 | try { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 579 | mService.partiallyUpdateAppWidgetIds(mPackageName, appWidgetIds, views); |
Adam Cohen | 2dd2197 | 2010-08-15 18:20:04 -0700 | [diff] [blame] | 580 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 581 | throw e.rethrowFromSystemServer(); |
Adam Cohen | 2dd2197 | 2010-08-15 18:20:04 -0700 | [diff] [blame] | 582 | } |
| 583 | } |
| 584 | |
| 585 | /** |
| 586 | * Perform an incremental update or command on the widget specified by appWidgetId. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 587 | * <p> |
Adam Cohen | 2dd2197 | 2010-08-15 18:20:04 -0700 | [diff] [blame] | 588 | * This update differs from {@link #updateAppWidget(int, RemoteViews)} in that the RemoteViews |
| 589 | * object which is passed is understood to be an incomplete representation of the widget, and |
| 590 | * hence is not cached by the AppWidgetService. Note that because these updates are not cached, |
| 591 | * any state that they modify that is not restored by restoreInstanceState will not persist in |
| 592 | * the case that the widgets are restored using the cached version in AppWidgetService. |
| 593 | * |
| 594 | * Use with {@link RemoteViews#showNext(int)}, {@link RemoteViews#showPrevious(int)}, |
| 595 | * {@link RemoteViews#setScrollPosition(int, int)} and similar commands. |
| 596 | * |
| 597 | * <p> |
| 598 | * It is okay to call this method both inside an {@link #ACTION_APPWIDGET_UPDATE} broadcast, |
| 599 | * and outside of the handler. |
| 600 | * This method will only work when called from the uid that owns the AppWidget provider. |
| 601 | * |
Winson Chung | 6611988 | 2012-10-11 14:26:25 -0700 | [diff] [blame] | 602 | * <p> |
| 603 | * This method will be ignored if a widget has not received a full update via |
| 604 | * {@link #updateAppWidget(int[], RemoteViews)}. |
| 605 | * |
Adam Cohen | 2dd2197 | 2010-08-15 18:20:04 -0700 | [diff] [blame] | 606 | * @param appWidgetId The AppWidget instance for which to set the RemoteViews. |
| 607 | * @param views The RemoteViews object containing the incremental update / command. |
| 608 | */ |
| 609 | public void partiallyUpdateAppWidget(int appWidgetId, RemoteViews views) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 610 | if (mService == null) { |
| 611 | return; |
| 612 | } |
Adam Cohen | 2dd2197 | 2010-08-15 18:20:04 -0700 | [diff] [blame] | 613 | partiallyUpdateAppWidget(new int[] { appWidgetId }, views); |
| 614 | } |
| 615 | |
| 616 | /** |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 617 | * Set the RemoteViews to use for all AppWidget instances for the supplied AppWidget provider. |
| 618 | * |
| 619 | * <p> |
| 620 | * It is okay to call this method both inside an {@link #ACTION_APPWIDGET_UPDATE} broadcast, |
| 621 | * and outside of the handler. |
| 622 | * This method will only work when called from the uid that owns the AppWidget provider. |
| 623 | * |
| 624 | * @param provider The {@link ComponentName} for the {@link |
| 625 | * android.content.BroadcastReceiver BroadcastReceiver} provider |
| 626 | * for your AppWidget. |
| 627 | * @param views The RemoteViews object to show. |
| 628 | */ |
| 629 | public void updateAppWidget(ComponentName provider, RemoteViews views) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 630 | if (mService == null) { |
| 631 | return; |
| 632 | } |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 633 | try { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 634 | mService.updateAppWidgetProvider(provider, views); |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 635 | } catch (RemoteException e) { |
| 636 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 637 | } |
| 638 | } |
| 639 | |
| 640 | /** |
Winson Chung | 499cb9f | 2010-07-16 11:18:17 -0700 | [diff] [blame] | 641 | * Notifies the specified collection view in all the specified AppWidget instances |
John Spurlock | 77624cd | 2013-06-03 09:47:01 -0400 | [diff] [blame] | 642 | * to invalidate their data. |
Winson Chung | 499cb9f | 2010-07-16 11:18:17 -0700 | [diff] [blame] | 643 | * |
John Spurlock | 77624cd | 2013-06-03 09:47:01 -0400 | [diff] [blame] | 644 | * @param appWidgetIds The AppWidget instances to notify of view data changes. |
Winson Chung | 499cb9f | 2010-07-16 11:18:17 -0700 | [diff] [blame] | 645 | * @param viewId The collection view id. |
| 646 | */ |
Winson Chung | 6394c0e | 2010-08-16 10:14:56 -0700 | [diff] [blame] | 647 | public void notifyAppWidgetViewDataChanged(int[] appWidgetIds, int viewId) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 648 | if (mService == null) { |
| 649 | return; |
| 650 | } |
Winson Chung | 499cb9f | 2010-07-16 11:18:17 -0700 | [diff] [blame] | 651 | try { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 652 | mService.notifyAppWidgetViewDataChanged(mPackageName, appWidgetIds, viewId); |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 653 | } catch (RemoteException e) { |
| 654 | throw e.rethrowFromSystemServer(); |
Winson Chung | 499cb9f | 2010-07-16 11:18:17 -0700 | [diff] [blame] | 655 | } |
| 656 | } |
| 657 | |
| 658 | /** |
John Spurlock | 77624cd | 2013-06-03 09:47:01 -0400 | [diff] [blame] | 659 | * Notifies the specified collection view in the specified AppWidget instance |
| 660 | * to invalidate its data. |
Winson Chung | 499cb9f | 2010-07-16 11:18:17 -0700 | [diff] [blame] | 661 | * |
John Spurlock | 77624cd | 2013-06-03 09:47:01 -0400 | [diff] [blame] | 662 | * @param appWidgetId The AppWidget instance to notify of view data changes. |
| 663 | * @param viewId The collection view id. |
Winson Chung | 499cb9f | 2010-07-16 11:18:17 -0700 | [diff] [blame] | 664 | */ |
Winson Chung | 6394c0e | 2010-08-16 10:14:56 -0700 | [diff] [blame] | 665 | public void notifyAppWidgetViewDataChanged(int appWidgetId, int viewId) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 666 | if (mService == null) { |
| 667 | return; |
| 668 | } |
Winson Chung | 6394c0e | 2010-08-16 10:14:56 -0700 | [diff] [blame] | 669 | notifyAppWidgetViewDataChanged(new int[] { appWidgetId }, viewId); |
Winson Chung | 499cb9f | 2010-07-16 11:18:17 -0700 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | /** |
Svetoslav | 8e1d299 | 2014-08-08 12:48:06 -0700 | [diff] [blame] | 673 | * Gets the AppWidget providers for the given user profile. User profile can only |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 674 | * be the current user or a profile of the current user. For example, the current |
| 675 | * user may have a corporate profile. In this case the parent user profile has a |
| 676 | * child profile, the corporate one. |
| 677 | * |
Svetoslav | 8e1d299 | 2014-08-08 12:48:06 -0700 | [diff] [blame] | 678 | * @param profile The profile for which to get providers. Passing null is equivaled |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 679 | * to passing only the current user handle. |
| 680 | * @return The intalled providers. |
| 681 | * |
| 682 | * @see android.os.Process#myUserHandle() |
| 683 | * @see android.os.UserManager#getUserProfiles() |
| 684 | */ |
Svetoslav | 8e1d299 | 2014-08-08 12:48:06 -0700 | [diff] [blame] | 685 | public List<AppWidgetProviderInfo> getInstalledProvidersForProfile(@Nullable UserHandle profile) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 686 | if (mService == null) { |
| 687 | return Collections.emptyList(); |
| 688 | } |
Svetoslav | 8e1d299 | 2014-08-08 12:48:06 -0700 | [diff] [blame] | 689 | return getInstalledProvidersForProfile(AppWidgetProviderInfo.WIDGET_CATEGORY_HOME_SCREEN, |
| 690 | profile); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | /** |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 694 | * Return a list of the AppWidget providers that are currently installed. |
| 695 | */ |
| 696 | public List<AppWidgetProviderInfo> getInstalledProviders() { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 697 | if (mService == null) { |
| 698 | return Collections.emptyList(); |
| 699 | } |
Svetoslav | 8e1d299 | 2014-08-08 12:48:06 -0700 | [diff] [blame] | 700 | return getInstalledProvidersForProfile(AppWidgetProviderInfo.WIDGET_CATEGORY_HOME_SCREEN, |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 701 | null); |
Adam Cohen | d9e5af3 | 2012-11-28 16:34:57 -0800 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | /** |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 705 | * Gets the AppWidget providers for the current user. |
Adam Cohen | d9e5af3 | 2012-11-28 16:34:57 -0800 | [diff] [blame] | 706 | * |
| 707 | * @param categoryFilter Will only return providers which register as any of the specified |
| 708 | * specified categories. See {@link AppWidgetProviderInfo#widgetCategory}. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 709 | * @return The intalled providers. |
| 710 | * |
| 711 | * @see android.os.Process#myUserHandle() |
| 712 | * @see android.os.UserManager#getUserProfiles() |
| 713 | * |
Adam Cohen | d9e5af3 | 2012-11-28 16:34:57 -0800 | [diff] [blame] | 714 | * @hide |
| 715 | */ |
| 716 | public List<AppWidgetProviderInfo> getInstalledProviders(int categoryFilter) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 717 | if (mService == null) { |
| 718 | return Collections.emptyList(); |
| 719 | } |
Svetoslav | 8e1d299 | 2014-08-08 12:48:06 -0700 | [diff] [blame] | 720 | return getInstalledProvidersForProfile(categoryFilter, null); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | /** |
Svetoslav | 8e1d299 | 2014-08-08 12:48:06 -0700 | [diff] [blame] | 724 | * Gets the AppWidget providers for the given user profile. User profile can only |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 725 | * be the current user or a profile of the current user. For example, the current |
| 726 | * user may have a corporate profile. In this case the parent user profile has a |
| 727 | * child profile, the corporate one. |
| 728 | * |
| 729 | * @param categoryFilter Will only return providers which register as any of the specified |
| 730 | * specified categories. See {@link AppWidgetProviderInfo#widgetCategory}. |
Svetoslav | 8e1d299 | 2014-08-08 12:48:06 -0700 | [diff] [blame] | 731 | * @param profile A profile of the current user which to be queried. The user |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 732 | * is itself also a profile. If null, the providers only for the current user |
| 733 | * are returned. |
| 734 | * @return The intalled providers. |
| 735 | * |
| 736 | * @see android.os.Process#myUserHandle() |
| 737 | * @see android.os.UserManager#getUserProfiles() |
| 738 | * |
| 739 | * @hide |
| 740 | */ |
Svetoslav | 8e1d299 | 2014-08-08 12:48:06 -0700 | [diff] [blame] | 741 | public List<AppWidgetProviderInfo> getInstalledProvidersForProfile(int categoryFilter, |
| 742 | UserHandle profile) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 743 | if (mService == null) { |
| 744 | return Collections.emptyList(); |
| 745 | } |
| 746 | |
Svetoslav | 8e1d299 | 2014-08-08 12:48:06 -0700 | [diff] [blame] | 747 | if (profile == null) { |
| 748 | profile = Process.myUserHandle(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 749 | } |
| 750 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 751 | try { |
Hyunyoung Song | ccf6c68 | 2015-06-17 15:23:31 -0700 | [diff] [blame] | 752 | ParceledListSlice<AppWidgetProviderInfo> providers = mService.getInstalledProvidersForProfile( |
Svetoslav | 8e1d299 | 2014-08-08 12:48:06 -0700 | [diff] [blame] | 753 | categoryFilter, profile.getIdentifier()); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 754 | if (providers == null) { |
| 755 | return Collections.emptyList(); |
| 756 | } |
Hyunyoung Song | ccf6c68 | 2015-06-17 15:23:31 -0700 | [diff] [blame] | 757 | for (AppWidgetProviderInfo info : providers.getList()) { |
Patrick Dubroy | 5d14091 | 2010-07-12 10:25:27 -0700 | [diff] [blame] | 758 | // Converting complex to dp. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 759 | convertSizesToPixels(info); |
Patrick Dubroy | 5d14091 | 2010-07-12 10:25:27 -0700 | [diff] [blame] | 760 | } |
Hyunyoung Song | ccf6c68 | 2015-06-17 15:23:31 -0700 | [diff] [blame] | 761 | return providers.getList(); |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 762 | } catch (RemoteException e) { |
| 763 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 764 | } |
| 765 | } |
| 766 | |
| 767 | /** |
| 768 | * Get the available info about the AppWidget. |
| 769 | * |
| 770 | * @return A appWidgetId. If the appWidgetId has not been bound to a provider yet, or |
| 771 | * you don't have access to that appWidgetId, null is returned. |
| 772 | */ |
| 773 | public AppWidgetProviderInfo getAppWidgetInfo(int appWidgetId) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 774 | if (mService == null) { |
| 775 | return null; |
| 776 | } |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 777 | try { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 778 | AppWidgetProviderInfo info = mService.getAppWidgetInfo(mPackageName, appWidgetId); |
Mitsuru Oshima | 8f25c42 | 2009-07-01 00:10:43 -0700 | [diff] [blame] | 779 | if (info != null) { |
| 780 | // Converting complex to dp. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 781 | convertSizesToPixels(info); |
Mitsuru Oshima | 8f25c42 | 2009-07-01 00:10:43 -0700 | [diff] [blame] | 782 | } |
| 783 | return info; |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 784 | } catch (RemoteException e) { |
| 785 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 786 | } |
| 787 | } |
| 788 | |
| 789 | /** |
| 790 | * Set the component for a given appWidgetId. |
| 791 | * |
Michael Jurka | 61a5b01 | 2012-04-13 10:39:45 -0700 | [diff] [blame] | 792 | * <p class="note">You need the BIND_APPWIDGET permission or the user must have enabled binding |
| 793 | * widgets always for your component. This method is used by the AppWidget picker and |
| 794 | * should not be used by other apps. |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 795 | * |
| 796 | * @param appWidgetId The AppWidget instance for which to set the RemoteViews. |
| 797 | * @param provider The {@link android.content.BroadcastReceiver} that will be the AppWidget |
| 798 | * provider for this AppWidget. |
Michael Jurka | 61a5b01 | 2012-04-13 10:39:45 -0700 | [diff] [blame] | 799 | * @hide |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 800 | */ |
| 801 | public void bindAppWidgetId(int appWidgetId, ComponentName provider) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 802 | if (mService == null) { |
| 803 | return; |
Adam Cohen | 0aa2d42 | 2012-09-07 17:37:26 -0700 | [diff] [blame] | 804 | } |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 805 | bindAppWidgetId(appWidgetId, provider, null); |
Adam Cohen | 0aa2d42 | 2012-09-07 17:37:26 -0700 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | /** |
| 809 | * Set the component for a given appWidgetId. |
| 810 | * |
| 811 | * <p class="note">You need the BIND_APPWIDGET permission or the user must have enabled binding |
| 812 | * widgets always for your component. This method is used by the AppWidget picker and |
| 813 | * should not be used by other apps. |
| 814 | * |
| 815 | * @param appWidgetId The AppWidget instance for which to set the RemoteViews. |
| 816 | * @param provider The {@link android.content.BroadcastReceiver} that will be the AppWidget |
| 817 | * provider for this AppWidget. |
| 818 | * @param options Bundle containing options for the AppWidget. See also |
| 819 | * {@link #updateAppWidgetOptions(int, Bundle)} |
| 820 | * |
| 821 | * @hide |
| 822 | */ |
| 823 | public void bindAppWidgetId(int appWidgetId, ComponentName provider, Bundle options) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 824 | if (mService == null) { |
| 825 | return; |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 826 | } |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 827 | bindAppWidgetIdIfAllowed(appWidgetId, Process.myUserHandle(), provider, options); |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | /** |
Michael Jurka | 61a5b01 | 2012-04-13 10:39:45 -0700 | [diff] [blame] | 831 | * Set the component for a given appWidgetId. |
| 832 | * |
| 833 | * <p class="note">You need the BIND_APPWIDGET permission or the user must have enabled binding |
| 834 | * widgets always for your component. Should be used by apps that host widgets; if this |
| 835 | * method returns false, call {@link #ACTION_APPWIDGET_BIND} to request permission to |
| 836 | * bind |
| 837 | * |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 838 | * @param appWidgetId The AppWidget id under which to bind the provider. |
Michael Jurka | 61a5b01 | 2012-04-13 10:39:45 -0700 | [diff] [blame] | 839 | * @param provider The {@link android.content.BroadcastReceiver} that will be the AppWidget |
| 840 | * provider for this AppWidget. |
| 841 | * @return true if this component has permission to bind the AppWidget |
| 842 | */ |
| 843 | public boolean bindAppWidgetIdIfAllowed(int appWidgetId, ComponentName provider) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 844 | if (mService == null) { |
Michael Jurka | 61a5b01 | 2012-04-13 10:39:45 -0700 | [diff] [blame] | 845 | return false; |
| 846 | } |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 847 | return bindAppWidgetIdIfAllowed(appWidgetId, UserHandle.myUserId(), provider, null); |
Adam Cohen | 0aa2d42 | 2012-09-07 17:37:26 -0700 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | /** |
| 851 | * Set the component for a given appWidgetId. |
| 852 | * |
| 853 | * <p class="note">You need the BIND_APPWIDGET permission or the user must have enabled binding |
| 854 | * widgets always for your component. Should be used by apps that host widgets; if this |
| 855 | * method returns false, call {@link #ACTION_APPWIDGET_BIND} to request permission to |
| 856 | * bind |
| 857 | * |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 858 | * @param appWidgetId The AppWidget id under which to bind the provider. |
Adam Cohen | 0aa2d42 | 2012-09-07 17:37:26 -0700 | [diff] [blame] | 859 | * @param provider The {@link android.content.BroadcastReceiver} that will be the AppWidget |
| 860 | * provider for this AppWidget. |
| 861 | * @param options Bundle containing options for the AppWidget. See also |
| 862 | * {@link #updateAppWidgetOptions(int, Bundle)} |
| 863 | * |
| 864 | * @return true if this component has permission to bind the AppWidget |
| 865 | */ |
| 866 | public boolean bindAppWidgetIdIfAllowed(int appWidgetId, ComponentName provider, |
| 867 | Bundle options) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 868 | if (mService == null) { |
| 869 | return false; |
| 870 | } |
| 871 | return bindAppWidgetIdIfAllowed(appWidgetId, UserHandle.myUserId(), provider, options); |
| 872 | } |
| 873 | |
| 874 | /** |
| 875 | * Set the provider for a given appWidgetId if the caller has a permission. |
| 876 | * <p> |
| 877 | * <strong>Note:</strong> You need the {@link android.Manifest.permission#BIND_APPWIDGET} |
| 878 | * permission or the user must have enabled binding widgets always for your component. |
| 879 | * Should be used by apps that host widgets. If this method returns false, call {@link |
| 880 | * #ACTION_APPWIDGET_BIND} to request permission to bind. |
| 881 | * </p> |
| 882 | * |
| 883 | * @param appWidgetId The AppWidget id under which to bind the provider. |
| 884 | * @param user The user id in which the provider resides. |
| 885 | * @param provider The component name of the provider. |
| 886 | * @param options An optional Bundle containing options for the AppWidget. |
| 887 | * |
| 888 | * @return true if this component has permission to bind the AppWidget |
| 889 | */ |
| 890 | public boolean bindAppWidgetIdIfAllowed(int appWidgetId, UserHandle user, |
| 891 | ComponentName provider, Bundle options) { |
| 892 | if (mService == null) { |
| 893 | return false; |
| 894 | } |
| 895 | return bindAppWidgetIdIfAllowed(appWidgetId, user.getIdentifier(), provider, options); |
| 896 | } |
| 897 | |
| 898 | /** |
| 899 | * Query if a given package was granted permission by the user to bind app widgets |
| 900 | * |
| 901 | * <p class="note">You need the MODIFY_APPWIDGET_BIND_PERMISSIONS permission |
| 902 | * |
| 903 | * @param packageName The package for which the permission is being queried |
| 904 | * @param userId The user id of the user under which the package runs. |
| 905 | * @return true if the package was granted permission by the user to bind app widgets |
| 906 | * @hide |
| 907 | */ |
| 908 | public boolean hasBindAppWidgetPermission(String packageName, int userId) { |
| 909 | if (mService == null) { |
Adam Cohen | 0aa2d42 | 2012-09-07 17:37:26 -0700 | [diff] [blame] | 910 | return false; |
| 911 | } |
| 912 | try { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 913 | return mService.hasBindAppWidgetPermission(packageName, userId); |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 914 | } catch (RemoteException e) { |
| 915 | throw e.rethrowFromSystemServer(); |
Michael Jurka | 61a5b01 | 2012-04-13 10:39:45 -0700 | [diff] [blame] | 916 | } |
| 917 | } |
| 918 | |
| 919 | /** |
| 920 | * Query if a given package was granted permission by the user to bind app widgets |
| 921 | * |
| 922 | * <p class="note">You need the MODIFY_APPWIDGET_BIND_PERMISSIONS permission |
| 923 | * |
| 924 | * @param packageName The package for which the permission is being queried |
| 925 | * @return true if the package was granted permission by the user to bind app widgets |
| 926 | * @hide |
| 927 | */ |
| 928 | public boolean hasBindAppWidgetPermission(String packageName) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 929 | if (mService == null) { |
| 930 | return false; |
| 931 | } |
Michael Jurka | 61a5b01 | 2012-04-13 10:39:45 -0700 | [diff] [blame] | 932 | try { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 933 | return mService.hasBindAppWidgetPermission(packageName, UserHandle.myUserId()); |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 934 | } catch (RemoteException e) { |
| 935 | throw e.rethrowFromSystemServer(); |
Michael Jurka | 61a5b01 | 2012-04-13 10:39:45 -0700 | [diff] [blame] | 936 | } |
| 937 | } |
| 938 | |
| 939 | /** |
| 940 | * Changes any user-granted permission for the given package to bind app widgets |
| 941 | * |
| 942 | * <p class="note">You need the MODIFY_APPWIDGET_BIND_PERMISSIONS permission |
| 943 | * |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 944 | * @param packageName The package whose permission is being changed |
| 945 | * @param permission Whether to give the package permission to bind widgets |
| 946 | * |
Michael Jurka | 61a5b01 | 2012-04-13 10:39:45 -0700 | [diff] [blame] | 947 | * @hide |
| 948 | */ |
| 949 | public void setBindAppWidgetPermission(String packageName, boolean permission) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 950 | if (mService == null) { |
| 951 | return; |
| 952 | } |
| 953 | setBindAppWidgetPermission(packageName, UserHandle.myUserId(), permission); |
| 954 | } |
| 955 | |
| 956 | /** |
| 957 | * Changes any user-granted permission for the given package to bind app widgets |
| 958 | * |
| 959 | * <p class="note">You need the MODIFY_APPWIDGET_BIND_PERMISSIONS permission |
| 960 | * |
| 961 | * @param packageName The package whose permission is being changed |
| 962 | * @param userId The user under which the package is running. |
| 963 | * @param permission Whether to give the package permission to bind widgets |
| 964 | * |
| 965 | * @hide |
| 966 | */ |
| 967 | public void setBindAppWidgetPermission(String packageName, int userId, boolean permission) { |
| 968 | if (mService == null) { |
| 969 | return; |
| 970 | } |
Michael Jurka | 61a5b01 | 2012-04-13 10:39:45 -0700 | [diff] [blame] | 971 | try { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 972 | mService.setBindAppWidgetPermission(packageName, userId, permission); |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 973 | } catch (RemoteException e) { |
| 974 | throw e.rethrowFromSystemServer(); |
Michael Jurka | 61a5b01 | 2012-04-13 10:39:45 -0700 | [diff] [blame] | 975 | } |
| 976 | } |
| 977 | |
| 978 | /** |
Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 979 | * Binds the RemoteViewsService for a given appWidgetId and intent. |
| 980 | * |
| 981 | * The appWidgetId specified must already be bound to the calling AppWidgetHost via |
| 982 | * {@link android.appwidget.AppWidgetManager#bindAppWidgetId AppWidgetManager.bindAppWidgetId()}. |
| 983 | * |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 984 | * @param packageName The package from which the binding is requested. |
Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 985 | * @param appWidgetId The AppWidget instance for which to bind the RemoteViewsService. |
| 986 | * @param intent The intent of the service which will be providing the data to the |
| 987 | * RemoteViewsAdapter. |
| 988 | * @param connection The callback interface to be notified when a connection is made or lost. |
| 989 | * @hide |
| 990 | */ |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 991 | public void bindRemoteViewsService(String packageName, int appWidgetId, Intent intent, |
| 992 | IBinder connection) { |
| 993 | if (mService == null) { |
| 994 | return; |
| 995 | } |
Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 996 | try { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 997 | mService.bindRemoteViewsService(packageName, appWidgetId, intent, connection); |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 998 | } catch (RemoteException e) { |
| 999 | throw e.rethrowFromSystemServer(); |
Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 1000 | } |
| 1001 | } |
| 1002 | |
| 1003 | /** |
| 1004 | * Unbinds the RemoteViewsService for a given appWidgetId and intent. |
| 1005 | * |
| 1006 | * The appWidgetId specified muse already be bound to the calling AppWidgetHost via |
| 1007 | * {@link android.appwidget.AppWidgetManager#bindAppWidgetId AppWidgetManager.bindAppWidgetId()}. |
| 1008 | * |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 1009 | * @param packageName The package from which the binding is requested. |
Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 1010 | * @param appWidgetId The AppWidget instance for which to bind the RemoteViewsService. |
| 1011 | * @param intent The intent of the service which will be providing the data to the |
| 1012 | * RemoteViewsAdapter. |
| 1013 | * @hide |
| 1014 | */ |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 1015 | public void unbindRemoteViewsService(String packageName, int appWidgetId, Intent intent) { |
| 1016 | if (mService == null) { |
| 1017 | return; |
| 1018 | } |
Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 1019 | try { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 1020 | mService.unbindRemoteViewsService(packageName, appWidgetId, intent); |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1021 | } catch (RemoteException e) { |
| 1022 | throw e.rethrowFromSystemServer(); |
Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | /** |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1027 | * Get the list of appWidgetIds that have been bound to the given AppWidget |
| 1028 | * provider. |
Christian Mehlmauer | 10c543d | 2010-06-25 19:27:04 +0200 | [diff] [blame] | 1029 | * |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1030 | * @param provider The {@link android.content.BroadcastReceiver} that is the |
| 1031 | * AppWidget provider to find appWidgetIds for. |
| 1032 | */ |
| 1033 | public int[] getAppWidgetIds(ComponentName provider) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 1034 | if (mService == null) { |
| 1035 | return new int[0]; |
| 1036 | } |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1037 | try { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 1038 | return mService.getAppWidgetIds(provider); |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1039 | } catch (RemoteException e) { |
| 1040 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1041 | } |
| 1042 | } |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1043 | |
Amith Yamasani | e4a8da8 | 2015-04-30 17:32:25 -0700 | [diff] [blame] | 1044 | /** |
| 1045 | * @hide |
| 1046 | */ |
| 1047 | public boolean isBoundWidgetPackage(String packageName, int userId) { |
| 1048 | if (mService == null) { |
| 1049 | return false; |
| 1050 | } |
| 1051 | try { |
| 1052 | return mService.isBoundWidgetPackage(packageName, userId); |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1053 | } catch (RemoteException e) { |
| 1054 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | e4a8da8 | 2015-04-30 17:32:25 -0700 | [diff] [blame] | 1055 | } |
| 1056 | } |
| 1057 | |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 1058 | private boolean bindAppWidgetIdIfAllowed(int appWidgetId, int profileId, |
| 1059 | ComponentName provider, Bundle options) { |
| 1060 | if (mService == null) { |
| 1061 | return false; |
| 1062 | } |
| 1063 | try { |
| 1064 | return mService.bindAppWidgetId(mPackageName, appWidgetId, |
| 1065 | profileId, provider, options); |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1066 | } catch (RemoteException e) { |
| 1067 | throw e.rethrowFromSystemServer(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 1068 | } |
| 1069 | } |
| 1070 | |
| 1071 | private void convertSizesToPixels(AppWidgetProviderInfo info) { |
| 1072 | // Converting complex to dp. |
| 1073 | info.minWidth = TypedValue.complexToDimensionPixelSize(info.minWidth, |
| 1074 | mDisplayMetrics); |
| 1075 | info.minHeight = TypedValue.complexToDimensionPixelSize(info.minHeight, |
| 1076 | mDisplayMetrics); |
| 1077 | info.minResizeWidth = TypedValue.complexToDimensionPixelSize(info.minResizeWidth, |
| 1078 | mDisplayMetrics); |
| 1079 | info.minResizeHeight = TypedValue.complexToDimensionPixelSize(info.minResizeHeight, |
| 1080 | mDisplayMetrics); |
| 1081 | } |
| 1082 | } |