Automatically detect operating system version.

GitOrigin-RevId: d693799fdbfe4919da5a70c141709f2db93063d7
This commit is contained in:
levlam 2020-06-19 03:45:24 +03:00
parent 2172c71191
commit 0877d7f716
13 changed files with 18 additions and 22 deletions

View File

@ -291,7 +291,6 @@ class TdExample {
parameters->api_hash_ = "a3406de8d171bb422bb6ddf3bbd800e2";
parameters->system_language_code_ = "en";
parameters->device_model_ = "Desktop";
parameters->system_version_ = "Unknown";
parameters->application_version_ = "1.0";
parameters->enable_storage_optimizer_ = true;
send_query(td_api::make_object<td_api::setTdlibParameters>(std::move(parameters)),

View File

@ -80,7 +80,6 @@ namespace TdExample
parameters.ApiHash = "a3406de8d171bb422bb6ddf3bbd800e2";
parameters.SystemLanguageCode = "en";
parameters.DeviceModel = "Desktop";
parameters.SystemVersion = "Unknown";
parameters.ApplicationVersion = "1.0";
parameters.EnableStorageOptimizer = true;

View File

@ -107,7 +107,6 @@ public final class Example {
parameters.apiHash = "a3406de8d171bb422bb6ddf3bbd800e2";
parameters.systemLanguageCode = "en";
parameters.deviceModel = "Desktop";
parameters.systemVersion = "Unknown";
parameters.applicationVersion = "1.0";
parameters.enableStorageOptimizer = true;

View File

@ -106,7 +106,6 @@ while True:
'api_hash': 'a3406de8d171bb422bb6ddf3bbd800e2',
'system_language_code': 'en',
'device_model': 'Desktop',
'system_version': 'Linux',
'application_version': '1.0',
'enable_storage_optimizer': True}})

View File

@ -117,7 +117,6 @@ func updateAuthorizationState(authorizationState: Dictionary<String, Any>) {
"api_hash":"a3406de8d171bb422bb6ddf3bbd800e2",
"system_language_code":"en",
"device_model":"Desktop",
"system_version":"Unknown",
"application_version":"1.0",
"enable_storage_optimizer":true
]

View File

@ -43,7 +43,6 @@ namespace TdApp
parameters.ApiHash = "a3406de8d171bb422bb6ddf3bbd800e2";
parameters.SystemLanguageCode = "en";
parameters.DeviceModel = "Desktop";
parameters.SystemVersion = "Unknown";
parameters.ApplicationVersion = "1.0.0";
_client.Send(new TdApi.SetTdlibParameters(parameters), null);
_client.Send(new TdApi.CheckDatabaseEncryptionKey(), null);

View File

@ -34,7 +34,7 @@ ok = Ok;
//@api_hash Application identifier hash for Telegram API access, which can be obtained at https://my.telegram.org
//@system_language_code IETF language tag of the user's operating system language; must be non-empty
//@device_model Model of the device the application is being run on; must be non-empty
//@system_version Version of the operating system the application is being run on; must be non-empty
//@system_version Version of the operating system the application is being run on. If empty, the version is automatically detected by TDLib
//@application_version Application version; must be non-empty
//@enable_storage_optimizer If set to true, old files will automatically be deleted
//@ignore_file_names If set to true, original file names will be ignored. Otherwise, downloaded files will be saved under names as close as possible to the original name

View File

@ -118,6 +118,7 @@
#include "td/utils/port/IPAddress.h"
#include "td/utils/port/path.h"
#include "td/utils/port/SocketFd.h"
#include "td/utils/port/uname.h"
#include "td/utils/Random.h"
#include "td/utils/Slice.h"
#include "td/utils/Status.h"
@ -4676,7 +4677,7 @@ Status Td::set_parameters(td_api::object_ptr<td_api::tdlibParameters> parameters
return Status::Error(400, "Device model must be non-empty");
}
if (options_.system_version.empty()) {
return Status::Error(400, "System version must be non-empty");
options_.system_version = get_operating_system_version().str();
}
if (options_.application_version.empty()) {
return Status::Error(400, "Application version must be non-empty");

View File

@ -407,7 +407,6 @@ class CliClient final : public Actor {
parameters->api_hash_ = api_hash_;
parameters->system_language_code_ = "en";
parameters->device_model_ = "Desktop";
parameters->system_version_ = "Unknown";
parameters->application_version_ = "1.0";
send_request(td_api::make_object<td_api::setTdlibParameters>(std::move(parameters)));
break;
@ -4385,13 +4384,15 @@ void main(int argc, char **argv) {
return;
}
if (!res.ok().empty()) {
LOG(PLAIN) << "tg_cli: " << "Have unexpected non-option parameters";
LOG(PLAIN) << "tg_cli: "
<< "Have unexpected non-option parameters";
LOG(PLAIN) << options;
return;
}
if (api_id == 0 || api_hash.empty()) {
LOG(PLAIN) << "tg_cli: " << "You should provide some valid api_id and api_hash";
LOG(PLAIN) << "tg_cli: "
<< "You should provide some valid api_id and api_hash";
LOG(PLAIN) << options;
return;
}

View File

@ -22,13 +22,15 @@
namespace td {
Slice get_operating_system_name() {
Slice get_operating_system_version() {
static string result = []() -> string {
#if TD_PORT_POSIX
#if TD_ANDROID
char version[PROP_VALUE_MAX + 1];
int length = __system_property_get("ro.build.version.release", version);
return length <= 0 ? string("Android") : "Android " + string(version, length);
if (length > 0) {
return "Android " + string(version, length);
}
#else
utsname name;
int err = uname(&name);
@ -38,8 +40,8 @@ Slice get_operating_system_name() {
return os_name;
}
}
LOG(ERROR) << "Failed to identify OS name; use generic one";
#endif
LOG(ERROR) << "Failed to identify OS name; use generic one";
#if TD_DARWIN_IOS
return "iOS";

View File

@ -10,6 +10,6 @@
namespace td {
Slice get_operating_system_name();
Slice get_operating_system_version();
}

View File

@ -1103,10 +1103,9 @@ TEST(Misc, CancellationToken) {
}
TEST(Misc, uname) {
auto first_name = get_operating_system_name();
auto second_name = get_operating_system_name();
ASSERT_STREQ(first_name, second_name);
ASSERT_EQ(first_name.begin(), second_name.begin());
ASSERT_TRUE(!first_name.empty());
LOG(ERROR) << first_name;
auto first_version = get_operating_system_version();
auto second_version = get_operating_system_version();
ASSERT_STREQ(first_version, second_version);
ASSERT_EQ(first_version.begin(), second_version.begin());
ASSERT_TRUE(!first_version.empty());
}

View File

@ -231,7 +231,6 @@ class DoAuthentication : public Task {
parameters->api_hash_ = "a3406de8d171bb422bb6ddf3bbd800e2";
parameters->system_language_code_ = "en";
parameters->device_model_ = "Desktop";
parameters->system_version_ = "Unknown";
parameters->application_version_ = "tdclient-test";
parameters->ignore_file_names_ = false;
parameters->enable_storage_optimizer_ = true;