| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package org.chromium.sync.notifier; | |
| 6 | |
| 7 import android.util.Base64; | |
| 8 | |
| 9 import org.chromium.base.annotations.MainDex; | |
| 10 | |
| 11 import java.util.Random; | |
| 12 | |
| 13 /** | |
| 14 * Generates a fully random client ID. | |
| 15 * | |
| 16 * This ID will not persist across restarts. Using this ID will break the inval
idator's "reflection | |
| 17 * blocking" feature. That's unfortunate, but better than using a hard-coded ID
. A hard-coded ID | |
| 18 * could prevent invalidations from being delivered. | |
| 19 */ | |
| 20 @MainDex | |
| 21 class RandomizedInvalidationClientNameGenerator implements InvalidationClientNam
eGenerator { | |
| 22 private static final Random RANDOM = new Random(); | |
| 23 | |
| 24 RandomizedInvalidationClientNameGenerator() {} | |
| 25 | |
| 26 /** | |
| 27 * Generates a random ID prefixed with the string "BadID". | |
| 28 * | |
| 29 * The prefix is intended to grab attention. We should never use it in real
builds. Hopefully, | |
| 30 * it will induce someone to file a bug if they see it. | |
| 31 * | |
| 32 * However, as bad as it is, this ID is better than a hard-coded default or
none at all. See | |
| 33 * the class description for more details. | |
| 34 */ | |
| 35 public byte[] generateInvalidatorClientName() { | |
| 36 byte[] randomBytes = new byte[8]; | |
| 37 RANDOM.nextBytes(randomBytes); | |
| 38 String encoded = Base64.encodeToString(randomBytes, 0, randomBytes.lengt
h, Base64.NO_WRAP); | |
| 39 String idString = "BadID" + encoded; | |
| 40 return idString.getBytes(); | |
| 41 } | |
| 42 } | |
| OLD | NEW |