diff options
author | John Spurlock <jspurlock@google.com> | 2014-04-25 18:19:06 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-04-25 18:19:06 +0000 |
commit | b22aabbbd2801db0be526a64badf2efa208f19f1 (patch) | |
tree | 66448c85315567c82ac93e472b03b30fdd192d56 /core/java/android | |
parent | 2be1f8c3f4d338c7b7c73bb642bc410ef27c8ee4 (diff) | |
parent | 7340fc8665ae3f9f1978f42aa0e5e1da85036158 (diff) | |
download | frameworks_base-b22aabbbd2801db0be526a64badf2efa208f19f1.zip frameworks_base-b22aabbbd2801db0be526a64badf2efa208f19f1.tar.gz frameworks_base-b22aabbbd2801db0be526a64badf2efa208f19f1.tar.bz2 |
Merge "Introduce condition provider services."
Diffstat (limited to 'core/java/android')
6 files changed, 323 insertions, 0 deletions
diff --git a/core/java/android/app/INotificationManager.aidl b/core/java/android/app/INotificationManager.aidl index 8681f5c..045fab1 100644 --- a/core/java/android/app/INotificationManager.aidl +++ b/core/java/android/app/INotificationManager.aidl @@ -22,6 +22,8 @@ import android.service.notification.StatusBarNotification; import android.app.Notification; import android.content.ComponentName; import android.content.Intent; +import android.service.notification.Condition; +import android.service.notification.IConditionProvider; import android.service.notification.INotificationListener; import android.service.notification.ZenModeConfig; @@ -53,4 +55,5 @@ interface INotificationManager ZenModeConfig getZenModeConfig(); boolean setZenModeConfig(in ZenModeConfig config); + void notifyCondition(in IConditionProvider provider, in Condition condition); }
\ No newline at end of file diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index 691317b..b578b48 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -723,6 +723,13 @@ public final class Settings { = "android.settings.NOTIFICATION_LISTENER_SETTINGS"; /** + * @hide + */ + @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) + public static final String ACTION_CONDITION_PROVIDER_SETTINGS + = "android.settings.ACTION_CONDITION_PROVIDER_SETTINGS"; + + /** * Activity Action: Show settings for video captioning. * <p> * In some cases, a matching Activity may not exist, so ensure you safeguard @@ -4516,6 +4523,11 @@ public final class Settings { */ public static final String ENABLED_NOTIFICATION_LISTENERS = "enabled_notification_listeners"; + /** + * @hide + */ + public static final String ENABLED_CONDITION_PROVIDERS = "enabled_condition_providers"; + /** @hide */ public static final String BAR_SERVICE_COMPONENT = "bar_service_component"; diff --git a/core/java/android/service/notification/Condition.aidl b/core/java/android/service/notification/Condition.aidl new file mode 100644 index 0000000..432852c --- /dev/null +++ b/core/java/android/service/notification/Condition.aidl @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2014, 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.service.notification; + +parcelable Condition; + diff --git a/core/java/android/service/notification/Condition.java b/core/java/android/service/notification/Condition.java new file mode 100644 index 0000000..cfd40f3 --- /dev/null +++ b/core/java/android/service/notification/Condition.java @@ -0,0 +1,119 @@ +/** + * Copyright (c) 2014, 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.service.notification; + +import android.net.Uri; +import android.os.Parcel; +import android.os.Parcelable; + +import java.util.Objects; + +/** + * Condition information from condition providers. + * + * @hide + */ +public class Condition implements Parcelable { + + public static final int FLAG_RELEVANT_NOW = 1 << 0; + public static final int FLAG_RELEVANT_ALWAYS = 1 << 1; + + public final Uri id; + public String caption; + public boolean state; + public int flags; + + + public Condition(Uri id, String caption, boolean state, int flags) { + if (id == null) throw new IllegalArgumentException("id is required"); + if (caption == null) throw new IllegalArgumentException("caption is required"); + this.id = id; + this.caption = caption; + this.state = state; + this.flags = flags; + } + + private Condition(Parcel source) { + id = Uri.CREATOR.createFromParcel(source); + caption = source.readString(); + state = source.readInt() == 1; + flags = source.readInt(); + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeParcelable(id, 0); + dest.writeString(caption); + dest.writeInt(state ? 1 : 0); + dest.writeInt(flags); + } + + @Override + public String toString() { + return new StringBuilder(Condition.class.getSimpleName()).append('[') + .append("id=").append(id) + .append(",caption=").append(caption) + .append(",state=").append(state) + .append(",flags=").append(flags) + .append(']').toString(); + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof Condition)) return false; + if (o == this) return true; + final Condition other = (Condition) o; + return Objects.equals(other.id, id) + && Objects.equals(other.caption, caption) + && other.state == state + && other.flags == flags; + } + + @Override + public int hashCode() { + return Objects.hash(id, caption, state, flags); + } + + @Override + public int describeContents() { + return 0; + } + + public Condition copy() { + final Parcel parcel = Parcel.obtain(); + try { + writeToParcel(parcel, 0); + parcel.setDataPosition(0); + return new Condition(parcel); + } finally { + parcel.recycle(); + } + } + + public static final Parcelable.Creator<Condition> CREATOR + = new Parcelable.Creator<Condition>() { + @Override + public Condition createFromParcel(Parcel source) { + return new Condition(source); + } + + @Override + public Condition[] newArray(int size) { + return new Condition[size]; + } + }; +} diff --git a/core/java/android/service/notification/ConditionProviderService.java b/core/java/android/service/notification/ConditionProviderService.java new file mode 100644 index 0000000..8777e50 --- /dev/null +++ b/core/java/android/service/notification/ConditionProviderService.java @@ -0,0 +1,141 @@ +/* + * Copyright (C) 2014 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.service.notification; + +import android.annotation.SdkConstant; +import android.app.INotificationManager; +import android.app.Service; +import android.content.Context; +import android.content.Intent; +import android.net.Uri; +import android.os.IBinder; +import android.os.ServiceManager; +import android.util.Log; + +/** + * A service that provides conditions about boolean state. + * <p>To extend this class, you must declare the service in your manifest file with + * the {@link android.Manifest.permission#BIND_CONDITION_PROVIDER_SERVICE} permission + * and include an intent filter with the {@link #SERVICE_INTERFACE} action. For example:</p> + * <pre> + * <service android:name=".MyConditionProvider" + * android:label="@string/service_name" + * android:permission="android.permission.BIND_CONDITION_PROVIDER_SERVICE"> + * <intent-filter> + * <action android:name="android.service.notification.ConditionProviderService" /> + * </intent-filter> + * </service></pre> + * + * @hide + */ +public abstract class ConditionProviderService extends Service { + private final String TAG = ConditionProviderService.class.getSimpleName() + + "[" + getClass().getSimpleName() + "]"; + + private Provider mProvider; + private INotificationManager mNoMan; + + /** + * The {@link Intent} that must be declared as handled by the service. + */ + @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION) + public static final String SERVICE_INTERFACE + = "android.service.notification.ConditionProviderService"; + + + abstract public Condition[] queryConditions(int relevance); + abstract public Condition[] getConditions(Uri[] conditionIds); + abstract public boolean subscribe(Uri conditionId); + abstract public boolean unsubscribe(Uri conditionId); + + private final INotificationManager getNotificationInterface() { + if (mNoMan == null) { + mNoMan = INotificationManager.Stub.asInterface( + ServiceManager.getService(Context.NOTIFICATION_SERVICE)); + } + return mNoMan; + } + + public final void notifyCondition(Condition condition) { + if (!isBound()) return; + try { + getNotificationInterface().notifyCondition(mProvider, condition); + } catch (android.os.RemoteException ex) { + Log.v(TAG, "Unable to contact notification manager", ex); + } + } + + @Override + public IBinder onBind(Intent intent) { + if (mProvider == null) { + mProvider = new Provider(); + } + return mProvider; + } + + private boolean isBound() { + if (mProvider == null) { + Log.w(TAG, "Condition provider service not yet bound."); + return false; + } + return true; + } + + private final class Provider extends IConditionProvider.Stub { + private final ConditionProviderService mService = ConditionProviderService.this; + + @Override + public Condition[] queryConditions(int relevance) { + try { + return mService.queryConditions(relevance); + } catch (Throwable t) { + Log.w(TAG, "Error running queryConditions", t); + return null; + } + } + + @Override + public Condition[] getConditions(Uri[] conditionIds) { + try { + return mService.getConditions(conditionIds); + } catch (Throwable t) { + Log.w(TAG, "Error running getConditions", t); + return null; + } + } + + @Override + public boolean subscribe(Uri conditionId) { + try { + return mService.subscribe(conditionId); + } catch (Throwable t) { + Log.w(TAG, "Error running subscribe", t); + return false; + } + } + + @Override + public boolean unsubscribe(Uri conditionId) { + try { + return mService.unsubscribe(conditionId); + } catch (Throwable t) { + Log.w(TAG, "Error running unsubscribe", t); + return false; + } + } + } +} diff --git a/core/java/android/service/notification/IConditionProvider.aidl b/core/java/android/service/notification/IConditionProvider.aidl new file mode 100644 index 0000000..cb582da --- /dev/null +++ b/core/java/android/service/notification/IConditionProvider.aidl @@ -0,0 +1,28 @@ +/** + * Copyright (c) 2014, 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.service.notification; + +import android.net.Uri; +import android.service.notification.Condition; + +/** @hide */ +interface IConditionProvider { + Condition[] queryConditions(int relevance); + Condition[] getConditions(in Uri[] conditionIds); + boolean subscribe(in Uri conditionId); + boolean unsubscribe(in Uri conditionId); +}
\ No newline at end of file |