612b8a1d3fdc7c309184f4783f188d3ed0421a2e
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / android / runtime / src / org / xwalk / runtime / MixedContext.java
1 // Copyright (c) 2013 Intel Corporation. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.xwalk.runtime;
6
7 import android.content.Context;
8 import android.content.ContextWrapper;
9 import android.content.Intent;
10 import android.content.ServiceConnection;
11
12 /**
13  * MixedContext provides ApplicationContext for the contextImpl object
14  * created by Context.CreatePackageContext().
15  *
16  * For cross package usage, the library part need the possibility to
17  * get both the application's context and the library itself's context.
18  *
19  */
20 class MixedContext extends ContextWrapper {
21     private Context mActivityCtx;
22
23     public MixedContext(Context base, Context activity) {
24         super(base);
25         mActivityCtx = activity;
26     }
27
28     @Override
29     public Context getApplicationContext() {
30         return mActivityCtx.getApplicationContext();
31     }
32
33     @Override
34     public boolean bindService(Intent in, ServiceConnection conn, int flags) {
35         return getApplicationContext().bindService(in, conn, flags);
36     }
37
38     @Override
39     public void unbindService(ServiceConnection conn) {
40         getApplicationContext().unbindService(conn);
41     }
42
43     @Override
44     public Object getSystemService(String name) {
45         return mActivityCtx.getSystemService(name);
46     }
47 }