Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
d9bbd2fb
Commit
d9bbd2fb
authored
Sep 28, 2016
by
Devon Carew
Committed by
GitHub
Sep 28, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make app ids more unique (#6113)
* make app ids more unique * in-line the uuid class
parent
6469872a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
100 additions
and
3 deletions
+100
-3
utils.dart
packages/flutter_tools/lib/src/base/utils.dart
+35
-0
daemon.dart
packages/flutter_tools/lib/src/commands/daemon.dart
+4
-3
utils_test.dart
packages/flutter_tools/test/utils_test.dart
+61
-0
No files found.
packages/flutter_tools/lib/src/base/utils.dart
View file @
d9bbd2fb
...
...
@@ -5,6 +5,7 @@
import
'dart:async'
;
import
'dart:convert'
;
import
'dart:io'
;
import
'dart:math'
show
Random
;
import
'package:crypto/crypto.dart'
;
import
'package:path/path.dart'
as
path
;
...
...
@@ -161,3 +162,37 @@ class SettingsFile {
}).
join
(
'
\n
'
));
}
}
/// A UUID generator. This will generate unique IDs in the format:
///
/// f47ac10b-58cc-4372-a567-0e02b2c3d479
///
/// The generated uuids are 128 bit numbers encoded in a specific string format.
///
/// For more information, see
/// http://en.wikipedia.org/wiki/Universally_unique_identifier.
class
Uuid
{
Random
_random
=
new
Random
();
/// Generate a version 4 (random) uuid. This is a uuid scheme that only uses
/// random numbers as the source of the generated uuid.
String
generateV4
()
{
// Generate xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx / 8-4-4-4-12.
int
special
=
8
+
_random
.
nextInt
(
4
);
return
'
${_bitsDigits(16, 4)}${_bitsDigits(16, 4)}
-'
'
${_bitsDigits(16, 4)}
-'
'4
${_bitsDigits(12, 3)}
-'
'
${_printDigits(special, 1)}${_bitsDigits(12, 3)}
-'
'
${_bitsDigits(16, 4)}${_bitsDigits(16, 4)}${_bitsDigits(16, 4)}
'
;
}
String
_bitsDigits
(
int
bitCount
,
int
digitCount
)
=>
_printDigits
(
_generateBits
(
bitCount
),
digitCount
);
int
_generateBits
(
int
bitCount
)
=>
_random
.
nextInt
(
1
<<
bitCount
);
String
_printDigits
(
int
value
,
int
count
)
=>
value
.
toRadixString
(
16
).
padLeft
(
count
,
'0'
);
}
packages/flutter_tools/lib/src/commands/daemon.dart
View file @
d9bbd2fb
...
...
@@ -9,6 +9,7 @@ import 'dart:io';
import
'../android/android_device.dart'
;
import
'../base/context.dart'
;
import
'../base/logger.dart'
;
import
'../base/utils.dart'
;
import
'../build_info.dart'
;
import
'../cache.dart'
;
import
'../device.dart'
;
...
...
@@ -280,9 +281,9 @@ class AppDomain extends Domain {
registerHandler
(
'discover'
,
discover
);
}
static
int
_nextAppId
=
0
;
static
Uuid
_uuidGenerator
=
new
Uuid
()
;
static
String
_getNe
xtAppId
()
=>
'app-
${_nextAppId++}
'
;
static
String
_getNe
wAppId
()
=>
_uuidGenerator
.
generateV4
()
;
List
<
AppInstance
>
_apps
=
<
AppInstance
>[];
...
...
@@ -341,7 +342,7 @@ class AppDomain extends Domain {
bool
supportsRestart
=
enableHotReload
?
device
.
supportsHotMode
:
device
.
supportsRestart
;
AppInstance
app
=
new
AppInstance
(
_getNe
xt
AppId
(),
runner
);
AppInstance
app
=
new
AppInstance
(
_getNe
w
AppId
(),
runner
);
_apps
.
add
(
app
);
_sendAppEvent
(
app
,
'start'
,
<
String
,
dynamic
>{
'deviceId'
:
deviceId
,
...
...
packages/flutter_tools/test/utils_test.dart
View file @
d9bbd2fb
...
...
@@ -18,4 +18,65 @@ baz=qux
expect
(
file
.
values
,
hasLength
(
2
));
});
});
group
(
'uuid'
,
()
{
// xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
test
(
'simple'
,
()
{
Uuid
uuid
=
new
Uuid
();
String
result
=
uuid
.
generateV4
();
expect
(
result
.
length
,
36
);
expect
(
result
[
8
],
'-'
);
expect
(
result
[
13
],
'-'
);
expect
(
result
[
18
],
'-'
);
expect
(
result
[
23
],
'-'
);
});
test
(
'can parse'
,
()
{
Uuid
uuid
=
new
Uuid
();
String
result
=
uuid
.
generateV4
();
expect
(
int
.
parse
(
result
.
substring
(
0
,
8
),
radix:
16
),
isNotNull
);
expect
(
int
.
parse
(
result
.
substring
(
9
,
13
),
radix:
16
),
isNotNull
);
expect
(
int
.
parse
(
result
.
substring
(
14
,
18
),
radix:
16
),
isNotNull
);
expect
(
int
.
parse
(
result
.
substring
(
19
,
23
),
radix:
16
),
isNotNull
);
expect
(
int
.
parse
(
result
.
substring
(
24
,
36
),
radix:
16
),
isNotNull
);
});
test
(
'special bits'
,
()
{
Uuid
uuid
=
new
Uuid
();
String
result
=
uuid
.
generateV4
();
expect
(
result
[
14
],
'4'
);
expect
(
result
[
19
].
toLowerCase
(),
isIn
(
'89ab'
));
result
=
uuid
.
generateV4
();
expect
(
result
[
19
].
toLowerCase
(),
isIn
(
'89ab'
));
result
=
uuid
.
generateV4
();
expect
(
result
[
19
].
toLowerCase
(),
isIn
(
'89ab'
));
});
test
(
'is pretty random'
,
()
{
Set
<
String
>
set
=
new
Set
<
String
>();
Uuid
uuid
=
new
Uuid
();
for
(
int
i
=
0
;
i
<
64
;
i
++)
{
String
val
=
uuid
.
generateV4
();
expect
(
set
,
isNot
(
contains
(
val
)));
set
.
add
(
val
);
}
uuid
=
new
Uuid
();
for
(
int
i
=
0
;
i
<
64
;
i
++)
{
String
val
=
uuid
.
generateV4
();
expect
(
set
,
isNot
(
contains
(
val
)));
set
.
add
(
val
);
}
uuid
=
new
Uuid
();
for
(
int
i
=
0
;
i
<
64
;
i
++)
{
String
val
=
uuid
.
generateV4
();
expect
(
set
,
isNot
(
contains
(
val
)));
set
.
add
(
val
);
}
});
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment