@@ -567,13 +567,13 @@ public void removeApiKey(){
567567
568568 public boolean isThisDeviceAlreadyRegisteredWithPrey (boolean notifyUser ) {
569569 String deviceId = getString (PreyConfig .DEVICE_ID , null );
570- boolean isVerified = (deviceId != null && !"" . equals ( deviceId ));
570+ boolean isVerified = (deviceId != null && !deviceId . isEmpty ( ));
571571 return isVerified ;
572572 }
573573
574574 public boolean isThisDeviceAlreadyRegisteredWithPrey () {
575575 String deviceID = getDeviceId ();
576- return deviceID != null && !"" . equals ( deviceID );
576+ return deviceID != null && !deviceID . isEmpty ( );
577577 }
578578
579579 public String getSimSerialNumber (){
@@ -611,7 +611,7 @@ public void registerC2dm() {
611611 String deviceId = PreyConfig .getPreyConfig (ctx ).getDeviceId ();
612612 boolean isTimeC2dm =PreyConfig .getPreyConfig (ctx ).isTimeC2dm ();
613613 PreyLogger .d ("registerC2dm deviceId:" +deviceId +" isTimeC2dm:" +isTimeC2dm );
614- if (deviceId != null && !"" . equals ( deviceId )) {
614+ if (deviceId != null && !deviceId . isEmpty ( )) {
615615 if (!isTimeC2dm ) {
616616 String token = null ;
617617 try {
@@ -653,7 +653,7 @@ public void onComplete(@NonNull Task<String> task) {
653653
654654 public static void sendToken (Context ctx ,String token ) {
655655 PreyLogger .d ("registerC2dm send token:" +token );
656- if (token !=null && !"null" .equals (token ) && !"" . equals ( token ) && UtilConnection .isInternetAvailable (ctx )) {
656+ if (token !=null && !"null" .equals (token ) && !token . isEmpty ( ) && UtilConnection .isInternetAvailable (ctx )) {
657657 try {
658658 StrictMode .ThreadPolicy policy = new StrictMode .ThreadPolicy .Builder ().permitAll ().build ();
659659 StrictMode .setThreadPolicy (policy );
@@ -1192,7 +1192,7 @@ public PreyLocation getLocationAware() {
11921192 // Retrieve the accuracy value from storage
11931193 float acc = getFloat (PreyConfig .AWARE_ACC , 0f );
11941194 // Check if the latitude or longitude values are empty or null
1195- if (lat == null || "" . equals ( lat ) || lng == null || "" . equals ( lng )) {
1195+ if (lat == null || lat . isEmpty ( ) || lng == null || lng . isEmpty ( )) {
11961196 // If either value is empty or null, return null
11971197 return null ;
11981198 }
@@ -1752,13 +1752,17 @@ public boolean isTimeNextAware() {
17521752 */
17531753 public String buildDeviceName (String defaultName ) {
17541754 String mdmDeviceName = getMdmDeviceName ();
1755- if (mdmDeviceName != null && !"" . equals ( mdmDeviceName )) {
1755+ if (mdmDeviceName != null && !mdmDeviceName . isEmpty ( )) {
17561756 return mdmDeviceName ;
17571757 }
17581758 String serialNumber = getMdmSerialNumber ();
1759- if (serialNumber != null && !"" . equals ( serialNumber )) {
1759+ if (serialNumber != null && !serialNumber . isEmpty ( )) {
17601760 return defaultName + " - " + serialNumber ;
17611761 }
1762+ String workEmail = resolveWorkEmail ();
1763+ if (workEmail != null && !workEmail .isEmpty ()) {
1764+ return workEmail ;
1765+ }
17621766 return defaultName ;
17631767 }
17641768
@@ -1770,7 +1774,7 @@ public String buildDeviceName(String defaultName) {
17701774 */
17711775 public String resolveImei () {
17721776 String mdmImei = getMdmImei ();
1773- if (mdmImei != null && !"" . equals ( mdmImei )) {
1777+ if (mdmImei != null && !mdmImei . isEmpty ( )) {
17741778 return mdmImei ;
17751779 }
17761780 return new PreyPhone (ctx ).getHardware ().getAndroidDeviceId ();
@@ -1787,6 +1791,8 @@ public void registerNewDeviceWithApiKey(String apiKey) throws Exception {
17871791 PreyAccountData accountData = PreyWebServices .getInstance ().registerNewDeviceWithApiKeyEmail (ctx , apiKey , deviceType , nameDevice );
17881792 if (accountData != null ) {
17891793 PreyConfig .getPreyConfig (ctx ).saveAccount (accountData );
1794+ PreyConfig .getPreyConfig (ctx ).setNotificationId ("" );
1795+ PreyConfig .getPreyConfig (ctx ).setRegisterC2dm (false );
17901796 // Register C2DM
17911797 PreyConfig .getPreyConfig (ctx ).registerC2dm ();
17921798 // Get the email associated with the account
@@ -1885,6 +1891,17 @@ public void setMdmDeviceName(String deviceName) {
18851891 saveString (MDM_DEVICE_NAME , deviceName );
18861892 }
18871893
1894+ /**
1895+ * Resolves the user's work email from the first Google account registered
1896+ * on the device — typically the work profile account under Android Enterprise
1897+ * (work profile apps see the work Google account, not the personal one).
1898+ *
1899+ * @return The work email, or null if no account is available.
1900+ */
1901+ public String resolveWorkEmail () {
1902+ return PreyEmail .getEmail (ctx );
1903+ }
1904+
18881905 /**
18891906 * Key for storing the IMEI received from MDM restrictions in the configuration.
18901907 */
0 commit comments