Home | History | Annotate | Download | only in core
      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 
     19 # target_sdk_version: parsed from manifest
     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 
     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"
     29 
     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 
     57 if [[ "${target_sdk_version}" -lt "28" ]]; then
     58   add_to_contexts "${conditional_host_libs_28}" "${conditional_target_libs_28}"
     59 fi
     60 
     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 
     67 # Generate the actual context string.
     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}}"
     70