@@ -153,61 +153,72 @@ public static String getTelephonyId(TelephonyManager telephonyManager, int index
153153 return Reflection .getTelephonyId (telephonyManager , index );
154154 }
155155
156+ public static boolean tryAddToStringList (List <String > list , String value ) {
157+ if (value == null ) {
158+ return false ;
159+ }
160+ if (list .contains (value )) {
161+ return false ;
162+ }
163+
164+ return list .add (value );
165+ }
166+
156167 public static String getTelephonyIds (TelephonyManager telephonyManager ) {
157- List <String > telephonyIds = new ArrayList <String >();
168+ List <String > telephonyIdList = new ArrayList <String >();
158169
159170 String telephonyId0 = getTelephonyId (telephonyManager , 0 );
160- if (telephonyId0 != null ) {
161- telephonyIds .add (telephonyId0 );
162- }
171+ tryAddToStringList (telephonyIdList , telephonyId0 );
163172
164173 for (int i = 1 ; i < 10 ; i ++) {
165174 String telephonyId = getTelephonyId (telephonyManager , i );
166- if (telephonyId == null ) {
175+ if (! tryAddToStringList ( telephonyIdList , telephonyId ) ) {
167176 break ;
168177 }
169- telephonyIds .add (telephonyId );
170178 }
171179
172- return TextUtils .join ("," , telephonyIds );
180+ String telephonyIdMax = getTelephonyId (telephonyManager , Integer .MAX_VALUE );
181+ tryAddToStringList (telephonyIdList , telephonyIdMax );
182+
183+ return TextUtils .join ("," , telephonyIdList );
173184 }
174185
175186 public static String getIMEIs (TelephonyManager telephonyManager ) {
176- List <String > imeis = new ArrayList <String >();
187+ List <String > imeiList = new ArrayList <String >();
177188
178189 String imei0 = getIMEI (telephonyManager , 0 );
179- if (imei0 != null ) {
180- imeis .add (imei0 );
181- }
190+ tryAddToStringList (imeiList , imei0 );
182191
183192 for (int i = 1 ; i < 10 ; i ++) {
184193 String imei = getIMEI (telephonyManager , i );
185- if (imei == null ) {
194+ if (! tryAddToStringList ( imeiList , imei ) ) {
186195 break ;
187196 }
188- imeis .add (imei );
189197 }
190198
191- return TextUtils .join ("," , imeis );
199+ String imeiMax = getIMEI (telephonyManager , Integer .MAX_VALUE );
200+ tryAddToStringList (imeiList , imeiMax );
201+
202+ return TextUtils .join ("," , imeiList );
192203 }
193204
194205 public static String getMEIDs (TelephonyManager telephonyManager ) {
195- List <String > meids = new ArrayList <String >();
206+ List <String > meidList = new ArrayList <String >();
196207
197208 String meid0 = getMEID (telephonyManager , 0 );
198- if (meid0 != null ) {
199- meids .add (meid0 );
200- }
209+ tryAddToStringList (meidList , meid0 );
201210
202211 for (int i = 1 ; i < 10 ; i ++) {
203212 String meid = getMEID (telephonyManager , i );
204- if (meid == null ) {
213+ if (! tryAddToStringList ( meidList , meid ) ) {
205214 break ;
206215 }
207- meids .add (meid );
208216 }
209217
210- return TextUtils .join ("," , meids );
218+ String meidMax = getMEID (telephonyManager , Integer .MAX_VALUE );
219+ tryAddToStringList (meidList , meidMax );
220+
221+ return TextUtils .join ("," , meidList );
211222 }
212223
213224 public static <T > T readObject (Context context , String filename , String objectName , Class <T > type ) {
0 commit comments