1 /* 2 * Copyright (C) 2014 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.res; 18 19 import com.android.layoutlib.bridge.impl.DelegateManager; 20 import com.android.tools.layoutlib.annotations.LayoutlibDelegate; 21 22 import android.util.SparseArray; 23 24 import libcore.util.NativeAllocationRegistry_Delegate; 25 26 /** 27 * Delegate used to provide implementation of a select few native methods of {@link AssetManager} 28 * <p/> 29 * Through the layoutlib_create tool, the original native methods of AssetManager have been replaced 30 * by calls to methods of the same name in this delegate class. 31 * 32 */ 33 public class AssetManager_Delegate { 34 35 // ---- delegate manager ---- 36 37 private static final DelegateManager<AssetManager_Delegate> sManager = 38 new DelegateManager<>(AssetManager_Delegate.class); 39 private static long sFinalizer = -1; 40 41 // ---- delegate methods. ---- 42 43 @LayoutlibDelegate nativeCreate()44 /*package*/ static long nativeCreate() { 45 AssetManager_Delegate delegate = new AssetManager_Delegate(); 46 return sManager.addNewDelegate(delegate); 47 } 48 49 @LayoutlibDelegate nativeDestroy(long ptr)50 /*package*/ static void nativeDestroy(long ptr) { 51 sManager.removeJavaReferenceFor(ptr); 52 } 53 54 @LayoutlibDelegate nativeThemeCreate(long ptr)55 /*package*/ static long nativeThemeCreate(long ptr) { 56 return Resources_Theme_Delegate.getDelegateManager() 57 .addNewDelegate(new Resources_Theme_Delegate()); 58 } 59 60 @LayoutlibDelegate nativeGetThemeFreeFunction()61 /*package*/ static long nativeGetThemeFreeFunction() { 62 synchronized (AssetManager_Delegate.class) { 63 if (sFinalizer == -1) { 64 sFinalizer = NativeAllocationRegistry_Delegate.createFinalizer( 65 Resources_Theme_Delegate.getDelegateManager()::removeJavaReferenceFor); 66 } 67 } 68 return sFinalizer; 69 } 70 71 @LayoutlibDelegate getAssignedPackageIdentifiers(AssetManager manager)72 /*package*/ static SparseArray<String> getAssignedPackageIdentifiers(AssetManager manager) { 73 return new SparseArray<>(); 74 } 75 76 @LayoutlibDelegate getAssignedPackageIdentifiers(AssetManager manager, boolean includeOverlays, boolean includeLoaders)77 /*package*/ static SparseArray<String> getAssignedPackageIdentifiers(AssetManager manager, 78 boolean includeOverlays, boolean includeLoaders) { 79 return new SparseArray<>(); 80 } 81 82 @LayoutlibDelegate createSystemAssetsInZygoteLocked(boolean reinitialize, String frameworkPath)83 /*package*/ static void createSystemAssetsInZygoteLocked(boolean reinitialize, 84 String frameworkPath) { } 85 } 86