Mathieu Chartier | d022b65 | 2018-03-23 21:57:02 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (C) 2018 The Android Open Source Project |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | set -e |
| 18 | |
Mathieu Chartier | d022b65 | 2018-03-23 21:57:02 -0700 | [diff] [blame] | 19 | # target_sdk_version: parsed from manifest |
Mathieu Chartier | d022b65 | 2018-03-23 21:57:02 -0700 | [diff] [blame] | 20 | # |
| 21 | # outputs |
| 22 | # class_loader_context_arg: final class loader conext arg |
| 23 | # stored_class_loader_context_arg: final stored class loader context arg |
| 24 | |
Colin Cross | 56199af | 2019-05-22 10:25:59 -0700 | [diff] [blame] | 25 | if [ -z "${target_sdk_version}" ]; then |
| 26 | echo "ERROR: target_sdk_version not set" |
| 27 | exit 2 |
| 28 | fi |
| 29 | |
Nicolas Geoffray | c04f312 | 2018-12-18 14:14:25 +0000 | [diff] [blame] | 30 | # The hidl.manager shared library has a dependency on hidl.base. We'll manually |
| 31 | # add that information to the class loader context if we see those libraries. |
| 32 | hidl_manager="android.hidl.manager-V1.0-java" |
| 33 | hidl_base="android.hidl.base-V1.0-java" |
Mathieu Chartier | d022b65 | 2018-03-23 21:57:02 -0700 | [diff] [blame] | 34 | |
Nicolas Geoffray | c04f312 | 2018-12-18 14:14:25 +0000 | [diff] [blame] | 35 | function add_to_contexts { |
| 36 | for i in $1; do |
| 37 | if [[ -z "${class_loader_context}" ]]; then |
| 38 | export class_loader_context="PCL[$i]" |
| 39 | else |
| 40 | export class_loader_context+="#PCL[$i]" |
| 41 | fi |
| 42 | if [[ $i == *"$hidl_manager"* ]]; then |
| 43 | export class_loader_context+="{PCL[${i/$hidl_manager/$hidl_base}]}" |
| 44 | fi |
| 45 | done |
| 46 | |
| 47 | for i in $2; do |
| 48 | if [[ -z "${stored_class_loader_context}" ]]; then |
| 49 | export stored_class_loader_context="PCL[$i]" |
| 50 | else |
| 51 | export stored_class_loader_context+="#PCL[$i]" |
| 52 | fi |
| 53 | if [[ $i == *"$hidl_manager"* ]]; then |
| 54 | export stored_class_loader_context+="{PCL[${i/$hidl_manager/$hidl_base}]}" |
| 55 | fi |
| 56 | done |
| 57 | } |
| 58 | |
| 59 | # The order below must match what the package manager also computes for |
| 60 | # class loader context. |
| 61 | |
Mathieu Chartier | d022b65 | 2018-03-23 21:57:02 -0700 | [diff] [blame] | 62 | if [[ "${target_sdk_version}" -lt "28" ]]; then |
Nicolas Geoffray | c04f312 | 2018-12-18 14:14:25 +0000 | [diff] [blame] | 63 | add_to_contexts "${conditional_host_libs_28}" "${conditional_target_libs_28}" |
Mathieu Chartier | d022b65 | 2018-03-23 21:57:02 -0700 | [diff] [blame] | 64 | fi |
| 65 | |
Nicolas Geoffray | c04f312 | 2018-12-18 14:14:25 +0000 | [diff] [blame] | 66 | if [[ "${target_sdk_version}" -lt "29" ]]; then |
| 67 | add_to_contexts "${conditional_host_libs_29}" "${conditional_target_libs_29}" |
| 68 | fi |
| 69 | |
| 70 | add_to_contexts "${dex_preopt_host_libraries}" "${dex_preopt_target_libraries}" |
| 71 | |
Mathieu Chartier | d022b65 | 2018-03-23 21:57:02 -0700 | [diff] [blame] | 72 | # Generate the actual context string. |
Nicolas Geoffray | c04f312 | 2018-12-18 14:14:25 +0000 | [diff] [blame] | 73 | export class_loader_context_arg="--class-loader-context=PCL[]{${class_loader_context}}" |
| 74 | export stored_class_loader_context_arg="--stored-class-loader-context=PCL[]{${stored_class_loader_context}}" |