[Content] Remove deprecated native functions, break backward compatibility 33/275833/1
authorMarcin Bialek <m.bialek@samsung.com>
Thu, 2 Jun 2022 10:40:24 +0000 (12:40 +0200)
committerMarcin Bialek <m.bialek@samsung.com>
Thu, 2 Jun 2022 10:40:24 +0000 (12:40 +0200)
The following properties of Content are marked as readonly since Tizen 5.5:
- DOMString name
- DOMString? description
- unsigned long rating
- SimpleCoordinates? geolocation
- ImageContentOrientation orientation

They were still writeable, if an application was compiled for version
below 5.5. This commit breaks the backward compatibility and writing
is not possible for all versions.

The following deprecated native functions have been removed:
- image_meta_set_orientation
- image_meta_update_to_db
- media_info_set_description
- media_info_set_longitude
- media_info_set_latitude
- media_info_set_rating

[Related ACR] https://code.sec.samsung.net/jira/browse/TWDAPI-203
[Verification] Code compiles. TCT tests for content module pass.

Change-Id: I7bd777998bcbc7cfe92794aedbbd8c55058fbac2
Signed-off-by: Marcin Bialek <m.bialek@samsung.com>
src/content/content_manager.cc
src/content/js/common.js
src/content/js/datatypes.js

index 4f22a0d..f61279b 100644 (file)
@@ -49,17 +49,6 @@ static const std::string uri_prefix = "file://";
 static const std::string uri_absolute_prefix = "file:///";
 }
 
-const std::map<std::string, media_content_orientation_e> orientationMap = {
-    {"NORMAL", MEDIA_CONTENT_ORIENTATION_NORMAL},
-    {"FLIP_HORIZONTAL", MEDIA_CONTENT_ORIENTATION_HFLIP},
-    {"ROTATE_180", MEDIA_CONTENT_ORIENTATION_ROT_180},
-    {"FLIP_VERTICAL", MEDIA_CONTENT_ORIENTATION_VFLIP},
-    {"TRANSPOSE", MEDIA_CONTENT_ORIENTATION_TRANSPOSE},
-    {"ROTATE_90", MEDIA_CONTENT_ORIENTATION_ROT_90},
-    {"TRANSVERSE", MEDIA_CONTENT_ORIENTATION_TRANSVERSE},
-    {"ROTATE_270", MEDIA_CONTENT_ORIENTATION_ROT_270},
-};
-
 std::string get_date(char* tmpStr) {
   ScopeLogger();
   if (tmpStr) {
@@ -423,8 +412,6 @@ static int setContent(media_info_h media, const picojson::value& content) {
   ScopeLogger();
 
   int ret = MEDIA_CONTENT_ERROR_NONE;
-  std::string description = content.get("description").to_str();
-  int rating = std::stoi(content.get("rating").to_str());
   bool is_fav = content.get("isFavorite").get<bool>();
 
   if (NULL == media) {
@@ -439,16 +426,6 @@ static int setContent(media_info_h media, const picojson::value& content) {
     return ret;
   }
 
-  ret = media_info_set_description(media, description.c_str());
-  if (ret != MEDIA_CONTENT_ERROR_NONE) {
-    LoggerE("Updating description failed.");
-  }
-
-  ret = media_info_set_rating(media, rating);
-  if (ret != MEDIA_CONTENT_ERROR_NONE) {
-    LoggerE("Updating rating failed.");
-  }
-
   ret = media_info_set_favorite(media, is_fav);
   if (ret != MEDIA_CONTENT_ERROR_NONE) {
     LoggerE("Updating isFavorite failed.");
@@ -458,42 +435,6 @@ static int setContent(media_info_h media, const picojson::value& content) {
     LoggerE("Updating favorite failed.");
   }
 
-  if (type == MEDIA_CONTENT_TYPE_IMAGE) {
-    std::string orientation = content.get("orientation").to_str();
-    auto orientationToSet = orientationMap.find(orientation);
-
-    if (orientationToSet != orientationMap.end()) {
-      image_meta_h img;
-      if (MEDIA_CONTENT_ERROR_NONE == media_info_get_image(media, &img) &&
-          MEDIA_CONTENT_ERROR_NONE == image_meta_set_orientation(img, orientationToSet->second) &&
-          MEDIA_CONTENT_ERROR_NONE == image_meta_update_to_db(img)) {
-        LoggerD("orientation update was successful");
-      } else {
-        LoggerE("orientation update failed");
-      }
-      image_meta_destroy(img);
-    }
-  }
-
-  if (type == MEDIA_CONTENT_TYPE_IMAGE || type == MEDIA_CONTENT_TYPE_VIDEO) {
-    picojson::value geo = content.get("geolocation");
-    if (geo.evaluate_as_boolean()) {
-      LoggerD("geolocation is not null");
-      double latitude = atof(geo.get("latitude").to_str().c_str());
-      double longitude = atof(geo.get("longitude").to_str().c_str());
-      ret = media_info_set_latitude(media, latitude);
-      if (ret != MEDIA_CONTENT_ERROR_NONE) {
-        LoggerE("Updating geolocation is failed.");
-      }
-      ret = media_info_set_longitude(media, longitude);
-      if (ret != MEDIA_CONTENT_ERROR_NONE) {
-        LoggerD("Updating geolocation is failed.");
-      }
-    } else {
-      LoggerD("geolocation is null");
-    }
-  }
-
   return MEDIA_CONTENT_ERROR_NONE;
 }
 
@@ -502,20 +443,11 @@ static int updateContent(const picojson::value& content) {
 
   int ret = MEDIA_CONTENT_ERROR_NONE;
   std::string id = content.get("id").to_str();
-  std::string new_name = content.get("name").to_str();
   media_info_h media = nullptr;
-  char* name = nullptr;
-  char* path = nullptr;
   SCOPE_EXIT {
     if (media) {
       media_info_destroy(media);
     }
-    if (name) {
-      free(name);
-    }
-    if (path) {
-      free(path);
-    }
   };
 
   ret = media_info_get_media_from_db(id.c_str(), &media);
@@ -533,28 +465,6 @@ static int updateContent(const picojson::value& content) {
     LoggerE("media_info_update_to_db failed: %d", ret);
     return ret;
   }
-  ret = media_info_get_display_name(media, &name);
-  if (ret != MEDIA_CONTENT_ERROR_NONE) {
-    LoggerE("media_info_get_display_name failed: %d", ret);
-    return ret;
-  }
-  const std::string name_str(name);
-  if (name_str != new_name) {
-    ret = media_info_get_file_path(media, &path);
-    if (ret != MEDIA_CONTENT_ERROR_NONE) {
-      LoggerE("media_info_get_file_path failed: %d", ret);
-      return ret;
-    }
-    std::string path_str(path);
-    const size_t p = path_str.rfind(name_str);
-    path_str.replace(p, name_str.length(), new_name);
-    LoggerD("new media path: %s", path_str.c_str());
-    ret = media_info_move_to_db(media, path_str.c_str());
-    if (ret != MEDIA_CONTENT_ERROR_NONE) {
-      LoggerE("media_info_move_to_db failed: %d", ret);
-      return ret;
-    }
-  }
 
   return ret;
 }
index f60783c..4c55df5 100755 (executable)
@@ -21,8 +21,6 @@ var validator_ = utils_.validator;
 var types_ = validator_.Types;
 var native_ = new xwalk.utils.NativeManager(extension);
 
-var isEarlierThan55 = utils_.isAppVersionEarlierThan('5.5');
-
 var EditManager = function() {
     this.isAllowed = false;
 };
index 658dc7c..2efea2b 100755 (executable)
@@ -126,14 +126,6 @@ function ContentDirectory(data) {
 
 function Content(data) {
     var editableAttributes = ['isFavorite'];
-    // since 5.5 these attributes are readonly, it is disallowed to modify them,
-    // but for applications developed for earlier versions backward compatibility
-    // is kept
-    if (isEarlierThan55) {
-        editableAttributes.push('name');
-        editableAttributes.push('rating');
-        editableAttributes.push('description');
-    }
     var id;
     var name;
     var type;
@@ -170,10 +162,8 @@ function Content(data) {
                 return name;
             },
             set: function(v) {
-                // since 5.5 this attribute is readonly, it is disallowed to modify it,
-                // but for applications developed for earlier versions backward
-                // compatibility is kept
-                if (isEarlierThan55 || edit_.isAllowed) {
+                // since 5.5 this attribute is readonly, it is disallowed to modify it
+                if (edit_.isAllowed) {
                     if (!type_.isNull(v)) {
                         name = converter_.toString(v, false);
                     }
@@ -279,10 +269,8 @@ function Content(data) {
                 return description;
             },
             set: function(v) {
-                // since 5.5 this attribute is readonly, it is disallowed to modify it,
-                // but for applications developed for earlier versions backward
-                // compatibility is kept
-                if (isEarlierThan55 || edit_.isAllowed) {
+                // since 5.5 this attribute is readonly, it is disallowed to modify it
+                if (edit_.isAllowed) {
                     description = converter_.toString(v, true);
                 } else {
                     utils_.warn(
@@ -298,10 +286,8 @@ function Content(data) {
                 return rating;
             },
             set: function(v) {
-                // since 5.5 this attribute is readonly, it is disallowed to modify it,
-                // but for applications developed for earlier versions backward
-                // compatibility is kept
-                if (isEarlierThan55 || edit_.isAllowed) {
+                // since 5.5 this attribute is readonly, it is disallowed to modify it
+                if (edit_.isAllowed) {
                     if (!type_.isNull(v) && v >= 0 && v <= 10) {
                         rating = converter_.toUnsignedLong(v, false);
                     }
@@ -343,13 +329,6 @@ function VideoContent(data) {
     Content.call(this, data);
 
     var editableAttributes = this.editableAttributes;
-    // since 5.5 this attribute is readonly, it is disallowed to modify it,
-    // but for applications developed for earlier versions backward compatibility
-    // is kept
-    if (isEarlierThan55) {
-        editableAttributes.push('geolocation');
-    }
-
     var geolocation;
     var album;
     var artists;
@@ -365,22 +344,16 @@ function VideoContent(data) {
         },
         geolocation: {
             get: function() {
-                if (isEarlierThan55) {
-                    return geolocation;
-                } else {
-                    // for keep geolocation's latitude and longitude readonly
-                    // we need to return copy of this object
-                    return new tizen.SimpleCoordinates(
-                        geolocation.latitude,
-                        geolocation.longitude
-                    );
-                }
+                // for keep geolocation's latitude and longitude readonly
+                // we need to return copy of this object
+                return new tizen.SimpleCoordinates(
+                    geolocation.latitude,
+                    geolocation.longitude
+                );
             },
             set: function(v) {
-                // since 5.5 this attribute is readonly, it is disallowed to modify it,
-                // but for applications developed for earlier versions backward
-                // compatibility is kept
-                if (isEarlierThan55 || edit_.isAllowed) {
+                // since 5.5 this attribute is readonly, it is disallowed to modify it
+                if (edit_.isAllowed) {
                     if (!type_.isNull(v)) {
                         var latitude = converter_.toDouble(v.latitude, false);
                         var longitude = converter_.toDouble(v.longitude, false);
@@ -680,14 +653,6 @@ function ImageContent(data) {
     Content.call(this, data);
 
     var editableAttributes = this.editableAttributes;
-    // since 5.5 these attributes are readonly, it is disallowed to modify them,
-    // but for applications developed for earlier versions backward compatibility
-    // is kept
-    if (isEarlierThan55) {
-        editableAttributes.push('geolocation');
-        editableAttributes.push('orientation');
-    }
-
     var geolocation;
     var width;
     var height;
@@ -701,22 +666,16 @@ function ImageContent(data) {
         },
         geolocation: {
             get: function() {
-                if (isEarlierThan55) {
-                    return geolocation;
-                } else {
-                    // for keep geolocation's latitude and longitude readonly
-                    // we need to return copy of this object
-                    return new tizen.SimpleCoordinates(
-                        geolocation.latitude,
-                        geolocation.longitude
-                    );
-                }
+                // for keep geolocation's latitude and longitude readonly
+                // we need to return copy of this object
+                return new tizen.SimpleCoordinates(
+                    geolocation.latitude,
+                    geolocation.longitude
+                );
             },
             set: function(v) {
-                // since 5.5 this attribute is readonly, it is disallowed to modify it,
-                // but for applications developed for earlier versions backward
-                // compatibility is kept
-                if (isEarlierThan55 || edit_.isAllowed) {
+                // since 5.5 this attribute is readonly, it is disallowed to modify it
+                if (edit_.isAllowed) {
                     if (!type_.isNull(v)) {
                         var latitude = converter_.toDouble(v.latitude, false);
                         var longitude = converter_.toDouble(v.longitude, false);
@@ -758,10 +717,8 @@ function ImageContent(data) {
                 return orientation;
             },
             set: function(v) {
-                // since 5.5 this attribute is readonly, it is disallowed to modify it,
-                // but for applications developed for earlier versions backward
-                // compatibility is kept
-                if (isEarlierThan55 || edit_.isAllowed) {
+                // since 5.5 this attribute is readonly, it is disallowed to modify it
+                if (edit_.isAllowed) {
                     if (!type_.isNull(v)) {
                         orientation = converter_.toEnum(
                             v,