Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a707013b authored by Ryan Mitchell's avatar Ryan Mitchell
Browse files

Add policies and enforce overlayable to header

If the fulfilled policies change without the contents of the target
and overlay APKs changing, the idmap for the overlay should be
regenerated. This change adds fulfilled policies and enforce
overlayable to the idmap header so that idmap2d can determine if the
polices or enforce overlayable changed from what was used to generate
the idmap.

Bug: 119328308
Test: idmap2_tests
Test: atest RegenerateIdmapTest

Change-Id: I96f970e82b5243be01b205ac2cb6ab249c6100bc
parent 57e977a5
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -168,13 +168,13 @@ cc_binary {
    ],
    ],
    host_supported: true,
    host_supported: true,
    srcs: [
    srcs: [
        "idmap2/CommandUtils.cpp",
        "idmap2/Create.cpp",
        "idmap2/Create.cpp",
        "idmap2/CreateMultiple.cpp",
        "idmap2/CreateMultiple.cpp",
        "idmap2/Dump.cpp",
        "idmap2/Dump.cpp",
        "idmap2/Lookup.cpp",
        "idmap2/Lookup.cpp",
        "idmap2/Main.cpp",
        "idmap2/Main.cpp",
        "idmap2/Scan.cpp",
        "idmap2/Scan.cpp",
        "idmap2/Verify.cpp",
    ],
    ],
    target: {
    target: {
        android: {
        android: {
+6 −16
Original line number Original line Diff line number Diff line
@@ -19,30 +19,19 @@
#include <string>
#include <string>
#include <vector>
#include <vector>


#include "idmap2/CommandLineOptions.h"
#include "idmap2/Idmap.h"
#include "idmap2/Idmap.h"
#include "idmap2/Result.h"
#include "idmap2/Result.h"
#include "idmap2/SysTrace.h"
#include "idmap2/SysTrace.h"


using android::idmap2::CommandLineOptions;
using android::idmap2::Error;
using android::idmap2::Error;
using android::idmap2::IdmapHeader;
using android::idmap2::IdmapHeader;
using android::idmap2::Result;
using android::idmap2::Result;
using android::idmap2::Unit;
using android::idmap2::Unit;


Result<Unit> Verify(const std::vector<std::string>& args) {
Result<Unit> Verify(const std::string& idmap_path, const std::string& target_path,
  SYSTRACE << "Verify " << args;
                    const std::string& overlay_path, uint32_t fulfilled_policies,
  std::string idmap_path;
                    bool enforce_overlayable) {

  SYSTRACE << "Verify " << idmap_path;
  const CommandLineOptions opts =
      CommandLineOptions("idmap2 verify")
          .MandatoryOption("--idmap-path", "input: path to idmap file to verify", &idmap_path);

  const auto opts_ok = opts.Parse(args);
  if (!opts_ok) {
    return opts_ok.GetError();
  }

  std::ifstream fin(idmap_path);
  std::ifstream fin(idmap_path);
  const std::unique_ptr<const IdmapHeader> header = IdmapHeader::FromBinaryStream(fin);
  const std::unique_ptr<const IdmapHeader> header = IdmapHeader::FromBinaryStream(fin);
  fin.close();
  fin.close();
@@ -50,7 +39,8 @@ Result<Unit> Verify(const std::vector<std::string>& args) {
    return Error("failed to parse idmap header");
    return Error("failed to parse idmap header");
  }
  }


  const auto header_ok = header->IsUpToDate();
  const auto header_ok = header->IsUpToDate(target_path.c_str(), overlay_path.c_str(),
                                            fulfilled_policies, enforce_overlayable);
  if (!header_ok) {
  if (!header_ok) {
    return Error(header_ok.GetError(), "idmap not up to date");
    return Error(header_ok.GetError(), "idmap not up to date");
  }
  }
+28 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef IDMAP2_IDMAP2_COMMAND_UTILS_H_
#define IDMAP2_IDMAP2_COMMAND_UTILS_H_

#include "idmap2/Result.h"

android::idmap2::Result<android::idmap2::Unit> Verify(const std::string& idmap_path,
                                                      const std::string& target_path,
                                                      const std::string& overlay_path,
                                                      uint32_t fulfilled_policies,
                                                      bool enforce_overlayable);

#endif  // IDMAP2_IDMAP2_COMMAND_UTILS_H_
+0 −1
Original line number Original line Diff line number Diff line
@@ -27,6 +27,5 @@ android::idmap2::Result<android::idmap2::Unit> CreateMultiple(const std::vector<
android::idmap2::Result<android::idmap2::Unit> Dump(const std::vector<std::string>& args);
android::idmap2::Result<android::idmap2::Unit> Dump(const std::vector<std::string>& args);
android::idmap2::Result<android::idmap2::Unit> Lookup(const std::vector<std::string>& args);
android::idmap2::Result<android::idmap2::Unit> Lookup(const std::vector<std::string>& args);
android::idmap2::Result<android::idmap2::Unit> Scan(const std::vector<std::string>& args);
android::idmap2::Result<android::idmap2::Unit> Scan(const std::vector<std::string>& args);
android::idmap2::Result<android::idmap2::Unit> Verify(const std::vector<std::string>& args);


#endif  // IDMAP2_IDMAP2_COMMANDS_H_
#endif  // IDMAP2_IDMAP2_COMMANDS_H_
+3 −1
Original line number Original line Diff line number Diff line
@@ -26,6 +26,7 @@
#include "android-base/stringprintf.h"
#include "android-base/stringprintf.h"
#include "idmap2/BinaryStreamVisitor.h"
#include "idmap2/BinaryStreamVisitor.h"
#include "idmap2/CommandLineOptions.h"
#include "idmap2/CommandLineOptions.h"
#include "idmap2/CommandUtils.h"
#include "idmap2/FileUtils.h"
#include "idmap2/FileUtils.h"
#include "idmap2/Idmap.h"
#include "idmap2/Idmap.h"
#include "idmap2/Policies.h"
#include "idmap2/Policies.h"
@@ -103,7 +104,8 @@ Result<Unit> CreateMultiple(const std::vector<std::string>& args) {
      continue;
      continue;
    }
    }


    if (!Verify(std::vector<std::string>({"--idmap-path", idmap_path}))) {
    if (!Verify(idmap_path, target_apk_path, overlay_apk_path, fulfilled_policies,
                !ignore_overlayable)) {
      const std::unique_ptr<const ApkAssets> overlay_apk = ApkAssets::Load(overlay_apk_path);
      const std::unique_ptr<const ApkAssets> overlay_apk = ApkAssets::Load(overlay_apk_path);
      if (!overlay_apk) {
      if (!overlay_apk) {
        LOG(WARNING) << "failed to load apk " << overlay_apk_path.c_str();
        LOG(WARNING) << "failed to load apk " << overlay_apk_path.c_str();
Loading