summaryrefslogtreecommitdiffstats
path: root/base/ios
diff options
context:
space:
mode:
authorqsr@chromium.org <qsr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-05 17:48:58 +0000
committerqsr@chromium.org <qsr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-05 17:48:58 +0000
commitaebcd0ddd09008a9285871f937012df8e94034f6 (patch)
treebace057e894e674fbf2aa3ecf12b3975f682c2c3 /base/ios
parent8a8c916b5ef34eff00574425986681c4d3341e7f (diff)
downloadchromium_src-aebcd0ddd09008a9285871f937012df8e94034f6.zip
chromium_src-aebcd0ddd09008a9285871f937012df8e94034f6.tar.gz
chromium_src-aebcd0ddd09008a9285871f937012df8e94034f6.tar.bz2
Adding utility method to test the version of the OS.
This had method to check which version of the OS the application is running. It also changes the ID generation mechanism to use identifierForVendor on iOS6 so that the ID are persisted across application reinstallation. BUG=None TEST=None R=stuartmorgan@chromium.org,mark@chromium.org Review URL: https://chromiumcodereview.appspot.com/11031066 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@160414 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/ios')
-rw-r--r--base/ios/OWNERS3
-rw-r--r--base/ios/device_util.mm8
-rw-r--r--base/ios/device_util_unittest.mm6
-rw-r--r--base/ios/ios_util.h26
-rw-r--r--base/ios/ios_util.mm42
5 files changed, 82 insertions, 3 deletions
diff --git a/base/ios/OWNERS b/base/ios/OWNERS
new file mode 100644
index 0000000..62564002
--- /dev/null
+++ b/base/ios/OWNERS
@@ -0,0 +1,3 @@
+qsr@chromium.org
+rohitrao@chromium.org
+stuartmorgan@chromium.org
diff --git a/base/ios/device_util.mm b/base/ios/device_util.mm
index 1d16de4b..e6801ab 100644
--- a/base/ios/device_util.mm
+++ b/base/ios/device_util.mm
@@ -5,7 +5,7 @@
#include "base/ios/device_util.h"
#include <CommonCrypto/CommonDigest.h>
-#import <Foundation/Foundation.h>
+#import <UIKit/UIKit.h>
#include <ifaddrs.h>
#include <net/if_dl.h>
@@ -13,6 +13,7 @@
#include <sys/socket.h>
#include <sys/sysctl.h>
+#include "base/ios/ios_util.h"
#include "base/logging.h"
#include "base/string_util.h"
#include "base/stringprintf.h"
@@ -103,7 +104,10 @@ std::string GetDeviceIdentifier(const char* salt) {
NSString* client_id = [defaults stringForKey:kClientIdPreferenceKey];
if (!client_id) {
- client_id = base::SysUTF8ToNSString(GetRandomId());
+ if (base::ios::IsRunningOnIOS6OrLater())
+ client_id = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
+ else
+ client_id = base::SysUTF8ToNSString(GetRandomId());
[defaults setObject:client_id forKey:kClientIdPreferenceKey];
[defaults synchronize];
}
diff --git a/base/ios/device_util_unittest.mm b/base/ios/device_util_unittest.mm
index 34c2d9c..b8ba10f 100644
--- a/base/ios/device_util_unittest.mm
+++ b/base/ios/device_util_unittest.mm
@@ -5,6 +5,7 @@
#import <Foundation/Foundation.h>
#include "base/ios/device_util.h"
+#include "base/ios/ios_util.h"
#include "base/sys_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/gtest_mac.h"
@@ -47,7 +48,10 @@ TEST_F(DeviceUtilTest, GetDeviceIdentifier) {
[defaults synchronize];
std::string new_default_id = ios::device_util::GetDeviceIdentifier(NULL);
- EXPECT_NE(default_id, new_default_id);
+ if (base::ios::IsRunningOnIOS6OrLater())
+ EXPECT_EQ(default_id, new_default_id);
+ else
+ EXPECT_NE(default_id, new_default_id);
}
} // namespace
diff --git a/base/ios/ios_util.h b/base/ios/ios_util.h
new file mode 100644
index 0000000..e8f9806
--- /dev/null
+++ b/base/ios/ios_util.h
@@ -0,0 +1,26 @@
+// Copyright 2012 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 BASE_IOS_IOS_UTIL_H_
+#define BASE_IOS_IOS_UTIL_H_
+
+#include "base/base_export.h"
+#include "base/basictypes.h"
+
+namespace base {
+namespace ios {
+
+// Returns whether the operation system is iOS 5 or later.
+BASE_EXPORT bool IsRunningOnIOS5OrLater();
+
+// Returns whether the operation system is iOS 6 or later.
+BASE_EXPORT bool IsRunningOnIOS6OrLater();
+
+// Returns whether the operation system is at the given version or later.
+BASE_EXPORT bool IsRunningOnOrLater(int32 major, int32 minor, int32 bug_fix);
+
+} // namespace ios
+} // namespace base
+
+#endif // BASE_IOS_IOS_UTIL_H_
diff --git a/base/ios/ios_util.mm b/base/ios/ios_util.mm
new file mode 100644
index 0000000..37f386d
--- /dev/null
+++ b/base/ios/ios_util.mm
@@ -0,0 +1,42 @@
+// Copyright 2012 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.
+
+#include "base/ios/ios_util.h"
+
+#include "base/sys_info.h"
+
+namespace {
+// Return a 3 elements array containing the major, minor and bug fix version of
+// the OS.
+const int32* OSVersionAsArray() {
+ int32* digits = new int32[3];
+ base::SysInfo::OperatingSystemVersionNumbers(
+ &digits[0], &digits[1], &digits[2]);
+ return digits;
+}
+} // namespace
+
+namespace base {
+namespace ios {
+
+bool IsRunningOnIOS5OrLater() {
+ return IsRunningOnOrLater(5, 0, 0);
+}
+
+bool IsRunningOnIOS6OrLater() {
+ return IsRunningOnOrLater(6, 0, 0);
+}
+
+bool IsRunningOnOrLater(int32 major, int32 minor, int32 bug_fix) {
+ static const int32* current_version = OSVersionAsArray();
+ int32 version[] = { major, minor, bug_fix };
+ for (size_t i = 0; i < arraysize(version); i++) {
+ if (current_version[i] != version[i])
+ return current_version[i] > version[i];
+ }
+ return true;
+}
+
+} // namespace ios
+} // namespace base