blob: 794795a7b5759d53bf0b31f8242199a537f29ccc [file] [log] [blame]
Mathieu Chartierd022b652018-03-23 21:57:02 -07001#!/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
17set -e
18
Mathieu Chartierd022b652018-03-23 21:57:02 -070019# target_sdk_version: parsed from manifest
Mathieu Chartierd022b652018-03-23 21:57:02 -070020#
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 Cross56199af2019-05-22 10:25:59 -070025if [ -z "${target_sdk_version}" ]; then
26 echo "ERROR: target_sdk_version not set"
27 exit 2
28fi
29
Nicolas Geoffrayc04f3122018-12-18 14:14:25 +000030# 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.
32hidl_manager="android.hidl.manager-V1.0-java"
33hidl_base="android.hidl.base-V1.0-java"
Mathieu Chartierd022b652018-03-23 21:57:02 -070034
Nicolas Geoffrayc04f3122018-12-18 14:14:25 +000035function 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 Chartierd022b652018-03-23 21:57:02 -070062if [[ "${target_sdk_version}" -lt "28" ]]; then
Nicolas Geoffrayc04f3122018-12-18 14:14:25 +000063 add_to_contexts "${conditional_host_libs_28}" "${conditional_target_libs_28}"
Mathieu Chartierd022b652018-03-23 21:57:02 -070064fi
65
Nicolas Geoffrayc04f3122018-12-18 14:14:25 +000066if [[ "${target_sdk_version}" -lt "29" ]]; then
67 add_to_contexts "${conditional_host_libs_29}" "${conditional_target_libs_29}"
68fi
69
70add_to_contexts "${dex_preopt_host_libraries}" "${dex_preopt_target_libraries}"
71
Mathieu Chartierd022b652018-03-23 21:57:02 -070072# Generate the actual context string.
Nicolas Geoffrayc04f3122018-12-18 14:14:25 +000073export class_loader_context_arg="--class-loader-context=PCL[]{${class_loader_context}}"
74export stored_class_loader_context_arg="--stored-class-loader-context=PCL[]{${stored_class_loader_context}}"