1 /*
2  * Copyright (C) 2007 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.database;
18 
19 import android.net.Uri;
20 
21 /**
22  * A specialization of {@link Observable} for {@link ContentObserver}
23  * that provides methods for sending notifications to a list of
24  * {@link ContentObserver} objects.
25  */
26 @android.ravenwood.annotation.RavenwoodKeepWholeClass
27 public class ContentObservable extends Observable<ContentObserver> {
28     // Even though the generic method defined in Observable would be perfectly
29     // fine on its own, we can't delete this overridden method because it would
30     // potentially break binary compatibility with existing applications.
31     @Override
registerObserver(ContentObserver observer)32     public void registerObserver(ContentObserver observer) {
33         super.registerObserver(observer);
34     }
35 
36     /**
37      * Invokes {@link ContentObserver#dispatchChange(boolean)} on each observer.
38      * <p>
39      * If <code>selfChange</code> is true, only delivers the notification
40      * to the observer if it has indicated that it wants to receive self-change
41      * notifications by implementing {@link ContentObserver#deliverSelfNotifications}
42      * to return true.
43      * </p>
44      *
45      * @param selfChange True if this is a self-change notification.
46      *
47      * @deprecated Use {@link #dispatchChange(boolean, Uri)} instead.
48      */
49     @Deprecated
dispatchChange(boolean selfChange)50     public void dispatchChange(boolean selfChange) {
51         dispatchChange(selfChange, null);
52     }
53 
54     /**
55      * Invokes {@link ContentObserver#dispatchChange(boolean, Uri)} on each observer.
56      * Includes the changed content Uri when available.
57      * <p>
58      * If <code>selfChange</code> is true, only delivers the notification
59      * to the observer if it has indicated that it wants to receive self-change
60      * notifications by implementing {@link ContentObserver#deliverSelfNotifications}
61      * to return true.
62      * </p>
63      *
64      * @param selfChange True if this is a self-change notification.
65      * @param uri The Uri of the changed content, or null if unknown.
66      */
dispatchChange(boolean selfChange, Uri uri)67     public void dispatchChange(boolean selfChange, Uri uri) {
68         synchronized(mObservers) {
69             for (ContentObserver observer : mObservers) {
70                 if (!selfChange || observer.deliverSelfNotifications()) {
71                     observer.dispatchChange(selfChange, uri);
72                 }
73             }
74         }
75     }
76 
77     /**
78      * Invokes {@link ContentObserver#onChange} on each observer.
79      *
80      * @param selfChange True if this is a self-change notification.
81      *
82      * @deprecated Use {@link #dispatchChange} instead.
83      */
84     @Deprecated
notifyChange(boolean selfChange)85     public void notifyChange(boolean selfChange) {
86         synchronized(mObservers) {
87             for (ContentObserver observer : mObservers) {
88                 observer.onChange(selfChange, null);
89             }
90         }
91     }
92 }
93