66import android .graphics .BitmapFactory ;
77import android .util .Log ;
88
9+ import com .smartdevicelink .util .DebugTool ;
10+
911import org .json .JSONException ;
1012import org .json .JSONObject ;
1113
@@ -37,10 +39,10 @@ boolean updateCachedImage(String iconUrl) {
3739 SharedPreferences sharedPref = this .context .getSharedPreferences (SDL_DEVICE_STATUS_SHARED_PREFS , Context .MODE_PRIVATE );
3840 String iconParameters = sharedPref .getString (iconHash , null );
3941 if (iconParameters == null ) {
40- Log . d ( TAG , "No Image Details Found In Preferences" );
42+ DebugTool . logInfo ( "No Icon Details Found In Shared Preferences" );
4143 return true ;
4244 } else {
43- Log . d ( TAG , "Image Details Found" );
45+ DebugTool . logInfo ( "Icon Details Found" );
4446 JSONObject jsonObject = null ;
4547 try {
4648 jsonObject = new JSONObject (iconParameters );
@@ -50,11 +52,10 @@ boolean updateCachedImage(String iconUrl) {
5052
5153 long timeDifference = currentTime - lastUpdatedTime ;
5254 long daysBetweenLastUpdate = timeDifference / (1000 * 60 * 60 * 24 );
53- Log .d (TAG , "Time since last update: " + daysBetweenLastUpdate );
5455 return daysBetweenLastUpdate >= 30 ;
5556 } catch (JSONException e ) {
5657 e .printStackTrace ();
57- Log . d ( TAG , "Exception Trying to read system preferences" );
58+ DebugTool . logError ( "Exception Trying to read shared preferences" );
5859 return true ;
5960 }
6061 }
@@ -65,7 +66,6 @@ void saveFileToCache(Bitmap icon, String iconUrl) {
6566 String iconHash = getMD5HashFromIconUrl (iconUrl );
6667
6768 File f = new File (this .context .getCacheDir () + "/" + STORED_ICON_PATH , iconHash );
68- Log .d (TAG , "Attempting to save to cache" );
6969 ByteArrayOutputStream bos = new ByteArrayOutputStream ();
7070 icon .compress (Bitmap .CompressFormat .PNG , 0 /*ignored for PNG*/ , bos );
7171 byte [] bitmapdata = bos .toByteArray ();
@@ -77,18 +77,17 @@ void saveFileToCache(Bitmap icon, String iconUrl) {
7777 fos .flush ();
7878 fos .close ();
7979 } catch (Exception e ) {
80- Log . d ( TAG , "Failed to save to Icon to Cache " );
80+ DebugTool . logError ( "Failed to save icon to cache " );
8181 e .printStackTrace ();
8282 return ;
8383 }
8484
8585 JSONObject iconParams ;
86- Log .d (TAG , "Attempting to save to system preferences" );
8786 try {
8887 iconParams = buildDeviceIconParameters (f .getAbsolutePath ());
8988 writeDeviceIconParametersToSystemPreferences (iconHash , iconParams );
9089 } catch (JSONException e ) {
91- Log . d ( TAG , "Failed to save to system preferences, clearing cache icon directory" );
90+ DebugTool . logError ( "Failed to save to shared preferences, clearing cache icon directory" );
9291 clearIconDirectory ();
9392 e .printStackTrace ();
9493 }
@@ -100,42 +99,38 @@ Bitmap getFileFromCache(String iconUrl) {
10099 String iconParameters = sharedPref .getString (iconHash , null );
101100
102101 if (iconParameters != null ) {
103- Log .d (TAG , "System Preferences Found" );
104102 JSONObject jsonObject = null ;
105103 try {
106- Log .d (TAG , "Attempting to get file from cache" );
107104 jsonObject = new JSONObject (iconParameters );
108105 String storedUrl = jsonObject .getString (STORED_URL );
109106 Bitmap cachedIcon = BitmapFactory .decodeFile (storedUrl );
110107 if (cachedIcon == null ) {
111- Log . d ( TAG , "Failed to get Bitmap from decoding file cache" );
108+ DebugTool . logError ( "Failed to get Bitmap from decoding file cache" );
112109 clearIconDirectory ();
113110 return null ;
114111 } else {
115112 return cachedIcon ;
116113 }
117114 } catch (JSONException e ) {
118- Log . d ( TAG , "Failed to get file from cache, removing from shared pref" );
115+ DebugTool . logError ( "Failed to get file from cache, removing shared pref" );
119116 sharedPref .edit ().remove (iconHash ).commit ();
120117 e .printStackTrace ();
121118 return null ;
122119 }
123120 } else {
124- Log . d ( TAG , "Failed to get system preferences" );
121+ DebugTool . logError ( "Failed to get system preferences" );
125122 return null ;
126123 }
127124 }
128125
129126 private void writeDeviceIconParametersToSystemPreferences (String iconHash , JSONObject jsonObject ) {
130- Log .d (TAG , "Attempting to write to system preferences" );
131127 SharedPreferences sharedPref = this .context .getSharedPreferences (SDL_DEVICE_STATUS_SHARED_PREFS , Context .MODE_PRIVATE );
132128 SharedPreferences .Editor editor = sharedPref .edit ();
133129 editor .putString (iconHash , jsonObject .toString ());
134130 editor .commit ();
135131 }
136132
137133 private JSONObject buildDeviceIconParameters (String storedUrl ) throws JSONException {
138- Log .d (TAG , "Attempting to write JSON" );
139134 JSONObject parametersJson = new JSONObject ();
140135 parametersJson .put (STORED_URL , storedUrl );
141136 parametersJson .put (LAST_UPDATED_TIME , System .currentTimeMillis ());
@@ -154,10 +149,9 @@ private String getMD5HashFromIconUrl(String iconUrl) {
154149 }
155150 iconHash = hashtext ;
156151 } catch (NoSuchAlgorithmException e ) {
157- Log . d ( TAG , "Unable to Hash URL " );
152+ DebugTool . logError ( "Unable to hash icon url " );
158153 e .printStackTrace ();
159154 }
160- Log .d (TAG , "icon hash: " + iconHash );
161155 return iconHash ;
162156 }
163157
0 commit comments