This question assumes Android OS 2.0 or higher.

My application tries to use the following API

         Intent item = DrmStore.addDrmFile(getContentResolver(), file,
"amy");

Where file is a File object pointing to a downloaded OMA1 forward
locked file (“amy.dm”). This method is called from a normal activity
running under its own user id.
The method DrmStore.addDrmFile then calls

             if (contentUri != null) {
                 ContentValues values = new ContentValues(3);
                 values.put(DrmStore.Columns.TITLE, title);
                 values.put(DrmStore.Columns.SIZE, size);
                 values.put(DrmStore.Columns.MIME_TYPE, mimeType);

                 Uri uri = cr.insert(contentUri, values);

This will cause DrmProvider.insert() to be called

<snip>
     @Override
     public Uri insert(Uri uri, ContentValues initialValues)
     {
         if
(getContext().checkCallingOrSelfPermission(Manifest.permission.INSTALL_DRM)
                 != PackageManager.PERMISSION_GRANTED) {
             throw new SecurityException("Requires INSTALL_DRM
permission");
         }

         long rowId;
         int match = URI_MATCHER.match(uri);
         Uri newUri = null;
         SQLiteDatabase db = mOpenHelper.getWritableDatabase();

         if (initialValues == null) {
             initialValues = new ContentValues();
         }

         switch (match) {
             case AUDIO: {
                 ContentValues values = ensureFile(initialValues);

 ...

     /**
      * Ensures there is a file in the _data column of values, if one
isn't
      * present a new file is created.
      *
      * @param initialValues the values passed to insert by the caller
      * @return the new values
      */
     private ContentValues ensureFile(ContentValues initialValues) {
         try {
             File parent = getContext().getFilesDir();
             parent.mkdirs();
             File file = File.createTempFile("DRM-", ".data", parent);
             ContentValues values = new ContentValues(initialValues);
             values.put("_data", file.toString());
             return values;
        } catch (IOException e) {
             Log.e(TAG, "Failed to create data file in ensureFile");
             return null;
        }
     }
</snip>

ensureFile() then throws an exception because it cannot create the
temp data file requested.

The same code (DrmStore.addDrmFile()) is used by the android download
manager and there it works fine. My assumption is that the reason for
that is that the download provider and the drm provider run under the
same user id.

However, when my code calls the method I get the before mentioned
exception. My theory is that the reason for this is that my activity
is running with a different user id. I have tried to make my
activities files directory world writable but that did not help.

When I create my own content provider I can observe that the content
provider is running under its own user id and getFilesDir() in the
contentprovider will return the directory of the content provider to
which it has full access. So I am really surprised why the DrmProvider
works differently.

Unfortunately I don't have the ability to debug native android OS code
so I have no means to find out what getContext().getFilesDir() inside
the DrmProvider really returns.

Since the INSTALL_DRM right is public (i.e. Does not require specific
signatures), IMHO it is legal for 3rd party apps to use this function.
Having it not working is really quite unexpected.

Any suggestions?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

To unsubscribe from this group, send email to 
android-developers+unsubscribegooglegroups.com or reply to this email with the 
words "REMOVE ME" as the subject.

Reply via email to