Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[platform] - add unique hardware identifier as info label #10543

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
fa0fa86
[language] - new string for the hardware uuid (for showing it in syst…
Memphiz Sep 23, 2016
56519be
[ServiceBroker] - allow access to the platform object
Memphiz Sep 23, 2016
45ac902
[SystemInfo] - add hardware uuid to system info class
Memphiz Sep 23, 2016
695ef39
[GUIInfoManager] - make the hardware uuid accessible as gui infolabel
Memphiz Sep 23, 2016
3f51a69
[GUIWindowSystemInfo] - show hardware uuid in system info window
Memphiz Sep 23, 2016
b95bdce
[DarwinUtils] - added GetHardwareUUID method
Memphiz Sep 23, 2016
0e4f084
[droid/jni] - add Settings.Secure class with ANDROID_ID member
Memphiz Sep 24, 2016
cd6ab49
[SystemInfo] - removed useless ifdef
Memphiz Sep 25, 2016
1470374
[Platform] - changed override define to PLATFORM_OVERRIDE_CLASSPLATFO…
Memphiz Sep 25, 2016
8b33bab
[Platform] - added default implementation for getting a unique hardwa…
Memphiz Sep 25, 2016
bcc5db3
[PlatformDarwin] - added override to InitUniqueHardwareIdentifier wh…
Memphiz Sep 25, 2016
0866481
[PlatformAndroid] - added override to InitUniqueHardwareIdentifier by…
Memphiz Sep 25, 2016
f1b7d1b
[PlatformLinux] - added PlatformLinux override and implemented InitUn…
Memphiz Sep 25, 2016
019fb6b
[PlatformRbpi] - added PlatformRbpi override and implemented InitUniq…
Memphiz Sep 25, 2016
969af88
[PlatformWindows] - added PlatformWindows override and implemented In…
Memphiz Sep 25, 2016
45e6a67
[platforms] - removed the logging of uuid for privacy reasons
Memphiz Sep 26, 2016
0fc6ee8
[PlatformRbpi] - removed the fallback for uuid fetching - serialnumbe…
Memphiz Sep 26, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions Kodi.xcodeproj/project.pbxproj
Expand Up @@ -820,7 +820,7 @@
DF033D381946612400BFC82E /* AEDeviceEnumerationOSX.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DF033D361946612400BFC82E /* AEDeviceEnumerationOSX.cpp */; };
DF0ABB73183A94A30018445D /* Utf8Utils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DF0ABB71183A94A30018445D /* Utf8Utils.cpp */; };
DF0ABB74183A94A30018445D /* Utf8Utils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DF0ABB71183A94A30018445D /* Utf8Utils.cpp */; };
DF0D9F4D1D63931F006A7DBB /* Platform.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DF0D9F4B1D63931F006A7DBB /* Platform.cpp */; settings = {COMPILER_FLAGS = "-DPLATFORM_OVERRIDE"; }; };
DF0D9F4D1D63931F006A7DBB /* Platform.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DF0D9F4B1D63931F006A7DBB /* Platform.cpp */; settings = {COMPILER_FLAGS = "-DPLATFORM_OVERRIDE_CLASSPLATFORM"; }; };
DF0D9F511D63961B006A7DBB /* PlatformDarwinOSX.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DF0D9F501D63961B006A7DBB /* PlatformDarwinOSX.cpp */; };
DF0D9F551D639898006A7DBB /* PlatformDarwinIOS.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DF0D9F531D639893006A7DBB /* PlatformDarwinIOS.cpp */; };
DF0DF15C13A3ADA7008ED511 /* NFSDirectory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DF0DF15913A3ADA7008ED511 /* NFSDirectory.cpp */; };
Expand Down Expand Up @@ -977,7 +977,7 @@
DFA8157E16713B1200E4E597 /* WakeOnAccess.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DFA8157C16713B1200E4E597 /* WakeOnAccess.cpp */; };
DFAB049813F8376700B70BFB /* InertialScrollingHandler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DFAB049613F8376700B70BFB /* InertialScrollingHandler.cpp */; };
DFACDB891D6CAC33003BBB92 /* PlatformDarwin.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DF8E55951D5F1D7000FD2BA3 /* PlatformDarwin.cpp */; };
DFACDB8E1D6CAD06003BBB92 /* Platform.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DF0D9F4B1D63931F006A7DBB /* Platform.cpp */; settings = {COMPILER_FLAGS = "-DPLATFORM_OVERRIDE"; }; };
DFACDB8E1D6CAD06003BBB92 /* Platform.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DF0D9F4B1D63931F006A7DBB /* Platform.cpp */; settings = {COMPILER_FLAGS = "-DPLATFORM_OVERRIDE_CLASSPLATFORM"; }; };
DFAF6A4F16EBAE3800D6AE12 /* RssManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DFAF6A4D16EBAE3800D6AE12 /* RssManager.cpp */; };
DFB02DEA16629DBA00F37752 /* PyContext.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DFB02DE816629DBA00F37752 /* PyContext.cpp */; };
DFB0F472161B747500D744F4 /* AddonsOperations.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DFB0F470161B747500D744F4 /* AddonsOperations.cpp */; };
Expand Down
8 changes: 7 additions & 1 deletion addons/resource.language.en_gb/resources/strings.po
Expand Up @@ -5525,7 +5525,13 @@ msgctxt "#12395"
msgid "Battery level"
msgstr ""

#empty strings from id 12396 to 12599
#. Please don't translate this but simply use the english version!
#: xbmc/windows/GUIWindowSystemInfo.cpp

This comment was marked as spam.

msgctxt "#12396"
msgid "Hardware UUID"
msgstr ""

#empty strings from id 12397 to 12599

#: xbmc/guilib/WindowIDs.h
msgctxt "#12600"
Expand Down
2 changes: 2 additions & 0 deletions xbmc/GUIInfoManager.cpp
Expand Up @@ -1188,6 +1188,7 @@ const infomap system_labels[] = {{ "hasnetwork", SYSTEM_ETHERNET_LINK_ACT
{ "profileautologin", SYSTEM_PROFILEAUTOLOGIN },
{ "progressbar", SYSTEM_PROGRESS_BAR },
{ "batterylevel", SYSTEM_BATTERY_LEVEL },
{ "hardwareuuid", SYSTEM_HARDWARE_UUID },
{ "friendlyname", SYSTEM_FRIENDLY_NAME },
{ "alarmpos", SYSTEM_ALARM_POS },
{ "isinhibit", SYSTEM_ISINHIBIT },
Expand Down Expand Up @@ -6306,6 +6307,7 @@ std::string CGUIInfoManager::GetLabel(int info, int contextWindow, std::string *
case SYSTEM_UPTIME:
case SYSTEM_TOTALUPTIME:
case SYSTEM_BATTERY_LEVEL:
case SYSTEM_HARDWARE_UUID:
return g_sysinfo.GetInfo(info);
break;

Expand Down
5 changes: 5 additions & 0 deletions xbmc/ServiceBroker.cpp
Expand Up @@ -60,3 +60,8 @@ CDataCacheCore &CServiceBroker::GetDataCacheCore()
{
return g_application.m_ServiceManager->GetDataCacheCore();
}

CPlatform& CServiceBroker::GetPlatform()
{
return g_application.m_ServiceManager->GetPlatform();
}
2 changes: 2 additions & 0 deletions xbmc/ServiceBroker.h
Expand Up @@ -42,6 +42,7 @@ namespace PVR
class CContextMenuManager;
class XBPython;
class CDataCacheCore;
class CPlatform;

class CServiceBroker
{
Expand All @@ -54,4 +55,5 @@ class CServiceBroker
static ActiveAE::CActiveAEDSP& GetADSP();
static CContextMenuManager& GetContextMenuManager();
static CDataCacheCore& GetDataCacheCore();
static CPlatform& GetPlatform();
};
2 changes: 2 additions & 0 deletions xbmc/guiinfo/GUIInfoLabels.h
Expand Up @@ -424,6 +424,8 @@
#define SYSTEM_CAN_HIBERNATE 752
#define SYSTEM_CAN_REBOOT 753

#define SYSTEM_HARDWARE_UUID 754

#define SLIDESHOW_ISPAUSED 800
#define SLIDESHOW_ISRANDOM 801
#define SLIDESHOW_ISACTIVE 802
Expand Down
2 changes: 1 addition & 1 deletion xbmc/platform/CMakeLists.txt
Expand Up @@ -15,5 +15,5 @@ set(HEADERS MessagePrinter.h
core_add_library(platform_common)

if(OVERRIDES_CPP)
target_compile_definitions(${CORE_LIBRARY} PRIVATE -DPLATFORM_OVERRIDE)
target_compile_definitions(${CORE_LIBRARY} PRIVATE -DPLATFORM_OVERRIDE_CLASSPLATFORM)
endif()
2 changes: 1 addition & 1 deletion xbmc/platform/Makefile.in
Expand Up @@ -2,7 +2,7 @@

OVERRIDES = $(wildcard overrides/@CORE_SYSTEM_NAME@/*.cpp) $(wildcard overrides/@CORE_SYSTEM_VARIANT@/*.cpp)
ifneq ($(strip $(OVERRIDES)),)
CXXFLAGS += -DPLATFORM_OVERRIDE
CXXFLAGS += -DPLATFORM_OVERRIDE_CLASSPLATFORM
endif

SRCS = posix/MessagePrinter.cpp
Expand Down
33 changes: 27 additions & 6 deletions xbmc/platform/Platform.cpp
Expand Up @@ -18,10 +18,17 @@
*
*/

#include "system.h"
#include "Platform.h"
#include "Application.h"
#include "network/Network.h"
#include "utils/log.h"
#include "utils/md5.h"

const std::string CPlatform::NoValidUUID = "NOUUID";

// Override for platform ports
#if !defined(PLATFORM_OVERRIDE)
#if !defined(PLATFORM_OVERRIDE_CLASSPLATFORM)

CPlatform* CPlatform::CreateInstance()
{
Expand All @@ -34,16 +41,30 @@ CPlatform* CPlatform::CreateInstance()

CPlatform::CPlatform()
{

m_uuid = NoValidUUID;
}

CPlatform::~CPlatform()
void CPlatform::Init()
{

InitUniqueHardwareIdentifier();
}

void CPlatform::Init()
void CPlatform::InitUniqueHardwareIdentifier()
{
CNetworkInterface* iface = g_application.getNetwork().GetFirstConnectedInterface();
if (iface)
{
m_uuid = iface->GetMacAddress();
#if defined(_DEBUG)
CLog::Log(LOGDEBUG, "HardwareUUID (nomd5): %s", m_uuid.c_str());
#endif
m_uuid = XBMC::XBMC_MD5::GetMD5(m_uuid);
CLog::Log(LOGNOTICE, "HardwareUUID: %s", m_uuid.c_str());
}
}

std::string CPlatform::GetUniqueHardwareIdentifier()
{
// nothing for now
return m_uuid;
}

29 changes: 27 additions & 2 deletions xbmc/platform/Platform.h
Expand Up @@ -20,6 +20,7 @@
*
*/

#include <string>

/**\brief Class for the Platform object
*
Expand All @@ -39,7 +40,7 @@ class CPlatform
CPlatform();

/**\brief D'tor */
virtual ~CPlatform();
virtual ~CPlatform() = default;

/**\brief Called at an early stage of application startup
*
Expand All @@ -48,4 +49,28 @@ class CPlatform
*/
virtual void Init();

};

/**\brief Geter for the m_uuid member
*
*\return the m_uuid member
*/
std::string GetUniqueHardwareIdentifier();

/**\brief Called for initing the m_uuid member.
*
* This method should set m_uuid to a string which identifies the hardware we
* are running on. The underlaying source for this information could
* be a network mac address, hw serial number or other uuid that is provided
* by the underlaying operating system.
* The best identifiers are those that never change (not even during operating system upgrades).
* m_uuid should be filled the the MD5 Hash of the unique identifier!
*/
virtual void InitUniqueHardwareIdentifier();

// constants
static const std::string NoValidUUID;

protected:
std::string m_uuid;

};
2 changes: 2 additions & 0 deletions xbmc/platform/android/jni/CMakeLists.txt
Expand Up @@ -45,6 +45,7 @@ set(SOURCES Activity.cpp
PowerManager.cpp
Resources.cpp
ScanResult.cpp
SettingsSecure.cpp
StatFs.cpp
StorageManager.cpp
StorageVolume.cpp
Expand Down Expand Up @@ -112,6 +113,7 @@ set(HEADERS Activity.h
PowerManager.h
Resources.h
ScanResult.h
SettingsSecure.h
StatFs.h
Surface.h
SurfaceTexture.h
Expand Down
2 changes: 2 additions & 0 deletions xbmc/platform/android/jni/Context.cpp
Expand Up @@ -48,6 +48,7 @@
#include "DisplayMetrics.h"
#include "Intent.h"
#include "KeyEvent.h"
#include "SettingsSecure.h"

#include <android/native_activity.h>

Expand Down Expand Up @@ -91,6 +92,7 @@ void CJNIContext::PopulateStaticFields()
CJNIIntent::PopulateStaticFields();
CJNIKeyEvent::PopulateStaticFields();
CJNIViewInputDevice::PopulateStaticFields();
CJNISettingsSecure::PopulateStaticFields();
}

CJNIPackageManager CJNIContext::GetPackageManager()
Expand Down
1 change: 1 addition & 0 deletions xbmc/platform/android/jni/Makefile.in
Expand Up @@ -62,6 +62,7 @@ SRCS += DisplayMetrics.cpp
SRCS += KeyEvent.cpp
SRCS += InputManager.cpp
SRCS += Os.cpp
SRCS += SettingsSecure.cpp

LIB = jni.a

Expand Down
36 changes: 36 additions & 0 deletions xbmc/platform/android/jni/SettingsSecure.cpp
@@ -0,0 +1,36 @@
/*
* Copyright (C) 2016 Team Kodi
* http://kodi.tv
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY 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 Kodi; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/

#include "SettingsSecure.h"

using namespace jni;

std::string CJNISettingsSecure::ANDROID_ID;

void CJNISettingsSecure::PopulateStaticFields()
{
jhclass clazz = find_class("android/provider/Settings$Secure");
ANDROID_ID = (jcast<std::string>(get_static_field<jhstring>(clazz, "ANDROID_ID")));
}

std::string CJNISettingsSecure::getString(CJNIContentResolver resolver, std::string name)
{
return jcast<std::string>(call_static_method<jhstring>("android/provider/Settings$Secure", "getString", "(Landroid/content/ContentResolver;Ljava/lang/String;)Ljava/lang/String;", resolver.get_raw(), jcast<jhstring>(name)));
}
40 changes: 40 additions & 0 deletions xbmc/platform/android/jni/SettingsSecure.h
@@ -0,0 +1,40 @@
#pragma once
/*
* Copyright (C) 2016 Team Kodi
* http://kodi.tv
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY 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 Kodi; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/

#include "jutils/jutils-details.hpp"
#include "ContentResolver.h"
#include <string>

namespace jni
{

class CJNISettingsSecure
{
public:
static void PopulateStaticFields();
static std::string getString(CJNIContentResolver resolver, std::string name);

static std::string ANDROID_ID;

};

};

1 change: 1 addition & 0 deletions xbmc/platform/darwin/DarwinUtils.h
Expand Up @@ -58,5 +58,6 @@ class CDarwinUtils
static bool IsAliasShortcut(const std::string& path, bool isdirectory);
static void TranslateAliasShortcut(std::string& path);
static bool CreateAliasShortcut(const std::string& fromPath, const std::string& toPath);
static std::string GetHardwareUUID();
};

40 changes: 40 additions & 0 deletions xbmc/platform/darwin/DarwinUtils.mm
Expand Up @@ -26,6 +26,7 @@
#include "utils/log.h"
#include "utils/URIUtils.h"
#include "CompileInfo.h"
#include "platform/Platform.h"

#undef BOOL

Expand Down Expand Up @@ -750,4 +751,43 @@ bool CFStringRefToStringWithEncoding(CFStringRef source, std::string &destinatio
return ret;
}

std::string CDarwinUtils::GetHardwareUUID()
{
static std::string uuid = CPlatform::NoValidUUID;
if (uuid == CPlatform::NoValidUUID)
{
#if defined(TARGET_DARWIN_OSX)
io_registry_entry_t ioRegistryRoot = IORegistryEntryFromPath(kIOMasterPortDefault, "IOService:/");
CFStringRef uuidCf = (CFStringRef) IORegistryEntryCreateCFProperty(ioRegistryRoot, CFSTR(kIOPlatformUUIDKey), kCFAllocatorDefault, 0);
IOObjectRelease(ioRegistryRoot);
CFStringRefToString(uuidCf, uuid);
CFRelease(uuidCf);
#elif defined(TARGET_DARWIN_IOS)
NSString *nsuuid = nullptr;
// all info about identifiers can be found here:
// http://nshipster.com/uuid-udid-unique-identifier/
// apple doesn't want us to call uniqueIdentifier and deprecated it
// but as long as devices are responding to it - we will call it - because
// 1. we don't care about app store restrictions
// 2. the identifier is the better one and stays "more static"
if ([[UIDevice currentDevice] respondsToSelector:@selector(uniqueIdentifier)])
{
nsuuid = [[UIDevice currentDevice] performSelector:@selector(uniqueIdentifier)];

}// try the official way in case the inofficial way fails
else if([[UIDevice currentDevice] respondsToSelector:@selector(identifierForVendor)])
{
nsuuid = [[UIDevice currentDevice] identifierForVendor].UUIDString;
}

if (nsuuid != nullptr)
{
uuid = [nsuuid UTF8String];
}
#endif
}

return uuid;
}

#endif