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 android.app.notification.legacy.cts; 17 18 import android.net.Uri; 19 import android.service.notification.Condition; 20 import android.service.notification.ConditionProviderService; 21 import android.util.Log; 22 23 public abstract class PollableConditionProviderService extends ConditionProviderService { 24 final static String TAG = "CtsCps"; 25 26 boolean isConnected; 27 boolean subscribed; 28 Uri conditionId; 29 30 @Override onConnected()31 public void onConnected() { 32 Log.d(TAG, getClass().getName() + " Connected"); 33 isConnected = true; 34 } 35 36 @Override onDestroy()37 public void onDestroy() { 38 Log.d(TAG, getClass().getName() + " Destroyed"); 39 isConnected = false; 40 super.onDestroy(); 41 } 42 43 @Override onSubscribe(Uri conditionId)44 public void onSubscribe(Uri conditionId) { 45 Log.d(TAG, getClass().getName() + " got subscribe"); 46 subscribed = true; 47 this.conditionId = conditionId; 48 notifyCondition(new Condition(conditionId, "", Condition.STATE_TRUE)); 49 } 50 51 @Override onUnsubscribe(Uri conditionId)52 public void onUnsubscribe(Uri conditionId) { 53 Log.d(TAG, getClass().getName() + " got unsubscribe"); 54 subscribed = false; 55 this.conditionId = null; 56 } 57 } 58