• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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 package com.android.wallpaper.module;
17 
18 import androidx.annotation.IntDef;
19 
20 
21 /**
22  * Provides updates on the status of packages (installed, updated, removed).
23  * Abstraction layer above Android's LauncherApps.
24  */
25 public interface PackageStatusNotifier {
26 
27     /**
28      * Possible app statuses.
29      */
30     @IntDef({
31             PackageStatus.ADDED,
32             PackageStatus.CHANGED,
33             PackageStatus.REMOVED
34     })
35     @interface PackageStatus {
36         int ADDED = 1;
37         int CHANGED = 2;
38         int REMOVED = 3;
39     }
40 
41     /**
42      * Interface to be notified when there's a package event.
43      */
44     interface Listener {
45         /**
46          * Called when a package status' change.
47          * @param packageName name of the package that changed
48          * @param status the new {@link PackageStatus} for that package
49          */
onPackageChanged(String packageName, @PackageStatus int status)50         void onPackageChanged(String packageName, @PackageStatus int status);
51     }
52 
53     /**
54      * Add a {@link Listener} to be notified of package events. Only packages that declare an
55      * Activity or Service responding to that Intent Action will trigger the Listener's callback,
56      * except for the case of PackageStatus#REMOVED which will be triggered for any removed package
57      * (since it will trigger after the package has been already removed)
58      * @param listener Callback to be notified of changes
59      * @param action Intent action to filter packages to be notified about
60      *              (except for REMOVED status)
61      */
addListener(Listener listener, String action)62     void addListener(Listener listener, String action);
63 
64     /**
65      * Unregister the given listener.
66      */
removeListener(Listener listener)67     void removeListener(Listener listener);
68 }
69