Пример #1
0
 /**
  * Returns a unique identifier for this device. The first (in the order the enums constants as
  * defined in the IDs enum) non null identifier is returned or a DeviceIDException is thrown. A
  * DeviceIDException is also thrown if ignoreBuggyAndroidID is false and the device has the
  * Android ID bug
  *
  * @param ctx an Android constant (to retrieve system services)
  * @param ignoreBuggyAndroidID if false, on a device with the android ID bug, the buggy android ID
  *     is not returned instead a DeviceIDException is thrown
  * @return a *device* ID - null is never returned, instead a DeviceIDException is thrown
  * @throws DeviceIDException if none of the enum methods manages to return a device ID
  */
 public static String getDeviceIdentifier(Context ctx, boolean ignoreBuggyAndroidID)
     throws DeviceIDException {
   String result = uuid;
   if (result == null) {
     synchronized (DeviceIdentifier.class) {
       result = uuid;
       if (result == null) {
         for (IDs id : IDs.values()) {
           try {
             result = uuid = id.getId(ctx);
           } catch (DeviceIDNotUniqueException e) {
             if (!ignoreBuggyAndroidID) {
               throw new DeviceIDException(e);
             }
           }
           if (result != null) {
             return result;
           }
         }
         throw new DeviceIDException();
       }
     }
   }
   return result;
 }