blob: 0fe6ffadd5efc41f3414496b215ed0c0e9ba51b6 [file] [log] [blame]
Jeongik Chaef26afd2019-02-07 15:51:47 +09001#!/usr/bin/env python3
2#
3# Copyright (C) 2019 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#
17import os
18import subprocess
19from glob import glob
20from collections import defaultdict
21import sys
22import json
23
24if len(sys.argv) < 3:
25 product_out = os.environ["PRODUCT_OUT"]
26 aapt = "aapt2"
27else:
28 product_out = sys.argv[1]
29 aapt = sys.argv[2]
30
31def make_aapt_cmd(file):
32 cmds = [aapt + ' dump ' + file + ' --file AndroidManifest.xml',
33 aapt + ' dump xmltree ' + file + ' --file AndroidManifest.xml']
34 return " || ".join(cmds)
35
36def extract_shared_uid(file):
37 manifest = subprocess.check_output(make_aapt_cmd(file), shell=True).decode().split('\n')
38 for l in manifest:
39 if "sharedUserId" in l:
40 return l.split('"')[-2]
41 return None
42
43
44partitions = ["system", "vendor", "product"]
45
46shareduid_app_dict = defaultdict(list)
47
48for p in partitions:
49 for f in glob(os.path.join(product_out, p, "*", "*", "*.apk")):
50 apk_file = os.path.basename(f)
51 shared_uid = extract_shared_uid(f)
52
53 if shared_uid is None:
54 continue
55 shareduid_app_dict[shared_uid].append((p, apk_file))
56
57
58output = defaultdict(lambda: defaultdict(list))
59
60for uid, app_infos in shareduid_app_dict.items():
61 partitions = {p for p, _ in app_infos}
62 if len(partitions) > 1:
63 for part in partitions:
64 output[uid][part].extend([a for p, a in app_infos if p == part])
65
66print(json.dumps(output, indent=2, sort_keys=True))