diff options
| author | Jesse Hall <jessehall@google.com> | 2016-12-12 12:53:02 -0800 |
|---|---|---|
| committer | Jesse Hall <jessehall@google.com> | 2017-01-14 19:19:28 -0800 |
| commit | 79bf392dc6d50436ff16693267c808fc115ab07c (patch) | |
| tree | 549256b5721be97a5fba77182554f90f50b48efd /core/java/android/os/GraphicsEnvironment.java | |
| parent | a959ccbc33c63213e857f91ea8b06ef5d4cc38f3 (diff) | |
Create GraphicsEnvironment for communicating with driver loaders
The GraphicsEnvironment class is given information during application
start, and makes it available to EGL/GLES/Vulkan loaders that don't
have easy access to the VM or to the application Context. Currently
only the driver path is handled, but the existing support for setting
library paths (for Vulkan extensions) and cache directory information
should move here.
Bug: 33531483
Change-Id: I4e4e7fb21f1bcc67122e9173514af5f18c063991
Merged-In: I5820d3d1301d5461e10706f551b268c54d4f8926
Diffstat (limited to 'core/java/android/os/GraphicsEnvironment.java')
| -rw-r--r-- | core/java/android/os/GraphicsEnvironment.java | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/core/java/android/os/GraphicsEnvironment.java b/core/java/android/os/GraphicsEnvironment.java new file mode 100644 index 000000000000..4b130ed1adc8 --- /dev/null +++ b/core/java/android/os/GraphicsEnvironment.java @@ -0,0 +1,95 @@ +/* + * Copyright 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.os; + +import android.content.Context; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; +import android.os.SystemProperties; +import android.util.Log; + +import dalvik.system.VMRuntime; + +import java.io.File; + +/** @hide */ +public final class GraphicsEnvironment { + + private static final boolean DEBUG = false; + private static final String TAG = "GraphicsEnvironment"; + private static final String PROPERTY_GFX_DRIVER = "ro.gfx.driver.0"; + + public static void setupGraphicsEnvironment(Context context) { + String driverPackageName = SystemProperties.get(PROPERTY_GFX_DRIVER); + if (driverPackageName == null || driverPackageName.isEmpty()) { + return; + } + // To minimize risk of driver updates crippling the device beyond user repair, never use an + // updated driver for privileged or non-updated system apps. Presumably pre-installed apps + // were tested thoroughly with the pre-installed driver. + ApplicationInfo ai = context.getApplicationInfo(); + if (ai.isPrivilegedApp() || (ai.isSystemApp() && !ai.isUpdatedSystemApp())) { + if (DEBUG) Log.v(TAG, "ignoring driver package for privileged/non-updated system app"); + return; + } + ApplicationInfo driverInfo; + try { + driverInfo = context.getPackageManager().getApplicationInfo(driverPackageName, + PackageManager.MATCH_SYSTEM_ONLY); + } catch (PackageManager.NameNotFoundException e) { + Log.w(TAG, "driver package '" + driverPackageName + "' not installed"); + return; + } + String abi = chooseAbi(driverInfo); + if (abi == null) { + if (DEBUG) { + // This is the normal case for the pre-installed empty driver package, don't spam + if (driverInfo.isUpdatedSystemApp()) { + Log.w(TAG, "updated driver package has no compatible native libraries"); + } + } + return; + } + + StringBuilder sb = new StringBuilder(); + sb.append(driverInfo.nativeLibraryDir) + .append(File.pathSeparator); + sb.append(driverInfo.sourceDir) + .append("!/lib/") + .append(abi); + String paths = sb.toString(); + + if (DEBUG) Log.v(TAG, "gfx driver package libs: " + paths); + setDriverPath(paths); + } + + private static String chooseAbi(ApplicationInfo ai) { + String isa = VMRuntime.getCurrentInstructionSet(); + if (ai.primaryCpuAbi != null && + isa.equals(VMRuntime.getInstructionSet(ai.primaryCpuAbi))) { + return ai.primaryCpuAbi; + } + if (ai.secondaryCpuAbi != null && + isa.equals(VMRuntime.getInstructionSet(ai.secondaryCpuAbi))) { + return ai.secondaryCpuAbi; + } + return null; + } + + private static native void setDriverPath(String path); + +} |
