PolicyManager.java revision 86f6786032b1a0380cf089aeeceef7e9d8982ef8
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
17package com.android.internal.policy;
18
19import android.content.Context;
20import android.view.FallbackEventHandler;
21import android.view.LayoutInflater;
22import android.view.Window;
23import android.view.WindowManagerPolicy;
24
25import com.android.internal.policy.IPolicy;
26
27/**
28 * {@hide}
29 */
30
31public final class PolicyManager {
32    private static final String POLICY_IMPL_CLASS_NAME =
33        "com.android.internal.policy.impl.Policy";
34
35    private static final IPolicy sPolicy;
36
37    static {
38        // Pull in the actual implementation of the policy at run-time
39        try {
40            Class policyClass = Class.forName(POLICY_IMPL_CLASS_NAME);
41            sPolicy = (IPolicy)policyClass.newInstance();
42        } catch (ClassNotFoundException ex) {
43            throw new RuntimeException(
44                    POLICY_IMPL_CLASS_NAME + " could not be loaded", ex);
45        } catch (InstantiationException ex) {
46            throw new RuntimeException(
47                    POLICY_IMPL_CLASS_NAME + " could not be instantiated", ex);
48        } catch (IllegalAccessException ex) {
49            throw new RuntimeException(
50                    POLICY_IMPL_CLASS_NAME + " could not be instantiated", ex);
51        }
52    }
53
54    // Cannot instantiate this class
55    private PolicyManager() {}
56
57    // The static methods to spawn new policy-specific objects
58    public static Window makeNewWindow(Context context) {
59        return sPolicy.makeNewWindow(context);
60    }
61
62    public static LayoutInflater makeNewLayoutInflater(Context context) {
63        return sPolicy.makeNewLayoutInflater(context);
64    }
65
66    public static WindowManagerPolicy makeNewWindowManager() {
67        return sPolicy.makeNewWindowManager();
68    }
69
70    public static FallbackEventHandler makeNewFallbackEventHandler(Context context) {
71        return sPolicy.makeNewFallbackEventHandler(context);
72    }
73}
74