Android Open Source - androiddevice.info Dir Property






From Project

Back to project page androiddevice.info.

License

The source code is released under:

GNU General Public License

If you think the Android project androiddevice.info listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package info.androiddevice.deviceinventory.info;
//from w w  w.ja va  2s. c  om

import android.os.Build;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;

import static info.androiddevice.deviceinventory.info.Utils.readFile;

public class DirProperty implements Property {
    private static final String[] directories = new String[] {"/dev/socket", "/system/bin", "/system/xbin"};

    @Override
    public Object getProperty() {
        JSONObject jsonDirectories = new JSONObject();
        for(String directory: directories) {
            try {
                jsonDirectories.put(directory, getDirListing(new File(directory)));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return jsonDirectories;
    }

    @Override
    public String getName() {
        return "directories";
    }


    private JSONArray getDirListing(File directory) {
        try {
            JSONArray result = new JSONArray();
            if(!directory.isDirectory()) {
                return result;
            }
            File[] files = directory.listFiles();
            if(files == null) {
                return result;
            }
            for(File file: files) {
                try {
                    JSONObject jsonFile = new JSONObject();
                    jsonFile.put("pathname", file.getName());
                    StructStat info = getFileInfo(file);
                    jsonFile.put("st_mode", info.st_mode);
                    jsonFile.put("st_uid", info.st_uid);
                    jsonFile.put("st_gid", info.st_gid);
                    result.put(jsonFile);
                } catch(Exception e) {
                    continue;
                }
            }
           return result;
        } catch (Exception e) {
            return new JSONArray();
        }
    }

    private StructStat getFileInfo(File file) throws Exception {
        if(Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
            libcore.io.Os os = libcore.io.Libcore.os;
            libcore.io.StructStat fileInfo = os.lstat(file.getAbsolutePath());
            return new StructStat(fileInfo);
        } else {
            android.system.StructStat fileInfo = android.system.Os.lstat(file.getAbsolutePath());
            return new StructStat(fileInfo);
        }
    }

    private static class StructStat {
        public final int st_uid;
        public final int st_gid;
        public final int st_mode;

        public StructStat(libcore.io.StructStat info) {
            this.st_uid = info.st_uid;
            this.st_gid = info.st_gid;
            this.st_mode = info.st_mode;
        }

        public StructStat(android.system.StructStat info) {
            this.st_uid = info.st_uid;
            this.st_gid = info.st_gid;
            this.st_mode = info.st_mode;
        }
    }
}




Java Source Code List

android.system.ErrnoException.java
android.system.Os.java
android.system.StructStat.java
info.androiddevice.deviceinventory.Application.java
info.androiddevice.deviceinventory.DeviceInformation.java
info.androiddevice.deviceinventory.Error.java
info.androiddevice.deviceinventory.info.CpuinfoProperty.java
info.androiddevice.deviceinventory.info.DirProperty.java
info.androiddevice.deviceinventory.info.DisplayProperty.java
info.androiddevice.deviceinventory.info.EnvironmentProperty.java
info.androiddevice.deviceinventory.info.FeaturesProperty.java
info.androiddevice.deviceinventory.info.FileProperty.java
info.androiddevice.deviceinventory.info.GetPropProperty.java
info.androiddevice.deviceinventory.info.JavaSystemProperty.java
info.androiddevice.deviceinventory.info.MeminfoProperty.java
info.androiddevice.deviceinventory.info.MountsProperty.java
info.androiddevice.deviceinventory.info.NameProperty.java
info.androiddevice.deviceinventory.info.OtacertsProperty.java
info.androiddevice.deviceinventory.info.PackageSigProperty.java
info.androiddevice.deviceinventory.info.Property.java
info.androiddevice.deviceinventory.info.SharedLibraryNamesProperty.java
info.androiddevice.deviceinventory.info.UsbProperty.java
info.androiddevice.deviceinventory.info.Utils.java
info.androiddevice.deviceinventory.info.VersionProperty.java
info.androiddevice.deviceinventory.submission.DeviceInformationListAdapter.java
info.androiddevice.deviceinventory.submission.MainActivity.java
libcore.io.ErrnoException.java
libcore.io.Libcore.java
libcore.io.Os.java
libcore.io.StructStat.java
name.unused.android.utils.systemproperties.SystemProperty.java
name.unused.android.utils.systemproperties.exception.NoSuchPropertyException.java