@Override
 protected void setUp() throws Exception {
   super.setUp();
   Instrumentation instrumentation = getInstrumentation();
   mContext = instrumentation.getTargetContext();
   mPackageManager = mContext.getPackageManager();
   mAvailableFeatures = new HashSet<String>();
   if (mPackageManager.getSystemAvailableFeatures() != null) {
     for (FeatureInfo feature : mPackageManager.getSystemAvailableFeatures()) {
       mAvailableFeatures.add(feature.name);
     }
   }
   mActivityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
   mLocationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
   mSensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
   mTelephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
   mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
 }
 @Override
 public boolean isSupported() {
   // see
   // http://stackoverflow.com/questions/23828487/how-can-i-check-my-android-device-support-wifi-direct
   PackageManager pm = this.getContext().getPackageManager();
   FeatureInfo[] features = pm.getSystemAvailableFeatures();
   for (FeatureInfo info : features) {
     if (info != null
         && info.name != null
         && info.name.equalsIgnoreCase("android.hardware.wifi.direct")) {
       return true;
     }
   }
   return false;
 }
Ejemplo n.º 3
0
 private static int getVersionFromPackageManager(Context context) {
   PackageManager packageManager = context.getPackageManager();
   FeatureInfo[] featureInfos = packageManager.getSystemAvailableFeatures();
   if (featureInfos != null && featureInfos.length > 0) {
     for (FeatureInfo featureInfo : featureInfos) {
       // Null feature name means this feature is the open gl es version feature.
       if (featureInfo.name == null) {
         if (featureInfo.reqGlEsVersion != FeatureInfo.GL_ES_VERSION_UNDEFINED) {
           return getMajorVersion(featureInfo.reqGlEsVersion);
         } else {
           return 1; // Lack of property means OpenGL ES version 1
         }
       }
     }
   }
   return 1;
 }
Ejemplo n.º 4
0
  /**
   * collects device features
   *
   * @param reportField the ReportField to collect
   * @param reportBuilder the current reportBuilder
   * @return Element of all device feature names
   */
  @NonNull
  @Override
  Element collect(ReportField reportField, ReportBuilder reportBuilder) {
    final ComplexElement result = new ComplexElement();
    try {
      final PackageManager pm = context.getPackageManager();
      final FeatureInfo[] features = pm.getSystemAvailableFeatures();
      for (final FeatureInfo feature : features) {
        final String featureName = feature.name;
        if (featureName != null) {
          result.put(featureName, true);
        } else {
          result.put("glEsVersion", feature.getGlEsVersion());
        }
      }
    } catch (Throwable e) {
      ACRA.log.w(LOG_TAG, "Couldn't retrieve DeviceFeatures for " + context.getPackageName(), e);
    }

    return result;
  }