forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Read assets out of APK on Android (flutter#4742)
- Loading branch information
Showing
21 changed files
with
242 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2018 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef FLUTTER_ASSETS_ASSET_PROVIDER_H_ | ||
#define FLUTTER_ASSETS_ASSET_PROVIDER_H_ | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include "lib/fxl/memory/ref_counted.h" | ||
|
||
namespace blink { | ||
|
||
class AssetProvider | ||
: public fxl::RefCountedThreadSafe<AssetProvider> | ||
{ | ||
public: | ||
virtual bool GetAsBuffer(const std::string& asset_name, | ||
std::vector<uint8_t>* data) = 0; | ||
virtual ~AssetProvider() = default; | ||
}; | ||
|
||
} // namespace blink | ||
#endif // FLUTTER_ASSETS_ASSET_PROVIDER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include <unistd.h> | ||
#include <algorithm> | ||
#include <sstream> | ||
|
||
#include "flutter/shell/platform/android/apk_asset_provider.h" | ||
#include "lib/fxl/logging.h" | ||
|
||
namespace blink { | ||
|
||
bool APKAssetProvider::GetAsBuffer(const std::string& asset_name, | ||
std::vector<uint8_t>* data) { | ||
std::stringstream ss; | ||
ss << directory_.c_str() << "/" << asset_name; | ||
AAsset* asset = AAssetManager_open(assetManager_, ss.str().c_str(), AASSET_MODE_BUFFER); | ||
if (!asset) { | ||
return false; | ||
} | ||
|
||
uint8_t* buffer = (uint8_t*)AAsset_getBuffer(asset); | ||
if (!buffer) { | ||
FXL_LOG(ERROR) << "Got null trying to acquire buffer for asset:" << asset; | ||
return false; | ||
} | ||
|
||
data->resize(AAsset_getLength(asset)); | ||
std::copy(buffer, buffer + data->size(), data->begin()); | ||
AAsset_close(asset); | ||
return true; | ||
} | ||
|
||
APKAssetProvider::~APKAssetProvider() {} | ||
|
||
APKAssetProvider::APKAssetProvider(JNIEnv* env, jobject jassetManager, std::string directory) | ||
: directory_(std::move(directory)) { | ||
assetManager_ = AAssetManager_fromJava(env, jassetManager); | ||
} | ||
|
||
} // namespace blink |
Oops, something went wrong.