forked from anbox/anbox
-
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.
Implement simple app database which maintains app information at runtime
This helps us to collect information about an app (title, ..) we can reuse for certain other things like window construction.
- Loading branch information
Showing
14 changed files
with
180 additions
and
53 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
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,58 @@ | ||
/* | ||
* Copyright (C) 2017 Simon Fels <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 3, as published | ||
* by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranties of | ||
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
* PURPOSE. See the GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#include "anbox/application/database.h" | ||
#include "anbox/application/launcher_storage.h" | ||
#include "anbox/config.h" | ||
#include "anbox/logger.h" | ||
|
||
namespace anbox { | ||
namespace application { | ||
const Database::Item Database::Unknown{}; | ||
|
||
Database::Database() : | ||
storage_(std::make_shared<LauncherStorage>(SystemConfiguration::instance().application_item_dir())) { | ||
storage_->reset(); | ||
} | ||
|
||
Database::~Database() {} | ||
|
||
void Database::store_or_update(const Item &item) { | ||
storage_->add_or_update(item); | ||
items_[item.package] = item; | ||
|
||
// We don't need to store the icon data anymore at this point as the | ||
// launcher is already stored it on the disk. | ||
items_[item.package].icon.clear(); | ||
} | ||
|
||
void Database::remove(const Item &item) { | ||
auto iter = items_.find(item.package); | ||
if (iter == items_.end()) | ||
return; | ||
storage_->remove(item); | ||
items_.erase(iter); | ||
} | ||
|
||
const Database::Item& Database::find_by_package(const std::string &package) const { | ||
auto iter = items_.find(package); | ||
if (iter == items_.end()) | ||
return Unknown; | ||
return iter->second; | ||
} | ||
} // namespace application | ||
} // namespace anbox |
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,58 @@ | ||
/* | ||
* Copyright (C) 2017 Simon Fels <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 3, as published | ||
* by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranties of | ||
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
* PURPOSE. See the GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#ifndef ANBOX_APPLICATION_DATABASE_H_ | ||
#define ANBOX_APPLICATION_DATABASE_H_ | ||
|
||
#include "anbox/android/intent.h" | ||
|
||
#include <string> | ||
#include <map> | ||
#include <memory> | ||
|
||
namespace anbox { | ||
namespace application { | ||
class LauncherStorage; | ||
class Database { | ||
public: | ||
struct Item { | ||
std::string name; | ||
std::string package; | ||
android::Intent launch_intent; | ||
std::vector<char> icon; | ||
|
||
bool valid() const { return package.length() > 0; } | ||
}; | ||
|
||
static const Item Unknown; | ||
|
||
Database(); | ||
~Database(); | ||
|
||
void store_or_update(const Item &item); | ||
void remove(const Item &item); | ||
|
||
const Item& find_by_package(const std::string &package) const; | ||
|
||
private: | ||
std::shared_ptr<LauncherStorage> storage_; | ||
std::map<std::string,Item> items_; | ||
}; | ||
} // namespace application | ||
} // namespace anbox | ||
|
||
#endif |
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
Oops, something went wrong.