• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 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.content.cts;
18 
19 import android.app.Service;
20 import android.content.ContextWrapper;
21 import android.content.Intent;
22 import android.os.Binder;
23 import android.os.Handler;
24 import android.os.IBinder;
25 import android.os.Message;
26 
27 /**
28  * This class is used for {@link ContextWrapper}
29  *
30  * @see ContextWrapperTest
31  */
32 public class MockContextWrapperService extends Service {
33     private static boolean mHadCalledOnBind = false;
34     private static boolean mHadCalledOnUnbind = false;
35     private static boolean mHadCalledOnStart = false;
36     private static boolean mHadCalledOnDestory = false;
37     private static final int TEST_MESSAGE_WHAT = 1;
38 
39     private final IBinder mBinder = new Binder();
40 
41     private Handler mHandler = new Handler() {
42         public void handleMessage(Message msg) {
43             mHandler.sendMessageDelayed(mHandler.obtainMessage(TEST_MESSAGE_WHAT), 1000);
44         }
45     };
46 
47     @Override
onCreate()48     public void onCreate() {
49         mHandler.sendMessageDelayed(mHandler.obtainMessage(TEST_MESSAGE_WHAT), 1000);
50     }
51 
52     @Override
onDestroy()53     public void onDestroy() {
54         mHadCalledOnDestory = true;
55         mHandler.removeMessages(1);
56     }
57 
58     @Override
onUnbind(Intent intent)59     public boolean onUnbind(Intent intent) {
60         mHadCalledOnUnbind = true;
61         return true;
62     }
63 
64     @Override
onBind(Intent intent)65     public IBinder onBind(Intent intent) {
66         mHadCalledOnBind = true;
67         return mBinder;
68     }
69 
70     @Override
onStart(Intent intent, int startId)71     public void onStart(Intent intent, int startId) {
72         mHadCalledOnStart = true;
73     }
74 
reset()75     public static void reset() {
76         mHadCalledOnBind = false;
77         mHadCalledOnUnbind = false;
78         mHadCalledOnStart = false;
79         mHadCalledOnDestory = false;
80     }
81 
hadCalledOnBind()82     public static boolean hadCalledOnBind() {
83         return mHadCalledOnBind;
84     }
85 
hadCalledOnUnbind()86     public static boolean hadCalledOnUnbind() {
87         return mHadCalledOnUnbind;
88     }
89 
hadCalledOnStart()90     public static boolean hadCalledOnStart() {
91         return mHadCalledOnStart;
92     }
93 
hadCalledOnDestory()94     public static boolean hadCalledOnDestory() {
95         return mHadCalledOnDestory;
96     }
97 }
98 
99