tasks: find-sharedui-violation: Partition location

Allow for relocated partition directories in out, mainly for
devices which do not possess e.g. /product but must
distribute it in /system/product.

Use argparse to cope with increased argument count.

Test: Device without physical /product partition
      m out/target/product/<device>/shareduid_violation_modules.json
      -> Observe addition of violating apks from product
      partition in shareduid_violation_modules.json

Signed-off-by: Felix <google@ix5.org>
Change-Id: I2d7826b41fb5b924f15ae21a73178fa4eec6a879
This commit is contained in:
Felix 2020-05-31 01:17:34 +02:00 committed by Felix Elsner
parent 4f353b78a7
commit 3769a205b6
2 changed files with 44 additions and 15 deletions

View File

@ -28,5 +28,13 @@ $(shareduid_violation_modules_filename): $(INSTALLED_SYSTEMIMAGE_TARGET) \
$(shareduid_violation_modules_filename): $(find_shareduid_script)
$(shareduid_violation_modules_filename): $(AAPT2)
$(find_shareduid_script) $(PRODUCT_OUT) $(AAPT2) > $@
$(find_shareduid_script) \
--product_out $(PRODUCT_OUT) \
--aapt $(AAPT2) \
--copy_out_system $(TARGET_COPY_OUT_SYSTEM) \
--copy_out_vendor $(TARGET_COPY_OUT_VENDOR) \
--copy_out_product $(TARGET_COPY_OUT_PRODUCT) \
--copy_out_system_ext $(TARGET_COPY_OUT_SYSTEM_EXT) \
> $@
$(call dist-for-goals,droidcore,$(shareduid_violation_modules_filename))

View File

@ -14,19 +14,31 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
import argparse
import json
import os
import subprocess
from glob import glob
from collections import defaultdict
import sys
import json
if len(sys.argv) < 3:
product_out = os.environ["PRODUCT_OUT"]
aapt = "aapt2"
else:
product_out = sys.argv[1]
aapt = sys.argv[2]
from collections import defaultdict
from glob import glob
def parse_args():
"""Parse commandline arguments."""
parser = argparse.ArgumentParser(description='Find sharedUserId violators')
parser.add_argument('--product_out', help='PRODUCT_OUT directory',
default=os.environ.get("PRODUCT_OUT"))
parser.add_argument('--aapt', help='Path to aapt or aapt2',
default="aapt2")
parser.add_argument('--copy_out_system', help='TARGET_COPY_OUT_SYSTEM',
default="system")
parser.add_argument('--copy_out_vendor', help='TARGET_COPY_OUT_VENDOR',
default="vendor")
parser.add_argument('--copy_out_product', help='TARGET_COPY_OUT_PRODUCT',
default="product")
parser.add_argument('--copy_out_system_ext', help='TARGET_COPY_OUT_SYSTEM_EXT',
default="system_ext")
return parser.parse_args()
def execute(cmd):
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
@ -45,7 +57,6 @@ def extract_shared_uid(file):
else:
print(error_msg, file=sys.stderr)
sys.exit()
return None
for l in manifest.split('\n'):
if "sharedUserId" in l:
@ -53,18 +64,28 @@ def extract_shared_uid(file):
return None
partitions = ["system", "vendor", "product"]
args = parse_args()
product_out = args.product_out
aapt = args.aapt
partitions = (
("system", args.copy_out_system),
("vendor", args.copy_out_vendor),
("product", args.copy_out_product),
("system_ext", args.copy_out_system_ext),
)
shareduid_app_dict = defaultdict(list)
for p in partitions:
for f in glob(os.path.join(product_out, p, "*", "*", "*.apk")):
for part, location in partitions:
for f in glob(os.path.join(product_out, location, "*", "*", "*.apk")):
apk_file = os.path.basename(f)
shared_uid = extract_shared_uid(f)
if shared_uid is None:
continue
shareduid_app_dict[shared_uid].append((p, apk_file))
shareduid_app_dict[shared_uid].append((part, apk_file))
output = defaultdict(lambda: defaultdict(list))