Search in sources :

Example 66 with ActivityManager

use of android.app.ActivityManager in project neo4j-mobile-android by neo4j-contrib.

the class GraphDbInstance method start.

/**
     * Starts Neo4j with default configuration
     * @param graphDb The graph database service.
     *
     * @param storeDir path to directory where Neo4j store is located
     * @param create if true a new Neo4j store will be created if no store exist
     *            at <CODE>storeDir</CODE>
     * @param configuration parameters
     * @throws StartupFailedException if unable to start
     */
public synchronized Map<Object, Object> start(GraphDatabaseService graphDb, KernelExtensionLoader kernelExtensionLoader) {
    if (started) {
        throw new IllegalStateException("Neo4j instance already started");
    }
    Map<Object, Object> params = config.getParams();
    boolean useMemoryMapped = Boolean.parseBoolean((String) config.getInputParams().get(Config.USE_MEMORY_MAPPED_BUFFERS));
    boolean dumpToConsole = Boolean.parseBoolean((String) config.getInputParams().get(Config.DUMP_CONFIGURATION));
    storeDir = FileUtils.fixSeparatorsInPath(storeDir);
    StringLogger logger = StringLogger.getLogger(storeDir);
    AutoConfigurator autoConfigurator = new AutoConfigurator(config.getContext(), storeDir, useMemoryMapped, dumpToConsole);
    autoConfigurator.configure(subset(config.getInputParams(), Config.USE_MEMORY_MAPPED_BUFFERS));
    // params.putAll( config.getInputParams() );
    String separator = System.getProperty("file.separator");
    String store = storeDir + separator + NeoStore.DEFAULT_NAME;
    params.put("store_dir", storeDir);
    params.put("neo_store", store);
    params.put("create", String.valueOf(create));
    String logicalLog = storeDir + separator + NeoStoreXaDataSource.LOGICAL_LOG_DEFAULT_NAME;
    params.put("logical_log", logicalLog);
    params.put(LockManager.class, config.getLockManager());
    params.put(LockReleaser.class, config.getLockReleaser());
    kernelExtensionLoader.configureKernelExtensions();
    config.getTxModule().registerDataSource(Config.DEFAULT_DATA_SOURCE_NAME, Config.NIO_NEO_DB_CLASS, NeoStoreXaDataSource.BRANCH_ID, params);
    // hack for lucene index recovery if in path
    if (!config.isReadOnly() || config.isBackupSlave()) {
        try {
            Class clazz = Class.forName(Config.LUCENE_DS_CLASS);
            cleanWriteLocksInLuceneDirectory(storeDir + File.separator + "lucene");
            byte[] luceneId = UTF8.encode("162373");
            registerLuceneDataSource("lucene", clazz.getName(), config.getTxModule(), storeDir + File.separator + "lucene", config.getLockManager(), luceneId, params);
        } catch (ClassNotFoundException e) {
        // ok index util not on class path
        } catch (NoClassDefFoundError err) {
        // ok index util not on class path
        }
        try {
            Class clazz = Class.forName(Config.LUCENE_FULLTEXT_DS_CLASS);
            cleanWriteLocksInLuceneDirectory(storeDir + File.separator + "lucene-fulltext");
            byte[] luceneId = UTF8.encode("262374");
            registerLuceneDataSource("lucene-fulltext", clazz.getName(), config.getTxModule(), storeDir + File.separator + "lucene-fulltext", config.getLockManager(), luceneId, params);
        } catch (ClassNotFoundException e) {
        // ok index util not on class path
        } catch (NoClassDefFoundError err) {
        // ok index util not on class path
        }
    }
    persistenceSource = new NioNeoDbPersistenceSource();
    config.setPersistenceSource(Config.DEFAULT_DATA_SOURCE_NAME, create);
    config.getIdGeneratorModule().setPersistenceSourceInstance(persistenceSource);
    config.getTxModule().init();
    config.getPersistenceModule().init();
    persistenceSource.init();
    config.getIdGeneratorModule().init();
    config.getGraphDbModule().init();
    kernelExtensionLoader.initializeIndexProviders();
    config.getTxModule().start();
    config.getPersistenceModule().start(config.getTxModule().getTxManager(), persistenceSource, config.getSyncHookFactory(), config.getLockReleaser());
    persistenceSource.start(config.getTxModule().getXaDataSourceManager());
    config.getIdGeneratorModule().start();
    config.getGraphDbModule().start(config.getLockReleaser(), config.getPersistenceModule().getPersistenceManager(), config.getRelationshipTypeCreator(), params);
    logger.logMessage("--- CONFIGURATION START ---");
    logger.logMessage(autoConfigurator.getNiceMemoryInformation());
    logger.logMessage("Kernel version: " + Version.getKernel());
    for (Version componentVersion : Service.load(Version.class)) {
        logger.logMessage(componentVersion.toString());
    }
    ActivityManager am = (ActivityManager) config.getContext().getSystemService(Context.ACTIVITY_SERVICE);
    logger.logMessage("Memory class: " + am.getMemoryClass());
    // NOTE AHS: in the Java version you get a lot of VM info here, but it's just logging.
    logger.logMessage("--- CONFIGURATION END ---");
    logger.flush();
    started = true;
    return Collections.unmodifiableMap(params);
}
Also used : NioNeoDbPersistenceSource(org.neo4j.kernel.impl.nioneo.xa.NioNeoDbPersistenceSource) ActivityManager(android.app.ActivityManager) StringLogger(org.neo4j.kernel.impl.util.StringLogger)

Example 67 with ActivityManager

use of android.app.ActivityManager in project UltimateAndroid by cymcsg.

the class BasicUtils method isServiceRunning.

/**
     * Check if the service is running
     *
     * @param context
     * @param cls
     * @return
     */
public static boolean isServiceRunning(Context context, Class<?> cls) {
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningServiceInfo> services = activityManager.getRunningServices(Integer.MAX_VALUE);
    for (ActivityManager.RunningServiceInfo serviceInfo : services) {
        ComponentName componentName = serviceInfo.service;
        String serviceName = componentName.getClassName();
        if (serviceName.equals(cls.getName())) {
            return true;
        }
    }
    return false;
}
Also used : ComponentName(android.content.ComponentName) ActivityManager(android.app.ActivityManager)

Example 68 with ActivityManager

use of android.app.ActivityManager in project superCleanMaster by joyoyao.

the class AppUtil method getAvailMemory.

/**
     *
     * 描述:解析数据.
     *
     * @param info
     *            User 39%, System 17%, IOW 3%, IRQ 0%
     * @return
     */
// public static AbCPUInfo parseCPUInfo(String info) {
// AbCPUInfo CPUInfo = new AbCPUInfo();
// String tempString = "";
// String[] rows = null;
// String[] columns = null;
// rows = info.split("[\n]+");
// // 使用正则表达式分割字符串
// for (int i = 0; i < rows.length; i++) {
// tempString = rows[i];
// //AbLogUtil.d(AbAppUtil.class, tempString);
// if (tempString.indexOf("User") != -1 && tempString.indexOf("System") !=
// -1) {
// tempString = tempString.trim();
// columns = tempString.split(",");
// for(int j = 0; j < columns.length; j++){
// String col = columns[j].trim();
// String[] cpu = col.split(" ");
// if(j == 0){
// CPUInfo.User = cpu[1];
// }else if(j == 1){
// CPUInfo.System = cpu[1];
// }else if(j == 2){
// CPUInfo.IOW = cpu[1];
// }else if(j == 3){
// CPUInfo.IRQ = cpu[1];
// }
// }
// }
// }
// return CPUInfo;
// }
/**
     * 描述:获取可用内存.
     *
     * @param context
     * @return
     */
public static long getAvailMemory(Context context) {
    // 获取android当前可用内存大小
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    MemoryInfo memoryInfo = new MemoryInfo();
    activityManager.getMemoryInfo(memoryInfo);
    return memoryInfo.availMem;
}
Also used : MemoryInfo(android.app.ActivityManager.MemoryInfo) ActivityManager(android.app.ActivityManager)

Example 69 with ActivityManager

use of android.app.ActivityManager in project superCleanMaster by joyoyao.

the class AppUtil method getRunningAppProcesses.

/**
     * 描述:获取运行的进程列表.
     *
     * @param context
     * @return
     */
public static List<AppProcessInfo> getRunningAppProcesses(Context context) {
    ActivityManager activityManager = null;
    List<AppProcessInfo> list = null;
    PackageManager packageManager = null;
    try {
        activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        packageManager = context.getApplicationContext().getPackageManager();
        list = new ArrayList<AppProcessInfo>();
        // 所有运行的进程
        List<RunningAppProcessInfo> appProcessList = activityManager.getRunningAppProcesses();
        ApplicationInfo appInfo = null;
        AppProcessInfo abAppProcessInfo = null;
        PackageInfo packageInfo = getPackageInfo(context);
        if (mProcessList != null) {
            mProcessList.clear();
        }
        mProcessList = getProcessRunningInfo();
        for (RunningAppProcessInfo appProcessInfo : appProcessList) {
            abAppProcessInfo = new AppProcessInfo(appProcessInfo.processName, appProcessInfo.pid, appProcessInfo.uid);
            appInfo = getApplicationInfo(context, appProcessInfo.processName);
            if (appInfo != null) {
                if ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
                    abAppProcessInfo.isSystem = true;
                } else {
                    abAppProcessInfo.isSystem = false;
                }
                Drawable icon = appInfo.loadIcon(packageManager);
                String appName = appInfo.loadLabel(packageManager).toString();
                abAppProcessInfo.icon = icon;
                abAppProcessInfo.appName = appName;
            } else {
                // :服务的命名
                if (appProcessInfo.processName.indexOf(":") != -1) {
                    appInfo = getApplicationInfo(context, appProcessInfo.processName.split(":")[0]);
                    Drawable icon = appInfo.loadIcon(packageManager);
                    abAppProcessInfo.icon = icon;
                }
                abAppProcessInfo.isSystem = true;
                abAppProcessInfo.appName = appProcessInfo.processName;
            }
            /*
                 * AbPsRow psRow = getPsRow(appProcessInfo.processName);
				 * if(psRow!=null){ abAppProcessInfo.memory = psRow.mem; }
				 */
            ProcessInfo processInfo = getMemInfo(appProcessInfo.processName);
            abAppProcessInfo.memory = processInfo.memory;
            abAppProcessInfo.cpu = processInfo.cpu;
            abAppProcessInfo.status = processInfo.status;
            abAppProcessInfo.threadsCount = processInfo.threadsCount;
            list.add(abAppProcessInfo);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return list;
}
Also used : PackageInfo(android.content.pm.PackageInfo) ApplicationInfo(android.content.pm.ApplicationInfo) Drawable(android.graphics.drawable.Drawable) ProcessInfo(com.yzy.supercleanmaster.bean.ProcessInfo) AppProcessInfo(com.yzy.supercleanmaster.bean.AppProcessInfo) RunningAppProcessInfo(android.app.ActivityManager.RunningAppProcessInfo) ActivityManager(android.app.ActivityManager) AppProcessInfo(com.yzy.supercleanmaster.bean.AppProcessInfo) RunningAppProcessInfo(android.app.ActivityManager.RunningAppProcessInfo) IOException(java.io.IOException) PackageManager(android.content.pm.PackageManager) RunningAppProcessInfo(android.app.ActivityManager.RunningAppProcessInfo)

Example 70 with ActivityManager

use of android.app.ActivityManager in project QLibrary by DragonsQC.

the class AppUtils method isServiceRunning.

/**
     * 检测服务是否运行
     *
     * @param context   Context
     * @param className 类名
     * @return 服务是否运行
     */
public static boolean isServiceRunning(Context context, String className) {
    boolean isRunning = false;
    ActivityManager activityManager = (ActivityManager) context.getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningServiceInfo> servicesList = activityManager.getRunningServices(Integer.MAX_VALUE);
    for (ActivityManager.RunningServiceInfo si : servicesList) {
        if (className.equals(si.service.getClassName())) {
            isRunning = true;
        }
    }
    return isRunning;
}
Also used : ActivityManager(android.app.ActivityManager)

Aggregations

ActivityManager (android.app.ActivityManager)339 Intent (android.content.Intent)44 Context (android.content.Context)33 RunningAppProcessInfo (android.app.ActivityManager.RunningAppProcessInfo)30 ComponentName (android.content.ComponentName)26 PackageManager (android.content.pm.PackageManager)23 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)18 IActivityManager (android.app.IActivityManager)16 ConfigurationInfo (android.content.pm.ConfigurationInfo)16 IOException (java.io.IOException)16 RunningServiceInfo (android.app.ActivityManager.RunningServiceInfo)15 View (android.view.View)15 ImageView (android.widget.ImageView)15 ArrayList (java.util.ArrayList)15 Point (android.graphics.Point)14 TextView (android.widget.TextView)14 RunningTaskInfo (android.app.ActivityManager.RunningTaskInfo)13 ResolveInfo (android.content.pm.ResolveInfo)12 RemoteException (android.os.RemoteException)12 TargetApi (android.annotation.TargetApi)11