blob: 8c7d327720a37b9db1431d06db94dad6db2bc4b6 [file] [log] [blame]
Amith Yamasani4f582632014-02-19 14:31:52 -08001/*
2 * Copyright (C) 2014 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
17package android.content.pm;
18
19import android.content.ComponentName;
20import android.content.Context;
21import android.content.Intent;
22import android.content.pm.ILauncherApps;
23import android.content.pm.IOnAppsChangedListener;
Kenny Guy77242752016-01-15 13:29:06 +000024import android.content.pm.PackageManager.ApplicationInfoFlags;
Amith Yamasanie781c812014-05-28 15:28:18 -070025import android.content.pm.PackageManager.NameNotFoundException;
Amith Yamasani4f582632014-02-19 14:31:52 -080026import android.graphics.Rect;
27import android.os.Bundle;
Kenny Guyb42c89b2014-07-28 19:20:07 +010028import android.os.Handler;
29import android.os.Looper;
30import android.os.Message;
Amith Yamasani4f582632014-02-19 14:31:52 -080031import android.os.RemoteException;
32import android.os.UserHandle;
Amith Yamasanie781c812014-05-28 15:28:18 -070033import android.os.UserManager;
Amith Yamasani4f582632014-02-19 14:31:52 -080034import android.util.Log;
35
36import java.util.ArrayList;
37import java.util.Collections;
38import java.util.List;
39
40/**
41 * Class for retrieving a list of launchable activities for the current user and any associated
42 * managed profiles. This is mainly for use by launchers. Apps can be queried for each user profile.
43 * Since the PackageManager will not deliver package broadcasts for other profiles, you can register
44 * for package changes here.
Amith Yamasanie781c812014-05-28 15:28:18 -070045 * <p>
46 * To watch for managed profiles being added or removed, register for the following broadcasts:
47 * {@link Intent#ACTION_MANAGED_PROFILE_ADDED} and {@link Intent#ACTION_MANAGED_PROFILE_REMOVED}.
48 * <p>
49 * You can retrieve the list of profiles associated with this user with
50 * {@link UserManager#getUserProfiles()}.
Amith Yamasani4f582632014-02-19 14:31:52 -080051 */
52public class LauncherApps {
53
54 static final String TAG = "LauncherApps";
55 static final boolean DEBUG = false;
56
57 private Context mContext;
58 private ILauncherApps mService;
Amith Yamasanie781c812014-05-28 15:28:18 -070059 private PackageManager mPm;
Amith Yamasani4f582632014-02-19 14:31:52 -080060
Kenny Guyb42c89b2014-07-28 19:20:07 +010061 private List<CallbackMessageHandler> mCallbacks
62 = new ArrayList<CallbackMessageHandler>();
Kenny Guyc01545372014-06-16 14:17:26 +010063
64 /**
65 * Callbacks for package changes to this and related managed profiles.
66 */
Kenny Guyf939dba2014-08-15 15:32:34 +010067 public static abstract class Callback {
Kenny Guyc01545372014-06-16 14:17:26 +010068 /**
69 * Indicates that a package was removed from the specified profile.
70 *
Kenny Guyb42c89b2014-07-28 19:20:07 +010071 * If a package is removed while being updated onPackageChanged will be
72 * called instead.
73 *
Kenny Guyc01545372014-06-16 14:17:26 +010074 * @param packageName The name of the package that was removed.
75 * @param user The UserHandle of the profile that generated the change.
76 */
77 abstract public void onPackageRemoved(String packageName, UserHandle user);
78
79 /**
80 * Indicates that a package was added to the specified profile.
81 *
Kenny Guyb42c89b2014-07-28 19:20:07 +010082 * If a package is added while being updated then onPackageChanged will be
83 * called instead.
84 *
Kenny Guyc01545372014-06-16 14:17:26 +010085 * @param packageName The name of the package that was added.
86 * @param user The UserHandle of the profile that generated the change.
87 */
88 abstract public void onPackageAdded(String packageName, UserHandle user);
89
90 /**
91 * Indicates that a package was modified in the specified profile.
Kenny Guyb42c89b2014-07-28 19:20:07 +010092 * This can happen, for example, when the package is updated or when
93 * one or more components are enabled or disabled.
Kenny Guyc01545372014-06-16 14:17:26 +010094 *
95 * @param packageName The name of the package that has changed.
96 * @param user The UserHandle of the profile that generated the change.
97 */
98 abstract public void onPackageChanged(String packageName, UserHandle user);
99
100 /**
101 * Indicates that one or more packages have become available. For
102 * example, this can happen when a removable storage card has
103 * reappeared.
104 *
105 * @param packageNames The names of the packages that have become
106 * available.
107 * @param user The UserHandle of the profile that generated the change.
108 * @param replacing Indicates whether these packages are replacing
109 * existing ones.
110 */
111 abstract public void onPackagesAvailable(String[] packageNames, UserHandle user,
112 boolean replacing);
113
114 /**
115 * Indicates that one or more packages have become unavailable. For
116 * example, this can happen when a removable storage card has been
117 * removed.
118 *
119 * @param packageNames The names of the packages that have become
120 * unavailable.
121 * @param user The UserHandle of the profile that generated the change.
122 * @param replacing Indicates whether the packages are about to be
123 * replaced with new versions.
124 */
125 abstract public void onPackagesUnavailable(String[] packageNames, UserHandle user,
126 boolean replacing);
Kenny Guy77242752016-01-15 13:29:06 +0000127
128 /**
129 * Indicates that one or more packages have been suspended. For
130 * example, this can happen when a Device Administrator suspends
131 * an applicaton.
132 *
133 * @param packageNames The names of the packages that have just been
134 * suspended.
135 * @param user The UserHandle of the profile that generated the change.
136 */
137 public void onPackagesSuspended(String[] packageNames, UserHandle user) {
138 }
139
140 /**
141 * Indicates that one or more packages have been unsuspended. For
142 * example, this can happen when a Device Administrator unsuspends
143 * an applicaton.
144 *
145 * @param packageNames The names of the packages that have just been
146 * unsuspended.
147 * @param user The UserHandle of the profile that generated the change.
148 */
149 public void onPackagesUnsuspended(String[] packageNames, UserHandle user) {
150 }
Kenny Guyc01545372014-06-16 14:17:26 +0100151 }
Amith Yamasani4f582632014-02-19 14:31:52 -0800152
Amith Yamasani4f582632014-02-19 14:31:52 -0800153 /** @hide */
154 public LauncherApps(Context context, ILauncherApps service) {
155 mContext = context;
156 mService = service;
Amith Yamasanie781c812014-05-28 15:28:18 -0700157 mPm = context.getPackageManager();
Amith Yamasani4f582632014-02-19 14:31:52 -0800158 }
159
160 /**
161 * Retrieves a list of launchable activities that match {@link Intent#ACTION_MAIN} and
162 * {@link Intent#CATEGORY_LAUNCHER}, for a specified user.
163 *
164 * @param packageName The specific package to query. If null, it checks all installed packages
165 * in the profile.
166 * @param user The UserHandle of the profile.
167 * @return List of launchable activities. Can be an empty list but will not be null.
168 */
169 public List<LauncherActivityInfo> getActivityList(String packageName, UserHandle user) {
Sunny Goyal6cbc2fe2015-11-24 09:34:20 -0800170 ParceledListSlice<ResolveInfo> activities = null;
Amith Yamasani4f582632014-02-19 14:31:52 -0800171 try {
172 activities = mService.getLauncherActivities(packageName, user);
173 } catch (RemoteException re) {
Sunny Goyal6cbc2fe2015-11-24 09:34:20 -0800174 throw new RuntimeException("Failed to call LauncherAppsService", re);
Amith Yamasani4f582632014-02-19 14:31:52 -0800175 }
176 if (activities == null) {
177 return Collections.EMPTY_LIST;
178 }
179 ArrayList<LauncherActivityInfo> lais = new ArrayList<LauncherActivityInfo>();
Sunny Goyal6cbc2fe2015-11-24 09:34:20 -0800180 for (ResolveInfo ri : activities.getList()) {
Sunny Goyal0736e202015-11-24 10:42:11 -0800181 LauncherActivityInfo lai = new LauncherActivityInfo(mContext, ri, user);
Amith Yamasani4f582632014-02-19 14:31:52 -0800182 if (DEBUG) {
183 Log.v(TAG, "Returning activity for profile " + user + " : "
184 + lai.getComponentName());
185 }
186 lais.add(lai);
187 }
188 return lais;
189 }
190
191 static ComponentName getComponentName(ResolveInfo ri) {
192 return new ComponentName(ri.activityInfo.packageName, ri.activityInfo.name);
193 }
194
195 /**
196 * Returns the activity info for a given intent and user handle, if it resolves. Otherwise it
197 * returns null.
198 *
199 * @param intent The intent to find a match for.
200 * @param user The profile to look in for a match.
201 * @return An activity info object if there is a match.
202 */
203 public LauncherActivityInfo resolveActivity(Intent intent, UserHandle user) {
204 try {
205 ResolveInfo ri = mService.resolveActivity(intent, user);
206 if (ri != null) {
Sunny Goyal0736e202015-11-24 10:42:11 -0800207 LauncherActivityInfo info = new LauncherActivityInfo(mContext, ri, user);
Amith Yamasani4f582632014-02-19 14:31:52 -0800208 return info;
209 }
210 } catch (RemoteException re) {
Sunny Goyal6cbc2fe2015-11-24 09:34:20 -0800211 throw new RuntimeException("Failed to call LauncherAppsService", re);
Amith Yamasani4f582632014-02-19 14:31:52 -0800212 }
213 return null;
214 }
215
216 /**
Kenny Guyf939dba2014-08-15 15:32:34 +0100217 * Starts a Main activity in the specified profile.
Amith Yamasani4f582632014-02-19 14:31:52 -0800218 *
219 * @param component The ComponentName of the activity to launch
Amith Yamasanie781c812014-05-28 15:28:18 -0700220 * @param user The UserHandle of the profile
221 * @param sourceBounds The Rect containing the source bounds of the clicked icon
222 * @param opts Options to pass to startActivity
223 */
Kenny Guyf939dba2014-08-15 15:32:34 +0100224 public void startMainActivity(ComponentName component, UserHandle user, Rect sourceBounds,
Amith Yamasanie781c812014-05-28 15:28:18 -0700225 Bundle opts) {
Amith Yamasani5abdbb62014-04-08 17:23:46 -0700226 if (DEBUG) {
Kenny Guyf939dba2014-08-15 15:32:34 +0100227 Log.i(TAG, "StartMainActivity " + component + " " + user.getIdentifier());
Amith Yamasani5abdbb62014-04-08 17:23:46 -0700228 }
Amith Yamasani4f582632014-02-19 14:31:52 -0800229 try {
230 mService.startActivityAsUser(component, sourceBounds, opts, user);
231 } catch (RemoteException re) {
232 // Oops!
233 }
234 }
235
236 /**
Kenny Guy466d2032014-07-23 12:23:35 +0100237 * Starts the settings activity to show the application details for a
238 * package in the specified profile.
239 *
240 * @param component The ComponentName of the package to launch settings for.
241 * @param user The UserHandle of the profile
242 * @param sourceBounds The Rect containing the source bounds of the clicked icon
243 * @param opts Options to pass to startActivity
244 */
Kenny Guyf939dba2014-08-15 15:32:34 +0100245 public void startAppDetailsActivity(ComponentName component, UserHandle user,
Kenny Guy466d2032014-07-23 12:23:35 +0100246 Rect sourceBounds, Bundle opts) {
247 try {
248 mService.showAppDetailsAsUser(component, sourceBounds, opts, user);
249 } catch (RemoteException re) {
250 // Oops!
251 }
252 }
253
254 /**
Kenny Guy53fa4ec2014-04-29 14:24:18 +0100255 * Checks if the package is installed and enabled for a profile.
256 *
257 * @param packageName The package to check.
258 * @param user The UserHandle of the profile.
259 *
260 * @return true if the package exists and is enabled.
261 */
Kenny Guyf939dba2014-08-15 15:32:34 +0100262 public boolean isPackageEnabled(String packageName, UserHandle user) {
Kenny Guy53fa4ec2014-04-29 14:24:18 +0100263 try {
264 return mService.isPackageEnabled(packageName, user);
265 } catch (RemoteException re) {
Sunny Goyal6cbc2fe2015-11-24 09:34:20 -0800266 throw new RuntimeException("Failed to call LauncherAppsService", re);
Kenny Guy53fa4ec2014-04-29 14:24:18 +0100267 }
268 }
269
270 /**
Kenny Guy77242752016-01-15 13:29:06 +0000271 * Retrieve all of the information we know about a particular package / application.
272 *
273 * @param packageName The package of the application
274 * @param flags Additional option flags {@link PackageManager#getApplicationInfo}
275 * @param user The UserHandle of the profile.
276 *
277 * @return An {@link ApplicationInfo} containing information about the package or
278 * null of the package isn't found.
279 */
280 public ApplicationInfo getApplicationInfo(String packageName, @ApplicationInfoFlags int flags,
281 UserHandle user) {
282 try {
283 return mService.getApplicationInfo(packageName, flags, user);
284 } catch (RemoteException re) {
285 throw new RuntimeException("Failed to call LauncherAppsService", re);
286 }
287 }
288
289 /**
Kenny Guy53fa4ec2014-04-29 14:24:18 +0100290 * Checks if the activity exists and it enabled for a profile.
291 *
292 * @param component The activity to check.
293 * @param user The UserHandle of the profile.
294 *
295 * @return true if the activity exists and is enabled.
296 */
Kenny Guyf939dba2014-08-15 15:32:34 +0100297 public boolean isActivityEnabled(ComponentName component, UserHandle user) {
Kenny Guy53fa4ec2014-04-29 14:24:18 +0100298 try {
299 return mService.isActivityEnabled(component, user);
300 } catch (RemoteException re) {
Sunny Goyal6cbc2fe2015-11-24 09:34:20 -0800301 throw new RuntimeException("Failed to call LauncherAppsService", re);
Kenny Guy53fa4ec2014-04-29 14:24:18 +0100302 }
303 }
304
305
306 /**
Kenny Guy10a574f2014-08-26 16:17:58 +0100307 * Registers a callback for changes to packages in current and managed profiles.
Kenny Guyc01545372014-06-16 14:17:26 +0100308 *
Kenny Guy10a574f2014-08-26 16:17:58 +0100309 * @param callback The callback to register.
Kenny Guyc01545372014-06-16 14:17:26 +0100310 */
Kenny Guy10a574f2014-08-26 16:17:58 +0100311 public void registerCallback(Callback callback) {
312 registerCallback(callback, null);
Kenny Guyb42c89b2014-07-28 19:20:07 +0100313 }
314
315 /**
Kenny Guy10a574f2014-08-26 16:17:58 +0100316 * Registers a callback for changes to packages in current and managed profiles.
Kenny Guyb42c89b2014-07-28 19:20:07 +0100317 *
Kenny Guy10a574f2014-08-26 16:17:58 +0100318 * @param callback The callback to register.
Kenny Guyb42c89b2014-07-28 19:20:07 +0100319 * @param handler that should be used to post callbacks on, may be null.
320 */
Kenny Guy10a574f2014-08-26 16:17:58 +0100321 public void registerCallback(Callback callback, Handler handler) {
Kenny Guyc01545372014-06-16 14:17:26 +0100322 synchronized (this) {
Kenny Guy172a2162015-06-19 17:21:28 +0100323 if (callback != null && findCallbackLocked(callback) < 0) {
Kenny Guyb42c89b2014-07-28 19:20:07 +0100324 boolean addedFirstCallback = mCallbacks.size() == 0;
325 addCallbackLocked(callback, handler);
326 if (addedFirstCallback) {
Kenny Guyc01545372014-06-16 14:17:26 +0100327 try {
328 mService.addOnAppsChangedListener(mAppsChangedListener);
329 } catch (RemoteException re) {
330 }
331 }
332 }
333 }
334 }
335
336 /**
Kenny Guy10a574f2014-08-26 16:17:58 +0100337 * Unregisters a callback that was previously registered.
Kenny Guyc01545372014-06-16 14:17:26 +0100338 *
Kenny Guy10a574f2014-08-26 16:17:58 +0100339 * @param callback The callback to unregister.
340 * @see #registerCallback(Callback)
Kenny Guyc01545372014-06-16 14:17:26 +0100341 */
Kenny Guy10a574f2014-08-26 16:17:58 +0100342 public void unregisterCallback(Callback callback) {
Kenny Guyc01545372014-06-16 14:17:26 +0100343 synchronized (this) {
Kenny Guyb42c89b2014-07-28 19:20:07 +0100344 removeCallbackLocked(callback);
Kenny Guy44b6dee2014-07-10 18:10:14 +0100345 if (mCallbacks.size() == 0) {
Amith Yamasanie781c812014-05-28 15:28:18 -0700346 try {
347 mService.removeOnAppsChangedListener(mAppsChangedListener);
348 } catch (RemoteException re) {
349 }
Amith Yamasani4f582632014-02-19 14:31:52 -0800350 }
351 }
352 }
353
Kenny Guy172a2162015-06-19 17:21:28 +0100354 /** @return position in mCallbacks for callback or -1 if not present. */
355 private int findCallbackLocked(Callback callback) {
Kenny Guyb42c89b2014-07-28 19:20:07 +0100356 if (callback == null) {
357 throw new IllegalArgumentException("Callback cannot be null");
358 }
359 final int size = mCallbacks.size();
360 for (int i = 0; i < size; ++i) {
361 if (mCallbacks.get(i).mCallback == callback) {
Kenny Guy172a2162015-06-19 17:21:28 +0100362 return i;
Kenny Guyb42c89b2014-07-28 19:20:07 +0100363 }
364 }
Kenny Guy172a2162015-06-19 17:21:28 +0100365 return -1;
366 }
367
368 private void removeCallbackLocked(Callback callback) {
369 int pos = findCallbackLocked(callback);
370 if (pos >= 0) {
371 mCallbacks.remove(pos);
372 }
Kenny Guyb42c89b2014-07-28 19:20:07 +0100373 }
374
Kenny Guyf939dba2014-08-15 15:32:34 +0100375 private void addCallbackLocked(Callback callback, Handler handler) {
Kenny Guyb42c89b2014-07-28 19:20:07 +0100376 // Remove if already present.
377 removeCallbackLocked(callback);
378 if (handler == null) {
379 handler = new Handler();
380 }
381 CallbackMessageHandler toAdd = new CallbackMessageHandler(handler.getLooper(), callback);
382 mCallbacks.add(toAdd);
383 }
384
Amith Yamasani4f582632014-02-19 14:31:52 -0800385 private IOnAppsChangedListener.Stub mAppsChangedListener = new IOnAppsChangedListener.Stub() {
386
387 @Override
Kenny Guyb42c89b2014-07-28 19:20:07 +0100388 public void onPackageRemoved(UserHandle user, String packageName)
389 throws RemoteException {
Amith Yamasani4f582632014-02-19 14:31:52 -0800390 if (DEBUG) {
391 Log.d(TAG, "onPackageRemoved " + user.getIdentifier() + "," + packageName);
392 }
393 synchronized (LauncherApps.this) {
Kenny Guyb42c89b2014-07-28 19:20:07 +0100394 for (CallbackMessageHandler callback : mCallbacks) {
395 callback.postOnPackageRemoved(packageName, user);
Kenny Guyc01545372014-06-16 14:17:26 +0100396 }
Amith Yamasani4f582632014-02-19 14:31:52 -0800397 }
398 }
399
400 @Override
401 public void onPackageChanged(UserHandle user, String packageName) throws RemoteException {
402 if (DEBUG) {
403 Log.d(TAG, "onPackageChanged " + user.getIdentifier() + "," + packageName);
404 }
405 synchronized (LauncherApps.this) {
Kenny Guyb42c89b2014-07-28 19:20:07 +0100406 for (CallbackMessageHandler callback : mCallbacks) {
407 callback.postOnPackageChanged(packageName, user);
Kenny Guyc01545372014-06-16 14:17:26 +0100408 }
Amith Yamasani4f582632014-02-19 14:31:52 -0800409 }
410 }
411
412 @Override
413 public void onPackageAdded(UserHandle user, String packageName) throws RemoteException {
414 if (DEBUG) {
415 Log.d(TAG, "onPackageAdded " + user.getIdentifier() + "," + packageName);
416 }
417 synchronized (LauncherApps.this) {
Kenny Guyb42c89b2014-07-28 19:20:07 +0100418 for (CallbackMessageHandler callback : mCallbacks) {
419 callback.postOnPackageAdded(packageName, user);
Kenny Guyc01545372014-06-16 14:17:26 +0100420 }
Amith Yamasani4f582632014-02-19 14:31:52 -0800421 }
422 }
423
424 @Override
425 public void onPackagesAvailable(UserHandle user, String[] packageNames, boolean replacing)
426 throws RemoteException {
427 if (DEBUG) {
428 Log.d(TAG, "onPackagesAvailable " + user.getIdentifier() + "," + packageNames);
429 }
430 synchronized (LauncherApps.this) {
Kenny Guyb42c89b2014-07-28 19:20:07 +0100431 for (CallbackMessageHandler callback : mCallbacks) {
432 callback.postOnPackagesAvailable(packageNames, user, replacing);
Kenny Guyc01545372014-06-16 14:17:26 +0100433 }
Amith Yamasani4f582632014-02-19 14:31:52 -0800434 }
435 }
436
437 @Override
438 public void onPackagesUnavailable(UserHandle user, String[] packageNames, boolean replacing)
439 throws RemoteException {
440 if (DEBUG) {
441 Log.d(TAG, "onPackagesUnavailable " + user.getIdentifier() + "," + packageNames);
442 }
443 synchronized (LauncherApps.this) {
Kenny Guyb42c89b2014-07-28 19:20:07 +0100444 for (CallbackMessageHandler callback : mCallbacks) {
445 callback.postOnPackagesUnavailable(packageNames, user, replacing);
Kenny Guyc01545372014-06-16 14:17:26 +0100446 }
Kenny Guy77242752016-01-15 13:29:06 +0000447 }
448 }
449
450 @Override
451 public void onPackagesSuspended(UserHandle user, String[] packageNames)
452 throws RemoteException {
453 if (DEBUG) {
454 Log.d(TAG, "onPackagesSuspended " + user.getIdentifier() + "," + packageNames);
455 }
456 synchronized (LauncherApps.this) {
457 for (CallbackMessageHandler callback : mCallbacks) {
458 callback.postOnPackagesSuspended(packageNames, user);
459 }
460 }
461 }
462
463 @Override
464 public void onPackagesUnsuspended(UserHandle user, String[] packageNames)
465 throws RemoteException {
466 if (DEBUG) {
467 Log.d(TAG, "onPackagesUnsuspended " + user.getIdentifier() + "," + packageNames);
468 }
469 synchronized (LauncherApps.this) {
470 for (CallbackMessageHandler callback : mCallbacks) {
471 callback.postOnPackagesUnsuspended(packageNames, user);
472 }
473 }
Amith Yamasani4f582632014-02-19 14:31:52 -0800474 }
475 };
Kenny Guyb42c89b2014-07-28 19:20:07 +0100476
477 private static class CallbackMessageHandler extends Handler {
478 private static final int MSG_ADDED = 1;
479 private static final int MSG_REMOVED = 2;
480 private static final int MSG_CHANGED = 3;
481 private static final int MSG_AVAILABLE = 4;
482 private static final int MSG_UNAVAILABLE = 5;
Kenny Guy77242752016-01-15 13:29:06 +0000483 private static final int MSG_SUSPENDED = 6;
484 private static final int MSG_UNSUSPENDED = 7;
Kenny Guyb42c89b2014-07-28 19:20:07 +0100485
Kenny Guyf939dba2014-08-15 15:32:34 +0100486 private LauncherApps.Callback mCallback;
Kenny Guyb42c89b2014-07-28 19:20:07 +0100487
488 private static class CallbackInfo {
489 String[] packageNames;
490 String packageName;
491 boolean replacing;
492 UserHandle user;
493 }
494
Kenny Guyf939dba2014-08-15 15:32:34 +0100495 public CallbackMessageHandler(Looper looper, LauncherApps.Callback callback) {
Kenny Guyb42c89b2014-07-28 19:20:07 +0100496 super(looper, null, true);
497 mCallback = callback;
498 }
499
500 @Override
501 public void handleMessage(Message msg) {
502 if (mCallback == null || !(msg.obj instanceof CallbackInfo)) {
503 return;
504 }
505 CallbackInfo info = (CallbackInfo) msg.obj;
506 switch (msg.what) {
507 case MSG_ADDED:
508 mCallback.onPackageAdded(info.packageName, info.user);
509 break;
510 case MSG_REMOVED:
511 mCallback.onPackageRemoved(info.packageName, info.user);
512 break;
513 case MSG_CHANGED:
514 mCallback.onPackageChanged(info.packageName, info.user);
515 break;
516 case MSG_AVAILABLE:
517 mCallback.onPackagesAvailable(info.packageNames, info.user, info.replacing);
518 break;
519 case MSG_UNAVAILABLE:
520 mCallback.onPackagesUnavailable(info.packageNames, info.user, info.replacing);
521 break;
Kenny Guy77242752016-01-15 13:29:06 +0000522 case MSG_SUSPENDED:
523 mCallback.onPackagesSuspended(info.packageNames, info.user);
524 break;
525 case MSG_UNSUSPENDED:
526 mCallback.onPackagesUnsuspended(info.packageNames, info.user);
527 break;
Kenny Guyb42c89b2014-07-28 19:20:07 +0100528 }
529 }
530
531 public void postOnPackageAdded(String packageName, UserHandle user) {
532 CallbackInfo info = new CallbackInfo();
533 info.packageName = packageName;
534 info.user = user;
535 obtainMessage(MSG_ADDED, info).sendToTarget();
536 }
537
538 public void postOnPackageRemoved(String packageName, UserHandle user) {
539 CallbackInfo info = new CallbackInfo();
540 info.packageName = packageName;
541 info.user = user;
542 obtainMessage(MSG_REMOVED, info).sendToTarget();
543 }
544
545 public void postOnPackageChanged(String packageName, UserHandle user) {
546 CallbackInfo info = new CallbackInfo();
547 info.packageName = packageName;
548 info.user = user;
549 obtainMessage(MSG_CHANGED, info).sendToTarget();
550 }
551
552 public void postOnPackagesAvailable(String[] packageNames, UserHandle user,
553 boolean replacing) {
554 CallbackInfo info = new CallbackInfo();
555 info.packageNames = packageNames;
556 info.replacing = replacing;
557 info.user = user;
558 obtainMessage(MSG_AVAILABLE, info).sendToTarget();
559 }
560
561 public void postOnPackagesUnavailable(String[] packageNames, UserHandle user,
562 boolean replacing) {
563 CallbackInfo info = new CallbackInfo();
564 info.packageNames = packageNames;
565 info.replacing = replacing;
566 info.user = user;
567 obtainMessage(MSG_UNAVAILABLE, info).sendToTarget();
568 }
Kenny Guy77242752016-01-15 13:29:06 +0000569
570 public void postOnPackagesSuspended(String[] packageNames, UserHandle user) {
571 CallbackInfo info = new CallbackInfo();
572 info.packageNames = packageNames;
573 info.user = user;
574 obtainMessage(MSG_SUSPENDED, info).sendToTarget();
575 }
576
577 public void postOnPackagesUnsuspended(String[] packageNames, UserHandle user) {
578 CallbackInfo info = new CallbackInfo();
579 info.packageNames = packageNames;
580 info.user = user;
581 obtainMessage(MSG_UNSUSPENDED, info).sendToTarget();
582 }
Kenny Guyb42c89b2014-07-28 19:20:07 +0100583 }
Amith Yamasani4f582632014-02-19 14:31:52 -0800584}