Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * This file is part of the RootFW Project: https://github.com/spazedog/rootfw
 *  
 * Copyright (c) 2015 Daniel Berglv
 *
 * RootFW is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
    
 * RootFW is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
    
 * You should have received a copy of the GNU Lesser General Public License
 * along with RootFW. If not, see <http://www.gnu.org/licenses/>
 */

import java.util.HashMap;
import java.util.Map;

import android.os.Process;

public class Main {
    public static Map<String, Integer> UIDS = new HashMap<String, Integer>();

    public static Integer getUID(String name) {
        if (name != null) {
            if (name.matches("^[0-9]+$")) {
                return Integer.parseInt(name);
            }

            if (UIDS.containsKey(name)) {
                return UIDS.get(name);

            } else if (name.startsWith("u")) {
                Integer sep = name.indexOf("_");

                if (sep > 0) {
                    Integer uid = Integer.parseInt(name.substring(1, sep));
                    Integer gid = Integer.parseInt(name.substring(sep + 2));

                    return uid * 100000 + ((Process.FIRST_APPLICATION_UID + gid) % 100000);
                }
            }
        }

        return -10000;
    }
}