-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from loveyu/1.6.5
1.6.5
- Loading branch information
Showing
15 changed files
with
192 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
app/src/main/java/net/loveyu/wifipwd/DeviceUuidFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package net.loveyu.wifipwd; | ||
|
||
import android.content.Context; | ||
import android.content.SharedPreferences; | ||
import android.provider.Settings; | ||
import android.provider.Settings.Secure; | ||
import android.telephony.TelephonyManager; | ||
|
||
import java.io.UnsupportedEncodingException; | ||
import java.util.UUID; | ||
|
||
public class DeviceUuidFactory { | ||
private static final String PREFS_FILE = "device_id.xml"; | ||
private static final String PREFS_DEVICE_ID = "device_id"; | ||
private static volatile UUID uuid; | ||
|
||
public DeviceUuidFactory(Context context) { | ||
if (uuid == null) { | ||
synchronized (DeviceUuidFactory.class) { | ||
if (uuid == null) { | ||
final SharedPreferences prefs = context | ||
.getSharedPreferences(PREFS_FILE, 0); | ||
final String id = prefs.getString(PREFS_DEVICE_ID, null); | ||
if (id != null) { | ||
// Use the ids previously computed and stored in the | ||
// prefs file | ||
uuid = UUID.fromString(id); | ||
} else { | ||
uuid = UUID.randomUUID(); | ||
// Write the value out to the prefs file | ||
prefs.edit().putString(PREFS_DEVICE_ID, uuid.toString()).apply(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
public UUID getDeviceUuid() { | ||
return uuid; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.