BubbleUtils.java 源代码


package com.xw.repo;

import android.content.res.Resources;
import android.os.Environment;
import android.util.TypedValue;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

class BubbleUtils {
    private static Properties sBuildProperties;
    private static final File BUILD_PROP_FILE = new File(Environment.getRootDirectory(), "build.prop");
    private static final Object sBuildPropertiesLock = new Object();

    BubbleUtils() {
    }

    private static Properties getBuildProperties() {
        FileInputStream fileInputStream;
        Throwable th;
        IOException e;
        synchronized (sBuildPropertiesLock) {
            if (sBuildProperties == null) {
                sBuildProperties = new Properties();
                try {
                    fileInputStream = new FileInputStream(BUILD_PROP_FILE);
                    try {
                        try {
                            sBuildProperties.load(fileInputStream);
                        } catch (IOException e2) {
                            e = e2;
                            e.printStackTrace();
                            if (fileInputStream != null) {
                                try {
                                    fileInputStream.close();
                                } catch (IOException e3) {
                                    e = e3;
                                    e.printStackTrace();
                                    return sBuildProperties;
                                }
                            }
                            return sBuildProperties;
                        }
                        try {
                            fileInputStream.close();
                        } catch (IOException e4) {
                            e = e4;
                            e.printStackTrace();
                            return sBuildProperties;
                        }
                    } catch (Throwable th2) {
                        th = th2;
                        if (fileInputStream != null) {
                            try {
                                fileInputStream.close();
                            } catch (IOException e5) {
                                e5.printStackTrace();
                            }
                        }
                        throw th;
                    }
                } catch (IOException e6) {
                    fileInputStream = null;
                    e = e6;
                } catch (Throwable th3) {
                    fileInputStream = null;
                    th = th3;
                    if (fileInputStream != null) {
                    }
                    throw th;
                }
            }
        }
        return sBuildProperties;
    }

    public static boolean isMIUI() {
        return getBuildProperties().containsKey("ro.miui.ui.version.name");
    }

    public static int dp2px(int i) {
        return (int) TypedValue.applyDimension(1, i, Resources.getSystem().getDisplayMetrics());
    }

    public static int sp2px(int i) {
        return (int) TypedValue.applyDimension(2, i, Resources.getSystem().getDisplayMetrics());
    }
}