Listener in createNotificationChannel
Necessary for when this will eventually trigger an Activity. New unit test file for NotificationServiceManager. Test: runtest systemui-notification (cts tests in separate CL) Change-Id: I8f3e8e34ddcebb1acb9ddd84bffc68affb4b6e89
This commit is contained in:
@@ -2,21 +2,22 @@
|
||||
**
|
||||
** Copyright 2007, The Android Open Source Project
|
||||
**
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
** you may not use this file except in compliance with the License.
|
||||
** You may obtain a copy of the License at
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
** you may not use this file except in compliance with the License.
|
||||
** You may obtain a copy of the License at
|
||||
**
|
||||
** http://www.apache.org/licenses/LICENSE-2.0
|
||||
** http://www.apache.org/licenses/LICENSE-2.0
|
||||
**
|
||||
** Unless required by applicable law or agreed to in writing, software
|
||||
** distributed under the License is distributed on an "AS IS" BASIS,
|
||||
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
** See the License for the specific language governing permissions and
|
||||
** Unless required by applicable law or agreed to in writing, software
|
||||
** distributed under the License is distributed on an "AS IS" BASIS,
|
||||
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
** See the License for the specific language governing permissions and
|
||||
** limitations under the License.
|
||||
*/
|
||||
|
||||
package android.app;
|
||||
|
||||
import android.app.IOnNotificationChannelCreatedListener;
|
||||
import android.app.ITransientNotification;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
@@ -58,7 +59,8 @@ interface INotificationManager
|
||||
int getImportance(String pkg, int uid);
|
||||
int getPackageImportance(String pkg);
|
||||
|
||||
void createNotificationChannel(String pkg, in NotificationChannel channel);
|
||||
void createNotificationChannel(String pkg, in NotificationChannel channel,
|
||||
in IOnNotificationChannelCreatedListener listener);
|
||||
void updateNotificationChannelForPackage(String pkg, int uid, in NotificationChannel channel);
|
||||
NotificationChannel getNotificationChannel(String pkg, String channelId);
|
||||
NotificationChannel getNotificationChannelForPackage(String pkg, int uid, String channelId);
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
**
|
||||
** Copyright 2016, The Android Open Source Project
|
||||
**
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
** you may not use this file except in compliance with the License.
|
||||
** You may obtain a copy of the License at
|
||||
**
|
||||
** http://www.apache.org/licenses/LICENSE-2.0
|
||||
**
|
||||
** Unless required by applicable law or agreed to in writing, software
|
||||
** distributed under the License is distributed on an "AS IS" BASIS,
|
||||
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
** See the License for the specific language governing permissions and
|
||||
** limitations under the License.
|
||||
*/
|
||||
|
||||
package android.app;
|
||||
|
||||
import android.app.NotificationChannel;
|
||||
|
||||
/** {@hide} */
|
||||
oneway interface IOnNotificationChannelCreatedListener {
|
||||
void onNotificationChannelCreated(in NotificationChannel channel);
|
||||
}
|
||||
@@ -18,6 +18,7 @@ package android.app;
|
||||
|
||||
import android.annotation.IntDef;
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.SdkConstant;
|
||||
import android.annotation.TestApi;
|
||||
import android.app.Notification.Builder;
|
||||
@@ -30,6 +31,7 @@ import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.os.Looper;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.os.RemoteException;
|
||||
@@ -379,12 +381,42 @@ public class NotificationManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a notification channel that notifications can be posted to.
|
||||
* Listener passed to {@link NotificationManager#createNotificationChannel} to notify
|
||||
* caller of result.
|
||||
*/
|
||||
public void createNotificationChannel(NotificationChannel channel) {
|
||||
public interface OnNotificationChannelCreatedListener {
|
||||
/**
|
||||
* @param createdChannel NotificationChannel created by the system. Value is null iff an
|
||||
* exception was thrown during channel creation.
|
||||
*/
|
||||
public void onNotificationChannelCreated(NotificationChannel createdChannel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a notification channel that notifications can be posted to.
|
||||
*
|
||||
* @param channel the channel to attempt to create. Note that the created channel may differ
|
||||
* from this value.
|
||||
* @param listener Called when operation is finished.
|
||||
* @param handler The handler to invoke the listener on, or {@code null} to use the main
|
||||
* handler.
|
||||
*/
|
||||
public void createNotificationChannel(
|
||||
@NonNull NotificationChannel channel,
|
||||
@NonNull OnNotificationChannelCreatedListener listener,
|
||||
@Nullable Handler handler) {
|
||||
INotificationManager service = getService();
|
||||
try {
|
||||
service.createNotificationChannel(mContext.getPackageName(), channel);
|
||||
final Handler actualHandler =
|
||||
handler != null ? handler : new Handler(Looper.getMainLooper());
|
||||
service.createNotificationChannel(mContext.getPackageName(), channel,
|
||||
new IOnNotificationChannelCreatedListener.Stub() {
|
||||
@Override public void onNotificationChannelCreated(
|
||||
NotificationChannel channel) {
|
||||
actualHandler.post(
|
||||
() -> { listener.onNotificationChannelCreated(channel); });
|
||||
}
|
||||
});
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
@@ -583,7 +615,7 @@ public class NotificationManager
|
||||
* <p>
|
||||
* Callers can only update rules that they own. See {@link AutomaticZenRule#getOwner}.
|
||||
* @param id The id of the rule to update
|
||||
* @param automaticZenRule the rule to update.
|
||||
* @param automaticZenRule the rule to update.
|
||||
* @return Whether the rule was successfully updated.
|
||||
*/
|
||||
public boolean updateAutomaticZenRule(String id, AutomaticZenRule automaticZenRule) {
|
||||
|
||||
Reference in New Issue
Block a user