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

Commit 6549309f authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Merge cherrypicks of [4562103, 4560827, 4563998, 4563999, 4564000, 4564001,...

Merge cherrypicks of [4562103, 4560827, 4563998, 4563999, 4564000, 4564001, 4564351, 4564352, 4564333, 4564033, 4560455, 4564034, 4560674, 4560675, 4563620, 4561607, 4561062, 4561063] into pi-release

Change-Id: I8b6494e6539f685ea265cd74dfbfa88ab3cb289f
parents 009b816d 19c3315c
Loading
Loading
Loading
Loading
+20 −1
Original line number Diff line number Diff line
@@ -32,11 +32,30 @@ Chunk ChunkIterator::Next() {

  if (len_ != 0) {
    // Prepare the next chunk.
    if (VerifyNextChunkNonFatal()) {
      VerifyNextChunk();
    }
  }
  return Chunk(this_chunk);
}

// TODO(b/111401637) remove this and have full resource file verification
// Returns false if there was an error.
bool ChunkIterator::VerifyNextChunkNonFatal() {
  if (len_ < sizeof(ResChunk_header)) {
    last_error_ = "not enough space for header";
    last_error_was_fatal_ = false;
    return false;
  }
  const size_t size = dtohl(next_chunk_->size);
  if (size > len_) {
    last_error_ = "chunk size is bigger than given data";
    last_error_was_fatal_ = false;
    return false;
  }
  return true;
}

// Returns false if there was an error.
bool ChunkIterator::VerifyNextChunk() {
  const uintptr_t header_start = reinterpret_cast<uintptr_t>(next_chunk_);
+9 −3
Original line number Diff line number Diff line
@@ -560,8 +560,10 @@ std::unique_ptr<const LoadedPackage> LoadedPackage::Load(const Chunk& chunk,

  if (iter.HadError()) {
    LOG(ERROR) << iter.GetLastError();
    if (iter.HadFatalError()) {
      return {};
    }
  }

  // Flatten and construct the TypeSpecs.
  for (auto& entry : type_builder_map) {
@@ -641,8 +643,10 @@ bool LoadedArsc::LoadTable(const Chunk& chunk, const LoadedIdmap* loaded_idmap,

  if (iter.HadError()) {
    LOG(ERROR) << iter.GetLastError();
    if (iter.HadFatalError()) {
      return false;
    }
  }
  return true;
}

@@ -673,8 +677,10 @@ std::unique_ptr<const LoadedArsc> LoadedArsc::Load(const StringPiece& data,

  if (iter.HadError()) {
    LOG(ERROR) << iter.GetLastError();
    if (iter.HadFatalError()) {
      return {};
    }
  }

  // Need to force a move for mingw32.
  return std::move(loaded_arsc);
+9 −0
Original line number Diff line number Diff line
@@ -94,18 +94,27 @@ class ChunkIterator {

  Chunk Next();
  inline bool HasNext() const { return !HadError() && len_ != 0; };
  // Returns whether there was an error and processing should stop
  inline bool HadError() const { return last_error_ != nullptr; }
  inline std::string GetLastError() const { return last_error_; }
  // Returns whether there was an error and processing should stop. For legacy purposes,
  // some errors are considered "non fatal". Fatal errors stop processing new chunks and
  // throw away any chunks already processed. Non fatal errors also stop processing new
  // chunks, but, will retain and use any valid chunks already processed.
  inline bool HadFatalError() const { return HadError() && last_error_was_fatal_; }

 private:
  DISALLOW_COPY_AND_ASSIGN(ChunkIterator);

  // Returns false if there was an error.
  bool VerifyNextChunk();
  // Returns false if there was an error. For legacy purposes.
  bool VerifyNextChunkNonFatal();

  const ResChunk_header* next_chunk_;
  size_t len_;
  const char* last_error_;
  bool last_error_was_fatal_ = true;
};

}  // namespace android
+8 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.settingslib.fuelgauge;

import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
@@ -89,6 +90,13 @@ public class PowerWhitelistBackend {
        if (TextUtils.equals(pkg, defaultDialer)) {
            return true;
        }

        final DevicePolicyManager devicePolicyManager = mAppContext.getSystemService(
                DevicePolicyManager.class);
        if (devicePolicyManager.packageHasActiveAdmins(pkg)) {
            return true;
        }

        return false;
    }

+15 −2
Original line number Diff line number Diff line
@@ -21,8 +21,10 @@ import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;

import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
@@ -51,7 +53,8 @@ public class PowerWhitelistBackendTest {

    @Mock
    private IDeviceIdleController mDeviceIdleService;

    @Mock
    private DevicePolicyManager mDevicePolicyManager;
    private PowerWhitelistBackend mPowerWhitelistBackend;
    private ShadowPackageManager mPackageManager;
    private Context mContext;
@@ -59,7 +62,9 @@ public class PowerWhitelistBackendTest {
    @Before
    public void setUp() throws Exception {
        MockitoAnnotations.initMocks(this);
        mContext = RuntimeEnvironment.application;
        mContext = spy(RuntimeEnvironment.application);
        doReturn(mContext).when(mContext).getApplicationContext();
        doReturn(mDevicePolicyManager).when(mContext).getSystemService(DevicePolicyManager.class);
        doReturn(new String[] {}).when(mDeviceIdleService).getFullPowerWhitelist();
        doReturn(new String[] {}).when(mDeviceIdleService).getSystemPowerWhitelist();
        doReturn(new String[] {}).when(mDeviceIdleService).getSystemPowerWhitelistExceptIdle();
@@ -68,6 +73,7 @@ public class PowerWhitelistBackendTest {
        mPackageManager = Shadow.extract(mContext.getPackageManager());
        mPackageManager.setSystemFeature(PackageManager.FEATURE_TELEPHONY, true);


        mPowerWhitelistBackend = new PowerWhitelistBackend(mContext, mDeviceIdleService);
    }

@@ -122,6 +128,13 @@ public class PowerWhitelistBackendTest {
        assertThat(mPowerWhitelistBackend.isWhitelisted(testDialer)).isTrue();
    }

    @Test
    public void isWhitelisted_shouldWhitelistActiveDeviceAdminApp() {
        doReturn(true).when(mDevicePolicyManager).packageHasActiveAdmins(PACKAGE_ONE);

        assertThat(mPowerWhitelistBackend.isWhitelisted(PACKAGE_ONE)).isTrue();
    }

    @Test
    public void testIsSystemWhitelisted() throws Exception {
        doReturn(new String[] {PACKAGE_ONE}).when(mDeviceIdleService).getSystemPowerWhitelist();
Loading