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