Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Android media library of analysis: MediaProvider     - Ubuntu prevent arp attacks (Linux)

- Moosefs Distributed File System Configuration (Server)

- MySQL Basic tutorial: About varchar (N) (Database)

- Grep, Ack, Ag searches Efficiency Comparison (Linux)

- Oracle Database routine inspection (Database)

- Ubuntu 14.04 / 12.04 subscribe users to install software Liferea 1.10.10 (Linux)

- You know the difference between URL, URI and URN among you (Linux)

- To achieve Linux Security (Linux)

- Oracle 10g, 11g database silent installation of small differences (Database)

- Several back door and log tool under Linux (Linux)

- Findbugs installation documentation (Linux)

- CentOS 6.5 system installation Oracle11.2.0.4 basic steps (Database)

- Ubuntu firewall installation and configuration (Linux)

- Oracle database file path changes (Database)

- Use web2py + uWSGI + Nginx Web server built on Linux (Server)

- Automate deployment of Docker-based Rails applications (Server)

- About MongoDB query method according to fuzzy field (Database)

- Tab set to four spaces in Vim (Linux)

- OpenGL Superb Learning Notes - Vertex Shader example (Programming)

- Ubuntu update bug fixes Daquan (Linux)

 
         
  Android media library of analysis: MediaProvider
     
  Add Date : 2017-05-23      
         
         
         
  In doing Android media application (Audio, Image, Video) requires Android media provider (MediaProvider) to do a detailed analysis, the following look at my record harvest:

First, get MediaProvider:
The project in the system source packages \ providers directory proposed and import Eclipse, easy to read

Second, engineering structures and internal relations:
It can be seen from the chart contains four files:
MediaScannerService.Java: media services, with the implementation instance broadcast media scan class initialization database work, but also provides an interface outside;
MediaScannerReceiver.Java: a broadcast receiver, a broadcast receiving system for distributed media services and media services to start;
MediaProvider.Java: wrapper class media database, the code larger than (more than four thousand lines), the function is more complex, but in general is to create a database, provide external URI additions and deletions to the database in order to achieve change search function;
MediaThumbRequest.Java: media file thumbnails request class, used in conjunction with MediaProvider;

The position and role of which is shown in Figure MediaProvider content in red box;
The figure also includes other content:
1, App layer: audio, image, video library and how to interact;
2, the frame layer (android.media package under): how the media scan;
3, Native Layer: how are the media file parsing;
4, resource storage layer: sd card, U disk and other media, DTCM store thumbnails;

Third, Detailed category

1, MediaScannerReceiver:

 public void onReceive (Context context, Intent intent) {
  String action = intent.getAction ();
  Uri uri = intent.getData ();
  // String externalStoragePath =
  // Environment.getExternalStorageDirectory () getPath ().;
  String externalSDStoragePath = Environment
    .getExternalSDStorageDirectory () getPath ().;
  String externalUDiskStoragePath = Environment
    .getExternalUDiskStorageDirectory () getPath ().;
  String externalExtSDStoragePath = Environment
    .getExternalExtSDStorageDirectory () getPath ().;

  if (action.equals (Intent.ACTION_BOOT_COMPLETED)) {
   // Scan internal storage
   scan (context, MediaProvider.INTERNAL_VOLUME);
  } Else {
   if (uri.getScheme (). equals ( "file")) {
    // Handle intents related to external storage
    String path = uri.getPath ();
    if (action.equals (Intent.ACTION_MEDIA_MOUNTED)) {
     if (externalSDStoragePath.equals (path))
      scan (context, MediaProvider.EXTERNAL_VOLUME_SD);
     else if (externalUDiskStoragePath.equals (path))
      scan (context, MediaProvider.EXTERNAL_VOLUME_UDISK);
     else if (externalExtSDStoragePath.equals (path))
      scan (context, MediaProvider.EXTERNAL_VOLUME_EXTSD);
     else
      Slog.w (TAG, "unknown volume path" + path);
    } Else if (action.equals (Intent.ACTION_MEDIA_SCANNER_SCAN_FILE)
      && Path! = Null
      && (Path.startsWith (externalSDStoragePath + "/")
        || Path.startsWith (externalExtSDStoragePath
          + "/") || Path
         .startsWith (externalUDiskStoragePath + "/"))) {
     scanFile (context, path);
    }
   }
  }
 }

Three categories need to start scanning service:
a, system startup is completed;
b, media mount (EXTERNAL_VOLUME_SD, EXTERNAL_VOLUME_UDISK, EXTERNAL_VOLUME_EXTSD);
c, broadcast media file scanning (ACTION_MEDIA_SCANNER_SCAN_FILE);

scanFile and scan method is very simple, just to start media services:

 private void scan (Context context, String volume) {
  Bundle args = new Bundle ();
  args.putString ( "volume", volume);
  context.startService (new Intent (context, MediaScannerService.class)
    .putExtras (args));
 }

 private void scanFile (Context context, String path) {
  Bundle args = new Bundle ();
  Slog.i (TAG, "Start scanFile.");
  args.putString ( "filepath", path);
  context.startService (new Intent (context, MediaScannerService.class)
    .putExtras (args));
 }

2, MediaScannerService:
Step one: Start a thread

 public void run () {
  // Reduce priority below other background threads to avoid interfering
  // With other services at boot time.
  Process.setThreadPriority (Process.THREAD_PRIORITY_BACKGROUND
    + Process.THREAD_PRIORITY_LESS_FAVORABLE);
  Looper.prepare ();

  mServiceLooper = Looper.myLooper ();
  mServiceHandler = new ServiceHandler ();

  Looper.loop ();
 }

Get the current thread's message queue, use the handler to process the message;

Step Two: Start ServiceHandler process messages
ServiceHandler or processed in two, one is scanned, the second is to resolve specific media file;
The second is to look at how to achieve:

     IBinder binder = arguments.getIBinder ( "listener");
     IMediaScannerListener listener = (binder == null? Null
       : IMediaScannerListener.Stub.asInterface (binder));
     Uri uri = scanFile (filePath,
       arguments.getString ( "mimetype"));
     if (listener! = null) {
      listener.scanCompleted (filePath, uri);
     }

Code

 private final IMediaScannerService.Stub mBinder = new IMediaScannerService.Stub () {
  public void requestScanFile (String path, String mimeType,
    IMediaScannerListener listener) {
   if (Config.LOGD) {
    Log.d (TAG, "IMediaScannerService.scanFile:" + path
      + "MimeType:" + mimeType);
   }
   Bundle args = new Bundle ();
   args.putString ( "filepath", path);
   args.putString ( "mimetype", mimeType);
   if (listener! = null) {
    args.putIBinder ( "listener", listener.asBinder ());
   }
   startService (new Intent (MediaScannerService.this,
     MediaScannerService.class) .putExtras (args));
  }

  public void scanFile (String path, String mimeType) {
   requestScanFile (path, mimeType, null);
  }
 };

So the question is: if we want the system to resolve the App library specific to a document, it should be how to do it?
You can see from the above code, bound interfaces MediaScannerService give us, we only need to pass filepath IMediaScannerListener listener and a can, a media library after completion will resolve callback method tells us scanCompleted analytical results;

Step three: Create MediaScanner objects to complete scanning and parsing;
Visible concrete scanning, analytical work is not done MediaScannerService, MediaScannerService only calling sacn, when acanfile method creates MediaScanner object and at his disposal;
MediaScanner in android.media.MediaScanner system framework inside, do not be discussed here;

MediaScannerService basic content of these;

3, MediaProvider:
MediaProvider is to create a database, provide external URI additions and deletions to the database in order to achieve change search function;

4, MediaThumbRequest:
Audio, Image, Video files are there thumbnail, the thumbnail path is stored in the DB, its true files are stored in sd card DICM folder, MediaThumbRequest only available to MediaProvider class action database.
Mainly on two methods, a new thumbnail method: execute, a thumbnail update method: updateDatabase
New skills get: Get application thumbnail, expect the next article;

So far, MediaProvider clear structural analysis, follow-up plans to make two articles:
APP system used in media library;
Scanning media files, parsing is how to achieve;
     
         
         
         
  More:      
 
- Android project and coding specifications (Programming)
- Mount NFS network file system (Linux)
- How to Install Puppet in the Ubuntu 15.04 (Server)
- Zabbix configure DataGuard monitoring (Database)
- VSFTPD Security (Linux)
- C ++ 11 feature: decltype keywords (Programming)
- Android memory optimization of the disk cache (Linux)
- Lua study notes under ubuntu (Linux)
- Struts2 configure a static resource files without Struts processing (regular match) (Programming)
- Linux Network Security: nmap port scanning software (Linux)
- Open remote MySQL database connection managed under CentOS (Database)
- Use CutyCapt to convert HTML pages to png images on Linux (Linux)
- Linux installation skynet issue summary (Linux)
- Increase Linux system security --chattr (Linux)
- Use libpq under Ubuntu 14.04 (Linux)
- Ubuntu Tutorial - Manually install Oracle Java JDK 8 (Linux)
- linux raid levels and concepts introduced (Linux)
- Linux security settings (Linux)
- CentOS yum configuration under local sources (Linux)
- OpenStack package problems and solutions under CentOS6 (Linux)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.