Home | History | Annotate | Download | only in deviceinfo
      1 /*
      2  * Copyright (C) 2015 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 package com.android.compatibility.common.deviceinfo;
     17 
     18 import android.app.ActivityManager;
     19 import android.app.ActivityManager.MemoryInfo;
     20 import android.content.Context;
     21 import android.os.Bundle;
     22 import android.os.Build;
     23 
     24 import android.media.CamcorderProfile;
     25 import android.media.MediaCodecInfo;
     26 import android.media.MediaCodecInfo.CodecCapabilities;
     27 import android.media.MediaCodecInfo.CodecProfileLevel;
     28 import android.media.MediaCodecInfo.VideoCapabilities;
     29 import android.media.MediaCodecList;
     30 
     31 import com.android.compatibility.common.util.DeviceInfoStore;
     32 import com.android.compatibility.common.util.ApiLevelUtil;
     33 
     34 import java.util.ArrayList;
     35 import java.util.List;
     36 
     37 /**
     38  * Media information collector.
     39  */
     40 public final class MediaDeviceInfo extends DeviceInfo {
     41 
     42     @Override
     43     protected void collectDeviceInfo(DeviceInfoStore store) throws Exception {
     44         MediaCodecList allCodecs = new MediaCodecList(MediaCodecList.ALL_CODECS);
     45         store.startArray("media_codec_info");
     46         for (MediaCodecInfo info : allCodecs.getCodecInfos()) {
     47 
     48             store.startGroup();
     49             store.addResult("name", info.getName());
     50             if (ApiLevelUtil.isAtLeast(Build.VERSION_CODES.Q)) {
     51                 store.addResult("canonical", info.getCanonicalName());
     52             }
     53             store.addResult("encoder", info.isEncoder());
     54             if (ApiLevelUtil.isAtLeast(Build.VERSION_CODES.Q)) {
     55                 store.addResult("alias", info.isAlias());
     56                 store.addResult("software", info.isSoftwareOnly());
     57                 store.addResult("hardware", info.isHardwareAccelerated());
     58                 store.addResult("vendor", info.isVendor());
     59             }
     60 
     61             store.startArray("supported_type");
     62             for (String type : info.getSupportedTypes()) {
     63                 store.startGroup();
     64                 store.addResult("type", type);
     65                 CodecCapabilities codecCapabilities = info.getCapabilitiesForType(type);
     66                 if (codecCapabilities.profileLevels.length > 0) {
     67                     store.startArray("codec_profile_level");
     68                     for (CodecProfileLevel profileLevel : codecCapabilities.profileLevels) {
     69                         store.startGroup();
     70                         store.addResult("level", profileLevel.level);
     71                         store.addResult("profile", profileLevel.profile);
     72                         store.endGroup();
     73                     }
     74                     store.endArray(); // codec_profile_level
     75                 }
     76                 if (codecCapabilities.colorFormats.length > 0) {
     77                     store.addArrayResult("codec_color_format", codecCapabilities.colorFormats);
     78                 }
     79                 store.addResult("supported_secure_playback", codecCapabilities.isFeatureSupported(
     80                         CodecCapabilities.FEATURE_SecurePlayback));
     81                 VideoCapabilities videoCapabilities = codecCapabilities.getVideoCapabilities();
     82                 if (videoCapabilities != null) {
     83                     store.startGroup("supported_resolutions");
     84                     store.addResult(
     85                             "supported_360p_30fps",
     86                             videoCapabilities.areSizeAndRateSupported(640, 360, 30));
     87                     store.addResult(
     88                             "supported_480p_30fps",
     89                             videoCapabilities.areSizeAndRateSupported(720, 480, 30));
     90                     store.addResult(
     91                             "supported_720p_30fps",
     92                             videoCapabilities.areSizeAndRateSupported(1280, 720, 30));
     93                     store.addResult(
     94                             "supported_1080p_30fps",
     95                             videoCapabilities.areSizeAndRateSupported(1920, 1080, 30));
     96                     // The QHD/WQHD 2560x1440 resolution is used to create YouTube and PlayMovies
     97                     // 2k content, so use that resolution to determine if a device supports 2k.
     98                     store.addResult(
     99                             "supported_2k_30fps",
    100                             videoCapabilities.areSizeAndRateSupported(2560, 1440, 30));
    101                     store.addResult(
    102                             "supported_4k_30fps",
    103                             videoCapabilities.areSizeAndRateSupported(3840, 2160, 30));
    104                     store.addResult(
    105                             "supported_8k_30fps",
    106                             videoCapabilities.areSizeAndRateSupported(7680, 4320, 30));
    107                     store.addResult(
    108                             "supported_360p_60fps",
    109                             videoCapabilities.areSizeAndRateSupported(640, 360, 60));
    110                     store.addResult(
    111                             "supported_480p_60fps",
    112                             videoCapabilities.areSizeAndRateSupported(720, 480, 60));
    113                     store.addResult(
    114                             "supported_720p_60fps",
    115                             videoCapabilities.areSizeAndRateSupported(1280, 720, 60));
    116                     store.addResult(
    117                             "supported_1080p_60fps",
    118                             videoCapabilities.areSizeAndRateSupported(1920, 1080, 60));
    119                     store.addResult(
    120                             "supported_2k_60fps",
    121                             videoCapabilities.areSizeAndRateSupported(2560, 1440, 60));
    122                     store.addResult(
    123                             "supported_4k_60fps",
    124                             videoCapabilities.areSizeAndRateSupported(3840, 2160, 60));
    125                     store.addResult(
    126                             "supported_8k_60fps",
    127                             videoCapabilities.areSizeAndRateSupported(7680, 4320, 60));
    128                     store.endGroup(); // supported_resolutions
    129                 }
    130                 store.endGroup();
    131             }
    132             store.endArray();
    133             store.endGroup();
    134         }
    135 
    136         store.endArray(); // media_codec_profile
    137     }
    138 }
    139