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 | |
Nicolas Geoffray | c04f312 | 2018-12-18 14:14:25 +0000 | [diff] [blame] | 25 | # The hidl.manager shared library has a dependency on hidl.base. We'll manually |
| 26 | # add that information to the class loader context if we see those libraries. |
| 27 | hidl_manager="android.hidl.manager-V1.0-java" |
| 28 | hidl_base="android.hidl.base-V1.0-java" |
Mathieu Chartier | d022b65 | 2018-03-23 21:57:02 -0700 | [diff] [blame] | 29 | |
Nicolas Geoffray | c04f312 | 2018-12-18 14:14:25 +0000 | [diff] [blame] | 30 | function add_to_contexts { |
| 31 | for i in $1; do |
| 32 | if [[ -z "${class_loader_context}" ]]; then |
| 33 | export class_loader_context="PCL[$i]" |
| 34 | else |
| 35 | export class_loader_context+="#PCL[$i]" |
| 36 | fi |
| 37 | if [[ $i == *"$hidl_manager"* ]]; then |
| 38 | export class_loader_context+="{PCL[${i/$hidl_manager/$hidl_base}]}" |
| 39 | fi |
| 40 | done |
| 41 | |
| 42 | for i in $2; do |
| 43 | if [[ -z "${stored_class_loader_context}" ]]; then |
| 44 | export stored_class_loader_context="PCL[$i]" |
| 45 | else |
| 46 | export stored_class_loader_context+="#PCL[$i]" |
| 47 | fi |
| 48 | if [[ $i == *"$hidl_manager"* ]]; then |
| 49 | export stored_class_loader_context+="{PCL[${i/$hidl_manager/$hidl_base}]}" |
| 50 | fi |
| 51 | done |
| 52 | } |
| 53 | |
| 54 | # The order below must match what the package manager also computes for |
| 55 | # class loader context. |
| 56 | |
Mathieu Chartier | d022b65 | 2018-03-23 21:57:02 -0700 | [diff] [blame] | 57 | if [[ "${target_sdk_version}" -lt "28" ]]; then |
Nicolas Geoffray | c04f312 | 2018-12-18 14:14:25 +0000 | [diff] [blame] | 58 | add_to_contexts "${conditional_host_libs_28}" "${conditional_target_libs_28}" |
Mathieu Chartier | d022b65 | 2018-03-23 21:57:02 -0700 | [diff] [blame] | 59 | fi |
| 60 | |
Nicolas Geoffray | c04f312 | 2018-12-18 14:14:25 +0000 | [diff] [blame] | 61 | if [[ "${target_sdk_version}" -lt "29" ]]; then |
| 62 | add_to_contexts "${conditional_host_libs_29}" "${conditional_target_libs_29}" |
| 63 | fi |
| 64 | |
| 65 | add_to_contexts "${dex_preopt_host_libraries}" "${dex_preopt_target_libraries}" |
| 66 | |
Mathieu Chartier | d022b65 | 2018-03-23 21:57:02 -0700 | [diff] [blame] | 67 | # Generate the actual context string. |
Nicolas Geoffray | c04f312 | 2018-12-18 14:14:25 +0000 | [diff] [blame] | 68 | export class_loader_context_arg="--class-loader-context=PCL[]{${class_loader_context}}" |
| 69 | export stored_class_loader_context_arg="--stored-class-loader-context=PCL[]{${stored_class_loader_context}}" |